securityos/node_modules/shell-parse/parser.js

3290 lines
89 KiB
JavaScript

module.exports = function parse(input, opts) {
// Wrap parser.parse to allow specifying the start rule
// as a shorthand option
if (!opts) {
opts = {}
}
else if (typeof opts == 'string') {
opts = { startRule: opts }
}
return parser.parse(input, opts)
}
var parser=(function() {
/*
* Generated by PEG.js 0.8.0.
*
* http://pegjs.majda.cz/
*/
function peg$subclass(child, parent) {
function ctor() { this.constructor = child; }
ctor.prototype = parent.prototype;
child.prototype = new ctor();
}
function SyntaxError(message, expected, found, offset, line, column) {
this.message = message;
this.expected = expected;
this.found = found;
this.offset = offset;
this.line = line;
this.column = column;
this.name = "SyntaxError";
}
peg$subclass(SyntaxError, Error);
function parse(input) {
var options = arguments.length > 1 ? arguments[1] : {},
peg$FAILED = {},
peg$startRuleFunctions = { script: peg$parsescript, command: peg$parsecommand, argument: peg$parseargument, continuationStart: peg$parsecontinuationStart },
peg$startRuleFunction = peg$parsescript,
peg$c0 = [],
peg$c1 = peg$FAILED,
peg$c2 = function(sections) {
var statements = []
map(sections, function (section) {
statements = statements.concat(section[1])
})
return statements
},
peg$c3 = { type: "other", description: "a list of statements" },
peg$c4 = null,
peg$c5 = function(first, rest, last) {
var statements = [first]
var prev = first
map(rest, function (spaceOpSpaceCmd, i, cmds) {
setOperator(spaceOpSpaceCmd[1], prev)
statements.push(prev = spaceOpSpaceCmd[3])
})
return statements
function setOperator(operator, command) {
while (command.next) {
command = command.next
}
command.control = operator
}
},
peg$c6 = function(statement, next) {
if (typeof next !== 'undefined' && next) {
next = next[1]
statement.control = next[0]
statement.next = next[1]
} else {
statement.control = ';'
statement.next = null
}
return statement
},
peg$c7 = "&&",
peg$c8 = { type: "literal", value: "&&", description: "\"&&\"" },
peg$c9 = "||",
peg$c10 = { type: "literal", value: "||", description: "\"||\"" },
peg$c11 = function(operator, statement) {
return [operator, statement]
},
peg$c12 = "&",
peg$c13 = { type: "literal", value: "&", description: "\"&\"" },
peg$c14 = ";",
peg$c15 = { type: "literal", value: ";", description: "\";\"" },
peg$c16 = "\n",
peg$c17 = { type: "literal", value: "\n", description: "\"\\n\"" },
peg$c18 = function(op) {
return op == '\n' ? ';' : op
},
peg$c19 = { type: "other", description: "a single command" },
peg$c20 = function(pre, name, post, pipe) {
var command = {
type: 'command',
command: name,
args: [],
redirects: [],
env: {},
control: ';',
next: null,
}
map(pre, first).concat(map(post, second)).forEach(function (token) {
if (!token || !token.type) return
switch (token.type) {
case 'moveFd':
case 'duplicateFd':
case 'redirectFd':
return command.redirects.push(token)
case 'variableAssignment':
return command.env[token.name] = token.value
default:
command.args.push(token)
}
})
if (pipe) {
command.redirects.push(pipe[1])
}
return command
},
peg$c21 = "while",
peg$c22 = { type: "literal", value: "while", description: "\"while\"" },
peg$c23 = "until",
peg$c24 = { type: "literal", value: "until", description: "\"until\"" },
peg$c25 = "do",
peg$c26 = { type: "literal", value: "do", description: "\"do\"" },
peg$c27 = "done",
peg$c28 = { type: "literal", value: "done", description: "\"done\"" },
peg$c29 = function(kind, test, body) {
return {
type: kind + '-loop',
test: test,
body: body
}
},
peg$c30 = "if",
peg$c31 = { type: "literal", value: "if", description: "\"if\"" },
peg$c32 = "then",
peg$c33 = { type: "literal", value: "then", description: "\"then\"" },
peg$c34 = "else",
peg$c35 = { type: "literal", value: "else", description: "\"else\"" },
peg$c36 = "fi",
peg$c37 = { type: "literal", value: "fi", description: "\"fi\"" },
peg$c38 = function(test, body, elifBlocks, elseBody) {
return {
type: 'ifElse',
test: test,
body: body,
elifBlocks: elifBlocks.length ? elifBlocks : null,
elseBody: elseBody ? elseBody[1] : null,
}
},
peg$c39 = "elif",
peg$c40 = { type: "literal", value: "elif", description: "\"elif\"" },
peg$c41 = function(test, body) {
return {
type: 'ifElse',
test: test,
body: body
}
},
peg$c42 = function(test) {
return test
},
peg$c43 = "=",
peg$c44 = { type: "literal", value: "=", description: "\"=\"" },
peg$c45 = function(name, value) {
return {type: 'variableAssignment', name: name, value: value}
},
peg$c46 = { type: "other", description: "command name" },
peg$c47 = void 0,
peg$c48 = function(name) {
return name
},
peg$c49 = "[",
peg$c50 = { type: "literal", value: "[", description: "\"[\"" },
peg$c51 = "[[",
peg$c52 = { type: "literal", value: "[[", description: "\"[[\"" },
peg$c53 = { type: "other", description: "command argument" },
peg$c54 = function(pieces) {
return flattenConcatenation(pieces)
},
peg$c55 = function(cs) { return literal(cs) },
peg$c56 = "\\",
peg$c57 = { type: "literal", value: "\\", description: "\"\\\\\"" },
peg$c58 = function(chr) { return chr },
peg$c59 = { type: "any", description: "any character" },
peg$c60 = /^[$"';&<>\n()[*?|` ]/,
peg$c61 = { type: "class", value: "[$\"';&<>\\n()[*?|` ]", description: "[$\"';&<>\\n()[*?|` ]" },
peg$c62 = "*",
peg$c63 = { type: "literal", value: "*", description: "\"*\"" },
peg$c64 = "?",
peg$c65 = { type: "literal", value: "?", description: "\"?\"" },
peg$c66 = function() {
return {
type: 'glob',
value: text()
}
},
peg$c67 = "-",
peg$c68 = { type: "literal", value: "-", description: "\"-\"" },
peg$c69 = "]",
peg$c70 = { type: "literal", value: "]", description: "\"]\"" },
peg$c71 = "$",
peg$c72 = { type: "literal", value: "$", description: "\"$\"" },
peg$c73 = "{",
peg$c74 = { type: "literal", value: "{", description: "\"{\"" },
peg$c75 = "}",
peg$c76 = { type: "literal", value: "}", description: "\"}\"" },
peg$c77 = "'",
peg$c78 = { type: "literal", value: "'", description: "\"'\"" },
peg$c79 = /^[^']/,
peg$c80 = { type: "class", value: "[^']", description: "[^']" },
peg$c81 = function(inner) { return literal(inner) },
peg$c82 = "\"",
peg$c83 = { type: "literal", value: "\"", description: "\"\\\"\"" },
peg$c84 = function(contents) {
var pieces = contents.map(function (it) {
return isArray(it) ? literal(it) : it
})
return flattenConcatenation(pieces)
},
peg$c85 = "\\\\",
peg$c86 = { type: "literal", value: "\\\\", description: "\"\\\\\\\\\"" },
peg$c87 = function() { return '\\' },
peg$c88 = "`",
peg$c89 = { type: "literal", value: "`", description: "\"`\"" },
peg$c90 = function(name) {
return {type: 'variable', name: name}
},
peg$c91 = /^[a-zA-Z0-9_]/,
peg$c92 = { type: "class", value: "[a-zA-Z0-9_]", description: "[a-zA-Z0-9_]" },
peg$c93 = function() { return text() },
peg$c94 = "${",
peg$c95 = { type: "literal", value: "${", description: "\"${\"" },
peg$c96 = /^[^}]/,
peg$c97 = { type: "class", value: "[^}]", description: "[^}]" },
peg$c98 = function(expr) {
return {
type: 'variableSubstitution',
expression: join(expr), // TODO subParser
}
},
peg$c99 = "$(",
peg$c100 = { type: "literal", value: "$(", description: "\"$(\"" },
peg$c101 = ")",
peg$c102 = { type: "literal", value: ")", description: "\")\"" },
peg$c103 = function(commands) {
return {
type: 'commandSubstitution',
commands: commands
}
},
peg$c104 = function(input) {
return { type: 'commandSubstitution', commands: parse(input.join('')) }
},
peg$c105 = "\\`",
peg$c106 = { type: "literal", value: "\\`", description: "\"\\\\`\"" },
peg$c107 = function() { return '`' },
peg$c108 = /^[<>]/,
peg$c109 = { type: "class", value: "[<>]", description: "[<>]" },
peg$c110 = "(",
peg$c111 = { type: "literal", value: "(", description: "\"(\"" },
peg$c112 = function(rw, commands) {
return {
type: 'processSubstitution',
readWrite: rw,
commands: commands,
}
},
peg$c113 = "|",
peg$c114 = { type: "literal", value: "|", description: "\"|\"" },
peg$c115 = function(command) {
return {type: 'pipe', command: command}
},
peg$c116 = "<&",
peg$c117 = { type: "literal", value: "<&", description: "\"<&\"" },
peg$c118 = ">&",
peg$c119 = { type: "literal", value: ">&", description: "\">&\"" },
peg$c120 = function(fd, op, dest) {
if (fd == null) fd = op[0] == '<' ? 0 : 1;
return {
type: 'moveFd',
fd: fd,
op: op,
dest: dest
}
},
peg$c121 = function(src, op, dest) {
if (src == null) src = op[0] == '<' ? 0 : 1;
return {
type: 'duplicateFd',
srcFd: src,
op: op,
destFd: dest,
}
},
peg$c122 = function(fd, op, filename) {
if (fd == null) fd = op[0] == '<' ? 0 : 1;
return {
type: 'redirectFd',
fd: fd,
op: op,
filename: filename
}
},
peg$c123 = "<",
peg$c124 = { type: "literal", value: "<", description: "\"<\"" },
peg$c125 = ">",
peg$c126 = { type: "literal", value: ">", description: "\">\"" },
peg$c127 = ">|",
peg$c128 = { type: "literal", value: ">|", description: "\">|\"" },
peg$c129 = "&>",
peg$c130 = { type: "literal", value: "&>", description: "\"&>\"" },
peg$c131 = ">>",
peg$c132 = { type: "literal", value: ">>", description: "\">>\"" },
peg$c133 = "&>>",
peg$c134 = { type: "literal", value: "&>>", description: "\"&>>\"" },
peg$c135 = /^[0-9]/,
peg$c136 = { type: "class", value: "[0-9]", description: "[0-9]" },
peg$c137 = function(digits) { return parseInt(join(digits), 10) },
peg$c138 = " ",
peg$c139 = { type: "literal", value: " ", description: "\" \"" },
peg$c140 = "\t",
peg$c141 = { type: "literal", value: "\t", description: "\"\\t\"" },
peg$c142 = "for",
peg$c143 = { type: "literal", value: "for", description: "\"for\"" },
peg$c144 = "case",
peg$c145 = { type: "literal", value: "case", description: "\"case\"" },
peg$c146 = "esac",
peg$c147 = { type: "literal", value: "esac", description: "\"esac\"" },
peg$currPos = 0,
peg$reportedPos = 0,
peg$cachedPos = 0,
peg$cachedPosDetails = { line: 1, column: 1, seenCR: false },
peg$maxFailPos = 0,
peg$maxFailExpected = [],
peg$silentFails = 0,
peg$result;
if ("startRule" in options) {
if (!(options.startRule in peg$startRuleFunctions)) {
throw new Error("Can't start parsing from rule \"" + options.startRule + "\".");
}
peg$startRuleFunction = peg$startRuleFunctions[options.startRule];
}
function text() {
return input.substring(peg$reportedPos, peg$currPos);
}
function offset() {
return peg$reportedPos;
}
function line() {
return peg$computePosDetails(peg$reportedPos).line;
}
function column() {
return peg$computePosDetails(peg$reportedPos).column;
}
function expected(description) {
throw peg$buildException(
null,
[{ type: "other", description: description }],
peg$reportedPos
);
}
function error(message) {
throw peg$buildException(message, null, peg$reportedPos);
}
function peg$computePosDetails(pos) {
function advance(details, startPos, endPos) {
var p, ch;
for (p = startPos; p < endPos; p++) {
ch = input.charAt(p);
if (ch === "\n") {
if (!details.seenCR) { details.line++; }
details.column = 1;
details.seenCR = false;
} else if (ch === "\r" || ch === "\u2028" || ch === "\u2029") {
details.line++;
details.column = 1;
details.seenCR = true;
} else {
details.column++;
details.seenCR = false;
}
}
}
if (peg$cachedPos !== pos) {
if (peg$cachedPos > pos) {
peg$cachedPos = 0;
peg$cachedPosDetails = { line: 1, column: 1, seenCR: false };
}
advance(peg$cachedPosDetails, peg$cachedPos, pos);
peg$cachedPos = pos;
}
return peg$cachedPosDetails;
}
function peg$fail(expected) {
if (peg$currPos < peg$maxFailPos) { return; }
if (peg$currPos > peg$maxFailPos) {
peg$maxFailPos = peg$currPos;
peg$maxFailExpected = [];
}
peg$maxFailExpected.push(expected);
}
function peg$buildException(message, expected, pos) {
function cleanupExpected(expected) {
var i = 1;
expected.sort(function(a, b) {
if (a.description < b.description) {
return -1;
} else if (a.description > b.description) {
return 1;
} else {
return 0;
}
});
while (i < expected.length) {
if (expected[i - 1] === expected[i]) {
expected.splice(i, 1);
} else {
i++;
}
}
}
function buildMessage(expected, found) {
function stringEscape(s) {
function hex(ch) { return ch.charCodeAt(0).toString(16).toUpperCase(); }
return s
.replace(/\\/g, '\\\\')
.replace(/"/g, '\\"')
.replace(/\x08/g, '\\b')
.replace(/\t/g, '\\t')
.replace(/\n/g, '\\n')
.replace(/\f/g, '\\f')
.replace(/\r/g, '\\r')
.replace(/[\x00-\x07\x0B\x0E\x0F]/g, function(ch) { return '\\x0' + hex(ch); })
.replace(/[\x10-\x1F\x80-\xFF]/g, function(ch) { return '\\x' + hex(ch); })
.replace(/[\u0180-\u0FFF]/g, function(ch) { return '\\u0' + hex(ch); })
.replace(/[\u1080-\uFFFF]/g, function(ch) { return '\\u' + hex(ch); });
}
var expectedDescs = new Array(expected.length),
expectedDesc, foundDesc, i;
for (i = 0; i < expected.length; i++) {
expectedDescs[i] = expected[i].description;
}
expectedDesc = expected.length > 1
? expectedDescs.slice(0, -1).join(", ")
+ " or "
+ expectedDescs[expected.length - 1]
: expectedDescs[0];
foundDesc = found ? "\"" + stringEscape(found) + "\"" : "end of input";
return "Expected " + expectedDesc + " but " + foundDesc + " found.";
}
var posDetails = peg$computePosDetails(pos),
found = pos < input.length ? input.charAt(pos) : null;
if (expected !== null) {
cleanupExpected(expected);
}
return new SyntaxError(
message !== null ? message : buildMessage(expected, found),
expected,
found,
pos,
posDetails.line,
posDetails.column
);
}
function peg$parsescript() {
var s0, s1, s2, s3, s4, s5, s6;
s0 = peg$currPos;
s1 = [];
s2 = peg$currPos;
s3 = [];
s4 = peg$parsespaceNL();
while (s4 !== peg$FAILED) {
s3.push(s4);
s4 = peg$parsespaceNL();
}
if (s3 !== peg$FAILED) {
s4 = peg$parsestatementList();
if (s4 !== peg$FAILED) {
s5 = [];
s6 = peg$parsespaceNL();
while (s6 !== peg$FAILED) {
s5.push(s6);
s6 = peg$parsespaceNL();
}
if (s5 !== peg$FAILED) {
s3 = [s3, s4, s5];
s2 = s3;
} else {
peg$currPos = s2;
s2 = peg$c1;
}
} else {
peg$currPos = s2;
s2 = peg$c1;
}
} else {
peg$currPos = s2;
s2 = peg$c1;
}
if (s2 !== peg$FAILED) {
while (s2 !== peg$FAILED) {
s1.push(s2);
s2 = peg$currPos;
s3 = [];
s4 = peg$parsespaceNL();
while (s4 !== peg$FAILED) {
s3.push(s4);
s4 = peg$parsespaceNL();
}
if (s3 !== peg$FAILED) {
s4 = peg$parsestatementList();
if (s4 !== peg$FAILED) {
s5 = [];
s6 = peg$parsespaceNL();
while (s6 !== peg$FAILED) {
s5.push(s6);
s6 = peg$parsespaceNL();
}
if (s5 !== peg$FAILED) {
s3 = [s3, s4, s5];
s2 = s3;
} else {
peg$currPos = s2;
s2 = peg$c1;
}
} else {
peg$currPos = s2;
s2 = peg$c1;
}
} else {
peg$currPos = s2;
s2 = peg$c1;
}
}
} else {
s1 = peg$c1;
}
if (s1 !== peg$FAILED) {
peg$reportedPos = s0;
s1 = peg$c2(s1);
}
s0 = s1;
return s0;
}
function peg$parsestatementList() {
var s0, s1, s2, s3, s4, s5, s6, s7;
peg$silentFails++;
s0 = peg$currPos;
s1 = peg$parsestatement();
if (s1 !== peg$FAILED) {
s2 = [];
s3 = peg$currPos;
s4 = [];
s5 = peg$parsespace();
while (s5 !== peg$FAILED) {
s4.push(s5);
s5 = peg$parsespace();
}
if (s4 !== peg$FAILED) {
s5 = peg$parsecontrolOperator();
if (s5 !== peg$FAILED) {
s6 = [];
s7 = peg$parsespaceNL();
while (s7 !== peg$FAILED) {
s6.push(s7);
s7 = peg$parsespaceNL();
}
if (s6 !== peg$FAILED) {
s7 = peg$parsestatement();
if (s7 !== peg$FAILED) {
s4 = [s4, s5, s6, s7];
s3 = s4;
} else {
peg$currPos = s3;
s3 = peg$c1;
}
} else {
peg$currPos = s3;
s3 = peg$c1;
}
} else {
peg$currPos = s3;
s3 = peg$c1;
}
} else {
peg$currPos = s3;
s3 = peg$c1;
}
while (s3 !== peg$FAILED) {
s2.push(s3);
s3 = peg$currPos;
s4 = [];
s5 = peg$parsespace();
while (s5 !== peg$FAILED) {
s4.push(s5);
s5 = peg$parsespace();
}
if (s4 !== peg$FAILED) {
s5 = peg$parsecontrolOperator();
if (s5 !== peg$FAILED) {
s6 = [];
s7 = peg$parsespaceNL();
while (s7 !== peg$FAILED) {
s6.push(s7);
s7 = peg$parsespaceNL();
}
if (s6 !== peg$FAILED) {
s7 = peg$parsestatement();
if (s7 !== peg$FAILED) {
s4 = [s4, s5, s6, s7];
s3 = s4;
} else {
peg$currPos = s3;
s3 = peg$c1;
}
} else {
peg$currPos = s3;
s3 = peg$c1;
}
} else {
peg$currPos = s3;
s3 = peg$c1;
}
} else {
peg$currPos = s3;
s3 = peg$c1;
}
}
if (s2 !== peg$FAILED) {
s3 = peg$currPos;
s4 = [];
s5 = peg$parsespace();
while (s5 !== peg$FAILED) {
s4.push(s5);
s5 = peg$parsespace();
}
if (s4 !== peg$FAILED) {
s5 = peg$parsecontrolOperator();
if (s5 !== peg$FAILED) {
s4 = [s4, s5];
s3 = s4;
} else {
peg$currPos = s3;
s3 = peg$c1;
}
} else {
peg$currPos = s3;
s3 = peg$c1;
}
if (s3 === peg$FAILED) {
s3 = peg$c4;
}
if (s3 !== peg$FAILED) {
peg$reportedPos = s0;
s1 = peg$c5(s1, s2, s3);
s0 = s1;
} else {
peg$currPos = s0;
s0 = peg$c1;
}
} else {
peg$currPos = s0;
s0 = peg$c1;
}
} else {
peg$currPos = s0;
s0 = peg$c1;
}
peg$silentFails--;
if (s0 === peg$FAILED) {
s1 = peg$FAILED;
if (peg$silentFails === 0) { peg$fail(peg$c3); }
}
return s0;
}
function peg$parsestatement() {
var s0, s1, s2, s3, s4;
s0 = peg$currPos;
s1 = peg$parsecommand();
if (s1 === peg$FAILED) {
s1 = peg$parsevariableAssignment();
if (s1 === peg$FAILED) {
s1 = peg$parseconditionalLoop();
if (s1 === peg$FAILED) {
s1 = peg$parseifBlock();
}
}
}
if (s1 !== peg$FAILED) {
s2 = peg$currPos;
s3 = [];
s4 = peg$parsespace();
while (s4 !== peg$FAILED) {
s3.push(s4);
s4 = peg$parsespace();
}
if (s3 !== peg$FAILED) {
s4 = peg$parsechainedStatement();
if (s4 !== peg$FAILED) {
s3 = [s3, s4];
s2 = s3;
} else {
peg$currPos = s2;
s2 = peg$c1;
}
} else {
peg$currPos = s2;
s2 = peg$c1;
}
if (s2 === peg$FAILED) {
s2 = peg$c4;
}
if (s2 !== peg$FAILED) {
peg$reportedPos = s0;
s1 = peg$c6(s1, s2);
s0 = s1;
} else {
peg$currPos = s0;
s0 = peg$c1;
}
} else {
peg$currPos = s0;
s0 = peg$c1;
}
return s0;
}
function peg$parsechainedStatement() {
var s0, s1, s2, s3;
s0 = peg$currPos;
if (input.substr(peg$currPos, 2) === peg$c7) {
s1 = peg$c7;
peg$currPos += 2;
} else {
s1 = peg$FAILED;
if (peg$silentFails === 0) { peg$fail(peg$c8); }
}
if (s1 === peg$FAILED) {
if (input.substr(peg$currPos, 2) === peg$c9) {
s1 = peg$c9;
peg$currPos += 2;
} else {
s1 = peg$FAILED;
if (peg$silentFails === 0) { peg$fail(peg$c10); }
}
}
if (s1 !== peg$FAILED) {
s2 = [];
s3 = peg$parsespaceNL();
while (s3 !== peg$FAILED) {
s2.push(s3);
s3 = peg$parsespaceNL();
}
if (s2 !== peg$FAILED) {
s3 = peg$parsestatement();
if (s3 !== peg$FAILED) {
peg$reportedPos = s0;
s1 = peg$c11(s1, s3);
s0 = s1;
} else {
peg$currPos = s0;
s0 = peg$c1;
}
} else {
peg$currPos = s0;
s0 = peg$c1;
}
} else {
peg$currPos = s0;
s0 = peg$c1;
}
return s0;
}
function peg$parsecontrolOperator() {
var s0, s1;
s0 = peg$currPos;
if (input.charCodeAt(peg$currPos) === 38) {
s1 = peg$c12;
peg$currPos++;
} else {
s1 = peg$FAILED;
if (peg$silentFails === 0) { peg$fail(peg$c13); }
}
if (s1 === peg$FAILED) {
if (input.charCodeAt(peg$currPos) === 59) {
s1 = peg$c14;
peg$currPos++;
} else {
s1 = peg$FAILED;
if (peg$silentFails === 0) { peg$fail(peg$c15); }
}
if (s1 === peg$FAILED) {
if (input.charCodeAt(peg$currPos) === 10) {
s1 = peg$c16;
peg$currPos++;
} else {
s1 = peg$FAILED;
if (peg$silentFails === 0) { peg$fail(peg$c17); }
}
}
}
if (s1 !== peg$FAILED) {
peg$reportedPos = s0;
s1 = peg$c18(s1);
}
s0 = s1;
return s0;
}
function peg$parsecommand() {
var s0, s1, s2, s3, s4, s5, s6;
peg$silentFails++;
s0 = peg$currPos;
s1 = [];
s2 = peg$currPos;
s3 = peg$parsevariableAssignment();
if (s3 === peg$FAILED) {
s3 = peg$parseredirect();
}
if (s3 !== peg$FAILED) {
s4 = [];
s5 = peg$parsespace();
if (s5 !== peg$FAILED) {
while (s5 !== peg$FAILED) {
s4.push(s5);
s5 = peg$parsespace();
}
} else {
s4 = peg$c1;
}
if (s4 !== peg$FAILED) {
s3 = [s3, s4];
s2 = s3;
} else {
peg$currPos = s2;
s2 = peg$c1;
}
} else {
peg$currPos = s2;
s2 = peg$c1;
}
while (s2 !== peg$FAILED) {
s1.push(s2);
s2 = peg$currPos;
s3 = peg$parsevariableAssignment();
if (s3 === peg$FAILED) {
s3 = peg$parseredirect();
}
if (s3 !== peg$FAILED) {
s4 = [];
s5 = peg$parsespace();
if (s5 !== peg$FAILED) {
while (s5 !== peg$FAILED) {
s4.push(s5);
s5 = peg$parsespace();
}
} else {
s4 = peg$c1;
}
if (s4 !== peg$FAILED) {
s3 = [s3, s4];
s2 = s3;
} else {
peg$currPos = s2;
s2 = peg$c1;
}
} else {
peg$currPos = s2;
s2 = peg$c1;
}
}
if (s1 !== peg$FAILED) {
s2 = peg$parsecommandName();
if (s2 === peg$FAILED) {
s2 = peg$parsebuiltinCommandName();
}
if (s2 !== peg$FAILED) {
s3 = [];
s4 = peg$currPos;
s5 = [];
s6 = peg$parsespace();
if (s6 !== peg$FAILED) {
while (s6 !== peg$FAILED) {
s5.push(s6);
s6 = peg$parsespace();
}
} else {
s5 = peg$c1;
}
if (s5 !== peg$FAILED) {
s6 = peg$parseredirect();
if (s6 === peg$FAILED) {
s6 = peg$parseargument();
}
if (s6 !== peg$FAILED) {
s5 = [s5, s6];
s4 = s5;
} else {
peg$currPos = s4;
s4 = peg$c1;
}
} else {
peg$currPos = s4;
s4 = peg$c1;
}
while (s4 !== peg$FAILED) {
s3.push(s4);
s4 = peg$currPos;
s5 = [];
s6 = peg$parsespace();
if (s6 !== peg$FAILED) {
while (s6 !== peg$FAILED) {
s5.push(s6);
s6 = peg$parsespace();
}
} else {
s5 = peg$c1;
}
if (s5 !== peg$FAILED) {
s6 = peg$parseredirect();
if (s6 === peg$FAILED) {
s6 = peg$parseargument();
}
if (s6 !== peg$FAILED) {
s5 = [s5, s6];
s4 = s5;
} else {
peg$currPos = s4;
s4 = peg$c1;
}
} else {
peg$currPos = s4;
s4 = peg$c1;
}
}
if (s3 !== peg$FAILED) {
s4 = peg$currPos;
s5 = [];
s6 = peg$parsespace();
while (s6 !== peg$FAILED) {
s5.push(s6);
s6 = peg$parsespace();
}
if (s5 !== peg$FAILED) {
s6 = peg$parsepipe();
if (s6 !== peg$FAILED) {
s5 = [s5, s6];
s4 = s5;
} else {
peg$currPos = s4;
s4 = peg$c1;
}
} else {
peg$currPos = s4;
s4 = peg$c1;
}
if (s4 === peg$FAILED) {
s4 = peg$c4;
}
if (s4 !== peg$FAILED) {
peg$reportedPos = s0;
s1 = peg$c20(s1, s2, s3, s4);
s0 = s1;
} else {
peg$currPos = s0;
s0 = peg$c1;
}
} else {
peg$currPos = s0;
s0 = peg$c1;
}
} else {
peg$currPos = s0;
s0 = peg$c1;
}
} else {
peg$currPos = s0;
s0 = peg$c1;
}
peg$silentFails--;
if (s0 === peg$FAILED) {
s1 = peg$FAILED;
if (peg$silentFails === 0) { peg$fail(peg$c19); }
}
return s0;
}
function peg$parseconditionalLoop() {
var s0, s1, s2, s3, s4, s5, s6, s7, s8;
s0 = peg$currPos;
if (input.substr(peg$currPos, 5) === peg$c21) {
s1 = peg$c21;
peg$currPos += 5;
} else {
s1 = peg$FAILED;
if (peg$silentFails === 0) { peg$fail(peg$c22); }
}
if (s1 === peg$FAILED) {
if (input.substr(peg$currPos, 5) === peg$c23) {
s1 = peg$c23;
peg$currPos += 5;
} else {
s1 = peg$FAILED;
if (peg$silentFails === 0) { peg$fail(peg$c24); }
}
}
if (s1 !== peg$FAILED) {
s2 = [];
s3 = peg$parsespaceNL();
if (s3 !== peg$FAILED) {
while (s3 !== peg$FAILED) {
s2.push(s3);
s3 = peg$parsespaceNL();
}
} else {
s2 = peg$c1;
}
if (s2 !== peg$FAILED) {
s3 = peg$parsecondition();
if (s3 !== peg$FAILED) {
s4 = [];
s5 = peg$parsespaceNL();
while (s5 !== peg$FAILED) {
s4.push(s5);
s5 = peg$parsespaceNL();
}
if (s4 !== peg$FAILED) {
if (input.substr(peg$currPos, 2) === peg$c25) {
s5 = peg$c25;
peg$currPos += 2;
} else {
s5 = peg$FAILED;
if (peg$silentFails === 0) { peg$fail(peg$c26); }
}
if (s5 !== peg$FAILED) {
s6 = peg$parsespaceNL();
if (s6 !== peg$FAILED) {
s7 = peg$parsescript();
if (s7 !== peg$FAILED) {
if (input.substr(peg$currPos, 4) === peg$c27) {
s8 = peg$c27;
peg$currPos += 4;
} else {
s8 = peg$FAILED;
if (peg$silentFails === 0) { peg$fail(peg$c28); }
}
if (s8 !== peg$FAILED) {
peg$reportedPos = s0;
s1 = peg$c29(s1, s3, s7);
s0 = s1;
} else {
peg$currPos = s0;
s0 = peg$c1;
}
} else {
peg$currPos = s0;
s0 = peg$c1;
}
} else {
peg$currPos = s0;
s0 = peg$c1;
}
} else {
peg$currPos = s0;
s0 = peg$c1;
}
} else {
peg$currPos = s0;
s0 = peg$c1;
}
} else {
peg$currPos = s0;
s0 = peg$c1;
}
} else {
peg$currPos = s0;
s0 = peg$c1;
}
} else {
peg$currPos = s0;
s0 = peg$c1;
}
return s0;
}
function peg$parseifBlock() {
var s0, s1, s2, s3, s4, s5, s6, s7, s8, s9, s10;
s0 = peg$currPos;
if (input.substr(peg$currPos, 2) === peg$c30) {
s1 = peg$c30;
peg$currPos += 2;
} else {
s1 = peg$FAILED;
if (peg$silentFails === 0) { peg$fail(peg$c31); }
}
if (s1 !== peg$FAILED) {
s2 = [];
s3 = peg$parsespaceNL();
if (s3 !== peg$FAILED) {
while (s3 !== peg$FAILED) {
s2.push(s3);
s3 = peg$parsespaceNL();
}
} else {
s2 = peg$c1;
}
if (s2 !== peg$FAILED) {
s3 = peg$parsescript();
if (s3 !== peg$FAILED) {
if (input.substr(peg$currPos, 4) === peg$c32) {
s4 = peg$c32;
peg$currPos += 4;
} else {
s4 = peg$FAILED;
if (peg$silentFails === 0) { peg$fail(peg$c33); }
}
if (s4 !== peg$FAILED) {
s5 = [];
s6 = peg$parsespaceNL();
if (s6 !== peg$FAILED) {
while (s6 !== peg$FAILED) {
s5.push(s6);
s6 = peg$parsespaceNL();
}
} else {
s5 = peg$c1;
}
if (s5 !== peg$FAILED) {
s6 = peg$parsescript();
if (s6 !== peg$FAILED) {
s7 = [];
s8 = peg$parseelifBlock();
while (s8 !== peg$FAILED) {
s7.push(s8);
s8 = peg$parseelifBlock();
}
if (s7 !== peg$FAILED) {
s8 = peg$currPos;
if (input.substr(peg$currPos, 4) === peg$c34) {
s9 = peg$c34;
peg$currPos += 4;
} else {
s9 = peg$FAILED;
if (peg$silentFails === 0) { peg$fail(peg$c35); }
}
if (s9 !== peg$FAILED) {
s10 = peg$parsescript();
if (s10 !== peg$FAILED) {
s9 = [s9, s10];
s8 = s9;
} else {
peg$currPos = s8;
s8 = peg$c1;
}
} else {
peg$currPos = s8;
s8 = peg$c1;
}
if (s8 === peg$FAILED) {
s8 = peg$c4;
}
if (s8 !== peg$FAILED) {
if (input.substr(peg$currPos, 2) === peg$c36) {
s9 = peg$c36;
peg$currPos += 2;
} else {
s9 = peg$FAILED;
if (peg$silentFails === 0) { peg$fail(peg$c37); }
}
if (s9 !== peg$FAILED) {
peg$reportedPos = s0;
s1 = peg$c38(s3, s6, s7, s8);
s0 = s1;
} else {
peg$currPos = s0;
s0 = peg$c1;
}
} else {
peg$currPos = s0;
s0 = peg$c1;
}
} else {
peg$currPos = s0;
s0 = peg$c1;
}
} else {
peg$currPos = s0;
s0 = peg$c1;
}
} else {
peg$currPos = s0;
s0 = peg$c1;
}
} else {
peg$currPos = s0;
s0 = peg$c1;
}
} else {
peg$currPos = s0;
s0 = peg$c1;
}
} else {
peg$currPos = s0;
s0 = peg$c1;
}
} else {
peg$currPos = s0;
s0 = peg$c1;
}
return s0;
}
function peg$parseelifBlock() {
var s0, s1, s2, s3, s4, s5, s6;
s0 = peg$currPos;
if (input.substr(peg$currPos, 4) === peg$c39) {
s1 = peg$c39;
peg$currPos += 4;
} else {
s1 = peg$FAILED;
if (peg$silentFails === 0) { peg$fail(peg$c40); }
}
if (s1 !== peg$FAILED) {
s2 = [];
s3 = peg$parsespaceNL();
if (s3 !== peg$FAILED) {
while (s3 !== peg$FAILED) {
s2.push(s3);
s3 = peg$parsespaceNL();
}
} else {
s2 = peg$c1;
}
if (s2 !== peg$FAILED) {
s3 = peg$parsecondition();
if (s3 !== peg$FAILED) {
if (input.substr(peg$currPos, 4) === peg$c32) {
s4 = peg$c32;
peg$currPos += 4;
} else {
s4 = peg$FAILED;
if (peg$silentFails === 0) { peg$fail(peg$c33); }
}
if (s4 !== peg$FAILED) {
s5 = [];
s6 = peg$parsespaceNL();
if (s6 !== peg$FAILED) {
while (s6 !== peg$FAILED) {
s5.push(s6);
s6 = peg$parsespaceNL();
}
} else {
s5 = peg$c1;
}
if (s5 !== peg$FAILED) {
s6 = peg$parsescript();
if (s6 !== peg$FAILED) {
peg$reportedPos = s0;
s1 = peg$c41(s3, s6);
s0 = s1;
} else {
peg$currPos = s0;
s0 = peg$c1;
}
} else {
peg$currPos = s0;
s0 = peg$c1;
}
} else {
peg$currPos = s0;
s0 = peg$c1;
}
} else {
peg$currPos = s0;
s0 = peg$c1;
}
} else {
peg$currPos = s0;
s0 = peg$c1;
}
} else {
peg$currPos = s0;
s0 = peg$c1;
}
return s0;
}
function peg$parsecondition() {
var s0, s1;
s0 = peg$currPos;
s1 = peg$parsescript();
if (s1 !== peg$FAILED) {
peg$reportedPos = s0;
s1 = peg$c42(s1);
}
s0 = s1;
return s0;
}
function peg$parsevariableAssignment() {
var s0, s1, s2, s3;
s0 = peg$currPos;
s1 = peg$parsewritableVariableName();
if (s1 !== peg$FAILED) {
if (input.charCodeAt(peg$currPos) === 61) {
s2 = peg$c43;
peg$currPos++;
} else {
s2 = peg$FAILED;
if (peg$silentFails === 0) { peg$fail(peg$c44); }
}
if (s2 !== peg$FAILED) {
s3 = peg$parseargument();
if (s3 !== peg$FAILED) {
peg$reportedPos = s0;
s1 = peg$c45(s1, s3);
s0 = s1;
} else {
peg$currPos = s0;
s0 = peg$c1;
}
} else {
peg$currPos = s0;
s0 = peg$c1;
}
} else {
peg$currPos = s0;
s0 = peg$c1;
}
return s0;
}
function peg$parsecommandName() {
var s0, s1, s2, s3, s4;
peg$silentFails++;
s0 = peg$currPos;
s1 = peg$currPos;
peg$silentFails++;
s2 = peg$parseredirect();
peg$silentFails--;
if (s2 === peg$FAILED) {
s1 = peg$c47;
} else {
peg$currPos = s1;
s1 = peg$c1;
}
if (s1 !== peg$FAILED) {
s2 = peg$currPos;
peg$silentFails++;
s3 = peg$parsekeyword();
peg$silentFails--;
if (s3 === peg$FAILED) {
s2 = peg$c47;
} else {
peg$currPos = s2;
s2 = peg$c1;
}
if (s2 !== peg$FAILED) {
s3 = peg$currPos;
peg$silentFails++;
s4 = peg$parsevariableAssignment();
peg$silentFails--;
if (s4 === peg$FAILED) {
s3 = peg$c47;
} else {
peg$currPos = s3;
s3 = peg$c1;
}
if (s3 !== peg$FAILED) {
s4 = peg$parseconcatenation();
if (s4 === peg$FAILED) {
s4 = peg$parsebuiltinCommandName();
}
if (s4 !== peg$FAILED) {
peg$reportedPos = s0;
s1 = peg$c48(s4);
s0 = s1;
} else {
peg$currPos = s0;
s0 = peg$c1;
}
} else {
peg$currPos = s0;
s0 = peg$c1;
}
} else {
peg$currPos = s0;
s0 = peg$c1;
}
} else {
peg$currPos = s0;
s0 = peg$c1;
}
peg$silentFails--;
if (s0 === peg$FAILED) {
s1 = peg$FAILED;
if (peg$silentFails === 0) { peg$fail(peg$c46); }
}
return s0;
}
function peg$parsebuiltinCommandName() {
var s0;
if (input.charCodeAt(peg$currPos) === 91) {
s0 = peg$c49;
peg$currPos++;
} else {
s0 = peg$FAILED;
if (peg$silentFails === 0) { peg$fail(peg$c50); }
}
if (s0 === peg$FAILED) {
if (input.substr(peg$currPos, 2) === peg$c51) {
s0 = peg$c51;
peg$currPos += 2;
} else {
s0 = peg$FAILED;
if (peg$silentFails === 0) { peg$fail(peg$c52); }
}
}
return s0;
}
function peg$parseargument() {
var s0, s1;
peg$silentFails++;
s0 = peg$parsecommandName();
if (s0 === peg$FAILED) {
s0 = peg$parseprocessSubstitution();
}
peg$silentFails--;
if (s0 === peg$FAILED) {
s1 = peg$FAILED;
if (peg$silentFails === 0) { peg$fail(peg$c53); }
}
return s0;
}
function peg$parseconcatenation() {
var s0, s1, s2;
s0 = peg$currPos;
s1 = [];
s2 = peg$parseglob();
if (s2 === peg$FAILED) {
s2 = peg$parsebareword();
if (s2 === peg$FAILED) {
s2 = peg$parseenvironmentVariable();
if (s2 === peg$FAILED) {
s2 = peg$parsevariableSubstitution();
if (s2 === peg$FAILED) {
s2 = peg$parsecommandSubstitution();
if (s2 === peg$FAILED) {
s2 = peg$parsesingleQuote();
if (s2 === peg$FAILED) {
s2 = peg$parsedoubleQuote();
}
}
}
}
}
}
if (s2 !== peg$FAILED) {
while (s2 !== peg$FAILED) {
s1.push(s2);
s2 = peg$parseglob();
if (s2 === peg$FAILED) {
s2 = peg$parsebareword();
if (s2 === peg$FAILED) {
s2 = peg$parseenvironmentVariable();
if (s2 === peg$FAILED) {
s2 = peg$parsevariableSubstitution();
if (s2 === peg$FAILED) {
s2 = peg$parsecommandSubstitution();
if (s2 === peg$FAILED) {
s2 = peg$parsesingleQuote();
if (s2 === peg$FAILED) {
s2 = peg$parsedoubleQuote();
}
}
}
}
}
}
}
} else {
s1 = peg$c1;
}
if (s1 !== peg$FAILED) {
peg$reportedPos = s0;
s1 = peg$c54(s1);
}
s0 = s1;
return s0;
}
function peg$parsebareword() {
var s0, s1, s2;
s0 = peg$currPos;
s1 = [];
s2 = peg$parsebarewordChar();
if (s2 !== peg$FAILED) {
while (s2 !== peg$FAILED) {
s1.push(s2);
s2 = peg$parsebarewordChar();
}
} else {
s1 = peg$c1;
}
if (s1 !== peg$FAILED) {
peg$reportedPos = s0;
s1 = peg$c55(s1);
}
s0 = s1;
return s0;
}
function peg$parsebarewordChar() {
var s0, s1, s2;
s0 = peg$currPos;
if (input.charCodeAt(peg$currPos) === 92) {
s1 = peg$c56;
peg$currPos++;
} else {
s1 = peg$FAILED;
if (peg$silentFails === 0) { peg$fail(peg$c57); }
}
if (s1 !== peg$FAILED) {
s2 = peg$parsebarewordMeta();
if (s2 !== peg$FAILED) {
peg$reportedPos = s0;
s1 = peg$c58(s2);
s0 = s1;
} else {
peg$currPos = s0;
s0 = peg$c1;
}
} else {
peg$currPos = s0;
s0 = peg$c1;
}
if (s0 === peg$FAILED) {
s0 = peg$currPos;
s1 = peg$currPos;
peg$silentFails++;
s2 = peg$parsebarewordMeta();
peg$silentFails--;
if (s2 === peg$FAILED) {
s1 = peg$c47;
} else {
peg$currPos = s1;
s1 = peg$c1;
}
if (s1 !== peg$FAILED) {
if (input.length > peg$currPos) {
s2 = input.charAt(peg$currPos);
peg$currPos++;
} else {
s2 = peg$FAILED;
if (peg$silentFails === 0) { peg$fail(peg$c59); }
}
if (s2 !== peg$FAILED) {
peg$reportedPos = s0;
s1 = peg$c58(s2);
s0 = s1;
} else {
peg$currPos = s0;
s0 = peg$c1;
}
} else {
peg$currPos = s0;
s0 = peg$c1;
}
}
return s0;
}
function peg$parsebarewordMeta() {
var s0;
if (peg$c60.test(input.charAt(peg$currPos))) {
s0 = input.charAt(peg$currPos);
peg$currPos++;
} else {
s0 = peg$FAILED;
if (peg$silentFails === 0) { peg$fail(peg$c61); }
}
return s0;
}
function peg$parseglob() {
var s0, s1, s2, s3, s4;
s0 = peg$currPos;
s1 = [];
s2 = peg$parsebarewordChar();
while (s2 !== peg$FAILED) {
s1.push(s2);
s2 = peg$parsebarewordChar();
}
if (s1 !== peg$FAILED) {
s2 = [];
if (input.charCodeAt(peg$currPos) === 42) {
s3 = peg$c62;
peg$currPos++;
} else {
s3 = peg$FAILED;
if (peg$silentFails === 0) { peg$fail(peg$c63); }
}
if (s3 === peg$FAILED) {
if (input.charCodeAt(peg$currPos) === 63) {
s3 = peg$c64;
peg$currPos++;
} else {
s3 = peg$FAILED;
if (peg$silentFails === 0) { peg$fail(peg$c65); }
}
if (s3 === peg$FAILED) {
s3 = peg$parsecharacterRange();
if (s3 === peg$FAILED) {
s3 = peg$parsebraceExpansion();
}
}
}
if (s3 !== peg$FAILED) {
while (s3 !== peg$FAILED) {
s2.push(s3);
if (input.charCodeAt(peg$currPos) === 42) {
s3 = peg$c62;
peg$currPos++;
} else {
s3 = peg$FAILED;
if (peg$silentFails === 0) { peg$fail(peg$c63); }
}
if (s3 === peg$FAILED) {
if (input.charCodeAt(peg$currPos) === 63) {
s3 = peg$c64;
peg$currPos++;
} else {
s3 = peg$FAILED;
if (peg$silentFails === 0) { peg$fail(peg$c65); }
}
if (s3 === peg$FAILED) {
s3 = peg$parsecharacterRange();
if (s3 === peg$FAILED) {
s3 = peg$parsebraceExpansion();
}
}
}
}
} else {
s2 = peg$c1;
}
if (s2 !== peg$FAILED) {
s3 = [];
s4 = peg$parsebarewordChar();
while (s4 !== peg$FAILED) {
s3.push(s4);
s4 = peg$parsebarewordChar();
}
if (s3 !== peg$FAILED) {
peg$reportedPos = s0;
s1 = peg$c66();
s0 = s1;
} else {
peg$currPos = s0;
s0 = peg$c1;
}
} else {
peg$currPos = s0;
s0 = peg$c1;
}
} else {
peg$currPos = s0;
s0 = peg$c1;
}
return s0;
}
function peg$parsecharacterRange() {
var s0, s1, s2, s3, s4, s5, s6, s7, s8;
s0 = peg$currPos;
s1 = peg$currPos;
if (input.charCodeAt(peg$currPos) === 91) {
s2 = peg$c49;
peg$currPos++;
} else {
s2 = peg$FAILED;
if (peg$silentFails === 0) { peg$fail(peg$c50); }
}
if (s2 !== peg$FAILED) {
s3 = peg$currPos;
peg$silentFails++;
if (input.charCodeAt(peg$currPos) === 45) {
s4 = peg$c67;
peg$currPos++;
} else {
s4 = peg$FAILED;
if (peg$silentFails === 0) { peg$fail(peg$c68); }
}
peg$silentFails--;
if (s4 === peg$FAILED) {
s3 = peg$c47;
} else {
peg$currPos = s3;
s3 = peg$c1;
}
if (s3 !== peg$FAILED) {
if (input.length > peg$currPos) {
s4 = input.charAt(peg$currPos);
peg$currPos++;
} else {
s4 = peg$FAILED;
if (peg$silentFails === 0) { peg$fail(peg$c59); }
}
if (s4 !== peg$FAILED) {
if (input.charCodeAt(peg$currPos) === 45) {
s5 = peg$c67;
peg$currPos++;
} else {
s5 = peg$FAILED;
if (peg$silentFails === 0) { peg$fail(peg$c68); }
}
if (s5 !== peg$FAILED) {
s6 = peg$currPos;
peg$silentFails++;
if (input.charCodeAt(peg$currPos) === 45) {
s7 = peg$c67;
peg$currPos++;
} else {
s7 = peg$FAILED;
if (peg$silentFails === 0) { peg$fail(peg$c68); }
}
peg$silentFails--;
if (s7 === peg$FAILED) {
s6 = peg$c47;
} else {
peg$currPos = s6;
s6 = peg$c1;
}
if (s6 !== peg$FAILED) {
if (input.length > peg$currPos) {
s7 = input.charAt(peg$currPos);
peg$currPos++;
} else {
s7 = peg$FAILED;
if (peg$silentFails === 0) { peg$fail(peg$c59); }
}
if (s7 !== peg$FAILED) {
if (input.charCodeAt(peg$currPos) === 93) {
s8 = peg$c69;
peg$currPos++;
} else {
s8 = peg$FAILED;
if (peg$silentFails === 0) { peg$fail(peg$c70); }
}
if (s8 !== peg$FAILED) {
s2 = [s2, s3, s4, s5, s6, s7, s8];
s1 = s2;
} else {
peg$currPos = s1;
s1 = peg$c1;
}
} else {
peg$currPos = s1;
s1 = peg$c1;
}
} else {
peg$currPos = s1;
s1 = peg$c1;
}
} else {
peg$currPos = s1;
s1 = peg$c1;
}
} else {
peg$currPos = s1;
s1 = peg$c1;
}
} else {
peg$currPos = s1;
s1 = peg$c1;
}
} else {
peg$currPos = s1;
s1 = peg$c1;
}
if (s1 !== peg$FAILED) {
s1 = input.substring(s0, peg$currPos);
}
s0 = s1;
return s0;
}
function peg$parsebraceExpansion() {
var s0, s1, s2, s3, s4;
s0 = peg$currPos;
s1 = peg$currPos;
if (input.length > peg$currPos) {
s2 = input.charAt(peg$currPos);
peg$currPos++;
} else {
s2 = peg$FAILED;
if (peg$silentFails === 0) { peg$fail(peg$c59); }
}
if (s2 === peg$FAILED) {
s2 = peg$c4;
}
if (s2 !== peg$FAILED) {
s3 = peg$currPos;
peg$silentFails++;
if (input.charCodeAt(peg$currPos) === 36) {
s4 = peg$c71;
peg$currPos++;
} else {
s4 = peg$FAILED;
if (peg$silentFails === 0) { peg$fail(peg$c72); }
}
peg$silentFails--;
if (s4 === peg$FAILED) {
s3 = peg$c47;
} else {
peg$currPos = s3;
s3 = peg$c1;
}
if (s3 !== peg$FAILED) {
s2 = [s2, s3];
s1 = s2;
} else {
peg$currPos = s1;
s1 = peg$c1;
}
} else {
peg$currPos = s1;
s1 = peg$c1;
}
if (s1 !== peg$FAILED) {
if (input.charCodeAt(peg$currPos) === 123) {
s2 = peg$c73;
peg$currPos++;
} else {
s2 = peg$FAILED;
if (peg$silentFails === 0) { peg$fail(peg$c74); }
}
if (s2 !== peg$FAILED) {
s3 = [];
s4 = peg$parsebarewordChar();
if (s4 !== peg$FAILED) {
while (s4 !== peg$FAILED) {
s3.push(s4);
s4 = peg$parsebarewordChar();
}
} else {
s3 = peg$c1;
}
if (s3 !== peg$FAILED) {
if (input.charCodeAt(peg$currPos) === 125) {
s4 = peg$c75;
peg$currPos++;
} else {
s4 = peg$FAILED;
if (peg$silentFails === 0) { peg$fail(peg$c76); }
}
if (s4 !== peg$FAILED) {
s1 = [s1, s2, s3, s4];
s0 = s1;
} else {
peg$currPos = s0;
s0 = peg$c1;
}
} else {
peg$currPos = s0;
s0 = peg$c1;
}
} else {
peg$currPos = s0;
s0 = peg$c1;
}
} else {
peg$currPos = s0;
s0 = peg$c1;
}
return s0;
}
function peg$parsesingleQuote() {
var s0, s1, s2, s3, s4;
s0 = peg$currPos;
if (input.charCodeAt(peg$currPos) === 39) {
s1 = peg$c77;
peg$currPos++;
} else {
s1 = peg$FAILED;
if (peg$silentFails === 0) { peg$fail(peg$c78); }
}
if (s1 !== peg$FAILED) {
s2 = peg$currPos;
s3 = [];
if (peg$c79.test(input.charAt(peg$currPos))) {
s4 = input.charAt(peg$currPos);
peg$currPos++;
} else {
s4 = peg$FAILED;
if (peg$silentFails === 0) { peg$fail(peg$c80); }
}
while (s4 !== peg$FAILED) {
s3.push(s4);
if (peg$c79.test(input.charAt(peg$currPos))) {
s4 = input.charAt(peg$currPos);
peg$currPos++;
} else {
s4 = peg$FAILED;
if (peg$silentFails === 0) { peg$fail(peg$c80); }
}
}
if (s3 !== peg$FAILED) {
s3 = input.substring(s2, peg$currPos);
}
s2 = s3;
if (s2 !== peg$FAILED) {
if (input.charCodeAt(peg$currPos) === 39) {
s3 = peg$c77;
peg$currPos++;
} else {
s3 = peg$FAILED;
if (peg$silentFails === 0) { peg$fail(peg$c78); }
}
if (s3 !== peg$FAILED) {
peg$reportedPos = s0;
s1 = peg$c81(s2);
s0 = s1;
} else {
peg$currPos = s0;
s0 = peg$c1;
}
} else {
peg$currPos = s0;
s0 = peg$c1;
}
} else {
peg$currPos = s0;
s0 = peg$c1;
}
return s0;
}
function peg$parsedoubleQuote() {
var s0, s1, s2, s3, s4;
s0 = peg$currPos;
if (input.charCodeAt(peg$currPos) === 34) {
s1 = peg$c82;
peg$currPos++;
} else {
s1 = peg$FAILED;
if (peg$silentFails === 0) { peg$fail(peg$c83); }
}
if (s1 !== peg$FAILED) {
s2 = [];
s3 = peg$parseexpandsInQuotes();
if (s3 === peg$FAILED) {
s3 = [];
s4 = peg$parsedoubleQuoteChar();
if (s4 !== peg$FAILED) {
while (s4 !== peg$FAILED) {
s3.push(s4);
s4 = peg$parsedoubleQuoteChar();
}
} else {
s3 = peg$c1;
}
}
while (s3 !== peg$FAILED) {
s2.push(s3);
s3 = peg$parseexpandsInQuotes();
if (s3 === peg$FAILED) {
s3 = [];
s4 = peg$parsedoubleQuoteChar();
if (s4 !== peg$FAILED) {
while (s4 !== peg$FAILED) {
s3.push(s4);
s4 = peg$parsedoubleQuoteChar();
}
} else {
s3 = peg$c1;
}
}
}
if (s2 !== peg$FAILED) {
if (input.charCodeAt(peg$currPos) === 34) {
s3 = peg$c82;
peg$currPos++;
} else {
s3 = peg$FAILED;
if (peg$silentFails === 0) { peg$fail(peg$c83); }
}
if (s3 !== peg$FAILED) {
peg$reportedPos = s0;
s1 = peg$c84(s2);
s0 = s1;
} else {
peg$currPos = s0;
s0 = peg$c1;
}
} else {
peg$currPos = s0;
s0 = peg$c1;
}
} else {
peg$currPos = s0;
s0 = peg$c1;
}
return s0;
}
function peg$parsedoubleQuoteChar() {
var s0, s1, s2;
s0 = peg$currPos;
if (input.charCodeAt(peg$currPos) === 92) {
s1 = peg$c56;
peg$currPos++;
} else {
s1 = peg$FAILED;
if (peg$silentFails === 0) { peg$fail(peg$c57); }
}
if (s1 !== peg$FAILED) {
s2 = peg$parsedoubleQuoteMeta();
if (s2 !== peg$FAILED) {
peg$reportedPos = s0;
s1 = peg$c58(s2);
s0 = s1;
} else {
peg$currPos = s0;
s0 = peg$c1;
}
} else {
peg$currPos = s0;
s0 = peg$c1;
}
if (s0 === peg$FAILED) {
s0 = peg$currPos;
if (input.substr(peg$currPos, 2) === peg$c85) {
s1 = peg$c85;
peg$currPos += 2;
} else {
s1 = peg$FAILED;
if (peg$silentFails === 0) { peg$fail(peg$c86); }
}
if (s1 !== peg$FAILED) {
peg$reportedPos = s0;
s1 = peg$c87();
}
s0 = s1;
if (s0 === peg$FAILED) {
s0 = peg$currPos;
s1 = peg$currPos;
peg$silentFails++;
s2 = peg$parsedoubleQuoteMeta();
peg$silentFails--;
if (s2 === peg$FAILED) {
s1 = peg$c47;
} else {
peg$currPos = s1;
s1 = peg$c1;
}
if (s1 !== peg$FAILED) {
if (input.length > peg$currPos) {
s2 = input.charAt(peg$currPos);
peg$currPos++;
} else {
s2 = peg$FAILED;
if (peg$silentFails === 0) { peg$fail(peg$c59); }
}
if (s2 !== peg$FAILED) {
peg$reportedPos = s0;
s1 = peg$c58(s2);
s0 = s1;
} else {
peg$currPos = s0;
s0 = peg$c1;
}
} else {
peg$currPos = s0;
s0 = peg$c1;
}
}
}
return s0;
}
function peg$parsedoubleQuoteMeta() {
var s0;
if (input.charCodeAt(peg$currPos) === 34) {
s0 = peg$c82;
peg$currPos++;
} else {
s0 = peg$FAILED;
if (peg$silentFails === 0) { peg$fail(peg$c83); }
}
if (s0 === peg$FAILED) {
if (input.charCodeAt(peg$currPos) === 36) {
s0 = peg$c71;
peg$currPos++;
} else {
s0 = peg$FAILED;
if (peg$silentFails === 0) { peg$fail(peg$c72); }
}
if (s0 === peg$FAILED) {
if (input.charCodeAt(peg$currPos) === 96) {
s0 = peg$c88;
peg$currPos++;
} else {
s0 = peg$FAILED;
if (peg$silentFails === 0) { peg$fail(peg$c89); }
}
}
}
return s0;
}
function peg$parseexpandsInQuotes() {
var s0;
s0 = peg$parsecommandSubstitution();
if (s0 === peg$FAILED) {
s0 = peg$parseenvironmentVariable();
if (s0 === peg$FAILED) {
s0 = peg$parsevariableSubstitution();
}
}
return s0;
}
function peg$parseenvironmentVariable() {
var s0, s1, s2;
s0 = peg$currPos;
if (input.charCodeAt(peg$currPos) === 36) {
s1 = peg$c71;
peg$currPos++;
} else {
s1 = peg$FAILED;
if (peg$silentFails === 0) { peg$fail(peg$c72); }
}
if (s1 !== peg$FAILED) {
s2 = peg$parsereadableVariableName();
if (s2 !== peg$FAILED) {
peg$reportedPos = s0;
s1 = peg$c90(s2);
s0 = s1;
} else {
peg$currPos = s0;
s0 = peg$c1;
}
} else {
peg$currPos = s0;
s0 = peg$c1;
}
return s0;
}
function peg$parsewritableVariableName() {
var s0, s1, s2;
s0 = peg$currPos;
s1 = [];
if (peg$c91.test(input.charAt(peg$currPos))) {
s2 = input.charAt(peg$currPos);
peg$currPos++;
} else {
s2 = peg$FAILED;
if (peg$silentFails === 0) { peg$fail(peg$c92); }
}
if (s2 !== peg$FAILED) {
while (s2 !== peg$FAILED) {
s1.push(s2);
if (peg$c91.test(input.charAt(peg$currPos))) {
s2 = input.charAt(peg$currPos);
peg$currPos++;
} else {
s2 = peg$FAILED;
if (peg$silentFails === 0) { peg$fail(peg$c92); }
}
}
} else {
s1 = peg$c1;
}
if (s1 !== peg$FAILED) {
peg$reportedPos = s0;
s1 = peg$c93();
}
s0 = s1;
return s0;
}
function peg$parsereadableVariableName() {
var s0;
s0 = peg$parsewritableVariableName();
if (s0 === peg$FAILED) {
if (input.charCodeAt(peg$currPos) === 63) {
s0 = peg$c64;
peg$currPos++;
} else {
s0 = peg$FAILED;
if (peg$silentFails === 0) { peg$fail(peg$c65); }
}
}
return s0;
}
function peg$parsevariableSubstitution() {
var s0, s1, s2, s3;
s0 = peg$currPos;
if (input.substr(peg$currPos, 2) === peg$c94) {
s1 = peg$c94;
peg$currPos += 2;
} else {
s1 = peg$FAILED;
if (peg$silentFails === 0) { peg$fail(peg$c95); }
}
if (s1 !== peg$FAILED) {
s2 = [];
if (peg$c96.test(input.charAt(peg$currPos))) {
s3 = input.charAt(peg$currPos);
peg$currPos++;
} else {
s3 = peg$FAILED;
if (peg$silentFails === 0) { peg$fail(peg$c97); }
}
while (s3 !== peg$FAILED) {
s2.push(s3);
if (peg$c96.test(input.charAt(peg$currPos))) {
s3 = input.charAt(peg$currPos);
peg$currPos++;
} else {
s3 = peg$FAILED;
if (peg$silentFails === 0) { peg$fail(peg$c97); }
}
}
if (s2 !== peg$FAILED) {
if (input.charCodeAt(peg$currPos) === 125) {
s3 = peg$c75;
peg$currPos++;
} else {
s3 = peg$FAILED;
if (peg$silentFails === 0) { peg$fail(peg$c76); }
}
if (s3 !== peg$FAILED) {
peg$reportedPos = s0;
s1 = peg$c98(s2);
s0 = s1;
} else {
peg$currPos = s0;
s0 = peg$c1;
}
} else {
peg$currPos = s0;
s0 = peg$c1;
}
} else {
peg$currPos = s0;
s0 = peg$c1;
}
return s0;
}
function peg$parsecommandSubstitution() {
var s0;
s0 = peg$parseparenCommandSubstitution();
if (s0 === peg$FAILED) {
s0 = peg$parsebackQuote();
}
return s0;
}
function peg$parseparenCommandSubstitution() {
var s0, s1, s2, s3;
s0 = peg$currPos;
if (input.substr(peg$currPos, 2) === peg$c99) {
s1 = peg$c99;
peg$currPos += 2;
} else {
s1 = peg$FAILED;
if (peg$silentFails === 0) { peg$fail(peg$c100); }
}
if (s1 !== peg$FAILED) {
s2 = peg$parsestatementList();
if (s2 !== peg$FAILED) {
if (input.charCodeAt(peg$currPos) === 41) {
s3 = peg$c101;
peg$currPos++;
} else {
s3 = peg$FAILED;
if (peg$silentFails === 0) { peg$fail(peg$c102); }
}
if (s3 !== peg$FAILED) {
peg$reportedPos = s0;
s1 = peg$c103(s2);
s0 = s1;
} else {
peg$currPos = s0;
s0 = peg$c1;
}
} else {
peg$currPos = s0;
s0 = peg$c1;
}
} else {
peg$currPos = s0;
s0 = peg$c1;
}
return s0;
}
function peg$parsebackQuote() {
var s0, s1, s2, s3;
s0 = peg$currPos;
if (input.charCodeAt(peg$currPos) === 96) {
s1 = peg$c88;
peg$currPos++;
} else {
s1 = peg$FAILED;
if (peg$silentFails === 0) { peg$fail(peg$c89); }
}
if (s1 !== peg$FAILED) {
s2 = [];
s3 = peg$parsebackQuoteChar();
if (s3 !== peg$FAILED) {
while (s3 !== peg$FAILED) {
s2.push(s3);
s3 = peg$parsebackQuoteChar();
}
} else {
s2 = peg$c1;
}
if (s2 !== peg$FAILED) {
if (input.charCodeAt(peg$currPos) === 96) {
s3 = peg$c88;
peg$currPos++;
} else {
s3 = peg$FAILED;
if (peg$silentFails === 0) { peg$fail(peg$c89); }
}
if (s3 !== peg$FAILED) {
peg$reportedPos = s0;
s1 = peg$c104(s2);
s0 = s1;
} else {
peg$currPos = s0;
s0 = peg$c1;
}
} else {
peg$currPos = s0;
s0 = peg$c1;
}
} else {
peg$currPos = s0;
s0 = peg$c1;
}
return s0;
}
function peg$parsebackQuoteChar() {
var s0, s1, s2;
s0 = peg$currPos;
if (input.substr(peg$currPos, 2) === peg$c105) {
s1 = peg$c105;
peg$currPos += 2;
} else {
s1 = peg$FAILED;
if (peg$silentFails === 0) { peg$fail(peg$c106); }
}
if (s1 !== peg$FAILED) {
peg$reportedPos = s0;
s1 = peg$c107();
}
s0 = s1;
if (s0 === peg$FAILED) {
s0 = peg$currPos;
if (input.substr(peg$currPos, 2) === peg$c85) {
s1 = peg$c85;
peg$currPos += 2;
} else {
s1 = peg$FAILED;
if (peg$silentFails === 0) { peg$fail(peg$c86); }
}
if (s1 !== peg$FAILED) {
peg$reportedPos = s0;
s1 = peg$c87();
}
s0 = s1;
if (s0 === peg$FAILED) {
s0 = peg$currPos;
s1 = peg$currPos;
peg$silentFails++;
if (input.charCodeAt(peg$currPos) === 96) {
s2 = peg$c88;
peg$currPos++;
} else {
s2 = peg$FAILED;
if (peg$silentFails === 0) { peg$fail(peg$c89); }
}
peg$silentFails--;
if (s2 === peg$FAILED) {
s1 = peg$c47;
} else {
peg$currPos = s1;
s1 = peg$c1;
}
if (s1 !== peg$FAILED) {
if (input.length > peg$currPos) {
s2 = input.charAt(peg$currPos);
peg$currPos++;
} else {
s2 = peg$FAILED;
if (peg$silentFails === 0) { peg$fail(peg$c59); }
}
if (s2 !== peg$FAILED) {
peg$reportedPos = s0;
s1 = peg$c58(s2);
s0 = s1;
} else {
peg$currPos = s0;
s0 = peg$c1;
}
} else {
peg$currPos = s0;
s0 = peg$c1;
}
}
}
return s0;
}
function peg$parseprocessSubstitution() {
var s0, s1, s2, s3, s4;
s0 = peg$currPos;
if (peg$c108.test(input.charAt(peg$currPos))) {
s1 = input.charAt(peg$currPos);
peg$currPos++;
} else {
s1 = peg$FAILED;
if (peg$silentFails === 0) { peg$fail(peg$c109); }
}
if (s1 !== peg$FAILED) {
if (input.charCodeAt(peg$currPos) === 40) {
s2 = peg$c110;
peg$currPos++;
} else {
s2 = peg$FAILED;
if (peg$silentFails === 0) { peg$fail(peg$c111); }
}
if (s2 !== peg$FAILED) {
s3 = peg$parsestatementList();
if (s3 !== peg$FAILED) {
if (input.charCodeAt(peg$currPos) === 41) {
s4 = peg$c101;
peg$currPos++;
} else {
s4 = peg$FAILED;
if (peg$silentFails === 0) { peg$fail(peg$c102); }
}
if (s4 !== peg$FAILED) {
peg$reportedPos = s0;
s1 = peg$c112(s1, s3);
s0 = s1;
} else {
peg$currPos = s0;
s0 = peg$c1;
}
} else {
peg$currPos = s0;
s0 = peg$c1;
}
} else {
peg$currPos = s0;
s0 = peg$c1;
}
} else {
peg$currPos = s0;
s0 = peg$c1;
}
return s0;
}
function peg$parseredirect() {
var s0;
s0 = peg$parsemoveFd();
if (s0 === peg$FAILED) {
s0 = peg$parseduplicateFd();
if (s0 === peg$FAILED) {
s0 = peg$parseredirectFd();
}
}
return s0;
}
function peg$parsepipe() {
var s0, s1, s2, s3;
s0 = peg$currPos;
if (input.charCodeAt(peg$currPos) === 124) {
s1 = peg$c113;
peg$currPos++;
} else {
s1 = peg$FAILED;
if (peg$silentFails === 0) { peg$fail(peg$c114); }
}
if (s1 !== peg$FAILED) {
s2 = [];
s3 = peg$parsespaceNL();
while (s3 !== peg$FAILED) {
s2.push(s3);
s3 = peg$parsespaceNL();
}
if (s2 !== peg$FAILED) {
s3 = peg$parsecommand();
if (s3 !== peg$FAILED) {
peg$reportedPos = s0;
s1 = peg$c115(s3);
s0 = s1;
} else {
peg$currPos = s0;
s0 = peg$c1;
}
} else {
peg$currPos = s0;
s0 = peg$c1;
}
} else {
peg$currPos = s0;
s0 = peg$c1;
}
return s0;
}
function peg$parsemoveFd() {
var s0, s1, s2, s3, s4;
s0 = peg$currPos;
s1 = peg$parsefd();
if (s1 === peg$FAILED) {
s1 = peg$c4;
}
if (s1 !== peg$FAILED) {
if (input.substr(peg$currPos, 2) === peg$c116) {
s2 = peg$c116;
peg$currPos += 2;
} else {
s2 = peg$FAILED;
if (peg$silentFails === 0) { peg$fail(peg$c117); }
}
if (s2 === peg$FAILED) {
if (input.substr(peg$currPos, 2) === peg$c118) {
s2 = peg$c118;
peg$currPos += 2;
} else {
s2 = peg$FAILED;
if (peg$silentFails === 0) { peg$fail(peg$c119); }
}
}
if (s2 !== peg$FAILED) {
s3 = peg$parsefd();
if (s3 !== peg$FAILED) {
if (input.charCodeAt(peg$currPos) === 45) {
s4 = peg$c67;
peg$currPos++;
} else {
s4 = peg$FAILED;
if (peg$silentFails === 0) { peg$fail(peg$c68); }
}
if (s4 !== peg$FAILED) {
peg$reportedPos = s0;
s1 = peg$c120(s1, s2, s3);
s0 = s1;
} else {
peg$currPos = s0;
s0 = peg$c1;
}
} else {
peg$currPos = s0;
s0 = peg$c1;
}
} else {
peg$currPos = s0;
s0 = peg$c1;
}
} else {
peg$currPos = s0;
s0 = peg$c1;
}
return s0;
}
function peg$parseduplicateFd() {
var s0, s1, s2, s3, s4;
s0 = peg$currPos;
s1 = peg$parsefd();
if (s1 === peg$FAILED) {
s1 = peg$c4;
}
if (s1 !== peg$FAILED) {
if (input.substr(peg$currPos, 2) === peg$c116) {
s2 = peg$c116;
peg$currPos += 2;
} else {
s2 = peg$FAILED;
if (peg$silentFails === 0) { peg$fail(peg$c117); }
}
if (s2 === peg$FAILED) {
if (input.substr(peg$currPos, 2) === peg$c118) {
s2 = peg$c118;
peg$currPos += 2;
} else {
s2 = peg$FAILED;
if (peg$silentFails === 0) { peg$fail(peg$c119); }
}
}
if (s2 !== peg$FAILED) {
s3 = [];
s4 = peg$parsespace();
while (s4 !== peg$FAILED) {
s3.push(s4);
s4 = peg$parsespace();
}
if (s3 !== peg$FAILED) {
s4 = peg$parsefd();
if (s4 !== peg$FAILED) {
peg$reportedPos = s0;
s1 = peg$c121(s1, s2, s4);
s0 = s1;
} else {
peg$currPos = s0;
s0 = peg$c1;
}
} else {
peg$currPos = s0;
s0 = peg$c1;
}
} else {
peg$currPos = s0;
s0 = peg$c1;
}
} else {
peg$currPos = s0;
s0 = peg$c1;
}
return s0;
}
function peg$parseredirectFd() {
var s0, s1, s2, s3, s4;
s0 = peg$currPos;
s1 = peg$parsefd();
if (s1 === peg$FAILED) {
s1 = peg$c4;
}
if (s1 !== peg$FAILED) {
s2 = peg$parseredirectionOperator();
if (s2 !== peg$FAILED) {
s3 = [];
s4 = peg$parsespace();
while (s4 !== peg$FAILED) {
s3.push(s4);
s4 = peg$parsespace();
}
if (s3 !== peg$FAILED) {
s4 = peg$parseargument();
if (s4 !== peg$FAILED) {
peg$reportedPos = s0;
s1 = peg$c122(s1, s2, s4);
s0 = s1;
} else {
peg$currPos = s0;
s0 = peg$c1;
}
} else {
peg$currPos = s0;
s0 = peg$c1;
}
} else {
peg$currPos = s0;
s0 = peg$c1;
}
} else {
peg$currPos = s0;
s0 = peg$c1;
}
return s0;
}
function peg$parseredirectionOperator() {
var s0;
if (input.charCodeAt(peg$currPos) === 60) {
s0 = peg$c123;
peg$currPos++;
} else {
s0 = peg$FAILED;
if (peg$silentFails === 0) { peg$fail(peg$c124); }
}
if (s0 === peg$FAILED) {
if (input.charCodeAt(peg$currPos) === 62) {
s0 = peg$c125;
peg$currPos++;
} else {
s0 = peg$FAILED;
if (peg$silentFails === 0) { peg$fail(peg$c126); }
}
if (s0 === peg$FAILED) {
if (input.substr(peg$currPos, 2) === peg$c127) {
s0 = peg$c127;
peg$currPos += 2;
} else {
s0 = peg$FAILED;
if (peg$silentFails === 0) { peg$fail(peg$c128); }
}
if (s0 === peg$FAILED) {
if (input.substr(peg$currPos, 2) === peg$c129) {
s0 = peg$c129;
peg$currPos += 2;
} else {
s0 = peg$FAILED;
if (peg$silentFails === 0) { peg$fail(peg$c130); }
}
if (s0 === peg$FAILED) {
if (input.substr(peg$currPos, 2) === peg$c131) {
s0 = peg$c131;
peg$currPos += 2;
} else {
s0 = peg$FAILED;
if (peg$silentFails === 0) { peg$fail(peg$c132); }
}
if (s0 === peg$FAILED) {
if (input.substr(peg$currPos, 3) === peg$c133) {
s0 = peg$c133;
peg$currPos += 3;
} else {
s0 = peg$FAILED;
if (peg$silentFails === 0) { peg$fail(peg$c134); }
}
}
}
}
}
}
return s0;
}
function peg$parsefd() {
var s0, s1, s2;
s0 = peg$currPos;
s1 = [];
if (peg$c135.test(input.charAt(peg$currPos))) {
s2 = input.charAt(peg$currPos);
peg$currPos++;
} else {
s2 = peg$FAILED;
if (peg$silentFails === 0) { peg$fail(peg$c136); }
}
if (s2 !== peg$FAILED) {
while (s2 !== peg$FAILED) {
s1.push(s2);
if (peg$c135.test(input.charAt(peg$currPos))) {
s2 = input.charAt(peg$currPos);
peg$currPos++;
} else {
s2 = peg$FAILED;
if (peg$silentFails === 0) { peg$fail(peg$c136); }
}
}
} else {
s1 = peg$c1;
}
if (s1 !== peg$FAILED) {
peg$reportedPos = s0;
s1 = peg$c137(s1);
}
s0 = s1;
return s0;
}
function peg$parsespace() {
var s0;
if (input.charCodeAt(peg$currPos) === 32) {
s0 = peg$c138;
peg$currPos++;
} else {
s0 = peg$FAILED;
if (peg$silentFails === 0) { peg$fail(peg$c139); }
}
if (s0 === peg$FAILED) {
if (input.charCodeAt(peg$currPos) === 9) {
s0 = peg$c140;
peg$currPos++;
} else {
s0 = peg$FAILED;
if (peg$silentFails === 0) { peg$fail(peg$c141); }
}
}
return s0;
}
function peg$parsespaceNL() {
var s0;
s0 = peg$parsespace();
if (s0 === peg$FAILED) {
if (input.charCodeAt(peg$currPos) === 10) {
s0 = peg$c16;
peg$currPos++;
} else {
s0 = peg$FAILED;
if (peg$silentFails === 0) { peg$fail(peg$c17); }
}
}
return s0;
}
function peg$parsekeyword() {
var s0, s1, s2, s3;
s0 = peg$currPos;
if (input.substr(peg$currPos, 5) === peg$c21) {
s1 = peg$c21;
peg$currPos += 5;
} else {
s1 = peg$FAILED;
if (peg$silentFails === 0) { peg$fail(peg$c22); }
}
if (s1 === peg$FAILED) {
if (input.substr(peg$currPos, 5) === peg$c23) {
s1 = peg$c23;
peg$currPos += 5;
} else {
s1 = peg$FAILED;
if (peg$silentFails === 0) { peg$fail(peg$c24); }
}
if (s1 === peg$FAILED) {
if (input.substr(peg$currPos, 3) === peg$c142) {
s1 = peg$c142;
peg$currPos += 3;
} else {
s1 = peg$FAILED;
if (peg$silentFails === 0) { peg$fail(peg$c143); }
}
if (s1 === peg$FAILED) {
if (input.substr(peg$currPos, 4) === peg$c27) {
s1 = peg$c27;
peg$currPos += 4;
} else {
s1 = peg$FAILED;
if (peg$silentFails === 0) { peg$fail(peg$c28); }
}
if (s1 === peg$FAILED) {
if (input.substr(peg$currPos, 2) === peg$c25) {
s1 = peg$c25;
peg$currPos += 2;
} else {
s1 = peg$FAILED;
if (peg$silentFails === 0) { peg$fail(peg$c26); }
}
if (s1 === peg$FAILED) {
if (input.substr(peg$currPos, 4) === peg$c144) {
s1 = peg$c144;
peg$currPos += 4;
} else {
s1 = peg$FAILED;
if (peg$silentFails === 0) { peg$fail(peg$c145); }
}
if (s1 === peg$FAILED) {
if (input.substr(peg$currPos, 4) === peg$c146) {
s1 = peg$c146;
peg$currPos += 4;
} else {
s1 = peg$FAILED;
if (peg$silentFails === 0) { peg$fail(peg$c147); }
}
if (s1 === peg$FAILED) {
if (input.substr(peg$currPos, 2) === peg$c30) {
s1 = peg$c30;
peg$currPos += 2;
} else {
s1 = peg$FAILED;
if (peg$silentFails === 0) { peg$fail(peg$c31); }
}
if (s1 === peg$FAILED) {
if (input.substr(peg$currPos, 4) === peg$c32) {
s1 = peg$c32;
peg$currPos += 4;
} else {
s1 = peg$FAILED;
if (peg$silentFails === 0) { peg$fail(peg$c33); }
}
if (s1 === peg$FAILED) {
if (input.substr(peg$currPos, 4) === peg$c34) {
s1 = peg$c34;
peg$currPos += 4;
} else {
s1 = peg$FAILED;
if (peg$silentFails === 0) { peg$fail(peg$c35); }
}
if (s1 === peg$FAILED) {
if (input.substr(peg$currPos, 4) === peg$c39) {
s1 = peg$c39;
peg$currPos += 4;
} else {
s1 = peg$FAILED;
if (peg$silentFails === 0) { peg$fail(peg$c40); }
}
if (s1 === peg$FAILED) {
if (input.substr(peg$currPos, 2) === peg$c36) {
s1 = peg$c36;
peg$currPos += 2;
} else {
s1 = peg$FAILED;
if (peg$silentFails === 0) { peg$fail(peg$c37); }
}
if (s1 === peg$FAILED) {
if (input.substr(peg$currPos, 2) === peg$c51) {
s1 = peg$c51;
peg$currPos += 2;
} else {
s1 = peg$FAILED;
if (peg$silentFails === 0) { peg$fail(peg$c52); }
}
}
}
}
}
}
}
}
}
}
}
}
}
if (s1 !== peg$FAILED) {
s2 = [];
s3 = peg$parsespaceNL();
if (s3 !== peg$FAILED) {
while (s3 !== peg$FAILED) {
s2.push(s3);
s3 = peg$parsespaceNL();
}
} else {
s2 = peg$c1;
}
if (s2 === peg$FAILED) {
s2 = peg$parseEOF();
}
if (s2 !== peg$FAILED) {
s1 = [s1, s2];
s0 = s1;
} else {
peg$currPos = s0;
s0 = peg$c1;
}
} else {
peg$currPos = s0;
s0 = peg$c1;
}
return s0;
}
function peg$parsecontinuationStart() {
var s0, s1, s2, s3;
s0 = peg$currPos;
s1 = peg$currPos;
peg$silentFails++;
s2 = peg$parsekeyword();
if (s2 === peg$FAILED) {
if (input.charCodeAt(peg$currPos) === 34) {
s2 = peg$c82;
peg$currPos++;
} else {
s2 = peg$FAILED;
if (peg$silentFails === 0) { peg$fail(peg$c83); }
}
if (s2 === peg$FAILED) {
if (input.charCodeAt(peg$currPos) === 39) {
s2 = peg$c77;
peg$currPos++;
} else {
s2 = peg$FAILED;
if (peg$silentFails === 0) { peg$fail(peg$c78); }
}
if (s2 === peg$FAILED) {
if (input.charCodeAt(peg$currPos) === 96) {
s2 = peg$c88;
peg$currPos++;
} else {
s2 = peg$FAILED;
if (peg$silentFails === 0) { peg$fail(peg$c89); }
}
if (s2 === peg$FAILED) {
if (input.substr(peg$currPos, 2) === peg$c99) {
s2 = peg$c99;
peg$currPos += 2;
} else {
s2 = peg$FAILED;
if (peg$silentFails === 0) { peg$fail(peg$c100); }
}
if (s2 === peg$FAILED) {
if (input.substr(peg$currPos, 2) === peg$c94) {
s2 = peg$c94;
peg$currPos += 2;
} else {
s2 = peg$FAILED;
if (peg$silentFails === 0) { peg$fail(peg$c95); }
}
if (s2 === peg$FAILED) {
if (input.charCodeAt(peg$currPos) === 40) {
s2 = peg$c110;
peg$currPos++;
} else {
s2 = peg$FAILED;
if (peg$silentFails === 0) { peg$fail(peg$c111); }
}
}
}
}
}
}
}
peg$silentFails--;
if (s2 !== peg$FAILED) {
peg$currPos = s1;
s1 = peg$c47;
} else {
s1 = peg$c1;
}
if (s1 !== peg$FAILED) {
s2 = [];
if (input.length > peg$currPos) {
s3 = input.charAt(peg$currPos);
peg$currPos++;
} else {
s3 = peg$FAILED;
if (peg$silentFails === 0) { peg$fail(peg$c59); }
}
while (s3 !== peg$FAILED) {
s2.push(s3);
if (input.length > peg$currPos) {
s3 = input.charAt(peg$currPos);
peg$currPos++;
} else {
s3 = peg$FAILED;
if (peg$silentFails === 0) { peg$fail(peg$c59); }
}
}
if (s2 !== peg$FAILED) {
s1 = [s1, s2];
s0 = s1;
} else {
peg$currPos = s0;
s0 = peg$c1;
}
} else {
peg$currPos = s0;
s0 = peg$c1;
}
return s0;
}
function peg$parseEOF() {
var s0, s1;
s0 = peg$currPos;
peg$silentFails++;
if (input.length > peg$currPos) {
s1 = input.charAt(peg$currPos);
peg$currPos++;
} else {
s1 = peg$FAILED;
if (peg$silentFails === 0) { peg$fail(peg$c59); }
}
peg$silentFails--;
if (s1 === peg$FAILED) {
s0 = peg$c47;
} else {
peg$currPos = s0;
s0 = peg$c1;
}
return s0;
}
var isArray = require("isarray")
var map = require("array-map")
function join(arr) {
return arr.join("")
}
function literal(string) {
return {
type: 'literal',
value: isArray(string) ? string.join('') : string
}
}
function first(arr) {
return arr[0]
}
function second(arr) {
return arr[1]
}
function flattenConcatenation(pieces) {
// TODO - this algo sucks, it's probably on the order of n^4
var result = [pieces[0]]
, len = pieces.length
, prev = pieces[0]
, current
for (var i = 1; i < len; i++) {
current = pieces[i]
if (current.type == 'concatenation') {
current = flattenConcatenation(current.pieces)
}
if (current.type == 'concatenation') {
// it's still a concatenation, append it's pieces to ours
result = result.concat(current.pieces)
}
else if ((current.type == 'literal' || current.type == 'glob')
&& (prev.type == 'literal' || prev.type == 'glob')) {
// globs & literals can be merged
prev.value += current.value
if (prev.type != 'glob' && current.type == 'glob') {
// globs are infectious
prev.type = 'glob'
}
}
else {
result.push(current)
prev = current
}
}
return result.length == 1 ? result[0] : {
type: 'concatenation',
pieces: result
}
}
peg$result = peg$startRuleFunction();
if (peg$result !== peg$FAILED && peg$currPos === input.length) {
return peg$result;
} else {
if (peg$result !== peg$FAILED && peg$currPos < input.length) {
peg$fail({ type: "end", description: "end of input" });
}
throw peg$buildException(null, peg$maxFailExpected, peg$maxFailPos);
}
}
return {
SyntaxError: SyntaxError,
parse: parse
};
})()
module.exports.SyntaxError = parser.SyntaxError