citron
citron copied to clipboard
sourceLocation() line messes up error reporting for empty braces
https://github.com/roop/citron/blob/a1b26d4049c3920a599e4df9f671712266988f96/Sources/citron/main.c#L3822
results in code like this when the action clause for a rule is empty:
case 1: /* rule_list ::= */
func codeBlockForRule01() throws -> EBNF.RuleList {
#sourceLocation(file: "Sources/ebnf-citron/EBNFGrammar.citron", line: 37)
#sourceLocation()
}
That causes the error report to point into the generated .swift file instead of the grammar file, which is not very useful.
Sources/ebnf-citron/EBNFGrammar.citron:37:1: error: missing return in local function expected to return 'EBNF.RuleList' (aka 'Array<(lhs: Substring, rhs: Array<Optional<Array<EBNF.Term>>>)>')
}
^
If you move the #sourceLocation()
to just after the closing brace, the report shows up in the right place. This is an important case because parsers will often be developed by capturing the grammar first and using %default_nonterminal_type Void
. When making the transition, it doesn't work out so well.