def test_python_lex(code=FIB, expected=54): g = Grammar(file('python.g').read()) l = g.lex(code) for x in l: y = x.value if isinstance(y, TokValue): logging.debug('%s %s %s', y.type, y, y.line, y.column) else: logging.debug('%s %s', x.type, x.value) assert len(l) == expected, len(l)
tikzpicture_env_options = styles.get(elem='tikzpicture', override=tikzpicture_env_options) #Apply sequence of preparse functions for prefunc in preparse_funcs: source = prefunc(source) #Make substitutions docpreamble = docpreamble.replace('%_document_class_%', document_class) docpreamble = docpreamble.replace('%_document_class_options_%', document_class_options) docpreamble = docpreamble.replace('%_tikz_package_options_%', tikz_package_options) docpreamble = docpreamble.replace('%_tikz_libraries_%', ','.join(tikz_libraries)) docpreamble = docpreamble.replace('%_additional_preamble_%', additional_preamble) tikzheader = tikzheader.replace('%_tikzpicture_env_options_%', tikzpicture_env_options) if arg.lex: for t in grammar.lex(source): print "line {0.lineno:<3}col {0.lexpos:<4}{0.type}:\t{0.value}".format(t) sys.exit(0) #Parse src file according to grammar ast = grammar.parse(source) ast.calc_parents() if arg.ast: print ast import pydot ast.to_png_with_pydot("ast.png") if transformer: ast = transformer.transform(ast) print "\npost transform:" print ast