diff --git a/README.md b/README.md index d97f9d3..06d78a7 100644 --- a/README.md +++ b/README.md @@ -227,10 +227,9 @@ The first rule can be preceded by an *initializer* — a piece of JavaScript cod in curly braces (“{” and “}”). This code is executed before the generated parser starts parsing. All variables and functions defined in the initializer are accessible in rule actions and semantic predicates. The code inside the -initializer can access the parser object using the `parser` variable and options -passed to the parser using the `options` variable. Curly braces in the -initializer code must be balanced. Let's look at the example grammar from above -using a simple initializer. +initializer can access options passed to the parser using the `options` +variable. Curly braces in the initializer code must be balanced. Let's look at +the example grammar from above using a simple initializer. ```pegjs { @@ -376,8 +375,8 @@ The `start` and `end` properties both refer to the current parse position. The `offset` property contains an offset as a zero-based index and `line` and `column` properties contain a line and a column as one-based indices. -The code inside the predicate can also access the parser object using the -`parser` variable and options passed to the parser using the `options` variable. +The code inside the predicate can also access options passed to the parser using +the `options` variable. Note that curly braces in the predicate code must be balanced. @@ -407,8 +406,8 @@ The `start` and `end` properties both refer to the current parse position. The `offset` property contains an offset as a zero-based index and `line` and `column` properties contain a line and a column as one-based indices. -The code inside the predicate can also access the parser object using the -`parser` variable and options passed to the parser using the `options` variable. +The code inside the predicate can also access options passed to the parser using +the `options` variable. Note that curly braces in the predicate code must be balanced. @@ -475,8 +474,8 @@ the `end` property refers to position after the end of the expression. The `offset` property contains an offset as a zero-based index and `line` and `column` properties contain a line and a column as one-based indices. -The code inside the action can also access the parser object using the `parser` -variable and options passed to the parser using the `options` variable. +The code inside the action can also access options passed to the parser using +the `options` variable. Note that curly braces in the action code must be balanced. diff --git a/lib/compiler/passes/generate-js.js b/lib/compiler/passes/generate-js.js index a03a2cc..7f5c9fd 100644 --- a/lib/compiler/passes/generate-js.js +++ b/lib/compiler/passes/generate-js.js @@ -953,9 +953,7 @@ function generateJS(ast, options) { 'function peg$parse(input, options) {', ' options = options !== void 0 ? options : {};', '', - ' var parser = this,', - '', - ' peg$FAILED = {},', + ' var peg$FAILED = {},', '' ].join('\n')); diff --git a/spec/behavior/generated-parser-behavior.spec.js b/spec/behavior/generated-parser-behavior.spec.js index 0dc9a39..c4c5881 100644 --- a/spec/behavior/generated-parser-behavior.spec.js +++ b/spec/behavior/generated-parser-behavior.spec.js @@ -133,15 +133,6 @@ describe("generated parser behavior", function() { }); describe("available variables and functions", function() { - it("|parser| contains the parser object", function() { - var parser = peg.generate([ - '{ var result = parser; }', - 'start = "a" { return result; }' - ].join("\n"), options); - - expect(parser).toParse("a", parser); - }); - it("|options| contains options", function() { var parser = peg.generate([ '{ var result = options; }', @@ -568,15 +559,6 @@ describe("generated parser behavior", function() { }); describe("available variables & functions", function() { - it("|parser| contains the parser object", function() { - var parser = peg.generate([ - '{ var result; }', - 'start = &{ result = parser; return true; } { return result; }' - ].join("\n"), options); - - expect(parser).toParse("", parser); - }); - it("|options| contains options", function() { var parser = peg.generate([ '{ var result; }', @@ -773,15 +755,6 @@ describe("generated parser behavior", function() { }); describe("available variables & functions", function() { - it("|parser| contains the parser object", function() { - var parser = peg.generate([ - '{ var result; }', - 'start = !{ result = parser; return false; } { return result; }' - ].join("\n"), options); - - expect(parser).toParse("", parser); - }); - it("|options| contains options", function() { var parser = peg.generate([ '{ var result; }', @@ -1151,15 +1124,6 @@ describe("generated parser behavior", function() { }); describe("available variables & functions", function() { - it("|parser| contains the parser object", function() { - var parser = peg.generate( - 'start = "a" { return parser; }', - options - ); - - expect(parser).toParse("a", parser); - }); - it("|options| contains options", function() { var parser = peg.generate( 'start = "a" { return options; }',