You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
36 lines
1.0 KiB
JavaScript
36 lines
1.0 KiB
JavaScript
10 years ago
|
"use strict";
|
||
|
|
||
10 years ago
|
var GrammarError = require("../../grammar-error"),
|
||
|
asts = require("../asts"),
|
||
|
visitor = require("../visitor");
|
||
|
|
||
|
/*
|
||
|
* Reports expressions that don't consume any input inside |*| or |+| in the
|
||
|
* grammar, which prevents infinite loops in the generated parser.
|
||
|
*/
|
||
8 years ago
|
function reportInfiniteRepetition(ast) {
|
||
10 years ago
|
var check = visitor.build({
|
||
|
zero_or_more: function(node) {
|
||
9 years ago
|
if (!asts.alwaysConsumesOnSuccess(ast, node.expression)) {
|
||
8 years ago
|
throw new GrammarError(
|
||
8 years ago
|
"Possible infinite loop when parsing (repetition used with an expression that may not consume any input).",
|
||
8 years ago
|
node.location
|
||
|
);
|
||
10 years ago
|
}
|
||
|
},
|
||
|
|
||
|
one_or_more: function(node) {
|
||
9 years ago
|
if (!asts.alwaysConsumesOnSuccess(ast, node.expression)) {
|
||
8 years ago
|
throw new GrammarError(
|
||
8 years ago
|
"Possible infinite loop when parsing (repetition used with an expression that may not consume any input).",
|
||
8 years ago
|
node.location
|
||
|
);
|
||
10 years ago
|
}
|
||
|
}
|
||
|
});
|
||
|
|
||
|
check(ast);
|
||
|
}
|
||
|
|
||
8 years ago
|
module.exports = reportInfiniteRepetition;
|