From 0459ab6b37453d00b85f7a5c30fce66b65280c08 Mon Sep 17 00:00:00 2001 From: David Majda Date: Fri, 4 Apr 2014 11:15:58 +0200 Subject: [PATCH] PEG.js grammar: Formatting & comments --- lib/parser.js | 13 ++----------- src/parser.pegjs | 20 +++++++------------- 2 files changed, 9 insertions(+), 24 deletions(-) diff --git a/lib/parser.js b/lib/parser.js index bae0836..92cdb34 100644 --- a/lib/parser.js +++ b/lib/parser.js @@ -42,12 +42,7 @@ module.exports = (function() { rules: extractList(rules, 0) }; }, - peg$c4 = function(code) { - return { - type: "initializer", - code: code - }; - }, + peg$c4 = function(code) { return { type: "initializer", code: code }; }, peg$c5 = "=", peg$c6 = { type: "literal", value: "=", description: "\"=\"" }, peg$c7 = function(name, displayName, expression) { @@ -83,11 +78,7 @@ module.exports = (function() { peg$c13 = ":", peg$c14 = { type: "literal", value: ":", description: "\":\"" }, peg$c15 = function(label, expression) { - return { - type: "labeled", - label: label, - expression: expression - }; + return { type: "labeled", label: label, expression: expression }; }, peg$c16 = function(operator, expression) { return { type: OPS_TO_PREFIXED_TYPES[operator], expression: expression }; diff --git a/src/parser.pegjs b/src/parser.pegjs index b57e363..9777b3b 100644 --- a/src/parser.pegjs +++ b/src/parser.pegjs @@ -48,6 +48,8 @@ } } +/* ---- Syntactic Grammar ----- */ + Grammar = __ initializer:(Initializer __)? rules:(Rule __)+ { return { @@ -58,18 +60,14 @@ Grammar } Initializer - = code:CodeBlock EOS { - return { - type: "initializer", - code: code - }; - } + = code:CodeBlock EOS { return { type: "initializer", code: code }; } Rule = name:IdentifierName __ displayName:(StringLiteral __)? "=" __ - expression:Expression EOS { + expression:Expression EOS + { return { type: "rule", name: name, @@ -109,11 +107,7 @@ SequenceExpression LabeledExpression = label:Identifier __ ":" __ expression:PrefixedExpression { - return { - type: "labeled", - label: label, - expression: expression - }; + return { type: "labeled", label: label, expression: expression }; } / PrefixedExpression @@ -161,7 +155,7 @@ SemanticPredicateOperator = "&" / "!" -/* "Lexical" elements */ +/* ---- Lexical Grammar ----- */ SourceCharacter = .