erlydtl_extension_testparser.yrl 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153
  1. %%% -*- mode: erlang -*- ------------------------------------------------------------------
  2. %%% File: erlydtl_parser.erl
  3. %%% @author Andreas Stenius <kaos@astekk.se>
  4. %%% @copyright 2013 Andreas Stenius
  5. %%% @doc Sample extension grammar
  6. %%% @reference See <a href="http://erlydtl.googlecode.com" target="_top">http://erlydtl.googlecode.com</a> for more information
  7. %%% @end
  8. %%%
  9. %%% The MIT License
  10. %%%
  11. %%% Copyright (c) 2013 Andreas Stenius
  12. %%%
  13. %%% Permission is hereby granted, free of charge, to any person obtaining a copy
  14. %%% of this software and associated documentation files (the "Software"), to deal
  15. %%% in the Software without restriction, including without limitation the rights
  16. %%% to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  17. %%% copies of the Software, and to permit persons to whom the Software is
  18. %%% furnished to do so, subject to the following conditions:
  19. %%%
  20. %%% The above copyright notice and this permission notice shall be included in
  21. %%% all copies or substantial portions of the Software.
  22. %%%
  23. %%% THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  24. %%% IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  25. %%% FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  26. %%% AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  27. %%% LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  28. %%% OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
  29. %%% THE SOFTWARE.
  30. %%%
  31. %%% @since 2013-06-20 by Andreas Stenius
  32. %%%-------------------------------------------------------------------
  33. Nonterminals
  34. Extensions
  35. Literal
  36. ValueExpressionBraced
  37. ValueExpression
  38. Value
  39. Variable
  40. .
  41. Terminals
  42. %% "new" terminals that are partially parsed tokens from the erlydtl parser:
  43. variable
  44. %% standard scanner tokens:
  45. %% and_keyword
  46. %% as_keyword
  47. %% autoescape_keyword
  48. %% block_keyword
  49. %% blocktrans_keyword
  50. %% by_keyword
  51. %% call_keyword
  52. %% close_tag
  53. close_var
  54. %% comment_keyword
  55. %% cycle_keyword
  56. %% elif_keyword
  57. %% else_keyword
  58. %% empty_keyword
  59. %% endautoescape_keyword
  60. %% endblock_keyword
  61. %% endblocktrans_keyword
  62. %% endcomment_keyword
  63. %% endfilter_keyword
  64. %% endfor_keyword
  65. %% endif_keyword
  66. %% endifchanged_keyword
  67. %% endifequal_keyword
  68. %% endifnotequal_keyword
  69. %% endregroup_keyword
  70. %% endspaceless_keyword
  71. %% endwith_keyword
  72. %% extends_keyword
  73. %% filter_keyword
  74. %% firstof_keyword
  75. %% for_keyword
  76. identifier
  77. %% if_keyword
  78. %% ifchanged_keyword
  79. %% ifequal_keyword
  80. %% ifnotequal_keyword
  81. %% in_keyword
  82. %% include_keyword
  83. %% noop_keyword
  84. %% not_keyword
  85. %% now_keyword
  86. number_literal
  87. %% only_keyword
  88. or_keyword
  89. %% open_tag
  90. open_var
  91. %% parsed_keyword
  92. %% regroup_keyword
  93. %% reversed_keyword
  94. %% spaceless_keyword
  95. %% ssi_keyword
  96. string_literal
  97. %% string
  98. %% templatetag_keyword
  99. %% openblock_keyword
  100. %% closeblock_keyword
  101. %% openvariable_keyword
  102. %% closevariable_keyword
  103. %% openbrace_keyword
  104. %% closebrace_keyword
  105. %% opencomment_keyword
  106. %% closecomment_keyword
  107. %% trans_keyword
  108. %% widthratio_keyword
  109. %% with_keyword
  110. %% ',' '|' '=' ':'
  111. '.'
  112. %% '==' '!='
  113. %% '>=' '<='
  114. %% '>' '<'
  115. %% '(' ')'
  116. %% '_'
  117. .
  118. Rootsymbol
  119. Extensions.
  120. %% Operator precedences for the E non terminal
  121. Left 100 or_keyword.
  122. %Left 110 and_keyword.
  123. %Nonassoc 300 '==' '!=' '>=' '<=' '>' '<'.
  124. %Unary 600 Unot.
  125. Extensions -> ValueExpressionBraced : ['$1'].
  126. ValueExpressionBraced -> open_var ValueExpression close_var : '$2'.
  127. ValueExpression -> Value or_keyword Value : {extension, {value_or, {'$1', '$3'}}}.
  128. %Value -> Value '|' Filter : {apply_filter, '$1', '$3'}.
  129. %Value -> '_' '(' Value ')' : {trans, '$3'}.
  130. Value -> Variable : '$1'.
  131. Value -> Literal : '$1'.
  132. Variable -> identifier : {variable, '$1'}.
  133. Variable -> variable : '$1'.
  134. Variable -> Variable '.' identifier : {attribute, {'$3', '$1'}}.
  135. Literal -> string_literal : '$1'.
  136. Literal -> number_literal : '$1'.
  137. %% vim: syntax=erlang