summaryrefslogtreecommitdiff
path: root/test/translate2.lm
blob: 47bda35d75c730c41c9f4aaffa33b49e497459cf (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
##### LM #####
lex
	ignore /space+/
	literal `# `{ `}
	token id2 /[a-zA-Z_]+/ 
end

def item2
	[id2]
|	[`{ item2* `}]

def start2
	[item2*]

context ctx

	lex
		ignore /space+/
		literal `* `( `) `!
		token SEMI_NL /';\n'/
		token id /[a-zA-Z_0-9]+/ 

		token ddd /'...'/ {
			print('translating\n')
			input.pull( match_length )
			input.push( make_token( typeid<id> "dot" ) )
			input.push( make_token( typeid<id> "dot" ) )
			input.push( make_token( typeid<id> "dot" ) )
		}
	end

	def item 
		[id]
	|	[`( item* `)]

	def A [] {
		print( 'A\n' )
	}

	def B [] {
		print( 'B\n' )
	}
	

	def start 
		[A item* `!]
	|	[B item* SEMI_NL]

end # ctx

CTX: ctx = cons ctx []
parse Input: ctx::start( CTX ) [ stdin ]
print( Input )

##### IN #####
a b c ( d1 ... d2 ) e f g ;
##### EXP #####
A
translating
B
translating
a b c ( d1 dotdotdot d2 ) e f g ;