summaryrefslogtreecommitdiff
path: root/examples/check_errors.py
diff options
context:
space:
mode:
authorMatthew Sotoudeh <matthew@masot.net>2024-03-11 16:33:24 -0700
committerMatthew Sotoudeh <matthew@masot.net>2024-03-11 16:33:24 -0700
commita9292a98cc6c65e2a4ad6da20937ef7568a4143d (patch)
treef921866c475208359285ff3f606c0fafa1812a32 /examples/check_errors.py
parent35fa21e59ad44de3ac5d075a3c1ae60d462a1a13 (diff)
earlpy
Diffstat (limited to 'examples/check_errors.py')
-rw-r--r--examples/check_errors.py14
1 files changed, 14 insertions, 0 deletions
diff --git a/examples/check_errors.py b/examples/check_errors.py
new file mode 100644
index 0000000..70f9f13
--- /dev/null
+++ b/examples/check_errors.py
@@ -0,0 +1,14 @@
+import earlpy
+import sys
+
+p = earlpy.Parser("grammars/c")
+node = p.parse_file(sys.argv[1])
+node.print_tree()
+def visit(n):
+ if isinstance(n, earlpy.Token):
+ return
+ if n.symbol.name == "ERROR":
+ print(n.line_numbers(), n.pprint())
+ else:
+ for a in n.contents: visit(a)
+visit(node)
generated by cgit on debian on lair
contact matthew@masot.net with questions or feedback