summaryrefslogtreecommitdiff
path: root/test/colm.d/undofrag3.lm
blob: 47ca79739220c92bdfecfb5f120392632ee47278 (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
context undo

	lex
		ignore /( ' ' | '\t' )+/
		literal `* `( `) `^ `; `.
		token NL /'\n'/
		token id /[a-zA-Z_]+/
	end

	Out: parser<out>

	def out_item
		[id]
	|	[`( item* `)]

	def out 
		[out_item*]

	def item 
		[id]
		{
			send Out [r1]
		}
	|	[`( item* `)]
		{
			send Out ['(']
			send Out [r2]
			send Out [')']
		}

	def A1 []
	def A2 []

	def F
		[]
		{
			print( xml( Out->finish() ) )
		}

	def start 
		[A1 item* F `. `^]
	|	[A2 item* F `. `; NL]

end # undo

Undo: undo = new undo()
Undo->Out = new parser<undo::out>( Undo )

parse Input: undo::start( Undo )[ stdin ]
print( Input )

##### IN #####
a . ;
##### EXP #####
<undo::out><undo::_repeat_out_item><undo::out_item><undo::id>a</undo::id></undo::out_item></undo::_repeat_out_item></undo::out><undo::out><undo::_repeat_out_item><undo::out_item><undo::id>a</undo::id></undo::out_item></undo::_repeat_out_item></undo::out>a . ;