metaborg / spoofax-pie

Spoofax implementation using PIE pipelines
Apache License 2.0
12 stars 9 forks source link

Forgetting to specify `context-free start-symbols` in SDF3 leads to unclear parsing errors #113

Open molenzwiebel opened 2 years ago

molenzwiebel commented 2 years ago

Summary

If the spoofaxc is configured to use a specific start symbol, but there is no [context-free] start-symbols entry for that symbol in the SDF3, parsing will fail with unclear errors.

What you did

SDF3:

// intentionally commented out:
// context-free start-symbols Module
context-free sorts Module
context-free syntax
  Module.Module =
<module <ModName>

<{Decl "\n\n"}*>>

spoofaxc.cfg:

parser {
  default-start-symbol = sort Module
}

Test file:

module foo

What you expected to happen

Either an error during parsing that the start-symbol does not exist/was not registered as such, or parsing to succeed into Module("foo", []).

What actually happened

Multiple markers at this line
- Syntax error near unexpected character 'm'
- Unexpected end of file
- Analysis failed. Exception: mb.jsglr.common.JsglrParseExceptions$ParseFail: Parsing failed; see error messages Messages of eclipse-resource##/ministratego/test.mstr: ERROR 0-6@1: Syntax error near unexpected character 'm' ERROR 7-10@1: Unexpected end of file 

Context

Gohla commented 2 years ago

This could maybe be checked by inspecting the produced ParseTable and checking if it contains the start symbol, if the ParseTable API allows you to do that.