Skip to content

Whitespace is discarded in token stream #1168

Closed

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

Activity

  1. sshailabh commented on Oct 5, 2025

    @sshailabh
    Author

    @jknack Could you please review the enhancement for re-constructing source content without loss? pr: #1169

    Thank you

  2. added this to the 4.5.2 milestone on Jun 16, 2026
  3. added a commit that references this issue on Oct 12, 2026
    b5870fa
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

      Milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions