mirror of
https://github.com/irmen/prog8.git
synced 2024-10-10 10:23:47 +00:00
print parse tree
This commit is contained in:
parent
3c70790fbf
commit
c587125674
@ -844,7 +844,8 @@ class Parser:
|
|||||||
groups = match.groupdict()
|
groups = match.groupdict()
|
||||||
subname = groups["subname"]
|
subname = groups["subname"]
|
||||||
return self.parse_call_or_goto(subname, groups["arguments"], None, None, True)
|
return self.parse_call_or_goto(subname, groups["arguments"], None, None, True)
|
||||||
match = re.fullmatch(r"(?P<outputs>[^\(]*\s*=)?\s*(?P<subname>[\S]+?)\s*(?P<preserve>!\s*[A-Z]*)?\s*(\((?P<arguments>.*)\))?\s*", line)
|
match = re.fullmatch(
|
||||||
|
r"(?P<outputs>[^\(]*\s*=)?\s*(?P<subname>[\S]+?)\s*(?P<preserve>!\s*[A-Z]*)?\s*(\((?P<arguments>.*)\))?\s*", line)
|
||||||
if match:
|
if match:
|
||||||
# subroutine call (not a goto) with possible output param assignment
|
# subroutine call (not a goto) with possible output param assignment
|
||||||
groups = match.groupdict()
|
groups = match.groupdict()
|
||||||
|
@ -483,4 +483,4 @@ if __name__ == "__main__":
|
|||||||
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))
|
result = parser.parse(input=file.read()) or Module(None, SourceRef("@todo-sfile", 1, 1))
|
||||||
print("RESULT")
|
print("RESULT")
|
||||||
print(result.nodes)
|
print(str(result))
|
||||||
|
@ -702,6 +702,40 @@ class AstNode:
|
|||||||
def lineref(self) -> str:
|
def lineref(self) -> str:
|
||||||
return "src l. " + str(self.sourceref.line)
|
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):
|
class Block(AstNode):
|
||||||
_unnamed_block_labels = {} # type: Dict[Block, str]
|
_unnamed_block_labels = {} # type: Dict[Block, str]
|
||||||
|
3
mypy.ini
3
mypy.ini
@ -2,3 +2,6 @@
|
|||||||
follow_imports = normal
|
follow_imports = normal
|
||||||
ignore_missing_imports = True
|
ignore_missing_imports = True
|
||||||
incremental = True
|
incremental = True
|
||||||
|
|
||||||
|
[mypy-il65/parsetab.*]
|
||||||
|
ignore_errors = True
|
||||||
|
Loading…
Reference in New Issue
Block a user