2012-04-30 13:42:13 +02:00
|
|
|
describe("compiler pass |reportLeftRecursion|", function() {
|
2013-01-13 11:17:44 +01:00
|
|
|
var pass = PEG.compiler.passes.check.reportLeftRecursion;
|
2012-04-30 13:42:13 +02:00
|
|
|
|
2014-06-07 09:11:00 +02:00
|
|
|
it("reports direct left recursion", function() {
|
|
|
|
expect(pass).toReportError('start = start', {
|
|
|
|
message: 'Left recursion detected for rule \"start\".'
|
2012-04-30 13:42:13 +02:00
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
it("reports indirect left recursion", function() {
|
2014-06-07 09:11:00 +02:00
|
|
|
expect(pass).toReportError([
|
2012-04-30 13:42:13 +02:00
|
|
|
'start = stop',
|
|
|
|
'stop = start'
|
2014-06-07 09:11:00 +02:00
|
|
|
].join("\n"), {
|
|
|
|
message: 'Left recursion detected for rule \"start\".'
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
describe("in sequences", function() {
|
|
|
|
it("reports left recursion only for the first element", function() {
|
|
|
|
expect(pass).toReportError('start = start "a" "b"', {
|
|
|
|
message: 'Left recursion detected for rule \"start\".'
|
|
|
|
});
|
|
|
|
|
|
|
|
expect(pass).not.toReportError('start = "a" start "b"');
|
|
|
|
expect(pass).not.toReportError('start = "a" "b" start');
|
|
|
|
});
|
2012-04-30 13:42:13 +02:00
|
|
|
});
|
|
|
|
});
|