コード例 #1
0
def main():
	sys.setrecursionlimit(5000)

	ifilename, ofilename = mocha.parse_input(sys.argv[1:])

	ibase = mocha.get_script_base(ifilename)
	package_name = mocha.build_package_name(ifilename)
	class_name = mocha.build_class_name(ifilename)

	parser = MochaParser()

	if ifilename[-9:] == "scriptlib":
		generator = JavaStaticClassGenerator()
	else:
		generator = JavaClassGenerator()

	ast = parser.parse_file(ifilename)

	functions = dict()

	#for inc in ast.includes:
	#	name = inc.name.value
	#	if len(name) >= 6 and name[:5] == "java.":
	#		continue

	#	fname = "%s/script/%s.scriptlib" % (ibase, name.replace(".", "/"))

	#	if not os.path.isfile(fname):
	#		continue

	#	alias = name.split(".")[-1]
	#	dast = parser.parse_file(fname)

	#	for stmt in dast.statements:
	#		if type(stmt) is FunctionDeclaration:
	#			func_name = "%s.%s" % (alias, stmt.name)
	#			functions[func_name] = {"return_type": stmt.return_type, "resizeable": True if "resizeable" in stmt.modifiers else False}

	if ofilename is "":
	    print generator.generate(package_name, class_name, ast, functions)
	else:
	    with open(ofilename, "w") as java_file:
	        java_file.write(generator.generate(package_name, class_name, ast, functions))
コード例 #2
0
#!/usr/bin/env python

import sys

if len(sys.argv) == 1:
    print('''usage: parse_file.py <filename> ...
   Example: parse_file.py path/to/file.script ''')
    sys.exit(1)

from mocha.parser import MochaParser

parser = MochaParser()
for _file in sys.argv[1:]:
    print(parser.parse_file(_file))
コード例 #3
0
#!/usr/bin/env python

import sys

if len(sys.argv) == 1:
    print('''usage: test_script.py <filename> ...
   Example: test_script.py '/path/to/file.script' ''')
    sys.exit(1)

from mocha.parser import MochaParser

parser = MochaParser()
parser.parse_file(sys.argv[1])
コード例 #4
0
ファイル: parse_stmt.py プロジェクト: grserver/infinity
#!/usr/bin/env python

import sys

if len(sys.argv) == 1:
    print(
        """usage: parse_stmt.py <statement> ...
   Example: parse_expr.py 'int a = 5;' """
    )
    sys.exit(1)

from mocha.parser import MochaParser

parser = MochaParser()
for stmt in sys.argv[1:]:
    print(parser.parse_statement(stmt))
コード例 #5
0
#!/usr/bin/env python

import sys

if len(sys.argv) == 1:
    print('''usage: parse_expr.py <expression> ...
   Example: parse_expr.py '1+2' '3' 'j = (int) i + 3' ''')
    sys.exit(1)

from mocha.parser import MochaParser

parser = MochaParser()
for expr in sys.argv[1:]:
    print(parser.parse_expression(expr))
コード例 #6
0
#!/usr/bin/env python

import sys

if len(sys.argv) == 1:
    print('''usage: tokenizer.py <filename> ...
   Example: tokenizer.py '/path/to/file.script' ''')
    sys.exit(1)

from mocha.parser import MochaParser

parser = MochaParser()
for filename in sys.argv[1:]:
    print(parser.tokenize_file(filename))