blob: f21e36b95fc225cc64e6df12ec9ba08b86a94f66 (
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
|
##### 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 PersonTag: tag[ stdin ]
match PersonTag.tree
["<person name=" Val:id attr*">" item* "</person>"]
NameTag1: tag = construct tag
["<name type=person>" ^Val "</name>"]
NameTag2: tag = construct tag
"<name type=person>[^Val]</name>"
print( NameTag1 '\n' )
print( NameTag2 '\n' )
##### IN #####
<person name=adrian hometown=kingston>
<t1 foo=bar2 e=f></t2>
</person>
##### EXP #####
<name type=person>adrian</name>
<name type=person>adrian</name>
|