From c20f719a22995393665096c3bd6888d0103bec63 Mon Sep 17 00:00:00 2001 From: Daniel Wang Date: Wed, 15 May 2019 00:29:03 +0800 Subject: [PATCH] T223296 --- lib/compiler/asts.js | 2 + lib/compiler/passes/ast-to-code.js | 28 +++- lib/compiler/traverser.js | 2 + lib/compiler/visitor.js | 2 + lib/parser.js | 218 ++++++++++++++++------------- lib/parser.pegjs | 6 +- 6 files changed, 154 insertions(+), 104 deletions(-) diff --git a/lib/compiler/asts.js b/lib/compiler/asts.js index fa68f67..6266705 100644 --- a/lib/compiler/asts.js +++ b/lib/compiler/asts.js @@ -44,6 +44,8 @@ var asts = { text: matchesExpression, simple_and: matchesTrue, simple_not: matchesTrue, + discarded_and:matchesTrue, + discarded_not:matchesTrue, optional: matchesTrue, zero_or_more: matchesTrue, one_or_more: matchesExpression, diff --git a/lib/compiler/passes/ast-to-code.js b/lib/compiler/passes/ast-to-code.js index 015d6ca..a486ea2 100644 --- a/lib/compiler/passes/ast-to-code.js +++ b/lib/compiler/passes/ast-to-code.js @@ -271,6 +271,7 @@ function generateJavascript(ast, options) { this.failBlock = []; this.epilogue = []; this.free = []; + this.discarded = false; } Result.prototype = { /** @@ -554,11 +555,11 @@ function generateJavascript(ast, options) { } /** - * Handler for simple_and and simple_not. + * Handler for simple_and, simple_not, discarded_and and discarded_not. */ function buildSimplePredicate(node, context) { var result = new Result(); - var negate = node.type === 'simple_not'; + var negate = (node.type === 'simple_not') || (node.type === 'discarded_not'); var posReg = allocPosReg(); var reg = context.getResultReg(result); result.block = [`${posReg} = ${language.currPos};`]; @@ -579,6 +580,15 @@ function generateJavascript(ast, options) { return result; } + /** + * Handler for discarded_and and discarded_not. + */ + function buildDiscardedPredicate(node, context) { + var result = buildSimplePredicate(node, context); + result.discarded = true; + return result; + } + /** * Handler for semantic_and and semantic_not */ @@ -1030,7 +1040,9 @@ function generateJavascript(ast, options) { var subresult = recurse(node.elements[i], context.noPassThru()); subresult.free = []; result.append(subresult); - parts.push(subresult.expression); + if (!subresult.discarded) { + parts.push(subresult.expression); + } // On failure, backtrack to the start of the sequence. If this is // the first element of the sequence, it's not necessary to backtrack @@ -1048,7 +1060,13 @@ function generateJavascript(ast, options) { if (context.getDiscard()) { result.block.push(`${resultReg} = true;`); } else { - result.block.push(`${resultReg} = [${parts.join(',')}];`); + if (parts.length > 1) { + result.block.push(`${resultReg} = [${parts.join(',')}];`); + } else if (parts.length === 1) { + result.block.push(`${resultReg} = ${parts[0]};`); + } else { + result.block.push(`${resultReg} = true;`); + } } result.block.push(language.blockEnd(label)); result.expression = resultReg; @@ -1097,6 +1115,8 @@ function generateJavascript(ast, options) { simple_and: buildSimplePredicate, simple_not: buildSimplePredicate, + discarded_and: buildDiscardedPredicate, + discarded_not: buildDiscardedPredicate, optional: function(node, context) { var result = new Result(); diff --git a/lib/compiler/traverser.js b/lib/compiler/traverser.js index 7100339..7051725 100644 --- a/lib/compiler/traverser.js +++ b/lib/compiler/traverser.js @@ -63,6 +63,8 @@ Traverser.prototype = { text: traverseExpression, simple_and: traverseExpression, simple_not: traverseExpression, + discarded_and: traverseExpression, + discarded_not: traverseExpression, optional: traverseExpression, zero_or_more: traverseExpression, one_or_more: traverseExpression, diff --git a/lib/compiler/visitor.js b/lib/compiler/visitor.js index 755bfb3..5dab54c 100644 --- a/lib/compiler/visitor.js +++ b/lib/compiler/visitor.js @@ -57,6 +57,8 @@ var visitor = { text: visitExpression, simple_and: visitExpression, simple_not: visitExpression, + discarded_and: visitExpression, + discarded_not: visitExpression, optional: visitExpression, zero_or_more: visitExpression, one_or_more: visitExpression, diff --git a/lib/parser.js b/lib/parser.js index d8bf40f..f4b831a 100644 --- a/lib/parser.js +++ b/lib/parser.js @@ -407,54 +407,56 @@ function peg$parse(input, options = {}) { var peg$c47 = {"type":"literal","value":"<","description":"\"<\""}; var peg$c48 = {"type":"literal","value":"&","description":"\"&\""}; var peg$c49 = {"type":"literal","value":">","description":"\">\""}; - var peg$c50 = {"type":"literal","value":"!","description":"\"!\""}; - var peg$c51 = {"type":"literal","value":"(","description":"\"(\""}; - var peg$c52 = {"type":"literal","value":")","description":"\")\""}; - var peg$c53 = {"type":"literal","value":"?","description":"\"?\""}; - var peg$c54 = {"type":"literal","value":"*","description":"\"*\""}; - var peg$c55 = {"type":"literal","value":"+","description":"\"+\""}; - var peg$c56 = {"type":"literal","value":"null","description":"\"null\""}; - var peg$c57 = {"type":"other","description":"literal"}; - var peg$c58 = {"type":"other","description":"character class"}; - var peg$c59 = {"type":"literal","value":".","description":"\".\""}; - var peg$c60 = {"type":"literal","value":"break","description":"\"break\""}; - var peg$c61 = {"type":"literal","value":"case","description":"\"case\""}; - var peg$c62 = {"type":"literal","value":"catch","description":"\"catch\""}; - var peg$c63 = {"type":"literal","value":"continue","description":"\"continue\""}; - var peg$c64 = {"type":"literal","value":"debugger","description":"\"debugger\""}; - var peg$c65 = {"type":"literal","value":"default","description":"\"default\""}; - var peg$c66 = {"type":"literal","value":"delete","description":"\"delete\""}; - var peg$c67 = {"type":"literal","value":"do","description":"\"do\""}; - var peg$c68 = {"type":"literal","value":"else","description":"\"else\""}; - var peg$c69 = {"type":"literal","value":"finally","description":"\"finally\""}; - var peg$c70 = {"type":"literal","value":"for","description":"\"for\""}; - var peg$c71 = {"type":"literal","value":"function","description":"\"function\""}; - var peg$c72 = {"type":"literal","value":"if","description":"\"if\""}; - var peg$c73 = {"type":"literal","value":"instanceof","description":"\"instanceof\""}; - var peg$c74 = {"type":"literal","value":"in","description":"\"in\""}; - var peg$c75 = {"type":"literal","value":"new","description":"\"new\""}; - var peg$c76 = {"type":"literal","value":"return","description":"\"return\""}; - var peg$c77 = {"type":"literal","value":"switch","description":"\"switch\""}; - var peg$c78 = {"type":"literal","value":"this","description":"\"this\""}; - var peg$c79 = {"type":"literal","value":"throw","description":"\"throw\""}; - var peg$c80 = {"type":"literal","value":"try","description":"\"try\""}; - var peg$c81 = {"type":"literal","value":"typeof","description":"\"typeof\""}; - var peg$c82 = {"type":"literal","value":"var","description":"\"var\""}; - var peg$c83 = {"type":"literal","value":"void","description":"\"void\""}; - var peg$c84 = {"type":"literal","value":"while","description":"\"while\""}; - var peg$c85 = {"type":"literal","value":"with","description":"\"with\""}; - var peg$c86 = {"type":"literal","value":"class","description":"\"class\""}; - var peg$c87 = {"type":"literal","value":"const","description":"\"const\""}; - var peg$c88 = {"type":"literal","value":"enum","description":"\"enum\""}; - var peg$c89 = {"type":"literal","value":"export","description":"\"export\""}; - var peg$c90 = {"type":"literal","value":"extends","description":"\"extends\""}; - var peg$c91 = {"type":"literal","value":"import","description":"\"import\""}; - var peg$c92 = {"type":"literal","value":"super","description":"\"super\""}; - var peg$c93 = {"type":"literal","value":"true","description":"\"true\""}; - var peg$c94 = {"type":"literal","value":"false","description":"\"false\""}; - var peg$c95 = {"type":"literal","value":"-","description":"\"-\""}; - var peg$c96 = {"type":"literal","value":",","description":"\",\""}; - var peg$c97 = {"type":"literal","value":"++","description":"\"++\""}; + var peg$c50 = {"type":"literal","value":"&?","description":"\"&?\""}; + var peg$c51 = {"type":"literal","value":"!?","description":"\"!?\""}; + var peg$c52 = {"type":"literal","value":"!","description":"\"!\""}; + var peg$c53 = {"type":"literal","value":"(","description":"\"(\""}; + var peg$c54 = {"type":"literal","value":")","description":"\")\""}; + var peg$c55 = {"type":"literal","value":"?","description":"\"?\""}; + var peg$c56 = {"type":"literal","value":"*","description":"\"*\""}; + var peg$c57 = {"type":"literal","value":"+","description":"\"+\""}; + var peg$c58 = {"type":"literal","value":"null","description":"\"null\""}; + var peg$c59 = {"type":"other","description":"literal"}; + var peg$c60 = {"type":"other","description":"character class"}; + var peg$c61 = {"type":"literal","value":".","description":"\".\""}; + var peg$c62 = {"type":"literal","value":"break","description":"\"break\""}; + var peg$c63 = {"type":"literal","value":"case","description":"\"case\""}; + var peg$c64 = {"type":"literal","value":"catch","description":"\"catch\""}; + var peg$c65 = {"type":"literal","value":"continue","description":"\"continue\""}; + var peg$c66 = {"type":"literal","value":"debugger","description":"\"debugger\""}; + var peg$c67 = {"type":"literal","value":"default","description":"\"default\""}; + var peg$c68 = {"type":"literal","value":"delete","description":"\"delete\""}; + var peg$c69 = {"type":"literal","value":"do","description":"\"do\""}; + var peg$c70 = {"type":"literal","value":"else","description":"\"else\""}; + var peg$c71 = {"type":"literal","value":"finally","description":"\"finally\""}; + var peg$c72 = {"type":"literal","value":"for","description":"\"for\""}; + var peg$c73 = {"type":"literal","value":"function","description":"\"function\""}; + var peg$c74 = {"type":"literal","value":"if","description":"\"if\""}; + var peg$c75 = {"type":"literal","value":"instanceof","description":"\"instanceof\""}; + var peg$c76 = {"type":"literal","value":"in","description":"\"in\""}; + var peg$c77 = {"type":"literal","value":"new","description":"\"new\""}; + var peg$c78 = {"type":"literal","value":"return","description":"\"return\""}; + var peg$c79 = {"type":"literal","value":"switch","description":"\"switch\""}; + var peg$c80 = {"type":"literal","value":"this","description":"\"this\""}; + var peg$c81 = {"type":"literal","value":"throw","description":"\"throw\""}; + var peg$c82 = {"type":"literal","value":"try","description":"\"try\""}; + var peg$c83 = {"type":"literal","value":"typeof","description":"\"typeof\""}; + var peg$c84 = {"type":"literal","value":"var","description":"\"var\""}; + var peg$c85 = {"type":"literal","value":"void","description":"\"void\""}; + var peg$c86 = {"type":"literal","value":"while","description":"\"while\""}; + var peg$c87 = {"type":"literal","value":"with","description":"\"with\""}; + var peg$c88 = {"type":"literal","value":"class","description":"\"class\""}; + var peg$c89 = {"type":"literal","value":"const","description":"\"const\""}; + var peg$c90 = {"type":"literal","value":"enum","description":"\"enum\""}; + var peg$c91 = {"type":"literal","value":"export","description":"\"export\""}; + var peg$c92 = {"type":"literal","value":"extends","description":"\"extends\""}; + var peg$c93 = {"type":"literal","value":"import","description":"\"import\""}; + var peg$c94 = {"type":"literal","value":"super","description":"\"super\""}; + var peg$c95 = {"type":"literal","value":"true","description":"\"true\""}; + var peg$c96 = {"type":"literal","value":"false","description":"\"false\""}; + var peg$c97 = {"type":"literal","value":"-","description":"\"-\""}; + var peg$c98 = {"type":"literal","value":",","description":"\",\""}; + var peg$c99 = {"type":"literal","value":"++","description":"\"++\""}; // actions function peg$a0(initializer, rules) { @@ -750,7 +752,9 @@ function peg$parse(input, options = {}) { var OPS_TO_PREFIXED_TYPES = { "$": "text", "&": "simple_and", - "!": "simple_not" + "!": "simple_not", + "&?": "discarded_and", + "!?": "discarded_not" }; var OPS_TO_SUFFIXED_TYPES = { @@ -3209,6 +3213,22 @@ function peg$parse(input, options = {}) { if (!silence) {peg$fail(peg$c16);} r1 = peg$FAILED; } + r1 = input.substr(peg$currPos,2); + if (r1 === "&?") { + peg$currPos += 2; + break choice_1; + } else { + if (!silence) {peg$fail(peg$c50);} + r1 = peg$FAILED; + } + r1 = input.substr(peg$currPos,2); + if (r1 === "!?") { + peg$currPos += 2; + break choice_1; + } else { + if (!silence) {peg$fail(peg$c51);} + r1 = peg$FAILED; + } if (input.charCodeAt(peg$currPos) === 38) { r1 = "&"; peg$currPos += 1; @@ -3221,7 +3241,7 @@ function peg$parse(input, options = {}) { r1 = "!"; peg$currPos += 1; } else { - if (!silence) {peg$fail(peg$c50);} + if (!silence) {peg$fail(peg$c52);} r1 = peg$FAILED; } } // choice_1 @@ -3412,7 +3432,7 @@ function peg$parse(input, options = {}) { r4 = "("; peg$currPos += 1; } else { - if (!silence) {peg$fail(peg$c51);} + if (!silence) {peg$fail(peg$c53);} r4 = peg$FAILED; r1 = peg$FAILED; break seq_1; @@ -3440,7 +3460,7 @@ function peg$parse(input, options = {}) { r8 = ")"; peg$currPos += 1; } else { - if (!silence) {peg$fail(peg$c52);} + if (!silence) {peg$fail(peg$c54);} r8 = peg$FAILED; peg$currPos = p3; r1 = peg$FAILED; @@ -3464,7 +3484,7 @@ function peg$parse(input, options = {}) { peg$currPos += 1; break choice_1; } else { - if (!silence) {peg$fail(peg$c53);} + if (!silence) {peg$fail(peg$c55);} r1 = peg$FAILED; } if (input.charCodeAt(peg$currPos) === 42) { @@ -3472,14 +3492,14 @@ function peg$parse(input, options = {}) { peg$currPos += 1; break choice_1; } else { - if (!silence) {peg$fail(peg$c54);} + if (!silence) {peg$fail(peg$c56);} r1 = peg$FAILED; } if (input.charCodeAt(peg$currPos) === 43) { r1 = "+"; peg$currPos += 1; } else { - if (!silence) {peg$fail(peg$c55);} + if (!silence) {peg$fail(peg$c57);} r1 = peg$FAILED; } } // choice_1 @@ -3631,7 +3651,7 @@ function peg$parse(input, options = {}) { if (r3 === "null") { peg$currPos += 4; } else { - if (!silence) {peg$fail(peg$c56);} + if (!silence) {peg$fail(peg$c58);} r3 = peg$FAILED; r2 = peg$FAILED; break seq_1; @@ -3689,7 +3709,7 @@ function peg$parse(input, options = {}) { peg$savedPos = p2; r1 = peg$a26(r4, r5); } else { - if (!silence) {peg$fail(peg$c57);} + if (!silence) {peg$fail(peg$c59);} } // free p3 return r1; @@ -3755,7 +3775,7 @@ function peg$parse(input, options = {}) { peg$savedPos = p2; r1 = peg$a27(r5, r6, r8); } else { - if (!silence) {peg$fail(peg$c58);} + if (!silence) {peg$fail(peg$c60);} } // free p3 return r1; @@ -3769,7 +3789,7 @@ function peg$parse(input, options = {}) { peg$savedPos = p2; r1 = peg$a28(); } else { - if (!silence) {peg$fail(peg$c59);} + if (!silence) {peg$fail(peg$c61);} r1 = peg$FAILED; } return r1; @@ -3954,7 +3974,7 @@ function peg$parse(input, options = {}) { if (r3 === "break") { peg$currPos += 5; } else { - if (!silence) {peg$fail(peg$c60);} + if (!silence) {peg$fail(peg$c62);} r3 = peg$FAILED; r2 = peg$FAILED; break seq_1; @@ -3984,7 +4004,7 @@ function peg$parse(input, options = {}) { if (r3 === "case") { peg$currPos += 4; } else { - if (!silence) {peg$fail(peg$c61);} + if (!silence) {peg$fail(peg$c63);} r3 = peg$FAILED; r2 = peg$FAILED; break seq_1; @@ -4014,7 +4034,7 @@ function peg$parse(input, options = {}) { if (r3 === "catch") { peg$currPos += 5; } else { - if (!silence) {peg$fail(peg$c62);} + if (!silence) {peg$fail(peg$c64);} r3 = peg$FAILED; r2 = peg$FAILED; break seq_1; @@ -4044,7 +4064,7 @@ function peg$parse(input, options = {}) { if (r3 === "continue") { peg$currPos += 8; } else { - if (!silence) {peg$fail(peg$c63);} + if (!silence) {peg$fail(peg$c65);} r3 = peg$FAILED; r2 = peg$FAILED; break seq_1; @@ -4074,7 +4094,7 @@ function peg$parse(input, options = {}) { if (r3 === "debugger") { peg$currPos += 8; } else { - if (!silence) {peg$fail(peg$c64);} + if (!silence) {peg$fail(peg$c66);} r3 = peg$FAILED; r2 = peg$FAILED; break seq_1; @@ -4104,7 +4124,7 @@ function peg$parse(input, options = {}) { if (r3 === "default") { peg$currPos += 7; } else { - if (!silence) {peg$fail(peg$c65);} + if (!silence) {peg$fail(peg$c67);} r3 = peg$FAILED; r2 = peg$FAILED; break seq_1; @@ -4134,7 +4154,7 @@ function peg$parse(input, options = {}) { if (r3 === "delete") { peg$currPos += 6; } else { - if (!silence) {peg$fail(peg$c66);} + if (!silence) {peg$fail(peg$c68);} r3 = peg$FAILED; r2 = peg$FAILED; break seq_1; @@ -4164,7 +4184,7 @@ function peg$parse(input, options = {}) { if (r3 === "do") { peg$currPos += 2; } else { - if (!silence) {peg$fail(peg$c67);} + if (!silence) {peg$fail(peg$c69);} r3 = peg$FAILED; r2 = peg$FAILED; break seq_1; @@ -4194,7 +4214,7 @@ function peg$parse(input, options = {}) { if (r3 === "else") { peg$currPos += 4; } else { - if (!silence) {peg$fail(peg$c68);} + if (!silence) {peg$fail(peg$c70);} r3 = peg$FAILED; r2 = peg$FAILED; break seq_1; @@ -4224,7 +4244,7 @@ function peg$parse(input, options = {}) { if (r3 === "finally") { peg$currPos += 7; } else { - if (!silence) {peg$fail(peg$c69);} + if (!silence) {peg$fail(peg$c71);} r3 = peg$FAILED; r2 = peg$FAILED; break seq_1; @@ -4254,7 +4274,7 @@ function peg$parse(input, options = {}) { if (r3 === "for") { peg$currPos += 3; } else { - if (!silence) {peg$fail(peg$c70);} + if (!silence) {peg$fail(peg$c72);} r3 = peg$FAILED; r2 = peg$FAILED; break seq_1; @@ -4284,7 +4304,7 @@ function peg$parse(input, options = {}) { if (r3 === "function") { peg$currPos += 8; } else { - if (!silence) {peg$fail(peg$c71);} + if (!silence) {peg$fail(peg$c73);} r3 = peg$FAILED; r2 = peg$FAILED; break seq_1; @@ -4314,7 +4334,7 @@ function peg$parse(input, options = {}) { if (r3 === "if") { peg$currPos += 2; } else { - if (!silence) {peg$fail(peg$c72);} + if (!silence) {peg$fail(peg$c74);} r3 = peg$FAILED; r2 = peg$FAILED; break seq_1; @@ -4344,7 +4364,7 @@ function peg$parse(input, options = {}) { if (r3 === "instanceof") { peg$currPos += 10; } else { - if (!silence) {peg$fail(peg$c73);} + if (!silence) {peg$fail(peg$c75);} r3 = peg$FAILED; r2 = peg$FAILED; break seq_1; @@ -4374,7 +4394,7 @@ function peg$parse(input, options = {}) { if (r3 === "in") { peg$currPos += 2; } else { - if (!silence) {peg$fail(peg$c74);} + if (!silence) {peg$fail(peg$c76);} r3 = peg$FAILED; r2 = peg$FAILED; break seq_1; @@ -4404,7 +4424,7 @@ function peg$parse(input, options = {}) { if (r3 === "new") { peg$currPos += 3; } else { - if (!silence) {peg$fail(peg$c75);} + if (!silence) {peg$fail(peg$c77);} r3 = peg$FAILED; r2 = peg$FAILED; break seq_1; @@ -4434,7 +4454,7 @@ function peg$parse(input, options = {}) { if (r3 === "return") { peg$currPos += 6; } else { - if (!silence) {peg$fail(peg$c76);} + if (!silence) {peg$fail(peg$c78);} r3 = peg$FAILED; r2 = peg$FAILED; break seq_1; @@ -4464,7 +4484,7 @@ function peg$parse(input, options = {}) { if (r3 === "switch") { peg$currPos += 6; } else { - if (!silence) {peg$fail(peg$c77);} + if (!silence) {peg$fail(peg$c79);} r3 = peg$FAILED; r2 = peg$FAILED; break seq_1; @@ -4494,7 +4514,7 @@ function peg$parse(input, options = {}) { if (r3 === "this") { peg$currPos += 4; } else { - if (!silence) {peg$fail(peg$c78);} + if (!silence) {peg$fail(peg$c80);} r3 = peg$FAILED; r2 = peg$FAILED; break seq_1; @@ -4524,7 +4544,7 @@ function peg$parse(input, options = {}) { if (r3 === "throw") { peg$currPos += 5; } else { - if (!silence) {peg$fail(peg$c79);} + if (!silence) {peg$fail(peg$c81);} r3 = peg$FAILED; r2 = peg$FAILED; break seq_1; @@ -4554,7 +4574,7 @@ function peg$parse(input, options = {}) { if (r3 === "try") { peg$currPos += 3; } else { - if (!silence) {peg$fail(peg$c80);} + if (!silence) {peg$fail(peg$c82);} r3 = peg$FAILED; r2 = peg$FAILED; break seq_1; @@ -4584,7 +4604,7 @@ function peg$parse(input, options = {}) { if (r3 === "typeof") { peg$currPos += 6; } else { - if (!silence) {peg$fail(peg$c81);} + if (!silence) {peg$fail(peg$c83);} r3 = peg$FAILED; r2 = peg$FAILED; break seq_1; @@ -4614,7 +4634,7 @@ function peg$parse(input, options = {}) { if (r3 === "var") { peg$currPos += 3; } else { - if (!silence) {peg$fail(peg$c82);} + if (!silence) {peg$fail(peg$c84);} r3 = peg$FAILED; r2 = peg$FAILED; break seq_1; @@ -4644,7 +4664,7 @@ function peg$parse(input, options = {}) { if (r3 === "void") { peg$currPos += 4; } else { - if (!silence) {peg$fail(peg$c83);} + if (!silence) {peg$fail(peg$c85);} r3 = peg$FAILED; r2 = peg$FAILED; break seq_1; @@ -4674,7 +4694,7 @@ function peg$parse(input, options = {}) { if (r3 === "while") { peg$currPos += 5; } else { - if (!silence) {peg$fail(peg$c84);} + if (!silence) {peg$fail(peg$c86);} r3 = peg$FAILED; r2 = peg$FAILED; break seq_1; @@ -4704,7 +4724,7 @@ function peg$parse(input, options = {}) { if (r3 === "with") { peg$currPos += 4; } else { - if (!silence) {peg$fail(peg$c85);} + if (!silence) {peg$fail(peg$c87);} r3 = peg$FAILED; r2 = peg$FAILED; break seq_1; @@ -4734,7 +4754,7 @@ function peg$parse(input, options = {}) { if (r3 === "class") { peg$currPos += 5; } else { - if (!silence) {peg$fail(peg$c86);} + if (!silence) {peg$fail(peg$c88);} r3 = peg$FAILED; r2 = peg$FAILED; break seq_1; @@ -4764,7 +4784,7 @@ function peg$parse(input, options = {}) { if (r3 === "const") { peg$currPos += 5; } else { - if (!silence) {peg$fail(peg$c87);} + if (!silence) {peg$fail(peg$c89);} r3 = peg$FAILED; r2 = peg$FAILED; break seq_1; @@ -4794,7 +4814,7 @@ function peg$parse(input, options = {}) { if (r3 === "enum") { peg$currPos += 4; } else { - if (!silence) {peg$fail(peg$c88);} + if (!silence) {peg$fail(peg$c90);} r3 = peg$FAILED; r2 = peg$FAILED; break seq_1; @@ -4824,7 +4844,7 @@ function peg$parse(input, options = {}) { if (r3 === "export") { peg$currPos += 6; } else { - if (!silence) {peg$fail(peg$c89);} + if (!silence) {peg$fail(peg$c91);} r3 = peg$FAILED; r2 = peg$FAILED; break seq_1; @@ -4854,7 +4874,7 @@ function peg$parse(input, options = {}) { if (r3 === "extends") { peg$currPos += 7; } else { - if (!silence) {peg$fail(peg$c90);} + if (!silence) {peg$fail(peg$c92);} r3 = peg$FAILED; r2 = peg$FAILED; break seq_1; @@ -4884,7 +4904,7 @@ function peg$parse(input, options = {}) { if (r3 === "import") { peg$currPos += 6; } else { - if (!silence) {peg$fail(peg$c91);} + if (!silence) {peg$fail(peg$c93);} r3 = peg$FAILED; r2 = peg$FAILED; break seq_1; @@ -4914,7 +4934,7 @@ function peg$parse(input, options = {}) { if (r3 === "super") { peg$currPos += 5; } else { - if (!silence) {peg$fail(peg$c92);} + if (!silence) {peg$fail(peg$c94);} r3 = peg$FAILED; r2 = peg$FAILED; break seq_1; @@ -4981,7 +5001,7 @@ function peg$parse(input, options = {}) { if (r3 === "true") { peg$currPos += 4; } else { - if (!silence) {peg$fail(peg$c93);} + if (!silence) {peg$fail(peg$c95);} r3 = peg$FAILED; r2 = peg$FAILED; break seq_1; @@ -5011,7 +5031,7 @@ function peg$parse(input, options = {}) { if (r3 === "false") { peg$currPos += 5; } else { - if (!silence) {peg$fail(peg$c94);} + if (!silence) {peg$fail(peg$c96);} r3 = peg$FAILED; r2 = peg$FAILED; break seq_1; @@ -5048,7 +5068,7 @@ function peg$parse(input, options = {}) { r5 = "-"; peg$currPos += 1; } else { - if (!silence) {peg$fail(peg$c95);} + if (!silence) {peg$fail(peg$c97);} r5 = peg$FAILED; peg$currPos = p3; r1 = peg$FAILED; @@ -5188,7 +5208,7 @@ function peg$parse(input, options = {}) { r11 = ","; peg$currPos += 1; } else { - if (!silence) {peg$fail(peg$c96);} + if (!silence) {peg$fail(peg$c98);} r11 = peg$FAILED; peg$currPos = p9; r8 = peg$FAILED; @@ -5343,7 +5363,7 @@ function peg$parse(input, options = {}) { r1 = "!"; peg$currPos += 1; } else { - if (!silence) {peg$fail(peg$c50);} + if (!silence) {peg$fail(peg$c52);} r1 = peg$FAILED; } } // choice_1 @@ -5364,7 +5384,7 @@ function peg$parse(input, options = {}) { r1 = "!"; peg$currPos += 1; } else { - if (!silence) {peg$fail(peg$c50);} + if (!silence) {peg$fail(peg$c52);} r1 = peg$FAILED; } } // choice_1 @@ -5606,7 +5626,7 @@ function peg$parse(input, options = {}) { peg$savedPos = p2; r1 = peg$a35(); } else { - if (!silence) {peg$fail(peg$c97);} + if (!silence) {peg$fail(peg$c99);} r1 = peg$FAILED; } return r1; diff --git a/lib/parser.pegjs b/lib/parser.pegjs index ad5a064..59fc67b 100644 --- a/lib/parser.pegjs +++ b/lib/parser.pegjs @@ -27,7 +27,9 @@ var OPS_TO_PREFIXED_TYPES = { "$": "text", "&": "simple_and", - "!": "simple_not" + "!": "simple_not", + "&?": "discarded_and", + "!?": "discarded_not" }; var OPS_TO_SUFFIXED_TYPES = { @@ -198,6 +200,8 @@ PrefixedExpression PrefixedOperator = "$" + / "&?" + / "!?" / "&" / "!"