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.

Jinj2.sublime-syntax 5.7KB

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