Skip to content

Whitespace is discarded in token stream #1168

@sshailabh

Description

@sshailabh

Lossless Parsing with Whitespace Preservation

It looks like the lexer discards the whitespace. This should not be discarded and rather sent to other hidden channel.
This results in loss of information. Downsides:

  • Cannot reconstruct the exact original source from the parse tree
  • Build accurate code formatters
  • Develop linters that understand whitespace context

https://github.com/jknack/handlebars.java/blob/master/handlebars/src/main/antlr4/com/github/jknack/handlebars/internal/HbsLexer.g4#L376

WS
 : [ \t\r\n] -> skip
 ;

I see this might be inspired from mustache: https://github.com/jknack/handlebars.java/blob/master/handlebars/src/main/java/com/github/jknack/handlebars/internal/MustacheSpec.java
However this can be discarded in TemplateBuilder.java

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions