##### 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
<_repeat_id>hellothereandthisisnot
<_repeat_id>hello<_ignore_0001> there<_ignore_0001> <_literal_0007>(<_repeat_nc_item> <_literal_0007>(<_repeat_nc_item>this is a nested comment /*sdf;asd_++_stuff<_literal_0009>) <_literal_0009>)<_ignore_0001> and<_ignore_0001> this<_ignore_0001> is<_ignore_0001> not
hello there ( (this is a nested comment /*sdf;asd_++_stuff) ) and this is not