blob: 5fbe7df6dcdab43f8b7c6b606172685d229036f9 (
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
56
57
58
59
60
61
62
63
64
65
66
|
lex
ignore /space+/
literal `# `{ `}
token id2 /[a-zA-Z_]+/
end
def item2
[id2]
| [`{ item2* `}]
def start2
[item2*]
context ctx
SP: parser<start2>
lex
ignore /space+/
literal `* `( `) `!
token semi_nl /';\n'/
token id /[a-zA-Z_]+/
end
def item
[id]
| [`( item* `)]
def A [] {
print( 'A\n' )
send SP "{ A{d} }"
}
def B [] {
print( 'B\n' )
send SP "{ B{d} }"
}
def start1
[A item* `!]
| [B item* semi_nl]
end # ctx
CTX: ctx = new ctx()
CTX->SP = new parser<start2>()
send CTX->SP "a b{c}"
parse Input: ctx::start1( CTX )[stdin]
send CTX->SP "{e}f g"
print( Input )
print( CTX->SP->finish(), '\n' )
##### IN #####
a b c ( d ) e f g ;
##### EXP #####
A
B
a b c ( d ) e f g ;
a b{c}{ B{d} }{e}f g
|