Skip to content

Commit

Permalink
enable parser error throws
Browse files Browse the repository at this point in the history
  • Loading branch information
jitsedesmet committed Dec 11, 2024
1 parent 1d19900 commit 47411d9
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions src/grammar/builder/parserBuilder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ export class Builder<Names extends string, RuleDefs extends RuleDefMap<Names>> {
lexerConfig?: ILexerConfig;
}, context: Partial<ImplArgs['context']> = {}): ParserFromRules<Names, RuleDefs> {
const lexer: Lexer = new Lexer(tokenVocabulary, {
positionTracking: 'onlyOffset',
positionTracking: 'onlyStart',
recoveryEnabled: false,
skipValidations: true,
ensureOptimizations: true,
Expand All @@ -148,7 +148,11 @@ export class Builder<Names extends string, RuleDefs extends RuleDefMap<Names>> {
const lexResult = lexer.tokenize(input);
parser.reset();
parser.input = lexResult.tokens;
return parser[rule.name](...args);
const result = parser[rule.name](...args);
if (parser.errors.length > 0) {
throw new Error(`Parse error on line ${parser.errors[0].token.startLine}`);
}
return result;
};
}
return <ParserFromRules<Names, RuleDefs>> selfSufficientParser;
Expand Down

0 comments on commit 47411d9

Please sign in to comment.