Compare commits
No commits in common. "46770419e6203695838e2ca840f7ad7ae981f9f1" and "ca240906c9a54c98201d9c0136afb00576f8dcb3" have entirely different histories.
46770419e6
...
ca240906c9
2 changed files with 5 additions and 40 deletions
|
|
@ -348,7 +348,7 @@ class Printer:
|
|||
def compile_rule(self, rule: parser.NonTerminal) -> Matcher:
|
||||
generated_grammar: list[typing.Tuple[str, list[str]]] = []
|
||||
visited: set[str] = set()
|
||||
groups: dict[tuple[str, ...], str] = {}
|
||||
group_count = 0
|
||||
indent_amounts: dict[str, int] = {}
|
||||
newline_map: dict[str, str] = {}
|
||||
done_forced_break = False
|
||||
|
|
@ -361,7 +361,7 @@ class Printer:
|
|||
generated_grammar.append((name, trans_prod))
|
||||
|
||||
def compile_production(production: parser.FlattenedWithMetadata) -> list[str]:
|
||||
nonlocal groups
|
||||
nonlocal group_count
|
||||
nonlocal indent_amounts
|
||||
nonlocal done_forced_break
|
||||
|
||||
|
|
@ -394,13 +394,9 @@ class Printer:
|
|||
if isinstance(pretty, parser.FormatMeta):
|
||||
if pretty.group:
|
||||
# Make a fake rule.
|
||||
child_key = tuple(tx_children)
|
||||
rule_name = groups.get(child_key)
|
||||
if rule_name is None:
|
||||
rule_name = f"g_{len(groups)}"
|
||||
groups[child_key] = rule_name
|
||||
generated_grammar.append((rule_name, tx_children))
|
||||
|
||||
rule_name = f"g_{group_count}"
|
||||
group_count += 1
|
||||
generated_grammar.append((rule_name, tx_children))
|
||||
tx_children = [rule_name]
|
||||
|
||||
if pretty.indent:
|
||||
|
|
|
|||
31
wrap.py
31
wrap.py
|
|
@ -1,31 +0,0 @@
|
|||
import grammar
|
||||
|
||||
import parser.runtime as runtime
|
||||
import parser.wadler as wadler
|
||||
|
||||
|
||||
def main():
|
||||
g = grammar.FineGrammar()
|
||||
parser = runtime.Parser(g.build_table())
|
||||
lexer = g.compile_lexer()
|
||||
|
||||
with open("test.fine", "r", encoding="utf-8") as f:
|
||||
text = f.read()
|
||||
|
||||
tree, errors = parser.parse(runtime.GenericTokenStream(text, lexer))
|
||||
if tree is None or len(errors) > 0:
|
||||
print(f"{len(errors)} ERRORS")
|
||||
for error in errors:
|
||||
print(f"{error}")
|
||||
return
|
||||
|
||||
WIDTH = 40
|
||||
|
||||
printer = wadler.Printer(g)
|
||||
result = printer.format_tree(tree, WIDTH).apply_to_source(text)
|
||||
for line in result.splitlines():
|
||||
print(f"{line:<{WIDTH}}|")
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
||||
Loading…
Add table
Add a link
Reference in a new issue