File: make_visitor.py

package info (click to toggle)
jython 2.2.1-2
  • links: PTS
  • area: main
  • in suites: lenny
  • size: 18,708 kB
  • ctags: 46,200
  • sloc: python: 150,937; java: 86,267; xml: 1,080; perl: 104; sh: 93; makefile: 81; ansic: 24
file content (42 lines) | stat: -rw-r--r-- 810 bytes parent folder | download | duplicates (12)
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
"""generate vistor code for javacc grammar.  code goes in SimpleNode.java"""

import string

file = "c:\\jpython\\JavaCode\\org\\python\\parser\\PythonGrammarTreeConstants.java"

fp = open(file, "r")
lines = fp.readlines()
fp.close()

names = []

in_names = 0
for line in lines:
	if in_names:
		if "}" in line:
			in_names = 0
			continue
		name = string.split(line, '"')[1]
		#if name != 'void':
		names.append(name)
	else:
		if "[" in line:
			in_names = 1
		
print names	


print "\t\tswitch(id) {"

for i in range(len(names)):
	print "\t\tcase %d:\r" % i
	print "\t\t\treturn visitor.%s(this);\r" % names[i]
print "\t\t}\r"


for name in names:
	print "\tpublic Object %s(SimpleNode n) throws Exception {\r" % name
	print '\t\tthrow new ParseException("Unhandled Node: "+n);\r'
	print "\t}\r"
	print '\r'