diff --git a/il65/lexer.py b/il65/lexer.py index d9bf7f377..9c28ea752 100644 --- a/il65/lexer.py +++ b/il65/lexer.py @@ -127,7 +127,7 @@ def t_inlineasm_lbrace(t): def t_inlineasm_rbrace(t): r"\}" t.lexer.level -= 1 - #if closing brace, return code fragment + # if closing brace, return code fragment if t.lexer.level == 0: t.value = t.lexer.lexdata[t.lexer.code_start:t.lexer.lexpos-1] t.type = "INLINEASM" @@ -285,5 +285,5 @@ lexer.error_function = error_function # can override this if __name__ == "__main__": ply.lex.runmain() - #lexer = ply.lex.Lexer() - #ply.lex.runmain(lexer=lexer) + # lexer = ply.lex.Lexer() + # ply.lex.runmain(lexer=lexer) diff --git a/il65/parse.py b/il65/parse.py index c1763f93b..a9c2174e0 100644 --- a/il65/parse.py +++ b/il65/parse.py @@ -486,7 +486,7 @@ class Parser: break # the first import directive actually is not part of the header anymore else: raise self.PError("invalid directive") - break # no more directives, header parsing finished! + break # no more directives, header parsing finished! self.prev_line() if not self.result.start_address: # set the proper default start address @@ -844,7 +844,8 @@ class Parser: groups = match.groupdict() subname = groups["subname"] return self.parse_call_or_goto(subname, groups["arguments"], None, None, True) - match = re.fullmatch(r"(?P[^\(]*\s*=)?\s*(?P[\S]+?)\s*(?P!\s*[A-Z]*)?\s*(\((?P.*)\))?\s*", line) + match = re.fullmatch( + r"(?P[^\(]*\s*=)?\s*(?P[\S]+?)\s*(?P!\s*[A-Z]*)?\s*(\((?P.*)\))?\s*", line) if match: # subroutine call (not a goto) with possible output param assignment groups = match.groupdict() diff --git a/il65/plyacc.py b/il65/plyacc.py index 51fa983e3..9178ae0c5 100644 --- a/il65/plyacc.py +++ b/il65/plyacc.py @@ -244,7 +244,7 @@ def p_type_opt(p): def p_dimensions(p): """dimensions : INTEGER | dimensions ',' INTEGER""" - if len(p)==2: + if len(p) == 2: p[0] = [p[1]] else: p[0] = p[1] + [p[3]] @@ -480,7 +480,7 @@ parser = yacc() if __name__ == "__main__": import sys - file=sys.stdin # open(sys.argv[1], "rU") + file = sys.stdin # open(sys.argv[1], "rU") result = parser.parse(input=file.read()) or Module(None, SourceRef("@todo-sfile", 1, 1)) print("RESULT") - print(result.nodes) + print(str(result)) diff --git a/il65/symbols.py b/il65/symbols.py index af9a78898..4cb681068 100644 --- a/il65/symbols.py +++ b/il65/symbols.py @@ -702,6 +702,40 @@ class AstNode: def lineref(self) -> str: return "src l. " + str(self.sourceref.line) + def __str__(self) -> str: + def tostr(node: Any, level: int) -> str: + indent = " " + clsname = node.__class__.__name__ + attrs = [] + try: + nvars = vars(node) + except TypeError: + if type(node) is str: + sv = repr(node) + if len(sv) > 20: + sv = sv[:20] + "...'" + return sv + return str(node) + for name, value in nvars.items(): + if name == "sourceref": + continue + if type(value) in (str, int, float, bool, type(None)): + attrs.append((name, tostr(value, level+1))) + for name, value in nvars.items(): + if type(value) is list: + strvalue = "[" + strvalue += (",\n" + indent*(level+1)).join(tostr(v, level+1) for v in value) + "\n" + (1+level)*indent + "]" + attrs.append((name, strvalue)) + for name, value in nvars.items(): + if name == "sourceref": + continue + if type(value) is not list and type(value) not in (str, int, float, bool, type(None)): + attrs.append((name, tostr(value, level+2))) + attrstr = ("\n" + indent*(1+level)).join("{} = {}".format(name, sv) for name, sv in attrs) + result = "\n" + indent * level + "<{0:s} l={1:d} c={2:d}".format(clsname, node.sourceref.line, node.sourceref.column) + return result + "{} |end {} l={:d}|>".format(attrstr, clsname, node.sourceref.line) + return tostr(self, 0) + class Block(AstNode): _unnamed_block_labels = {} # type: Dict[Block, str] diff --git a/mypy.ini b/mypy.ini index 8cc8b9027..f31a065a1 100644 --- a/mypy.ini +++ b/mypy.ini @@ -2,3 +2,6 @@ follow_imports = normal ignore_missing_imports = True incremental = True + +[mypy-il65/parsetab.*] +ignore_errors = True diff --git a/setup.cfg b/setup.cfg index f9d40e7e5..ee290141b 100644 --- a/setup.cfg +++ b/setup.cfg @@ -1,3 +1,3 @@ [pycodestyle] max-line-length = 140 -exclude = .git,__pycache__,.tox,docs,tests,build,dist +exclude = .git,__pycache__,.tox,docs,tests,build,dist,parsetab.py