Debian Codegraph @

lib/compiler/passes/report-infinite-repetition.js

raw symbols SCIP
1 "use strict";
2
3 var GrammarError = require("../../grammar-error"),
4 asts = require("../asts"),
5 visitor = require("../visitor");
6
7 /*
8 * Reports expressions that don't consume any input inside |*| or |+| in the
9 * grammar, which prevents infinite loops in the generated parser.
10 */
11 function reportInfiniteRepetition(ast) {
12 var check = visitor.build({
13 zero_or_more: function(node) {
14 if (!asts.alwaysConsumesOnSuccess(ast, node.expression)) {
15 throw new GrammarError(
16 "Possible infinite loop when parsing (repetition used with an expression that may not consume any input).",
17 node.location
18 );
19 }
20 },
21
22 one_or_more: function(node) {
23 if (!asts.alwaysConsumesOnSuccess(ast, node.expression)) {
24 throw new GrammarError(
25 "Possible infinite loop when parsing (repetition used with an expression that may not consume any input).",
26 node.location
27 );
28 }
29 }
30 });
31
32 check(ast);
33 }
34
35 module.exports = reportInfiniteRepetition;