summaryrefslogtreecommitdiff
path: root/test/colm.d/btscan2.lm
blob: bce516f2d295792fd4498e6650fad43d6ee3f2ef (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
namespace r1

	lex
		literal `! `a `b
		ignore /[ \n\t]+/
	end

	def line [ `! `a `b `b `a]

end # r1

namespace r2

	lex
		literal `!
		token id /[a-zA-Z_]+/
		ignore /[ \n\t]+/
	end

	def line [ `! id ]

end # r2

def item 
	[r1::line]
|	[r2::line]

def btscan 
	[item*]

Parser: parser<btscan> = new parser<btscan>()

send Parser "!ab"
send Parser "b "
send Parser "!ab"
send Parser "ba !aab\n"

print( xml( Parser->finish() ) )
print( '\n' )
##### EXP #####
<btscan><_repeat_item><item><r2::line><r2::_literal_0009>!</r2::_literal_0009><r2::id>abb</r2::id></r2::line></item><item><r1::line><r1::_literal_0001>!</r1::_literal_0001><r1::_literal_0003>a</r1::_literal_0003><r1::_literal_0005>b</r1::_literal_0005><r1::_literal_0005>b</r1::_literal_0005><r1::_literal_0003>a</r1::_literal_0003></r1::line></item><item><r2::line><r2::_literal_0009>!</r2::_literal_0009><r2::id>aab</r2::id></r2::line></item></_repeat_item></btscan>