summaryrefslogtreecommitdiff
path: root/test/heredoc.lm
blob: 59ae2bd8b11686975dd7f6001ff138a75738f2c3 (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
rl ident_char /[a-zA-Z_]/

lex start
{
	# Tokens
	token other /(^(ident_char|0|'\n'))+/

	token here_close //
	token id 
		/ident_char+/
		{
			if HereId && HereId == match_text {
				input.push( make_token( 
					typeid here_close
					input.pull(match_length - 1) ) )
			}
			else {
				input.push( make_token( typeid id input.pull(match_length) ) )
			}
		}

	token nl /'\n'/
}

def here_name 
	[id]
	{
		HereId = $r1
	}

global HereId: str

def here_data 
	[here_data_item*]

def here_data_item 
	[id]
|	[other]
|	[nl]

def heredoc 
	[here_name here_data here_close id nl]


S: heredoc = parse heredoc(stdin)
print_xml(S)