summaryrefslogtreecommitdiff
path: root/test/nestedcomm.lm
diff options
context:
space:
mode:
Diffstat (limited to 'test/nestedcomm.lm')
-rw-r--r--test/nestedcomm.lm55
1 files changed, 55 insertions, 0 deletions
diff --git a/test/nestedcomm.lm b/test/nestedcomm.lm
new file mode 100644
index 0000000..1b1b6a4
--- /dev/null
+++ b/test/nestedcomm.lm
@@ -0,0 +1,55 @@
+##### LM #####
+#
+# Tokens
+#
+
+# Any single character can be a literal
+lex
+ # Ignore whitespace.
+ ignore /[ \t\n\r\v]+/
+
+ # Open and close id
+ token id /[a-zA-Z_][a-zA-Z0-9_]*/
+
+ token open_paren /'('/
+ {
+ parse_stop NC: nested_comment[ stdin ]
+ print( %NC '\n' )
+ input.push_ignore( NC )
+ }
+end
+
+#
+# Token translation
+#
+
+lex
+ literal `( `)
+ token nc_data /[^()]+/
+end
+
+def nc_item
+ [nc_data]
+| [nested_comment]
+
+def nested_comment
+ [`( nc_item* `)]
+
+def nested [id*]
+
+parse P: nested[ stdin ]
+
+print( ^P '\n' )
+print_xml( ^P )
+print( '\n' )
+print_xml_ac( ^P )
+print( '\n' )
+print( ^P '\n' )
+##### IN #####
+hello there ( (this is a nested comment /*sdf;asd_++_stuff) ) and this is not
+##### EXP #####
+( (this is a nested comment /*sdf;asd_++_stuff) )
+hello there ( (this is a nested comment /*sdf;asd_++_stuff) ) and this is not
+<nested><_repeat_id><id>hello</id><id>there</id><id>and</id><id>this</id><id>is</id><id>not</id></_repeat_id></nested>
+<nested><_repeat_id><id>hello</id><_ignore_0001> </_ignore_0001><id>there</id><_ignore_0001> </_ignore_0001><nested_comment><_literal_0007>(</_literal_0007><_repeat_nc_item><nc_item><nc_data> </nc_data></nc_item><nc_item><nested_comment><_literal_0007>(</_literal_0007><_repeat_nc_item><nc_item><nc_data>this is a nested comment /*sdf;asd_++_stuff</nc_data></nc_item></_repeat_nc_item><_literal_0009>)</_literal_0009></nested_comment></nc_item><nc_item><nc_data> </nc_data></nc_item></_repeat_nc_item><_literal_0009>)</_literal_0009></nested_comment><_ignore_0001> </_ignore_0001><id>and</id><_ignore_0001> </_ignore_0001><id>this</id><_ignore_0001> </_ignore_0001><id>is</id><_ignore_0001> </_ignore_0001><id>not</id></_repeat_id></nested>
+hello there ( (this is a nested comment /*sdf;asd_++_stuff) ) and this is not