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

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

def start2
	[item2*]

context ctx
{
	lex
		ignore /space+/
		literal '*', '(', ')', '!', ';\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* ';\n']
}

CTX: ctx = cons ctx []
parse InputP: ctx::start( CTX ) [ stdin ]
Input: ctx::start = InputP.tree

print( Input )