|
|
|
@ -436,112 +436,116 @@ describe("generated parser behavior", function() {
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
describe("label variables", function() {
|
|
|
|
|
it("can access label variables from preceding labeled elements in a sequence", function() {
|
|
|
|
|
var parser = PEG.buildParser(
|
|
|
|
|
'start = a:"a" b:"b" c:"c" &{ return a === "a" && b === "b" && c === "c"; }',
|
|
|
|
|
options
|
|
|
|
|
);
|
|
|
|
|
describe("in a containing sequence", function() {
|
|
|
|
|
it("can access variables defined by preceding labeled elements", function() {
|
|
|
|
|
var parser = PEG.buildParser(
|
|
|
|
|
'start = a:"a" b:"b" c:"c" &{ return a === "a" && b === "b" && c === "c"; }',
|
|
|
|
|
options
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
expect(parser).toParse("abc");
|
|
|
|
|
expect(parser).toParse("abc");
|
|
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
it("can access label variables from preceding labeled elements in an outside sequence (group)", function() {
|
|
|
|
|
var parser = PEG.buildParser(
|
|
|
|
|
'start = a:"a" ("b" &{ return a === "a"; })',
|
|
|
|
|
options
|
|
|
|
|
);
|
|
|
|
|
describe("in an outside sequence", function() {
|
|
|
|
|
it("can access variables defined by preceding labeled elements (group)", function() {
|
|
|
|
|
var parser = PEG.buildParser(
|
|
|
|
|
'start = a:"a" ("b" &{ return a === "a"; })',
|
|
|
|
|
options
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
expect(parser).toParse("ab", ["a", ["b", undefined]]);
|
|
|
|
|
});
|
|
|
|
|
expect(parser).toParse("ab", ["a", ["b", undefined]]);
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
it("can access label variables from preceding labeled elements in an outside sequence (optional)", function() {
|
|
|
|
|
var parser = PEG.buildParser(
|
|
|
|
|
'start = a:"a" ("b" &{ return a === "a"; })?',
|
|
|
|
|
options
|
|
|
|
|
);
|
|
|
|
|
it("can access variables defined by preceding labeled elements (optional)", function() {
|
|
|
|
|
var parser = PEG.buildParser(
|
|
|
|
|
'start = a:"a" ("b" &{ return a === "a"; })?',
|
|
|
|
|
options
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
expect(parser).toParse("ab", ["a", ["b", undefined]]);
|
|
|
|
|
});
|
|
|
|
|
expect(parser).toParse("ab", ["a", ["b", undefined]]);
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
it("can access label variables from preceding labeled elements in an outside sequence (zero or more)", function() {
|
|
|
|
|
var parser = PEG.buildParser(
|
|
|
|
|
'start = a:"a" ("b" &{ return a === "a"; })*',
|
|
|
|
|
options
|
|
|
|
|
);
|
|
|
|
|
it("can access variables defined by preceding labeled elements (zero or more)", function() {
|
|
|
|
|
var parser = PEG.buildParser(
|
|
|
|
|
'start = a:"a" ("b" &{ return a === "a"; })*',
|
|
|
|
|
options
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
expect(parser).toParse("ab", ["a", [["b", undefined]]]);
|
|
|
|
|
});
|
|
|
|
|
expect(parser).toParse("ab", ["a", [["b", undefined]]]);
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
it("can access label variables from preceding labeled elements in an outside sequence (one or more)", function() {
|
|
|
|
|
var parser = PEG.buildParser(
|
|
|
|
|
'start = a:"a" ("b" &{ return a === "a"; })+',
|
|
|
|
|
options
|
|
|
|
|
);
|
|
|
|
|
it("can access variables defined by preceding labeled elements (one or more)", function() {
|
|
|
|
|
var parser = PEG.buildParser(
|
|
|
|
|
'start = a:"a" ("b" &{ return a === "a"; })+',
|
|
|
|
|
options
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
expect(parser).toParse("ab", ["a", [["b", undefined]]]);
|
|
|
|
|
});
|
|
|
|
|
expect(parser).toParse("ab", ["a", [["b", undefined]]]);
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
it("can access label variables from preceding labeled elements in an outside sequence (text)", function() {
|
|
|
|
|
var parser = PEG.buildParser(
|
|
|
|
|
'start = a:"a" $("b" &{ return a === "a"; })',
|
|
|
|
|
options
|
|
|
|
|
);
|
|
|
|
|
it("can access variables defined by preceding labeled elements (text)", function() {
|
|
|
|
|
var parser = PEG.buildParser(
|
|
|
|
|
'start = a:"a" $("b" &{ return a === "a"; })',
|
|
|
|
|
options
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
expect(parser).toParse("ab", ["a", "b"]);
|
|
|
|
|
});
|
|
|
|
|
expect(parser).toParse("ab", ["a", "b"]);
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
it("can access label variables from preceding labeled elements in an outside sequence (positive simple predicate)", function() {
|
|
|
|
|
var parser = PEG.buildParser(
|
|
|
|
|
'start = a:"a" &("b" &{ return a === "a"; }) "b"',
|
|
|
|
|
options
|
|
|
|
|
);
|
|
|
|
|
it("can access variables defined by preceding labeled elements (positive simple predicate)", function() {
|
|
|
|
|
var parser = PEG.buildParser(
|
|
|
|
|
'start = a:"a" &("b" &{ return a === "a"; }) "b"',
|
|
|
|
|
options
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
expect(parser).toParse("ab", ["a", undefined, "b"]);
|
|
|
|
|
});
|
|
|
|
|
expect(parser).toParse("ab", ["a", undefined, "b"]);
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
it("can access label variables from preceding labeled elements in an outside sequence (negative simple predicate)", function() {
|
|
|
|
|
var parser = PEG.buildParser(
|
|
|
|
|
'start = a:"a" !("b" &{ return a === "a"; }) "c"',
|
|
|
|
|
options
|
|
|
|
|
);
|
|
|
|
|
it("can access variables defined by preceding labeled elements (negative simple predicate)", function() {
|
|
|
|
|
var parser = PEG.buildParser(
|
|
|
|
|
'start = a:"a" !("b" &{ return a === "a"; }) "c"',
|
|
|
|
|
options
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
expect(parser).toParse("ac", ["a", undefined, "c"]);
|
|
|
|
|
});
|
|
|
|
|
expect(parser).toParse("ac", ["a", undefined, "c"]);
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
it("can access label variables from preceding labeled elements in an outside sequence (label)", function() {
|
|
|
|
|
var parser = PEG.buildParser(
|
|
|
|
|
'start = a:"a" b:("b" &{ return a === "a"; })',
|
|
|
|
|
options
|
|
|
|
|
);
|
|
|
|
|
it("can access variables defined by preceding labeled elements (label)", function() {
|
|
|
|
|
var parser = PEG.buildParser(
|
|
|
|
|
'start = a:"a" b:("b" &{ return a === "a"; })',
|
|
|
|
|
options
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
expect(parser).toParse("ab", ["a", ["b", undefined]]);
|
|
|
|
|
});
|
|
|
|
|
expect(parser).toParse("ab", ["a", ["b", undefined]]);
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
it("can access label variables from preceding labeled elements in an outside sequence (sequence)", function() {
|
|
|
|
|
var parser = PEG.buildParser(
|
|
|
|
|
'start = a:"a" ("b" ("c" &{ return a === "a"; }) "d")',
|
|
|
|
|
options
|
|
|
|
|
);
|
|
|
|
|
it("can access variables defined by preceding labeled elements (sequence)", function() {
|
|
|
|
|
var parser = PEG.buildParser(
|
|
|
|
|
'start = a:"a" ("b" ("c" &{ return a === "a"; }) "d")',
|
|
|
|
|
options
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
expect(parser).toParse("abcd", ["a", ["b", ["c", undefined], "d"]]);
|
|
|
|
|
});
|
|
|
|
|
expect(parser).toParse("abcd", ["a", ["b", ["c", undefined], "d"]]);
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
it("can access label variables from preceding labeled elements in an outside sequence (action)", function() {
|
|
|
|
|
var parser = PEG.buildParser(
|
|
|
|
|
'start = a:"a" (b:("b" &{ return a === "a"; }) { return b; })',
|
|
|
|
|
options
|
|
|
|
|
);
|
|
|
|
|
it("can access variables defined by preceding labeled elements (action)", function() {
|
|
|
|
|
var parser = PEG.buildParser(
|
|
|
|
|
'start = a:"a" (b:("b" &{ return a === "a"; }) { return b; })',
|
|
|
|
|
options
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
expect(parser).toParse("ab", ["a", ["b", undefined]]);
|
|
|
|
|
});
|
|
|
|
|
expect(parser).toParse("ab", ["a", ["b", undefined]]);
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
it("can access label variables from preceding labeled elements in an outside sequence (choice)", function() {
|
|
|
|
|
var parser = PEG.buildParser(
|
|
|
|
|
'start = a:"a" ("b" / "c" &{ return a === "a"; } / "d")',
|
|
|
|
|
options
|
|
|
|
|
);
|
|
|
|
|
it("can access variables defined by preceding labeled elements (choice)", function() {
|
|
|
|
|
var parser = PEG.buildParser(
|
|
|
|
|
'start = a:"a" ("b" / "c" &{ return a === "a"; } / "d")',
|
|
|
|
|
options
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
expect(parser).toParse("ac", ["a", ["c", undefined]]);
|
|
|
|
|
expect(parser).toParse("ac", ["a", ["c", undefined]]);
|
|
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
@ -645,112 +649,116 @@ describe("generated parser behavior", function() {
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
describe("label variables", function() {
|
|
|
|
|
it("can access label variables from preceding labeled elements in a sequence", function() {
|
|
|
|
|
var parser = PEG.buildParser(
|
|
|
|
|
'start = a:"a" b:"b" c:"c" !{ return a !== "a" || b !== "b" || c !== "c"; }',
|
|
|
|
|
options
|
|
|
|
|
);
|
|
|
|
|
describe("in a containing sequence", function() {
|
|
|
|
|
it("can access variables defined by preceding labeled elements", function() {
|
|
|
|
|
var parser = PEG.buildParser(
|
|
|
|
|
'start = a:"a" b:"b" c:"c" !{ return a !== "a" || b !== "b" || c !== "c"; }',
|
|
|
|
|
options
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
expect(parser).toParse("abc");
|
|
|
|
|
expect(parser).toParse("abc");
|
|
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
it("can access label variables from preceding labeled elements in an outside sequence (group)", function() {
|
|
|
|
|
var parser = PEG.buildParser(
|
|
|
|
|
'start = a:"a" ("b" !{ return a !== "a"; })',
|
|
|
|
|
options
|
|
|
|
|
);
|
|
|
|
|
describe("in an outside sequence", function() {
|
|
|
|
|
it("can access variables defined by preceding labeled elements (group)", function() {
|
|
|
|
|
var parser = PEG.buildParser(
|
|
|
|
|
'start = a:"a" ("b" !{ return a !== "a"; })',
|
|
|
|
|
options
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
expect(parser).toParse("ab", ["a", ["b", undefined]]);
|
|
|
|
|
});
|
|
|
|
|
expect(parser).toParse("ab", ["a", ["b", undefined]]);
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
it("can access label variables from preceding labeled elements in an outside sequence (optional)", function() {
|
|
|
|
|
var parser = PEG.buildParser(
|
|
|
|
|
'start = a:"a" ("b" !{ return a !== "a"; })?',
|
|
|
|
|
options
|
|
|
|
|
);
|
|
|
|
|
it("can access variables defined by preceding labeled elements (optional)", function() {
|
|
|
|
|
var parser = PEG.buildParser(
|
|
|
|
|
'start = a:"a" ("b" !{ return a !== "a"; })?',
|
|
|
|
|
options
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
expect(parser).toParse("ab", ["a", ["b", undefined]]);
|
|
|
|
|
});
|
|
|
|
|
expect(parser).toParse("ab", ["a", ["b", undefined]]);
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
it("can access label variables from preceding labeled elements in an outside sequence (zero or more)", function() {
|
|
|
|
|
var parser = PEG.buildParser(
|
|
|
|
|
'start = a:"a" ("b" !{ return a !== "a"; })*',
|
|
|
|
|
options
|
|
|
|
|
);
|
|
|
|
|
it("can access variables defined by preceding labeled elements (zero or more)", function() {
|
|
|
|
|
var parser = PEG.buildParser(
|
|
|
|
|
'start = a:"a" ("b" !{ return a !== "a"; })*',
|
|
|
|
|
options
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
expect(parser).toParse("ab", ["a", [["b", undefined]]]);
|
|
|
|
|
});
|
|
|
|
|
expect(parser).toParse("ab", ["a", [["b", undefined]]]);
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
it("can access label variables from preceding labeled elements in an outside sequence (one or more)", function() {
|
|
|
|
|
var parser = PEG.buildParser(
|
|
|
|
|
'start = a:"a" ("b" !{ return a !== "a"; })+',
|
|
|
|
|
options
|
|
|
|
|
);
|
|
|
|
|
it("can access variables defined by preceding labeled elements (one or more)", function() {
|
|
|
|
|
var parser = PEG.buildParser(
|
|
|
|
|
'start = a:"a" ("b" !{ return a !== "a"; })+',
|
|
|
|
|
options
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
expect(parser).toParse("ab", ["a", [["b", undefined]]]);
|
|
|
|
|
});
|
|
|
|
|
expect(parser).toParse("ab", ["a", [["b", undefined]]]);
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
it("can access label variables from preceding labeled elements in an outside sequence (text)", function() {
|
|
|
|
|
var parser = PEG.buildParser(
|
|
|
|
|
'start = a:"a" $("b" !{ return a !== "a"; })',
|
|
|
|
|
options
|
|
|
|
|
);
|
|
|
|
|
it("can access variables defined by preceding labeled elements (text)", function() {
|
|
|
|
|
var parser = PEG.buildParser(
|
|
|
|
|
'start = a:"a" $("b" !{ return a !== "a"; })',
|
|
|
|
|
options
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
expect(parser).toParse("ab", ["a", "b"]);
|
|
|
|
|
});
|
|
|
|
|
expect(parser).toParse("ab", ["a", "b"]);
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
it("can access label variables from preceding labeled elements in an outside sequence (positive simple predicate)", function() {
|
|
|
|
|
var parser = PEG.buildParser(
|
|
|
|
|
'start = a:"a" &("b" !{ return a !== "a"; }) "b"',
|
|
|
|
|
options
|
|
|
|
|
);
|
|
|
|
|
it("can access variables defined by preceding labeled elements (positive simple predicate)", function() {
|
|
|
|
|
var parser = PEG.buildParser(
|
|
|
|
|
'start = a:"a" &("b" !{ return a !== "a"; }) "b"',
|
|
|
|
|
options
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
expect(parser).toParse("ab", ["a", undefined, "b"]);
|
|
|
|
|
});
|
|
|
|
|
expect(parser).toParse("ab", ["a", undefined, "b"]);
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
it("can access label variables from preceding labeled elements in an outside sequence (negative simple predicate)", function() {
|
|
|
|
|
var parser = PEG.buildParser(
|
|
|
|
|
'start = a:"a" !("b" !{ return a !== "a"; }) "c"',
|
|
|
|
|
options
|
|
|
|
|
);
|
|
|
|
|
it("can access variables defined by preceding labeled elements (negative simple predicate)", function() {
|
|
|
|
|
var parser = PEG.buildParser(
|
|
|
|
|
'start = a:"a" !("b" !{ return a !== "a"; }) "c"',
|
|
|
|
|
options
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
expect(parser).toParse("ac", ["a", undefined, "c"]);
|
|
|
|
|
});
|
|
|
|
|
expect(parser).toParse("ac", ["a", undefined, "c"]);
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
it("can access label variables from preceding labeled elements in an outside sequence (label)", function() {
|
|
|
|
|
var parser = PEG.buildParser(
|
|
|
|
|
'start = a:"a" b:("b" !{ return a !== "a"; })',
|
|
|
|
|
options
|
|
|
|
|
);
|
|
|
|
|
it("can access variables defined by preceding labeled elements (label)", function() {
|
|
|
|
|
var parser = PEG.buildParser(
|
|
|
|
|
'start = a:"a" b:("b" !{ return a !== "a"; })',
|
|
|
|
|
options
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
expect(parser).toParse("ab", ["a", ["b", undefined]]);
|
|
|
|
|
});
|
|
|
|
|
expect(parser).toParse("ab", ["a", ["b", undefined]]);
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
it("can access label variables from preceding labeled elements in an outside sequence (sequence)", function() {
|
|
|
|
|
var parser = PEG.buildParser(
|
|
|
|
|
'start = a:"a" ("b" ("c" !{ return a !== "a"; }) "d")',
|
|
|
|
|
options
|
|
|
|
|
);
|
|
|
|
|
it("can access variables defined by preceding labeled elements (sequence)", function() {
|
|
|
|
|
var parser = PEG.buildParser(
|
|
|
|
|
'start = a:"a" ("b" ("c" !{ return a !== "a"; }) "d")',
|
|
|
|
|
options
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
expect(parser).toParse("abcd", ["a", ["b", ["c", undefined], "d"]]);
|
|
|
|
|
});
|
|
|
|
|
expect(parser).toParse("abcd", ["a", ["b", ["c", undefined], "d"]]);
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
it("can access label variables from preceding labeled elements in an outside sequence (action)", function() {
|
|
|
|
|
var parser = PEG.buildParser(
|
|
|
|
|
'start = a:"a" (b:("b" !{ return a !== "a"; }) { return b; })',
|
|
|
|
|
options
|
|
|
|
|
);
|
|
|
|
|
it("can access variables defined by preceding labeled elements (action)", function() {
|
|
|
|
|
var parser = PEG.buildParser(
|
|
|
|
|
'start = a:"a" (b:("b" !{ return a !== "a"; }) { return b; })',
|
|
|
|
|
options
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
expect(parser).toParse("ab", ["a", ["b", undefined]]);
|
|
|
|
|
});
|
|
|
|
|
expect(parser).toParse("ab", ["a", ["b", undefined]]);
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
it("can access label variables from preceding labeled elements in an outside sequence (choice)", function() {
|
|
|
|
|
var parser = PEG.buildParser(
|
|
|
|
|
'start = a:"a" ("b" / "c" !{ return a !== "a"; } / "d")',
|
|
|
|
|
options
|
|
|
|
|
);
|
|
|
|
|
it("can access variables defined by preceding labeled elements (choice)", function() {
|
|
|
|
|
var parser = PEG.buildParser(
|
|
|
|
|
'start = a:"a" ("b" / "c" !{ return a !== "a"; } / "d")',
|
|
|
|
|
options
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
expect(parser).toParse("ac", ["a", ["c", undefined]]);
|
|
|
|
|
expect(parser).toParse("ac", ["a", ["c", undefined]]);
|
|
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
@ -1044,118 +1052,122 @@ describe("generated parser behavior", function() {
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
describe("label variables", function() {
|
|
|
|
|
it("can access label variables from a labeled expression", function() {
|
|
|
|
|
var parser = PEG.buildParser('start = a:"a" { return a; }', options);
|
|
|
|
|
describe("in the expression", function() {
|
|
|
|
|
it("can access label variables defined by a labeled expression", function() {
|
|
|
|
|
var parser = PEG.buildParser('start = a:"a" { return a; }', options);
|
|
|
|
|
|
|
|
|
|
expect(parser).toParse("a", "a");
|
|
|
|
|
});
|
|
|
|
|
expect(parser).toParse("a", "a");
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
it("can access label variables from a sequence with labeled elements", function() {
|
|
|
|
|
var parser = PEG.buildParser(
|
|
|
|
|
'start = a:"a" b:"b" c:"c" { return [a, b, c]; }',
|
|
|
|
|
options
|
|
|
|
|
);
|
|
|
|
|
it("can access label variables defined by labeled sequence elements", function() {
|
|
|
|
|
var parser = PEG.buildParser(
|
|
|
|
|
'start = a:"a" b:"b" c:"c" { return [a, b, c]; }',
|
|
|
|
|
options
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
expect(parser).toParse("abc", ["a", "b", "c"]);
|
|
|
|
|
expect(parser).toParse("abc", ["a", "b", "c"]);
|
|
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
it("can access label variables from preceding labeled elements in an outside sequence (group)", function() {
|
|
|
|
|
var parser = PEG.buildParser(
|
|
|
|
|
'start = a:"a" ("b" { return a; })',
|
|
|
|
|
options
|
|
|
|
|
);
|
|
|
|
|
describe("in an outside sequence", function() {
|
|
|
|
|
it("can access variables defined by preceding labeled elements (group)", function() {
|
|
|
|
|
var parser = PEG.buildParser(
|
|
|
|
|
'start = a:"a" ("b" { return a; })',
|
|
|
|
|
options
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
expect(parser).toParse("ab", ["a", "a"]);
|
|
|
|
|
});
|
|
|
|
|
expect(parser).toParse("ab", ["a", "a"]);
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
it("can access label variables from preceding labeled elements in an outside sequence (optional)", function() {
|
|
|
|
|
var parser = PEG.buildParser(
|
|
|
|
|
'start = a:"a" ("b" { return a; })?',
|
|
|
|
|
options
|
|
|
|
|
);
|
|
|
|
|
it("can access variables defined by preceding labeled elements (optional)", function() {
|
|
|
|
|
var parser = PEG.buildParser(
|
|
|
|
|
'start = a:"a" ("b" { return a; })?',
|
|
|
|
|
options
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
expect(parser).toParse("ab", ["a", "a"]);
|
|
|
|
|
});
|
|
|
|
|
expect(parser).toParse("ab", ["a", "a"]);
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
it("can access label variables from preceding labeled elements in an outside sequence (zero or more)", function() {
|
|
|
|
|
var parser = PEG.buildParser(
|
|
|
|
|
'start = a:"a" ("b" { return a; })*',
|
|
|
|
|
options
|
|
|
|
|
);
|
|
|
|
|
it("can access variables defined by preceding labeled elements (zero or more)", function() {
|
|
|
|
|
var parser = PEG.buildParser(
|
|
|
|
|
'start = a:"a" ("b" { return a; })*',
|
|
|
|
|
options
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
expect(parser).toParse("ab", ["a", ["a"]]);
|
|
|
|
|
});
|
|
|
|
|
expect(parser).toParse("ab", ["a", ["a"]]);
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
it("can access label variables from preceding labeled elements in an outside sequence (one or more)", function() {
|
|
|
|
|
var parser = PEG.buildParser(
|
|
|
|
|
'start = a:"a" ("b" { return a; })+',
|
|
|
|
|
options
|
|
|
|
|
);
|
|
|
|
|
it("can access variables defined by preceding labeled elements (one or more)", function() {
|
|
|
|
|
var parser = PEG.buildParser(
|
|
|
|
|
'start = a:"a" ("b" { return a; })+',
|
|
|
|
|
options
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
expect(parser).toParse("ab", ["a", ["a"]]);
|
|
|
|
|
});
|
|
|
|
|
expect(parser).toParse("ab", ["a", ["a"]]);
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
it("can access label variables from preceding labeled elements in an outside sequence (text)", function() {
|
|
|
|
|
var parser = PEG.buildParser(
|
|
|
|
|
'start = a:"a" $("b" { return a; })',
|
|
|
|
|
options
|
|
|
|
|
);
|
|
|
|
|
it("can access variables defined by preceding labeled elements (text)", function() {
|
|
|
|
|
var parser = PEG.buildParser(
|
|
|
|
|
'start = a:"a" $("b" { return a; })',
|
|
|
|
|
options
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
expect(parser).toParse("ab", ["a", "b"]);
|
|
|
|
|
});
|
|
|
|
|
expect(parser).toParse("ab", ["a", "b"]);
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
it("can access label variables from preceding labeled elements in an outside sequence (positive simple predicate)", function() {
|
|
|
|
|
var parser = PEG.buildParser(
|
|
|
|
|
'start = a:"a" &("b" { return a; }) "b"',
|
|
|
|
|
options
|
|
|
|
|
);
|
|
|
|
|
it("can access variables defined by preceding labeled elements (positive simple predicate)", function() {
|
|
|
|
|
var parser = PEG.buildParser(
|
|
|
|
|
'start = a:"a" &("b" { return a; }) "b"',
|
|
|
|
|
options
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
expect(parser).toParse("ab", ["a", undefined, "b"]);
|
|
|
|
|
});
|
|
|
|
|
expect(parser).toParse("ab", ["a", undefined, "b"]);
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
it("can access label variables from preceding labeled elements in an outside sequence (negative simple predicate)", function() {
|
|
|
|
|
var parser = PEG.buildParser(
|
|
|
|
|
'start = a:"a" !("b" { return a; }) "c"',
|
|
|
|
|
options
|
|
|
|
|
);
|
|
|
|
|
it("can access variables defined by preceding labeled elements (negative simple predicate)", function() {
|
|
|
|
|
var parser = PEG.buildParser(
|
|
|
|
|
'start = a:"a" !("b" { return a; }) "c"',
|
|
|
|
|
options
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
expect(parser).toParse("ac", ["a", undefined, "c"]);
|
|
|
|
|
});
|
|
|
|
|
expect(parser).toParse("ac", ["a", undefined, "c"]);
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
it("can access label variables from preceding labeled elements in an outside sequence (label)", function() {
|
|
|
|
|
var parser = PEG.buildParser(
|
|
|
|
|
'start = a:"a" b:("b" { return a; })',
|
|
|
|
|
options
|
|
|
|
|
);
|
|
|
|
|
it("can access variables defined by preceding labeled elements (label)", function() {
|
|
|
|
|
var parser = PEG.buildParser(
|
|
|
|
|
'start = a:"a" b:("b" { return a; })',
|
|
|
|
|
options
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
expect(parser).toParse("ab", ["a", "a"]);
|
|
|
|
|
});
|
|
|
|
|
expect(parser).toParse("ab", ["a", "a"]);
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
it("can access label variables from preceding labeled elements in an outside sequence (sequence)", function() {
|
|
|
|
|
var parser = PEG.buildParser(
|
|
|
|
|
'start = a:"a" ("b" ("c" { return a; }) "d")',
|
|
|
|
|
options
|
|
|
|
|
);
|
|
|
|
|
it("can access variables defined by preceding labeled elements (sequence)", function() {
|
|
|
|
|
var parser = PEG.buildParser(
|
|
|
|
|
'start = a:"a" ("b" ("c" { return a; }) "d")',
|
|
|
|
|
options
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
expect(parser).toParse("abcd", ["a", ["b", "a", "d"]]);
|
|
|
|
|
});
|
|
|
|
|
expect(parser).toParse("abcd", ["a", ["b", "a", "d"]]);
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
it("can access label variables from preceding labeled elements in an outside sequence (action)", function() {
|
|
|
|
|
var parser = PEG.buildParser(
|
|
|
|
|
'start = a:"a" (b:("b" { return a; }) { return b; })',
|
|
|
|
|
options
|
|
|
|
|
);
|
|
|
|
|
it("can access variables defined by preceding labeled elements (action)", function() {
|
|
|
|
|
var parser = PEG.buildParser(
|
|
|
|
|
'start = a:"a" (b:("b" { return a; }) { return b; })',
|
|
|
|
|
options
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
expect(parser).toParse("ab", ["a", "a"]);
|
|
|
|
|
});
|
|
|
|
|
expect(parser).toParse("ab", ["a", "a"]);
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
it("can access label variables from preceding labeled elements in an outside sequence (choice)", function() {
|
|
|
|
|
var parser = PEG.buildParser(
|
|
|
|
|
'start = a:"a" ("b" / "c" { return a; } / "d")',
|
|
|
|
|
options
|
|
|
|
|
);
|
|
|
|
|
it("can access variables defined by preceding labeled elements (choice)", function() {
|
|
|
|
|
var parser = PEG.buildParser(
|
|
|
|
|
'start = a:"a" ("b" / "c" { return a; } / "d")',
|
|
|
|
|
options
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
expect(parser).toParse("ac", ["a", "a"]);
|
|
|
|
|
expect(parser).toParse("ac", ["a", "a"]);
|
|
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|