bdf91b5941
This is purely a mechanical change, not taking advantage of block scope of "let" and "const". Minimizing variable scope will come in the next commit. In general, "var" is converted into "let" and "const" is used only for immutable variables of permanent character (generally spelled in ALL_CAPS). Using it for any immutable variable regardless on its permanence would feel confusing. Any code which is not transpiled and needs to run in ES6 environment (examples, code in grammars embedded in specs, ...) is kept unchanged. This is also true for code generated by PEG.js. See #442.
96 lines
3.1 KiB
JavaScript
96 lines
3.1 KiB
JavaScript
"use strict";
|
|
|
|
let peg = require("../../../../lib/peg");
|
|
|
|
describe("compiler pass |reportInfiniteRepetition|", function() {
|
|
let pass = peg.compiler.passes.check.reportInfiniteRepetition;
|
|
|
|
it("reports infinite loops for zero_or_more", function() {
|
|
expect(pass).toReportError('start = ("")*', {
|
|
message: "Possible infinite loop when parsing (repetition used with an expression that may not consume any input).",
|
|
location: {
|
|
start: { offset: 8, line: 1, column: 9 },
|
|
end: { offset: 13, line: 1, column: 14 }
|
|
}
|
|
});
|
|
});
|
|
|
|
it("reports infinite loops for one_or_more", function() {
|
|
expect(pass).toReportError('start = ("")+', {
|
|
message: "Possible infinite loop when parsing (repetition used with an expression that may not consume any input).",
|
|
location: {
|
|
start: { offset: 8, line: 1, column: 9 },
|
|
end: { offset: 13, line: 1, column: 14 }
|
|
}
|
|
});
|
|
});
|
|
|
|
it("computes expressions that always consume input on success correctly", function() {
|
|
expect(pass).toReportError([
|
|
'start = a*',
|
|
'a "a" = ""'
|
|
].join('\n'));
|
|
expect(pass).not.toReportError([
|
|
'start = a*',
|
|
'a "a" = "a"'
|
|
].join('\n'));
|
|
|
|
expect(pass).toReportError('start = ("" / "a" / "b")*');
|
|
expect(pass).toReportError('start = ("a" / "" / "b")*');
|
|
expect(pass).toReportError('start = ("a" / "b" / "")*');
|
|
expect(pass).not.toReportError('start = ("a" / "b" / "c")*');
|
|
|
|
expect(pass).toReportError('start = ("" { })*');
|
|
expect(pass).not.toReportError('start = ("a" { })*');
|
|
|
|
expect(pass).toReportError('start = ("" "" "")*');
|
|
expect(pass).not.toReportError('start = ("a" "" "")*');
|
|
expect(pass).not.toReportError('start = ("" "a" "")*');
|
|
expect(pass).not.toReportError('start = ("" "" "a")*');
|
|
|
|
expect(pass).toReportError('start = (a:"")*');
|
|
expect(pass).not.toReportError('start = (a:"a")*');
|
|
|
|
expect(pass).toReportError('start = ($"")*');
|
|
expect(pass).not.toReportError('start = ($"a")*');
|
|
|
|
expect(pass).toReportError('start = (&"")*');
|
|
expect(pass).toReportError('start = (&"a")*');
|
|
|
|
expect(pass).toReportError('start = (!"")*');
|
|
expect(pass).toReportError('start = (!"a")*');
|
|
|
|
expect(pass).toReportError('start = (""?)*');
|
|
expect(pass).toReportError('start = ("a"?)*');
|
|
|
|
expect(pass).toReportError('start = (""*)*');
|
|
expect(pass).toReportError('start = ("a"*)*');
|
|
|
|
expect(pass).toReportError('start = (""+)*');
|
|
expect(pass).not.toReportError('start = ("a"+)*');
|
|
|
|
expect(pass).toReportError('start = ("")*');
|
|
expect(pass).not.toReportError('start = ("a")*');
|
|
|
|
expect(pass).toReportError('start = (&{ })*');
|
|
|
|
expect(pass).toReportError('start = (!{ })*');
|
|
|
|
expect(pass).toReportError([
|
|
'start = a*',
|
|
'a = ""'
|
|
].join('\n'));
|
|
expect(pass).not.toReportError([
|
|
'start = a*',
|
|
'a = "a"'
|
|
].join('\n'));
|
|
|
|
expect(pass).toReportError('start = ""*');
|
|
expect(pass).not.toReportError('start = "a"*');
|
|
|
|
expect(pass).not.toReportError('start = [a-d]*');
|
|
|
|
expect(pass).not.toReportError('start = .*');
|
|
});
|
|
});
|