Avoid aligning object keys

The only exception left are objects representing a mapping with simple
keys and values -- essentially tables written as object literals.

See #443.
redux
David Majda 8 years ago
parent 12112310f2
commit 400a3cfa3c

@ -371,7 +371,7 @@ The code inside the predicate can also access location information using the
```javascript ```javascript
{ {
start: { offset: 23, line: 5, column: 6 }, start: { offset: 23, line: 5, column: 6 },
end: { offset: 23, line: 5, column: 6 } end: { offset: 23, line: 5, column: 6 }
} }
``` ```
@ -402,7 +402,7 @@ The code inside the predicate can also access location information using the
```javascript ```javascript
{ {
start: { offset: 23, line: 5, column: 6 }, start: { offset: 23, line: 5, column: 6 },
end: { offset: 23, line: 5, column: 6 } end: { offset: 23, line: 5, column: 6 }
} }
``` ```
@ -469,7 +469,7 @@ The code inside the action can also access location information using the
```javascript ```javascript
{ {
start: { offset: 23, line: 5, column: 6 }, start: { offset: 23, line: 5, column: 6 },
end: { offset: 25, line: 5, column: 8 } end: { offset: 25, line: 5, column: 8 }
} }
``` ```

@ -2,8 +2,8 @@
let benchmarks = [ let benchmarks = [
{ {
id: "json", id: "json",
title: "JSON", title: "JSON",
tests: [ tests: [
{ file: "example1.json", title: "Example 1" }, { file: "example1.json", title: "Example 1" },
{ file: "example2.json", title: "Example 2" }, { file: "example2.json", title: "Example 2" },
@ -13,8 +13,8 @@ let benchmarks = [
] ]
}, },
{ {
id: "css", id: "css",
title: "CSS", title: "CSS",
tests: [ tests: [
{ file: "blueprint/src/reset.css", title: "Blueprint - reset.css (source)" }, { file: "blueprint/src/reset.css", title: "Blueprint - reset.css (source)" },
{ file: "blueprint/src/typography.css", title: "Blueprint - typography.css (source)" }, { file: "blueprint/src/typography.css", title: "Blueprint - typography.css (source)" },

@ -62,7 +62,7 @@ $("#run").click(() => {
let runCount = parseInt($("#run-count").val(), 10); let runCount = parseInt($("#run-count").val(), 10);
let options = { let options = {
cache: $("#cache").is(":checked"), cache: $("#cache").is(":checked"),
optimize: $("#optimize").val() optimize: $("#optimize").val()
}; };
@ -74,10 +74,10 @@ $("#run").click(() => {
Runner.run(benchmarks, runCount, options, { Runner.run(benchmarks, runCount, options, {
readFile: function(file) { readFile: function(file) {
return $.ajax({ return $.ajax({
type: "GET", type: "GET",
url: file, url: file,
dataType: "text", dataType: "text",
async: false async: false
}).responseText; }).responseText;
}, },

@ -113,7 +113,7 @@ function nextArg() {
let runCount = 10; let runCount = 10;
let options = { let options = {
cache: false, cache: false,
optimize: "speed" optimize: "speed"
}; };

@ -106,14 +106,14 @@ let inputFile = null;
let outputFile = null; let outputFile = null;
let options = { let options = {
cache: false, cache: false,
dependencies: {}, dependencies: {},
exportVar: null, exportVar: null,
format: "commonjs", format: "commonjs",
optimize: "speed", optimize: "speed",
output: "source", output: "source",
plugins: [], plugins: [],
trace: false trace: false
}; };
while (args.length > 0 && isOption(args[0])) { while (args.length > 0 && isOption(args[0])) {

@ -35,10 +35,10 @@
function buildExpression(head, tail) { function buildExpression(head, tail) {
return tail.reduce(function(result, element) { return tail.reduce(function(result, element) {
return { return {
type: "Expression", type: "Expression",
operator: element[0], operator: element[0],
left: result, left: result,
right: element[1] right: element[1]
}; };
}, head); }, head);
} }
@ -55,18 +55,18 @@ stylesheet
rules:((ruleset / media / page) (CDO S* / CDC S*)*)* rules:((ruleset / media / page) (CDO S* / CDC S*)*)*
{ {
return { return {
type: "StyleSheet", type: "StyleSheet",
charset: extractOptional(charset, 1), charset: extractOptional(charset, 1),
imports: extractList(imports, 0), imports: extractList(imports, 0),
rules: extractList(rules, 0) rules: extractList(rules, 0)
}; };
} }
import import
= IMPORT_SYM S* href:(STRING / URI) S* media:media_list? ";" S* { = IMPORT_SYM S* href:(STRING / URI) S* media:media_list? ";" S* {
return { return {
type: "ImportRule", type: "ImportRule",
href: href, href: href,
media: media !== null ? media : [] media: media !== null ? media : []
}; };
} }
@ -94,8 +94,8 @@ page
"}" S* "}" S*
{ {
return { return {
type: "PageRule", type: "PageRule",
selector: selector, selector: selector,
declarations: buildList(declarationsHead, declarationsTail, 2) declarations: buildList(declarationsHead, declarationsTail, 2)
}; };
} }
@ -123,8 +123,8 @@ ruleset
"}" S* "}" S*
{ {
return { return {
type: "RuleSet", type: "RuleSet",
selectors: buildList(selectorsHead, selectorsTail, 2), selectors: buildList(selectorsHead, selectorsTail, 2),
declarations: buildList(declarationsHead, declarationsTail, 2) declarations: buildList(declarationsHead, declarationsTail, 2)
}; };
} }
@ -132,18 +132,18 @@ ruleset
selector selector
= left:simple_selector S* combinator:combinator right:selector { = left:simple_selector S* combinator:combinator right:selector {
return { return {
type: "Selector", type: "Selector",
combinator: combinator, combinator: combinator,
left: left, left: left,
right: right right: right
}; };
} }
/ left:simple_selector S+ right:selector { / left:simple_selector S+ right:selector {
return { return {
type: "Selector", type: "Selector",
combinator: " ", combinator: " ",
left: left, left: left,
right: right right: right
}; };
} }
/ selector:simple_selector S* { return selector; } / selector:simple_selector S* { return selector; }
@ -151,15 +151,15 @@ selector
simple_selector simple_selector
= element:element_name qualifiers:(id / class / attrib / pseudo)* { = element:element_name qualifiers:(id / class / attrib / pseudo)* {
return { return {
type: "SimpleSelector", type: "SimpleSelector",
element: element, element: element,
qualifiers: qualifiers qualifiers: qualifiers
}; };
} }
/ qualifiers:(id / class / attrib / pseudo)+ { / qualifiers:(id / class / attrib / pseudo)+ {
return { return {
type: "SimpleSelector", type: "SimpleSelector",
element: "*", element: "*",
qualifiers: qualifiers qualifiers: qualifiers
}; };
} }
@ -181,10 +181,10 @@ attrib
"]" "]"
{ {
return { return {
type: "AttributeSelector", type: "AttributeSelector",
attribute: attribute, attribute: attribute,
operator: extractOptional(operatorAndValue, 0), operator: extractOptional(operatorAndValue, 0),
value: extractOptional(operatorAndValue, 2) value: extractOptional(operatorAndValue, 2)
}; };
} }
@ -193,8 +193,8 @@ pseudo
value:( value:(
name:FUNCTION S* params:(IDENT S*)? ")" { name:FUNCTION S* params:(IDENT S*)? ")" {
return { return {
type: "Function", type: "Function",
name: name, name: name,
params: params !== null ? [params[0]] : [] params: params !== null ? [params[0]] : []
}; };
} }
@ -205,9 +205,9 @@ pseudo
declaration declaration
= name:property ':' S* value:expr prio:prio? { = name:property ':' S* value:expr prio:prio? {
return { return {
type: "Declaration", type: "Declaration",
name: name, name: name,
value: value, value: value,
important: prio !== null important: prio !== null
}; };
} }
@ -223,9 +223,9 @@ term
S* S*
{ {
return { return {
type: "Quantity", type: "Quantity",
value: quantity.value, value: quantity.value,
unit: quantity.unit unit: quantity.unit
}; };
} }
/ value:STRING S* { return { type: "String", value: value }; } / value:STRING S* { return { type: "String", value: value }; }

@ -56,10 +56,10 @@
function buildBinaryExpression(head, tail) { function buildBinaryExpression(head, tail) {
return tail.reduce(function(result, element) { return tail.reduce(function(result, element) {
return { return {
type: "BinaryExpression", type: "BinaryExpression",
operator: element[1], operator: element[1],
left: result, left: result,
right: element[3] right: element[3]
}; };
}, head); }, head);
} }
@ -67,10 +67,10 @@
function buildLogicalExpression(head, tail) { function buildLogicalExpression(head, tail) {
return tail.reduce(function(result, element) { return tail.reduce(function(result, element) {
return { return {
type: "LogicalExpression", type: "LogicalExpression",
operator: element[1], operator: element[1],
left: result, left: result,
right: element[3] right: element[3]
}; };
}, head); }, head);
} }
@ -504,19 +504,19 @@ PrimaryExpression
ArrayLiteral ArrayLiteral
= "[" __ elision:(Elision __)? "]" { = "[" __ elision:(Elision __)? "]" {
return { return {
type: "ArrayExpression", type: "ArrayExpression",
elements: optionalList(extractOptional(elision, 0)) elements: optionalList(extractOptional(elision, 0))
}; };
} }
/ "[" __ elements:ElementList __ "]" { / "[" __ elements:ElementList __ "]" {
return { return {
type: "ArrayExpression", type: "ArrayExpression",
elements: elements elements: elements
}; };
} }
/ "[" __ elements:ElementList __ "," __ elision:(Elision __)? "]" { / "[" __ elements:ElementList __ "," __ elision:(Elision __)? "]" {
return { return {
type: "ArrayExpression", type: "ArrayExpression",
elements: elements.concat(optionalList(extractOptional(elision, 0))) elements: elements.concat(optionalList(extractOptional(elision, 0)))
}; };
} }
@ -559,15 +559,15 @@ PropertyAssignment
"{" __ body:FunctionBody __ "}" "{" __ body:FunctionBody __ "}"
{ {
return { return {
type: "Property", type: "Property",
key: key, key: key,
value: { value: {
type: "FunctionExpression", type: "FunctionExpression",
id: null, id: null,
params: [], params: [],
body: body body: body
}, },
kind: "get" kind: "get"
}; };
} }
/ SetToken __ key:PropertyName __ / SetToken __ key:PropertyName __
@ -575,15 +575,15 @@ PropertyAssignment
"{" __ body:FunctionBody __ "}" "{" __ body:FunctionBody __ "}"
{ {
return { return {
type: "Property", type: "Property",
key: key, key: key,
value: { value: {
type: "FunctionExpression", type: "FunctionExpression",
id: null, id: null,
params: params, params: params,
body: body body: body
}, },
kind: "set" kind: "set"
}; };
} }
@ -614,8 +614,8 @@ MemberExpression
{ {
return tail.reduce(function(result, element) { return tail.reduce(function(result, element) {
return { return {
type: "MemberExpression", type: "MemberExpression",
object: result, object: result,
property: element.property, property: element.property,
computed: element.computed computed: element.computed
}; };
@ -640,14 +640,14 @@ CallExpression
} }
/ __ "[" __ property:Expression __ "]" { / __ "[" __ property:Expression __ "]" {
return { return {
type: "MemberExpression", type: "MemberExpression",
property: property, property: property,
computed: true computed: true
}; };
} }
/ __ "." __ property:IdentifierName { / __ "." __ property:IdentifierName {
return { return {
type: "MemberExpression", type: "MemberExpression",
property: property, property: property,
computed: false computed: false
}; };
@ -678,10 +678,10 @@ LeftHandSideExpression
PostfixExpression PostfixExpression
= argument:LeftHandSideExpression _ operator:PostfixOperator { = argument:LeftHandSideExpression _ operator:PostfixOperator {
return { return {
type: "UpdateExpression", type: "UpdateExpression",
operator: operator, operator: operator,
argument: argument, argument: argument,
prefix: false prefix: false
}; };
} }
/ LeftHandSideExpression / LeftHandSideExpression
@ -698,10 +698,10 @@ UnaryExpression
: "UnaryExpression"; : "UnaryExpression";
return { return {
type: type, type: type,
operator: operator, operator: operator,
argument: argument, argument: argument,
prefix: true prefix: true
}; };
} }
@ -857,10 +857,10 @@ ConditionalExpression
":" __ alternate:AssignmentExpression ":" __ alternate:AssignmentExpression
{ {
return { return {
type: "ConditionalExpression", type: "ConditionalExpression",
test: test, test: test,
consequent: consequent, consequent: consequent,
alternate: alternate alternate: alternate
}; };
} }
/ LogicalORExpression / LogicalORExpression
@ -871,10 +871,10 @@ ConditionalExpressionNoIn
":" __ alternate:AssignmentExpressionNoIn ":" __ alternate:AssignmentExpressionNoIn
{ {
return { return {
type: "ConditionalExpression", type: "ConditionalExpression",
test: test, test: test,
consequent: consequent, consequent: consequent,
alternate: alternate alternate: alternate
}; };
} }
/ LogicalORExpressionNoIn / LogicalORExpressionNoIn
@ -885,10 +885,10 @@ AssignmentExpression
right:AssignmentExpression right:AssignmentExpression
{ {
return { return {
type: "AssignmentExpression", type: "AssignmentExpression",
operator: "=", operator: "=",
left: left, left: left,
right: right right: right
}; };
} }
/ left:LeftHandSideExpression __ / left:LeftHandSideExpression __
@ -896,10 +896,10 @@ AssignmentExpression
right:AssignmentExpression right:AssignmentExpression
{ {
return { return {
type: "AssignmentExpression", type: "AssignmentExpression",
operator: operator, operator: operator,
left: left, left: left,
right: right right: right
}; };
} }
/ ConditionalExpression / ConditionalExpression
@ -910,10 +910,10 @@ AssignmentExpressionNoIn
right:AssignmentExpressionNoIn right:AssignmentExpressionNoIn
{ {
return { return {
type: "AssignmentExpression", type: "AssignmentExpression",
operator: "=", operator: "=",
left: left, left: left,
right: right right: right
}; };
} }
/ left:LeftHandSideExpression __ / left:LeftHandSideExpression __
@ -921,10 +921,10 @@ AssignmentExpressionNoIn
right:AssignmentExpressionNoIn right:AssignmentExpressionNoIn
{ {
return { return {
type: "AssignmentExpression", type: "AssignmentExpression",
operator: operator, operator: operator,
left: left, left: left,
right: right right: right
}; };
} }
/ ConditionalExpressionNoIn / ConditionalExpressionNoIn
@ -989,9 +989,9 @@ StatementList
VariableStatement VariableStatement
= VarToken __ declarations:VariableDeclarationList EOS { = VarToken __ declarations:VariableDeclarationList EOS {
return { return {
type: "VariableDeclaration", type: "VariableDeclaration",
declarations: declarations, declarations: declarations,
kind: "var" kind: "var"
}; };
} }
@ -1009,7 +1009,7 @@ VariableDeclaration
= id:Identifier init:(__ Initialiser)? { = id:Identifier init:(__ Initialiser)? {
return { return {
type: "VariableDeclarator", type: "VariableDeclarator",
id: id, id: id,
init: extractOptional(init, 1) init: extractOptional(init, 1)
}; };
} }
@ -1018,7 +1018,7 @@ VariableDeclarationNoIn
= id:Identifier init:(__ InitialiserNoIn)? { = id:Identifier init:(__ InitialiserNoIn)? {
return { return {
type: "VariableDeclarator", type: "VariableDeclarator",
id: id, id: id,
init: extractOptional(init, 1) init: extractOptional(init, 1)
}; };
} }
@ -1035,7 +1035,7 @@ EmptyStatement
ExpressionStatement ExpressionStatement
= !("{" / FunctionToken) expression:Expression EOS { = !("{" / FunctionToken) expression:Expression EOS {
return { return {
type: "ExpressionStatement", type: "ExpressionStatement",
expression: expression expression: expression
}; };
} }
@ -1047,19 +1047,19 @@ IfStatement
alternate:Statement alternate:Statement
{ {
return { return {
type: "IfStatement", type: "IfStatement",
test: test, test: test,
consequent: consequent, consequent: consequent,
alternate: alternate alternate: alternate
}; };
} }
/ IfToken __ "(" __ test:Expression __ ")" __ / IfToken __ "(" __ test:Expression __ ")" __
consequent:Statement { consequent:Statement {
return { return {
type: "IfStatement", type: "IfStatement",
test: test, test: test,
consequent: consequent, consequent: consequent,
alternate: null alternate: null
}; };
} }
@ -1080,11 +1080,11 @@ IterationStatement
body:Statement body:Statement
{ {
return { return {
type: "ForStatement", type: "ForStatement",
init: extractOptional(init, 0), init: extractOptional(init, 0),
test: extractOptional(test, 0), test: extractOptional(test, 0),
update: extractOptional(update, 0), update: extractOptional(update, 0),
body: body body: body
}; };
} }
/ ForToken __ / ForToken __
@ -1096,15 +1096,15 @@ IterationStatement
body:Statement body:Statement
{ {
return { return {
type: "ForStatement", type: "ForStatement",
init: { init: {
type: "VariableDeclaration", type: "VariableDeclaration",
declarations: declarations, declarations: declarations,
kind: "var" kind: "var"
}, },
test: extractOptional(test, 0), test: extractOptional(test, 0),
update: extractOptional(update, 0), update: extractOptional(update, 0),
body: body body: body
}; };
} }
/ ForToken __ / ForToken __
@ -1116,10 +1116,10 @@ IterationStatement
body:Statement body:Statement
{ {
return { return {
type: "ForInStatement", type: "ForInStatement",
left: left, left: left,
right: right, right: right,
body: body body: body
}; };
} }
/ ForToken __ / ForToken __
@ -1131,14 +1131,14 @@ IterationStatement
body:Statement body:Statement
{ {
return { return {
type: "ForInStatement", type: "ForInStatement",
left: { left: {
type: "VariableDeclaration", type: "VariableDeclaration",
declarations: declarations, declarations: declarations,
kind: "var" kind: "var"
}, },
right: right, right: right,
body: body body: body
}; };
} }
@ -1176,9 +1176,9 @@ SwitchStatement
cases:CaseBlock cases:CaseBlock
{ {
return { return {
type: "SwitchStatement", type: "SwitchStatement",
discriminant: discriminant, discriminant: discriminant,
cases: cases cases: cases
}; };
} }
@ -1202,8 +1202,8 @@ CaseClauses
CaseClause CaseClause
= CaseToken __ test:Expression __ ":" consequent:(__ StatementList)? { = CaseToken __ test:Expression __ ":" consequent:(__ StatementList)? {
return { return {
type: "SwitchCase", type: "SwitchCase",
test: test, test: test,
consequent: optionalList(extractOptional(consequent, 1)) consequent: optionalList(extractOptional(consequent, 1))
}; };
} }
@ -1211,8 +1211,8 @@ CaseClause
DefaultClause DefaultClause
= DefaultToken __ ":" consequent:(__ StatementList)? { = DefaultToken __ ":" consequent:(__ StatementList)? {
return { return {
type: "SwitchCase", type: "SwitchCase",
test: null, test: null,
consequent: optionalList(extractOptional(consequent, 1)) consequent: optionalList(extractOptional(consequent, 1))
}; };
} }
@ -1230,25 +1230,25 @@ ThrowStatement
TryStatement TryStatement
= TryToken __ block:Block __ handler:Catch __ finalizer:Finally { = TryToken __ block:Block __ handler:Catch __ finalizer:Finally {
return { return {
type: "TryStatement", type: "TryStatement",
block: block, block: block,
handler: handler, handler: handler,
finalizer: finalizer finalizer: finalizer
}; };
} }
/ TryToken __ block:Block __ handler:Catch { / TryToken __ block:Block __ handler:Catch {
return { return {
type: "TryStatement", type: "TryStatement",
block: block, block: block,
handler: handler, handler: handler,
finalizer: null finalizer: null
}; };
} }
/ TryToken __ block:Block __ finalizer:Finally { / TryToken __ block:Block __ finalizer:Finally {
return { return {
type: "TryStatement", type: "TryStatement",
block: block, block: block,
handler: null, handler: null,
finalizer: finalizer finalizer: finalizer
}; };
} }
@ -1256,9 +1256,9 @@ TryStatement
Catch Catch
= CatchToken __ "(" __ param:Identifier __ ")" __ body:Block { = CatchToken __ "(" __ param:Identifier __ ")" __ body:Block {
return { return {
type: "CatchClause", type: "CatchClause",
param: param, param: param,
body: body body: body
}; };
} }
@ -1276,10 +1276,10 @@ FunctionDeclaration
"{" __ body:FunctionBody __ "}" "{" __ body:FunctionBody __ "}"
{ {
return { return {
type: "FunctionDeclaration", type: "FunctionDeclaration",
id: id, id: id,
params: optionalList(extractOptional(params, 0)), params: optionalList(extractOptional(params, 0)),
body: body body: body
}; };
} }
@ -1289,10 +1289,10 @@ FunctionExpression
"{" __ body:FunctionBody __ "}" "{" __ body:FunctionBody __ "}"
{ {
return { return {
type: "FunctionExpression", type: "FunctionExpression",
id: extractOptional(id, 0), id: extractOptional(id, 0),
params: optionalList(extractOptional(params, 0)), params: optionalList(extractOptional(params, 0)),
body: body body: body
}; };
} }

@ -33,7 +33,7 @@ let asts = {
} }
let consumes = visitor.build({ let consumes = visitor.build({
rule: consumesExpression, rule: consumesExpression,
named: consumesExpression, named: consumesExpression,
choice: function(node) { choice: function(node) {
@ -46,14 +46,14 @@ let asts = {
return node.elements.some(consumes); return node.elements.some(consumes);
}, },
labeled: consumesExpression, labeled: consumesExpression,
text: consumesExpression, text: consumesExpression,
simple_and: consumesFalse, simple_and: consumesFalse,
simple_not: consumesFalse, simple_not: consumesFalse,
optional: consumesFalse, optional: consumesFalse,
zero_or_more: consumesFalse, zero_or_more: consumesFalse,
one_or_more: consumesExpression, one_or_more: consumesExpression,
group: consumesExpression, group: consumesExpression,
semantic_and: consumesFalse, semantic_and: consumesFalse,
semantic_not: consumesFalse, semantic_not: consumesFalse,
@ -66,7 +66,7 @@ let asts = {
}, },
"class": consumesTrue, "class": consumesTrue,
any: consumesTrue any: consumesTrue
}); });
return consumes(node); return consumes(node);

@ -28,18 +28,18 @@ let compiler = {
// |peg.GrammarError|. // |peg.GrammarError|.
passes: { passes: {
check: { check: {
reportUndefinedRules: require("./passes/report-undefined-rules"), reportUndefinedRules: require("./passes/report-undefined-rules"),
reportDuplicateRules: require("./passes/report-duplicate-rules"), reportDuplicateRules: require("./passes/report-duplicate-rules"),
reportDuplicateLabels: require("./passes/report-duplicate-labels"), reportDuplicateLabels: require("./passes/report-duplicate-labels"),
reportInfiniteRecursion: require("./passes/report-infinite-recursion"), reportInfiniteRecursion: require("./passes/report-infinite-recursion"),
reportInfiniteRepetition: require("./passes/report-infinite-repetition") reportInfiniteRepetition: require("./passes/report-infinite-repetition")
}, },
transform: { transform: {
removeProxyRules: require("./passes/remove-proxy-rules") removeProxyRules: require("./passes/remove-proxy-rules")
}, },
generate: { generate: {
generateBytecode: require("./passes/generate-bytecode"), generateBytecode: require("./passes/generate-bytecode"),
generateJS: require("./passes/generate-js") generateJS: require("./passes/generate-js")
} }
}, },
@ -52,13 +52,13 @@ let compiler = {
options = processOptions(options, { options = processOptions(options, {
allowedStartRules: [ast.rules[0].name], allowedStartRules: [ast.rules[0].name],
cache: false, cache: false,
dependencies: {}, dependencies: {},
exportVar: null, exportVar: null,
format: "bare", format: "bare",
optimize: "speed", optimize: "speed",
output: "parser", output: "parser",
trace: false trace: false
}); });
Object.keys(passes).forEach(stage => { Object.keys(passes).forEach(stage => {

@ -239,8 +239,8 @@ function generateBytecode(ast) {
[op.PUSH_CURR_POS], [op.PUSH_CURR_POS],
[op.SILENT_FAILS_ON], [op.SILENT_FAILS_ON],
generate(expression, { generate(expression, {
sp: context.sp + 1, sp: context.sp + 1,
env: cloneEnv(context.env), env: cloneEnv(context.env),
action: null action: null
}), }),
[op.SILENT_FAILS_OFF], [op.SILENT_FAILS_OFF],
@ -296,8 +296,8 @@ function generateBytecode(ast) {
rule: function(node) { rule: function(node) {
node.bytecode = generate(node.expression, { node.bytecode = generate(node.expression, {
sp: -1, // stack pointer sp: -1, // stack pointer
env: { }, // mapping of label names to stack positions env: { }, // mapping of label names to stack positions
action: null // action nodes pass themselves to children here action: null // action nodes pass themselves to children here
}); });
}, },
@ -323,8 +323,8 @@ function generateBytecode(ast) {
function buildAlternativesCode(alternatives, context) { function buildAlternativesCode(alternatives, context) {
return buildSequence( return buildSequence(
generate(alternatives[0], { generate(alternatives[0], {
sp: context.sp, sp: context.sp,
env: cloneEnv(context.env), env: cloneEnv(context.env),
action: null action: null
}), }),
alternatives.length > 1 alternatives.length > 1
@ -348,8 +348,8 @@ function generateBytecode(ast) {
let emitCall = node.expression.type !== "sequence" let emitCall = node.expression.type !== "sequence"
|| node.expression.elements.length === 0; || node.expression.elements.length === 0;
let expressionCode = generate(node.expression, { let expressionCode = generate(node.expression, {
sp: context.sp + (emitCall ? 1 : 0), sp: context.sp + (emitCall ? 1 : 0),
env: env, env: env,
action: node action: node
}); });
let functionIndex = addFunctionConst(Object.keys(env), node.code); let functionIndex = addFunctionConst(Object.keys(env), node.code);
@ -378,15 +378,15 @@ function generateBytecode(ast) {
return buildSequence( return buildSequence(
generate(elements[0], { generate(elements[0], {
sp: context.sp, sp: context.sp,
env: context.env, env: context.env,
action: null action: null
}), }),
buildCondition( buildCondition(
[op.IF_NOT_ERROR], [op.IF_NOT_ERROR],
buildElementsCode(elements.slice(1), { buildElementsCode(elements.slice(1), {
sp: context.sp + 1, sp: context.sp + 1,
env: context.env, env: context.env,
action: context.action action: context.action
}), }),
buildSequence( buildSequence(
@ -422,8 +422,8 @@ function generateBytecode(ast) {
return buildSequence( return buildSequence(
[op.PUSH_CURR_POS], [op.PUSH_CURR_POS],
buildElementsCode(node.elements, { buildElementsCode(node.elements, {
sp: context.sp + 1, sp: context.sp + 1,
env: context.env, env: context.env,
action: context.action action: context.action
}) })
); );
@ -435,8 +435,8 @@ function generateBytecode(ast) {
context.env[node.label] = context.sp + 1; context.env[node.label] = context.sp + 1;
return generate(node.expression, { return generate(node.expression, {
sp: context.sp, sp: context.sp,
env: env, env: env,
action: null action: null
}); });
}, },
@ -445,8 +445,8 @@ function generateBytecode(ast) {
return buildSequence( return buildSequence(
[op.PUSH_CURR_POS], [op.PUSH_CURR_POS],
generate(node.expression, { generate(node.expression, {
sp: context.sp + 1, sp: context.sp + 1,
env: cloneEnv(context.env), env: cloneEnv(context.env),
action: null action: null
}), }),
buildCondition( buildCondition(
@ -468,8 +468,8 @@ function generateBytecode(ast) {
optional: function(node, context) { optional: function(node, context) {
return buildSequence( return buildSequence(
generate(node.expression, { generate(node.expression, {
sp: context.sp, sp: context.sp,
env: cloneEnv(context.env), env: cloneEnv(context.env),
action: null action: null
}), }),
buildCondition( buildCondition(
@ -482,8 +482,8 @@ function generateBytecode(ast) {
zero_or_more: function(node, context) { zero_or_more: function(node, context) {
let expressionCode = generate(node.expression, { let expressionCode = generate(node.expression, {
sp: context.sp + 1, sp: context.sp + 1,
env: cloneEnv(context.env), env: cloneEnv(context.env),
action: null action: null
}); });
@ -497,8 +497,8 @@ function generateBytecode(ast) {
one_or_more: function(node, context) { one_or_more: function(node, context) {
let expressionCode = generate(node.expression, { let expressionCode = generate(node.expression, {
sp: context.sp + 1, sp: context.sp + 1,
env: cloneEnv(context.env), env: cloneEnv(context.env),
action: null action: null
}); });
@ -515,8 +515,8 @@ function generateBytecode(ast) {
group: function(node, context) { group: function(node, context) {
return generate(node.expression, { return generate(node.expression, {
sp: context.sp, sp: context.sp,
env: cloneEnv(context.env), env: cloneEnv(context.env),
action: null action: null
}); });
}, },

@ -40,8 +40,8 @@ function generateJS(ast, options) {
if (options.trace) { if (options.trace) {
parts.push([ parts.push([
"peg$tracer.trace({", "peg$tracer.trace({",
" type: \"rule.enter\",", " type: \"rule.enter\",",
" rule: " + ruleNameCode + ",", " rule: " + ruleNameCode + ",",
" location: peg$computeLocation(startPos, startPos)", " location: peg$computeLocation(startPos, startPos)",
"});", "});",
"" ""
@ -62,8 +62,8 @@ function generateJS(ast, options) {
parts.push([ parts.push([
"if (cached.result !== peg$FAILED) {", "if (cached.result !== peg$FAILED) {",
" peg$tracer.trace({", " peg$tracer.trace({",
" type: \"rule.match\",", " type: \"rule.match\",",
" rule: " + ruleNameCode + ",", " rule: " + ruleNameCode + ",",
" result: cached.result,", " result: cached.result,",
" location: peg$computeLocation(startPos, peg$currPos)", " location: peg$computeLocation(startPos, peg$currPos)",
" });", " });",
@ -103,8 +103,8 @@ function generateJS(ast, options) {
"", "",
"if (" + resultCode + " !== peg$FAILED) {", "if (" + resultCode + " !== peg$FAILED) {",
" peg$tracer.trace({", " peg$tracer.trace({",
" type: \"rule.match\",", " type: \"rule.match\",",
" rule: " + ruleNameCode + ",", " rule: " + ruleNameCode + ",",
" result: " + resultCode + ",", " result: " + resultCode + ",",
" location: peg$computeLocation(startPos, peg$currPos)", " location: peg$computeLocation(startPos, peg$currPos)",
" });", " });",
@ -411,7 +411,7 @@ function generateJS(ast, options) {
function s(i) { return "s" + i; } // |stack[i]| of the abstract machine function s(i) { return "s" + i; } // |stack[i]| of the abstract machine
let stack = { let stack = {
sp: -1, sp: -1,
maxSp: -1, maxSp: -1,
push: function(exprCode) { push: function(exprCode) {
@ -1088,7 +1088,7 @@ function generateJS(ast, options) {
"", "",
" details = peg$posDetailsCache[p];", " details = peg$posDetailsCache[p];",
" details = {", " details = {",
" line: details.line,", " line: details.line,",
" column: details.column", " column: details.column",
" };", " };",
"", "",
@ -1115,12 +1115,12 @@ function generateJS(ast, options) {
" return {", " return {",
" start: {", " start: {",
" offset: startPos,", " offset: startPos,",
" line: startPosDetails.line,", " line: startPosDetails.line,",
" column: startPosDetails.column", " column: startPosDetails.column",
" },", " },",
" end: {", " end: {",
" offset: endPos,", " offset: endPos,",
" line: endPosDetails.line,", " line: endPosDetails.line,",
" column: endPosDetails.column", " column: endPosDetails.column",
" }", " }",
" };", " };",
@ -1209,15 +1209,15 @@ function generateJS(ast, options) {
return options.trace return options.trace
? [ ? [
"{", "{",
" SyntaxError: peg$SyntaxError,", " SyntaxError: peg$SyntaxError,",
" DefaultTracer: peg$DefaultTracer,", " DefaultTracer: peg$DefaultTracer,",
" parse: peg$parse", " parse: peg$parse",
"}" "}"
].join("\n") ].join("\n")
: [ : [
"{", "{",
" SyntaxError: peg$SyntaxError,", " SyntaxError: peg$SyntaxError,",
" parse: peg$parse", " parse: peg$parse",
"}" "}"
].join("\n"); ].join("\n");
} }

@ -47,13 +47,13 @@ function reportDuplicateLabels(ast) {
env[node.label] = node.location; env[node.label] = node.location;
}, },
text: checkExpressionWithClonedEnv, text: checkExpressionWithClonedEnv,
simple_and: checkExpressionWithClonedEnv, simple_and: checkExpressionWithClonedEnv,
simple_not: checkExpressionWithClonedEnv, simple_not: checkExpressionWithClonedEnv,
optional: checkExpressionWithClonedEnv, optional: checkExpressionWithClonedEnv,
zero_or_more: checkExpressionWithClonedEnv, zero_or_more: checkExpressionWithClonedEnv,
one_or_more: checkExpressionWithClonedEnv, one_or_more: checkExpressionWithClonedEnv,
group: checkExpressionWithClonedEnv group: checkExpressionWithClonedEnv
}); });
check(ast); check(ast);

@ -38,26 +38,26 @@ let visitor = {
}); });
}, },
initializer: visitNop, initializer: visitNop,
rule: visitExpression, rule: visitExpression,
named: visitExpression, named: visitExpression,
choice: visitChildren("alternatives"), choice: visitChildren("alternatives"),
action: visitExpression, action: visitExpression,
sequence: visitChildren("elements"), sequence: visitChildren("elements"),
labeled: visitExpression, labeled: visitExpression,
text: visitExpression, text: visitExpression,
simple_and: visitExpression, simple_and: visitExpression,
simple_not: visitExpression, simple_not: visitExpression,
optional: visitExpression, optional: visitExpression,
zero_or_more: visitExpression, zero_or_more: visitExpression,
one_or_more: visitExpression, one_or_more: visitExpression,
group: visitExpression, group: visitExpression,
semantic_and: visitNop, semantic_and: visitNop,
semantic_not: visitNop, semantic_not: visitNop,
rule_ref: visitNop, rule_ref: visitNop,
literal: visitNop, literal: visitNop,
"class": visitNop, "class": visitNop,
any: visitNop any: visitNop
}; };
Object.keys(DEFAULT_FUNCTIONS).forEach(type => { Object.keys(DEFAULT_FUNCTIONS).forEach(type => {

@ -137,10 +137,10 @@ function peg$parse(input, options) {
var peg$c0 = function(initializer, rules) { var peg$c0 = function(initializer, rules) {
return { return {
type: "grammar", type: "grammar",
initializer: extractOptional(initializer, 0), initializer: extractOptional(initializer, 0),
rules: extractList(rules, 0), rules: extractList(rules, 0),
location: location() location: location()
}; };
}; };
var peg$c1 = function(code) { var peg$c1 = function(code) {
@ -150,17 +150,17 @@ function peg$parse(input, options) {
var peg$c3 = peg$literalExpectation("=", false); var peg$c3 = peg$literalExpectation("=", false);
var peg$c4 = function(name, displayName, expression) { var peg$c4 = function(name, displayName, expression) {
return { return {
type: "rule", type: "rule",
name: name, name: name,
expression: displayName !== null expression: displayName !== null
? { ? {
type: "named", type: "named",
name: displayName[0], name: displayName[0],
expression: expression, expression: expression,
location: location() location: location()
} }
: expression, : expression,
location: location() location: location()
}; };
}; };
var peg$c5 = "/"; var peg$c5 = "/";
@ -168,26 +168,26 @@ function peg$parse(input, options) {
var peg$c7 = function(head, tail) { var peg$c7 = function(head, tail) {
return tail.length > 0 return tail.length > 0
? { ? {
type: "choice", type: "choice",
alternatives: buildList(head, tail, 3), alternatives: buildList(head, tail, 3),
location: location() location: location()
} }
: head; : head;
}; };
var peg$c8 = function(expression, code) { var peg$c8 = function(expression, code) {
return code !== null return code !== null
? { ? {
type: "action", type: "action",
expression: expression, expression: expression,
code: code[1], code: code[1],
location: location() location: location()
} }
: expression; : expression;
}; };
var peg$c9 = function(head, tail) { var peg$c9 = function(head, tail) {
return tail.length > 0 return tail.length > 0
? { ? {
type: "sequence", type: "sequence",
elements: buildList(head, tail, 1), elements: buildList(head, tail, 1),
location: location() location: location()
} }
@ -197,17 +197,17 @@ function peg$parse(input, options) {
var peg$c11 = peg$literalExpectation(":", false); var peg$c11 = peg$literalExpectation(":", false);
var peg$c12 = function(label, expression) { var peg$c12 = function(label, expression) {
return { return {
type: "labeled", type: "labeled",
label: label, label: label,
expression: expression, expression: expression,
location: location() location: location()
}; };
}; };
var peg$c13 = function(operator, expression) { var peg$c13 = function(operator, expression) {
return { return {
type: OPS_TO_PREFIXED_TYPES[operator], type: OPS_TO_PREFIXED_TYPES[operator],
expression: expression, expression: expression,
location: location() location: location()
}; };
}; };
var peg$c14 = "$"; var peg$c14 = "$";
@ -218,9 +218,9 @@ function peg$parse(input, options) {
var peg$c19 = peg$literalExpectation("!", false); var peg$c19 = peg$literalExpectation("!", false);
var peg$c20 = function(expression, operator) { var peg$c20 = function(expression, operator) {
return { return {
type: OPS_TO_SUFFIXED_TYPES[operator], type: OPS_TO_SUFFIXED_TYPES[operator],
expression: expression, expression: expression,
location: location() location: location()
}; };
}; };
var peg$c21 = "?"; var peg$c21 = "?";
@ -247,8 +247,8 @@ function peg$parse(input, options) {
}; };
var peg$c33 = function(operator, code) { var peg$c33 = function(operator, code) {
return { return {
type: OPS_TO_SEMANTIC_PREDICATE_TYPES[operator], type: OPS_TO_SEMANTIC_PREDICATE_TYPES[operator],
code: code, code: code,
location: location() location: location()
}; };
}; };
@ -303,10 +303,10 @@ function peg$parse(input, options) {
var peg$c82 = peg$literalExpectation("i", false); var peg$c82 = peg$literalExpectation("i", false);
var peg$c83 = function(value, ignoreCase) { var peg$c83 = function(value, ignoreCase) {
return { return {
type: "literal", type: "literal",
value: value, value: value,
ignoreCase: ignoreCase !== null, ignoreCase: ignoreCase !== null,
location: location() location: location()
}; };
}; };
var peg$c84 = peg$otherExpectation("string"); var peg$c84 = peg$otherExpectation("string");
@ -325,11 +325,11 @@ function peg$parse(input, options) {
var peg$c97 = peg$literalExpectation("]", false); var peg$c97 = peg$literalExpectation("]", false);
var peg$c98 = function(inverted, parts, ignoreCase) { var peg$c98 = function(inverted, parts, ignoreCase) {
return { return {
type: "class", type: "class",
parts: parts.filter(part => part !== ""), parts: parts.filter(part => part !== ""),
inverted: inverted !== null, inverted: inverted !== null,
ignoreCase: ignoreCase !== null, ignoreCase: ignoreCase !== null,
location: location() location: location()
}; };
}; };
var peg$c99 = "-"; var peg$c99 = "-";
@ -559,7 +559,7 @@ function peg$parse(input, options) {
details = peg$posDetailsCache[p]; details = peg$posDetailsCache[p];
details = { details = {
line: details.line, line: details.line,
column: details.column column: details.column
}; };
@ -586,12 +586,12 @@ function peg$parse(input, options) {
return { return {
start: { start: {
offset: startPos, offset: startPos,
line: startPosDetails.line, line: startPosDetails.line,
column: startPosDetails.column column: startPosDetails.column
}, },
end: { end: {
offset: endPos, offset: endPos,
line: endPosDetails.line, line: endPosDetails.line,
column: endPosDetails.column column: endPosDetails.column
} }
}; };
@ -5008,5 +5008,5 @@ function peg$parse(input, options) {
module.exports = { module.exports = {
SyntaxError: peg$SyntaxError, SyntaxError: peg$SyntaxError,
parse: peg$parse parse: peg$parse
}; };

@ -5,8 +5,8 @@ let peg = {
VERSION: "0.10.0", VERSION: "0.10.0",
GrammarError: require("./grammar-error"), GrammarError: require("./grammar-error"),
parser: require("./parser"), parser: require("./parser"),
compiler: require("./compiler"), compiler: require("./compiler"),
// Generates a parser from a specified grammar and returns it. // Generates a parser from a specified grammar and returns it.
// //

@ -80,53 +80,53 @@ describe("generated parser API", function() {
parser.parse("b", { tracer: tracer }); parser.parse("b", { tracer: tracer });
expect(tracer.trace).toHaveBeenCalledWith({ expect(tracer.trace).toHaveBeenCalledWith({
type: "rule.enter", type: "rule.enter",
rule: "start", rule: "start",
location: { location: {
start: { offset: 0, line: 1, column: 1 }, start: { offset: 0, line: 1, column: 1 },
end: { offset: 0, line: 1, column: 1 } end: { offset: 0, line: 1, column: 1 }
} }
}); });
expect(tracer.trace).toHaveBeenCalledWith({ expect(tracer.trace).toHaveBeenCalledWith({
type: "rule.enter", type: "rule.enter",
rule: "a", rule: "a",
location: { location: {
start: { offset: 0, line: 1, column: 1 }, start: { offset: 0, line: 1, column: 1 },
end: { offset: 0, line: 1, column: 1 } end: { offset: 0, line: 1, column: 1 }
} }
}); });
expect(tracer.trace).toHaveBeenCalledWith({ expect(tracer.trace).toHaveBeenCalledWith({
type: "rule.fail", type: "rule.fail",
rule: "a", rule: "a",
location: { location: {
start: { offset: 0, line: 1, column: 1 }, start: { offset: 0, line: 1, column: 1 },
end: { offset: 0, line: 1, column: 1 } end: { offset: 0, line: 1, column: 1 }
} }
}); });
expect(tracer.trace).toHaveBeenCalledWith({ expect(tracer.trace).toHaveBeenCalledWith({
type: "rule.enter", type: "rule.enter",
rule: "b", rule: "b",
location: { location: {
start: { offset: 0, line: 1, column: 1 }, start: { offset: 0, line: 1, column: 1 },
end: { offset: 0, line: 1, column: 1 } end: { offset: 0, line: 1, column: 1 }
} }
}); });
expect(tracer.trace).toHaveBeenCalledWith({ expect(tracer.trace).toHaveBeenCalledWith({
type: "rule.match", type: "rule.match",
rule: "b", rule: "b",
result: "b", result: "b",
location: { location: {
start: { offset: 0, line: 1, column: 1 }, start: { offset: 0, line: 1, column: 1 },
end: { offset: 1, line: 1, column: 2 } end: { offset: 1, line: 1, column: 2 }
} }
}); });
expect(tracer.trace).toHaveBeenCalledWith({ expect(tracer.trace).toHaveBeenCalledWith({
type: "rule.match", type: "rule.match",
rule: "start", rule: "start",
result: "b", result: "b",
location: { location: {
start: { offset: 0, line: 1, column: 1 }, start: { offset: 0, line: 1, column: 1 },
end: { offset: 1, line: 1, column: 2 } end: { offset: 1, line: 1, column: 2 }
} }
}); });
}); });

@ -43,7 +43,7 @@ describe("PEG.js API", function() {
describe("when |allowedStartRules| is set", function() { describe("when |allowedStartRules| is set", function() {
it("generated parser can start only from specified rules", function() { it("generated parser can start only from specified rules", function() {
let parser = peg.generate(grammar, { let parser = peg.generate(grammar, {
optimize: "speed", optimize: "speed",
allowedStartRules: ["b", "c"] allowedStartRules: ["b", "c"]
}); });
@ -68,7 +68,7 @@ describe("PEG.js API", function() {
describe("when |allowedStartRules| is set", function() { describe("when |allowedStartRules| is set", function() {
it("generated parser can start only from specified rules", function() { it("generated parser can start only from specified rules", function() {
let parser = peg.generate(grammar, { let parser = peg.generate(grammar, {
optimize: "size", optimize: "size",
allowedStartRules: ["b", "c"] allowedStartRules: ["b", "c"]
}); });

@ -97,11 +97,11 @@ describe("plugin API", function() {
let parser = peg.generate([ let parser = peg.generate([
"start = .* {", "start = .* {",
" return {", " return {",
" type: 'grammar',", " type: 'grammar',",
" rules: [", " rules: [",
" {", " {",
" type: 'rule',", " type: 'rule',",
" name: 'start',", " name: 'start',",
" expression: { type: 'literal', value: text(), ignoreCase: false }", " expression: { type: 'literal', value: text(), ignoreCase: false }",
" }", " }",
" ]", " ]",
@ -145,7 +145,7 @@ describe("plugin API", function() {
}; };
let parser = peg.generate(grammar, { let parser = peg.generate(grammar, {
allowedStartRules: ["a"], allowedStartRules: ["a"],
plugins: [plugin] plugins: [plugin]
}); });
expect(() => { parser.parse("x", { startRule: "a" }); }).toThrow(); expect(() => { parser.parse("x", { startRule: "a" }); }).toThrow();

@ -460,47 +460,47 @@ describe("generated parser behavior", function() {
let testcases = [ let testcases = [
{ {
grammar: "start = (a:'a') &{ return a === 'a'; }", grammar: "start = (a:'a') &{ return a === 'a'; }",
input: "a" input: "a"
}, },
{ {
grammar: "start = (a:'a')? &{ return a === 'a'; }", grammar: "start = (a:'a')? &{ return a === 'a'; }",
input: "a" input: "a"
}, },
{ {
grammar: "start = (a:'a')* &{ return a === 'a'; }", grammar: "start = (a:'a')* &{ return a === 'a'; }",
input: "a" input: "a"
}, },
{ {
grammar: "start = (a:'a')+ &{ return a === 'a'; }", grammar: "start = (a:'a')+ &{ return a === 'a'; }",
input: "a" input: "a"
}, },
{ {
grammar: "start = $(a:'a') &{ return a === 'a'; }", grammar: "start = $(a:'a') &{ return a === 'a'; }",
input: "a" input: "a"
}, },
{ {
grammar: "start = &(a:'a') 'a' &{ return a === 'a'; }", grammar: "start = &(a:'a') 'a' &{ return a === 'a'; }",
input: "a" input: "a"
}, },
{ {
grammar: "start = !(a:'a') 'b' &{ return a === 'a'; }", grammar: "start = !(a:'a') 'b' &{ return a === 'a'; }",
input: "b" input: "b"
}, },
{ {
grammar: "start = b:(a:'a') &{ return a === 'a'; }", grammar: "start = b:(a:'a') &{ return a === 'a'; }",
input: "a" input: "a"
}, },
{ {
grammar: "start = ('a' b:'b' 'c') &{ return b === 'b'; }", grammar: "start = ('a' b:'b' 'c') &{ return b === 'b'; }",
input: "abc" input: "abc"
}, },
{ {
grammar: "start = (a:'a' { return a; }) &{ return a === 'a'; }", grammar: "start = (a:'a' { return a; }) &{ return a === 'a'; }",
input: "a" input: "a"
}, },
{ {
grammar: "start = ('a' / b:'b' / 'c') &{ return b === 'b'; }", grammar: "start = ('a' / b:'b' / 'c') &{ return b === 'b'; }",
input: "b" input: "b"
} }
]; ];
let parser; let parser;
@ -585,17 +585,17 @@ describe("generated parser behavior", function() {
expect(parser).toParse("1\n2\n\n3\n\n\n4 5 x", { expect(parser).toParse("1\n2\n\n3\n\n\n4 5 x", {
start: { offset: 13, line: 7, column: 5 }, start: { offset: 13, line: 7, column: 5 },
end: { offset: 13, line: 7, column: 5 } end: { offset: 13, line: 7, column: 5 }
}); });
// Newline representations // Newline representations
expect(parser).toParse("1\nx", { // Unix expect(parser).toParse("1\nx", { // Unix
start: { offset: 2, line: 2, column: 1 }, start: { offset: 2, line: 2, column: 1 },
end: { offset: 2, line: 2, column: 1 } end: { offset: 2, line: 2, column: 1 }
}); });
expect(parser).toParse("1\r\nx", { // Windows expect(parser).toParse("1\r\nx", { // Windows
start: { offset: 3, line: 2, column: 1 }, start: { offset: 3, line: 2, column: 1 },
end: { offset: 3, line: 2, column: 1 } end: { offset: 3, line: 2, column: 1 }
}); });
}); });
}); });
@ -654,47 +654,47 @@ describe("generated parser behavior", function() {
let testcases = [ let testcases = [
{ {
grammar: "start = (a:'a') !{ return a !== 'a'; }", grammar: "start = (a:'a') !{ return a !== 'a'; }",
input: "a" input: "a"
}, },
{ {
grammar: "start = (a:'a')? !{ return a !== 'a'; }", grammar: "start = (a:'a')? !{ return a !== 'a'; }",
input: "a" input: "a"
}, },
{ {
grammar: "start = (a:'a')* !{ return a !== 'a'; }", grammar: "start = (a:'a')* !{ return a !== 'a'; }",
input: "a" input: "a"
}, },
{ {
grammar: "start = (a:'a')+ !{ return a !== 'a'; }", grammar: "start = (a:'a')+ !{ return a !== 'a'; }",
input: "a" input: "a"
}, },
{ {
grammar: "start = $(a:'a') !{ return a !== 'a'; }", grammar: "start = $(a:'a') !{ return a !== 'a'; }",
input: "a" input: "a"
}, },
{ {
grammar: "start = &(a:'a') 'a' !{ return a !== 'a'; }", grammar: "start = &(a:'a') 'a' !{ return a !== 'a'; }",
input: "a" input: "a"
}, },
{ {
grammar: "start = !(a:'a') 'b' !{ return a !== 'a'; }", grammar: "start = !(a:'a') 'b' !{ return a !== 'a'; }",
input: "b" input: "b"
}, },
{ {
grammar: "start = b:(a:'a') !{ return a !== 'a'; }", grammar: "start = b:(a:'a') !{ return a !== 'a'; }",
input: "a" input: "a"
}, },
{ {
grammar: "start = ('a' b:'b' 'c') !{ return b !== 'b'; }", grammar: "start = ('a' b:'b' 'c') !{ return b !== 'b'; }",
input: "abc" input: "abc"
}, },
{ {
grammar: "start = (a:'a' { return a; }) !{ return a !== 'a'; }", grammar: "start = (a:'a' { return a; }) !{ return a !== 'a'; }",
input: "a" input: "a"
}, },
{ {
grammar: "start = ('a' / b:'b' / 'c') !{ return b !== 'b'; }", grammar: "start = ('a' / b:'b' / 'c') !{ return b !== 'b'; }",
input: "b" input: "b"
} }
]; ];
let parser; let parser;
@ -779,17 +779,17 @@ describe("generated parser behavior", function() {
expect(parser).toParse("1\n2\n\n3\n\n\n4 5 x", { expect(parser).toParse("1\n2\n\n3\n\n\n4 5 x", {
start: { offset: 13, line: 7, column: 5 }, start: { offset: 13, line: 7, column: 5 },
end: { offset: 13, line: 7, column: 5 } end: { offset: 13, line: 7, column: 5 }
}); });
// Newline representations // Newline representations
expect(parser).toParse("1\nx", { // Unix expect(parser).toParse("1\nx", { // Unix
start: { offset: 2, line: 2, column: 1 }, start: { offset: 2, line: 2, column: 1 },
end: { offset: 2, line: 2, column: 1 } end: { offset: 2, line: 2, column: 1 }
}); });
expect(parser).toParse("1\r\nx", { // Windows expect(parser).toParse("1\r\nx", { // Windows
start: { offset: 3, line: 2, column: 1 }, start: { offset: 3, line: 2, column: 1 },
end: { offset: 3, line: 2, column: 1 } end: { offset: 3, line: 2, column: 1 }
}); });
}); });
}); });
@ -1023,47 +1023,47 @@ describe("generated parser behavior", function() {
let testcases = [ let testcases = [
{ {
grammar: "start = (a:'a') { return a; }", grammar: "start = (a:'a') { return a; }",
input: "a" input: "a"
}, },
{ {
grammar: "start = (a:'a')? { return a; }", grammar: "start = (a:'a')? { return a; }",
input: "a" input: "a"
}, },
{ {
grammar: "start = (a:'a')* { return a; }", grammar: "start = (a:'a')* { return a; }",
input: "a" input: "a"
}, },
{ {
grammar: "start = (a:'a')+ { return a; }", grammar: "start = (a:'a')+ { return a; }",
input: "a" input: "a"
}, },
{ {
grammar: "start = $(a:'a') { return a; }", grammar: "start = $(a:'a') { return a; }",
input: "a" input: "a"
}, },
{ {
grammar: "start = &(a:'a') 'a' { return a; }", grammar: "start = &(a:'a') 'a' { return a; }",
input: "a" input: "a"
}, },
{ {
grammar: "start = !(a:'a') 'b' { return a; }", grammar: "start = !(a:'a') 'b' { return a; }",
input: "b" input: "b"
}, },
{ {
grammar: "start = b:(a:'a') { return a; }", grammar: "start = b:(a:'a') { return a; }",
input: "a" input: "a"
}, },
{ {
grammar: "start = ('a' b:'b' 'c') { return b; }", grammar: "start = ('a' b:'b' 'c') { return b; }",
input: "abc" input: "abc"
}, },
{ {
grammar: "start = (a:'a' { return a; }) { return a; }", grammar: "start = (a:'a' { return a; }) { return a; }",
input: "a" input: "a"
}, },
{ {
grammar: "start = ('a' / b:'b' / 'c') { return b; }", grammar: "start = ('a' / b:'b' / 'c') { return b; }",
input: "b" input: "b"
} }
]; ];
let parser; let parser;
@ -1157,17 +1157,17 @@ describe("generated parser behavior", function() {
expect(parser).toParse("1\n2\n\n3\n\n\n4 5 x", { expect(parser).toParse("1\n2\n\n3\n\n\n4 5 x", {
start: { offset: 13, line: 7, column: 5 }, start: { offset: 13, line: 7, column: 5 },
end: { offset: 14, line: 7, column: 6 } end: { offset: 14, line: 7, column: 6 }
}); });
// Newline representations // Newline representations
expect(parser).toParse("1\nx", { // Unix expect(parser).toParse("1\nx", { // Unix
start: { offset: 2, line: 2, column: 1 }, start: { offset: 2, line: 2, column: 1 },
end: { offset: 3, line: 2, column: 2 } end: { offset: 3, line: 2, column: 2 }
}); });
expect(parser).toParse("1\r\nx", { // Windows expect(parser).toParse("1\r\nx", { // Windows
start: { offset: 3, line: 2, column: 1 }, start: { offset: 3, line: 2, column: 1 },
end: { offset: 4, line: 2, column: 2 } end: { offset: 4, line: 2, column: 2 }
}); });
}); });
@ -1179,12 +1179,12 @@ describe("generated parser behavior", function() {
); );
expect(parser).toFailToParse("a", { expect(parser).toFailToParse("a", {
message: "Expected a but \"a\" found.", message: "Expected a but \"a\" found.",
expected: [{ type: "other", description: "a" }], expected: [{ type: "other", description: "a" }],
found: "a", found: "a",
location: { location: {
start: { offset: 0, line: 1, column: 1 }, start: { offset: 0, line: 1, column: 1 },
end: { offset: 1, line: 1, column: 2 } end: { offset: 1, line: 1, column: 2 }
} }
}); });
}); });
@ -1194,18 +1194,18 @@ describe("generated parser behavior", function() {
"start = 'a' {", "start = 'a' {",
" expected('a', {", " expected('a', {",
" start: { offset: 1, line: 1, column: 2 },", " start: { offset: 1, line: 1, column: 2 },",
" end: { offset: 2, line: 1, column: 3 }", " end: { offset: 2, line: 1, column: 3 }",
" });", " });",
"}" "}"
].join("\n"), options); ].join("\n"), options);
expect(parser).toFailToParse("a", { expect(parser).toFailToParse("a", {
message: "Expected a but \"a\" found.", message: "Expected a but \"a\" found.",
expected: [{ type: "other", description: "a" }], expected: [{ type: "other", description: "a" }],
found: "a", found: "a",
location: { location: {
start: { offset: 1, line: 1, column: 2 }, start: { offset: 1, line: 1, column: 2 },
end: { offset: 2, line: 1, column: 3 } end: { offset: 2, line: 1, column: 3 }
} }
}); });
}); });
@ -1219,12 +1219,12 @@ describe("generated parser behavior", function() {
); );
expect(parser).toFailToParse("a", { expect(parser).toFailToParse("a", {
message: "a", message: "a",
found: null, found: null,
expected: null, expected: null,
location: { location: {
start: { offset: 0, line: 1, column: 1 }, start: { offset: 0, line: 1, column: 1 },
end: { offset: 1, line: 1, column: 2 } end: { offset: 1, line: 1, column: 2 }
} }
}); });
}); });
@ -1234,18 +1234,18 @@ describe("generated parser behavior", function() {
"start = 'a' {", "start = 'a' {",
" error('a', {", " error('a', {",
" start: { offset: 1, line: 1, column: 2 },", " start: { offset: 1, line: 1, column: 2 },",
" end: { offset: 2, line: 1, column: 3 }", " end: { offset: 2, line: 1, column: 3 }",
" });", " });",
"}" "}"
].join("\n"), options); ].join("\n"), options);
expect(parser).toFailToParse("a", { expect(parser).toFailToParse("a", {
message: "a", message: "a",
expected: null, expected: null,
found: null, found: null,
location: { location: {
start: { offset: 1, line: 1, column: 2 }, start: { offset: 1, line: 1, column: 2 },
end: { offset: 2, line: 1, column: 3 } end: { offset: 2, line: 1, column: 3 }
} }
}); });
}); });
@ -1412,7 +1412,7 @@ describe("generated parser behavior", function() {
expect(parser).toFailToParse("", { expect(parser).toFailToParse("", {
location: { location: {
start: { offset: 0, line: 1, column: 1 }, start: { offset: 0, line: 1, column: 1 },
end: { offset: 0, line: 1, column: 1 } end: { offset: 0, line: 1, column: 1 }
} }
}); });
}); });
@ -1423,7 +1423,7 @@ describe("generated parser behavior", function() {
expect(parser).toFailToParse("b", { expect(parser).toFailToParse("b", {
location: { location: {
start: { offset: 0, line: 1, column: 1 }, start: { offset: 0, line: 1, column: 1 },
end: { offset: 1, line: 1, column: 2 } end: { offset: 1, line: 1, column: 2 }
} }
}); });
}); });
@ -1434,7 +1434,7 @@ describe("generated parser behavior", function() {
expect(parser).toFailToParse("aa", { expect(parser).toFailToParse("aa", {
location: { location: {
start: { offset: 1, line: 1, column: 2 }, start: { offset: 1, line: 1, column: 2 },
end: { offset: 2, line: 1, column: 3 } end: { offset: 2, line: 1, column: 3 }
} }
}); });
}); });
@ -1450,7 +1450,7 @@ describe("generated parser behavior", function() {
expect(parser).toFailToParse("1\n2\n\n3\n\n\n4 5 x", { expect(parser).toFailToParse("1\n2\n\n3\n\n\n4 5 x", {
location: { location: {
start: { offset: 13, line: 7, column: 5 }, start: { offset: 13, line: 7, column: 5 },
end: { offset: 14, line: 7, column: 6 } end: { offset: 14, line: 7, column: 6 }
} }
}); });
@ -1458,13 +1458,13 @@ describe("generated parser behavior", function() {
expect(parser).toFailToParse("1\nx", { // Old Mac expect(parser).toFailToParse("1\nx", { // Old Mac
location: { location: {
start: { offset: 2, line: 2, column: 1 }, start: { offset: 2, line: 2, column: 1 },
end: { offset: 3, line: 2, column: 2 } end: { offset: 3, line: 2, column: 2 }
} }
}); });
expect(parser).toFailToParse("1\r\nx", { // Windows expect(parser).toFailToParse("1\r\nx", { // Windows
location: { location: {
start: { offset: 3, line: 2, column: 1 }, start: { offset: 3, line: 2, column: 1 },
end: { offset: 4, line: 2, column: 2 } end: { offset: 4, line: 2, column: 2 }
} }
}); });
}); });

@ -16,7 +16,7 @@ describe("compiler pass |removeProxyRules|", function() {
{ {
rules: [ rules: [
{ {
name: "start", name: "start",
expression: { type: "rule_ref", name: "proxied" } expression: { type: "rule_ref", name: "proxied" }
}, },
{ name: "proxied" } { name: "proxied" }
@ -38,11 +38,11 @@ describe("compiler pass |removeProxyRules|", function() {
{ {
rules: [ rules: [
{ {
name: "start", name: "start",
expression: { type: "rule_ref", name: "proxied" } expression: { type: "rule_ref", name: "proxied" }
}, },
{ {
name: "proxy", name: "proxy",
expression: { type: "rule_ref", name: "proxied" } expression: { type: "rule_ref", name: "proxied" }
}, },
{ name: "proxied" } { name: "proxied" }

@ -8,10 +8,10 @@ describe("compiler pass |reportDuplicateLabels|", function() {
describe("in a sequence", function() { describe("in a sequence", function() {
it("reports labels duplicate with labels of preceding elements", function() { it("reports labels duplicate with labels of preceding elements", function() {
expect(pass).toReportError("start = a:'a' a:'a'", { expect(pass).toReportError("start = a:'a' a:'a'", {
message: "Label \"a\" is already defined at line 1, column 9.", message: "Label \"a\" is already defined at line 1, column 9.",
location: { location: {
start: { offset: 14, line: 1, column: 15 }, start: { offset: 14, line: 1, column: 15 },
end: { offset: 19, line: 1, column: 20 } end: { offset: 19, line: 1, column: 20 }
} }
}); });
}); });
@ -40,10 +40,10 @@ describe("compiler pass |reportDuplicateLabels|", function() {
describe("in outer sequence", function() { describe("in outer sequence", function() {
it("reports labels duplicate with labels of preceding elements", function() { it("reports labels duplicate with labels of preceding elements", function() {
expect(pass).toReportError("start = a:'a' (a:'a')", { expect(pass).toReportError("start = a:'a' (a:'a')", {
message: "Label \"a\" is already defined at line 1, column 9.", message: "Label \"a\" is already defined at line 1, column 9.",
location: { location: {
start: { offset: 15, line: 1, column: 16 }, start: { offset: 15, line: 1, column: 16 },
end: { offset: 20, line: 1, column: 21 } end: { offset: 20, line: 1, column: 21 }
} }
}); });
}); });

@ -10,10 +10,10 @@ describe("compiler pass |reportDuplicateRules|", function() {
"start = 'a'", "start = 'a'",
"start = 'b'" "start = 'b'"
].join("\n"), { ].join("\n"), {
message: "Rule \"start\" is already defined at line 1, column 1.", message: "Rule \"start\" is already defined at line 1, column 1.",
location: { location: {
start: { offset: 12, line: 2, column: 1 }, start: { offset: 12, line: 2, column: 1 },
end: { offset: 23, line: 2, column: 12 } end: { offset: 23, line: 2, column: 12 }
} }
}); });
}); });

@ -7,10 +7,10 @@ describe("compiler pass |reportInfiniteRecursion|", function() {
it("reports direct left recursion", function() { it("reports direct left recursion", function() {
expect(pass).toReportError("start = start", { expect(pass).toReportError("start = start", {
message: "Possible infinite loop when parsing (left recursion: start -> start).", message: "Possible infinite loop when parsing (left recursion: start -> start).",
location: { location: {
start: { offset: 8, line: 1, column: 9 }, start: { offset: 8, line: 1, column: 9 },
end: { offset: 13, line: 1, column: 14 } end: { offset: 13, line: 1, column: 14 }
} }
}); });
}); });
@ -20,10 +20,10 @@ describe("compiler pass |reportInfiniteRecursion|", function() {
"start = stop", "start = stop",
"stop = start" "stop = start"
].join("\n"), { ].join("\n"), {
message: "Possible infinite loop when parsing (left recursion: start -> stop -> start).", message: "Possible infinite loop when parsing (left recursion: start -> stop -> start).",
location: { location: {
start: { offset: 21, line: 2, column: 9 }, start: { offset: 21, line: 2, column: 9 },
end: { offset: 26, line: 2, column: 14 } end: { offset: 26, line: 2, column: 14 }
} }
}); });
}); });

@ -7,20 +7,20 @@ describe("compiler pass |reportInfiniteRepetition|", function() {
it("reports infinite loops for zero_or_more", function() { it("reports infinite loops for zero_or_more", function() {
expect(pass).toReportError("start = ('')*", { expect(pass).toReportError("start = ('')*", {
message: "Possible infinite loop when parsing (repetition used with an expression that may not consume any input).", message: "Possible infinite loop when parsing (repetition used with an expression that may not consume any input).",
location: { location: {
start: { offset: 8, line: 1, column: 9 }, start: { offset: 8, line: 1, column: 9 },
end: { offset: 13, line: 1, column: 14 } end: { offset: 13, line: 1, column: 14 }
} }
}); });
}); });
it("reports infinite loops for one_or_more", function() { it("reports infinite loops for one_or_more", function() {
expect(pass).toReportError("start = ('')+", { expect(pass).toReportError("start = ('')+", {
message: "Possible infinite loop when parsing (repetition used with an expression that may not consume any input).", message: "Possible infinite loop when parsing (repetition used with an expression that may not consume any input).",
location: { location: {
start: { offset: 8, line: 1, column: 9 }, start: { offset: 8, line: 1, column: 9 },
end: { offset: 13, line: 1, column: 14 } end: { offset: 13, line: 1, column: 14 }
} }
}); });
}); });

@ -7,10 +7,10 @@ describe("compiler pass |reportUndefinedRules|", function() {
it("reports undefined rules", function() { it("reports undefined rules", function() {
expect(pass).toReportError("start = undefined", { expect(pass).toReportError("start = undefined", {
message: "Rule \"undefined\" is not defined.", message: "Rule \"undefined\" is not defined.",
location: { location: {
start: { offset: 8, line: 1, column: 9 }, start: { offset: 8, line: 1, column: 9 },
end: { offset: 17, line: 1, column: 18 } end: { offset: 17, line: 1, column: 18 }
} }
}); });
}); });

@ -22,15 +22,15 @@ describe("PEG.js grammar parser", function() {
let labeledMnop = { type: "labeled", label: "d", expression: literalMnop }; let labeledMnop = { type: "labeled", label: "d", expression: literalMnop };
let labeledSimpleNot = { type: "labeled", label: "a", expression: simpleNotAbcd }; let labeledSimpleNot = { type: "labeled", label: "a", expression: simpleNotAbcd };
let sequence = { let sequence = {
type: "sequence", type: "sequence",
elements: [literalAbcd, literalEfgh, literalIjkl] elements: [literalAbcd, literalEfgh, literalIjkl]
}; };
let sequence2 = { let sequence2 = {
type: "sequence", type: "sequence",
elements: [labeledAbcd, labeledEfgh] elements: [labeledAbcd, labeledEfgh]
}; };
let sequence4 = { let sequence4 = {
type: "sequence", type: "sequence",
elements: [labeledAbcd, labeledEfgh, labeledIjkl, labeledMnop] elements: [labeledAbcd, labeledEfgh, labeledIjkl, labeledMnop]
}; };
let groupLabeled = { type: "group", expression: labeledAbcd }; let groupLabeled = { type: "group", expression: labeledAbcd };
@ -41,15 +41,15 @@ describe("PEG.js grammar parser", function() {
let actionMnop = { type: "action", expression: literalMnop, code: " code " }; let actionMnop = { type: "action", expression: literalMnop, code: " code " };
let actionSequence = { type: "action", expression: sequence, code: " code " }; let actionSequence = { type: "action", expression: sequence, code: " code " };
let choice = { let choice = {
type: "choice", type: "choice",
alternatives: [literalAbcd, literalEfgh, literalIjkl] alternatives: [literalAbcd, literalEfgh, literalIjkl]
}; };
let choice2 = { let choice2 = {
type: "choice", type: "choice",
alternatives: [actionAbcd, actionEfgh] alternatives: [actionAbcd, actionEfgh]
}; };
let choice4 = { let choice4 = {
type: "choice", type: "choice",
alternatives: [actionAbcd, actionEfgh, actionIjkl, actionMnop] alternatives: [actionAbcd, actionEfgh, actionIjkl, actionMnop]
}; };
let named = { type: "named", name: "start rule", expression: literalAbcd }; let named = { type: "named", name: "start rule", expression: literalAbcd };
@ -61,9 +61,9 @@ describe("PEG.js grammar parser", function() {
function oneRuleGrammar(expression) { function oneRuleGrammar(expression) {
return { return {
type: "grammar", type: "grammar",
initializer: null, initializer: null,
rules: [{ type: "rule", name: "start", expression: expression }] rules: [{ type: "rule", name: "start", expression: expression }]
}; };
} }
@ -81,9 +81,9 @@ describe("PEG.js grammar parser", function() {
function classGrammar(parts, inverted, ignoreCase) { function classGrammar(parts, inverted, ignoreCase) {
return oneRuleGrammar({ return oneRuleGrammar({
type: "class", type: "class",
parts: parts, parts: parts,
inverted: inverted, inverted: inverted,
ignoreCase: ignoreCase ignoreCase: ignoreCase
}); });
} }
@ -98,9 +98,9 @@ describe("PEG.js grammar parser", function() {
let trivialGrammar = literalGrammar("abcd", false); let trivialGrammar = literalGrammar("abcd", false);
let twoRuleGrammar = { let twoRuleGrammar = {
type: "grammar", type: "grammar",
initializer: null, initializer: null,
rules: [ruleA, ruleB] rules: [ruleA, ruleB]
}; };
let stripLocation = (function() { let stripLocation = (function() {
@ -138,26 +138,26 @@ describe("PEG.js grammar parser", function() {
node.rules.forEach(strip); node.rules.forEach(strip);
}, },
initializer: stripLeaf, initializer: stripLeaf,
rule: stripExpression, rule: stripExpression,
named: stripExpression, named: stripExpression,
choice: stripChildren("alternatives"), choice: stripChildren("alternatives"),
action: stripExpression, action: stripExpression,
sequence: stripChildren("elements"), sequence: stripChildren("elements"),
labeled: stripExpression, labeled: stripExpression,
text: stripExpression, text: stripExpression,
simple_and: stripExpression, simple_and: stripExpression,
simple_not: stripExpression, simple_not: stripExpression,
optional: stripExpression, optional: stripExpression,
zero_or_more: stripExpression, zero_or_more: stripExpression,
one_or_more: stripExpression, one_or_more: stripExpression,
group: stripExpression, group: stripExpression,
semantic_and: stripLeaf, semantic_and: stripLeaf,
semantic_not: stripLeaf, semantic_not: stripLeaf,
rule_ref: stripLeaf, rule_ref: stripLeaf,
literal: stripLeaf, literal: stripLeaf,
"class": stripLeaf, "class": stripLeaf,
any: stripLeaf any: stripLeaf
}); });
return strip; return strip;
@ -165,7 +165,7 @@ describe("PEG.js grammar parser", function() {
beforeEach(function() { beforeEach(function() {
this.addMatchers({ this.addMatchers({
toParseAs: function(expected) { toParseAs: function(expected) {
let result; let result;
try { try {

@ -57,10 +57,10 @@
Grammar Grammar
= __ initializer:(Initializer __)? rules:(Rule __)+ { = __ initializer:(Initializer __)? rules:(Rule __)+ {
return { return {
type: "grammar", type: "grammar",
initializer: extractOptional(initializer, 0), initializer: extractOptional(initializer, 0),
rules: extractList(rules, 0), rules: extractList(rules, 0),
location: location() location: location()
}; };
} }
@ -76,17 +76,17 @@ Rule
expression:Expression EOS expression:Expression EOS
{ {
return { return {
type: "rule", type: "rule",
name: name, name: name,
expression: displayName !== null expression: displayName !== null
? { ? {
type: "named", type: "named",
name: displayName[0], name: displayName[0],
expression: expression, expression: expression,
location: location() location: location()
} }
: expression, : expression,
location: location() location: location()
}; };
} }
@ -97,9 +97,9 @@ ChoiceExpression
= head:ActionExpression tail:(__ "/" __ ActionExpression)* { = head:ActionExpression tail:(__ "/" __ ActionExpression)* {
return tail.length > 0 return tail.length > 0
? { ? {
type: "choice", type: "choice",
alternatives: buildList(head, tail, 3), alternatives: buildList(head, tail, 3),
location: location() location: location()
} }
: head; : head;
} }
@ -108,10 +108,10 @@ ActionExpression
= expression:SequenceExpression code:(__ CodeBlock)? { = expression:SequenceExpression code:(__ CodeBlock)? {
return code !== null return code !== null
? { ? {
type: "action", type: "action",
expression: expression, expression: expression,
code: code[1], code: code[1],
location: location() location: location()
} }
: expression; : expression;
} }
@ -120,7 +120,7 @@ SequenceExpression
= head:LabeledExpression tail:(__ LabeledExpression)* { = head:LabeledExpression tail:(__ LabeledExpression)* {
return tail.length > 0 return tail.length > 0
? { ? {
type: "sequence", type: "sequence",
elements: buildList(head, tail, 1), elements: buildList(head, tail, 1),
location: location() location: location()
} }
@ -130,10 +130,10 @@ SequenceExpression
LabeledExpression LabeledExpression
= label:Identifier __ ":" __ expression:PrefixedExpression { = label:Identifier __ ":" __ expression:PrefixedExpression {
return { return {
type: "labeled", type: "labeled",
label: label, label: label,
expression: expression, expression: expression,
location: location() location: location()
}; };
} }
/ PrefixedExpression / PrefixedExpression
@ -141,9 +141,9 @@ LabeledExpression
PrefixedExpression PrefixedExpression
= operator:PrefixedOperator __ expression:SuffixedExpression { = operator:PrefixedOperator __ expression:SuffixedExpression {
return { return {
type: OPS_TO_PREFIXED_TYPES[operator], type: OPS_TO_PREFIXED_TYPES[operator],
expression: expression, expression: expression,
location: location() location: location()
}; };
} }
/ SuffixedExpression / SuffixedExpression
@ -156,9 +156,9 @@ PrefixedOperator
SuffixedExpression SuffixedExpression
= expression:PrimaryExpression __ operator:SuffixedOperator { = expression:PrimaryExpression __ operator:SuffixedOperator {
return { return {
type: OPS_TO_SUFFIXED_TYPES[operator], type: OPS_TO_SUFFIXED_TYPES[operator],
expression: expression, expression: expression,
location: location() location: location()
}; };
} }
/ PrimaryExpression / PrimaryExpression
@ -192,8 +192,8 @@ RuleReferenceExpression
SemanticPredicateExpression SemanticPredicateExpression
= operator:SemanticPredicateOperator __ code:CodeBlock { = operator:SemanticPredicateOperator __ code:CodeBlock {
return { return {
type: OPS_TO_SEMANTIC_PREDICATE_TYPES[operator], type: OPS_TO_SEMANTIC_PREDICATE_TYPES[operator],
code: code, code: code,
location: location() location: location()
}; };
} }
@ -330,10 +330,10 @@ BooleanLiteral
LiteralMatcher "literal" LiteralMatcher "literal"
= value:StringLiteral ignoreCase:"i"? { = value:StringLiteral ignoreCase:"i"? {
return { return {
type: "literal", type: "literal",
value: value, value: value,
ignoreCase: ignoreCase !== null, ignoreCase: ignoreCase !== null,
location: location() location: location()
}; };
} }
@ -359,11 +359,11 @@ CharacterClassMatcher "character class"
ignoreCase:"i"? ignoreCase:"i"?
{ {
return { return {
type: "class", type: "class",
parts: parts.filter(part => part !== ""), parts: parts.filter(part => part !== ""),
inverted: inverted !== null, inverted: inverted !== null,
ignoreCase: ignoreCase !== null, ignoreCase: ignoreCase !== null,
location: location() location: location()
}; };
} }

Loading…
Cancel
Save