|
|
|
@ -282,16 +282,18 @@ PEG.Compiler = {
|
|
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
rule: checkExpression,
|
|
|
|
|
choice: checkSubnodes("alternatives"),
|
|
|
|
|
sequence: checkSubnodes("elements"),
|
|
|
|
|
labeled: checkExpression,
|
|
|
|
|
and_predicate: checkExpression,
|
|
|
|
|
not_predicate: checkExpression,
|
|
|
|
|
optional: checkExpression,
|
|
|
|
|
zero_or_more: checkExpression,
|
|
|
|
|
one_or_more: checkExpression,
|
|
|
|
|
action: checkExpression,
|
|
|
|
|
rule: checkExpression,
|
|
|
|
|
choice: checkSubnodes("alternatives"),
|
|
|
|
|
sequence: checkSubnodes("elements"),
|
|
|
|
|
labeled: checkExpression,
|
|
|
|
|
simple_and: checkExpression,
|
|
|
|
|
simple_not: checkExpression,
|
|
|
|
|
semantic_and: nop,
|
|
|
|
|
semantic_not: nop,
|
|
|
|
|
optional: checkExpression,
|
|
|
|
|
zero_or_more: checkExpression,
|
|
|
|
|
one_or_more: checkExpression,
|
|
|
|
|
action: checkExpression,
|
|
|
|
|
|
|
|
|
|
rule_ref:
|
|
|
|
|
function(node) {
|
|
|
|
@ -302,9 +304,9 @@ PEG.Compiler = {
|
|
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
literal: nop,
|
|
|
|
|
any: nop,
|
|
|
|
|
"class": nop
|
|
|
|
|
literal: nop,
|
|
|
|
|
any: nop,
|
|
|
|
|
"class": nop
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
function check(node) { checkFunctions[node.type](node); }
|
|
|
|
@ -347,13 +349,15 @@ PEG.Compiler = {
|
|
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
labeled: checkExpression,
|
|
|
|
|
and_predicate: checkExpression,
|
|
|
|
|
not_predicate: checkExpression,
|
|
|
|
|
optional: checkExpression,
|
|
|
|
|
zero_or_more: checkExpression,
|
|
|
|
|
one_or_more: checkExpression,
|
|
|
|
|
action: checkExpression,
|
|
|
|
|
labeled: checkExpression,
|
|
|
|
|
simple_and: checkExpression,
|
|
|
|
|
simple_not: checkExpression,
|
|
|
|
|
semantic_and: nop,
|
|
|
|
|
semantic_not: nop,
|
|
|
|
|
optional: checkExpression,
|
|
|
|
|
zero_or_more: checkExpression,
|
|
|
|
|
one_or_more: checkExpression,
|
|
|
|
|
action: checkExpression,
|
|
|
|
|
|
|
|
|
|
rule_ref:
|
|
|
|
|
function(node, appliedRules) {
|
|
|
|
@ -365,9 +369,9 @@ PEG.Compiler = {
|
|
|
|
|
check(ast.rules[node.name], appliedRules);
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
literal: nop,
|
|
|
|
|
any: nop,
|
|
|
|
|
"class": nop
|
|
|
|
|
literal: nop,
|
|
|
|
|
any: nop,
|
|
|
|
|
"class": nop
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
function check(node, appliedRules) {
|
|
|
|
@ -416,16 +420,18 @@ PEG.Compiler = {
|
|
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
rule: replaceInExpression,
|
|
|
|
|
choice: replaceInSubnodes("alternatives"),
|
|
|
|
|
sequence: replaceInSubnodes("elements"),
|
|
|
|
|
labeled: replaceInExpression,
|
|
|
|
|
and_predicate: replaceInExpression,
|
|
|
|
|
not_predicate: replaceInExpression,
|
|
|
|
|
optional: replaceInExpression,
|
|
|
|
|
zero_or_more: replaceInExpression,
|
|
|
|
|
one_or_more: replaceInExpression,
|
|
|
|
|
action: replaceInExpression,
|
|
|
|
|
rule: replaceInExpression,
|
|
|
|
|
choice: replaceInSubnodes("alternatives"),
|
|
|
|
|
sequence: replaceInSubnodes("elements"),
|
|
|
|
|
labeled: replaceInExpression,
|
|
|
|
|
simple_and: replaceInExpression,
|
|
|
|
|
simple_not: replaceInExpression,
|
|
|
|
|
semantic_and: nop,
|
|
|
|
|
semantic_not: nop,
|
|
|
|
|
optional: replaceInExpression,
|
|
|
|
|
zero_or_more: replaceInExpression,
|
|
|
|
|
one_or_more: replaceInExpression,
|
|
|
|
|
action: replaceInExpression,
|
|
|
|
|
|
|
|
|
|
rule_ref:
|
|
|
|
|
function(node, from, to) {
|
|
|
|
@ -434,9 +440,9 @@ PEG.Compiler = {
|
|
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
literal: nop,
|
|
|
|
|
any: nop,
|
|
|
|
|
"class": nop
|
|
|
|
|
literal: nop,
|
|
|
|
|
any: nop,
|
|
|
|
|
"class": nop
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
function replace(node, from, to) {
|
|
|
|
@ -819,7 +825,7 @@ PEG.Compiler = {
|
|
|
|
|
return PEG.Compiler.compileNode(node.expression, resultVar);
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
and_predicate: function(node, resultVar) {
|
|
|
|
|
simple_and: function(node, resultVar) {
|
|
|
|
|
var savedPosVar = PEG.Compiler.generateUniqueIdentifier("savedPos");
|
|
|
|
|
var savedReportMatchFailuresVar = PEG.Compiler.generateUniqueIdentifier("savedReportMatchFailuresVar");
|
|
|
|
|
var expressionResultVar = PEG.Compiler.generateUniqueIdentifier("result");
|
|
|
|
@ -846,7 +852,7 @@ PEG.Compiler = {
|
|
|
|
|
);
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
not_predicate: function(node, resultVar) {
|
|
|
|
|
simple_not: function(node, resultVar) {
|
|
|
|
|
var savedPosVar = PEG.Compiler.generateUniqueIdentifier("savedPos");
|
|
|
|
|
var savedReportMatchFailuresVar = PEG.Compiler.generateUniqueIdentifier("savedReportMatchFailuresVar");
|
|
|
|
|
var expressionResultVar = PEG.Compiler.generateUniqueIdentifier("result");
|
|
|
|
@ -873,6 +879,30 @@ PEG.Compiler = {
|
|
|
|
|
);
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
semantic_and: function(node, resultVar) {
|
|
|
|
|
var savedPosVar = PEG.Compiler.generateUniqueIdentifier("savedPos");
|
|
|
|
|
|
|
|
|
|
return PEG.Compiler.formatCode(
|
|
|
|
|
"var ${resultVar} = (function() {${actionCode}})() ? '' : null;",
|
|
|
|
|
{
|
|
|
|
|
actionCode: node.code,
|
|
|
|
|
resultVar: resultVar
|
|
|
|
|
}
|
|
|
|
|
);
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
semantic_not: function(node, resultVar) {
|
|
|
|
|
var savedPosVar = PEG.Compiler.generateUniqueIdentifier("savedPos");
|
|
|
|
|
|
|
|
|
|
return PEG.Compiler.formatCode(
|
|
|
|
|
"var ${resultVar} = (function() {${actionCode}})() ? null : '';",
|
|
|
|
|
{
|
|
|
|
|
actionCode: node.code,
|
|
|
|
|
resultVar: resultVar
|
|
|
|
|
}
|
|
|
|
|
);
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
optional: function(node, resultVar) {
|
|
|
|
|
var expressionResultVar = PEG.Compiler.generateUniqueIdentifier("result");
|
|
|
|
|
|
|
|
|
|