metaborg / stratego

Apache License 2.0
10 stars 6 forks source link

Stratego syntax reports ambiguity on invalid input #18

Closed wildarch closed 2 years ago

wildarch commented 2 years ago

Describe the bug Syntactically invalid stratego rule definitions can lead to an ambiguous parse.

Project In the editor when using Stratego 2.

Versions Spoofax 3 0.16.3

To Reproduce I found two small snippets that produce an ambiguous parse. Both can be pasted into main.str2 on a new clean project to trigger the bug.

  1. Adding a colon after rules

    rules
    :    // This colon does not belong here 
    a: b -> b
  2. Omitting the where keyword

    rules
    a: b -> c
       <id> b => c

Observed behaviour

Expected behaviour A syntax error.

Ideally for any ambiguous parse, it would be good to explain in the warning that the ambiguity is in the internal Stratego syntax definition, not in the stratego rule written by the user (so not their fault).

Additional context N/A

Apanatshka commented 2 years ago

In Spoofax 3 0.16.13 I can reproduce the issues with the ambiguity warnings, but on top of those warnings, I also get parse errors. I'm going ask @Gohla to have a look at this, since I don't expect those ambiguity warnings either when there are parse errors that are the problem.

Gohla commented 2 years ago

@Apanatshka I debugged this and this is just what JSGLR2 provides as output. It parses and recovers successfully, produces a number of errors, but there are also several ambiguities in the AST that are reported as warnings. There's not much I can do other than filter out ambiguities when parsing fails or recovers, but I'm not sure I should do that in general.