summaryrefslogtreecommitdiff
path: root/test/nestedcomm.lm
blob: 1b1b6a48794920fbe326b0ff1b9c9ec1b118a332 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
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