diff options
Diffstat (limited to 'test/nestedcomm.lm')
-rw-r--r-- | test/nestedcomm.lm | 41 |
1 files changed, 41 insertions, 0 deletions
diff --git a/test/nestedcomm.lm b/test/nestedcomm.lm new file mode 100644 index 00000000..cc28726e --- /dev/null +++ b/test/nestedcomm.lm @@ -0,0 +1,41 @@ +# +# Tokens +# + +# Any single character can be a literal +lex start +{ + # Ignore whitespace. + ignore /[ \t\n\r\v]+/ + + # Open and close id + token id /[a-zA-Z_][a-zA-Z0-9_]*/ + + token open_paren /'('/ + { + send_ignore( parse_stop nested_comment( stdin ) ) + } +} + +# +# Token translation +# + +lex nc_scan +{ + literal '(', ')' + token nc_data /[^()]+/ +} + +def nc_item + [nc_data] +| [nested_comment] + +def nested_comment + ['(' nc_item* ')'] + +def nested [id*] + +nested P = parse nested( stdin ) +print_xml( P ) +print( P, '\n' ) |