Last active
August 29, 2015 14:07
Pre-compiled parser for pigshell
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
parser = (function(){ | |
/* | |
* Generated by PEG.js 0.7.0. | |
* | |
* http://pegjs.majda.cz/ | |
*/ | |
function subclass(child, parent) { | |
function ctor() { this.constructor = child; } | |
ctor.prototype = parent.prototype; | |
child.prototype = new ctor(); | |
} | |
function quote(s) { | |
/* | |
* ECMA-262, 5th ed., 7.8.4: All characters may appear literally in a | |
* string literal except for the closing quote character, backslash, | |
* carriage return, line separator, paragraph separator, and line feed. | |
* Any character may appear in the form of an escape sequence. | |
* | |
* For portability, we also escape escape all control and non-ASCII | |
* characters. Note that "\0" and "\v" escape sequences are not used | |
* because JSHint does not like the first and IE the second. | |
*/ | |
return '"' + s | |
.replace(/\\/g, '\\\\') // backslash | |
.replace(/"/g, '\\"') // closing quote character | |
.replace(/\x08/g, '\\b') // backspace | |
.replace(/\t/g, '\\t') // horizontal tab | |
.replace(/\n/g, '\\n') // line feed | |
.replace(/\f/g, '\\f') // form feed | |
.replace(/\r/g, '\\r') // carriage return | |
.replace(/[\x00-\x07\x0B\x0E-\x1F\x80-\uFFFF]/g, escape) | |
+ '"'; | |
} | |
var result = { | |
/* | |
* Parses the input with a generated parser. If the parsing is successful, | |
* returns a value explicitly or implicitly specified by the grammar from | |
* which the parser was generated (see |PEG.buildParser|). If the parsing is | |
* unsuccessful, throws |PEG.parser.SyntaxError| describing the error. | |
*/ | |
parse: function(input) { | |
var parseFunctions = { | |
"start": parse_start, | |
"TokenList": parse_TokenList | |
}; | |
var options = arguments.length > 1 ? arguments[1] : {}, | |
startRule; | |
var depth = 0, | |
tabspace = options.tabspace || 2; | |
if (options.startRule !== undefined) { | |
startRule = options.startRule; | |
if (parseFunctions[startRule] === undefined) { | |
throw new Error("Can't start parsing from rule " + quote(startRule) + "."); | |
} | |
} else { | |
startRule = "start"; | |
} | |
var pos = 0; | |
var reportFailures = 0; | |
var rightmostFailuresPos = 0; | |
var rightmostFailuresExpected = []; | |
function padLeft(input, padding, length) { | |
var result = input; | |
var padLength = length - input.length; | |
for (var i = 0; i < padLength; i++) { | |
result = padding + result; | |
} | |
return result; | |
} | |
function escape(ch) { | |
var charCode = ch.charCodeAt(0); | |
var escapeChar; | |
var length; | |
if (charCode <= 0xFF) { | |
escapeChar = 'x'; | |
length = 2; | |
} else { | |
escapeChar = 'u'; | |
length = 4; | |
} | |
return '\\' + escapeChar + padLeft(charCode.toString(16).toUpperCase(), '0', length); | |
} | |
function matchFailed(failure) { | |
if (pos < rightmostFailuresPos) { | |
return; | |
} | |
if (pos > rightmostFailuresPos) { | |
rightmostFailuresPos = pos; | |
rightmostFailuresExpected = []; | |
} | |
rightmostFailuresExpected.push(failure); | |
} | |
function parse_start() { | |
depth++; | |
var r0, r1, r2, r3, r4, r5, r6; | |
r1 = pos; | |
r2 = pos; | |
r3 = parse____(); | |
if (r3 !== null) { | |
r4 = parse_Program(); | |
if (r4 !== null) { | |
r5 = parse____(); | |
if (r5 !== null) { | |
r6 = parse_EOF(); | |
if (r6 !== null) { | |
r0 = [r3, r4, r5, r6]; | |
} else { | |
r0 = null; | |
pos = r2; | |
} | |
} else { | |
r0 = null; | |
pos = r2; | |
} | |
} else { | |
r0 = null; | |
pos = r2; | |
} | |
} else { | |
r0 = null; | |
pos = r2; | |
} | |
if (r0 !== null) { | |
r0 = (function(offset, program) { return program; })(r1, r4); | |
} | |
if (r0 === null) { | |
pos = r1; | |
} | |
depth--; | |
return r0; | |
} | |
function parse_Program() { | |
depth++; | |
var r0, r1, r2, r3, r4, r5; | |
reportFailures++; | |
r1 = pos; | |
r2 = pos; | |
r3 = parse_BlockList(); | |
r3 = r3 !== null ? r3 : ""; | |
if (r3 !== null) { | |
r4 = []; | |
r5 = parse_EOS(); | |
while (r5 !== null) { | |
r4.push(r5); | |
r5 = parse_EOS(); | |
} | |
if (r4 !== null) { | |
r0 = [r3, r4]; | |
} else { | |
r0 = null; | |
pos = r2; | |
} | |
} else { | |
r0 = null; | |
pos = r2; | |
} | |
if (r0 !== null) { | |
r0 = (function(offset, elements) { | |
return elements; | |
})(r1, r3); | |
} | |
if (r0 === null) { | |
pos = r1; | |
} | |
reportFailures--; | |
if (reportFailures === 0 && r0 === null) { | |
matchFailed("Program"); | |
} | |
depth--; | |
return r0; | |
} | |
function parse_BlockList() { | |
depth++; | |
var r0, r1, r2, r3, r4, r5, r6, r7, r8, r9; | |
reportFailures++; | |
r1 = pos; | |
r2 = pos; | |
r3 = parse_Function(); | |
if (r3 === null) { | |
r3 = parse_StatementBlock(); | |
} | |
if (r3 !== null) { | |
r4 = []; | |
r6 = pos; | |
r7 = parse_EOS(); | |
if (r7 !== null) { | |
r8 = parse__(); | |
if (r8 !== null) { | |
r9 = parse_Function(); | |
if (r9 === null) { | |
r9 = parse_StatementBlock(); | |
} | |
if (r9 !== null) { | |
r5 = [r7, r8, r9]; | |
} else { | |
r5 = null; | |
pos = r6; | |
} | |
} else { | |
r5 = null; | |
pos = r6; | |
} | |
} else { | |
r5 = null; | |
pos = r6; | |
} | |
while (r5 !== null) { | |
r4.push(r5); | |
r6 = pos; | |
r7 = parse_EOS(); | |
if (r7 !== null) { | |
r8 = parse__(); | |
if (r8 !== null) { | |
r9 = parse_Function(); | |
if (r9 === null) { | |
r9 = parse_StatementBlock(); | |
} | |
if (r9 !== null) { | |
r5 = [r7, r8, r9]; | |
} else { | |
r5 = null; | |
pos = r6; | |
} | |
} else { | |
r5 = null; | |
pos = r6; | |
} | |
} else { | |
r5 = null; | |
pos = r6; | |
} | |
} | |
if (r4 !== null) { | |
r0 = [r3, r4]; | |
} else { | |
r0 = null; | |
pos = r2; | |
} | |
} else { | |
r0 = null; | |
pos = r2; | |
} | |
if (r0 !== null) { | |
r0 = (function(offset, head, tail) { | |
var result = head; | |
for (var i = 0; i < tail.length; i++) { | |
result = result.concat(tail[i][2]); | |
} | |
return result; | |
})(r1, r3, r4); | |
} | |
if (r0 === null) { | |
pos = r1; | |
} | |
reportFailures--; | |
if (reportFailures === 0 && r0 === null) { | |
matchFailed("BlockList"); | |
} | |
depth--; | |
return r0; | |
} | |
function parse_Function() { | |
depth++; | |
var r0, r1, r2, r3, r4, r5, r6, r7, r8, r9, r10, r11, r12; | |
reportFailures++; | |
r1 = pos; | |
r2 = pos; | |
if (input.substr(pos, 8) === "function") { | |
r3 = "function"; | |
pos += 8; | |
} else { | |
r3 = null; | |
if (reportFailures === 0) { | |
matchFailed("\"function\""); | |
} | |
} | |
if (r3 !== null) { | |
r4 = parse___(); | |
if (r4 !== null) { | |
r5 = parse_Identifier(); | |
if (r5 !== null) { | |
r6 = parse____(); | |
if (r6 !== null) { | |
if (input.charCodeAt(pos) === 123) { | |
r7 = "{"; | |
pos++; | |
} else { | |
r7 = null; | |
if (reportFailures === 0) { | |
matchFailed("\"{\""); | |
} | |
} | |
if (r7 !== null) { | |
r8 = parse____(); | |
if (r8 !== null) { | |
r9 = parse_StatementBlock(); | |
r9 = r9 !== null ? r9 : ""; | |
if (r9 !== null) { | |
r10 = parse_EOS(); | |
if (r10 !== null) { | |
r11 = parse__(); | |
if (r11 !== null) { | |
if (input.charCodeAt(pos) === 125) { | |
r12 = "}"; | |
pos++; | |
} else { | |
r12 = null; | |
if (reportFailures === 0) { | |
matchFailed("\"}\""); | |
} | |
} | |
if (r12 !== null) { | |
r0 = [r3, r4, r5, r6, r7, r8, r9, r10, r11, r12]; | |
} else { | |
r0 = null; | |
pos = r2; | |
} | |
} else { | |
r0 = null; | |
pos = r2; | |
} | |
} else { | |
r0 = null; | |
pos = r2; | |
} | |
} else { | |
r0 = null; | |
pos = r2; | |
} | |
} else { | |
r0 = null; | |
pos = r2; | |
} | |
} else { | |
r0 = null; | |
pos = r2; | |
} | |
} else { | |
r0 = null; | |
pos = r2; | |
} | |
} else { | |
r0 = null; | |
pos = r2; | |
} | |
} else { | |
r0 = null; | |
pos = r2; | |
} | |
} else { | |
r0 = null; | |
pos = r2; | |
} | |
if (r0 !== null) { | |
r0 = (function(offset, fname, body) { | |
return [{'FUNCTION': [fname, body]}]; | |
})(r1, r5, r9); | |
} | |
if (r0 === null) { | |
pos = r1; | |
} | |
if (r0 === null) { | |
r1 = pos; | |
r2 = pos; | |
if (input.substr(pos, 8) === "function") { | |
r3 = "function"; | |
pos += 8; | |
} else { | |
r3 = null; | |
if (reportFailures === 0) { | |
matchFailed("\"function\""); | |
} | |
} | |
if (r3 !== null) { | |
r4 = parse___(); | |
if (r4 !== null) { | |
r5 = parse_Identifier(); | |
if (r5 !== null) { | |
r6 = parse____(); | |
if (r6 !== null) { | |
if (input.charCodeAt(pos) === 123) { | |
r7 = "{"; | |
pos++; | |
} else { | |
r7 = null; | |
if (reportFailures === 0) { | |
matchFailed("\"{\""); | |
} | |
} | |
if (r7 !== null) { | |
r8 = parse____(); | |
if (r8 !== null) { | |
if (input.charCodeAt(pos) === 125) { | |
r9 = "}"; | |
pos++; | |
} else { | |
r9 = null; | |
if (reportFailures === 0) { | |
matchFailed("\"}\""); | |
} | |
} | |
if (r9 !== null) { | |
r0 = [r3, r4, r5, r6, r7, r8, r9]; | |
} else { | |
r0 = null; | |
pos = r2; | |
} | |
} else { | |
r0 = null; | |
pos = r2; | |
} | |
} else { | |
r0 = null; | |
pos = r2; | |
} | |
} else { | |
r0 = null; | |
pos = r2; | |
} | |
} else { | |
r0 = null; | |
pos = r2; | |
} | |
} else { | |
r0 = null; | |
pos = r2; | |
} | |
} else { | |
r0 = null; | |
pos = r2; | |
} | |
if (r0 !== null) { | |
r0 = (function(offset, fname) { | |
return [{'FUNCTION': [fname, []]}]; | |
})(r1, r5); | |
} | |
if (r0 === null) { | |
pos = r1; | |
} | |
if (r0 === null) { | |
r1 = pos; | |
r2 = pos; | |
if (input.substr(pos, 8) === "function") { | |
r3 = "function"; | |
pos += 8; | |
} else { | |
r3 = null; | |
if (reportFailures === 0) { | |
matchFailed("\"function\""); | |
} | |
} | |
if (r3 !== null) { | |
r4 = parse___(); | |
if (r4 !== null) { | |
r5 = parse_Identifier(); | |
if (r5 !== null) { | |
r7 = pos; | |
reportFailures++; | |
r6 = parse_EOS(); | |
if (r6 === null) { | |
r6 = parse_EOF(); | |
} | |
reportFailures--; | |
if (r6 !== null) { | |
r6 = ""; | |
pos = r7; | |
} else { | |
r6 = null; | |
} | |
if (r6 !== null) { | |
r0 = [r3, r4, r5, r6]; | |
} else { | |
r0 = null; | |
pos = r2; | |
} | |
} else { | |
r0 = null; | |
pos = r2; | |
} | |
} else { | |
r0 = null; | |
pos = r2; | |
} | |
} else { | |
r0 = null; | |
pos = r2; | |
} | |
if (r0 !== null) { | |
r0 = (function(offset, fname) { | |
return [{'FUNCTION': [fname, null]}]; | |
})(r1, r5); | |
} | |
if (r0 === null) { | |
pos = r1; | |
} | |
} | |
} | |
reportFailures--; | |
if (reportFailures === 0 && r0 === null) { | |
matchFailed("Function"); | |
} | |
depth--; | |
return r0; | |
} | |
function parse_StatementBlock() { | |
depth++; | |
var r0, r1, r2, r3, r4, r5, r6, r7, r8, r9; | |
reportFailures++; | |
r1 = pos; | |
r2 = pos; | |
r3 = parse_Statement(); | |
if (r3 !== null) { | |
r4 = []; | |
r6 = pos; | |
r7 = parse_EOS(); | |
if (r7 !== null) { | |
r8 = parse__(); | |
if (r8 !== null) { | |
r9 = parse_Statement(); | |
if (r9 !== null) { | |
r5 = [r7, r8, r9]; | |
} else { | |
r5 = null; | |
pos = r6; | |
} | |
} else { | |
r5 = null; | |
pos = r6; | |
} | |
} else { | |
r5 = null; | |
pos = r6; | |
} | |
while (r5 !== null) { | |
r4.push(r5); | |
r6 = pos; | |
r7 = parse_EOS(); | |
if (r7 !== null) { | |
r8 = parse__(); | |
if (r8 !== null) { | |
r9 = parse_Statement(); | |
if (r9 !== null) { | |
r5 = [r7, r8, r9]; | |
} else { | |
r5 = null; | |
pos = r6; | |
} | |
} else { | |
r5 = null; | |
pos = r6; | |
} | |
} else { | |
r5 = null; | |
pos = r6; | |
} | |
} | |
if (r4 !== null) { | |
r0 = [r3, r4]; | |
} else { | |
r0 = null; | |
pos = r2; | |
} | |
} else { | |
r0 = null; | |
pos = r2; | |
} | |
if (r0 !== null) { | |
r0 = (function(offset, head, tail) { | |
var result = [head]; | |
for (var i = 0; i < tail.length; i++) { | |
result.push(tail[i][2]); | |
} | |
return result; | |
})(r1, r3, r4); | |
} | |
if (r0 === null) { | |
pos = r1; | |
} | |
reportFailures--; | |
if (reportFailures === 0 && r0 === null) { | |
matchFailed("StatementBlock"); | |
} | |
depth--; | |
return r0; | |
} | |
function parse_Statement() { | |
depth++; | |
var r0, r1; | |
reportFailures++; | |
r1 = pos; | |
r0 = parse_WhileStatement(); | |
if (r0 === null) { | |
r0 = parse_ForStatement(); | |
if (r0 === null) { | |
r0 = parse_IfStatement(); | |
if (r0 === null) { | |
r0 = parse_AssignStatement(); | |
if (r0 === null) { | |
r0 = parse_ReturnStatement(); | |
if (r0 === null) { | |
r0 = parse_OrStatement(); | |
if (r0 === null) { | |
r0 = parse_EmptyStatement(); | |
} | |
} | |
} | |
} | |
} | |
} | |
if (r0 !== null) { | |
r0 = (function(offset, statement) { return statement; })(r1, r0); | |
} | |
if (r0 === null) { | |
pos = r1; | |
} | |
reportFailures--; | |
if (reportFailures === 0 && r0 === null) { | |
matchFailed("Statement"); | |
} | |
depth--; | |
return r0; | |
} | |
function parse_WhileStatement() { | |
depth++; | |
var r0, r1, r2, r3, r4, r5, r6, r7, r8, r9, r10, r11, r12, r13; | |
reportFailures++; | |
r1 = pos; | |
r2 = pos; | |
if (input.substr(pos, 5) === "while") { | |
r3 = "while"; | |
pos += 5; | |
} else { | |
r3 = null; | |
if (reportFailures === 0) { | |
matchFailed("\"while\""); | |
} | |
} | |
if (r3 !== null) { | |
r4 = parse___(); | |
if (r4 !== null) { | |
r5 = parse_OrStatement(); | |
if (r5 !== null) { | |
r7 = parse_EOS(); | |
if (r7 !== null) { | |
r6 = []; | |
while (r7 !== null) { | |
r6.push(r7); | |
r7 = parse_EOS(); | |
} | |
} else { | |
r6 = null; | |
} | |
if (r6 !== null) { | |
r7 = parse__(); | |
if (r7 !== null) { | |
if (input.substr(pos, 2) === "do") { | |
r8 = "do"; | |
pos += 2; | |
} else { | |
r8 = null; | |
if (reportFailures === 0) { | |
matchFailed("\"do\""); | |
} | |
} | |
if (r8 !== null) { | |
r10 = pos; | |
r11 = parse_EOS(); | |
if (r11 !== null) { | |
r12 = parse__(); | |
if (r12 !== null) { | |
r9 = [r11, r12]; | |
} else { | |
r9 = null; | |
pos = r10; | |
} | |
} else { | |
r9 = null; | |
pos = r10; | |
} | |
if (r9 === null) { | |
r9 = parse___(); | |
} | |
if (r9 !== null) { | |
r10 = parse_StatementBlock(); | |
if (r10 !== null) { | |
r11 = parse_EOS(); | |
if (r11 !== null) { | |
r12 = parse__(); | |
if (r12 !== null) { | |
if (input.substr(pos, 4) === "done") { | |
r13 = "done"; | |
pos += 4; | |
} else { | |
r13 = null; | |
if (reportFailures === 0) { | |
matchFailed("\"done\""); | |
} | |
} | |
if (r13 !== null) { | |
r0 = [r3, r4, r5, r6, r7, r8, r9, r10, r11, r12, r13]; | |
} else { | |
r0 = null; | |
pos = r2; | |
} | |
} else { | |
r0 = null; | |
pos = r2; | |
} | |
} else { | |
r0 = null; | |
pos = r2; | |
} | |
} else { | |
r0 = null; | |
pos = r2; | |
} | |
} else { | |
r0 = null; | |
pos = r2; | |
} | |
} else { | |
r0 = null; | |
pos = r2; | |
} | |
} else { | |
r0 = null; | |
pos = r2; | |
} | |
} else { | |
r0 = null; | |
pos = r2; | |
} | |
} else { | |
r0 = null; | |
pos = r2; | |
} | |
} else { | |
r0 = null; | |
pos = r2; | |
} | |
} else { | |
r0 = null; | |
pos = r2; | |
} | |
if (r0 !== null) { | |
r0 = (function(offset, cond, body) { | |
return {'WHILE': [cond, body]}; | |
})(r1, r5, r10); | |
} | |
if (r0 === null) { | |
pos = r1; | |
} | |
reportFailures--; | |
if (reportFailures === 0 && r0 === null) { | |
matchFailed("WhileStatement"); | |
} | |
depth--; | |
return r0; | |
} | |
function parse_ForStatement() { | |
depth++; | |
var r0, r1, r2, r3, r4, r5, r6, r7, r8, r9, r10, r11, r12, r13, r14, r15, r16, r17, r18; | |
reportFailures++; | |
r1 = pos; | |
r2 = pos; | |
if (input.substr(pos, 3) === "for") { | |
r3 = "for"; | |
pos += 3; | |
} else { | |
r3 = null; | |
if (reportFailures === 0) { | |
matchFailed("\"for\""); | |
} | |
} | |
if (r3 !== null) { | |
r4 = parse___(); | |
if (r4 !== null) { | |
r5 = parse_Identifier(); | |
if (r5 !== null) { | |
r6 = parse___(); | |
if (r6 !== null) { | |
if (input.substr(pos, 2) === "in") { | |
r7 = "in"; | |
pos += 2; | |
} else { | |
r7 = null; | |
if (reportFailures === 0) { | |
matchFailed("\"in\""); | |
} | |
} | |
if (r7 !== null) { | |
r8 = parse___(); | |
if (r8 !== null) { | |
r9 = parse_Argword(); | |
if (r9 !== null) { | |
r10 = []; | |
r12 = pos; | |
r13 = parse___(); | |
if (r13 !== null) { | |
r14 = parse_Argword(); | |
if (r14 !== null) { | |
r11 = [r13, r14]; | |
} else { | |
r11 = null; | |
pos = r12; | |
} | |
} else { | |
r11 = null; | |
pos = r12; | |
} | |
while (r11 !== null) { | |
r10.push(r11); | |
r12 = pos; | |
r13 = parse___(); | |
if (r13 !== null) { | |
r14 = parse_Argword(); | |
if (r14 !== null) { | |
r11 = [r13, r14]; | |
} else { | |
r11 = null; | |
pos = r12; | |
} | |
} else { | |
r11 = null; | |
pos = r12; | |
} | |
} | |
if (r10 !== null) { | |
r12 = parse_EOS(); | |
if (r12 !== null) { | |
r11 = []; | |
while (r12 !== null) { | |
r11.push(r12); | |
r12 = parse_EOS(); | |
} | |
} else { | |
r11 = null; | |
} | |
if (r11 !== null) { | |
r12 = parse__(); | |
if (r12 !== null) { | |
if (input.substr(pos, 2) === "do") { | |
r13 = "do"; | |
pos += 2; | |
} else { | |
r13 = null; | |
if (reportFailures === 0) { | |
matchFailed("\"do\""); | |
} | |
} | |
if (r13 !== null) { | |
r15 = pos; | |
r16 = parse_EOS(); | |
if (r16 !== null) { | |
r17 = parse__(); | |
if (r17 !== null) { | |
r14 = [r16, r17]; | |
} else { | |
r14 = null; | |
pos = r15; | |
} | |
} else { | |
r14 = null; | |
pos = r15; | |
} | |
if (r14 === null) { | |
r14 = parse___(); | |
} | |
if (r14 !== null) { | |
r15 = parse_StatementBlock(); | |
if (r15 !== null) { | |
r16 = parse_EOS(); | |
if (r16 !== null) { | |
r17 = parse__(); | |
if (r17 !== null) { | |
if (input.substr(pos, 4) === "done") { | |
r18 = "done"; | |
pos += 4; | |
} else { | |
r18 = null; | |
if (reportFailures === 0) { | |
matchFailed("\"done\""); | |
} | |
} | |
if (r18 !== null) { | |
r0 = [r3, r4, r5, r6, r7, r8, r9, r10, r11, r12, r13, r14, r15, r16, r17, r18]; | |
} else { | |
r0 = null; | |
pos = r2; | |
} | |
} else { | |
r0 = null; | |
pos = r2; | |
} | |
} else { | |
r0 = null; | |
pos = r2; | |
} | |
} else { | |
r0 = null; | |
pos = r2; | |
} | |
} else { | |
r0 = null; | |
pos = r2; | |
} | |
} else { | |
r0 = null; | |
pos = r2; | |
} | |
} else { | |
r0 = null; | |
pos = r2; | |
} | |
} else { | |
r0 = null; | |
pos = r2; | |
} | |
} else { | |
r0 = null; | |
pos = r2; | |
} | |
} else { | |
r0 = null; | |
pos = r2; | |
} | |
} else { | |
r0 = null; | |
pos = r2; | |
} | |
} else { | |
r0 = null; | |
pos = r2; | |
} | |
} else { | |
r0 = null; | |
pos = r2; | |
} | |
} else { | |
r0 = null; | |
pos = r2; | |
} | |
} else { | |
r0 = null; | |
pos = r2; | |
} | |
} else { | |
r0 = null; | |
pos = r2; | |
} | |
if (r0 !== null) { | |
r0 = (function(offset, id, head, tail, body) { | |
var args = [head]; | |
for (var i = 0; i < tail.length; i++) { | |
args.push(tail[i][1]); | |
} | |
return {'FOR': [id, {'ARGLIST': args}, body]}; | |
})(r1, r5, r9, r10, r15); | |
} | |
if (r0 === null) { | |
pos = r1; | |
} | |
reportFailures--; | |
if (reportFailures === 0 && r0 === null) { | |
matchFailed("ForStatement"); | |
} | |
depth--; | |
return r0; | |
} | |
function parse_IfStatement() { | |
depth++; | |
var r0, r1, r2, r3, r4, r5, r6, r7, r8, r9, r10, r11, r12, r13, r14, r15, r16, r17; | |
reportFailures++; | |
r1 = pos; | |
r2 = pos; | |
if (input.substr(pos, 2) === "if") { | |
r3 = "if"; | |
pos += 2; | |
} else { | |
r3 = null; | |
if (reportFailures === 0) { | |
matchFailed("\"if\""); | |
} | |
} | |
if (r3 !== null) { | |
r4 = parse___(); | |
if (r4 !== null) { | |
r6 = pos; | |
if (input.charCodeAt(pos) === 33) { | |
r7 = "!"; | |
pos++; | |
} else { | |
r7 = null; | |
if (reportFailures === 0) { | |
matchFailed("\"!\""); | |
} | |
} | |
if (r7 !== null) { | |
r8 = parse___(); | |
if (r8 !== null) { | |
r5 = [r7, r8]; | |
} else { | |
r5 = null; | |
pos = r6; | |
} | |
} else { | |
r5 = null; | |
pos = r6; | |
} | |
r5 = r5 !== null ? r5 : ""; | |
if (r5 !== null) { | |
r6 = parse_OrStatement(); | |
if (r6 !== null) { | |
r8 = parse_EOS(); | |
if (r8 !== null) { | |
r7 = []; | |
while (r8 !== null) { | |
r7.push(r8); | |
r8 = parse_EOS(); | |
} | |
} else { | |
r7 = null; | |
} | |
if (r7 !== null) { | |
r8 = parse__(); | |
if (r8 !== null) { | |
if (input.substr(pos, 4) === "then") { | |
r9 = "then"; | |
pos += 4; | |
} else { | |
r9 = null; | |
if (reportFailures === 0) { | |
matchFailed("\"then\""); | |
} | |
} | |
if (r9 !== null) { | |
r11 = pos; | |
r12 = parse_EOS(); | |
if (r12 !== null) { | |
r13 = parse__(); | |
if (r13 !== null) { | |
r10 = [r12, r13]; | |
} else { | |
r10 = null; | |
pos = r11; | |
} | |
} else { | |
r10 = null; | |
pos = r11; | |
} | |
if (r10 === null) { | |
r10 = parse___(); | |
} | |
if (r10 !== null) { | |
r11 = parse_StatementBlock(); | |
if (r11 !== null) { | |
r12 = []; | |
r14 = pos; | |
r15 = parse_EOS(); | |
if (r15 !== null) { | |
r16 = parse__(); | |
if (r16 !== null) { | |
r17 = parse_ElifBlock(); | |
if (r17 !== null) { | |
r13 = [r15, r16, r17]; | |
} else { | |
r13 = null; | |
pos = r14; | |
} | |
} else { | |
r13 = null; | |
pos = r14; | |
} | |
} else { | |
r13 = null; | |
pos = r14; | |
} | |
while (r13 !== null) { | |
r12.push(r13); | |
r14 = pos; | |
r15 = parse_EOS(); | |
if (r15 !== null) { | |
r16 = parse__(); | |
if (r16 !== null) { | |
r17 = parse_ElifBlock(); | |
if (r17 !== null) { | |
r13 = [r15, r16, r17]; | |
} else { | |
r13 = null; | |
pos = r14; | |
} | |
} else { | |
r13 = null; | |
pos = r14; | |
} | |
} else { | |
r13 = null; | |
pos = r14; | |
} | |
} | |
if (r12 !== null) { | |
r13 = parse_EOS(); | |
if (r13 !== null) { | |
r14 = parse__(); | |
if (r14 !== null) { | |
r15 = parse_IfTail(); | |
if (r15 !== null) { | |
r0 = [r3, r4, r5, r6, r7, r8, r9, r10, r11, r12, r13, r14, r15]; | |
} else { | |
r0 = null; | |
pos = r2; | |
} | |
} else { | |
r0 = null; | |
pos = r2; | |
} | |
} else { | |
r0 = null; | |
pos = r2; | |
} | |
} else { | |
r0 = null; | |
pos = r2; | |
} | |
} else { | |
r0 = null; | |
pos = r2; | |
} | |
} else { | |
r0 = null; | |
pos = r2; | |
} | |
} else { | |
r0 = null; | |
pos = r2; | |
} | |
} else { | |
r0 = null; | |
pos = r2; | |
} | |
} else { | |
r0 = null; | |
pos = r2; | |
} | |
} else { | |
r0 = null; | |
pos = r2; | |
} | |
} else { | |
r0 = null; | |
pos = r2; | |
} | |
} else { | |
r0 = null; | |
pos = r2; | |
} | |
} else { | |
r0 = null; | |
pos = r2; | |
} | |
if (r0 !== null) { | |
r0 = (function(offset, ifnot, cond, body, elif, tail) { | |
var result = {}, | |
ifblock = {}, | |
op = (ifnot.length === 0) ? 'IF' : 'IFNOT', | |
ifblocks = []; | |
ifblocks.push([op, cond, body]); | |
for (var i = 0; i < elif.length; i++) { | |
ifblocks.push(elif[i][2]); | |
} | |
result['IF'] = [ifblocks, tail]; | |
return result; | |
})(r1, r5, r6, r11, r12, r15); | |
} | |
if (r0 === null) { | |
pos = r1; | |
} | |
reportFailures--; | |
if (reportFailures === 0 && r0 === null) { | |
matchFailed("IfStatement"); | |
} | |
depth--; | |
return r0; | |
} | |
function parse_ElifBlock() { | |
depth++; | |
var r0, r1, r2, r3, r4, r5, r6, r7, r8, r9, r10, r11, r12, r13; | |
reportFailures++; | |
r1 = pos; | |
r2 = pos; | |
if (input.substr(pos, 4) === "elif") { | |
r3 = "elif"; | |
pos += 4; | |
} else { | |
r3 = null; | |
if (reportFailures === 0) { | |
matchFailed("\"elif\""); | |
} | |
} | |
if (r3 !== null) { | |
r4 = parse___(); | |
if (r4 !== null) { | |
r6 = pos; | |
if (input.charCodeAt(pos) === 33) { | |
r7 = "!"; | |
pos++; | |
} else { | |
r7 = null; | |
if (reportFailures === 0) { | |
matchFailed("\"!\""); | |
} | |
} | |
if (r7 !== null) { | |
r8 = parse___(); | |
if (r8 !== null) { | |
r5 = [r7, r8]; | |
} else { | |
r5 = null; | |
pos = r6; | |
} | |
} else { | |
r5 = null; | |
pos = r6; | |
} | |
r5 = r5 !== null ? r5 : ""; | |
if (r5 !== null) { | |
r6 = parse_OrStatement(); | |
if (r6 !== null) { | |
r8 = parse_EOS(); | |
if (r8 !== null) { | |
r7 = []; | |
while (r8 !== null) { | |
r7.push(r8); | |
r8 = parse_EOS(); | |
} | |
} else { | |
r7 = null; | |
} | |
if (r7 !== null) { | |
r8 = parse__(); | |
if (r8 !== null) { | |
if (input.substr(pos, 4) === "then") { | |
r9 = "then"; | |
pos += 4; | |
} else { | |
r9 = null; | |
if (reportFailures === 0) { | |
matchFailed("\"then\""); | |
} | |
} | |
if (r9 !== null) { | |
r11 = pos; | |
r12 = parse_EOS(); | |
if (r12 !== null) { | |
r13 = parse__(); | |
if (r13 !== null) { | |
r10 = [r12, r13]; | |
} else { | |
r10 = null; | |
pos = r11; | |
} | |
} else { | |
r10 = null; | |
pos = r11; | |
} | |
if (r10 === null) { | |
r10 = parse___(); | |
} | |
if (r10 !== null) { | |
r11 = parse_StatementBlock(); | |
if (r11 !== null) { | |
r0 = [r3, r4, r5, r6, r7, r8, r9, r10, r11]; | |
} else { | |
r0 = null; | |
pos = r2; | |
} | |
} else { | |
r0 = null; | |
pos = r2; | |
} | |
} else { | |
r0 = null; | |
pos = r2; | |
} | |
} else { | |
r0 = null; | |
pos = r2; | |
} | |
} else { | |
r0 = null; | |
pos = r2; | |
} | |
} else { | |
r0 = null; | |
pos = r2; | |
} | |
} else { | |
r0 = null; | |
pos = r2; | |
} | |
} else { | |
r0 = null; | |
pos = r2; | |
} | |
} else { | |
r0 = null; | |
pos = r2; | |
} | |
if (r0 !== null) { | |
r0 = (function(offset, ifnot, cond, body) { | |
var result; | |
op = (ifnot.length === 0) ? 'IF' : 'IFNOT'; | |
result = [op, cond, body]; | |
return result; | |
})(r1, r5, r6, r11); | |
} | |
if (r0 === null) { | |
pos = r1; | |
} | |
reportFailures--; | |
if (reportFailures === 0 && r0 === null) { | |
matchFailed("ElifBlock"); | |
} | |
depth--; | |
return r0; | |
} | |
function parse_IfTail() { | |
depth++; | |
var r0, r1, r2, r3, r4, r5, r6, r7, r8; | |
reportFailures++; | |
r1 = pos; | |
r2 = pos; | |
if (input.substr(pos, 4) === "else") { | |
r3 = "else"; | |
pos += 4; | |
} else { | |
r3 = null; | |
if (reportFailures === 0) { | |
matchFailed("\"else\""); | |
} | |
} | |
if (r3 !== null) { | |
r5 = pos; | |
r6 = parse_EOS(); | |
if (r6 !== null) { | |
r7 = parse__(); | |
if (r7 !== null) { | |
r4 = [r6, r7]; | |
} else { | |
r4 = null; | |
pos = r5; | |
} | |
} else { | |
r4 = null; | |
pos = r5; | |
} | |
if (r4 === null) { | |
r4 = parse___(); | |
} | |
if (r4 !== null) { | |
r5 = parse_StatementBlock(); | |
if (r5 !== null) { | |
r6 = parse_EOS(); | |
if (r6 !== null) { | |
r7 = parse__(); | |
if (r7 !== null) { | |
if (input.substr(pos, 2) === "fi") { | |
r8 = "fi"; | |
pos += 2; | |
} else { | |
r8 = null; | |
if (reportFailures === 0) { | |
matchFailed("\"fi\""); | |
} | |
} | |
if (r8 !== null) { | |
r0 = [r3, r4, r5, r6, r7, r8]; | |
} else { | |
r0 = null; | |
pos = r2; | |
} | |
} else { | |
r0 = null; | |
pos = r2; | |
} | |
} else { | |
r0 = null; | |
pos = r2; | |
} | |
} else { | |
r0 = null; | |
pos = r2; | |
} | |
} else { | |
r0 = null; | |
pos = r2; | |
} | |
} else { | |
r0 = null; | |
pos = r2; | |
} | |
if (r0 !== null) { | |
r0 = (function(offset, elseblock) { return elseblock; })(r1, r5); | |
} | |
if (r0 === null) { | |
pos = r1; | |
} | |
if (r0 === null) { | |
r1 = pos; | |
if (input.substr(pos, 2) === "fi") { | |
r0 = "fi"; | |
pos += 2; | |
} else { | |
r0 = null; | |
if (reportFailures === 0) { | |
matchFailed("\"fi\""); | |
} | |
} | |
if (r0 !== null) { | |
r0 = (function(offset) { return [];})(r1); | |
} | |
if (r0 === null) { | |
pos = r1; | |
} | |
} | |
reportFailures--; | |
if (reportFailures === 0 && r0 === null) { | |
matchFailed("IfTail"); | |
} | |
depth--; | |
return r0; | |
} | |
function parse_AssignStatement() { | |
depth++; | |
var r0, r1, r2, r3, r4, r5; | |
r1 = pos; | |
r2 = pos; | |
r3 = parse_Identifier(); | |
if (r3 !== null) { | |
if (input.charCodeAt(pos) === 61) { | |
r4 = "="; | |
pos++; | |
} else { | |
r4 = null; | |
if (reportFailures === 0) { | |
matchFailed("\"=\""); | |
} | |
} | |
if (r4 !== null) { | |
r5 = parse_Argword(); | |
if (r5 !== null) { | |
r0 = [r3, r4, r5]; | |
} else { | |
r0 = null; | |
pos = r2; | |
} | |
} else { | |
r0 = null; | |
pos = r2; | |
} | |
} else { | |
r0 = null; | |
pos = r2; | |
} | |
if (r0 !== null) { | |
r0 = (function(offset, id, arg) { | |
var result = {'ASSIGN': {}}; | |
result['ASSIGN'][id] = arg; | |
return result; | |
})(r1, r3, r5); | |
} | |
if (r0 === null) { | |
pos = r1; | |
} | |
depth--; | |
return r0; | |
} | |
function parse_ReturnStatement() { | |
depth++; | |
var r0, r1, r2, r3, r4, r5, r6, r7; | |
r1 = pos; | |
r2 = pos; | |
if (input.substr(pos, 6) === "return") { | |
r3 = "return"; | |
pos += 6; | |
} else { | |
r3 = null; | |
if (reportFailures === 0) { | |
matchFailed("\"return\""); | |
} | |
} | |
if (r3 !== null) { | |
r5 = pos; | |
r6 = parse___(); | |
if (r6 !== null) { | |
r7 = parse_Argword(); | |
if (r7 !== null) { | |
r4 = [r6, r7]; | |
} else { | |
r4 = null; | |
pos = r5; | |
} | |
} else { | |
r4 = null; | |
pos = r5; | |
} | |
r4 = r4 !== null ? r4 : ""; | |
if (r4 !== null) { | |
r0 = [r3, r4]; | |
} else { | |
r0 = null; | |
pos = r2; | |
} | |
} else { | |
r0 = null; | |
pos = r2; | |
} | |
if (r0 !== null) { | |
r0 = (function(offset, arg) { | |
var retval = (arg.length === 0) ? '' : arg[1], | |
result = {'RETURN': retval}; | |
return result; | |
})(r1, r4); | |
} | |
if (r0 === null) { | |
pos = r1; | |
} | |
depth--; | |
return r0; | |
} | |
function parse_OrStatement() { | |
depth++; | |
var r0, r1, r2, r3, r4, r5, r6, r7, r8, r9, r10; | |
reportFailures++; | |
r1 = pos; | |
r2 = pos; | |
r3 = parse_AndStatement(); | |
if (r3 !== null) { | |
r4 = []; | |
r6 = pos; | |
r7 = parse__(); | |
if (r7 !== null) { | |
if (input.substr(pos, 2) === "||") { | |
r8 = "||"; | |
pos += 2; | |
} else { | |
r8 = null; | |
if (reportFailures === 0) { | |
matchFailed("\"||\""); | |
} | |
} | |
if (r8 !== null) { | |
r9 = parse__(); | |
if (r9 !== null) { | |
r10 = parse_AndStatement(); | |
if (r10 !== null) { | |
r5 = [r7, r8, r9, r10]; | |
} else { | |
r5 = null; | |
pos = r6; | |
} | |
} else { | |
r5 = null; | |
pos = r6; | |
} | |
} else { | |
r5 = null; | |
pos = r6; | |
} | |
} else { | |
r5 = null; | |
pos = r6; | |
} | |
while (r5 !== null) { | |
r4.push(r5); | |
r6 = pos; | |
r7 = parse__(); | |
if (r7 !== null) { | |
if (input.substr(pos, 2) === "||") { | |
r8 = "||"; | |
pos += 2; | |
} else { | |
r8 = null; | |
if (reportFailures === 0) { | |
matchFailed("\"||\""); | |
} | |
} | |
if (r8 !== null) { | |
r9 = parse__(); | |
if (r9 !== null) { | |
r10 = parse_AndStatement(); | |
if (r10 !== null) { | |
r5 = [r7, r8, r9, r10]; | |
} else { | |
r5 = null; | |
pos = r6; | |
} | |
} else { | |
r5 = null; | |
pos = r6; | |
} | |
} else { | |
r5 = null; | |
pos = r6; | |
} | |
} else { | |
r5 = null; | |
pos = r6; | |
} | |
} | |
if (r4 !== null) { | |
r0 = [r3, r4]; | |
} else { | |
r0 = null; | |
pos = r2; | |
} | |
} else { | |
r0 = null; | |
pos = r2; | |
} | |
if (r0 !== null) { | |
r0 = (function(offset, head, tail) { | |
var result = head; | |
for (var i = 0; i < tail.length; i++) { | |
result = {'OR': [result, tail[i][3]]}; | |
} | |
return result; | |
})(r1, r3, r4); | |
} | |
if (r0 === null) { | |
pos = r1; | |
} | |
reportFailures--; | |
if (reportFailures === 0 && r0 === null) { | |
matchFailed("OrStatement"); | |
} | |
depth--; | |
return r0; | |
} | |
function parse_AndStatement() { | |
depth++; | |
var r0, r1, r2, r3, r4, r5, r6, r7, r8, r9, r10; | |
reportFailures++; | |
r1 = pos; | |
r2 = pos; | |
r3 = parse_SimpleStatement(); | |
if (r3 !== null) { | |
r4 = []; | |
r6 = pos; | |
r7 = parse__(); | |
if (r7 !== null) { | |
if (input.substr(pos, 2) === "&&") { | |
r8 = "&&"; | |
pos += 2; | |
} else { | |
r8 = null; | |
if (reportFailures === 0) { | |
matchFailed("\"&&\""); | |
} | |
} | |
if (r8 !== null) { | |
r9 = parse__(); | |
if (r9 !== null) { | |
r10 = parse_SimpleStatement(); | |
if (r10 !== null) { | |
r5 = [r7, r8, r9, r10]; | |
} else { | |
r5 = null; | |
pos = r6; | |
} | |
} else { | |
r5 = null; | |
pos = r6; | |
} | |
} else { | |
r5 = null; | |
pos = r6; | |
} | |
} else { | |
r5 = null; | |
pos = r6; | |
} | |
while (r5 !== null) { | |
r4.push(r5); | |
r6 = pos; | |
r7 = parse__(); | |
if (r7 !== null) { | |
if (input.substr(pos, 2) === "&&") { | |
r8 = "&&"; | |
pos += 2; | |
} else { | |
r8 = null; | |
if (reportFailures === 0) { | |
matchFailed("\"&&\""); | |
} | |
} | |
if (r8 !== null) { | |
r9 = parse__(); | |
if (r9 !== null) { | |
r10 = parse_SimpleStatement(); | |
if (r10 !== null) { | |
r5 = [r7, r8, r9, r10]; | |
} else { | |
r5 = null; | |
pos = r6; | |
} | |
} else { | |
r5 = null; | |
pos = r6; | |
} | |
} else { | |
r5 = null; | |
pos = r6; | |
} | |
} else { | |
r5 = null; | |
pos = r6; | |
} | |
} | |
if (r4 !== null) { | |
r0 = [r3, r4]; | |
} else { | |
r0 = null; | |
pos = r2; | |
} | |
} else { | |
r0 = null; | |
pos = r2; | |
} | |
if (r0 !== null) { | |
r0 = (function(offset, head, tail) { | |
var result = head; | |
for (var i = 0; i < tail.length; i++) { | |
result = {'AND': [result, tail[i][3]]}; | |
} | |
return result; | |
})(r1, r3, r4); | |
} | |
if (r0 === null) { | |
pos = r1; | |
} | |
reportFailures--; | |
if (reportFailures === 0 && r0 === null) { | |
matchFailed("AndStatement"); | |
} | |
depth--; | |
return r0; | |
} | |
function parse_SimpleStatement() { | |
depth++; | |
var r0, r1, r2, r3, r4, r5, r6, r7, r8; | |
reportFailures++; | |
r1 = pos; | |
r2 = pos; | |
r3 = parse_PipeCommand(); | |
if (r3 === null) { | |
r3 = parse_SimpleCommand(); | |
} | |
if (r3 !== null) { | |
r4 = []; | |
r6 = pos; | |
r7 = parse__(); | |
if (r7 !== null) { | |
r8 = parse_Redir(); | |
if (r8 !== null) { | |
r5 = [r7, r8]; | |
} else { | |
r5 = null; | |
pos = r6; | |
} | |
} else { | |
r5 = null; | |
pos = r6; | |
} | |
while (r5 !== null) { | |
r4.push(r5); | |
r6 = pos; | |
r7 = parse__(); | |
if (r7 !== null) { | |
r8 = parse_Redir(); | |
if (r8 !== null) { | |
r5 = [r7, r8]; | |
} else { | |
r5 = null; | |
pos = r6; | |
} | |
} else { | |
r5 = null; | |
pos = r6; | |
} | |
} | |
if (r4 !== null) { | |
r0 = [r3, r4]; | |
} else { | |
r0 = null; | |
pos = r2; | |
} | |
} else { | |
r0 = null; | |
pos = r2; | |
} | |
if (r0 !== null) { | |
r0 = (function(offset, head, tail) { | |
if (tail.length === 0) { | |
return head; | |
} | |
var redir = []; | |
for (var i = 0; i < tail.length; i++) { | |
redir.push(tail[i][1]); | |
} | |
head['TAIL'] = redir; | |
return head; | |
})(r1, r3, r4); | |
} | |
if (r0 === null) { | |
pos = r1; | |
} | |
reportFailures--; | |
if (reportFailures === 0 && r0 === null) { | |
matchFailed("SimpleStatement"); | |
} | |
depth--; | |
return r0; | |
} | |
function parse_EmptyStatement() { | |
depth++; | |
var r0, r1, r2; | |
reportFailures++; | |
r1 = pos; | |
r2 = pos; | |
reportFailures++; | |
r0 = parse_EOS(); | |
reportFailures--; | |
if (r0 !== null) { | |
r0 = ""; | |
pos = r2; | |
} else { | |
r0 = null; | |
} | |
if (r0 !== null) { | |
r0 = (function(offset) {return '';})(r1); | |
} | |
if (r0 === null) { | |
pos = r1; | |
} | |
reportFailures--; | |
if (reportFailures === 0 && r0 === null) { | |
matchFailed("EmptyStatement"); | |
} | |
depth--; | |
return r0; | |
} | |
function parse_Redir() { | |
depth++; | |
var r0, r1, r2, r3, r4, r5; | |
reportFailures++; | |
r1 = pos; | |
r2 = pos; | |
if (input.substr(pos, 2) === ">>") { | |
r3 = ">>"; | |
pos += 2; | |
} else { | |
r3 = null; | |
if (reportFailures === 0) { | |
matchFailed("\">>\""); | |
} | |
} | |
if (r3 !== null) { | |
r4 = parse__(); | |
if (r4 !== null) { | |
r5 = parse_Argword(); | |
if (r5 !== null) { | |
r0 = [r3, r4, r5]; | |
} else { | |
r0 = null; | |
pos = r2; | |
} | |
} else { | |
r0 = null; | |
pos = r2; | |
} | |
} else { | |
r0 = null; | |
pos = r2; | |
} | |
if (r0 !== null) { | |
r0 = (function(offset, arg) { return {'REDIRAPPEND': arg}; })(r1, r5); | |
} | |
if (r0 === null) { | |
pos = r1; | |
} | |
if (r0 === null) { | |
r1 = pos; | |
r2 = pos; | |
if (input.charCodeAt(pos) === 62) { | |
r3 = ">"; | |
pos++; | |
} else { | |
r3 = null; | |
if (reportFailures === 0) { | |
matchFailed("\">\""); | |
} | |
} | |
if (r3 !== null) { | |
r4 = parse__(); | |
if (r4 !== null) { | |
r5 = parse_Argword(); | |
if (r5 !== null) { | |
r0 = [r3, r4, r5]; | |
} else { | |
r0 = null; | |
pos = r2; | |
} | |
} else { | |
r0 = null; | |
pos = r2; | |
} | |
} else { | |
r0 = null; | |
pos = r2; | |
} | |
if (r0 !== null) { | |
r0 = (function(offset, arg) { return {'REDIROUT': arg}; })(r1, r5); | |
} | |
if (r0 === null) { | |
pos = r1; | |
} | |
if (r0 === null) { | |
r1 = pos; | |
r2 = pos; | |
if (input.substr(pos, 2) === "2>") { | |
r3 = "2>"; | |
pos += 2; | |
} else { | |
r3 = null; | |
if (reportFailures === 0) { | |
matchFailed("\"2>\""); | |
} | |
} | |
if (r3 !== null) { | |
r4 = parse__(); | |
if (r4 !== null) { | |
r5 = parse_Argword(); | |
if (r5 !== null) { | |
r0 = [r3, r4, r5]; | |
} else { | |
r0 = null; | |
pos = r2; | |
} | |
} else { | |
r0 = null; | |
pos = r2; | |
} | |
} else { | |
r0 = null; | |
pos = r2; | |
} | |
if (r0 !== null) { | |
r0 = (function(offset, arg) { return {'REDIR2OUT': arg}; })(r1, r5); | |
} | |
if (r0 === null) { | |
pos = r1; | |
} | |
if (r0 === null) { | |
r1 = pos; | |
r2 = pos; | |
if (input.substr(pos, 3) === "2>>") { | |
r3 = "2>>"; | |
pos += 3; | |
} else { | |
r3 = null; | |
if (reportFailures === 0) { | |
matchFailed("\"2>>\""); | |
} | |
} | |
if (r3 !== null) { | |
r4 = parse__(); | |
if (r4 !== null) { | |
r5 = parse_Argword(); | |
if (r5 !== null) { | |
r0 = [r3, r4, r5]; | |
} else { | |
r0 = null; | |
pos = r2; | |
} | |
} else { | |
r0 = null; | |
pos = r2; | |
} | |
} else { | |
r0 = null; | |
pos = r2; | |
} | |
if (r0 !== null) { | |
r0 = (function(offset, arg) { return {'REDIR2APPEND': arg}; })(r1, r5); | |
} | |
if (r0 === null) { | |
pos = r1; | |
} | |
if (r0 === null) { | |
r1 = pos; | |
r2 = pos; | |
if (input.charCodeAt(pos) === 60) { | |
r3 = "<"; | |
pos++; | |
} else { | |
r3 = null; | |
if (reportFailures === 0) { | |
matchFailed("\"<\""); | |
} | |
} | |
if (r3 !== null) { | |
r4 = parse__(); | |
if (r4 !== null) { | |
r5 = parse_Argword(); | |
if (r5 !== null) { | |
r0 = [r3, r4, r5]; | |
} else { | |
r0 = null; | |
pos = r2; | |
} | |
} else { | |
r0 = null; | |
pos = r2; | |
} | |
} else { | |
r0 = null; | |
pos = r2; | |
} | |
if (r0 !== null) { | |
r0 = (function(offset, arg) { return {'REDIRIN': arg}; })(r1, r5); | |
} | |
if (r0 === null) { | |
pos = r1; | |
} | |
} | |
} | |
} | |
} | |
reportFailures--; | |
if (reportFailures === 0 && r0 === null) { | |
matchFailed("Redir"); | |
} | |
depth--; | |
return r0; | |
} | |
function parse_PipeCommand() { | |
depth++; | |
var r0, r1, r2, r3, r4, r5, r6, r7, r8, r9, r10; | |
reportFailures++; | |
r1 = pos; | |
r2 = pos; | |
r3 = parse_SimpleCommand(); | |
if (r3 !== null) { | |
r6 = pos; | |
r7 = parse__(); | |
if (r7 !== null) { | |
if (input.charCodeAt(pos) === 124) { | |
r8 = "|"; | |
pos++; | |
} else { | |
r8 = null; | |
if (reportFailures === 0) { | |
matchFailed("\"|\""); | |
} | |
} | |
if (r8 !== null) { | |
r9 = parse__(); | |
if (r9 !== null) { | |
r10 = parse_SimpleCommand(); | |
if (r10 !== null) { | |
r5 = [r7, r8, r9, r10]; | |
} else { | |
r5 = null; | |
pos = r6; | |
} | |
} else { | |
r5 = null; | |
pos = r6; | |
} | |
} else { | |
r5 = null; | |
pos = r6; | |
} | |
} else { | |
r5 = null; | |
pos = r6; | |
} | |
if (r5 !== null) { | |
r4 = []; | |
while (r5 !== null) { | |
r4.push(r5); | |
r6 = pos; | |
r7 = parse__(); | |
if (r7 !== null) { | |
if (input.charCodeAt(pos) === 124) { | |
r8 = "|"; | |
pos++; | |
} else { | |
r8 = null; | |
if (reportFailures === 0) { | |
matchFailed("\"|\""); | |
} | |
} | |
if (r8 !== null) { | |
r9 = parse__(); | |
if (r9 !== null) { | |
r10 = parse_SimpleCommand(); | |
if (r10 !== null) { | |
r5 = [r7, r8, r9, r10]; | |
} else { | |
r5 = null; | |
pos = r6; | |
} | |
} else { | |
r5 = null; | |
pos = r6; | |
} | |
} else { | |
r5 = null; | |
pos = r6; | |
} | |
} else { | |
r5 = null; | |
pos = r6; | |
} | |
} | |
} else { | |
r4 = null; | |
} | |
if (r4 !== null) { | |
r6 = pos; | |
reportFailures++; | |
r5 = parse_EOCP(); | |
reportFailures--; | |
if (r5 !== null) { | |
r5 = ""; | |
pos = r6; | |
} else { | |
r5 = null; | |
} | |
if (r5 !== null) { | |
r0 = [r3, r4, r5]; | |
} else { | |
r0 = null; | |
pos = r2; | |
} | |
} else { | |
r0 = null; | |
pos = r2; | |
} | |
} else { | |
r0 = null; | |
pos = r2; | |
} | |
if (r0 !== null) { | |
r0 = (function(offset, head, tail) { | |
var result = [head]; | |
for (var i = 0; i < tail.length; i++) { | |
result.push(tail[i][3]); | |
} | |
return {'PIPE': result}; | |
})(r1, r3, r4); | |
} | |
if (r0 === null) { | |
pos = r1; | |
} | |
reportFailures--; | |
if (reportFailures === 0 && r0 === null) { | |
matchFailed("PipeCommand"); | |
} | |
depth--; | |
return r0; | |
} | |
function parse_SimpleCommand() { | |
depth++; | |
var r0, r1, r2, r3, r4, r5, r6, r7, r8; | |
reportFailures++; | |
r1 = pos; | |
r2 = pos; | |
r3 = parse_Command(); | |
if (r3 !== null) { | |
r4 = []; | |
r6 = pos; | |
r7 = parse___(); | |
if (r7 !== null) { | |
r8 = parse_Argword(); | |
if (r8 !== null) { | |
r5 = [r7, r8]; | |
} else { | |
r5 = null; | |
pos = r6; | |
} | |
} else { | |
r5 = null; | |
pos = r6; | |
} | |
while (r5 !== null) { | |
r4.push(r5); | |
r6 = pos; | |
r7 = parse___(); | |
if (r7 !== null) { | |
r8 = parse_Argword(); | |
if (r8 !== null) { | |
r5 = [r7, r8]; | |
} else { | |
r5 = null; | |
pos = r6; | |
} | |
} else { | |
r5 = null; | |
pos = r6; | |
} | |
} | |
if (r4 !== null) { | |
r6 = pos; | |
reportFailures++; | |
r5 = parse_EOC(); | |
reportFailures--; | |
if (r5 !== null) { | |
r5 = ""; | |
pos = r6; | |
} else { | |
r5 = null; | |
} | |
if (r5 !== null) { | |
r0 = [r3, r4, r5]; | |
} else { | |
r0 = null; | |
pos = r2; | |
} | |
} else { | |
r0 = null; | |
pos = r2; | |
} | |
} else { | |
r0 = null; | |
pos = r2; | |
} | |
if (r0 !== null) { | |
r0 = (function(offset, head, tail) { | |
var result = [head]; | |
for (var i = 0; i < tail.length; i++) { | |
result.push(tail[i][1]); | |
} | |
return {'ARGLIST': result}; | |
})(r1, r3, r4); | |
} | |
if (r0 === null) { | |
pos = r1; | |
} | |
reportFailures--; | |
if (reportFailures === 0 && r0 === null) { | |
matchFailed("SimpleCommand"); | |
} | |
depth--; | |
return r0; | |
} | |
function parse_Command() { | |
depth++; | |
var r0, r1, r2, r3, r4, r5, r6, r7; | |
r1 = pos; | |
r2 = pos; | |
r4 = pos; | |
reportFailures++; | |
r5 = pos; | |
r6 = parse_Keyword(); | |
if (r6 !== null) { | |
r7 = parse_EOC(); | |
if (r7 !== null) { | |
r3 = [r6, r7]; | |
} else { | |
r3 = null; | |
pos = r5; | |
} | |
} else { | |
r3 = null; | |
pos = r5; | |
} | |
if (r3 === null) { | |
if (input.charCodeAt(pos) === 125) { | |
r3 = "}"; | |
pos++; | |
} else { | |
r3 = null; | |
if (reportFailures === 0) { | |
matchFailed("\"}\""); | |
} | |
} | |
} | |
reportFailures--; | |
if (r3 === null) { | |
r3 = ""; | |
} else { | |
r3 = null; | |
pos = r4; | |
} | |
if (r3 !== null) { | |
r4 = parse_Argword(); | |
if (r4 !== null) { | |
r0 = [r3, r4]; | |
} else { | |
r0 = null; | |
pos = r2; | |
} | |
} else { | |
r0 = null; | |
pos = r2; | |
} | |
if (r0 !== null) { | |
r0 = (function(offset, cmd) { return cmd;})(r1, r4); | |
} | |
if (r0 === null) { | |
pos = r1; | |
} | |
depth--; | |
return r0; | |
} | |
function parse_Identifier() { | |
depth++; | |
var r0, r1, r2, r3, r4, r5; | |
reportFailures++; | |
r1 = pos; | |
r2 = pos; | |
if (/^[a-zA-Z_]/.test(input.charAt(pos))) { | |
r3 = input.charAt(pos); | |
pos++; | |
} else { | |
r3 = null; | |
if (reportFailures === 0) { | |
matchFailed("[a-zA-Z_]"); | |
} | |
} | |
if (r3 !== null) { | |
r4 = []; | |
if (/^[a-zA-Z0-9_]/.test(input.charAt(pos))) { | |
r5 = input.charAt(pos); | |
pos++; | |
} else { | |
r5 = null; | |
if (reportFailures === 0) { | |
matchFailed("[a-zA-Z0-9_]"); | |
} | |
} | |
while (r5 !== null) { | |
r4.push(r5); | |
if (/^[a-zA-Z0-9_]/.test(input.charAt(pos))) { | |
r5 = input.charAt(pos); | |
pos++; | |
} else { | |
r5 = null; | |
if (reportFailures === 0) { | |
matchFailed("[a-zA-Z0-9_]"); | |
} | |
} | |
} | |
if (r4 !== null) { | |
r0 = [r3, r4]; | |
} else { | |
r0 = null; | |
pos = r2; | |
} | |
} else { | |
r0 = null; | |
pos = r2; | |
} | |
if (r0 !== null) { | |
r0 = (function(offset, head, tail) { | |
var result = head + tail.join(""); | |
return result; | |
})(r1, r3, r4); | |
} | |
if (r0 === null) { | |
pos = r1; | |
} | |
reportFailures--; | |
if (reportFailures === 0 && r0 === null) { | |
matchFailed("Identifier"); | |
} | |
depth--; | |
return r0; | |
} | |
function parse_TokenList() { | |
depth++; | |
var r0, r1, r2, r3, r4, r5, r6, r7, r8, r9, r10; | |
r1 = pos; | |
r2 = pos; | |
r3 = parse__(); | |
if (r3 !== null) { | |
r4 = parse_Argword(); | |
if (r4 !== null) { | |
r5 = parse__(); | |
if (r5 !== null) { | |
r6 = []; | |
r8 = pos; | |
r9 = parse_Argword(); | |
if (r9 === null) { | |
r9 = parse_SimpleCmdSep(); | |
if (r9 === null) { | |
if (input.substr(pos, 2) === "$(") { | |
r9 = "$("; | |
pos += 2; | |
} else { | |
r9 = null; | |
if (reportFailures === 0) { | |
matchFailed("\"$(\""); | |
} | |
} | |
} | |
} | |
if (r9 !== null) { | |
r10 = parse__(); | |
if (r10 !== null) { | |
r7 = [r9, r10]; | |
} else { | |
r7 = null; | |
pos = r8; | |
} | |
} else { | |
r7 = null; | |
pos = r8; | |
} | |
while (r7 !== null) { | |
r6.push(r7); | |
r8 = pos; | |
r9 = parse_Argword(); | |
if (r9 === null) { | |
r9 = parse_SimpleCmdSep(); | |
if (r9 === null) { | |
if (input.substr(pos, 2) === "$(") { | |
r9 = "$("; | |
pos += 2; | |
} else { | |
r9 = null; | |
if (reportFailures === 0) { | |
matchFailed("\"$(\""); | |
} | |
} | |
} | |
} | |
if (r9 !== null) { | |
r10 = parse__(); | |
if (r10 !== null) { | |
r7 = [r9, r10]; | |
} else { | |
r7 = null; | |
pos = r8; | |
} | |
} else { | |
r7 = null; | |
pos = r8; | |
} | |
} | |
if (r6 !== null) { | |
r7 = []; | |
r8 = parse_WhiteSpace(); | |
if (r8 === null) { | |
r8 = parse_LineTerminator(); | |
} | |
while (r8 !== null) { | |
r7.push(r8); | |
r8 = parse_WhiteSpace(); | |
if (r8 === null) { | |
r8 = parse_LineTerminator(); | |
} | |
} | |
if (r7 !== null) { | |
r0 = [r3, r4, r5, r6, r7]; | |
} else { | |
r0 = null; | |
pos = r2; | |
} | |
} else { | |
r0 = null; | |
pos = r2; | |
} | |
} else { | |
r0 = null; | |
pos = r2; | |
} | |
} else { | |
r0 = null; | |
pos = r2; | |
} | |
} else { | |
r0 = null; | |
pos = r2; | |
} | |
if (r0 !== null) { | |
r0 = (function(offset, head, tail) { | |
var result = [head]; | |
for (var i = 0; i < tail.length; i++) { | |
result.push(tail[i][0]); | |
} | |
return result; | |
})(r1, r4, r6); | |
} | |
if (r0 === null) { | |
pos = r1; | |
} | |
depth--; | |
return r0; | |
} | |
function parse_Argwordlist() { | |
depth++; | |
var r0, r1, r2, r3, r4, r5, r6, r7, r8; | |
r1 = pos; | |
r2 = pos; | |
r3 = parse_Argword(); | |
if (r3 !== null) { | |
r4 = []; | |
r6 = pos; | |
r7 = parse___(); | |
if (r7 !== null) { | |
r8 = parse_Argword(); | |
if (r8 !== null) { | |
r5 = [r7, r8]; | |
} else { | |
r5 = null; | |
pos = r6; | |
} | |
} else { | |
r5 = null; | |
pos = r6; | |
} | |
while (r5 !== null) { | |
r4.push(r5); | |
r6 = pos; | |
r7 = parse___(); | |
if (r7 !== null) { | |
r8 = parse_Argword(); | |
if (r8 !== null) { | |
r5 = [r7, r8]; | |
} else { | |
r5 = null; | |
pos = r6; | |
} | |
} else { | |
r5 = null; | |
pos = r6; | |
} | |
} | |
if (r4 !== null) { | |
r0 = [r3, r4]; | |
} else { | |
r0 = null; | |
pos = r2; | |
} | |
} else { | |
r0 = null; | |
pos = r2; | |
} | |
if (r0 !== null) { | |
r0 = (function(offset, head, tail) { | |
var result = [head]; | |
for (var i = 0; i < tail.length; i++) { | |
result.push(tail[i][1]); | |
} | |
return result; | |
})(r1, r3, r4); | |
} | |
if (r0 === null) { | |
pos = r1; | |
} | |
depth--; | |
return r0; | |
} | |
function parse_Argword() { | |
depth++; | |
var r0; | |
reportFailures++; | |
r0 = parse_Concat(); | |
if (r0 === null) { | |
r0 = parse_Argword2(); | |
} | |
reportFailures--; | |
if (reportFailures === 0 && r0 === null) { | |
matchFailed("Argword"); | |
} | |
depth--; | |
return r0; | |
} | |
function parse_Argword2() { | |
depth++; | |
var r0, r1; | |
reportFailures++; | |
r1 = pos; | |
r0 = parse_Deferred(); | |
if (r0 === null) { | |
r0 = parse_Backquote(); | |
if (r0 === null) { | |
r0 = parse_Varlen(); | |
if (r0 === null) { | |
r0 = parse_Varjoin(); | |
if (r0 === null) { | |
r0 = parse_Varref(); | |
if (r0 === null) { | |
r0 = parse_List(); | |
if (r0 === null) { | |
r0 = parse_StringLiteral(); | |
} | |
} | |
} | |
} | |
} | |
} | |
if (r0 !== null) { | |
r0 = (function(offset, arg) { | |
return arg; | |
})(r1, r0); | |
} | |
if (r0 === null) { | |
pos = r1; | |
} | |
reportFailures--; | |
if (reportFailures === 0 && r0 === null) { | |
matchFailed("Argword2"); | |
} | |
depth--; | |
return r0; | |
} | |
function parse_List() { | |
depth++; | |
var r0, r1, r2, r3, r4, r5, r6, r7; | |
r1 = pos; | |
r2 = pos; | |
if (input.charCodeAt(pos) === 40) { | |
r3 = "("; | |
pos++; | |
} else { | |
r3 = null; | |
if (reportFailures === 0) { | |
matchFailed("\"(\""); | |
} | |
} | |
if (r3 !== null) { | |
r4 = parse__(); | |
if (r4 !== null) { | |
r5 = parse_Argwordlist(); | |
r5 = r5 !== null ? r5 : ""; | |
if (r5 !== null) { | |
r6 = parse__(); | |
if (r6 !== null) { | |
if (input.charCodeAt(pos) === 41) { | |
r7 = ")"; | |
pos++; | |
} else { | |
r7 = null; | |
if (reportFailures === 0) { | |
matchFailed("\")\""); | |
} | |
} | |
if (r7 !== null) { | |
r0 = [r3, r4, r5, r6, r7]; | |
} else { | |
r0 = null; | |
pos = r2; | |
} | |
} else { | |
r0 = null; | |
pos = r2; | |
} | |
} else { | |
r0 = null; | |
pos = r2; | |
} | |
} else { | |
r0 = null; | |
pos = r2; | |
} | |
} else { | |
r0 = null; | |
pos = r2; | |
} | |
if (r0 !== null) { | |
r0 = (function(offset, args) { | |
return {'LIST': args}; | |
})(r1, r5); | |
} | |
if (r0 === null) { | |
pos = r1; | |
} | |
depth--; | |
return r0; | |
} | |
function parse_VarIdentifier() { | |
depth++; | |
var r0; | |
r0 = parse_Identifier(); | |
if (r0 === null) { | |
if (input.charCodeAt(pos) === 63) { | |
r0 = "?"; | |
pos++; | |
} else { | |
r0 = null; | |
if (reportFailures === 0) { | |
matchFailed("\"?\""); | |
} | |
} | |
if (r0 === null) { | |
if (input.charCodeAt(pos) === 42) { | |
r0 = "*"; | |
pos++; | |
} else { | |
r0 = null; | |
if (reportFailures === 0) { | |
matchFailed("\"*\""); | |
} | |
} | |
if (r0 === null) { | |
if (input.charCodeAt(pos) === 33) { | |
r0 = "!"; | |
pos++; | |
} else { | |
r0 = null; | |
if (reportFailures === 0) { | |
matchFailed("\"!\""); | |
} | |
} | |
if (r0 === null) { | |
if (input.charCodeAt(pos) === 35) { | |
r0 = "#"; | |
pos++; | |
} else { | |
r0 = null; | |
if (reportFailures === 0) { | |
matchFailed("\"#\""); | |
} | |
} | |
if (r0 === null) { | |
r0 = parse_Number(); | |
} | |
} | |
} | |
} | |
} | |
depth--; | |
return r0; | |
} | |
function parse_Varlen() { | |
depth++; | |
var r0, r1, r2, r3, r4; | |
reportFailures++; | |
r1 = pos; | |
r2 = pos; | |
if (input.substr(pos, 2) === "$#") { | |
r3 = "$#"; | |
pos += 2; | |
} else { | |
r3 = null; | |
if (reportFailures === 0) { | |
matchFailed("\"$#\""); | |
} | |
} | |
if (r3 !== null) { | |
r4 = parse_VarIdentifier(); | |
if (r4 !== null) { | |
r0 = [r3, r4]; | |
} else { | |
r0 = null; | |
pos = r2; | |
} | |
} else { | |
r0 = null; | |
pos = r2; | |
} | |
if (r0 !== null) { | |
r0 = (function(offset, id) { | |
return {'VARLEN': id}; | |
})(r1, r4); | |
} | |
if (r0 === null) { | |
pos = r1; | |
} | |
reportFailures--; | |
if (reportFailures === 0 && r0 === null) { | |
matchFailed("Varlen"); | |
} | |
depth--; | |
return r0; | |
} | |
function parse_Varjoin() { | |
depth++; | |
var r0, r1, r2, r3, r4; | |
reportFailures++; | |
r1 = pos; | |
r2 = pos; | |
if (input.substr(pos, 2) === "$\"") { | |
r3 = "$\""; | |
pos += 2; | |
} else { | |
r3 = null; | |
if (reportFailures === 0) { | |
matchFailed("\"$\\\"\""); | |
} | |
} | |
if (r3 !== null) { | |
r4 = parse_VarIdentifier(); | |
if (r4 !== null) { | |
r0 = [r3, r4]; | |
} else { | |
r0 = null; | |
pos = r2; | |
} | |
} else { | |
r0 = null; | |
pos = r2; | |
} | |
if (r0 !== null) { | |
r0 = (function(offset, id) { | |
return {'VARJOIN': id}; | |
})(r1, r4); | |
} | |
if (r0 === null) { | |
pos = r1; | |
} | |
reportFailures--; | |
if (reportFailures === 0 && r0 === null) { | |
matchFailed("Varjoin"); | |
} | |
depth--; | |
return r0; | |
} | |
function parse_Varref() { | |
depth++; | |
var r0, r1, r2, r3, r4, r5, r6, r7, r8, r9; | |
reportFailures++; | |
r1 = pos; | |
r2 = pos; | |
if (input.charCodeAt(pos) === 36) { | |
r3 = "$"; | |
pos++; | |
} else { | |
r3 = null; | |
if (reportFailures === 0) { | |
matchFailed("\"$\""); | |
} | |
} | |
if (r3 !== null) { | |
r4 = parse_VarIdentifier(); | |
if (r4 !== null) { | |
if (input.charCodeAt(pos) === 40) { | |
r5 = "("; | |
pos++; | |
} else { | |
r5 = null; | |
if (reportFailures === 0) { | |
matchFailed("\"(\""); | |
} | |
} | |
if (r5 !== null) { | |
r6 = parse__(); | |
if (r6 !== null) { | |
r7 = parse_Argwordlist(); | |
r7 = r7 !== null ? r7 : ""; | |
if (r7 !== null) { | |
r8 = parse__(); | |
if (r8 !== null) { | |
if (input.charCodeAt(pos) === 41) { | |
r9 = ")"; | |
pos++; | |
} else { | |
r9 = null; | |
if (reportFailures === 0) { | |
matchFailed("\")\""); | |
} | |
} | |
if (r9 !== null) { | |
r0 = [r3, r4, r5, r6, r7, r8, r9]; | |
} else { | |
r0 = null; | |
pos = r2; | |
} | |
} else { | |
r0 = null; | |
pos = r2; | |
} | |
} else { | |
r0 = null; | |
pos = r2; | |
} | |
} else { | |
r0 = null; | |
pos = r2; | |
} | |
} else { | |
r0 = null; | |
pos = r2; | |
} | |
} else { | |
r0 = null; | |
pos = r2; | |
} | |
} else { | |
r0 = null; | |
pos = r2; | |
} | |
if (r0 !== null) { | |
r0 = (function(offset, id, slist) { | |
return {'VARVAL': [id, slist]}; | |
})(r1, r4, r7); | |
} | |
if (r0 === null) { | |
pos = r1; | |
} | |
if (r0 === null) { | |
r1 = pos; | |
r2 = pos; | |
if (input.charCodeAt(pos) === 36) { | |
r3 = "$"; | |
pos++; | |
} else { | |
r3 = null; | |
if (reportFailures === 0) { | |
matchFailed("\"$\""); | |
} | |
} | |
if (r3 !== null) { | |
r4 = parse_VarIdentifier(); | |
if (r4 !== null) { | |
r0 = [r3, r4]; | |
} else { | |
r0 = null; | |
pos = r2; | |
} | |
} else { | |
r0 = null; | |
pos = r2; | |
} | |
if (r0 !== null) { | |
r0 = (function(offset, id) { | |
return {'VARVAL': id} | |
})(r1, r4); | |
} | |
if (r0 === null) { | |
pos = r1; | |
} | |
} | |
reportFailures--; | |
if (reportFailures === 0 && r0 === null) { | |
matchFailed("Varref"); | |
} | |
depth--; | |
return r0; | |
} | |
function parse_Number() { | |
depth++; | |
var r0, r1, r2; | |
r1 = pos; | |
if (/^[0-9]/.test(input.charAt(pos))) { | |
r2 = input.charAt(pos); | |
pos++; | |
} else { | |
r2 = null; | |
if (reportFailures === 0) { | |
matchFailed("[0-9]"); | |
} | |
} | |
if (r2 !== null) { | |
r0 = []; | |
while (r2 !== null) { | |
r0.push(r2); | |
if (/^[0-9]/.test(input.charAt(pos))) { | |
r2 = input.charAt(pos); | |
pos++; | |
} else { | |
r2 = null; | |
if (reportFailures === 0) { | |
matchFailed("[0-9]"); | |
} | |
} | |
} | |
} else { | |
r0 = null; | |
} | |
if (r0 !== null) { | |
r0 = (function(offset, num) { return num.join("");})(r1, r0); | |
} | |
if (r0 === null) { | |
pos = r1; | |
} | |
depth--; | |
return r0; | |
} | |
function parse_Concat() { | |
depth++; | |
var r0, r1, r2, r3, r4, r5, r6, r7, r8; | |
r1 = pos; | |
r2 = pos; | |
r3 = parse_Argword2(); | |
if (r3 !== null) { | |
r6 = pos; | |
if (input.charCodeAt(pos) === 94) { | |
r7 = "^"; | |
pos++; | |
} else { | |
r7 = null; | |
if (reportFailures === 0) { | |
matchFailed("\"^\""); | |
} | |
} | |
r7 = r7 !== null ? r7 : ""; | |
if (r7 !== null) { | |
r8 = parse_Argword2(); | |
if (r8 !== null) { | |
r5 = [r7, r8]; | |
} else { | |
r5 = null; | |
pos = r6; | |
} | |
} else { | |
r5 = null; | |
pos = r6; | |
} | |
if (r5 !== null) { | |
r4 = []; | |
while (r5 !== null) { | |
r4.push(r5); | |
r6 = pos; | |
if (input.charCodeAt(pos) === 94) { | |
r7 = "^"; | |
pos++; | |
} else { | |
r7 = null; | |
if (reportFailures === 0) { | |
matchFailed("\"^\""); | |
} | |
} | |
r7 = r7 !== null ? r7 : ""; | |
if (r7 !== null) { | |
r8 = parse_Argword2(); | |
if (r8 !== null) { | |
r5 = [r7, r8]; | |
} else { | |
r5 = null; | |
pos = r6; | |
} | |
} else { | |
r5 = null; | |
pos = r6; | |
} | |
} | |
} else { | |
r4 = null; | |
} | |
if (r4 !== null) { | |
r0 = [r3, r4]; | |
} else { | |
r0 = null; | |
pos = r2; | |
} | |
} else { | |
r0 = null; | |
pos = r2; | |
} | |
if (r0 !== null) { | |
r0 = (function(offset, head, tail) { | |
var result = head; | |
for (var i = 0; i < tail.length; i++) { | |
result = {"^": [result, tail[i][1]]}; | |
} | |
return result; | |
})(r1, r3, r4); | |
} | |
if (r0 === null) { | |
pos = r1; | |
} | |
depth--; | |
return r0; | |
} | |
function parse_Backquote() { | |
depth++; | |
var r0, r1, r2, r3, r4, r5, r6, r7; | |
r1 = pos; | |
r2 = pos; | |
if (input.substr(pos, 2) === "$(") { | |
r3 = "$("; | |
pos += 2; | |
} else { | |
r3 = null; | |
if (reportFailures === 0) { | |
matchFailed("\"$(\""); | |
} | |
} | |
if (r3 !== null) { | |
r4 = parse__(); | |
if (r4 !== null) { | |
r5 = parse_StatementBlock(); | |
if (r5 !== null) { | |
r6 = parse__(); | |
if (r6 !== null) { | |
if (input.charCodeAt(pos) === 41) { | |
r7 = ")"; | |
pos++; | |
} else { | |
r7 = null; | |
if (reportFailures === 0) { | |
matchFailed("\")\""); | |
} | |
} | |
if (r7 !== null) { | |
r0 = [r3, r4, r5, r6, r7]; | |
} else { | |
r0 = null; | |
pos = r2; | |
} | |
} else { | |
r0 = null; | |
pos = r2; | |
} | |
} else { | |
r0 = null; | |
pos = r2; | |
} | |
} else { | |
r0 = null; | |
pos = r2; | |
} | |
} else { | |
r0 = null; | |
pos = r2; | |
} | |
if (r0 !== null) { | |
r0 = (function(offset, cmds) { | |
return {'BACKQUOTE': cmds}; | |
})(r1, r5); | |
} | |
if (r0 === null) { | |
pos = r1; | |
} | |
depth--; | |
return r0; | |
} | |
function parse_Deferred() { | |
depth++; | |
var r0, r1, r2, r3, r4, r5, r6, r7; | |
r1 = pos; | |
r2 = pos; | |
if (input.substr(pos, 2) === "${") { | |
r3 = "${"; | |
pos += 2; | |
} else { | |
r3 = null; | |
if (reportFailures === 0) { | |
matchFailed("\"${\""); | |
} | |
} | |
if (r3 !== null) { | |
r4 = parse__(); | |
if (r4 !== null) { | |
r5 = parse_StatementBlock(); | |
if (r5 !== null) { | |
r6 = parse__(); | |
if (r6 !== null) { | |
if (input.charCodeAt(pos) === 125) { | |
r7 = "}"; | |
pos++; | |
} else { | |
r7 = null; | |
if (reportFailures === 0) { | |
matchFailed("\"}\""); | |
} | |
} | |
if (r7 !== null) { | |
r0 = [r3, r4, r5, r6, r7]; | |
} else { | |
r0 = null; | |
pos = r2; | |
} | |
} else { | |
r0 = null; | |
pos = r2; | |
} | |
} else { | |
r0 = null; | |
pos = r2; | |
} | |
} else { | |
r0 = null; | |
pos = r2; | |
} | |
} else { | |
r0 = null; | |
pos = r2; | |
} | |
if (r0 !== null) { | |
r0 = (function(offset, cmds) { | |
return {'DEFERRED': cmds}; | |
})(r1, r5); | |
} | |
if (r0 === null) { | |
pos = r1; | |
} | |
depth--; | |
return r0; | |
} | |
function parse_StringLiteral() { | |
depth++; | |
var r0, r1, r2, r3, r4, r5; | |
reportFailures++; | |
r1 = pos; | |
r2 = pos; | |
if (input.charCodeAt(pos) === 34) { | |
r3 = "\""; | |
pos++; | |
} else { | |
r3 = null; | |
if (reportFailures === 0) { | |
matchFailed("\"\\\"\""); | |
} | |
} | |
if (r3 !== null) { | |
r4 = parse_DoubleStringCharacters(); | |
r4 = r4 !== null ? r4 : ""; | |
if (r4 !== null) { | |
if (input.charCodeAt(pos) === 34) { | |
r5 = "\""; | |
pos++; | |
} else { | |
r5 = null; | |
if (reportFailures === 0) { | |
matchFailed("\"\\\"\""); | |
} | |
} | |
if (r5 !== null) { | |
r0 = [r3, r4, r5]; | |
} else { | |
r0 = null; | |
pos = r2; | |
} | |
} else { | |
r0 = null; | |
pos = r2; | |
} | |
} else { | |
r0 = null; | |
pos = r2; | |
} | |
if (r0 !== null) { | |
r0 = (function(offset, parts) { | |
return {'DQUOTED_STRING': parts[1]}; | |
})(r1, r0); | |
} | |
if (r0 === null) { | |
pos = r1; | |
} | |
if (r0 === null) { | |
r1 = pos; | |
r2 = pos; | |
if (input.charCodeAt(pos) === 39) { | |
r3 = "'"; | |
pos++; | |
} else { | |
r3 = null; | |
if (reportFailures === 0) { | |
matchFailed("\"'\""); | |
} | |
} | |
if (r3 !== null) { | |
r4 = parse_SingleStringCharacters(); | |
r4 = r4 !== null ? r4 : ""; | |
if (r4 !== null) { | |
if (input.charCodeAt(pos) === 39) { | |
r5 = "'"; | |
pos++; | |
} else { | |
r5 = null; | |
if (reportFailures === 0) { | |
matchFailed("\"'\""); | |
} | |
} | |
if (r5 !== null) { | |
r0 = [r3, r4, r5]; | |
} else { | |
r0 = null; | |
pos = r2; | |
} | |
} else { | |
r0 = null; | |
pos = r2; | |
} | |
} else { | |
r0 = null; | |
pos = r2; | |
} | |
if (r0 !== null) { | |
r0 = (function(offset, parts) { | |
return {'SQUOTED_STRING': parts[1]}; | |
})(r1, r0); | |
} | |
if (r0 === null) { | |
pos = r1; | |
} | |
if (r0 === null) { | |
r0 = parse_BareStringCharacters(); | |
} | |
} | |
reportFailures--; | |
if (reportFailures === 0 && r0 === null) { | |
matchFailed("StringLiteral"); | |
} | |
depth--; | |
return r0; | |
} | |
function parse_DoubleStringCharacters() { | |
depth++; | |
var r0, r1, r2; | |
r1 = pos; | |
r2 = parse_DoubleStringCharacter(); | |
if (r2 !== null) { | |
r0 = []; | |
while (r2 !== null) { | |
r0.push(r2); | |
r2 = parse_DoubleStringCharacter(); | |
} | |
} else { | |
r0 = null; | |
} | |
if (r0 !== null) { | |
r0 = (function(offset, chars) { return chars.join(""); })(r1, r0); | |
} | |
if (r0 === null) { | |
pos = r1; | |
} | |
depth--; | |
return r0; | |
} | |
function parse_SingleStringCharacters() { | |
depth++; | |
var r0, r1, r2; | |
r1 = pos; | |
r2 = parse_SingleStringCharacter(); | |
if (r2 !== null) { | |
r0 = []; | |
while (r2 !== null) { | |
r0.push(r2); | |
r2 = parse_SingleStringCharacter(); | |
} | |
} else { | |
r0 = null; | |
} | |
if (r0 !== null) { | |
r0 = (function(offset, chars) { return chars.join(""); })(r1, r0); | |
} | |
if (r0 === null) { | |
pos = r1; | |
} | |
depth--; | |
return r0; | |
} | |
function parse_DoubleStringCharacter() { | |
depth++; | |
var r0, r1, r2, r3, r4; | |
r1 = pos; | |
r2 = pos; | |
r4 = pos; | |
reportFailures++; | |
if (input.charCodeAt(pos) === 34) { | |
r3 = "\""; | |
pos++; | |
} else { | |
r3 = null; | |
if (reportFailures === 0) { | |
matchFailed("\"\\\"\""); | |
} | |
} | |
if (r3 === null) { | |
if (input.charCodeAt(pos) === 92) { | |
r3 = "\\"; | |
pos++; | |
} else { | |
r3 = null; | |
if (reportFailures === 0) { | |
matchFailed("\"\\\\\""); | |
} | |
} | |
if (r3 === null) { | |
r3 = parse_LineTerminator(); | |
} | |
} | |
reportFailures--; | |
if (r3 === null) { | |
r3 = ""; | |
} else { | |
r3 = null; | |
pos = r4; | |
} | |
if (r3 !== null) { | |
r4 = parse_SourceCharacter(); | |
if (r4 !== null) { | |
r0 = [r3, r4]; | |
} else { | |
r0 = null; | |
pos = r2; | |
} | |
} else { | |
r0 = null; | |
pos = r2; | |
} | |
if (r0 !== null) { | |
r0 = (function(offset, char) { return char; })(r1, r4); | |
} | |
if (r0 === null) { | |
pos = r1; | |
} | |
if (r0 === null) { | |
r1 = pos; | |
r0 = parse_QuotedCharacter(); | |
if (r0 !== null) { | |
r0 = (function(offset, qc) { return qc; })(r1, r0); | |
} | |
if (r0 === null) { | |
pos = r1; | |
} | |
} | |
depth--; | |
return r0; | |
} | |
function parse_SingleStringCharacter() { | |
depth++; | |
var r0, r1, r2, r3, r4; | |
r1 = pos; | |
r2 = pos; | |
r4 = pos; | |
reportFailures++; | |
if (input.charCodeAt(pos) === 39) { | |
r3 = "'"; | |
pos++; | |
} else { | |
r3 = null; | |
if (reportFailures === 0) { | |
matchFailed("\"'\""); | |
} | |
} | |
if (r3 === null) { | |
if (input.charCodeAt(pos) === 92) { | |
r3 = "\\"; | |
pos++; | |
} else { | |
r3 = null; | |
if (reportFailures === 0) { | |
matchFailed("\"\\\\\""); | |
} | |
} | |
if (r3 === null) { | |
r3 = parse_LineTerminator(); | |
} | |
} | |
reportFailures--; | |
if (r3 === null) { | |
r3 = ""; | |
} else { | |
r3 = null; | |
pos = r4; | |
} | |
if (r3 !== null) { | |
r4 = parse_SourceCharacter(); | |
if (r4 !== null) { | |
r0 = [r3, r4]; | |
} else { | |
r0 = null; | |
pos = r2; | |
} | |
} else { | |
r0 = null; | |
pos = r2; | |
} | |
if (r0 !== null) { | |
r0 = (function(offset, char) { return char; })(r1, r4); | |
} | |
if (r0 === null) { | |
pos = r1; | |
} | |
if (r0 === null) { | |
r1 = pos; | |
r0 = parse_QuotedCharacter(); | |
if (r0 !== null) { | |
r0 = (function(offset, qc) { return qc; })(r1, r0); | |
} | |
if (r0 === null) { | |
pos = r1; | |
} | |
} | |
depth--; | |
return r0; | |
} | |
function parse_QuotedCharacter() { | |
depth++; | |
var r0, r1, r2, r3, r4, r5, r6, r7, r8, r9; | |
r1 = pos; | |
if (input.substr(pos, 2) === "\\0") { | |
r0 = "\\0"; | |
pos += 2; | |
} else { | |
r0 = null; | |
if (reportFailures === 0) { | |
matchFailed("\"\\\\0\""); | |
} | |
} | |
if (r0 !== null) { | |
r0 = (function(offset) { return "\0"; })(r1); | |
} | |
if (r0 === null) { | |
pos = r1; | |
} | |
if (r0 === null) { | |
r1 = pos; | |
if (input.substr(pos, 2) === "\\b") { | |
r0 = "\\b"; | |
pos += 2; | |
} else { | |
r0 = null; | |
if (reportFailures === 0) { | |
matchFailed("\"\\\\b\""); | |
} | |
} | |
if (r0 !== null) { | |
r0 = (function(offset) { return "\b"; })(r1); | |
} | |
if (r0 === null) { | |
pos = r1; | |
} | |
if (r0 === null) { | |
r1 = pos; | |
if (input.substr(pos, 2) === "\\t") { | |
r0 = "\\t"; | |
pos += 2; | |
} else { | |
r0 = null; | |
if (reportFailures === 0) { | |
matchFailed("\"\\\\t\""); | |
} | |
} | |
if (r0 !== null) { | |
r0 = (function(offset) { return "\t"; })(r1); | |
} | |
if (r0 === null) { | |
pos = r1; | |
} | |
if (r0 === null) { | |
r1 = pos; | |
if (input.substr(pos, 2) === "\\n") { | |
r0 = "\\n"; | |
pos += 2; | |
} else { | |
r0 = null; | |
if (reportFailures === 0) { | |
matchFailed("\"\\\\n\""); | |
} | |
} | |
if (r0 !== null) { | |
r0 = (function(offset) { return "\n"; })(r1); | |
} | |
if (r0 === null) { | |
pos = r1; | |
} | |
if (r0 === null) { | |
r1 = pos; | |
if (input.substr(pos, 2) === "\\v") { | |
r0 = "\\v"; | |
pos += 2; | |
} else { | |
r0 = null; | |
if (reportFailures === 0) { | |
matchFailed("\"\\\\v\""); | |
} | |
} | |
if (r0 !== null) { | |
r0 = (function(offset) { return "\v"; })(r1); | |
} | |
if (r0 === null) { | |
pos = r1; | |
} | |
if (r0 === null) { | |
r1 = pos; | |
if (input.substr(pos, 2) === "\\f") { | |
r0 = "\\f"; | |
pos += 2; | |
} else { | |
r0 = null; | |
if (reportFailures === 0) { | |
matchFailed("\"\\\\f\""); | |
} | |
} | |
if (r0 !== null) { | |
r0 = (function(offset) { return "\f"; })(r1); | |
} | |
if (r0 === null) { | |
pos = r1; | |
} | |
if (r0 === null) { | |
r1 = pos; | |
if (input.substr(pos, 2) === "\\r") { | |
r0 = "\\r"; | |
pos += 2; | |
} else { | |
r0 = null; | |
if (reportFailures === 0) { | |
matchFailed("\"\\\\r\""); | |
} | |
} | |
if (r0 !== null) { | |
r0 = (function(offset) { return "\r"; })(r1); | |
} | |
if (r0 === null) { | |
pos = r1; | |
} | |
if (r0 === null) { | |
r1 = pos; | |
r2 = pos; | |
if (input.substr(pos, 2) === "\\x") { | |
r3 = "\\x"; | |
pos += 2; | |
} else { | |
r3 = null; | |
if (reportFailures === 0) { | |
matchFailed("\"\\\\x\""); | |
} | |
} | |
if (r3 !== null) { | |
r5 = pos; | |
r6 = parse_HexDigit(); | |
if (r6 !== null) { | |
r7 = parse_HexDigit(); | |
if (r7 !== null) { | |
r4 = [r6, r7]; | |
} else { | |
r4 = null; | |
pos = r5; | |
} | |
} else { | |
r4 = null; | |
pos = r5; | |
} | |
if (r4 !== null) { | |
r0 = [r3, r4]; | |
} else { | |
r0 = null; | |
pos = r2; | |
} | |
} else { | |
r0 = null; | |
pos = r2; | |
} | |
if (r0 !== null) { | |
r0 = (function(offset, sequence) { return String.fromCharCode(parseInt("0x" + sequence.join(''))); })(r1, r4); | |
} | |
if (r0 === null) { | |
pos = r1; | |
} | |
if (r0 === null) { | |
r1 = pos; | |
r2 = pos; | |
if (input.substr(pos, 2) === "\\u") { | |
r3 = "\\u"; | |
pos += 2; | |
} else { | |
r3 = null; | |
if (reportFailures === 0) { | |
matchFailed("\"\\\\u\""); | |
} | |
} | |
if (r3 !== null) { | |
r5 = pos; | |
r6 = parse_HexDigit(); | |
if (r6 !== null) { | |
r7 = parse_HexDigit(); | |
if (r7 !== null) { | |
r8 = parse_HexDigit(); | |
if (r8 !== null) { | |
r9 = parse_HexDigit(); | |
if (r9 !== null) { | |
r4 = [r6, r7, r8, r9]; | |
} else { | |
r4 = null; | |
pos = r5; | |
} | |
} else { | |
r4 = null; | |
pos = r5; | |
} | |
} else { | |
r4 = null; | |
pos = r5; | |
} | |
} else { | |
r4 = null; | |
pos = r5; | |
} | |
if (r4 !== null) { | |
r0 = [r3, r4]; | |
} else { | |
r0 = null; | |
pos = r2; | |
} | |
} else { | |
r0 = null; | |
pos = r2; | |
} | |
if (r0 !== null) { | |
r0 = (function(offset, sequence) { return String.fromCharCode(parseInt("0x" + sequence.join(''))); })(r1, r4); | |
} | |
if (r0 === null) { | |
pos = r1; | |
} | |
if (r0 === null) { | |
r1 = pos; | |
r2 = pos; | |
if (input.charCodeAt(pos) === 92) { | |
r3 = "\\"; | |
pos++; | |
} else { | |
r3 = null; | |
if (reportFailures === 0) { | |
matchFailed("\"\\\\\""); | |
} | |
} | |
if (r3 !== null) { | |
if (input.charCodeAt(pos) === 34) { | |
r4 = "\""; | |
pos++; | |
} else { | |
r4 = null; | |
if (reportFailures === 0) { | |
matchFailed("\"\\\"\""); | |
} | |
} | |
if (r4 === null) { | |
if (input.charCodeAt(pos) === 39) { | |
r4 = "'"; | |
pos++; | |
} else { | |
r4 = null; | |
if (reportFailures === 0) { | |
matchFailed("\"'\""); | |
} | |
} | |
if (r4 === null) { | |
if (input.charCodeAt(pos) === 92) { | |
r4 = "\\"; | |
pos++; | |
} else { | |
r4 = null; | |
if (reportFailures === 0) { | |
matchFailed("\"\\\\\""); | |
} | |
} | |
if (r4 === null) { | |
r4 = parse_LineTerminator(); | |
} | |
} | |
} | |
if (r4 !== null) { | |
r0 = [r3, r4]; | |
} else { | |
r0 = null; | |
pos = r2; | |
} | |
} else { | |
r0 = null; | |
pos = r2; | |
} | |
if (r0 !== null) { | |
r0 = (function(offset, sequence) { return sequence; })(r1, r4); | |
} | |
if (r0 === null) { | |
pos = r1; | |
} | |
if (r0 === null) { | |
r1 = pos; | |
r2 = pos; | |
if (input.charCodeAt(pos) === 92) { | |
r3 = "\\"; | |
pos++; | |
} else { | |
r3 = null; | |
if (reportFailures === 0) { | |
matchFailed("\"\\\\\""); | |
} | |
} | |
if (r3 !== null) { | |
r4 = parse_SourceCharacter(); | |
if (r4 !== null) { | |
r0 = [r3, r4]; | |
} else { | |
r0 = null; | |
pos = r2; | |
} | |
} else { | |
r0 = null; | |
pos = r2; | |
} | |
if (r0 !== null) { | |
r0 = (function(offset, sequence) { return "\\" + sequence; })(r1, r4); | |
} | |
if (r0 === null) { | |
pos = r1; | |
} | |
} | |
} | |
} | |
} | |
} | |
} | |
} | |
} | |
} | |
} | |
depth--; | |
return r0; | |
} | |
function parse_HexDigit() { | |
depth++; | |
var r0, r1; | |
r1 = pos; | |
if (/^[0-9a-fA-F]/.test(input.charAt(pos))) { | |
r0 = input.charAt(pos); | |
pos++; | |
} else { | |
r0 = null; | |
if (reportFailures === 0) { | |
matchFailed("[0-9a-fA-F]"); | |
} | |
} | |
if (r0 !== null) { | |
r0 = (function(offset, num) { return num; })(r1, r0); | |
} | |
if (r0 === null) { | |
pos = r1; | |
} | |
depth--; | |
return r0; | |
} | |
function parse_BareStringCharacters() { | |
depth++; | |
var r0, r1, r2; | |
reportFailures++; | |
r1 = pos; | |
r2 = parse_BareStringCharacter(); | |
if (r2 !== null) { | |
r0 = []; | |
while (r2 !== null) { | |
r0.push(r2); | |
r2 = parse_BareStringCharacter(); | |
} | |
} else { | |
r0 = null; | |
} | |
if (r0 !== null) { | |
r0 = (function(offset, chars) { | |
return chars.join(""); | |
})(r1, r0); | |
} | |
if (r0 === null) { | |
pos = r1; | |
} | |
reportFailures--; | |
if (reportFailures === 0 && r0 === null) { | |
matchFailed("BareString"); | |
} | |
depth--; | |
return r0; | |
} | |
function parse_BareStringCharacter() { | |
depth++; | |
var r0, r1, r2, r3, r4; | |
r1 = pos; | |
r2 = pos; | |
r4 = pos; | |
reportFailures++; | |
r3 = parse_WhiteSpace(); | |
if (r3 === null) { | |
r3 = parse_LineTerminator(); | |
if (r3 === null) { | |
r3 = parse_SimpleCmdSep(); | |
if (r3 === null) { | |
if (input.charCodeAt(pos) === 36) { | |
r3 = "$"; | |
pos++; | |
} else { | |
r3 = null; | |
if (reportFailures === 0) { | |
matchFailed("\"$\""); | |
} | |
} | |
if (r3 === null) { | |
if (input.charCodeAt(pos) === 35) { | |
r3 = "#"; | |
pos++; | |
} else { | |
r3 = null; | |
if (reportFailures === 0) { | |
matchFailed("\"#\""); | |
} | |
} | |
if (r3 === null) { | |
if (input.charCodeAt(pos) === 34) { | |
r3 = "\""; | |
pos++; | |
} else { | |
r3 = null; | |
if (reportFailures === 0) { | |
matchFailed("\"\\\"\""); | |
} | |
} | |
if (r3 === null) { | |
if (input.charCodeAt(pos) === 92) { | |
r3 = "\\"; | |
pos++; | |
} else { | |
r3 = null; | |
if (reportFailures === 0) { | |
matchFailed("\"\\\\\""); | |
} | |
} | |
if (r3 === null) { | |
if (input.charCodeAt(pos) === 39) { | |
r3 = "'"; | |
pos++; | |
} else { | |
r3 = null; | |
if (reportFailures === 0) { | |
matchFailed("\"'\""); | |
} | |
} | |
} | |
} | |
} | |
} | |
} | |
} | |
} | |
reportFailures--; | |
if (r3 === null) { | |
r3 = ""; | |
} else { | |
r3 = null; | |
pos = r4; | |
} | |
if (r3 !== null) { | |
r4 = parse_SourceCharacter(); | |
if (r4 !== null) { | |
r0 = [r3, r4]; | |
} else { | |
r0 = null; | |
pos = r2; | |
} | |
} else { | |
r0 = null; | |
pos = r2; | |
} | |
if (r0 !== null) { | |
r0 = (function(offset, char) { return char;})(r1, r4); | |
} | |
if (r0 === null) { | |
pos = r1; | |
} | |
if (r0 === null) { | |
r1 = pos; | |
r2 = pos; | |
if (input.charCodeAt(pos) === 92) { | |
r3 = "\\"; | |
pos++; | |
} else { | |
r3 = null; | |
if (reportFailures === 0) { | |
matchFailed("\"\\\\\""); | |
} | |
} | |
if (r3 !== null) { | |
r4 = parse_SourceCharacter(); | |
if (r4 !== null) { | |
r0 = [r3, r4]; | |
} else { | |
r0 = null; | |
pos = r2; | |
} | |
} else { | |
r0 = null; | |
pos = r2; | |
} | |
if (r0 !== null) { | |
r0 = (function(offset, sequence) { return sequence; })(r1, r4); | |
} | |
if (r0 === null) { | |
pos = r1; | |
} | |
} | |
depth--; | |
return r0; | |
} | |
function parse_PipeCmdSep() { | |
depth++; | |
var r0; | |
if (/^[|&><()^};]/.test(input.charAt(pos))) { | |
r0 = input.charAt(pos); | |
pos++; | |
} else { | |
r0 = null; | |
if (reportFailures === 0) { | |
matchFailed("[|&><()^};]"); | |
} | |
} | |
if (r0 === null) { | |
if (input.substr(pos, 2) === "2>") { | |
r0 = "2>"; | |
pos += 2; | |
} else { | |
r0 = null; | |
if (reportFailures === 0) { | |
matchFailed("\"2>\""); | |
} | |
} | |
if (r0 === null) { | |
if (input.substr(pos, 3) === "2>>") { | |
r0 = "2>>"; | |
pos += 3; | |
} else { | |
r0 = null; | |
if (reportFailures === 0) { | |
matchFailed("\"2>>\""); | |
} | |
} | |
} | |
} | |
depth--; | |
return r0; | |
} | |
function parse_SimpleCmdSep() { | |
depth++; | |
var r0; | |
r0 = parse_PipeCmdSep(); | |
if (r0 === null) { | |
if (input.charCodeAt(pos) === 124) { | |
r0 = "|"; | |
pos++; | |
} else { | |
r0 = null; | |
if (reportFailures === 0) { | |
matchFailed("\"|\""); | |
} | |
} | |
} | |
depth--; | |
return r0; | |
} | |
function parse_EOC() { | |
depth++; | |
var r0; | |
r0 = parse_SimpleCmdSep(); | |
if (r0 === null) { | |
r0 = parse_WhiteSpace(); | |
if (r0 === null) { | |
r0 = parse_LineTerminator(); | |
if (r0 === null) { | |
r0 = parse_EOF(); | |
} | |
} | |
} | |
depth--; | |
return r0; | |
} | |
function parse_EOCP() { | |
depth++; | |
var r0; | |
r0 = parse_PipeCmdSep(); | |
if (r0 === null) { | |
r0 = parse_WhiteSpace(); | |
if (r0 === null) { | |
r0 = parse_LineTerminator(); | |
if (r0 === null) { | |
r0 = parse_EOF(); | |
} | |
} | |
} | |
depth--; | |
return r0; | |
} | |
function parse_EOS() { | |
depth++; | |
var r0, r1, r2, r3, r4; | |
r1 = pos; | |
r2 = parse__(); | |
if (r2 !== null) { | |
r3 = []; | |
r4 = parse_Comment(); | |
while (r4 !== null) { | |
r3.push(r4); | |
r4 = parse_Comment(); | |
} | |
if (r3 !== null) { | |
if (input.charCodeAt(pos) === 59) { | |
r4 = ";"; | |
pos++; | |
} else { | |
r4 = null; | |
if (reportFailures === 0) { | |
matchFailed("\";\""); | |
} | |
} | |
if (r4 !== null) { | |
r0 = [r2, r3, r4]; | |
} else { | |
r0 = null; | |
pos = r1; | |
} | |
} else { | |
r0 = null; | |
pos = r1; | |
} | |
} else { | |
r0 = null; | |
pos = r1; | |
} | |
if (r0 === null) { | |
r1 = pos; | |
r2 = parse__(); | |
if (r2 !== null) { | |
r3 = []; | |
r4 = parse_Comment(); | |
while (r4 !== null) { | |
r3.push(r4); | |
r4 = parse_Comment(); | |
} | |
if (r3 !== null) { | |
r4 = parse_LineTerminatorSequence(); | |
if (r4 !== null) { | |
r0 = [r2, r3, r4]; | |
} else { | |
r0 = null; | |
pos = r1; | |
} | |
} else { | |
r0 = null; | |
pos = r1; | |
} | |
} else { | |
r0 = null; | |
pos = r1; | |
} | |
} | |
depth--; | |
return r0; | |
} | |
function parse____() { | |
depth++; | |
var r0, r1; | |
r0 = []; | |
r1 = parse_WhiteSpace(); | |
if (r1 === null) { | |
r1 = parse_LineTerminatorSequence(); | |
if (r1 === null) { | |
r1 = parse_Comment(); | |
} | |
} | |
while (r1 !== null) { | |
r0.push(r1); | |
r1 = parse_WhiteSpace(); | |
if (r1 === null) { | |
r1 = parse_LineTerminatorSequence(); | |
if (r1 === null) { | |
r1 = parse_Comment(); | |
} | |
} | |
} | |
depth--; | |
return r0; | |
} | |
function parse__() { | |
depth++; | |
var r0, r1; | |
r0 = []; | |
r1 = parse_WhiteSpace(); | |
while (r1 !== null) { | |
r0.push(r1); | |
r1 = parse_WhiteSpace(); | |
} | |
depth--; | |
return r0; | |
} | |
function parse___() { | |
depth++; | |
var r0, r1; | |
r1 = parse_WhiteSpace(); | |
if (r1 !== null) { | |
r0 = []; | |
while (r1 !== null) { | |
r0.push(r1); | |
r1 = parse_WhiteSpace(); | |
} | |
} else { | |
r0 = null; | |
} | |
depth--; | |
return r0; | |
} | |
function parse_LineTerminator() { | |
depth++; | |
var r0; | |
if (/^[\n\r]/.test(input.charAt(pos))) { | |
r0 = input.charAt(pos); | |
pos++; | |
} else { | |
r0 = null; | |
if (reportFailures === 0) { | |
matchFailed("[\\n\\r]"); | |
} | |
} | |
depth--; | |
return r0; | |
} | |
function parse_LineTerminatorSequence() { | |
depth++; | |
var r0; | |
if (input.charCodeAt(pos) === 10) { | |
r0 = "\n"; | |
pos++; | |
} else { | |
r0 = null; | |
if (reportFailures === 0) { | |
matchFailed("\"\\n\""); | |
} | |
} | |
if (r0 === null) { | |
if (input.substr(pos, 2) === "\r\n") { | |
r0 = "\r\n"; | |
pos += 2; | |
} else { | |
r0 = null; | |
if (reportFailures === 0) { | |
matchFailed("\"\\r\\n\""); | |
} | |
} | |
if (r0 === null) { | |
if (input.charCodeAt(pos) === 13) { | |
r0 = "\r"; | |
pos++; | |
} else { | |
r0 = null; | |
if (reportFailures === 0) { | |
matchFailed("\"\\r\""); | |
} | |
} | |
} | |
} | |
depth--; | |
return r0; | |
} | |
function parse_WhiteSpace() { | |
depth++; | |
var r0; | |
if (/^[\t\x0B\f ]/.test(input.charAt(pos))) { | |
r0 = input.charAt(pos); | |
pos++; | |
} else { | |
r0 = null; | |
if (reportFailures === 0) { | |
matchFailed("[\\t\\x0B\\f ]"); | |
} | |
} | |
depth--; | |
return r0; | |
} | |
function parse_Comment() { | |
depth++; | |
var r0, r1, r2, r3, r4, r5, r6, r7; | |
r1 = pos; | |
if (input.charCodeAt(pos) === 35) { | |
r2 = "#"; | |
pos++; | |
} else { | |
r2 = null; | |
if (reportFailures === 0) { | |
matchFailed("\"#\""); | |
} | |
} | |
if (r2 !== null) { | |
r3 = []; | |
r5 = pos; | |
r7 = pos; | |
reportFailures++; | |
r6 = parse_LineTerminator(); | |
reportFailures--; | |
if (r6 === null) { | |
r6 = ""; | |
} else { | |
r6 = null; | |
pos = r7; | |
} | |
if (r6 !== null) { | |
if (input.length > pos) { | |
r7 = input.charAt(pos); | |
pos++; | |
} else { | |
r7 = null; | |
if (reportFailures === 0) { | |
matchFailed("any character"); | |
} | |
} | |
if (r7 !== null) { | |
r4 = [r6, r7]; | |
} else { | |
r4 = null; | |
pos = r5; | |
} | |
} else { | |
r4 = null; | |
pos = r5; | |
} | |
while (r4 !== null) { | |
r3.push(r4); | |
r5 = pos; | |
r7 = pos; | |
reportFailures++; | |
r6 = parse_LineTerminator(); | |
reportFailures--; | |
if (r6 === null) { | |
r6 = ""; | |
} else { | |
r6 = null; | |
pos = r7; | |
} | |
if (r6 !== null) { | |
if (input.length > pos) { | |
r7 = input.charAt(pos); | |
pos++; | |
} else { | |
r7 = null; | |
if (reportFailures === 0) { | |
matchFailed("any character"); | |
} | |
} | |
if (r7 !== null) { | |
r4 = [r6, r7]; | |
} else { | |
r4 = null; | |
pos = r5; | |
} | |
} else { | |
r4 = null; | |
pos = r5; | |
} | |
} | |
if (r3 !== null) { | |
r0 = [r2, r3]; | |
} else { | |
r0 = null; | |
pos = r1; | |
} | |
} else { | |
r0 = null; | |
pos = r1; | |
} | |
depth--; | |
return r0; | |
} | |
function parse_SourceCharacter() { | |
depth++; | |
var r0; | |
if (input.length > pos) { | |
r0 = input.charAt(pos); | |
pos++; | |
} else { | |
r0 = null; | |
if (reportFailures === 0) { | |
matchFailed("any character"); | |
} | |
} | |
depth--; | |
return r0; | |
} | |
function parse_EOF() { | |
depth++; | |
var r0, r1; | |
r1 = pos; | |
reportFailures++; | |
if (input.length > pos) { | |
r0 = input.charAt(pos); | |
pos++; | |
} else { | |
r0 = null; | |
if (reportFailures === 0) { | |
matchFailed("any character"); | |
} | |
} | |
reportFailures--; | |
if (r0 === null) { | |
r0 = ""; | |
} else { | |
r0 = null; | |
pos = r1; | |
} | |
depth--; | |
return r0; | |
} | |
function parse_Keyword() { | |
depth++; | |
var r0; | |
if (input.substr(pos, 8) === "function") { | |
r0 = "function"; | |
pos += 8; | |
} else { | |
r0 = null; | |
if (reportFailures === 0) { | |
matchFailed("\"function\""); | |
} | |
} | |
if (r0 === null) { | |
if (input.substr(pos, 2) === "if") { | |
r0 = "if"; | |
pos += 2; | |
} else { | |
r0 = null; | |
if (reportFailures === 0) { | |
matchFailed("\"if\""); | |
} | |
} | |
if (r0 === null) { | |
if (input.substr(pos, 4) === "then") { | |
r0 = "then"; | |
pos += 4; | |
} else { | |
r0 = null; | |
if (reportFailures === 0) { | |
matchFailed("\"then\""); | |
} | |
} | |
if (r0 === null) { | |
if (input.substr(pos, 4) === "elif") { | |
r0 = "elif"; | |
pos += 4; | |
} else { | |
r0 = null; | |
if (reportFailures === 0) { | |
matchFailed("\"elif\""); | |
} | |
} | |
if (r0 === null) { | |
if (input.substr(pos, 4) === "else") { | |
r0 = "else"; | |
pos += 4; | |
} else { | |
r0 = null; | |
if (reportFailures === 0) { | |
matchFailed("\"else\""); | |
} | |
} | |
if (r0 === null) { | |
if (input.substr(pos, 2) === "fi") { | |
r0 = "fi"; | |
pos += 2; | |
} else { | |
r0 = null; | |
if (reportFailures === 0) { | |
matchFailed("\"fi\""); | |
} | |
} | |
if (r0 === null) { | |
if (input.substr(pos, 3) === "for") { | |
r0 = "for"; | |
pos += 3; | |
} else { | |
r0 = null; | |
if (reportFailures === 0) { | |
matchFailed("\"for\""); | |
} | |
} | |
if (r0 === null) { | |
if (input.substr(pos, 2) === "in") { | |
r0 = "in"; | |
pos += 2; | |
} else { | |
r0 = null; | |
if (reportFailures === 0) { | |
matchFailed("\"in\""); | |
} | |
} | |
if (r0 === null) { | |
if (input.substr(pos, 4) === "done") { | |
r0 = "done"; | |
pos += 4; | |
} else { | |
r0 = null; | |
if (reportFailures === 0) { | |
matchFailed("\"done\""); | |
} | |
} | |
if (r0 === null) { | |
if (input.substr(pos, 2) === "do") { | |
r0 = "do"; | |
pos += 2; | |
} else { | |
r0 = null; | |
if (reportFailures === 0) { | |
matchFailed("\"do\""); | |
} | |
} | |
if (r0 === null) { | |
if (input.substr(pos, 5) === "while") { | |
r0 = "while"; | |
pos += 5; | |
} else { | |
r0 = null; | |
if (reportFailures === 0) { | |
matchFailed("\"while\""); | |
} | |
} | |
if (r0 === null) { | |
if (input.charCodeAt(pos) === 33) { | |
r0 = "!"; | |
pos++; | |
} else { | |
r0 = null; | |
if (reportFailures === 0) { | |
matchFailed("\"!\""); | |
} | |
} | |
if (r0 === null) { | |
if (input.substr(pos, 6) === "return") { | |
r0 = "return"; | |
pos += 6; | |
} else { | |
r0 = null; | |
if (reportFailures === 0) { | |
matchFailed("\"return\""); | |
} | |
} | |
} | |
} | |
} | |
} | |
} | |
} | |
} | |
} | |
} | |
} | |
} | |
} | |
depth--; | |
return r0; | |
} | |
function cleanupExpected(expected) { | |
expected.sort(); | |
var lastExpected = null; | |
var cleanExpected = []; | |
for (var i = 0; i < expected.length; i++) { | |
if (expected[i] !== lastExpected) { | |
cleanExpected.push(expected[i]); | |
lastExpected = expected[i]; | |
} | |
} | |
return cleanExpected; | |
} | |
function computeErrorPosition() { | |
/* | |
* The first idea was to use |String.split| to break the input up to the | |
* error position along newlines and derive the line and column from | |
* there. However IE's |split| implementation is so broken that it was | |
* enough to prevent it. | |
*/ | |
var line = 1; | |
var column = 1; | |
var seenCR = false; | |
for (var i = 0; i < Math.max(pos, rightmostFailuresPos); i++) { | |
var ch = input.charAt(i); | |
if (ch === "\n") { | |
if (!seenCR) { line++; } | |
column = 1; | |
seenCR = false; | |
} else if (ch === "\r" || ch === "\u2028" || ch === "\u2029") { | |
line++; | |
column = 1; | |
seenCR = true; | |
} else { | |
column++; | |
seenCR = false; | |
} | |
} | |
return { line: line, column: column }; | |
} | |
var result = parseFunctions[startRule](); | |
/* | |
* The parser is now in one of the following three states: | |
* | |
* 1. The parser successfully parsed the whole input. | |
* | |
* - |result !== null| | |
* - |pos === input.length| | |
* - |rightmostFailuresExpected| may or may not contain something | |
* | |
* 2. The parser successfully parsed only a part of the input. | |
* | |
* - |result !== null| | |
* - |pos < input.length| | |
* - |rightmostFailuresExpected| may or may not contain something | |
* | |
* 3. The parser did not successfully parse any part of the input. | |
* | |
* - |result === null| | |
* - |pos === 0| | |
* - |rightmostFailuresExpected| contains at least one failure | |
* | |
* All code following this comment (including called functions) must | |
* handle these states. | |
*/ | |
if (result === null || pos !== input.length) { | |
var offset = Math.max(pos, rightmostFailuresPos); | |
var found = offset < input.length ? input.charAt(offset) : null; | |
var errorPosition = computeErrorPosition(); | |
throw new this.SyntaxError( | |
cleanupExpected(rightmostFailuresExpected), | |
found, | |
offset, | |
errorPosition.line, | |
errorPosition.column | |
); | |
} | |
return result; | |
} | |
}; | |
/* Thrown when a parser encounters a syntax error. */ | |
result.SyntaxError = function(expected, found, offset, line, column) { | |
function buildMessage(expected, found) { | |
var expectedHumanized, foundHumanized; | |
switch (expected.length) { | |
case 0: | |
expectedHumanized = "end of input"; | |
break; | |
case 1: | |
expectedHumanized = expected[0]; | |
break; | |
default: | |
expectedHumanized = expected.slice(0, expected.length - 1).join(", ") | |
+ " or " | |
+ expected[expected.length - 1]; | |
} | |
foundHumanized = found ? quote(found) : "end of input"; | |
return "Expected " + expectedHumanized + " but " + foundHumanized + " found."; | |
} | |
this.name = "SyntaxError"; | |
this.expected = expected; | |
this.found = found; | |
this.message = buildMessage(expected, found); | |
this.offset = offset; | |
this.line = line; | |
this.column = column; | |
}; | |
subclass(result.SyntaxError, Error); | |
return result; | |
})(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment