blob: d56c60df8940397794d2f541a77a95444376f3db (
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
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
|
lex
token func_chr /[^{}]+/
token func_open /'{'/
token func_close /'}'/
end
def func_item
[func_chr]
| [func_open func_body func_close]
def func_body
[func_item*]
def func
[ident `( `) `{ func_body func_close ]
lex
token ident /[a-zA-Z_]+/
token number /[0-9]+/
rl s_string / "'" ([^'\\\n] | '\\' any )* "'" /
rl d_string / '"' ([^"\\\n] | '\\' any )* '"' /
token string /s_string | d_string/
literal `+ `* `; `( `) `{ `}
ignore wp / [ \t\n]+ /
end
def class_item
[func]
| [class]
| [ident `;]
| [number `;]
| [string `;]
def class_body
[class_item*]
def class
[ident `{ class_body `} ]
def top_item
[func]
| [class]
def start
[top_item*]
parse S: start[ stdin ]
print_xml( S )
print( '\n' )
#pattern start
# ~class { func() { func() { 1+{2}} } } func() {{a}}
##### IN #####
class
{
1;
"string";
foo;
func()
{
func()
{
1+{2}
}
}
}
func()
{
"data"
{a}
}
##### EXP #####
<start><_repeat_top_item><top_item><class><ident>class</ident><_literal_0017>{</_literal_0017><class_body><_repeat_class_item><class_item><number>1</number><_literal_0011>;</_literal_0011></class_item><class_item><string>"string"</string><_literal_0011>;</_literal_0011></class_item><class_item><ident>foo</ident><_literal_0011>;</_literal_0011></class_item><class_item><func><ident>func</ident><_literal_0013>(</_literal_0013><_literal_0015>)</_literal_0015><_literal_0017>{</_literal_0017><func_body><_repeat_func_item><func_item><func_chr>func()
</func_chr></func_item><func_item><func_open>{</func_open><func_body><_repeat_func_item><func_item><func_chr>
1+</func_chr></func_item><func_item><func_open>{</func_open><func_body><_repeat_func_item><func_item><func_chr>2</func_chr></func_item></_repeat_func_item></func_body><func_close>}</func_close></func_item><func_item><func_chr>
</func_chr></func_item></_repeat_func_item></func_body><func_close>}</func_close></func_item><func_item><func_chr>
</func_chr></func_item></_repeat_func_item></func_body><func_close>}</func_close></func></class_item></_repeat_class_item></class_body><_literal_0019>}</_literal_0019></class></top_item><top_item><func><ident>func</ident><_literal_0013>(</_literal_0013><_literal_0015>)</_literal_0015><_literal_0017>{</_literal_0017><func_body><_repeat_func_item><func_item><func_chr>"data"
</func_chr></func_item><func_item><func_open>{</func_open><func_body><_repeat_func_item><func_item><func_chr>a</func_chr></func_item></_repeat_func_item></func_body><func_close>}</func_close></func_item><func_item><func_chr>
</func_chr></func_item></_repeat_func_item></func_body><func_close>}</func_close></func></top_item></_repeat_top_item></start>
|