Exemplo n.º 1
0
def run():
    g = Grammar.from_file('rhapsody.pg')

    this_folder = dirname(__file__)
    parser = Parser(g)

    # Small file
    parser.parse_file(join(this_folder, 'test_inputs', 'LightSwitch.rpy'))

    # Large file
    parser.parse_file(join(this_folder, 'test_inputs',
                           'LightSwitchDouble.rpy'))
Exemplo n.º 2
0
def refinementChecker(scriptFile):
	try:
		g = Grammar.from_file("grammar")
		parser = Parser(g, actions=actions)
	except Exception as e:
		print e
		print "Parse generation: Failed."
		print "Terminating."
		sys.exit()
	print "Parser generation: Done."
	try:
		script = parser.parse_file(scriptFile)
		print "Parse input: Done."
	except Exception as e:
		print e
		print "Parse input: Failed."
		print "Terminating."
		sys.exit()
	try:
		execute(script)
	except Exception as e:
		print e
		print "Script execution: Failed."
		print "Terminating."
		sys.exit()
	print "Script execution: Done."
	print "Terminating."
Exemplo n.º 3
0
def main(debug=False):
    this_folder = os.path.dirname(__file__)
    g = Grammar.from_file(os.path.join(this_folder, 'json.pg'))
    parser = Parser(g, debug=debug, debug_colors=True)

    for i in range(5):
        result = parser.parse_file(
            os.path.join(this_folder, f'example{i+1}.json'))
        print(result)
Exemplo n.º 4
0
    def from_file(self, filename, cleaned=True, **kwargs):
        actions = self.actions if cleaned else None
        g = Grammar.from_file(self.grammar, **kwargs)
        parser = Parser(g, actions=actions, build_tree=self.build_tree, **kwargs)

        result = parser.parse_file(file_name=filename)
        self.fetch_tree(result)

        return result
Exemplo n.º 5
0
def main(debug=False):
    this_folder = os.path.dirname(__file__)
    g = Grammar.from_file(os.path.join(this_folder, 'robot.pg'),
                          debug=debug, debug_colors=True)
    parser = Parser(g, actions=action.all, debug=debug,
                    debug_colors=True)

    end_position = parser.parse_file(os.path.join(this_folder, 'program.rbt'))

    print("Robot stops at position: {}".format(end_position))
Exemplo n.º 6
0
def test_parsing_from_file():
    grammar = get_grammar()
    p = Parser(grammar)
    assert p.parse_file(join(dirname(__file__), 'parsing_from_file.txt'))