blob: 77d56f555deebf7e358be2f64e7063968639ad32 (
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 #####
# Token names.
lex
token number /[0-9]+/
token id /[a-z]+/
token string /'"' [^"]* '"'/
ignore ws / [ \t\n]+ /
end
def prefix [id]
def choice1
[number number]
| [number]
def choice2
[string id]
| [number number]
| [id number]
| [number]
def start
[prefix choice1 choice2 string id id]
cons I: parser<start> []
send I " id "
send I " 77 "
send I " 88 "
send I " \"hello\" "
send I " dude "
send I " dude\n"
S: start = I()
S = match S
~id 77 88 "hello" dude dude
print_xml( S )
print( '\n' )
##### EXP #####
<start><prefix><id>id</id></prefix><choice1><number>77</number></choice1><choice2><number>88</number></choice2><string>"hello"</string><id>dude</id><id>dude</id></start>
|