""" tweetex.py nick creel | nov 12 2019 | mit license """ from lexer import Lexer from parser import Parser import re import argparse def getfile(): parser = argparse.ArgumentParser(description="accepts input \ for TweeTex compiler") parser.add_argument('file', metavar='filename', type=str, nargs=1, help='the location of the TweeTex file to compile') args = parser.parse_args() with open(args.file[0], "r") as file: source = file.read() return source def printchildren(token): #this is depth first, just a test. if type(token.children) != list: print(token.children) printchildren(token.children) else: for token in token.children: if len(token.children) != 0: print(token) printchildren(token) else: print(token) def main(): source = getfile() mylexer = Lexer(source) mylexer.lex() tokens = mylexer.tokens myparser = Parser(tokens) ast = myparser.parse() print(ast) print(ast.children) printchildren(ast) main()