summaryrefslogtreecommitdiff
path: root/test/string.lm
blob: ea41cb23c5fe39086c0c1797ff6bfa99b6e7686a (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
##### LM #####
lex
	token str_escape /'\\' any/
	token str_chr /[^\\"]+/
end

def str_item 
	[str_escape]
|	[str_chr]

def string 
	[`" str_item* `"]

lex
	token ident /[a-zA-Z_]+/
	token number /[0-9]+/

	literal `+ `* `; `" `' `( `)
	literal `+= `-= `*=

	ignore wp /[ \t\n]+/
end

def expr 
	[expr `+ term]
|	[term]

def term 
	[term `* primary]
|	[primary]

def primary 
	[number]
|	[ident]
|	[string]
|	[`( expr `)]

def expr_list 
	[expr_list expr `;]
|	[]

def start 
	[expr_list]
	{
		if match lhs 
			~a + "%{{"; 1 * 2;
		{
			print( 'yes\n' )
		}
	}

parse S: start[stdin]
print_xml( S )
print( '\n' )
##### IN #####
a + "%{{"; 1 * 2;

##### EXP #####
yes
<start><expr_list><expr_list><expr_list></expr_list><expr><expr><term><primary><ident>a</ident></primary></term></expr><_literal_0009>+</_literal_0009><term><primary><string><_literal_000f>"</_literal_000f><_repeat_str_item><str_item><str_chr>%{{</str_chr></str_item></_repeat_str_item><_literal_000f>"</_literal_000f></string></primary></term></expr><_literal_000d>;</_literal_000d></expr_list><expr><term><term><primary><number>1</number></primary></term><_literal_000b>*</_literal_000b><primary><number>2</number></primary></term></expr><_literal_000d>;</_literal_000d></expr_list></start>