Skip to content

Grammar error line info incorrect when using additional JSΒ #539

@aliclark

Description

@aliclark

The following grammar produces a Syntax Error with line 2 and col 12:

@{%
%}
test[a] -> ]

Since offset is 18, nearley is able to display the correct location of the error when formatting, but I think it would be nice to reflect the original file line and column also.

For example, this PR with moo to provide contextual errors makes use of line and col over offset, so would point to the wrong location in this example.

A workaround can be for the grammar author to move additional JS blocks towards the bottom of the grammar file, therefore not changing the line locations of the grammar above.

I imagine a straightforward fix could be to "blank" out the locations where additional JS is present in any intermediate grammar, ie. intermediate result looking like:



test[a] -> ]

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