Skip to content

Commit

Permalink
chore(generate): dedup and warn about duplicate or invalid rules
Browse files Browse the repository at this point in the history
  • Loading branch information
amaanq committed Feb 11, 2024
1 parent 78ccc39 commit 05de36d
Showing 1 changed file with 11 additions and 1 deletion.
12 changes: 11 additions & 1 deletion cli/src/generate/dsl.js
Original file line number Diff line number Diff line change
Expand Up @@ -351,7 +351,17 @@ function grammar(baseGrammar, options) {
throw new Error("Grammar's inline must be an array of rules.");
}

inline = inlineRules.map(symbol => symbol.name);
inline = inlineRules.filter((symbol, index, self) => {
if (self.findIndex(s => s.name === symbol.name) !== index) {
console.log(`Warning: duplicate inline rule '${symbol.name}'`);
return false;
}
if (symbol.name === 'ReferenceError') {
console.log(`Warning: inline rule '${symbol.symbol.name}' is not defined.`);
return false;
}
return true;
}).map(symbol => symbol.name);
}

let supertypes = baseGrammar.supertypes;
Expand Down

0 comments on commit 05de36d

Please sign in to comment.