You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

182 lines
5.7KB

  1. %YAML 1.2
  2. ---
  3. # http://www.sublimetext.com/docs/3/syntax.html
  4. name: Jinja2
  5. file_extensions:
  6. - j2
  7. - jinja2
  8. scope: text.html.jinja2
  9. contexts:
  10. main:
  11. - include: scope:text.html.basic
  12. - match: '({%)\s*(raw)\s*(%})'
  13. captures:
  14. 1: entity.other.jinja2.delimiter.tag
  15. 2: keyword.control.jinja2
  16. 3: entity.other.jinja2.delimiter.tag
  17. push:
  18. - meta_scope: comment.block.jinja2.raw
  19. - match: '({%)\s*(endraw)\s*(%})'
  20. captures:
  21. 1: entity.other.jinja2.delimiter.tag
  22. 2: keyword.control.jinja2
  23. 3: entity.other.jinja2.delimiter.tag
  24. pop: true
  25. - match: "{#-?"
  26. captures:
  27. 0: entity.other.jinja2.delimiter.comment
  28. push:
  29. - meta_scope: comment.block.jinja2
  30. - match: "-?#}"
  31. captures:
  32. 0: entity.other.jinja2.delimiter.comment
  33. pop: true
  34. - match: "{{-?"
  35. captures:
  36. 0: entity.other.jinja2.delimiter.variable
  37. push:
  38. - meta_scope: meta.scope.jinja2.variable
  39. - match: "-?}}"
  40. captures:
  41. 0: entity.other.jinja2.delimiter.variable
  42. pop: true
  43. - include: expression
  44. - match: "{%-?"
  45. captures:
  46. 0: entity.other.jinja2.delimiter.tag
  47. push:
  48. - meta_scope: meta.scope.jinja2.tag
  49. - match: "-?%}"
  50. captures:
  51. 0: entity.other.jinja2.delimiter.tag
  52. pop: true
  53. - include: expression
  54. escaped_char:
  55. - match: '\\x[0-9A-F]{2}'
  56. scope: constant.character.escape.hex.jinja2
  57. escaped_unicode_char:
  58. - match: '(\\U[0-9A-Fa-f]{8})|(\\u[0-9A-Fa-f]{4})|(\\N\{[a-zA-Z ]+\})'
  59. captures:
  60. 1: constant.character.escape.unicode.16-bit-hex.jinja2
  61. 2: constant.character.escape.unicode.32-bit-hex.jinja2
  62. 3: constant.character.escape.unicode.name.jinja2
  63. expression:
  64. - match: '\s*\b(macro)\s+([a-zA-Z_][a-zA-Z0-9_]*)\b'
  65. captures:
  66. 1: keyword.control.jinja2
  67. 2: variable.other.jinja2.macro
  68. - match: '\s*\b(block)\s+([a-zA-Z_][a-zA-Z0-9_]*)\b'
  69. captures:
  70. 1: keyword.control.jinja2
  71. 2: variable.other.jinja2.block
  72. - match: '\s*\b(filter)\s+([a-zA-Z_][a-zA-Z0-9_]*)\b'
  73. captures:
  74. 1: keyword.control.jinja2
  75. 2: variable.other.jinja2.filter
  76. - match: '\s*\b(is)\s+([a-zA-Z_][a-zA-Z0-9_]*)\b'
  77. captures:
  78. 1: keyword.control.jinja2
  79. 2: variable.other.jinja2.test
  80. - match: '(?<=\{\%-|\{\%)\s*\b([a-zA-Z_][a-zA-Z0-9_]*)\b(?!\s*[,=])'
  81. captures:
  82. 1: keyword.control.jinja2
  83. - match: \b(and|else|if|in|import|not|or|recursive|with(out)?\s+context)\b
  84. scope: keyword.control.jinja2
  85. - match: '\b([Tt]rue|[Ff]alse|[Nn]one)\b'
  86. scope: constant.language.jinja2
  87. - match: \b(loop|super|self|varargs|kwargs)\b
  88. scope: variable.language.jinja2
  89. - match: "[a-zA-Z_][a-zA-Z0-9_]*"
  90. scope: variable.other.jinja2
  91. - match: (\+|\-|\*\*|\*|//|/|%)
  92. scope: keyword.operator.arithmetic.jinja2
  93. - match: '(\|)([a-zA-Z_][a-zA-Z0-9_]*)'
  94. captures:
  95. 1: punctuation.other.jinja2
  96. 2: variable.other.jinja2.filter
  97. - match: '(\.)([a-zA-Z_][a-zA-Z0-9_]*)'
  98. captures:
  99. 1: punctuation.other.jinja2
  100. 2: variable.other.jinja2.attribute
  101. - match: '\['
  102. captures:
  103. 0: punctuation.other.jinja2
  104. push:
  105. - match: '\]'
  106. captures:
  107. 0: punctuation.other.jinja2
  108. pop: true
  109. - include: expression
  110. - match: \(
  111. captures:
  112. 0: punctuation.other.jinja2
  113. push:
  114. - match: \)
  115. captures:
  116. 0: punctuation.other.jinja2
  117. pop: true
  118. - include: expression
  119. - match: '\{'
  120. captures:
  121. 0: punctuation.other.jinja2
  122. push:
  123. - match: '\}'
  124. captures:
  125. 0: punctuation.other.jinja2
  126. pop: true
  127. - include: expression
  128. - match: (\.|:|\||,)
  129. scope: punctuation.other.jinja2
  130. - match: (==|<=|=>|<|>|!=)
  131. scope: keyword.operator.comparison.jinja2
  132. - match: "="
  133. scope: keyword.operator.assignment.jinja2
  134. - match: '"'
  135. captures:
  136. 0: punctuation.definition.string.begin.jinja2
  137. push:
  138. - meta_scope: string.quoted.double.jinja2
  139. - match: '"'
  140. captures:
  141. 0: punctuation.definition.string.end.jinja2
  142. pop: true
  143. - include: string
  144. - match: "'"
  145. captures:
  146. 0: punctuation.definition.string.begin.jinja2
  147. push:
  148. - meta_scope: string.quoted.single.jinja2
  149. - match: "'"
  150. captures:
  151. 0: punctuation.definition.string.end.jinja2
  152. pop: true
  153. - include: string
  154. - match: "@/"
  155. captures:
  156. 0: punctuation.definition.regexp.begin.jinja2
  157. push:
  158. - meta_scope: string.regexp.jinja2
  159. - match: /
  160. captures:
  161. 0: punctuation.definition.regexp.end.jinja2
  162. pop: true
  163. - include: simple_escapes
  164. simple_escapes:
  165. - match: (\\\n)|(\\\\)|(\\\")|(\\')|(\\a)|(\\b)|(\\f)|(\\n)|(\\r)|(\\t)|(\\v)
  166. captures:
  167. 1: constant.character.escape.newline.jinja2
  168. 2: constant.character.escape.backlash.jinja2
  169. 3: constant.character.escape.double-quote.jinja2
  170. 4: constant.character.escape.single-quote.jinja2
  171. 5: constant.character.escape.bell.jinja2
  172. 6: constant.character.escape.backspace.jinja2
  173. 7: constant.character.escape.formfeed.jinja2
  174. 8: constant.character.escape.linefeed.jinja2
  175. 9: constant.character.escape.return.jinja2
  176. 10: constant.character.escape.tab.jinja2
  177. 11: constant.character.escape.vertical-tab.jinja2
  178. string:
  179. - include: simple_escapes
  180. - include: escaped_char
  181. - include: escaped_unicode_char