Skip to content

Java backend fails to escape \n inside terminator/separator #566

Open

Description

@katrinafyi

This leads to a syntax error inside PrettyPrinter.java.

rules Entry ::= [A];
rules A ::= "a";
separator A "\n";
~/Downloads/bnfc-2.9.6.3-linux.binary a.cf -java           

Generated code with the un-escaped newline in render().

  private static void ppListA(java.util.Iterator<a.Absyn.A> it, int _i_)
  {
    if (it.hasNext())
    { /* cons */
      a.Absyn.A el = it.next();
      pp(el, _i_); render("
"); ppListA(it, _i_);
    }
  }

Of course, because of whitespace normalisation, a "\n" separator is the same as a " " separator and we could just use that instead. But it would be nice to avoid the syntax error.

I haven't tested all other backends. The Ocaml and Tree-sitter ones seemed to be fine with the same grammar.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions