citron icon indicating copy to clipboard operation
citron copied to clipboard

sourceLocation() line messes up error reporting for empty braces

Open dabrahams opened this issue 2 years ago • 0 comments

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.

dabrahams avatar Mar 15 '22 02:03 dabrahams