Skip to content

Commit

Permalink
#2178 Improve readability of the translated BNF
Browse files Browse the repository at this point in the history
  • Loading branch information
homedirectory committed Feb 15, 2024
1 parent 80e63d0 commit c0f5d98
Showing 1 changed file with 3 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -29,13 +29,14 @@ public String bnfToText(EBNF ebnf) {
var rules = entry.getValue();
return new ERule(variable, rules.stream().flatMap(ERule::bodies).toList());
})
.map(this::toString).collect(joining("\n"));
.map(this::toString).collect(joining("\n\n"));
}

protected String toString(ERule eRule) {
final int prefixLen = eRule.variable.name().length();
return eRule.bodies()
.map(this::toString)
.collect(joining(" | ", "%s = ".formatted(eRule.variable), ";"));
.collect(joining("\n%s | ".formatted(" ".repeat(prefixLen)), "%s = ".formatted(eRule.variable), ";"));
}

protected String toString(final Body body) {
Expand Down

0 comments on commit c0f5d98

Please sign in to comment.