summaryrefslogtreecommitdiff
path: root/test/matchex.lm
blob: 9dd24c4d72caaf9497badba28fabde590308c5bb (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
##### LM #####
lex
	token id /[a-zA-Z_][a-zA-Z0-9_]*/
	literal `= `< `> `/
	ignore /[ \t\n\r\v]+/
end

def attr 
	[id `= id]

def open_tag 
	[`< id attr* `>]

def close_tag
	[`< `/ id `>]

def tag 
	[open_tag item* close_tag]

def item
	[tag]
|	[id]

parse Tag: tag[ stdin ]

# Style: List of literal text and types.
match Tag ["<person name=" Val1:id attr*">" item* "</person>"]

# Style: Literal text with embedded lists of types.
match Tag "<person name=[Val2:id attr*]>[item*]</person>"

print( ^Val1 '\n' )
print( ^Val2 '\n' )

##### IN #####
<person name=adrian hometown=kingston>
	<t1 foo=bar2 e=f></t2>
</person>
##### EXP #####
adrian
adrian