Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

sourceLocation() line messes up error reporting for empty braces #23

Open
dabrahams opened this issue Mar 15, 2022 · 0 comments
Open

sourceLocation() line messes up error reporting for empty braces #23

dabrahams opened this issue Mar 15, 2022 · 0 comments

Comments

@dabrahams
Copy link
Contributor

fprintf(out, "#sourceLocation()\n\n");

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant