Skip to content

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

Description

@dabrahams

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions