|
|
@ -171,6 +171,33 @@ describe("generated parser", function() {
|
|
|
|
expect(parser).toParse("a", 42);
|
|
|
|
expect(parser).toParse("a", 42);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
it("can use the |text| function", function() {
|
|
|
|
|
|
|
|
var parser = PEG.buildParser([
|
|
|
|
|
|
|
|
'{ var result = text(); }',
|
|
|
|
|
|
|
|
'start = "a" { return result; }'
|
|
|
|
|
|
|
|
].join("\n"), options);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
expect(parser).toParse("a", "");
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
it("can use the |offset| function to get the current parse position", function() {
|
|
|
|
|
|
|
|
var parser = PEG.buildParser([
|
|
|
|
|
|
|
|
'{ var result = offset(); }',
|
|
|
|
|
|
|
|
'start = "a" { return result; }'
|
|
|
|
|
|
|
|
].join("\n"), options);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
expect(parser).toParse("a", 0);
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
it("can use the |line| and |column| functions to get the current line and column", function() {
|
|
|
|
|
|
|
|
var parser = PEG.buildParser([
|
|
|
|
|
|
|
|
'{ var result = [line(), column()]; }',
|
|
|
|
|
|
|
|
'start = "a" { return result; }'
|
|
|
|
|
|
|
|
].join("\n"), options);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
expect(parser).toParse("a", [1, 1]);
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
it("can use options passed to the parser", function() {
|
|
|
|
it("can use options passed to the parser", function() {
|
|
|
|
var parser = PEG.buildParser([
|
|
|
|
var parser = PEG.buildParser([
|
|
|
|
'{ var result = options; }',
|
|
|
|
'{ var result = options; }',
|
|
|
@ -255,6 +282,15 @@ describe("generated parser", function() {
|
|
|
|
expect(parser).toParse("a", "a");
|
|
|
|
expect(parser).toParse("a", "a");
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
it("can use the |text| function to get the text matched by the expression", function() {
|
|
|
|
|
|
|
|
var parser = PEG.buildParser(
|
|
|
|
|
|
|
|
'start = "a" "b" "c" { return text(); }',
|
|
|
|
|
|
|
|
options
|
|
|
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
expect(parser).toParse("abc", "abc");
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
it("can use the |offset| function to get the current parse position", function() {
|
|
|
|
it("can use the |offset| function to get the current parse position", function() {
|
|
|
|
var parser = PEG.buildParser(
|
|
|
|
var parser = PEG.buildParser(
|
|
|
|
'start = "a" ("b" { return offset(); })',
|
|
|
|
'start = "a" ("b" { return offset(); })',
|
|
|
@ -425,6 +461,15 @@ describe("generated parser", function() {
|
|
|
|
expect(parser).toParse("a", ["a", ""]);
|
|
|
|
expect(parser).toParse("a", ["a", ""]);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
it("can use the |text| function", function() {
|
|
|
|
|
|
|
|
var parser = PEG.buildParser(
|
|
|
|
|
|
|
|
'start = "a" &{ return text() === ""; }',
|
|
|
|
|
|
|
|
options
|
|
|
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
expect(parser).toParse("a", ["a", ""]);
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
it("can use the |offset| function to get the current parse position", function() {
|
|
|
|
it("can use the |offset| function to get the current parse position", function() {
|
|
|
|
var parser = PEG.buildParser(
|
|
|
|
var parser = PEG.buildParser(
|
|
|
|
'start = "a" &{ return offset() === 1; }',
|
|
|
|
'start = "a" &{ return offset() === 1; }',
|
|
|
@ -507,6 +552,15 @@ describe("generated parser", function() {
|
|
|
|
expect(parser).toParse("a", ["a", ""]);
|
|
|
|
expect(parser).toParse("a", ["a", ""]);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
it("can use the |text| function", function() {
|
|
|
|
|
|
|
|
var parser = PEG.buildParser(
|
|
|
|
|
|
|
|
'start = "a" !{ return text() !== ""; }',
|
|
|
|
|
|
|
|
options
|
|
|
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
expect(parser).toParse("a", ["a", ""]);
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
it("can use the |offset| function to get the current parse position", function() {
|
|
|
|
it("can use the |offset| function to get the current parse position", function() {
|
|
|
|
var parser = PEG.buildParser(
|
|
|
|
var parser = PEG.buildParser(
|
|
|
|
'start = "a" !{ return offset() !== 1; }',
|
|
|
|
'start = "a" !{ return offset() !== 1; }',
|
|
|
|