erlydtl_parser.yrl 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478
  1. %%% -*- mode: erlang -*- ------------------------------------------------------------------
  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. FilterArg
  43. AutoEscapeBlock
  44. AutoEscapeBraced
  45. EndAutoEscapeBraced
  46. BlockBlock
  47. BlockBraced
  48. EndBlockBraced
  49. CommentTag
  50. CommentBlock
  51. CommentBraced
  52. EndCommentBraced
  53. CycleAs
  54. CycleTag
  55. CycleNames
  56. CycleNamesCompat
  57. ExtendsTag
  58. IncludeTag
  59. NowTag
  60. LanguageBlock
  61. LanguageBraced
  62. EndLanguageBraced
  63. FirstofTag
  64. FilterBlock
  65. FilterBraced
  66. EndFilterBraced
  67. Filters
  68. ForBlock
  69. ForBraced
  70. EmptyBraced
  71. EndForBraced
  72. ForExpression
  73. ForGroup
  74. IfBlock
  75. IfBraced
  76. ElifBlock
  77. ElifBraced
  78. IfExpression
  79. ElseBraced
  80. EndIfBraced
  81. IfChangedBlock
  82. IfChangedBraced
  83. EndIfChangedBraced
  84. IfEqualBlock
  85. IfEqualBraced
  86. IfEqualExpression
  87. EndIfEqualBraced
  88. IfNotEqualBlock
  89. IfNotEqualBraced
  90. IfNotEqualExpression
  91. EndIfNotEqualBraced
  92. CustomTag
  93. CustomArgs
  94. Arg
  95. Args
  96. RegroupTag
  97. SpacelessBlock
  98. SSITag
  99. BlockTransBlock
  100. BlockTransBraced
  101. EndBlockTransBraced
  102. BlockTransArgs
  103. BlockTransContents
  104. PluralTag
  105. TransTag
  106. TransArgs
  107. TransText
  108. TransValue
  109. TemplatetagTag
  110. Templatetag
  111. WidthRatioTag
  112. WithBlock
  113. WithBraced
  114. EndWithBraced
  115. CallTag
  116. CallWithTag
  117. LoadTag
  118. LoadArgs
  119. Unot.
  120. Terminals
  121. and_keyword
  122. as_keyword
  123. autoescape_keyword
  124. block_keyword
  125. blocktrans_keyword
  126. by_keyword
  127. call_keyword
  128. close_tag
  129. close_var
  130. comment_tag
  131. comment_keyword
  132. context_keyword
  133. count_keyword
  134. cycle_keyword
  135. elif_keyword
  136. else_keyword
  137. empty_keyword
  138. endautoescape_keyword
  139. endblock_keyword
  140. endblocktrans_keyword
  141. endcomment_keyword
  142. endfilter_keyword
  143. endfor_keyword
  144. endif_keyword
  145. endifchanged_keyword
  146. endifequal_keyword
  147. endifnotequal_keyword
  148. endlanguage_keyword
  149. endregroup_keyword
  150. endspaceless_keyword
  151. endwith_keyword
  152. extends_keyword
  153. filter_keyword
  154. firstof_keyword
  155. for_keyword
  156. from_keyword
  157. identifier
  158. if_keyword
  159. ifchanged_keyword
  160. ifequal_keyword
  161. ifnotequal_keyword
  162. in_keyword
  163. include_keyword
  164. language_keyword
  165. load_keyword
  166. noop_keyword
  167. not_keyword
  168. now_keyword
  169. number_literal
  170. only_keyword
  171. or_keyword
  172. open_tag
  173. open_var
  174. parsed_keyword
  175. plural_keyword
  176. regroup_keyword
  177. reversed_keyword
  178. silent_keyword
  179. spaceless_keyword
  180. ssi_keyword
  181. string_literal
  182. string
  183. templatetag_keyword
  184. openblock_keyword
  185. closeblock_keyword
  186. openvariable_keyword
  187. closevariable_keyword
  188. openbrace_keyword
  189. closebrace_keyword
  190. opencomment_keyword
  191. closecomment_keyword
  192. trans_keyword
  193. widthratio_keyword
  194. with_keyword
  195. ',' '|' '=' ':' '.'
  196. '==' '!='
  197. '>=' '<='
  198. '>' '<'
  199. '(' ')'
  200. '_'.
  201. Rootsymbol
  202. Elements.
  203. %% Operator precedences for the E non terminal
  204. Left 100 or_keyword.
  205. Left 110 and_keyword.
  206. Nonassoc 300 '==' '!=' '>=' '<=' '>' '<'.
  207. Unary 600 Unot.
  208. Elements -> '$empty' : [].
  209. Elements -> Elements string : '$1' ++ ['$2'].
  210. Elements -> Elements AutoEscapeBlock : '$1' ++ ['$2'].
  211. Elements -> Elements BlockBlock : '$1' ++ ['$2'].
  212. Elements -> Elements BlockTransBlock : '$1' ++ ['$2'].
  213. Elements -> Elements CallTag : '$1' ++ ['$2'].
  214. Elements -> Elements CallWithTag : '$1' ++ ['$2'].
  215. Elements -> Elements CommentBlock : '$1' ++ ['$2'].
  216. Elements -> Elements CommentTag : '$1' ++ ['$2'].
  217. Elements -> Elements CustomTag : '$1' ++ ['$2'].
  218. Elements -> Elements CycleTag : '$1' ++ ['$2'].
  219. Elements -> Elements ExtendsTag : '$1' ++ ['$2'].
  220. Elements -> Elements FilterBlock : '$1' ++ ['$2'].
  221. Elements -> Elements FirstofTag : '$1' ++ ['$2'].
  222. Elements -> Elements ForBlock : '$1' ++ ['$2'].
  223. Elements -> Elements IfBlock : '$1' ++ ['$2'].
  224. Elements -> Elements IfEqualBlock : '$1' ++ ['$2'].
  225. Elements -> Elements IfNotEqualBlock : '$1' ++ ['$2'].
  226. Elements -> Elements IfChangedBlock : '$1' ++ ['$2'].
  227. Elements -> Elements IncludeTag : '$1' ++ ['$2'].
  228. Elements -> Elements LanguageBlock : '$1' ++ ['$2'].
  229. Elements -> Elements LoadTag : '$1' ++ ['$2'].
  230. Elements -> Elements NowTag : '$1' ++ ['$2'].
  231. Elements -> Elements RegroupTag : '$1' ++ ['$2'].
  232. Elements -> Elements SpacelessBlock : '$1' ++ ['$2'].
  233. Elements -> Elements SSITag : '$1' ++ ['$2'].
  234. Elements -> Elements TemplatetagTag : '$1' ++ ['$2'].
  235. Elements -> Elements TransTag : '$1' ++ ['$2'].
  236. Elements -> Elements ValueBraced : '$1' ++ ['$2'].
  237. Elements -> Elements WidthRatioTag : '$1' ++ ['$2'].
  238. Elements -> Elements WithBlock : '$1' ++ ['$2'].
  239. ValueBraced -> open_var Value close_var : '$2'.
  240. Value -> Value '|' Filter : {apply_filter, '$1', '$3'}.
  241. Value -> '_' '(' Value ')' : {trans, '$3'}.
  242. Value -> Variable : '$1'.
  243. Value -> Literal : '$1'.
  244. Values -> Value : ['$1'].
  245. Values -> Value Values : ['$1'|'$2'].
  246. Filter -> identifier FilterArg : {'$1', '$2'}.
  247. FilterArg -> '$empty' : [].
  248. FilterArg -> ':' Variable : ['$2'].
  249. FilterArg -> ':' Literal : ['$2'].
  250. Variable -> identifier : {variable, '$1'}.
  251. Variable -> Variable '.' identifier : {attribute, {'$3', '$1'}}.
  252. Variable -> Variable '.' Literal : {attribute, {'$3', '$1'}}.
  253. Literal -> string_literal : '$1'.
  254. Literal -> number_literal : '$1'.
  255. AutoEscapeBlock -> AutoEscapeBraced Elements EndAutoEscapeBraced : {autoescape, '$1', '$2'}.
  256. AutoEscapeBraced -> open_tag autoescape_keyword identifier close_tag : '$3'.
  257. EndAutoEscapeBraced -> open_tag endautoescape_keyword close_tag.
  258. BlockBlock -> BlockBraced Elements EndBlockBraced : {block, '$1', '$2'}.
  259. BlockBraced -> open_tag block_keyword identifier close_tag : '$3'.
  260. EndBlockBraced -> open_tag endblock_keyword close_tag.
  261. LanguageBlock -> LanguageBraced Elements EndLanguageBraced : {language, '$1', '$2'}.
  262. LanguageBraced -> open_tag language_keyword Value close_tag : '$3'.
  263. EndLanguageBraced -> open_tag endlanguage_keyword close_tag.
  264. ExtendsTag -> open_tag extends_keyword string_literal close_tag : {extends, '$3'}.
  265. IncludeTag -> open_tag include_keyword string_literal close_tag : {include, '$3', []}.
  266. IncludeTag -> open_tag include_keyword string_literal with_keyword Args close_tag : {include, '$3', '$5'}.
  267. IncludeTag -> open_tag include_keyword string_literal only_keyword close_tag : {include_only, '$3', []}.
  268. IncludeTag -> open_tag include_keyword string_literal with_keyword Args only_keyword close_tag : {include_only, '$3', '$5'}.
  269. LoadTag -> open_tag load_keyword LoadArgs close_tag : {load_libs, '$3'}.
  270. LoadTag -> open_tag load_keyword LoadArgs from_keyword identifier close_tag : {load_from_lib, '$3', '$5'}.
  271. LoadArgs -> '$empty' : [].
  272. LoadArgs -> identifier LoadArgs : ['$1'|'$2'].
  273. NowTag -> open_tag now_keyword string_literal close_tag : {date, now, '$3'}.
  274. CommentBlock -> CommentBraced Elements EndCommentBraced : {comment, '$2'}.
  275. CommentBraced -> open_tag comment_keyword close_tag.
  276. EndCommentBraced -> open_tag endcomment_keyword close_tag.
  277. CommentTag -> comment_tag : '$1'.
  278. CycleTag -> open_tag cycle_keyword CycleNamesCompat close_tag : {cycle_compat, '$3'}.
  279. CycleTag -> open_tag cycle_keyword CycleNames CycleAs close_tag : {cycle, '$3', '$4'}.
  280. CycleNames -> Value : ['$1'].
  281. CycleNames -> CycleNames Value : '$1' ++ ['$2'].
  282. CycleAs -> '$empty' : undefined.
  283. CycleAs -> as_keyword identifier : ['$2'].
  284. CycleAs -> as_keyword identifier silent_keyword : ['$2', silent].
  285. CycleNamesCompat -> identifier ',' : ['$1'].
  286. CycleNamesCompat -> CycleNamesCompat identifier ',' : '$1' ++ ['$2'].
  287. CycleNamesCompat -> CycleNamesCompat identifier : '$1' ++ ['$2'].
  288. FilterBlock -> FilterBraced Elements EndFilterBraced : {filter, '$1', '$2'}.
  289. FilterBraced -> open_tag filter_keyword Filters close_tag : '$3'.
  290. EndFilterBraced -> open_tag endfilter_keyword close_tag.
  291. Filters -> Filter : ['$1'].
  292. Filters -> Filter '|' Filters : ['$1'|'$3'].
  293. FirstofTag -> open_tag firstof_keyword Values close_tag : {firstof, '$3'}.
  294. ForBlock -> ForBraced Elements EndForBraced : {for, '$1', '$2'}.
  295. ForBlock -> ForBraced Elements EmptyBraced Elements EndForBraced : {for, '$1', '$2', '$4'}.
  296. EmptyBraced -> open_tag empty_keyword close_tag.
  297. ForBraced -> open_tag for_keyword ForExpression close_tag : '$3'.
  298. EndForBraced -> open_tag endfor_keyword close_tag.
  299. ForExpression -> ForGroup in_keyword Value : {'in', '$1', '$3', false}.
  300. ForExpression -> ForGroup in_keyword Value reversed_keyword : {'in', '$1', '$3', true}.
  301. ForGroup -> identifier : ['$1'].
  302. ForGroup -> ForGroup ',' identifier : '$1' ++ ['$3'].
  303. IfBlock -> IfBraced Elements ElseBraced Elements EndIfBraced : {'ifelse', '$1', '$2', '$4'}.
  304. IfBlock -> IfBraced Elements EndIfBraced : {'if', '$1', '$2'}.
  305. IfBlock -> IfBraced Elements ElifBlock : {'if', '$1', '$2', ['$3']}.
  306. ElifBlock -> ElifBraced Elements ElseBraced Elements EndIfBraced : {'ifelse', '$1', '$2', '$4'}.
  307. ElifBlock -> ElifBraced Elements EndIfBraced : {'if', '$1', '$2'}.
  308. ElifBlock -> ElifBraced Elements ElifBlock : {'if', '$1', '$2', ['$3']}.
  309. IfBraced -> open_tag if_keyword IfExpression close_tag : '$3'.
  310. ElifBraced -> open_tag elif_keyword IfExpression close_tag : '$3'.
  311. IfExpression -> Value in_keyword Value : {'expr', "in", '$1', '$3'}.
  312. IfExpression -> Value not_keyword in_keyword Value : {'expr', "not", {'expr', "in", '$1', '$4'}}.
  313. IfExpression -> Value '==' Value : {'expr', "eq", '$1', '$3'}.
  314. IfExpression -> Value '!=' Value : {'expr', "ne", '$1', '$3'}.
  315. IfExpression -> Value '>=' Value : {'expr', "ge", '$1', '$3'}.
  316. IfExpression -> Value '<=' Value : {'expr', "le", '$1', '$3'}.
  317. IfExpression -> Value '>' Value : {'expr', "gt", '$1', '$3'}.
  318. IfExpression -> Value '<' Value : {'expr', "lt", '$1', '$3'}.
  319. IfExpression -> '(' IfExpression ')' : '$2'.
  320. IfExpression -> Unot : '$1'.
  321. IfExpression -> IfExpression or_keyword IfExpression : {'expr', "or", '$1', '$3'}.
  322. IfExpression -> IfExpression and_keyword IfExpression : {'expr', "and", '$1', '$3'}.
  323. IfExpression -> Value : '$1'.
  324. Unot -> not_keyword IfExpression : {expr, "not", '$2'}.
  325. ElseBraced -> open_tag else_keyword close_tag.
  326. EndIfBraced -> open_tag endif_keyword close_tag.
  327. IfChangedBlock -> IfChangedBraced Elements ElseBraced Elements EndIfChangedBraced : {ifchangedelse, '$1', '$2', '$4'}.
  328. IfChangedBlock -> IfChangedBraced Elements EndIfChangedBraced : {ifchanged, '$1', '$2'}.
  329. IfChangedBraced -> open_tag ifchanged_keyword close_tag.
  330. IfChangedBraced -> open_tag ifchanged_keyword Values close_tag : '$3'.
  331. EndIfChangedBraced -> open_tag endifchanged_keyword close_tag.
  332. IfEqualBlock -> IfEqualBraced Elements ElseBraced Elements EndIfEqualBraced : {ifequalelse, '$1', '$2', '$4'}.
  333. IfEqualBlock -> IfEqualBraced Elements EndIfEqualBraced : {ifequal, '$1', '$2'}.
  334. IfEqualBraced -> open_tag ifequal_keyword IfEqualExpression Value close_tag : ['$3', '$4'].
  335. IfEqualExpression -> Value : '$1'.
  336. EndIfEqualBraced -> open_tag endifequal_keyword close_tag.
  337. IfNotEqualBlock -> IfNotEqualBraced Elements ElseBraced Elements EndIfNotEqualBraced : {ifnotequalelse, '$1', '$2', '$4'}.
  338. IfNotEqualBlock -> IfNotEqualBraced Elements EndIfNotEqualBraced : {ifnotequal, '$1', '$2'}.
  339. IfNotEqualBraced -> open_tag ifnotequal_keyword IfNotEqualExpression Value close_tag : ['$3', '$4'].
  340. IfNotEqualExpression -> Value : '$1'.
  341. EndIfNotEqualBraced -> open_tag endifnotequal_keyword close_tag.
  342. RegroupTag -> open_tag regroup_keyword Value by_keyword Value as_keyword identifier close_tag : {regroup, {'$3', '$5', '$7'}}.
  343. RegroupTag -> open_tag endregroup_keyword close_tag : end_regroup.
  344. SpacelessBlock -> open_tag spaceless_keyword close_tag Elements open_tag endspaceless_keyword close_tag : {spaceless, '$4'}.
  345. SSITag -> open_tag ssi_keyword Value close_tag : {ssi, '$3'}.
  346. SSITag -> open_tag ssi_keyword string_literal parsed_keyword close_tag : {ssi_parsed, '$3'}.
  347. BlockTransBlock -> BlockTransBraced BlockTransContents EndBlockTransBraced : {blocktrans, '$1', '$2', undefined}.
  348. BlockTransBlock -> BlockTransBraced BlockTransContents PluralTag BlockTransContents EndBlockTransBraced : {blocktrans, '$1', '$2', '$4'}.
  349. BlockTransBraced -> open_tag blocktrans_keyword BlockTransArgs close_tag : '$3'.
  350. EndBlockTransBraced -> open_tag endblocktrans_keyword close_tag.
  351. BlockTransArgs -> '$empty' : [].
  352. BlockTransArgs -> count_keyword Arg BlockTransArgs : [{count, '$2'}|'$3'].
  353. BlockTransArgs -> with_keyword Args BlockTransArgs : [{args, '$2'}|'$3'].
  354. BlockTransArgs -> context_keyword string_literal BlockTransArgs : [{context, '$2'}|'$3'].
  355. BlockTransContents -> '$empty' : [].
  356. BlockTransContents -> open_var identifier close_var BlockTransContents : [{variable, '$2'}|'$4'].
  357. BlockTransContents -> string BlockTransContents : ['$1'|'$2'].
  358. PluralTag -> open_tag plural_keyword close_tag.
  359. TemplatetagTag -> open_tag templatetag_keyword Templatetag close_tag : {templatetag, '$3'}.
  360. Templatetag -> openblock_keyword : '$1'.
  361. Templatetag -> closeblock_keyword : '$1'.
  362. Templatetag -> openvariable_keyword : '$1'.
  363. Templatetag -> closevariable_keyword : '$1'.
  364. Templatetag -> openbrace_keyword : '$1'.
  365. Templatetag -> closebrace_keyword : '$1'.
  366. Templatetag -> opencomment_keyword : '$1'.
  367. Templatetag -> closecomment_keyword : '$1'.
  368. TransTag -> open_tag trans_keyword TransArgs close_tag : '$3'.
  369. TransTag -> open_tag trans_keyword TransArgs as_keyword identifier close_tag : {scope_as, '$5', ['$3']}.
  370. TransArgs -> TransText : {trans, '$1'}.
  371. TransArgs -> TransText context_keyword string_literal: {trans, '$1', '$3'}.
  372. TransText -> TransValue : '$1'.
  373. TransText -> TransValue noop_keyword : {noop, '$1'}.
  374. TransValue -> string_literal : '$1'.
  375. TransValue -> Variable : '$1'.
  376. WidthRatioTag -> open_tag widthratio_keyword Value Value number_literal close_tag : {widthratio, '$3', '$4', '$5'}.
  377. WithBlock -> WithBraced Elements EndWithBraced : {with, '$1', '$2'}.
  378. WithBraced -> open_tag with_keyword Args close_tag : '$3'.
  379. EndWithBraced -> open_tag endwith_keyword close_tag.
  380. CustomTag -> open_tag identifier CustomArgs close_tag : {tag, '$2', '$3'}.
  381. CustomTag -> open_tag identifier CustomArgs as_keyword identifier close_tag : {tag, '$2', '$3', '$5'}.
  382. CustomArgs -> '$empty' : [].
  383. CustomArgs -> identifier '=' Value CustomArgs : [{'$1', '$3'}|'$4'].
  384. CustomArgs -> Value CustomArgs : ['$1'|'$2'].
  385. Args -> '$empty' : [].
  386. Args -> Arg Args : ['$1'|'$2'].
  387. Arg -> identifier '=' Value : {'$1', '$3'}.
  388. %% Arg -> identifier : {'$1', true}.
  389. CallTag -> open_tag call_keyword identifier close_tag : {call, '$3'}.
  390. CallWithTag -> open_tag call_keyword identifier with_keyword Value close_tag : {call, '$3', '$5'}.
  391. Erlang code.
  392. %% vim: syntax=erlang