From 7d4911ec531552887603c37e4eea6bdc32331bd5 Mon Sep 17 00:00:00 2001 From: David Majda Date: Mon, 7 Jun 2010 10:45:26 +0200 Subject: [PATCH] Emit little bit less whitespace in actions --- lib/compiler.js | 2 +- lib/metagrammar.js | 130 ++++++++++++++++++++++----------------------- 2 files changed, 66 insertions(+), 66 deletions(-) diff --git a/lib/compiler.js b/lib/compiler.js index af54255..6b34bb7 100644 --- a/lib/compiler.js +++ b/lib/compiler.js @@ -746,7 +746,7 @@ PEG.Compiler = { return PEG.Compiler.formatCode( "${expressionCode}", "var ${resultVar} = ${expressionResultVar} !== null", - " ? (function(${formalParams}) { ${action} })(${actualParams})", + " ? (function(${formalParams}) {${action}})(${actualParams})", " : null;", { expressionCode: PEG.Compiler.compileNode(node.expression, expressionResultVar), diff --git a/lib/metagrammar.js b/lib/metagrammar.js index 324f6e6..ab0fa7f 100644 --- a/lib/metagrammar.js +++ b/lib/metagrammar.js @@ -85,11 +85,11 @@ PEG.grammarParser = (function(){ this._pos = savedPos0; } var result0 = result1 !== null - ? (function(rules) { + ? (function(rules) { var result = {}; PEG.ArrayUtils.each(rules, function(rule) { result[rule.name] = rule; }); return result; - })(result1[1]) + })(result1[1]) : null; @@ -157,14 +157,14 @@ PEG.grammarParser = (function(){ this._pos = savedPos1; } var result5 = result6 !== null - ? (function(name, displayName, expression) { + ? (function(name, displayName, expression) { return { type: "rule", name: name, displayName: displayName !== "" ? displayName : null, expression: expression }; - })(result6[0], result6[1], result6[3]) + })(result6[0], result6[1], result6[3]) : null; @@ -233,7 +233,7 @@ PEG.grammarParser = (function(){ this._pos = savedPos2; } var result13 = result14 !== null - ? (function(head, tail) { + ? (function(head, tail) { if (tail.length > 0) { var alternatives = [head].concat(PEG.ArrayUtils.map( tail, @@ -246,7 +246,7 @@ PEG.grammarParser = (function(){ } else { return head; } - })(result14[0], result14[1]) + })(result14[0], result14[1]) : null; @@ -289,7 +289,7 @@ PEG.grammarParser = (function(){ this._pos = savedPos4; } var result24 = result25 !== null - ? (function(elements, action) { + ? (function(elements, action) { var expression = elements.length != 1 ? { type: "sequence", @@ -301,7 +301,7 @@ PEG.grammarParser = (function(){ expression: expression, action: action }; - })(result25[0], result25[1]) + })(result25[0], result25[1]) : null; if (result24 !== null) { var result20 = result24; @@ -313,14 +313,14 @@ PEG.grammarParser = (function(){ var result23 = this._parse_labeled(context); } var result21 = result22 !== null - ? (function(elements) { + ? (function(elements) { return elements.length != 1 ? { type: "sequence", elements: elements } : elements[0]; - })(result22) + })(result22) : null; if (result21 !== null) { var result20 = result21; @@ -370,13 +370,13 @@ PEG.grammarParser = (function(){ this._pos = savedPos5; } var result31 = result32 !== null - ? (function(label, expression) { + ? (function(label, expression) { return { type: "labeled", label: label, expression: expression }; - })(result32[0], result32[2]) + })(result32[0], result32[2]) : null; if (result31 !== null) { var result29 = result31; @@ -424,12 +424,12 @@ PEG.grammarParser = (function(){ this._pos = savedPos7; } var result42 = result43 !== null - ? (function(expression) { + ? (function(expression) { return { type: "and_predicate", expression: expression }; - })(result43[1]) + })(result43[1]) : null; if (result42 !== null) { var result36 = result42; @@ -449,12 +449,12 @@ PEG.grammarParser = (function(){ this._pos = savedPos6; } var result38 = result39 !== null - ? (function(expression) { + ? (function(expression) { return { type: "not_predicate", expression: expression }; - })(result39[1]) + })(result39[1]) : null; if (result38 !== null) { var result36 = result38; @@ -503,12 +503,12 @@ PEG.grammarParser = (function(){ this._pos = savedPos10; } var result56 = result57 !== null - ? (function(expression) { + ? (function(expression) { return { type: "optional", expression: expression }; - })(result57[0]) + })(result57[0]) : null; if (result56 !== null) { var result46 = result56; @@ -528,12 +528,12 @@ PEG.grammarParser = (function(){ this._pos = savedPos9; } var result52 = result53 !== null - ? (function(expression) { + ? (function(expression) { return { type: "zero_or_more", expression: expression }; - })(result53[0]) + })(result53[0]) : null; if (result52 !== null) { var result46 = result52; @@ -553,12 +553,12 @@ PEG.grammarParser = (function(){ this._pos = savedPos8; } var result48 = result49 !== null - ? (function(expression) { + ? (function(expression) { return { type: "one_or_more", expression: expression }; - })(result49[0]) + })(result49[0]) : null; if (result48 !== null) { var result46 = result48; @@ -649,31 +649,31 @@ PEG.grammarParser = (function(){ this._pos = savedPos12; } var result71 = result72 !== null - ? (function(name) { + ? (function(name) { return { type: "rule_ref", name: name }; - })(result72[0]) + })(result72[0]) : null; if (result71 !== null) { var result60 = result71; } else { var result70 = this._parse_literal(context); var result69 = result70 !== null - ? (function(value) { + ? (function(value) { return { type: "literal", value: value }; - })(result70) + })(result70) : null; if (result69 !== null) { var result60 = result69; } else { var result68 = this._parse_dot(context); var result67 = result68 !== null - ? (function() { return { type: "any" }; })() + ? (function() { return { type: "any" }; })() : null; if (result67 !== null) { var result60 = result67; @@ -703,7 +703,7 @@ PEG.grammarParser = (function(){ this._pos = savedPos11; } var result61 = result62 !== null - ? (function(expression) { return expression; })(result62[1]) + ? (function(expression) { return expression; })(result62[1]) : null; if (result61 !== null) { var result60 = result61; @@ -751,7 +751,7 @@ PEG.grammarParser = (function(){ this._pos = savedPos15; } var result80 = result81 !== null - ? (function(braced) { return braced.substr(1, braced.length - 2); })(result81[0]) + ? (function(braced) { return braced.substr(1, braced.length - 2); })(result81[0]) : null; context.reportMatchFailures = savedReportMatchFailures; if (context.reportMatchFailures && result80 === null) { @@ -838,9 +838,9 @@ PEG.grammarParser = (function(){ this._pos = savedPos16; } var result84 = result85 !== null - ? (function(parts) { + ? (function(parts) { return "{" + parts.join("") + "}"; - })(result85[1]) + })(result85[1]) : null; @@ -874,7 +874,7 @@ PEG.grammarParser = (function(){ var result93 = null; } var result92 = result93 !== null - ? (function(chars) { return chars.join(""); })(result93) + ? (function(chars) { return chars.join(""); })(result93) : null; @@ -950,7 +950,7 @@ PEG.grammarParser = (function(){ this._pos = savedPos17; } var result96 = result97 !== null - ? (function() { return "="; })() + ? (function() { return "="; })() : null; @@ -996,7 +996,7 @@ PEG.grammarParser = (function(){ this._pos = savedPos18; } var result100 = result101 !== null - ? (function() { return ":"; })() + ? (function() { return ":"; })() : null; @@ -1042,7 +1042,7 @@ PEG.grammarParser = (function(){ this._pos = savedPos19; } var result104 = result105 !== null - ? (function() { return "/"; })() + ? (function() { return "/"; })() : null; @@ -1088,7 +1088,7 @@ PEG.grammarParser = (function(){ this._pos = savedPos20; } var result108 = result109 !== null - ? (function() { return "&"; })() + ? (function() { return "&"; })() : null; @@ -1134,7 +1134,7 @@ PEG.grammarParser = (function(){ this._pos = savedPos21; } var result112 = result113 !== null - ? (function() { return "!"; })() + ? (function() { return "!"; })() : null; @@ -1180,7 +1180,7 @@ PEG.grammarParser = (function(){ this._pos = savedPos22; } var result116 = result117 !== null - ? (function() { return "?"; })() + ? (function() { return "?"; })() : null; @@ -1226,7 +1226,7 @@ PEG.grammarParser = (function(){ this._pos = savedPos23; } var result120 = result121 !== null - ? (function() { return "*"; })() + ? (function() { return "*"; })() : null; @@ -1272,7 +1272,7 @@ PEG.grammarParser = (function(){ this._pos = savedPos24; } var result124 = result125 !== null - ? (function() { return "+"; })() + ? (function() { return "+"; })() : null; @@ -1318,7 +1318,7 @@ PEG.grammarParser = (function(){ this._pos = savedPos25; } var result128 = result129 !== null - ? (function() { return "("; })() + ? (function() { return "("; })() : null; @@ -1364,7 +1364,7 @@ PEG.grammarParser = (function(){ this._pos = savedPos26; } var result132 = result133 !== null - ? (function() { return ")"; })() + ? (function() { return ")"; })() : null; @@ -1410,7 +1410,7 @@ PEG.grammarParser = (function(){ this._pos = savedPos27; } var result136 = result137 !== null - ? (function() { return "."; })() + ? (function() { return "."; })() : null; @@ -1563,9 +1563,9 @@ PEG.grammarParser = (function(){ this._pos = savedPos28; } var result140 = result141 !== null - ? (function(head, tail) { + ? (function(head, tail) { return head + tail.join(""); - })(result141[0], result141[1]) + })(result141[0], result141[1]) : null; context.reportMatchFailures = savedReportMatchFailures; if (context.reportMatchFailures && result140 === null) { @@ -1616,7 +1616,7 @@ PEG.grammarParser = (function(){ this._pos = savedPos29; } var result153 = result154 !== null - ? (function(literal) { return literal; })(result154[0]) + ? (function(literal) { return literal; })(result154[0]) : null; context.reportMatchFailures = savedReportMatchFailures; if (context.reportMatchFailures && result153 === null) { @@ -1683,7 +1683,7 @@ PEG.grammarParser = (function(){ this._pos = savedPos30; } var result159 = result160 !== null - ? (function(chars) { return chars.join(""); })(result160[1]) + ? (function(chars) { return chars.join(""); })(result160[1]) : null; @@ -1822,7 +1822,7 @@ PEG.grammarParser = (function(){ this._pos = savedPos31; } var result172 = result173 !== null - ? (function(char_) { return char_; })(result173[1]) + ? (function(char_) { return char_; })(result173[1]) : null; @@ -1887,7 +1887,7 @@ PEG.grammarParser = (function(){ this._pos = savedPos33; } var result180 = result181 !== null - ? (function(chars) { return chars.join(""); })(result181[1]) + ? (function(chars) { return chars.join(""); })(result181[1]) : null; @@ -2026,7 +2026,7 @@ PEG.grammarParser = (function(){ this._pos = savedPos34; } var result193 = result194 !== null - ? (function(char_) { return char_; })(result194[1]) + ? (function(char_) { return char_; })(result194[1]) : null; @@ -2133,7 +2133,7 @@ PEG.grammarParser = (function(){ this._pos = savedPos36; } var result201 = result202 !== null - ? (function(inverted, parts) { + ? (function(inverted, parts) { partsConverted = PEG.ArrayUtils.map(parts, function(part) { return part.data; }); @@ -2151,7 +2151,7 @@ PEG.grammarParser = (function(){ // FIXME: Get the raw text from the input directly. rawText: rawText }; - })(result202[1], result202[2]) + })(result202[1], result202[2]) : null; context.reportMatchFailures = savedReportMatchFailures; if (context.reportMatchFailures && result201 === null) { @@ -2205,7 +2205,7 @@ PEG.grammarParser = (function(){ this._pos = savedPos37; } var result212 = result213 !== null - ? (function(begin, end) { + ? (function(begin, end) { if (begin.data.charCodeAt(0) > end.data.charCodeAt(0)) { throw new this.SyntaxError( "Invalid character range: " + begin.rawText + "-" + end.rawText + "." @@ -2217,7 +2217,7 @@ PEG.grammarParser = (function(){ // FIXME: Get the raw text from the input directly. rawText: begin.rawText + "-" + end.rawText } - })(result213[0], result213[2]) + })(result213[0], result213[2]) : null; @@ -2242,13 +2242,13 @@ PEG.grammarParser = (function(){ var result218 = this._parse_bracketDelimitedCharacter(context); var result217 = result218 !== null - ? (function(char_) { + ? (function(char_) { return { data: char_, // FIXME: Get the raw text from the input directly. rawText: PEG.RegExpUtils.quoteForClass(char_) }; - })(result218) + })(result218) : null; @@ -2387,7 +2387,7 @@ PEG.grammarParser = (function(){ this._pos = savedPos38; } var result226 = result227 !== null - ? (function(char_) { return char_; })(result227[1]) + ? (function(char_) { return char_; })(result227[1]) : null; @@ -2493,7 +2493,7 @@ PEG.grammarParser = (function(){ this._pos = savedPos40; } var result234 = result235 !== null - ? (function(char_) { + ? (function(char_) { return char_ .replace("b", "\b") .replace("f", "\f") @@ -2501,7 +2501,7 @@ PEG.grammarParser = (function(){ .replace("r", "\r") .replace("t", "\t") .replace("v", "\x0B") // IE does not recognize "\v". - })(result235[2]) + })(result235[2]) : null; @@ -2557,7 +2557,7 @@ PEG.grammarParser = (function(){ this._pos = savedPos42; } var result244 = result245 !== null - ? (function() { return "\0"; })() + ? (function() { return "\0"; })() : null; @@ -2609,9 +2609,9 @@ PEG.grammarParser = (function(){ this._pos = savedPos44; } var result249 = result250 !== null - ? (function(h1, h2) { + ? (function(h1, h2) { return String.fromCharCode(parseInt("0x" + h1 + h2)); - })(result250[1], result250[2]) + })(result250[1], result250[2]) : null; @@ -2675,9 +2675,9 @@ PEG.grammarParser = (function(){ this._pos = savedPos45; } var result254 = result255 !== null - ? (function(h1, h2, h3, h4) { + ? (function(h1, h2, h3, h4) { return String.fromCharCode(parseInt("0x" + h1 + h2 + h3 + h4)); - })(result255[1], result255[2], result255[3], result255[4]) + })(result255[1], result255[2], result255[3], result255[4]) : null; @@ -2723,7 +2723,7 @@ PEG.grammarParser = (function(){ this._pos = savedPos46; } var result261 = result262 !== null - ? (function(eol) { return eol; })(result262[1]) + ? (function(eol) { return eol; })(result262[1]) : null;