From 57e806383cdcb15be3ea23ac4c0bbf5d3463e396 Mon Sep 17 00:00:00 2001 From: David Majda Date: Wed, 16 Oct 2013 08:08:35 +0200 Subject: [PATCH] Error handling: Use a special value (not |null|) to indicate failure Using a special value to indicate match failure instead of |null| allows actions to return |null| as a regular value. This simplifies e.g. the JSON parser. Note the special value is internal and intentionally undocumented. This means that there is currently no official way how to trigger a match failure from an action. This is a temporary state which will be fixed soon. The negative performance impact (see below) is probably caused by changing lot of comparisons against |null| (which likely check the value against a fixed constant representing |null| in the interpreter) to comparisons against the special value (which likely check the value against another value in the interpreter). Implements part of #198. Speed impact ------------ Before: 1146.82 kB/s After: 1031.25 kB/s Difference: -10.08% Size impact ----------- Before: 950817 b After: 973269 b Difference: 2.36% (Measured by /tools/impact with Node.js v0.6.18 on x86_64 GNU/Linux.) --- README.md | 2 +- examples/json.pegjs | 24 +- lib/compiler/passes/generate-bytecode.js | 28 +- lib/compiler/passes/generate-javascript.js | 20 +- lib/parser.js | 734 +++++++++--------- .../compiler/passes/generate-bytecode.spec.js | 18 +- spec/generated-parser.spec.js | 17 +- 7 files changed, 409 insertions(+), 434 deletions(-) diff --git a/README.md b/README.md index aa1d36a..1549129 100644 --- a/README.md +++ b/README.md @@ -374,7 +374,7 @@ The action is a piece of JavaScript code that is executed as if it was inside a function. It gets the match results of labeled expressions in preceding expression as its arguments. The action should return some JavaScript value using the `return` statement. This value is considered match result of the -preceding expression. The action can return `null` to indicate a match failure. +preceding expression. The code inside the action can access all variables and functions defined in the initializer at the beginning of the grammar. Curly braces in the action code diff --git a/examples/json.pegjs b/examples/json.pegjs index 91ffa0c..43b2314 100644 --- a/examples/json.pegjs +++ b/examples/json.pegjs @@ -1,19 +1,5 @@ /* JSON parser based on the grammar described at http://json.org/. */ -{ - /* - * We can't return |null| in the |value| rule because that would mean parse - * failure. So we return a special object instead and convert it to |null| - * later. - */ - - var null_ = new Object; - - function fixNull(value) { - return value === null_ ? null : value; - } -} - /* ===== Syntactical Elements ===== */ start @@ -26,9 +12,9 @@ object members = head:pair tail:("," _ pair)* { var result = {}; - result[head[0]] = fixNull(head[1]); + result[head[0]] = head[1]; for (var i = 0; i < tail.length; i++) { - result[tail[i][2][0]] = fixNull(tail[i][2][1]); + result[tail[i][2][0]] = tail[i][2][1]; } return result; } @@ -42,9 +28,9 @@ array elements = head:value tail:("," _ value)* { - var result = [fixNull(head)]; + var result = [head]; for (var i = 0; i < tail.length; i++) { - result.push(fixNull(tail[i][2])); + result.push(tail[i][2]); } return result; } @@ -56,7 +42,7 @@ value / array / "true" _ { return true; } / "false" _ { return false; } - / "null" _ { return null_; } + / "null" _ { return null; } /* ===== Lexical Elements ===== */ diff --git a/lib/compiler/passes/generate-bytecode.js b/lib/compiler/passes/generate-bytecode.js index fc9b7fc..e9d95cd 100644 --- a/lib/compiler/passes/generate-bytecode.js +++ b/lib/compiler/passes/generate-bytecode.js @@ -70,7 +70,7 @@ var utils = require("../../utils"), * * [11] IF_ERROR t, f * - * if (stack.top() === null) { + * if (stack.top() === FAILED) { * interpret(ip + 3, ip + 3 + t); * } else { * interpret(ip + 3 + t, ip + 3 + t + f); @@ -78,7 +78,7 @@ var utils = require("../../utils"), * * [12] IF_NOT_ERROR t, f * - * if (stack.top() !== null) { + * if (stack.top() !== FAILED) { * interpret(ip + 3, ip + 3 + t); * } else { * interpret(ip + 3 + t, ip + 3 + t + f); @@ -86,7 +86,7 @@ var utils = require("../../utils"), * * [13] WHILE_NOT_ERROR b * - * while(stack.top() !== null) { + * while(stack.top() !== FAILED) { * interpret(ip + 2, ip + 2 + b); * } * @@ -137,7 +137,7 @@ var utils = require("../../utils"), * * [20] FAIL e * - * stack.push(null); + * stack.push(FAILED); * fail(consts[e]); * * Calls @@ -214,7 +214,7 @@ module.exports = function(ast, options) { function buildSimplePredicate(expression, negative, context) { var emptyStringIndex = addConst('""'), - nullIndex = addConst('null'); + failedIndex = addConst('peg$FAILED'); return buildSequence( [op.PUSH_CURR_POS], @@ -235,7 +235,7 @@ module.exports = function(ast, options) { buildSequence( [op.POP], [negative ? op.POP_CURR_POS : op.POP], - [op.PUSH, nullIndex] + [op.PUSH, failedIndex] ) ) ); @@ -244,7 +244,7 @@ module.exports = function(ast, options) { function buildSemanticPredicate(code, negative, context) { var functionIndex = addFunctionConst(utils.keys(context.env), code), emptyStringIndex = addConst('""'), - nullIndex = addConst('null'); + failedIndex = addConst('peg$FAILED'); return buildSequence( [op.REPORT_CURR_POS], @@ -253,11 +253,11 @@ module.exports = function(ast, options) { [op.IF], buildSequence( [op.POP], - [op.PUSH, negative ? nullIndex : emptyStringIndex] + [op.PUSH, negative ? failedIndex : emptyStringIndex] ), buildSequence( [op.POP], - [op.PUSH, negative ? emptyStringIndex : nullIndex] + [op.PUSH, negative ? emptyStringIndex : failedIndex] ) ) ); @@ -357,7 +357,7 @@ module.exports = function(ast, options) { }, sequence: function(node, context) { - var emptyArrayIndex, nullIndex; + var emptyArrayIndex, failIndex; function buildElementsCode(elements, context) { var processedCount, functionIndex; @@ -381,7 +381,7 @@ module.exports = function(ast, options) { buildSequence( processedCount > 1 ? [op.POP_N, processedCount] : [op.POP], [op.POP_CURR_POS], - [op.PUSH, nullIndex] + [op.PUSH, failedIndex] ) ) ); @@ -409,7 +409,7 @@ module.exports = function(ast, options) { } if (node.elements.length > 0) { - nullIndex = addConst('null'); + failedIndex = addConst('peg$FAILED'); return buildSequence( [op.PUSH_CURR_POS], @@ -500,7 +500,7 @@ module.exports = function(ast, options) { one_or_more: function(node, context) { var emptyArrayIndex = addConst('[]'); - nullIndex = addConst('null'); + failedIndex = addConst('peg$FAILED'); expressionCode = generate(node.expression, { sp: context.sp + 1, env: { }, @@ -513,7 +513,7 @@ module.exports = function(ast, options) { buildCondition( [op.IF_NOT_ERROR], buildSequence(buildAppendLoop(expressionCode), [op.POP]), - buildSequence([op.POP], [op.POP], [op.PUSH, nullIndex]) + buildSequence([op.POP], [op.POP], [op.PUSH, failedIndex]) ) ); }, diff --git a/lib/compiler/passes/generate-javascript.js b/lib/compiler/passes/generate-javascript.js index d463f11..fadd891 100644 --- a/lib/compiler/passes/generate-javascript.js +++ b/lib/compiler/passes/generate-javascript.js @@ -223,18 +223,18 @@ module.exports = function(ast, options) { '', ' case ' + op.IF_ERROR + ':', // IF_ERROR t, f indent10(generateCondition( - 'stack[stack.length - 1] === null', + 'stack[stack.length - 1] === peg$FAILED', 0 )), '', ' case ' + op.IF_NOT_ERROR + ':', // IF_NOT_ERROR t, f indent10( - generateCondition('stack[stack.length - 1] !== null', + generateCondition('stack[stack.length - 1] !== peg$FAILED', 0 )), '', ' case ' + op.WHILE_NOT_ERROR + ':', // WHILE_NOT_ERROR b - indent10(generateLoop('stack[stack.length - 1] !== null')), + indent10(generateLoop('stack[stack.length - 1] !== peg$FAILED')), '', ' case ' + op.MATCH_ANY + ':', // MATCH_ANY a, f, ... indent10(generateCondition('input.length > peg$currPos', 0)), @@ -270,7 +270,7 @@ module.exports = function(ast, options) { ' break;', '', ' case ' + op.FAIL + ':', // FAIL e - ' stack.push(null);', + ' stack.push(peg$FAILED);', ' if (peg$silentFails === 0) {', ' peg$fail(peg$consts[bc[ip + 1]]);', ' }', @@ -515,15 +515,15 @@ module.exports = function(ast, options) { break; case op.IF_ERROR: // IF_ERROR t, f - compileCondition(stack.top() + ' === null', 0); + compileCondition(stack.top() + ' === peg$FAILED', 0); break; case op.IF_NOT_ERROR: // IF_NOT_ERROR t, f - compileCondition(stack.top() + ' !== null', 0); + compileCondition(stack.top() + ' !== peg$FAILED', 0); break; case op.WHILE_NOT_ERROR: // WHILE_NOT_ERROR b - compileLoop(stack.top() + ' !== null', 0); + compileLoop(stack.top() + ' !== peg$FAILED', 0); break; case op.MATCH_ANY: // MATCH_ANY a, f, ... @@ -585,7 +585,7 @@ module.exports = function(ast, options) { break; case op.FAIL: // FAIL e - parts.push(stack.push('null')); + parts.push(stack.push('peg$FAILED')); parts.push('if (peg$silentFails === 0) { peg$fail(' + c(bc[ip + 1]) + '); }'); ip += 2; break; @@ -745,6 +745,8 @@ module.exports = function(ast, options) { '', ' function parse(input) {', ' var options = arguments.length > 1 ? arguments[1] : {},', + '', + ' peg$FAILED = {},', '' ].join('\n')); @@ -937,7 +939,7 @@ module.exports = function(ast, options) { parts.push([ '', - ' if (peg$result !== null && peg$currPos === input.length) {', + ' if (peg$result !== peg$FAILED && peg$currPos === input.length) {', ' return peg$result;', ' } else {', ' peg$cleanupExpected(peg$maxFailExpected);', diff --git a/lib/parser.js b/lib/parser.js index ab6b1cf..ded3551 100644 --- a/lib/parser.js +++ b/lib/parser.js @@ -73,10 +73,12 @@ module.exports = (function() { function parse(input) { var options = arguments.length > 1 ? arguments[1] : {}, + peg$FAILED = {}, + peg$startRuleFunctions = { grammar: peg$parsegrammar }, peg$startRuleFunction = peg$parsegrammar, - peg$c0 = null, + peg$c0 = peg$FAILED, peg$c1 = "", peg$c2 = [], peg$c3 = function(initializer, rules) { @@ -482,26 +484,26 @@ module.exports = (function() { s0 = peg$currPos; s1 = peg$parse__(); - if (s1 !== null) { + if (s1 !== peg$FAILED) { s2 = peg$parseinitializer(); - if (s2 === null) { + if (s2 === peg$FAILED) { s2 = peg$c1; } - if (s2 !== null) { + if (s2 !== peg$FAILED) { s3 = []; s4 = peg$parserule(); - if (s4 !== null) { - while (s4 !== null) { + if (s4 !== peg$FAILED) { + while (s4 !== peg$FAILED) { s3.push(s4); s4 = peg$parserule(); } } else { s3 = peg$c0; } - if (s3 !== null) { + if (s3 !== peg$FAILED) { peg$reportedPos = s0; s1 = peg$c3(s2, s3); - if (s1 === null) { + if (s1 === peg$FAILED) { peg$currPos = s0; s0 = s1; } else { @@ -528,15 +530,15 @@ module.exports = (function() { s0 = peg$currPos; s1 = peg$parseaction(); - if (s1 !== null) { + if (s1 !== peg$FAILED) { s2 = peg$parsesemicolon(); - if (s2 === null) { + if (s2 === peg$FAILED) { s2 = peg$c1; } - if (s2 !== null) { + if (s2 !== peg$FAILED) { peg$reportedPos = s0; s1 = peg$c4(s1); - if (s1 === null) { + if (s1 === peg$FAILED) { peg$currPos = s0; s0 = s1; } else { @@ -559,24 +561,24 @@ module.exports = (function() { s0 = peg$currPos; s1 = peg$parseidentifier(); - if (s1 !== null) { + if (s1 !== peg$FAILED) { s2 = peg$parsestring(); - if (s2 === null) { + if (s2 === peg$FAILED) { s2 = peg$c1; } - if (s2 !== null) { + if (s2 !== peg$FAILED) { s3 = peg$parseequals(); - if (s3 !== null) { + if (s3 !== peg$FAILED) { s4 = peg$parsechoice(); - if (s4 !== null) { + if (s4 !== peg$FAILED) { s5 = peg$parsesemicolon(); - if (s5 === null) { + if (s5 === peg$FAILED) { s5 = peg$c1; } - if (s5 !== null) { + if (s5 !== peg$FAILED) { peg$reportedPos = s0; s1 = peg$c5(s1, s2, s4); - if (s1 === null) { + if (s1 === peg$FAILED) { peg$currPos = s0; s0 = s1; } else { @@ -611,13 +613,13 @@ module.exports = (function() { s0 = peg$currPos; s1 = peg$parsesequence(); - if (s1 !== null) { + if (s1 !== peg$FAILED) { s2 = []; s3 = peg$currPos; s4 = peg$parseslash(); - if (s4 !== null) { + if (s4 !== peg$FAILED) { s5 = peg$parsesequence(); - if (s5 !== null) { + if (s5 !== peg$FAILED) { s4 = [s4, s5]; s3 = s4; } else { @@ -628,13 +630,13 @@ module.exports = (function() { peg$currPos = s3; s3 = peg$c0; } - while (s3 !== null) { + while (s3 !== peg$FAILED) { s2.push(s3); s3 = peg$currPos; s4 = peg$parseslash(); - if (s4 !== null) { + if (s4 !== peg$FAILED) { s5 = peg$parsesequence(); - if (s5 !== null) { + if (s5 !== peg$FAILED) { s4 = [s4, s5]; s3 = s4; } else { @@ -646,10 +648,10 @@ module.exports = (function() { s3 = peg$c0; } } - if (s2 !== null) { + if (s2 !== peg$FAILED) { peg$reportedPos = s0; s1 = peg$c6(s1, s2); - if (s1 === null) { + if (s1 === peg$FAILED) { peg$currPos = s0; s0 = s1; } else { @@ -673,16 +675,16 @@ module.exports = (function() { s0 = peg$currPos; s1 = []; s2 = peg$parselabeled(); - while (s2 !== null) { + while (s2 !== peg$FAILED) { s1.push(s2); s2 = peg$parselabeled(); } - if (s1 !== null) { + if (s1 !== peg$FAILED) { s2 = peg$parseaction(); - if (s2 !== null) { + if (s2 !== peg$FAILED) { peg$reportedPos = s0; s1 = peg$c7(s1, s2); - if (s1 === null) { + if (s1 === peg$FAILED) { peg$currPos = s0; s0 = s1; } else { @@ -696,19 +698,19 @@ module.exports = (function() { peg$currPos = s0; s0 = peg$c0; } - if (s0 === null) { + if (s0 === peg$FAILED) { s0 = peg$currPos; s1 = []; s2 = peg$parselabeled(); - while (s2 !== null) { + while (s2 !== peg$FAILED) { s1.push(s2); s2 = peg$parselabeled(); } - if (s1 !== null) { + if (s1 !== peg$FAILED) { peg$reportedPos = s0; s1 = peg$c8(s1); } - if (s1 === null) { + if (s1 === peg$FAILED) { peg$currPos = s0; s0 = s1; } else { @@ -724,14 +726,14 @@ module.exports = (function() { s0 = peg$currPos; s1 = peg$parseidentifier(); - if (s1 !== null) { + if (s1 !== peg$FAILED) { s2 = peg$parsecolon(); - if (s2 !== null) { + if (s2 !== peg$FAILED) { s3 = peg$parseprefixed(); - if (s3 !== null) { + if (s3 !== peg$FAILED) { peg$reportedPos = s0; s1 = peg$c9(s1, s3); - if (s1 === null) { + if (s1 === peg$FAILED) { peg$currPos = s0; s0 = s1; } else { @@ -749,7 +751,7 @@ module.exports = (function() { peg$currPos = s0; s0 = peg$c0; } - if (s0 === null) { + if (s0 === peg$FAILED) { s0 = peg$parseprefixed(); } @@ -761,12 +763,12 @@ module.exports = (function() { s0 = peg$currPos; s1 = peg$parsedollar(); - if (s1 !== null) { + if (s1 !== peg$FAILED) { s2 = peg$parsesuffixed(); - if (s2 !== null) { + if (s2 !== peg$FAILED) { peg$reportedPos = s0; s1 = peg$c10(s2); - if (s1 === null) { + if (s1 === peg$FAILED) { peg$currPos = s0; s0 = s1; } else { @@ -780,15 +782,15 @@ module.exports = (function() { peg$currPos = s0; s0 = peg$c0; } - if (s0 === null) { + if (s0 === peg$FAILED) { s0 = peg$currPos; s1 = peg$parseand(); - if (s1 !== null) { + if (s1 !== peg$FAILED) { s2 = peg$parseaction(); - if (s2 !== null) { + if (s2 !== peg$FAILED) { peg$reportedPos = s0; s1 = peg$c11(s2); - if (s1 === null) { + if (s1 === peg$FAILED) { peg$currPos = s0; s0 = s1; } else { @@ -802,15 +804,15 @@ module.exports = (function() { peg$currPos = s0; s0 = peg$c0; } - if (s0 === null) { + if (s0 === peg$FAILED) { s0 = peg$currPos; s1 = peg$parseand(); - if (s1 !== null) { + if (s1 !== peg$FAILED) { s2 = peg$parsesuffixed(); - if (s2 !== null) { + if (s2 !== peg$FAILED) { peg$reportedPos = s0; s1 = peg$c12(s2); - if (s1 === null) { + if (s1 === peg$FAILED) { peg$currPos = s0; s0 = s1; } else { @@ -824,15 +826,15 @@ module.exports = (function() { peg$currPos = s0; s0 = peg$c0; } - if (s0 === null) { + if (s0 === peg$FAILED) { s0 = peg$currPos; s1 = peg$parsenot(); - if (s1 !== null) { + if (s1 !== peg$FAILED) { s2 = peg$parseaction(); - if (s2 !== null) { + if (s2 !== peg$FAILED) { peg$reportedPos = s0; s1 = peg$c13(s2); - if (s1 === null) { + if (s1 === peg$FAILED) { peg$currPos = s0; s0 = s1; } else { @@ -846,15 +848,15 @@ module.exports = (function() { peg$currPos = s0; s0 = peg$c0; } - if (s0 === null) { + if (s0 === peg$FAILED) { s0 = peg$currPos; s1 = peg$parsenot(); - if (s1 !== null) { + if (s1 !== peg$FAILED) { s2 = peg$parsesuffixed(); - if (s2 !== null) { + if (s2 !== peg$FAILED) { peg$reportedPos = s0; s1 = peg$c14(s2); - if (s1 === null) { + if (s1 === peg$FAILED) { peg$currPos = s0; s0 = s1; } else { @@ -868,7 +870,7 @@ module.exports = (function() { peg$currPos = s0; s0 = peg$c0; } - if (s0 === null) { + if (s0 === peg$FAILED) { s0 = peg$parsesuffixed(); } } @@ -884,12 +886,12 @@ module.exports = (function() { s0 = peg$currPos; s1 = peg$parseprimary(); - if (s1 !== null) { + if (s1 !== peg$FAILED) { s2 = peg$parsequestion(); - if (s2 !== null) { + if (s2 !== peg$FAILED) { peg$reportedPos = s0; s1 = peg$c15(s1); - if (s1 === null) { + if (s1 === peg$FAILED) { peg$currPos = s0; s0 = s1; } else { @@ -903,15 +905,15 @@ module.exports = (function() { peg$currPos = s0; s0 = peg$c0; } - if (s0 === null) { + if (s0 === peg$FAILED) { s0 = peg$currPos; s1 = peg$parseprimary(); - if (s1 !== null) { + if (s1 !== peg$FAILED) { s2 = peg$parsestar(); - if (s2 !== null) { + if (s2 !== peg$FAILED) { peg$reportedPos = s0; s1 = peg$c16(s1); - if (s1 === null) { + if (s1 === peg$FAILED) { peg$currPos = s0; s0 = s1; } else { @@ -925,15 +927,15 @@ module.exports = (function() { peg$currPos = s0; s0 = peg$c0; } - if (s0 === null) { + if (s0 === peg$FAILED) { s0 = peg$currPos; s1 = peg$parseprimary(); - if (s1 !== null) { + if (s1 !== peg$FAILED) { s2 = peg$parseplus(); - if (s2 !== null) { + if (s2 !== peg$FAILED) { peg$reportedPos = s0; s1 = peg$c17(s1); - if (s1 === null) { + if (s1 === peg$FAILED) { peg$currPos = s0; s0 = s1; } else { @@ -947,7 +949,7 @@ module.exports = (function() { peg$currPos = s0; s0 = peg$c0; } - if (s0 === null) { + if (s0 === peg$FAILED) { s0 = peg$parseprimary(); } } @@ -961,17 +963,17 @@ module.exports = (function() { s0 = peg$currPos; s1 = peg$parseidentifier(); - if (s1 !== null) { + if (s1 !== peg$FAILED) { s2 = peg$currPos; peg$silentFails++; s3 = peg$currPos; s4 = peg$parsestring(); - if (s4 === null) { + if (s4 === peg$FAILED) { s4 = peg$c1; } - if (s4 !== null) { + if (s4 !== peg$FAILED) { s5 = peg$parseequals(); - if (s5 !== null) { + if (s5 !== peg$FAILED) { s4 = [s4, s5]; s3 = s4; } else { @@ -983,16 +985,16 @@ module.exports = (function() { s3 = peg$c0; } peg$silentFails--; - if (s3 === null) { + if (s3 === peg$FAILED) { s2 = peg$c1; } else { peg$currPos = s2; s2 = peg$c0; } - if (s2 !== null) { + if (s2 !== peg$FAILED) { peg$reportedPos = s0; s1 = peg$c18(s1); - if (s1 === null) { + if (s1 === peg$FAILED) { peg$currPos = s0; s0 = s1; } else { @@ -1006,34 +1008,34 @@ module.exports = (function() { peg$currPos = s0; s0 = peg$c0; } - if (s0 === null) { + if (s0 === peg$FAILED) { s0 = peg$parseliteral(); - if (s0 === null) { + if (s0 === peg$FAILED) { s0 = peg$parseclass(); - if (s0 === null) { + if (s0 === peg$FAILED) { s0 = peg$currPos; s1 = peg$parsedot(); - if (s1 !== null) { + if (s1 !== peg$FAILED) { peg$reportedPos = s0; s1 = peg$c19(); } - if (s1 === null) { + if (s1 === peg$FAILED) { peg$currPos = s0; s0 = s1; } else { s0 = s1; } - if (s0 === null) { + if (s0 === peg$FAILED) { s0 = peg$currPos; s1 = peg$parselparen(); - if (s1 !== null) { + if (s1 !== peg$FAILED) { s2 = peg$parsechoice(); - if (s2 !== null) { + if (s2 !== peg$FAILED) { s3 = peg$parserparen(); - if (s3 !== null) { + if (s3 !== peg$FAILED) { peg$reportedPos = s0; s1 = peg$c20(s2); - if (s1 === null) { + if (s1 === peg$FAILED) { peg$currPos = s0; s0 = s1; } else { @@ -1065,12 +1067,12 @@ module.exports = (function() { peg$silentFails++; s0 = peg$currPos; s1 = peg$parsebraced(); - if (s1 !== null) { + if (s1 !== peg$FAILED) { s2 = peg$parse__(); - if (s2 !== null) { + if (s2 !== peg$FAILED) { peg$reportedPos = s0; s1 = peg$c22(s1); - if (s1 === null) { + if (s1 === peg$FAILED) { peg$currPos = s0; s0 = s1; } else { @@ -1085,8 +1087,8 @@ module.exports = (function() { s0 = peg$c0; } peg$silentFails--; - if (s0 === null) { - s1 = null; + if (s0 === peg$FAILED) { + s1 = peg$FAILED; if (peg$silentFails === 0) { peg$fail(peg$c21); } } @@ -1102,31 +1104,31 @@ module.exports = (function() { s2 = peg$c23; peg$currPos++; } else { - s2 = null; + s2 = peg$FAILED; if (peg$silentFails === 0) { peg$fail(peg$c24); } } - if (s2 !== null) { + if (s2 !== peg$FAILED) { s3 = []; s4 = peg$parsebraced(); - if (s4 === null) { + if (s4 === peg$FAILED) { s4 = peg$parsenonBraceCharacters(); } - while (s4 !== null) { + while (s4 !== peg$FAILED) { s3.push(s4); s4 = peg$parsebraced(); - if (s4 === null) { + if (s4 === peg$FAILED) { s4 = peg$parsenonBraceCharacters(); } } - if (s3 !== null) { + if (s3 !== peg$FAILED) { if (input.charCodeAt(peg$currPos) === 125) { s4 = peg$c25; peg$currPos++; } else { - s4 = null; + s4 = peg$FAILED; if (peg$silentFails === 0) { peg$fail(peg$c26); } } - if (s4 !== null) { + if (s4 !== peg$FAILED) { s2 = [s2, s3, s4]; s1 = s2; } else { @@ -1141,7 +1143,7 @@ module.exports = (function() { peg$currPos = s1; s1 = peg$c0; } - if (s1 !== null) { + if (s1 !== peg$FAILED) { s1 = input.substring(s0, peg$currPos); } s0 = s1; @@ -1154,8 +1156,8 @@ module.exports = (function() { s0 = []; s1 = peg$parsenonBraceCharacter(); - if (s1 !== null) { - while (s1 !== null) { + if (s1 !== peg$FAILED) { + while (s1 !== peg$FAILED) { s0.push(s1); s1 = peg$parsenonBraceCharacter(); } @@ -1173,7 +1175,7 @@ module.exports = (function() { s0 = input.charAt(peg$currPos); peg$currPos++; } else { - s0 = null; + s0 = peg$FAILED; if (peg$silentFails === 0) { peg$fail(peg$c28); } } @@ -1188,15 +1190,15 @@ module.exports = (function() { s1 = peg$c29; peg$currPos++; } else { - s1 = null; + s1 = peg$FAILED; if (peg$silentFails === 0) { peg$fail(peg$c30); } } - if (s1 !== null) { + if (s1 !== peg$FAILED) { s2 = peg$parse__(); - if (s2 !== null) { + if (s2 !== peg$FAILED) { peg$reportedPos = s0; s1 = peg$c31(); - if (s1 === null) { + if (s1 === peg$FAILED) { peg$currPos = s0; s0 = s1; } else { @@ -1222,15 +1224,15 @@ module.exports = (function() { s1 = peg$c32; peg$currPos++; } else { - s1 = null; + s1 = peg$FAILED; if (peg$silentFails === 0) { peg$fail(peg$c33); } } - if (s1 !== null) { + if (s1 !== peg$FAILED) { s2 = peg$parse__(); - if (s2 !== null) { + if (s2 !== peg$FAILED) { peg$reportedPos = s0; s1 = peg$c34(); - if (s1 === null) { + if (s1 === peg$FAILED) { peg$currPos = s0; s0 = s1; } else { @@ -1256,15 +1258,15 @@ module.exports = (function() { s1 = peg$c35; peg$currPos++; } else { - s1 = null; + s1 = peg$FAILED; if (peg$silentFails === 0) { peg$fail(peg$c36); } } - if (s1 !== null) { + if (s1 !== peg$FAILED) { s2 = peg$parse__(); - if (s2 !== null) { + if (s2 !== peg$FAILED) { peg$reportedPos = s0; s1 = peg$c37(); - if (s1 === null) { + if (s1 === peg$FAILED) { peg$currPos = s0; s0 = s1; } else { @@ -1290,15 +1292,15 @@ module.exports = (function() { s1 = peg$c38; peg$currPos++; } else { - s1 = null; + s1 = peg$FAILED; if (peg$silentFails === 0) { peg$fail(peg$c39); } } - if (s1 !== null) { + if (s1 !== peg$FAILED) { s2 = peg$parse__(); - if (s2 !== null) { + if (s2 !== peg$FAILED) { peg$reportedPos = s0; s1 = peg$c40(); - if (s1 === null) { + if (s1 === peg$FAILED) { peg$currPos = s0; s0 = s1; } else { @@ -1324,15 +1326,15 @@ module.exports = (function() { s1 = peg$c41; peg$currPos++; } else { - s1 = null; + s1 = peg$FAILED; if (peg$silentFails === 0) { peg$fail(peg$c42); } } - if (s1 !== null) { + if (s1 !== peg$FAILED) { s2 = peg$parse__(); - if (s2 !== null) { + if (s2 !== peg$FAILED) { peg$reportedPos = s0; s1 = peg$c43(); - if (s1 === null) { + if (s1 === peg$FAILED) { peg$currPos = s0; s0 = s1; } else { @@ -1358,15 +1360,15 @@ module.exports = (function() { s1 = peg$c44; peg$currPos++; } else { - s1 = null; + s1 = peg$FAILED; if (peg$silentFails === 0) { peg$fail(peg$c45); } } - if (s1 !== null) { + if (s1 !== peg$FAILED) { s2 = peg$parse__(); - if (s2 !== null) { + if (s2 !== peg$FAILED) { peg$reportedPos = s0; s1 = peg$c46(); - if (s1 === null) { + if (s1 === peg$FAILED) { peg$currPos = s0; s0 = s1; } else { @@ -1392,15 +1394,15 @@ module.exports = (function() { s1 = peg$c47; peg$currPos++; } else { - s1 = null; + s1 = peg$FAILED; if (peg$silentFails === 0) { peg$fail(peg$c48); } } - if (s1 !== null) { + if (s1 !== peg$FAILED) { s2 = peg$parse__(); - if (s2 !== null) { + if (s2 !== peg$FAILED) { peg$reportedPos = s0; s1 = peg$c49(); - if (s1 === null) { + if (s1 === peg$FAILED) { peg$currPos = s0; s0 = s1; } else { @@ -1426,15 +1428,15 @@ module.exports = (function() { s1 = peg$c50; peg$currPos++; } else { - s1 = null; + s1 = peg$FAILED; if (peg$silentFails === 0) { peg$fail(peg$c51); } } - if (s1 !== null) { + if (s1 !== peg$FAILED) { s2 = peg$parse__(); - if (s2 !== null) { + if (s2 !== peg$FAILED) { peg$reportedPos = s0; s1 = peg$c52(); - if (s1 === null) { + if (s1 === peg$FAILED) { peg$currPos = s0; s0 = s1; } else { @@ -1460,15 +1462,15 @@ module.exports = (function() { s1 = peg$c53; peg$currPos++; } else { - s1 = null; + s1 = peg$FAILED; if (peg$silentFails === 0) { peg$fail(peg$c54); } } - if (s1 !== null) { + if (s1 !== peg$FAILED) { s2 = peg$parse__(); - if (s2 !== null) { + if (s2 !== peg$FAILED) { peg$reportedPos = s0; s1 = peg$c55(); - if (s1 === null) { + if (s1 === peg$FAILED) { peg$currPos = s0; s0 = s1; } else { @@ -1494,15 +1496,15 @@ module.exports = (function() { s1 = peg$c56; peg$currPos++; } else { - s1 = null; + s1 = peg$FAILED; if (peg$silentFails === 0) { peg$fail(peg$c57); } } - if (s1 !== null) { + if (s1 !== peg$FAILED) { s2 = peg$parse__(); - if (s2 !== null) { + if (s2 !== peg$FAILED) { peg$reportedPos = s0; s1 = peg$c58(); - if (s1 === null) { + if (s1 === peg$FAILED) { peg$currPos = s0; s0 = s1; } else { @@ -1528,15 +1530,15 @@ module.exports = (function() { s1 = peg$c59; peg$currPos++; } else { - s1 = null; + s1 = peg$FAILED; if (peg$silentFails === 0) { peg$fail(peg$c60); } } - if (s1 !== null) { + if (s1 !== peg$FAILED) { s2 = peg$parse__(); - if (s2 !== null) { + if (s2 !== peg$FAILED) { peg$reportedPos = s0; s1 = peg$c61(); - if (s1 === null) { + if (s1 === peg$FAILED) { peg$currPos = s0; s0 = s1; } else { @@ -1562,15 +1564,15 @@ module.exports = (function() { s1 = peg$c62; peg$currPos++; } else { - s1 = null; + s1 = peg$FAILED; if (peg$silentFails === 0) { peg$fail(peg$c63); } } - if (s1 !== null) { + if (s1 !== peg$FAILED) { s2 = peg$parse__(); - if (s2 !== null) { + if (s2 !== peg$FAILED) { peg$reportedPos = s0; s1 = peg$c64(); - if (s1 === null) { + if (s1 === peg$FAILED) { peg$currPos = s0; s0 = s1; } else { @@ -1596,15 +1598,15 @@ module.exports = (function() { s1 = peg$c65; peg$currPos++; } else { - s1 = null; + s1 = peg$FAILED; if (peg$silentFails === 0) { peg$fail(peg$c66); } } - if (s1 !== null) { + if (s1 !== peg$FAILED) { s2 = peg$parse__(); - if (s2 !== null) { + if (s2 !== peg$FAILED) { peg$reportedPos = s0; s1 = peg$c67(); - if (s1 === null) { + if (s1 === peg$FAILED) { peg$currPos = s0; s0 = s1; } else { @@ -1630,47 +1632,47 @@ module.exports = (function() { s1 = peg$currPos; s2 = peg$currPos; s3 = peg$parseletter(); - if (s3 === null) { + if (s3 === peg$FAILED) { if (input.charCodeAt(peg$currPos) === 95) { s3 = peg$c69; peg$currPos++; } else { - s3 = null; + s3 = peg$FAILED; if (peg$silentFails === 0) { peg$fail(peg$c70); } } } - if (s3 !== null) { + if (s3 !== peg$FAILED) { s4 = []; s5 = peg$parseletter(); - if (s5 === null) { + if (s5 === peg$FAILED) { s5 = peg$parsedigit(); - if (s5 === null) { + if (s5 === peg$FAILED) { if (input.charCodeAt(peg$currPos) === 95) { s5 = peg$c69; peg$currPos++; } else { - s5 = null; + s5 = peg$FAILED; if (peg$silentFails === 0) { peg$fail(peg$c70); } } } } - while (s5 !== null) { + while (s5 !== peg$FAILED) { s4.push(s5); s5 = peg$parseletter(); - if (s5 === null) { + if (s5 === peg$FAILED) { s5 = peg$parsedigit(); - if (s5 === null) { + if (s5 === peg$FAILED) { if (input.charCodeAt(peg$currPos) === 95) { s5 = peg$c69; peg$currPos++; } else { - s5 = null; + s5 = peg$FAILED; if (peg$silentFails === 0) { peg$fail(peg$c70); } } } } } - if (s4 !== null) { + if (s4 !== peg$FAILED) { s3 = [s3, s4]; s2 = s3; } else { @@ -1681,16 +1683,16 @@ module.exports = (function() { peg$currPos = s2; s2 = peg$c0; } - if (s2 !== null) { + if (s2 !== peg$FAILED) { s2 = input.substring(s1, peg$currPos); } s1 = s2; - if (s1 !== null) { + if (s1 !== peg$FAILED) { s2 = peg$parse__(); - if (s2 !== null) { + if (s2 !== peg$FAILED) { peg$reportedPos = s0; s1 = peg$c71(s1); - if (s1 === null) { + if (s1 === peg$FAILED) { peg$currPos = s0; s0 = s1; } else { @@ -1705,8 +1707,8 @@ module.exports = (function() { s0 = peg$c0; } peg$silentFails--; - if (s0 === null) { - s1 = null; + if (s0 === peg$FAILED) { + s1 = peg$FAILED; if (peg$silentFails === 0) { peg$fail(peg$c68); } } @@ -1719,26 +1721,26 @@ module.exports = (function() { peg$silentFails++; s0 = peg$currPos; s1 = peg$parsedoubleQuotedString(); - if (s1 === null) { + if (s1 === peg$FAILED) { s1 = peg$parsesingleQuotedString(); } - if (s1 !== null) { + if (s1 !== peg$FAILED) { if (input.charCodeAt(peg$currPos) === 105) { s2 = peg$c73; peg$currPos++; } else { - s2 = null; + s2 = peg$FAILED; if (peg$silentFails === 0) { peg$fail(peg$c74); } } - if (s2 === null) { + if (s2 === peg$FAILED) { s2 = peg$c1; } - if (s2 !== null) { + if (s2 !== peg$FAILED) { s3 = peg$parse__(); - if (s3 !== null) { + if (s3 !== peg$FAILED) { peg$reportedPos = s0; s1 = peg$c75(s1, s2); - if (s1 === null) { + if (s1 === peg$FAILED) { peg$currPos = s0; s0 = s1; } else { @@ -1757,8 +1759,8 @@ module.exports = (function() { s0 = peg$c0; } peg$silentFails--; - if (s0 === null) { - s1 = null; + if (s0 === peg$FAILED) { + s1 = peg$FAILED; if (peg$silentFails === 0) { peg$fail(peg$c72); } } @@ -1771,15 +1773,15 @@ module.exports = (function() { peg$silentFails++; s0 = peg$currPos; s1 = peg$parsedoubleQuotedString(); - if (s1 === null) { + if (s1 === peg$FAILED) { s1 = peg$parsesingleQuotedString(); } - if (s1 !== null) { + if (s1 !== peg$FAILED) { s2 = peg$parse__(); - if (s2 !== null) { + if (s2 !== peg$FAILED) { peg$reportedPos = s0; s1 = peg$c77(s1); - if (s1 === null) { + if (s1 === peg$FAILED) { peg$currPos = s0; s0 = s1; } else { @@ -1794,8 +1796,8 @@ module.exports = (function() { s0 = peg$c0; } peg$silentFails--; - if (s0 === null) { - s1 = null; + if (s0 === peg$FAILED) { + s1 = peg$FAILED; if (peg$silentFails === 0) { peg$fail(peg$c76); } } @@ -1810,28 +1812,28 @@ module.exports = (function() { s1 = peg$c78; peg$currPos++; } else { - s1 = null; + s1 = peg$FAILED; if (peg$silentFails === 0) { peg$fail(peg$c79); } } - if (s1 !== null) { + if (s1 !== peg$FAILED) { s2 = []; s3 = peg$parsedoubleQuotedCharacter(); - while (s3 !== null) { + while (s3 !== peg$FAILED) { s2.push(s3); s3 = peg$parsedoubleQuotedCharacter(); } - if (s2 !== null) { + if (s2 !== peg$FAILED) { if (input.charCodeAt(peg$currPos) === 34) { s3 = peg$c78; peg$currPos++; } else { - s3 = null; + s3 = peg$FAILED; if (peg$silentFails === 0) { peg$fail(peg$c79); } } - if (s3 !== null) { + if (s3 !== peg$FAILED) { peg$reportedPos = s0; s1 = peg$c80(s2); - if (s1 === null) { + if (s1 === peg$FAILED) { peg$currPos = s0; s0 = s1; } else { @@ -1857,15 +1859,15 @@ module.exports = (function() { var s0; s0 = peg$parsesimpleDoubleQuotedCharacter(); - if (s0 === null) { + if (s0 === peg$FAILED) { s0 = peg$parsesimpleEscapeSequence(); - if (s0 === null) { + if (s0 === peg$FAILED) { s0 = peg$parsezeroEscapeSequence(); - if (s0 === null) { + if (s0 === peg$FAILED) { s0 = peg$parsehexEscapeSequence(); - if (s0 === null) { + if (s0 === peg$FAILED) { s0 = peg$parseunicodeEscapeSequence(); - if (s0 === null) { + if (s0 === peg$FAILED) { s0 = peg$parseeolEscapeSequence(); } } @@ -1886,40 +1888,40 @@ module.exports = (function() { s2 = peg$c78; peg$currPos++; } else { - s2 = null; + s2 = peg$FAILED; if (peg$silentFails === 0) { peg$fail(peg$c79); } } - if (s2 === null) { + if (s2 === peg$FAILED) { if (input.charCodeAt(peg$currPos) === 92) { s2 = peg$c81; peg$currPos++; } else { - s2 = null; + s2 = peg$FAILED; if (peg$silentFails === 0) { peg$fail(peg$c82); } } - if (s2 === null) { + if (s2 === peg$FAILED) { s2 = peg$parseeolChar(); } } peg$silentFails--; - if (s2 === null) { + if (s2 === peg$FAILED) { s1 = peg$c1; } else { peg$currPos = s1; s1 = peg$c0; } - if (s1 !== null) { + if (s1 !== peg$FAILED) { if (input.length > peg$currPos) { s2 = input.charAt(peg$currPos); peg$currPos++; } else { - s2 = null; + s2 = peg$FAILED; if (peg$silentFails === 0) { peg$fail(peg$c83); } } - if (s2 !== null) { + if (s2 !== peg$FAILED) { peg$reportedPos = s0; s1 = peg$c84(s2); - if (s1 === null) { + if (s1 === peg$FAILED) { peg$currPos = s0; s0 = s1; } else { @@ -1945,28 +1947,28 @@ module.exports = (function() { s1 = peg$c85; peg$currPos++; } else { - s1 = null; + s1 = peg$FAILED; if (peg$silentFails === 0) { peg$fail(peg$c86); } } - if (s1 !== null) { + if (s1 !== peg$FAILED) { s2 = []; s3 = peg$parsesingleQuotedCharacter(); - while (s3 !== null) { + while (s3 !== peg$FAILED) { s2.push(s3); s3 = peg$parsesingleQuotedCharacter(); } - if (s2 !== null) { + if (s2 !== peg$FAILED) { if (input.charCodeAt(peg$currPos) === 39) { s3 = peg$c85; peg$currPos++; } else { - s3 = null; + s3 = peg$FAILED; if (peg$silentFails === 0) { peg$fail(peg$c86); } } - if (s3 !== null) { + if (s3 !== peg$FAILED) { peg$reportedPos = s0; s1 = peg$c80(s2); - if (s1 === null) { + if (s1 === peg$FAILED) { peg$currPos = s0; s0 = s1; } else { @@ -1992,15 +1994,15 @@ module.exports = (function() { var s0; s0 = peg$parsesimpleSingleQuotedCharacter(); - if (s0 === null) { + if (s0 === peg$FAILED) { s0 = peg$parsesimpleEscapeSequence(); - if (s0 === null) { + if (s0 === peg$FAILED) { s0 = peg$parsezeroEscapeSequence(); - if (s0 === null) { + if (s0 === peg$FAILED) { s0 = peg$parsehexEscapeSequence(); - if (s0 === null) { + if (s0 === peg$FAILED) { s0 = peg$parseunicodeEscapeSequence(); - if (s0 === null) { + if (s0 === peg$FAILED) { s0 = peg$parseeolEscapeSequence(); } } @@ -2021,40 +2023,40 @@ module.exports = (function() { s2 = peg$c85; peg$currPos++; } else { - s2 = null; + s2 = peg$FAILED; if (peg$silentFails === 0) { peg$fail(peg$c86); } } - if (s2 === null) { + if (s2 === peg$FAILED) { if (input.charCodeAt(peg$currPos) === 92) { s2 = peg$c81; peg$currPos++; } else { - s2 = null; + s2 = peg$FAILED; if (peg$silentFails === 0) { peg$fail(peg$c82); } } - if (s2 === null) { + if (s2 === peg$FAILED) { s2 = peg$parseeolChar(); } } peg$silentFails--; - if (s2 === null) { + if (s2 === peg$FAILED) { s1 = peg$c1; } else { peg$currPos = s1; s1 = peg$c0; } - if (s1 !== null) { + if (s1 !== peg$FAILED) { if (input.length > peg$currPos) { s2 = input.charAt(peg$currPos); peg$currPos++; } else { - s2 = null; + s2 = peg$FAILED; if (peg$silentFails === 0) { peg$fail(peg$c83); } } - if (s2 !== null) { + if (s2 !== peg$FAILED) { peg$reportedPos = s0; s1 = peg$c84(s2); - if (s1 === null) { + if (s1 === peg$FAILED) { peg$currPos = s0; s0 = s1; } else { @@ -2081,58 +2083,58 @@ module.exports = (function() { s1 = peg$c88; peg$currPos++; } else { - s1 = null; + s1 = peg$FAILED; if (peg$silentFails === 0) { peg$fail(peg$c89); } } - if (s1 !== null) { + if (s1 !== peg$FAILED) { if (input.charCodeAt(peg$currPos) === 94) { s2 = peg$c90; peg$currPos++; } else { - s2 = null; + s2 = peg$FAILED; if (peg$silentFails === 0) { peg$fail(peg$c91); } } - if (s2 === null) { + if (s2 === peg$FAILED) { s2 = peg$c1; } - if (s2 !== null) { + if (s2 !== peg$FAILED) { s3 = []; s4 = peg$parseclassCharacterRange(); - if (s4 === null) { + if (s4 === peg$FAILED) { s4 = peg$parseclassCharacter(); } - while (s4 !== null) { + while (s4 !== peg$FAILED) { s3.push(s4); s4 = peg$parseclassCharacterRange(); - if (s4 === null) { + if (s4 === peg$FAILED) { s4 = peg$parseclassCharacter(); } } - if (s3 !== null) { + if (s3 !== peg$FAILED) { if (input.charCodeAt(peg$currPos) === 93) { s4 = peg$c92; peg$currPos++; } else { - s4 = null; + s4 = peg$FAILED; if (peg$silentFails === 0) { peg$fail(peg$c93); } } - if (s4 !== null) { + if (s4 !== peg$FAILED) { if (input.charCodeAt(peg$currPos) === 105) { s5 = peg$c73; peg$currPos++; } else { - s5 = null; + s5 = peg$FAILED; if (peg$silentFails === 0) { peg$fail(peg$c74); } } - if (s5 === null) { + if (s5 === peg$FAILED) { s5 = peg$c1; } - if (s5 !== null) { + if (s5 !== peg$FAILED) { s6 = peg$parse__(); - if (s6 !== null) { + if (s6 !== peg$FAILED) { peg$reportedPos = s0; s1 = peg$c94(s2, s3, s5); - if (s1 === null) { + if (s1 === peg$FAILED) { peg$currPos = s0; s0 = s1; } else { @@ -2163,8 +2165,8 @@ module.exports = (function() { s0 = peg$c0; } peg$silentFails--; - if (s0 === null) { - s1 = null; + if (s0 === peg$FAILED) { + s1 = peg$FAILED; if (peg$silentFails === 0) { peg$fail(peg$c87); } } @@ -2176,20 +2178,20 @@ module.exports = (function() { s0 = peg$currPos; s1 = peg$parseclassCharacter(); - if (s1 !== null) { + if (s1 !== peg$FAILED) { if (input.charCodeAt(peg$currPos) === 45) { s2 = peg$c95; peg$currPos++; } else { - s2 = null; + s2 = peg$FAILED; if (peg$silentFails === 0) { peg$fail(peg$c96); } } - if (s2 !== null) { + if (s2 !== peg$FAILED) { s3 = peg$parseclassCharacter(); - if (s3 !== null) { + if (s3 !== peg$FAILED) { peg$reportedPos = s0; s1 = peg$c97(s1, s3); - if (s1 === null) { + if (s1 === peg$FAILED) { peg$currPos = s0; s0 = s1; } else { @@ -2216,11 +2218,11 @@ module.exports = (function() { s0 = peg$currPos; s1 = peg$parsebracketDelimitedCharacter(); - if (s1 !== null) { + if (s1 !== peg$FAILED) { peg$reportedPos = s0; s1 = peg$c98(s1); } - if (s1 === null) { + if (s1 === peg$FAILED) { peg$currPos = s0; s0 = s1; } else { @@ -2234,15 +2236,15 @@ module.exports = (function() { var s0; s0 = peg$parsesimpleBracketDelimitedCharacter(); - if (s0 === null) { + if (s0 === peg$FAILED) { s0 = peg$parsesimpleEscapeSequence(); - if (s0 === null) { + if (s0 === peg$FAILED) { s0 = peg$parsezeroEscapeSequence(); - if (s0 === null) { + if (s0 === peg$FAILED) { s0 = peg$parsehexEscapeSequence(); - if (s0 === null) { + if (s0 === peg$FAILED) { s0 = peg$parseunicodeEscapeSequence(); - if (s0 === null) { + if (s0 === peg$FAILED) { s0 = peg$parseeolEscapeSequence(); } } @@ -2263,40 +2265,40 @@ module.exports = (function() { s2 = peg$c92; peg$currPos++; } else { - s2 = null; + s2 = peg$FAILED; if (peg$silentFails === 0) { peg$fail(peg$c93); } } - if (s2 === null) { + if (s2 === peg$FAILED) { if (input.charCodeAt(peg$currPos) === 92) { s2 = peg$c81; peg$currPos++; } else { - s2 = null; + s2 = peg$FAILED; if (peg$silentFails === 0) { peg$fail(peg$c82); } } - if (s2 === null) { + if (s2 === peg$FAILED) { s2 = peg$parseeolChar(); } } peg$silentFails--; - if (s2 === null) { + if (s2 === peg$FAILED) { s1 = peg$c1; } else { peg$currPos = s1; s1 = peg$c0; } - if (s1 !== null) { + if (s1 !== peg$FAILED) { if (input.length > peg$currPos) { s2 = input.charAt(peg$currPos); peg$currPos++; } else { - s2 = null; + s2 = peg$FAILED; if (peg$silentFails === 0) { peg$fail(peg$c83); } } - if (s2 !== null) { + if (s2 !== peg$FAILED) { peg$reportedPos = s0; s1 = peg$c84(s2); - if (s1 === null) { + if (s1 === peg$FAILED) { peg$currPos = s0; s0 = s1; } else { @@ -2322,53 +2324,53 @@ module.exports = (function() { s1 = peg$c81; peg$currPos++; } else { - s1 = null; + s1 = peg$FAILED; if (peg$silentFails === 0) { peg$fail(peg$c82); } } - if (s1 !== null) { + if (s1 !== peg$FAILED) { s2 = peg$currPos; peg$silentFails++; s3 = peg$parsedigit(); - if (s3 === null) { + if (s3 === peg$FAILED) { if (input.charCodeAt(peg$currPos) === 120) { s3 = peg$c99; peg$currPos++; } else { - s3 = null; + s3 = peg$FAILED; if (peg$silentFails === 0) { peg$fail(peg$c100); } } - if (s3 === null) { + if (s3 === peg$FAILED) { if (input.charCodeAt(peg$currPos) === 117) { s3 = peg$c101; peg$currPos++; } else { - s3 = null; + s3 = peg$FAILED; if (peg$silentFails === 0) { peg$fail(peg$c102); } } - if (s3 === null) { + if (s3 === peg$FAILED) { s3 = peg$parseeolChar(); } } } peg$silentFails--; - if (s3 === null) { + if (s3 === peg$FAILED) { s2 = peg$c1; } else { peg$currPos = s2; s2 = peg$c0; } - if (s2 !== null) { + if (s2 !== peg$FAILED) { if (input.length > peg$currPos) { s3 = input.charAt(peg$currPos); peg$currPos++; } else { - s3 = null; + s3 = peg$FAILED; if (peg$silentFails === 0) { peg$fail(peg$c83); } } - if (s3 !== null) { + if (s3 !== peg$FAILED) { peg$reportedPos = s0; s1 = peg$c103(s3); - if (s1 === null) { + if (s1 === peg$FAILED) { peg$currPos = s0; s0 = s1; } else { @@ -2398,24 +2400,24 @@ module.exports = (function() { s1 = peg$c104; peg$currPos += 2; } else { - s1 = null; + s1 = peg$FAILED; if (peg$silentFails === 0) { peg$fail(peg$c105); } } - if (s1 !== null) { + if (s1 !== peg$FAILED) { s2 = peg$currPos; peg$silentFails++; s3 = peg$parsedigit(); peg$silentFails--; - if (s3 === null) { + if (s3 === peg$FAILED) { s2 = peg$c1; } else { peg$currPos = s2; s2 = peg$c0; } - if (s2 !== null) { + if (s2 !== peg$FAILED) { peg$reportedPos = s0; s1 = peg$c106(); - if (s1 === null) { + if (s1 === peg$FAILED) { peg$currPos = s0; s0 = s1; } else { @@ -2441,16 +2443,16 @@ module.exports = (function() { s1 = peg$c107; peg$currPos += 2; } else { - s1 = null; + s1 = peg$FAILED; if (peg$silentFails === 0) { peg$fail(peg$c108); } } - if (s1 !== null) { + if (s1 !== peg$FAILED) { s2 = peg$currPos; s3 = peg$currPos; s4 = peg$parsehexDigit(); - if (s4 !== null) { + if (s4 !== peg$FAILED) { s5 = peg$parsehexDigit(); - if (s5 !== null) { + if (s5 !== peg$FAILED) { s4 = [s4, s5]; s3 = s4; } else { @@ -2461,14 +2463,14 @@ module.exports = (function() { peg$currPos = s3; s3 = peg$c0; } - if (s3 !== null) { + if (s3 !== peg$FAILED) { s3 = input.substring(s2, peg$currPos); } s2 = s3; - if (s2 !== null) { + if (s2 !== peg$FAILED) { peg$reportedPos = s0; s1 = peg$c109(s2); - if (s1 === null) { + if (s1 === peg$FAILED) { peg$currPos = s0; s0 = s1; } else { @@ -2494,20 +2496,20 @@ module.exports = (function() { s1 = peg$c110; peg$currPos += 2; } else { - s1 = null; + s1 = peg$FAILED; if (peg$silentFails === 0) { peg$fail(peg$c111); } } - if (s1 !== null) { + if (s1 !== peg$FAILED) { s2 = peg$currPos; s3 = peg$currPos; s4 = peg$parsehexDigit(); - if (s4 !== null) { + if (s4 !== peg$FAILED) { s5 = peg$parsehexDigit(); - if (s5 !== null) { + if (s5 !== peg$FAILED) { s6 = peg$parsehexDigit(); - if (s6 !== null) { + if (s6 !== peg$FAILED) { s7 = peg$parsehexDigit(); - if (s7 !== null) { + if (s7 !== peg$FAILED) { s4 = [s4, s5, s6, s7]; s3 = s4; } else { @@ -2526,14 +2528,14 @@ module.exports = (function() { peg$currPos = s3; s3 = peg$c0; } - if (s3 !== null) { + if (s3 !== peg$FAILED) { s3 = input.substring(s2, peg$currPos); } s2 = s3; - if (s2 !== null) { + if (s2 !== peg$FAILED) { peg$reportedPos = s0; s1 = peg$c109(s2); - if (s1 === null) { + if (s1 === peg$FAILED) { peg$currPos = s0; s0 = s1; } else { @@ -2559,15 +2561,15 @@ module.exports = (function() { s1 = peg$c81; peg$currPos++; } else { - s1 = null; + s1 = peg$FAILED; if (peg$silentFails === 0) { peg$fail(peg$c82); } } - if (s1 !== null) { + if (s1 !== peg$FAILED) { s2 = peg$parseeol(); - if (s2 !== null) { + if (s2 !== peg$FAILED) { peg$reportedPos = s0; s1 = peg$c112(s2); - if (s1 === null) { + if (s1 === peg$FAILED) { peg$currPos = s0; s0 = s1; } else { @@ -2592,7 +2594,7 @@ module.exports = (function() { s0 = input.charAt(peg$currPos); peg$currPos++; } else { - s0 = null; + s0 = peg$FAILED; if (peg$silentFails === 0) { peg$fail(peg$c114); } } @@ -2606,7 +2608,7 @@ module.exports = (function() { s0 = input.charAt(peg$currPos); peg$currPos++; } else { - s0 = null; + s0 = peg$FAILED; if (peg$silentFails === 0) { peg$fail(peg$c116); } } @@ -2617,7 +2619,7 @@ module.exports = (function() { var s0; s0 = peg$parselowerCaseLetter(); - if (s0 === null) { + if (s0 === peg$FAILED) { s0 = peg$parseupperCaseLetter(); } @@ -2631,7 +2633,7 @@ module.exports = (function() { s0 = input.charAt(peg$currPos); peg$currPos++; } else { - s0 = null; + s0 = peg$FAILED; if (peg$silentFails === 0) { peg$fail(peg$c118); } } @@ -2645,7 +2647,7 @@ module.exports = (function() { s0 = input.charAt(peg$currPos); peg$currPos++; } else { - s0 = null; + s0 = peg$FAILED; if (peg$silentFails === 0) { peg$fail(peg$c120); } } @@ -2657,18 +2659,18 @@ module.exports = (function() { s0 = []; s1 = peg$parsewhitespace(); - if (s1 === null) { + if (s1 === peg$FAILED) { s1 = peg$parseeol(); - if (s1 === null) { + if (s1 === peg$FAILED) { s1 = peg$parsecomment(); } } - while (s1 !== null) { + while (s1 !== peg$FAILED) { s0.push(s1); s1 = peg$parsewhitespace(); - if (s1 === null) { + if (s1 === peg$FAILED) { s1 = peg$parseeol(); - if (s1 === null) { + if (s1 === peg$FAILED) { s1 = peg$parsecomment(); } } @@ -2682,12 +2684,12 @@ module.exports = (function() { peg$silentFails++; s0 = peg$parsesingleLineComment(); - if (s0 === null) { + if (s0 === peg$FAILED) { s0 = peg$parsemultiLineComment(); } peg$silentFails--; - if (s0 === null) { - s1 = null; + if (s0 === peg$FAILED) { + s1 = peg$FAILED; if (peg$silentFails === 0) { peg$fail(peg$c121); } } @@ -2702,31 +2704,31 @@ module.exports = (function() { s1 = peg$c122; peg$currPos += 2; } else { - s1 = null; + s1 = peg$FAILED; if (peg$silentFails === 0) { peg$fail(peg$c123); } } - if (s1 !== null) { + if (s1 !== peg$FAILED) { s2 = []; s3 = peg$currPos; s4 = peg$currPos; peg$silentFails++; s5 = peg$parseeolChar(); peg$silentFails--; - if (s5 === null) { + if (s5 === peg$FAILED) { s4 = peg$c1; } else { peg$currPos = s4; s4 = peg$c0; } - if (s4 !== null) { + if (s4 !== peg$FAILED) { if (input.length > peg$currPos) { s5 = input.charAt(peg$currPos); peg$currPos++; } else { - s5 = null; + s5 = peg$FAILED; if (peg$silentFails === 0) { peg$fail(peg$c83); } } - if (s5 !== null) { + if (s5 !== peg$FAILED) { s4 = [s4, s5]; s3 = s4; } else { @@ -2737,28 +2739,28 @@ module.exports = (function() { peg$currPos = s3; s3 = peg$c0; } - while (s3 !== null) { + while (s3 !== peg$FAILED) { s2.push(s3); s3 = peg$currPos; s4 = peg$currPos; peg$silentFails++; s5 = peg$parseeolChar(); peg$silentFails--; - if (s5 === null) { + if (s5 === peg$FAILED) { s4 = peg$c1; } else { peg$currPos = s4; s4 = peg$c0; } - if (s4 !== null) { + if (s4 !== peg$FAILED) { if (input.length > peg$currPos) { s5 = input.charAt(peg$currPos); peg$currPos++; } else { - s5 = null; + s5 = peg$FAILED; if (peg$silentFails === 0) { peg$fail(peg$c83); } } - if (s5 !== null) { + if (s5 !== peg$FAILED) { s4 = [s4, s5]; s3 = s4; } else { @@ -2770,7 +2772,7 @@ module.exports = (function() { s3 = peg$c0; } } - if (s2 !== null) { + if (s2 !== peg$FAILED) { s1 = [s1, s2]; s0 = s1; } else { @@ -2793,10 +2795,10 @@ module.exports = (function() { s1 = peg$c124; peg$currPos += 2; } else { - s1 = null; + s1 = peg$FAILED; if (peg$silentFails === 0) { peg$fail(peg$c125); } } - if (s1 !== null) { + if (s1 !== peg$FAILED) { s2 = []; s3 = peg$currPos; s4 = peg$currPos; @@ -2805,25 +2807,25 @@ module.exports = (function() { s5 = peg$c126; peg$currPos += 2; } else { - s5 = null; + s5 = peg$FAILED; if (peg$silentFails === 0) { peg$fail(peg$c127); } } peg$silentFails--; - if (s5 === null) { + if (s5 === peg$FAILED) { s4 = peg$c1; } else { peg$currPos = s4; s4 = peg$c0; } - if (s4 !== null) { + if (s4 !== peg$FAILED) { if (input.length > peg$currPos) { s5 = input.charAt(peg$currPos); peg$currPos++; } else { - s5 = null; + s5 = peg$FAILED; if (peg$silentFails === 0) { peg$fail(peg$c83); } } - if (s5 !== null) { + if (s5 !== peg$FAILED) { s4 = [s4, s5]; s3 = s4; } else { @@ -2834,7 +2836,7 @@ module.exports = (function() { peg$currPos = s3; s3 = peg$c0; } - while (s3 !== null) { + while (s3 !== peg$FAILED) { s2.push(s3); s3 = peg$currPos; s4 = peg$currPos; @@ -2843,25 +2845,25 @@ module.exports = (function() { s5 = peg$c126; peg$currPos += 2; } else { - s5 = null; + s5 = peg$FAILED; if (peg$silentFails === 0) { peg$fail(peg$c127); } } peg$silentFails--; - if (s5 === null) { + if (s5 === peg$FAILED) { s4 = peg$c1; } else { peg$currPos = s4; s4 = peg$c0; } - if (s4 !== null) { + if (s4 !== peg$FAILED) { if (input.length > peg$currPos) { s5 = input.charAt(peg$currPos); peg$currPos++; } else { - s5 = null; + s5 = peg$FAILED; if (peg$silentFails === 0) { peg$fail(peg$c83); } } - if (s5 !== null) { + if (s5 !== peg$FAILED) { s4 = [s4, s5]; s3 = s4; } else { @@ -2873,15 +2875,15 @@ module.exports = (function() { s3 = peg$c0; } } - if (s2 !== null) { + if (s2 !== peg$FAILED) { if (input.substr(peg$currPos, 2) === peg$c126) { s3 = peg$c126; peg$currPos += 2; } else { - s3 = null; + s3 = peg$FAILED; if (peg$silentFails === 0) { peg$fail(peg$c127); } } - if (s3 !== null) { + if (s3 !== peg$FAILED) { s1 = [s1, s2, s3]; s0 = s1; } else { @@ -2908,39 +2910,39 @@ module.exports = (function() { s0 = peg$c129; peg$currPos++; } else { - s0 = null; + s0 = peg$FAILED; if (peg$silentFails === 0) { peg$fail(peg$c130); } } - if (s0 === null) { + if (s0 === peg$FAILED) { if (input.substr(peg$currPos, 2) === peg$c131) { s0 = peg$c131; peg$currPos += 2; } else { - s0 = null; + s0 = peg$FAILED; if (peg$silentFails === 0) { peg$fail(peg$c132); } } - if (s0 === null) { + if (s0 === peg$FAILED) { if (input.charCodeAt(peg$currPos) === 13) { s0 = peg$c133; peg$currPos++; } else { - s0 = null; + s0 = peg$FAILED; if (peg$silentFails === 0) { peg$fail(peg$c134); } } - if (s0 === null) { + if (s0 === peg$FAILED) { if (input.charCodeAt(peg$currPos) === 8232) { s0 = peg$c135; peg$currPos++; } else { - s0 = null; + s0 = peg$FAILED; if (peg$silentFails === 0) { peg$fail(peg$c136); } } - if (s0 === null) { + if (s0 === peg$FAILED) { if (input.charCodeAt(peg$currPos) === 8233) { s0 = peg$c137; peg$currPos++; } else { - s0 = null; + s0 = peg$FAILED; if (peg$silentFails === 0) { peg$fail(peg$c138); } } } @@ -2948,8 +2950,8 @@ module.exports = (function() { } } peg$silentFails--; - if (s0 === null) { - s1 = null; + if (s0 === peg$FAILED) { + s1 = peg$FAILED; if (peg$silentFails === 0) { peg$fail(peg$c128); } } @@ -2963,7 +2965,7 @@ module.exports = (function() { s0 = input.charAt(peg$currPos); peg$currPos++; } else { - s0 = null; + s0 = peg$FAILED; if (peg$silentFails === 0) { peg$fail(peg$c140); } } @@ -2978,12 +2980,12 @@ module.exports = (function() { s0 = input.charAt(peg$currPos); peg$currPos++; } else { - s0 = null; + s0 = peg$FAILED; if (peg$silentFails === 0) { peg$fail(peg$c143); } } peg$silentFails--; - if (s0 === null) { - s1 = null; + if (s0 === peg$FAILED) { + s1 = peg$FAILED; if (peg$silentFails === 0) { peg$fail(peg$c141); } } @@ -2996,7 +2998,7 @@ module.exports = (function() { peg$result = peg$startRuleFunction(); - if (peg$result !== null && peg$currPos === input.length) { + if (peg$result !== peg$FAILED && peg$currPos === input.length) { return peg$result; } else { peg$cleanupExpected(peg$maxFailExpected); diff --git a/spec/compiler/passes/generate-bytecode.spec.js b/spec/compiler/passes/generate-bytecode.spec.js index dd9d0d4..829b78b 100644 --- a/spec/compiler/passes/generate-bytecode.spec.js +++ b/spec/compiler/passes/generate-bytecode.spec.js @@ -163,7 +163,7 @@ describe("compiler pass |generateBytecode|", function() { it("defines correct constants", function() { expect(pass).toChangeAST(grammar, constsDetails([ - 'null', + 'peg$FAILED', '"a"', '{ type: "literal", value: "a", description: "\\"a\\"" }', '"b"', @@ -219,7 +219,7 @@ describe("compiler pass |generateBytecode|", function() { it("defines correct constants", function() { expect(pass).toChangeAST(grammar, constsDetails([ - 'null', + 'peg$FAILED', '"a"', '{ type: "literal", value: "a", description: "\\"a\\"" }', '"b"', @@ -273,7 +273,7 @@ describe("compiler pass |generateBytecode|", function() { it("defines correct constants", function() { expect(pass).toChangeAST(grammar, constsDetails([ '""', - 'null', + 'peg$FAILED', '"a"', '{ type: "literal", value: "a", description: "\\"a\\"" }' ])); @@ -302,7 +302,7 @@ describe("compiler pass |generateBytecode|", function() { it("defines correct constants", function() { expect(pass).toChangeAST(grammar, constsDetails([ '""', - 'null', + 'peg$FAILED', '"a"', '{ type: "literal", value: "a", description: "\\"a\\"" }' ])); @@ -328,7 +328,7 @@ describe("compiler pass |generateBytecode|", function() { it("defines correct constants", function() { expect(pass).toChangeAST( grammar, - constsDetails(['function() { code }', '""', 'null']) + constsDetails(['function() { code }', '""', 'peg$FAILED']) ); }); }); @@ -372,7 +372,7 @@ describe("compiler pass |generateBytecode|", function() { it("defines correct constants", function() { expect(pass).toChangeAST(grammar, constsDetails([ - 'null', + 'peg$FAILED', '"a"', '{ type: "literal", value: "a", description: "\\"a\\"" }', '"b"', @@ -405,7 +405,7 @@ describe("compiler pass |generateBytecode|", function() { it("defines correct constants", function() { expect(pass).toChangeAST( grammar, - constsDetails(['function() { code }', '""', 'null']) + constsDetails(['function() { code }', '""', 'peg$FAILED']) ); }); }); @@ -449,7 +449,7 @@ describe("compiler pass |generateBytecode|", function() { it("defines correct constants", function() { expect(pass).toChangeAST(grammar, constsDetails([ - 'null', + 'peg$FAILED', '"a"', '{ type: "literal", value: "a", description: "\\"a\\"" }', '"b"', @@ -528,7 +528,7 @@ describe("compiler pass |generateBytecode|", function() { it("defines correct constants", function() { expect(pass).toChangeAST(grammar, constsDetails([ '[]', - 'null', + 'peg$FAILED', '"a"', '{ type: "literal", value: "a", description: "\\"a\\"" }' ])); diff --git a/spec/generated-parser.spec.js b/spec/generated-parser.spec.js index 71eb211..f1912d4 100644 --- a/spec/generated-parser.spec.js +++ b/spec/generated-parser.spec.js @@ -266,18 +266,12 @@ describe("generated parser", function() { }); describe("action code", function() { - it("tranforms the expression result by returnung a non-|null| value", function() { + it("tranforms the expression result by returnung a value", function() { var parser = PEG.buildParser('start = "a" { return 42; }', options); expect(parser).toParse("a", 42); }); - it("causes match failure by returning |null|", function() { - var parser = PEG.buildParser('start = "a" { return null; }', options); - - expect(parser).toFailToParse("a"); - }); - it("is not called when the expression does not match", function() { var parser = PEG.buildParser( 'start = "a" { throw "Boom!"; } / "b"', @@ -360,15 +354,6 @@ describe("generated parser", function() { expect(parser).toParse("a", { a: 42 }, { a: 42 }); }); - - it("does not advance position when the expression matches but the action returns |null|", function() { - var parser = PEG.buildParser( - 'start = "a" { return null; } / "a"', - options - ); - - expect(parser).toParse("a", "a"); - }); }); describe("sequence matching", function() {