Text nodes: Use text nodes in PEG.js grammar

redux
David Majda 12 years ago
parent 5e146fce38
commit f0a6bc92cc

@ -913,38 +913,24 @@ module.exports = (function(){
pos = r2; pos = r2;
} }
if (r0 !== null) { if (r0 !== null) {
reportedPos = r1; r0 = input.substring(pos, r1);
r0 = (function(parts) {
return "{" + parts.join("") + "}";
})(r4);
}
if (r0 === null) {
pos = r1;
} }
return r0; return r0;
} }
function parse_nonBraceCharacters() { function parse_nonBraceCharacters() {
var r0, r1, r2; var r0, r1;
r1 = pos; r1 = parse_nonBraceCharacter();
r2 = parse_nonBraceCharacter(); if (r1 !== null) {
if (r2 !== null) {
r0 = []; r0 = [];
while (r2 !== null) { while (r1 !== null) {
r0.push(r2); r0.push(r1);
r2 = parse_nonBraceCharacter(); r1 = parse_nonBraceCharacter();
} }
} else { } else {
r0 = null; r0 = null;
} }
if (r0 !== null) {
reportedPos = r1;
r0 = (function(chars) { return chars.join(""); })(r0);
}
if (r0 === null) {
pos = r1;
}
return r0; return r0;
} }
@ -1432,51 +1418,53 @@ module.exports = (function(){
} }
function parse_identifier() { function parse_identifier() {
var r0, r1, r2, r3, r4, r5; var r0, r1, r2, r3, r4, r5, r6, r7, r8;
reportFailures++; reportFailures++;
r1 = pos; r1 = pos;
r2 = pos; r2 = pos;
r3 = parse_letter(); r4 = pos;
if (r3 === null) { r5 = pos;
r6 = parse_letter();
if (r6 === null) {
if (input.charCodeAt(pos) === 95) { if (input.charCodeAt(pos) === 95) {
r3 = "_"; r6 = "_";
pos++; pos++;
} else { } else {
r3 = null; r6 = null;
if (reportFailures === 0) { if (reportFailures === 0) {
matchFailed("\"_\""); matchFailed("\"_\"");
} }
} }
} }
if (r3 !== null) { if (r6 !== null) {
r4 = []; r7 = [];
r5 = parse_letter(); r8 = parse_letter();
if (r5 === null) { if (r8 === null) {
r5 = parse_digit(); r8 = parse_digit();
if (r5 === null) { if (r8 === null) {
if (input.charCodeAt(pos) === 95) { if (input.charCodeAt(pos) === 95) {
r5 = "_"; r8 = "_";
pos++; pos++;
} else { } else {
r5 = null; r8 = null;
if (reportFailures === 0) { if (reportFailures === 0) {
matchFailed("\"_\""); matchFailed("\"_\"");
} }
} }
} }
} }
while (r5 !== null) { while (r8 !== null) {
r4.push(r5); r7.push(r8);
r5 = parse_letter(); r8 = parse_letter();
if (r5 === null) { if (r8 === null) {
r5 = parse_digit(); r8 = parse_digit();
if (r5 === null) { if (r8 === null) {
if (input.charCodeAt(pos) === 95) { if (input.charCodeAt(pos) === 95) {
r5 = "_"; r8 = "_";
pos++; pos++;
} else { } else {
r5 = null; r8 = null;
if (reportFailures === 0) { if (reportFailures === 0) {
matchFailed("\"_\""); matchFailed("\"_\"");
} }
@ -1484,14 +1472,23 @@ module.exports = (function(){
} }
} }
} }
if (r4 !== null) { if (r7 !== null) {
r5 = parse___(); r3 = [r6, r7];
if (r5 !== null) {
r0 = [r3, r4, r5];
} else { } else {
r0 = null; r3 = null;
pos = r2; pos = r5;
}
} else {
r3 = null;
pos = r5;
}
if (r3 !== null) {
r3 = input.substring(pos, r4);
} }
if (r3 !== null) {
r4 = parse___();
if (r4 !== null) {
r0 = [r3, r4];
} else { } else {
r0 = null; r0 = null;
pos = r2; pos = r2;
@ -1502,9 +1499,7 @@ module.exports = (function(){
} }
if (r0 !== null) { if (r0 !== null) {
reportedPos = r1; reportedPos = r1;
r0 = (function(head, tail) { r0 = (function(chars) { return chars; })(r3);
return head + tail.join("");
})(r3, r4);
} }
if (r0 === null) { if (r0 === null) {
pos = r1; pos = r1;
@ -2317,7 +2312,7 @@ module.exports = (function(){
} }
function parse_hexEscapeSequence() { function parse_hexEscapeSequence() {
var r0, r1, r2, r3, r4, r5; var r0, r1, r2, r3, r4, r5, r6, r7, r8;
r1 = pos; r1 = pos;
r2 = pos; r2 = pos;
@ -2331,15 +2326,26 @@ module.exports = (function(){
} }
} }
if (r3 !== null) { if (r3 !== null) {
r4 = parse_hexDigit(); r5 = pos;
if (r4 !== null) { r6 = pos;
r5 = parse_hexDigit(); r7 = parse_hexDigit();
if (r5 !== null) { if (r7 !== null) {
r0 = [r3, r4, r5]; r8 = parse_hexDigit();
if (r8 !== null) {
r4 = [r7, r8];
} else { } else {
r0 = null; r4 = null;
pos = r2; pos = r6;
}
} else {
r4 = null;
pos = r6;
} }
if (r4 !== null) {
r4 = input.substring(pos, r5);
}
if (r4 !== null) {
r0 = [r3, r4];
} else { } else {
r0 = null; r0 = null;
pos = r2; pos = r2;
@ -2350,9 +2356,9 @@ module.exports = (function(){
} }
if (r0 !== null) { if (r0 !== null) {
reportedPos = r1; reportedPos = r1;
r0 = (function(h1, h2) { r0 = (function(digits) {
return String.fromCharCode(parseInt(h1 + h2, 16)); return String.fromCharCode(parseInt(digits, 16));
})(r4, r5); })(r4);
} }
if (r0 === null) { if (r0 === null) {
pos = r1; pos = r1;
@ -2361,7 +2367,7 @@ module.exports = (function(){
} }
function parse_unicodeEscapeSequence() { function parse_unicodeEscapeSequence() {
var r0, r1, r2, r3, r4, r5, r6, r7; var r0, r1, r2, r3, r4, r5, r6, r7, r8, r9, r10;
r1 = pos; r1 = pos;
r2 = pos; r2 = pos;
@ -2375,27 +2381,38 @@ module.exports = (function(){
} }
} }
if (r3 !== null) { if (r3 !== null) {
r4 = parse_hexDigit(); r5 = pos;
if (r4 !== null) { r6 = pos;
r5 = parse_hexDigit();
if (r5 !== null) {
r6 = parse_hexDigit();
if (r6 !== null) {
r7 = parse_hexDigit(); r7 = parse_hexDigit();
if (r7 !== null) { if (r7 !== null) {
r0 = [r3, r4, r5, r6, r7]; r8 = parse_hexDigit();
if (r8 !== null) {
r9 = parse_hexDigit();
if (r9 !== null) {
r10 = parse_hexDigit();
if (r10 !== null) {
r4 = [r7, r8, r9, r10];
} else { } else {
r0 = null; r4 = null;
pos = r2; pos = r6;
} }
} else { } else {
r0 = null; r4 = null;
pos = r2; pos = r6;
} }
} else { } else {
r0 = null; r4 = null;
pos = r2; pos = r6;
}
} else {
r4 = null;
pos = r6;
}
if (r4 !== null) {
r4 = input.substring(pos, r5);
} }
if (r4 !== null) {
r0 = [r3, r4];
} else { } else {
r0 = null; r0 = null;
pos = r2; pos = r2;
@ -2406,9 +2423,9 @@ module.exports = (function(){
} }
if (r0 !== null) { if (r0 !== null) {
reportedPos = r1; reportedPos = r1;
r0 = (function(h1, h2, h3, h4) { r0 = (function(digits) {
return String.fromCharCode(parseInt(h1 + h2 + h3 + h4, 16)); return String.fromCharCode(parseInt(digits, 16));
})(r4, r5, r6, r7); })(r4);
} }
if (r0 === null) { if (r0 === null) {
pos = r1; pos = r1;

@ -159,12 +159,10 @@ action "action"
= braced:braced __ { return braced.substr(1, braced.length - 2); } = braced:braced __ { return braced.substr(1, braced.length - 2); }
braced braced
= "{" parts:(braced / nonBraceCharacters)* "}" { = $("{" (braced / nonBraceCharacters)* "}")
return "{" + parts.join("") + "}";
}
nonBraceCharacters nonBraceCharacters
= chars:nonBraceCharacter+ { return chars.join(""); } = nonBraceCharacter+
nonBraceCharacter nonBraceCharacter
= [^{}] = [^{}]
@ -202,9 +200,7 @@ dot = "." __ { return "."; }
* purpose in the grammar. * purpose in the grammar.
*/ */
identifier "identifier" identifier "identifier"
= head:(letter / "_") tail:(letter / digit / "_")* __ { = chars:$((letter / "_") (letter / digit / "_")*) __ { return chars; }
return head + tail.join("");
}
/* /*
* Modeled after ECMA-262, 5th ed., 7.8.4. (syntax & semantics, rules only * Modeled after ECMA-262, 5th ed., 7.8.4. (syntax & semantics, rules only
@ -319,13 +315,13 @@ zeroEscapeSequence
= "\\0" !digit { return "\x00"; } = "\\0" !digit { return "\x00"; }
hexEscapeSequence hexEscapeSequence
= "\\x" h1:hexDigit h2:hexDigit { = "\\x" digits:$(hexDigit hexDigit) {
return String.fromCharCode(parseInt(h1 + h2, 16)); return String.fromCharCode(parseInt(digits, 16));
} }
unicodeEscapeSequence unicodeEscapeSequence
= "\\u" h1:hexDigit h2:hexDigit h3:hexDigit h4:hexDigit { = "\\u" digits:$(hexDigit hexDigit hexDigit hexDigit) {
return String.fromCharCode(parseInt(h1 + h2 + h3 + h4, 16)); return String.fromCharCode(parseInt(digits, 16));
} }
eolEscapeSequence eolEscapeSequence

Loading…
Cancel
Save