erlydtl_parser.yrl 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360
  1. %%%-------------------------------------------------------------------
  2. %%% File: erlydtl_parser.erl
  3. %%% @author Roberto Saccon <rsaccon@gmail.com> [http://rsaccon.com]
  4. %%% @author Evan Miller <emmiller@gmail.com>
  5. %%% @copyright 2008 Roberto Saccon, Evan Miller
  6. %%% @doc Template language grammar
  7. %%% @reference See <a href="http://erlydtl.googlecode.com" target="_top">http://erlydtl.googlecode.com</a> for more information
  8. %%% @end
  9. %%%
  10. %%% The MIT License
  11. %%%
  12. %%% Copyright (c) 2007 Roberto Saccon, Evan Miller
  13. %%%
  14. %%% Permission is hereby granted, free of charge, to any person obtaining a copy
  15. %%% of this software and associated documentation files (the "Software"), to deal
  16. %%% in the Software without restriction, including without limitation the rights
  17. %%% to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  18. %%% copies of the Software, and to permit persons to whom the Software is
  19. %%% furnished to do so, subject to the following conditions:
  20. %%%
  21. %%% The above copyright notice and this permission notice shall be included in
  22. %%% all copies or substantial portions of the Software.
  23. %%%
  24. %%% THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  25. %%% IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  26. %%% FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  27. %%% AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  28. %%% LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  29. %%% OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
  30. %%% THE SOFTWARE.
  31. %%%
  32. %%% @since 2007-11-11 by Roberto Saccon, Evan Miller
  33. %%%-------------------------------------------------------------------
  34. Nonterminals
  35. Elements
  36. Literal
  37. ValueBraced
  38. Value
  39. Values
  40. Variable
  41. Filter
  42. AutoEscapeBlock
  43. AutoEscapeBraced
  44. EndAutoEscapeBraced
  45. BlockBlock
  46. BlockBraced
  47. EndBlockBraced
  48. CommentBlock
  49. CommentBraced
  50. EndCommentBraced
  51. CycleTag
  52. CycleNames
  53. CycleNamesCompat
  54. ExtendsTag
  55. IncludeTag
  56. NowTag
  57. FirstofTag
  58. FilterBlock
  59. FilterBraced
  60. EndFilterBraced
  61. Filters
  62. ForBlock
  63. ForBraced
  64. EmptyBraced
  65. EndForBraced
  66. ForExpression
  67. ForGroup
  68. IfBlock
  69. IfBraced
  70. IfExpression
  71. ElseBraced
  72. EndIfBraced
  73. IfEqualBlock
  74. IfEqualBraced
  75. IfEqualExpression
  76. EndIfEqualBraced
  77. IfNotEqualBlock
  78. IfNotEqualBraced
  79. IfNotEqualExpression
  80. EndIfNotEqualBraced
  81. CustomTag
  82. Args
  83. SpacelessBlock
  84. SSITag
  85. BlockTransBlock
  86. TransTag
  87. TemplatetagTag
  88. Templatetag
  89. WidthRatioTag
  90. WithBlock
  91. WithBraced
  92. EndWithBraced
  93. CallTag
  94. CallWithTag
  95. Unot.
  96. Terminals
  97. and_keyword
  98. autoescape_keyword
  99. block_keyword
  100. blocktrans_keyword
  101. call_keyword
  102. close_tag
  103. close_var
  104. comment_keyword
  105. cycle_keyword
  106. else_keyword
  107. empty_keyword
  108. endautoescape_keyword
  109. endblock_keyword
  110. endblocktrans_keyword
  111. endcomment_keyword
  112. endfilter_keyword
  113. endfor_keyword
  114. endif_keyword
  115. endifequal_keyword
  116. endifnotequal_keyword
  117. endspaceless_keyword
  118. endwith_keyword
  119. extends_keyword
  120. filter_keyword
  121. firstof_keyword
  122. for_keyword
  123. identifier
  124. if_keyword
  125. ifequal_keyword
  126. ifnotequal_keyword
  127. in_keyword
  128. include_keyword
  129. noop_keyword
  130. not_keyword
  131. now_keyword
  132. number_literal
  133. only_keyword
  134. or_keyword
  135. open_tag
  136. open_var
  137. parsed_keyword
  138. spaceless_keyword
  139. ssi_keyword
  140. string_literal
  141. string
  142. templatetag_keyword
  143. openblock_keyword
  144. closeblock_keyword
  145. openvariable_keyword
  146. closevariable_keyword
  147. openbrace_keyword
  148. closebrace_keyword
  149. opencomment_keyword
  150. closecomment_keyword
  151. trans_keyword
  152. widthratio_keyword
  153. with_keyword
  154. ',' '|' '=' ':' '.'
  155. '==' '!='
  156. '>=' '<='
  157. '>' '<'
  158. '(' ')'
  159. '_'.
  160. Rootsymbol
  161. Elements.
  162. %% Operator precedences for the E non terminal
  163. Left 100 or_keyword.
  164. Left 110 and_keyword.
  165. Nonassoc 300 '==' '!=' '>=' '<=' '>' '<'.
  166. Unary 600 Unot.
  167. Elements -> '$empty' : [].
  168. Elements -> Elements string : '$1' ++ ['$2'].
  169. Elements -> Elements AutoEscapeBlock : '$1' ++ ['$2'].
  170. Elements -> Elements BlockBlock : '$1' ++ ['$2'].
  171. Elements -> Elements BlockTransBlock : '$1' ++ ['$2'].
  172. Elements -> Elements CallTag : '$1' ++ ['$2'].
  173. Elements -> Elements CallWithTag : '$1' ++ ['$2'].
  174. Elements -> Elements CommentBlock : '$1' ++ ['$2'].
  175. Elements -> Elements CustomTag : '$1' ++ ['$2'].
  176. Elements -> Elements CycleTag : '$1' ++ ['$2'].
  177. Elements -> Elements ExtendsTag : '$1' ++ ['$2'].
  178. Elements -> Elements FilterBlock : '$1' ++ ['$2'].
  179. Elements -> Elements FirstofTag : '$1' ++ ['$2'].
  180. Elements -> Elements ForBlock : '$1' ++ ['$2'].
  181. Elements -> Elements IfBlock : '$1' ++ ['$2'].
  182. Elements -> Elements IfEqualBlock : '$1' ++ ['$2'].
  183. Elements -> Elements IfNotEqualBlock : '$1' ++ ['$2'].
  184. Elements -> Elements IncludeTag : '$1' ++ ['$2'].
  185. Elements -> Elements NowTag : '$1' ++ ['$2'].
  186. Elements -> Elements SpacelessBlock : '$1' ++ ['$2'].
  187. Elements -> Elements SSITag : '$1' ++ ['$2'].
  188. Elements -> Elements TemplatetagTag : '$1' ++ ['$2'].
  189. Elements -> Elements TransTag : '$1' ++ ['$2'].
  190. Elements -> Elements ValueBraced : '$1' ++ ['$2'].
  191. Elements -> Elements WidthRatioTag : '$1' ++ ['$2'].
  192. Elements -> Elements WithBlock : '$1' ++ ['$2'].
  193. ValueBraced -> open_var Value close_var : '$2'.
  194. Value -> Value '|' Filter : {apply_filter, '$1', '$3'}.
  195. Value -> Variable : '$1'.
  196. Value -> Literal : '$1'.
  197. Values -> Value : ['$1'].
  198. Values -> Values Value : '$1' ++ ['$2'].
  199. Variable -> identifier : {variable, '$1'}.
  200. Variable -> Variable '.' identifier : {attribute, {'$3', '$1'}}.
  201. AutoEscapeBlock -> AutoEscapeBraced Elements EndAutoEscapeBraced : {autoescape, '$1', '$2'}.
  202. AutoEscapeBraced -> open_tag autoescape_keyword identifier close_tag : '$3'.
  203. EndAutoEscapeBraced -> open_tag endautoescape_keyword close_tag.
  204. BlockBlock -> BlockBraced Elements EndBlockBraced : {block, '$1', '$2'}.
  205. BlockBraced -> open_tag block_keyword identifier close_tag : '$3'.
  206. EndBlockBraced -> open_tag endblock_keyword close_tag.
  207. ExtendsTag -> open_tag extends_keyword string_literal close_tag : {extends, '$3'}.
  208. IncludeTag -> open_tag include_keyword string_literal close_tag : {include, '$3', []}.
  209. IncludeTag -> open_tag include_keyword string_literal with_keyword Args close_tag : {include, '$3', '$5'}.
  210. IncludeTag -> open_tag include_keyword string_literal only_keyword close_tag : {include_only, '$3', []}.
  211. IncludeTag -> open_tag include_keyword string_literal with_keyword Args only_keyword close_tag : {include_only, '$3', '$5'}.
  212. NowTag -> open_tag now_keyword string_literal close_tag : {date, now, '$3'}.
  213. CommentBlock -> CommentBraced Elements EndCommentBraced : {comment, '$2'}.
  214. CommentBraced -> open_tag comment_keyword close_tag.
  215. EndCommentBraced -> open_tag endcomment_keyword close_tag.
  216. CycleTag -> open_tag cycle_keyword CycleNamesCompat close_tag : {cycle_compat, '$3'}.
  217. CycleTag -> open_tag cycle_keyword CycleNames close_tag : {cycle, '$3'}.
  218. CycleNames -> Value : ['$1'].
  219. CycleNames -> CycleNames Value : '$1' ++ ['$2'].
  220. CycleNamesCompat -> identifier ',' : ['$1'].
  221. CycleNamesCompat -> CycleNamesCompat identifier ',' : '$1' ++ ['$2'].
  222. CycleNamesCompat -> CycleNamesCompat identifier : '$1' ++ ['$2'].
  223. FilterBlock -> FilterBraced Elements EndFilterBraced : {filter, '$1', '$2'}.
  224. FilterBraced -> open_tag filter_keyword Filters close_tag : '$3'.
  225. EndFilterBraced -> open_tag endfilter_keyword close_tag.
  226. Filters -> Filter : ['$1'].
  227. Filters -> Filters '|' Filter : '$1' ++ ['$3'].
  228. FirstofTag -> open_tag firstof_keyword Values close_tag : {firstof, '$3'}.
  229. ForBlock -> ForBraced Elements EndForBraced : {for, '$1', '$2'}.
  230. ForBlock -> ForBraced Elements EmptyBraced Elements EndForBraced : {for, '$1', '$2', '$4'}.
  231. EmptyBraced -> open_tag empty_keyword close_tag.
  232. ForBraced -> open_tag for_keyword ForExpression close_tag : '$3'.
  233. EndForBraced -> open_tag endfor_keyword close_tag.
  234. ForExpression -> ForGroup in_keyword Variable : {'in', '$1', '$3'}.
  235. ForGroup -> identifier : ['$1'].
  236. ForGroup -> ForGroup ',' identifier : '$1' ++ ['$3'].
  237. IfBlock -> IfBraced Elements ElseBraced Elements EndIfBraced : {ifelse, '$1', '$2', '$4'}.
  238. IfBlock -> IfBraced Elements EndIfBraced : {'if', '$1', '$2'}.
  239. IfBraced -> open_tag if_keyword IfExpression close_tag : '$3'.
  240. IfExpression -> Value in_keyword Value : {'expr', "in", '$1', '$3'}.
  241. IfExpression -> Value not_keyword in_keyword Value : {'expr', "not", {'expr', "in", '$1', '$4'}}.
  242. IfExpression -> Value '==' Value : {'expr', "eq", '$1', '$3'}.
  243. IfExpression -> Value '!=' Value : {'expr', "ne", '$1', '$3'}.
  244. IfExpression -> Value '>=' Value : {'expr', "ge", '$1', '$3'}.
  245. IfExpression -> Value '<=' Value : {'expr', "le", '$1', '$3'}.
  246. IfExpression -> Value '>' Value : {'expr', "gt", '$1', '$3'}.
  247. IfExpression -> Value '<' Value : {'expr', "lt", '$1', '$3'}.
  248. IfExpression -> '(' IfExpression ')' : '$2'.
  249. IfExpression -> Unot : '$1'.
  250. IfExpression -> IfExpression or_keyword IfExpression : {'expr', "or", '$1', '$3'}.
  251. IfExpression -> IfExpression and_keyword IfExpression : {'expr', "and", '$1', '$3'}.
  252. IfExpression -> Value : '$1'.
  253. Unot -> not_keyword IfExpression : {expr, "not", '$2'}.
  254. ElseBraced -> open_tag else_keyword close_tag.
  255. EndIfBraced -> open_tag endif_keyword close_tag.
  256. IfEqualBlock -> IfEqualBraced Elements ElseBraced Elements EndIfEqualBraced : {ifequalelse, '$1', '$2', '$4'}.
  257. IfEqualBlock -> IfEqualBraced Elements EndIfEqualBraced : {ifequal, '$1', '$2'}.
  258. IfEqualBraced -> open_tag ifequal_keyword IfEqualExpression Value close_tag : ['$3', '$4'].
  259. IfEqualExpression -> Value : '$1'.
  260. EndIfEqualBraced -> open_tag endifequal_keyword close_tag.
  261. IfNotEqualBlock -> IfNotEqualBraced Elements ElseBraced Elements EndIfNotEqualBraced : {ifnotequalelse, '$1', '$2', '$4'}.
  262. IfNotEqualBlock -> IfNotEqualBraced Elements EndIfNotEqualBraced : {ifnotequal, '$1', '$2'}.
  263. IfNotEqualBraced -> open_tag ifnotequal_keyword IfNotEqualExpression Value close_tag : ['$3', '$4'].
  264. IfNotEqualExpression -> Value : '$1'.
  265. EndIfNotEqualBraced -> open_tag endifnotequal_keyword close_tag.
  266. SpacelessBlock -> open_tag spaceless_keyword close_tag Elements open_tag endspaceless_keyword close_tag : {spaceless, '$4'}.
  267. SSITag -> open_tag ssi_keyword Value close_tag : {ssi, '$3'}.
  268. SSITag -> open_tag ssi_keyword string_literal parsed_keyword close_tag : {ssi_parsed, '$3'}.
  269. BlockTransBlock -> open_tag blocktrans_keyword close_tag Elements open_tag endblocktrans_keyword close_tag : {blocktrans, [], '$4'}.
  270. BlockTransBlock -> open_tag blocktrans_keyword with_keyword Args close_tag Elements open_tag endblocktrans_keyword close_tag : {blocktrans, '$4', '$6'}.
  271. TemplatetagTag -> open_tag templatetag_keyword Templatetag close_tag : {templatetag, '$3'}.
  272. Templatetag -> openblock_keyword : '$1'.
  273. Templatetag -> closeblock_keyword : '$1'.
  274. Templatetag -> openvariable_keyword : '$1'.
  275. Templatetag -> closevariable_keyword : '$1'.
  276. Templatetag -> openbrace_keyword : '$1'.
  277. Templatetag -> closebrace_keyword : '$1'.
  278. Templatetag -> opencomment_keyword : '$1'.
  279. Templatetag -> closecomment_keyword : '$1'.
  280. TransTag -> open_tag trans_keyword string_literal close_tag : {trans, '$3'}.
  281. TransTag -> open_tag trans_keyword Variable close_tag : {trans, '$3'}.
  282. TransTag -> open_tag trans_keyword string_literal noop_keyword close_tag : '$3'.
  283. TransTag -> open_tag trans_keyword Variable noop_keyword close_tag : '$3'.
  284. WidthRatioTag -> open_tag widthratio_keyword Value Value number_literal close_tag : {widthratio, '$3', '$4', '$5'}.
  285. WithBlock -> WithBraced Elements EndWithBraced : {with, '$1', '$2'}.
  286. WithBraced -> open_tag with_keyword Args close_tag : '$3'.
  287. EndWithBraced -> open_tag endwith_keyword close_tag.
  288. Filter -> identifier : ['$1'].
  289. Filter -> identifier ':' Literal : ['$1', '$3'].
  290. Filter -> identifier ':' Variable : ['$1', '$3'].
  291. Literal -> '_' '(' string_literal ')' : {trans, '$3'}.
  292. Literal -> string_literal : '$1'.
  293. Literal -> number_literal : '$1'.
  294. CustomTag -> open_tag identifier Args close_tag : {tag, '$2', '$3'}.
  295. Args -> '$empty' : [].
  296. Args -> Args identifier '=' Value : '$1' ++ [{'$2', '$4'}].
  297. CallTag -> open_tag call_keyword identifier close_tag : {call, '$3'}.
  298. CallWithTag -> open_tag call_keyword identifier with_keyword Value close_tag : {call, '$3', '$5'}.