def _initialize(self, ttlfile=None): optimize = self.compiler['optimize'] lex_debug = self.compiler['lex_debug'] lextab = self.compiler['lextab'] yacc_debug = self.compiler['yacc_debug'] yacctab = self.compiler['yacctab'] yacc_outputdir = self.compiler['yacc_outputdir'] self.ttlfile = ttlfile # Build Lexer self.ttllex = TTLLexer(self.compiler) kwargs = {'ttlfile': ttlfile} kwargs.update(optimize=optimize) if optimize else None kwargs.update(debug=lex_debug) kwargs.update(lextab=lextab) if lextab else None self.ttllex.build(**kwargs) self.tokens = self.ttllex.tokens # Important for YACCer self.ttllex.reset_lineno() # Build Yaccer kwargs = {'optimize': optimize} if optimize else {} kwargs.update(debug=yacc_debug) kwargs.update(outputdir=yacc_outputdir) if yacc_outputdir else None kwargs.update(tabmodule=yacctab) self.parser = ply.yacc.yacc(module=self, **kwargs) self.parser.ttlparser = self # For AST nodes to access `this` self.parser.compiler = self.compiler self.prolog = True
def lexical(pa, options): from tayra.lexer import TTLLexer stats = {} setts = {'optimize': 0} compiler = pa.qp(pa, ISettings, 'tayra.ttlcompiler', settings=setts) ttllex = TTLLexer(compiler) ttllex.build(ttlfile=options.ttlfile) ttllex.input(open(options.ttlfile, encoding='utf-8-sig').read()) tok = fetchtoken(ttllex, stats) while tok: tok = fetchtoken(ttllex, stats)