erlydtl_parser.yrl 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344
  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. Variable
  40. Filter
  41. AutoEscapeBlock
  42. AutoEscapeBraced
  43. EndAutoEscapeBraced
  44. BlockBlock
  45. BlockBraced
  46. EndBlockBraced
  47. CommentBlock
  48. CommentBraced
  49. EndCommentBraced
  50. CycleTag
  51. CycleNames
  52. CycleNamesCompat
  53. ExtendsTag
  54. IncludeTag
  55. NowTag
  56. FirstofTag
  57. FirstofList
  58. FirstofValues
  59. FilterBlock
  60. FilterBraced
  61. EndFilterBraced
  62. Filters
  63. ForBlock
  64. ForBraced
  65. EmptyBraced
  66. EndForBraced
  67. ForExpression
  68. ForGroup
  69. IfBlock
  70. IfBraced
  71. IfExpression
  72. ElseBraced
  73. EndIfBraced
  74. IfEqualBlock
  75. IfEqualBraced
  76. IfEqualExpression
  77. EndIfEqualBraced
  78. IfNotEqualBlock
  79. IfNotEqualBraced
  80. IfNotEqualExpression
  81. EndIfNotEqualBraced
  82. CustomTag
  83. Args
  84. SpacelessBlock
  85. SSITag
  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. call_keyword
  101. close_tag
  102. close_var
  103. comment_keyword
  104. cycle_keyword
  105. else_keyword
  106. empty_keyword
  107. endautoescape_keyword
  108. endblock_keyword
  109. endcomment_keyword
  110. endfilter_keyword
  111. endfor_keyword
  112. endif_keyword
  113. endifequal_keyword
  114. endifnotequal_keyword
  115. endspaceless_keyword
  116. endwith_keyword
  117. extends_keyword
  118. filter_keyword
  119. firstof_keyword
  120. for_keyword
  121. identifier
  122. if_keyword
  123. ifequal_keyword
  124. ifnotequal_keyword
  125. in_keyword
  126. include_keyword
  127. noop_keyword
  128. not_keyword
  129. now_keyword
  130. number_literal
  131. or_keyword
  132. open_tag
  133. open_var
  134. spaceless_keyword
  135. ssi_keyword
  136. string_literal
  137. string
  138. templatetag_keyword
  139. openblock_keyword
  140. closeblock_keyword
  141. openvariable_keyword
  142. closevariable_keyword
  143. openbrace_keyword
  144. closebrace_keyword
  145. opencomment_keyword
  146. closecomment_keyword
  147. trans_keyword
  148. widthratio_keyword
  149. with_keyword
  150. ',' '|' '=' ':' '.'
  151. '==' '!='
  152. '>=' '<='
  153. '>' '<'
  154. '(' ')'.
  155. Rootsymbol
  156. Elements.
  157. %% Operator precedences for the E non terminal
  158. Left 100 or_keyword.
  159. Left 110 and_keyword.
  160. Nonassoc 300 '==' '!=' '>=' '<=' '>' '<'.
  161. Unary 600 Unot.
  162. Elements -> '$empty' : [].
  163. Elements -> Elements string : '$1' ++ ['$2'].
  164. Elements -> Elements AutoEscapeBlock : '$1' ++ ['$2'].
  165. Elements -> Elements BlockBlock : '$1' ++ ['$2'].
  166. Elements -> Elements CallTag : '$1' ++ ['$2'].
  167. Elements -> Elements CallWithTag : '$1' ++ ['$2'].
  168. Elements -> Elements CommentBlock : '$1' ++ ['$2'].
  169. Elements -> Elements CustomTag : '$1' ++ ['$2'].
  170. Elements -> Elements CycleTag : '$1' ++ ['$2'].
  171. Elements -> Elements ExtendsTag : '$1' ++ ['$2'].
  172. Elements -> Elements FilterBlock : '$1' ++ ['$2'].
  173. Elements -> Elements FirstofTag : '$1' ++ ['$2'].
  174. Elements -> Elements ForBlock : '$1' ++ ['$2'].
  175. Elements -> Elements IfBlock : '$1' ++ ['$2'].
  176. Elements -> Elements IfEqualBlock : '$1' ++ ['$2'].
  177. Elements -> Elements IfNotEqualBlock : '$1' ++ ['$2'].
  178. Elements -> Elements IncludeTag : '$1' ++ ['$2'].
  179. Elements -> Elements NowTag : '$1' ++ ['$2'].
  180. Elements -> Elements SpacelessBlock : '$1' ++ ['$2'].
  181. Elements -> Elements SSITag : '$1' ++ ['$2'].
  182. Elements -> Elements TemplatetagTag : '$1' ++ ['$2'].
  183. Elements -> Elements TransTag : '$1' ++ ['$2'].
  184. Elements -> Elements ValueBraced : '$1' ++ ['$2'].
  185. Elements -> Elements WidthRatioTag : '$1' ++ ['$2'].
  186. Elements -> Elements WithBlock : '$1' ++ ['$2'].
  187. ValueBraced -> open_var Value close_var : '$2'.
  188. Value -> Value '|' Filter : {apply_filter, '$1', '$3'}.
  189. Value -> Variable : '$1'.
  190. Value -> Literal : '$1'.
  191. Variable -> identifier : {variable, '$1'}.
  192. Variable -> Variable '.' identifier : {attribute, {'$3', '$1'}}.
  193. AutoEscapeBlock -> AutoEscapeBraced Elements EndAutoEscapeBraced : {autoescape, '$1', '$2'}.
  194. AutoEscapeBraced -> open_tag autoescape_keyword identifier close_tag : '$3'.
  195. EndAutoEscapeBraced -> open_tag endautoescape_keyword close_tag.
  196. BlockBlock -> BlockBraced Elements EndBlockBraced : {block, '$1', '$2'}.
  197. BlockBraced -> open_tag block_keyword identifier close_tag : '$3'.
  198. EndBlockBraced -> open_tag endblock_keyword close_tag.
  199. ExtendsTag -> open_tag extends_keyword string_literal close_tag : {extends, '$3'}.
  200. IncludeTag -> open_tag include_keyword string_literal close_tag : {include, '$3'}.
  201. NowTag -> open_tag now_keyword string_literal close_tag : {date, now, '$3'}.
  202. CommentBlock -> CommentBraced Elements EndCommentBraced : {comment, '$2'}.
  203. CommentBraced -> open_tag comment_keyword close_tag.
  204. EndCommentBraced -> open_tag endcomment_keyword close_tag.
  205. CycleTag -> open_tag cycle_keyword CycleNamesCompat close_tag : {cycle_compat, '$3'}.
  206. CycleTag -> open_tag cycle_keyword CycleNames close_tag : {cycle, '$3'}.
  207. CycleNames -> Value : ['$1'].
  208. CycleNames -> CycleNames Value : '$1' ++ ['$2'].
  209. CycleNamesCompat -> identifier ',' : ['$1'].
  210. CycleNamesCompat -> CycleNamesCompat identifier ',' : '$1' ++ ['$2'].
  211. CycleNamesCompat -> CycleNamesCompat identifier : '$1' ++ ['$2'].
  212. FilterBlock -> FilterBraced Elements EndFilterBraced : {filter, '$1', '$2'}.
  213. FilterBraced -> open_tag filter_keyword Filters close_tag : '$3'.
  214. EndFilterBraced -> open_tag endfilter_keyword close_tag.
  215. Filters -> Filter : ['$1'].
  216. Filters -> Filters '|' Filter : '$1' ++ ['$3'].
  217. FirstofTag -> open_tag firstof_keyword FirstofList close_tag : '$3'.
  218. FirstofList -> FirstofValues : {firstof, '$1'}.
  219. FirstofValues -> FirstofValues Value : ['$2'|'$1'].
  220. FirstofValues -> Value : ['$1'].
  221. ForBlock -> ForBraced Elements EndForBraced : {for, '$1', '$2'}.
  222. ForBlock -> ForBraced Elements EmptyBraced Elements EndForBraced : {for, '$1', '$2', '$4'}.
  223. EmptyBraced -> open_tag empty_keyword close_tag.
  224. ForBraced -> open_tag for_keyword ForExpression close_tag : '$3'.
  225. EndForBraced -> open_tag endfor_keyword close_tag.
  226. ForExpression -> ForGroup in_keyword Variable : {'in', '$1', '$3'}.
  227. ForGroup -> identifier : ['$1'].
  228. ForGroup -> ForGroup ',' identifier : '$1' ++ ['$3'].
  229. IfBlock -> IfBraced Elements ElseBraced Elements EndIfBraced : {ifelse, '$1', '$2', '$4'}.
  230. IfBlock -> IfBraced Elements EndIfBraced : {'if', '$1', '$2'}.
  231. IfBraced -> open_tag if_keyword IfExpression close_tag : '$3'.
  232. IfExpression -> Value in_keyword Value : {'expr', "in", '$1', '$3'}.
  233. IfExpression -> Value not_keyword in_keyword Value : {'expr', "not", {'expr', "in", '$1', '$4'}}.
  234. IfExpression -> Value '==' Value : {'expr', "eq", '$1', '$3'}.
  235. IfExpression -> Value '!=' Value : {'expr', "ne", '$1', '$3'}.
  236. IfExpression -> Value '>=' Value : {'expr', "ge", '$1', '$3'}.
  237. IfExpression -> Value '<=' Value : {'expr', "le", '$1', '$3'}.
  238. IfExpression -> Value '>' Value : {'expr', "gt", '$1', '$3'}.
  239. IfExpression -> Value '<' Value : {'expr', "lt", '$1', '$3'}.
  240. IfExpression -> '(' IfExpression ')' : '$2'.
  241. IfExpression -> Unot : '$1'.
  242. IfExpression -> IfExpression or_keyword IfExpression : {'expr', "or", '$1', '$3'}.
  243. IfExpression -> IfExpression and_keyword IfExpression : {'expr', "and", '$1', '$3'}.
  244. IfExpression -> Value : '$1'.
  245. Unot -> not_keyword IfExpression : {expr, "not", '$2'}.
  246. ElseBraced -> open_tag else_keyword close_tag.
  247. EndIfBraced -> open_tag endif_keyword close_tag.
  248. IfEqualBlock -> IfEqualBraced Elements ElseBraced Elements EndIfEqualBraced : {ifequalelse, '$1', '$2', '$4'}.
  249. IfEqualBlock -> IfEqualBraced Elements EndIfEqualBraced : {ifequal, '$1', '$2'}.
  250. IfEqualBraced -> open_tag ifequal_keyword IfEqualExpression Value close_tag : ['$3', '$4'].
  251. IfEqualExpression -> Value : '$1'.
  252. EndIfEqualBraced -> open_tag endifequal_keyword close_tag.
  253. IfNotEqualBlock -> IfNotEqualBraced Elements ElseBraced Elements EndIfNotEqualBraced : {ifnotequalelse, '$1', '$2', '$4'}.
  254. IfNotEqualBlock -> IfNotEqualBraced Elements EndIfNotEqualBraced : {ifnotequal, '$1', '$2'}.
  255. IfNotEqualBraced -> open_tag ifnotequal_keyword IfNotEqualExpression Value close_tag : ['$3', '$4'].
  256. IfNotEqualExpression -> Value : '$1'.
  257. EndIfNotEqualBraced -> open_tag endifnotequal_keyword close_tag.
  258. SpacelessBlock -> open_tag spaceless_keyword close_tag Elements open_tag endspaceless_keyword close_tag : {spaceless, '$4'}.
  259. SSITag -> open_tag ssi_keyword Value close_tag : {ssi, '$3'}.
  260. TemplatetagTag -> open_tag templatetag_keyword Templatetag close_tag : {templatetag, '$3'}.
  261. Templatetag -> openblock_keyword : '$1'.
  262. Templatetag -> closeblock_keyword : '$1'.
  263. Templatetag -> openvariable_keyword : '$1'.
  264. Templatetag -> closevariable_keyword : '$1'.
  265. Templatetag -> openbrace_keyword : '$1'.
  266. Templatetag -> closebrace_keyword : '$1'.
  267. Templatetag -> opencomment_keyword : '$1'.
  268. Templatetag -> closecomment_keyword : '$1'.
  269. TransTag -> open_tag trans_keyword string_literal close_tag : {trans, '$3'}.
  270. TransTag -> open_tag trans_keyword Variable close_tag : {trans, '$3'}.
  271. TransTag -> open_tag trans_keyword string_literal noop_keyword close_tag : '$3'.
  272. TransTag -> open_tag trans_keyword Variable noop_keyword close_tag : '$3'.
  273. WidthRatioTag -> open_tag widthratio_keyword Value Value number_literal close_tag : {widthratio, '$3', '$4', '$5'}.
  274. WithBlock -> WithBraced Elements EndWithBraced : {with, '$1', '$2'}.
  275. WithBraced -> open_tag with_keyword Args close_tag : '$3'.
  276. EndWithBraced -> open_tag endwith_keyword close_tag.
  277. Filter -> identifier : ['$1'].
  278. Filter -> identifier ':' Literal : ['$1', '$3'].
  279. Filter -> identifier ':' Variable : ['$1', '$3'].
  280. Literal -> string_literal : '$1'.
  281. Literal -> number_literal : '$1'.
  282. CustomTag -> open_tag identifier Args close_tag : {tag, '$2', '$3'}.
  283. Args -> '$empty' : [].
  284. Args -> Args identifier '=' Value : '$1' ++ [{'$2', '$4'}].
  285. CallTag -> open_tag call_keyword identifier close_tag : {call, '$3'}.
  286. CallWithTag -> open_tag call_keyword identifier with_keyword Value close_tag : {call, '$3', '$5'}.