def __init__(self, sk_basedir, logger=None): if logger: self.logger = logger else: self.logger = logging.getLogger('sk.skbank') # Base directory of sk files self.sk_basedir = sk_basedir self.cache = Bunch.threadSafeBunch() lexer = sk_lexer.skScanner(logger=self.logger, debug=0, lextab='scan1_tab') self.param_parser = sk_parser.paramParser(lexer, logger=self.logger) self.param_parser.build(debug=0, tabmodule='param_parser_tab') self.param_parser.reset() lexer = sk_lexer.skScanner(logger=self.logger, debug=0, lextab='scan2_tab') self.ope_parser = sk_parser.opeParser(lexer, logger=self.logger) self.ope_parser.build(debug=0, tabmodule='ope_parser_tab') self.ope_parser.reset() lexer = sk_lexer.skScanner(logger=self.logger, debug=0, lextab='scan3_tab') self.sk_parser = sk_parser.skParser(lexer, logger=self.logger) self.sk_parser.build(debug=0, tabmodule='sk_parser_tab') self.sk_parser.reset()
def main(options, args): # TODO: configure the logger logger = logging.getLogger('sk.parser') lexer = sk_lexer.skScanner(logger=logger, debug=False, lextab='scan_tab') if options.ope: parser = opeParser(lexer, logger=logger) else: parser = skParser(lexer, logger=logger) parser.build(debug=False, tabmodule='parser_tab') parser.reset() if len(args) > 0: for filename in args: try: if options.ope: res = parser.parse_opefile(filename) else: res = parser.parse_skfile(filename) if res.errors > 0: for errbnch in res.errinfo: print("%d: %s (%s)" % (errbnch.lineno, errbnch.errstr, errbnch.token)) print(errbnch.verbose) print("") elif (res.ast != None) and options.verbose: res.ast.printAST() print("%s: %d errors" % (filename, res.errors)) except Exception as e: # Print error message and continue to next file print(str(e)) else: buf = sys.stdin.read() try: res = parser.parse_skbuf(buf) if res.errors > 0: for errbnch in res.errinfo: ## print("%d: %s (%s)" % (errbnch.lineno, errbnch.errstr, ## errbnch.token)) print(errbnch.verbose) print("") elif (res.ast != None) and options.verbose: res.ast.printAST() print("%d errors" % (res.errors)) print("Error info: %s" % (res.errinfo)) except skParseError as e: # Print error message print(str(e))
def setUp(self): lexer = sk_lexer.skScanner(debug=0, lextab='scan_tab', logger=self.logger) parser = sk_parser.skParser(lexer, logger=self.logger) parser.build(debug=0, tabmodule='parser_tab') parser.reset() self.setparser(parser.parse_skfile)
def setUp(self): lexer = sk_lexer.skScanner(debug=0, lextab='scan_tab', logger=self.logger) self.parser = sk_parser.skParser(lexer, logger=self.logger) self.parser.build(debug=0, tabmodule='parser_tab') self.parser.reset() self.sk_bank = sk_interp.skBank(self.skbase) variable_resolver = sk_interp.VariableResolver({}) register_resolver = sk_interp.RegisterResolver() status_resolver = sk_interp.MockStatusResolver(fakeStatus) frame_source = sk_interp.MockFrameSource() self.eval = sk_interp.Evaluator(variable_resolver, register_resolver, status_resolver, frame_source, self.logger)
def setUp(self): lexer = sk_lexer.skScanner(debug=0, lextab='scan_tab', logger=self.logger) self.setparser(lexer.scan_skfile)