Skip to content

Whitespace not handling comments correctly at beginning of parsed source #2

@booch

Description

@booch

I'm trying to add comments to my language. So I added a %whitespace directive, similar to the JSON and INI examples. But when my source code starts with a comment, the parser always reports a syntax error, expecting the source code to end with a comment — even if it does end with a comment.

My RTLR file looks something like this:

%start program
%whitespace ( SPACE+ / comment )*
program             <- expression+ EOF          <AST::Program.new>
expression          <- literal_integer
literal_integer     <- @DIGIT+                  <AST::LiteralInteger.new>
comment             <- ~([#] [^\n]*)

If I try to parse this:

# Comment
123

then I get an error like this:

bundler/gems/rattler-5b3806afad53/lib/rattler/runtime/parser.rb:179:in `raise_error': parse error at line 3, column 1: (Rattler::Runtime::SyntaxError)
 comment expected

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