]> git.ipfire.org Git - thirdparty/jinja.git/commitdiff
Add suport for line comments
authorKevin Brown <kevin@kevin-brown.com>
Fri, 8 May 2020 22:21:40 +0000 (18:21 -0400)
committerKevin <kevin@kevin-brown.com>
Sun, 10 May 2020 01:50:06 +0000 (21:50 -0400)
This also switches comments to produce the same AST whether it is
an inline comment or a line comment.

tatsu_grammar.txt
test_template.jinja

index c1a711f662dbbe21f9e9f46b255bf987fb4fd237..68e29afc118b97ec74371be8b21151a90482fc83 100644 (file)
@@ -17,6 +17,7 @@ expression
     | line_block_expression\r
     | variable_expression\r
     | comment_expression\r
+    | line_comment_expression\r
     ;\r
 \r
 raw_block_expression\r
@@ -229,7 +230,7 @@ filter_parameters
 \r
 comment_expression\r
     =\r
-    comment_open comment_content comment_close\r
+    comment_open comment:comment_content comment_close\r
     ;\r
 \r
 comment_open\r
@@ -247,6 +248,21 @@ comment_content
     { !comment_close CHAR }*\r
     ;\r
 \r
+line_comment_expression\r
+    =\r
+    line_comment_open comment:line_comment_content &"\n"\r
+    ;\r
+\r
+line_comment_open\r
+    =\r
+    "## "\r
+    ;\r
+\r
+line_comment_content\r
+    =\r
+    { !"\n" CHAR } *\r
+    ;\r
+\r
 content\r
     =\r
     !(\r
@@ -254,6 +270,7 @@ content
         | block_open\r
         | variable_open\r
         | comment_open\r
+        | line_comment_open\r
     ) CHAR ;\r
 \r
 LITERAL\r
index 57a6b6c856f069533af57d4130187fb2fe8e9e5a..df46fe8b7dc04055aee33cfd4b634cd2005fadf8 100644 (file)
@@ -35,9 +35,10 @@ across lines #}
     <textarea name="{{ name }}" rows="{{ rows }}" cols="{{ cols\r
         }}">{{ value|e }}</textarea>\r
 {% endmacro %}\r
+{# comment contents\r
+across lines #}\r
 <ul>\r
-# for href, caption in [('index.html', 'Index'),\r
-                        ('about.html', 'About')]:\r
-    <li><a href="{{ href }}">{{ caption }}</a></li>\r
+# for item in seq:\r
+    <li>{{ item }}</li>     ## this comment is ignored\r
 # endfor\r
 </ul>
\ No newline at end of file