module.exports = parse 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() { "use strict"; /* * Generated by PEG.js 0.9.0. * * http://pegjs.org/ */ function peg$subclass(child, parent) { function ctor() { this.constructor = child; } ctor.prototype = parent.prototype; child.prototype = new ctor(); } function peg$SyntaxError(message, expected, found, location) { this.message = message; this.expected = expected; this.found = found; this.location = location; this.name = "SyntaxError"; if (typeof Error.captureStackTrace === "function") { Error.captureStackTrace(this, peg$SyntaxError); } } peg$subclass(peg$SyntaxError, Error); function peg$parse(input) { var options = arguments.length > 1 ? arguments[1] : {}, parser = this, peg$FAILED = {}, peg$startRuleFunctions = { script: peg$parsescript, command: peg$parsecommand, argument: peg$parseargument, continuationStart: peg$parsecontinuationStart }, peg$startRuleFunction = peg$parsescript, peg$c0 = function(statements) { return statements || [] }, peg$c1 = function(head, tail, last) { var statements = [head] var prev = head map(tail, function (spaceOpSpaceCmd, i, cmds) { setOperator(spaceOpSpaceCmd[0], prev) statements.push(prev = spaceOpSpaceCmd[2]) }) if (last) { if (!prev) { debugger } setOperator(last, prev) } return statements function setOperator(operator, command) { while (command.next) { command = command.next } command.control = operator } }, peg$c2 = 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$c3 = "&&", peg$c4 = { type: "literal", value: "&&", description: "\"&&\"" }, peg$c5 = "||", peg$c6 = { type: "literal", value: "||", description: "\"||\"" }, peg$c7 = function(operator, statement) { return [operator, statement] }, peg$c8 = { type: "other", description: "a subshell" }, peg$c9 = "(", peg$c10 = { type: "literal", value: "(", description: "\"(\"" }, peg$c11 = ")", peg$c12 = { type: "literal", value: ")", description: "\")\"" }, peg$c13 = function(statements) { return { type: 'subshell', statements: statements, } }, peg$c14 = { type: "other", description: "a single command" }, peg$c15 = 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$c16 = function(test) { return test }, peg$c17 = { type: "other", description: "an if/elif/else statement" }, peg$c18 = "if", peg$c19 = { type: "literal", value: "if", description: "\"if\"" }, peg$c20 = "then", peg$c21 = { type: "literal", value: "then", description: "\"then\"" }, peg$c22 = "else", peg$c23 = { type: "literal", value: "else", description: "\"else\"" }, peg$c24 = "fi", peg$c25 = { type: "literal", value: "fi", description: "\"fi\"" }, peg$c26 = function(test, body, elifBlocks, elseBody) { return { type: 'ifElse', test: test, body: body, elifBlocks: elifBlocks.length ? elifBlocks : null, elseBody: elseBody ? elseBody[1] : null, } }, peg$c27 = "elif", peg$c28 = { type: "literal", value: "elif", description: "\"elif\"" }, peg$c29 = function(test, body) { return { type: 'ifElse', test: test, body: body } }, peg$c30 = { type: "other", description: "a while/until loop" }, peg$c31 = "while", peg$c32 = { type: "literal", value: "while", description: "\"while\"" }, peg$c33 = "until", peg$c34 = { type: "literal", value: "until", description: "\"until\"" }, peg$c35 = "do", peg$c36 = { type: "literal", value: "do", description: "\"do\"" }, peg$c37 = "done", peg$c38 = { type: "literal", value: "done", description: "\"done\"" }, peg$c39 = function(kind, test, body) { return { type: kind + 'Loop', test: test, body: body } }, peg$c40 = { type: "other", description: "a for loop" }, peg$c41 = "for", peg$c42 = { type: "literal", value: "for", description: "\"for\"" }, peg$c43 = "in", peg$c44 = { type: "literal", value: "in", description: "\"in\"" }, peg$c45 = ";", peg$c46 = { type: "literal", value: ";", description: "\";\"" }, peg$c47 = "\n", peg$c48 = { type: "literal", value: "\n", description: "\"\\n\"" }, peg$c49 = function(loopVar, subjects, body) { return { type: 'forLoop', loopVariable: loopVar, subjects: subjects[1].map(second), body: body } }, peg$c50 = { type: "other", description: "time builtin" }, peg$c51 = "time", peg$c52 = { type: "literal", value: "time", description: "\"time\"" }, peg$c53 = "-", peg$c54 = { type: "literal", value: "-", description: "\"-\"" }, peg$c55 = /^[a-z]/, peg$c56 = { type: "class", value: "[a-z]", description: "[a-z]" }, peg$c57 = function(flags, statements) { return { type: 'time', flags: flags, command: statements } }, peg$c58 = { type: "other", description: "declare builtin" }, peg$c59 = "declare", peg$c60 = { type: "literal", value: "declare", description: "\"declare\"" }, peg$c61 = "typeset", peg$c62 = { type: "literal", value: "typeset", description: "\"typeset\"" }, peg$c63 = /^[^\n]/, peg$c64 = { type: "class", value: "[^\\n]", description: "[^\\n]" }, peg$c65 = { type: "other", description: "a variable assignment" }, peg$c66 = "=", peg$c67 = { type: "literal", value: "=", description: "\"=\"" }, peg$c68 = function(name, value) { return {type: 'variableAssignment', name: name, value: value} }, peg$c69 = { type: "other", description: "command name" }, peg$c70 = function(name) { return name }, peg$c71 = "[[", peg$c72 = { type: "literal", value: "[[", description: "\"[[\"" }, peg$c73 = "[", peg$c74 = { type: "literal", value: "[", description: "\"[\"" }, peg$c75 = { type: "other", description: "command argument" }, peg$c76 = { type: "other", description: "concatenation of strings and/or variables" }, peg$c77 = function(pieces) { return flattenConcatenation(pieces) }, peg$c78 = { type: "other", description: "bareword" }, peg$c79 = "#", peg$c80 = { type: "literal", value: "#", description: "\"#\"" }, peg$c81 = function(cs) { return literal(cs) }, peg$c82 = "\\", peg$c83 = { type: "literal", value: "\\", description: "\"\\\\\"" }, peg$c84 = function(chr) { return chr }, peg$c85 = { type: "any", description: "any character" }, peg$c86 = /^[$"';&<>\n()[*?|` ]/, peg$c87 = { type: "class", value: "[$\"';&<>\\n()\\[*?|` ]", description: "[$\"';&<>\\n()\\[*?|` ]" }, peg$c88 = "*", peg$c89 = { type: "literal", value: "*", description: "\"*\"" }, peg$c90 = "?", peg$c91 = { type: "literal", value: "?", description: "\"?\"" }, peg$c92 = function() { return { type: 'glob', value: text() } }, peg$c93 = "]", peg$c94 = { type: "literal", value: "]", description: "\"]\"" }, peg$c95 = "$", peg$c96 = { type: "literal", value: "$", description: "\"$\"" }, peg$c97 = "{", peg$c98 = { type: "literal", value: "{", description: "\"{\"" }, peg$c99 = "}", peg$c100 = { type: "literal", value: "}", description: "\"}\"" }, peg$c101 = "'", peg$c102 = { type: "literal", value: "'", description: "\"'\"" }, peg$c103 = /^[^']/, peg$c104 = { type: "class", value: "[^']", description: "[^']" }, peg$c105 = function(inner) { return literal(inner) }, peg$c106 = "\"", peg$c107 = { type: "literal", value: "\"", description: "\"\\\"\"" }, peg$c108 = function(contents) { var pieces = contents.map(function (it) { return isArray(it) ? literal(it) : it }) return flattenConcatenation(pieces) }, peg$c109 = "\\\\", peg$c110 = { type: "literal", value: "\\\\", description: "\"\\\\\\\\\"" }, peg$c111 = function() { return '\\' }, peg$c112 = "`", peg$c113 = { type: "literal", value: "`", description: "\"`\"" }, peg$c114 = function(name) { return {type: 'variable', name: name} }, peg$c115 = /^[a-zA-Z0-9_]/, peg$c116 = { type: "class", value: "[a-zA-Z0-9_]", description: "[a-zA-Z0-9_]" }, peg$c117 = function() { return text() }, peg$c118 = "${", peg$c119 = { type: "literal", value: "${", description: "\"${\"" }, peg$c120 = /^[^}]/, peg$c121 = { type: "class", value: "[^}]", description: "[^}]" }, peg$c122 = function(expr) { return { type: 'variableSubstitution', expression: join(expr), // TODO subParser } }, peg$c123 = "$(", peg$c124 = { type: "literal", value: "$(", description: "\"$(\"" }, peg$c125 = function(commands) { return { type: 'commandSubstitution', commands: commands } }, peg$c126 = function(input) { return { type: 'commandSubstitution', commands: parse(input.join('')) } }, peg$c127 = "\\`", peg$c128 = { type: "literal", value: "\\`", description: "\"\\\\`\"" }, peg$c129 = function() { return '`' }, peg$c130 = /^[<>]/, peg$c131 = { type: "class", value: "[<>]", description: "[<>]" }, peg$c132 = function(rw, commands) { return { type: 'processSubstitution', readWrite: rw, commands: commands, } }, peg$c133 = "<&", peg$c134 = { type: "literal", value: "<&", description: "\"<&\"" }, peg$c135 = ">&", peg$c136 = { type: "literal", value: ">&", description: "\">&\"" }, peg$c137 = function(fd, op, dest) { if (fd == null) fd = op[0] == '<' ? 0 : 1; return { type: 'moveFd', fd: fd, op: op, dest: dest } }, peg$c138 = function(src, op, dest) { if (src == null) src = op[0] == '<' ? 0 : 1; return { type: 'duplicateFd', srcFd: src, op: op, destFd: dest, } }, peg$c139 = function(fd, op, filename) { if (fd == null) fd = op[0] == '<' ? 0 : 1; return { type: 'redirectFd', fd: fd, op: op, filename: filename } }, peg$c140 = ">|", peg$c141 = { type: "literal", value: ">|", description: "\">|\"" }, peg$c142 = ">>", peg$c143 = { type: "literal", value: ">>", description: "\">>\"" }, peg$c144 = "&>>", peg$c145 = { type: "literal", value: "&>>", description: "\"&>>\"" }, peg$c146 = "&>", peg$c147 = { type: "literal", value: "&>", description: "\"&>\"" }, peg$c148 = "<", peg$c149 = { type: "literal", value: "<", description: "\"<\"" }, peg$c150 = ">", peg$c151 = { type: "literal", value: ">", description: "\">\"" }, peg$c152 = /^[0-9]/, peg$c153 = { type: "class", value: "[0-9]", description: "[0-9]" }, peg$c154 = function(digits) { return parseInt(join(digits), 10) }, peg$c155 = "&", peg$c156 = { type: "literal", value: "&", description: "\"&\"" }, peg$c157 = function(op) { return op == '\n' ? ';' : op }, peg$c158 = "|", peg$c159 = { type: "literal", value: "|", description: "\"|\"" }, peg$c160 = function(command) { return {type: 'pipe', command: command} }, peg$c161 = { type: "other", description: "whitespace" }, peg$c162 = " ", peg$c163 = { type: "literal", value: " ", description: "\" \"" }, peg$c164 = "\t", peg$c165 = { type: "literal", value: "\t", description: "\"\\t\"" }, peg$c166 = { type: "other", description: "a comment" }, peg$c167 = "case", peg$c168 = { type: "literal", value: "case", description: "\"case\"" }, peg$c169 = "esac", peg$c170 = { type: "literal", value: "esac", description: "\"esac\"" }, peg$currPos = 0, peg$savedPos = 0, peg$posDetailsCache = [{ 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$savedPos, peg$currPos); } function location() { return peg$computeLocation(peg$savedPos, peg$currPos); } function expected(description) { throw peg$buildException( null, [{ type: "other", description: description }], input.substring(peg$savedPos, peg$currPos), peg$computeLocation(peg$savedPos, peg$currPos) ); } function error(message) { throw peg$buildException( message, null, input.substring(peg$savedPos, peg$currPos), peg$computeLocation(peg$savedPos, peg$currPos) ); } function peg$computePosDetails(pos) { var details = peg$posDetailsCache[pos], p, ch; if (details) { return details; } else { p = pos - 1; while (!peg$posDetailsCache[p]) { p--; } details = peg$posDetailsCache[p]; details = { line: details.line, column: details.column, seenCR: details.seenCR }; while (p < pos) { 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; } p++; } peg$posDetailsCache[pos] = details; return details; } } function peg$computeLocation(startPos, endPos) { var startPosDetails = peg$computePosDetails(startPos), endPosDetails = peg$computePosDetails(endPos); return { start: { offset: startPos, line: startPosDetails.line, column: startPosDetails.column }, end: { offset: endPos, line: endPosDetails.line, column: endPosDetails.column } }; } 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, found, location) { 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(/[\u0100-\u0FFF]/g, function(ch) { return '\\u0' + hex(ch); }) .replace(/[\u1000-\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."; } if (expected !== null) { cleanupExpected(expected); } return new peg$SyntaxError( message !== null ? message : buildMessage(expected, found), expected, found, location ); } function peg$parsescript() { var s0, s1, s2; s0 = peg$currPos; s1 = []; s2 = peg$parsespaceNL(); while (s2 !== peg$FAILED) { s1.push(s2); s2 = peg$parsespaceNL(); } if (s1 !== peg$FAILED) { s2 = peg$parsestatementList(); if (s2 === peg$FAILED) { s2 = null; } if (s2 !== peg$FAILED) { peg$savedPos = s0; s1 = peg$c0(s2); s0 = s1; } else { peg$currPos = s0; s0 = peg$FAILED; } } else { peg$currPos = s0; s0 = peg$FAILED; } return s0; } function peg$parsestatementList() { var s0, s1, s2, s3, s4, s5, s6; s0 = peg$currPos; s1 = peg$parsestatement(); if (s1 !== peg$FAILED) { s2 = []; s3 = peg$currPos; s4 = peg$parsecontrolOperator(); if (s4 !== peg$FAILED) { s5 = []; s6 = peg$parsespaceNL(); while (s6 !== peg$FAILED) { s5.push(s6); s6 = peg$parsespaceNL(); } if (s5 !== peg$FAILED) { s6 = peg$parsestatement(); if (s6 !== peg$FAILED) { s4 = [s4, s5, s6]; s3 = s4; } else { peg$currPos = s3; s3 = peg$FAILED; } } else { peg$currPos = s3; s3 = peg$FAILED; } } else { peg$currPos = s3; s3 = peg$FAILED; } while (s3 !== peg$FAILED) { s2.push(s3); s3 = peg$currPos; s4 = peg$parsecontrolOperator(); if (s4 !== peg$FAILED) { s5 = []; s6 = peg$parsespaceNL(); while (s6 !== peg$FAILED) { s5.push(s6); s6 = peg$parsespaceNL(); } if (s5 !== peg$FAILED) { s6 = peg$parsestatement(); if (s6 !== peg$FAILED) { s4 = [s4, s5, s6]; s3 = s4; } else { peg$currPos = s3; s3 = peg$FAILED; } } else { peg$currPos = s3; s3 = peg$FAILED; } } else { peg$currPos = s3; s3 = peg$FAILED; } } if (s2 !== peg$FAILED) { s3 = []; s4 = peg$parsespace(); while (s4 !== peg$FAILED) { s3.push(s4); s4 = peg$parsespace(); } if (s3 !== peg$FAILED) { s4 = peg$parsecontrolOperator(); if (s4 === peg$FAILED) { s4 = null; } if (s4 !== peg$FAILED) { s5 = []; s6 = peg$parsespaceNL(); while (s6 !== peg$FAILED) { s5.push(s6); s6 = peg$parsespaceNL(); } if (s5 !== peg$FAILED) { peg$savedPos = s0; s1 = peg$c1(s1, s2, s4); s0 = s1; } else { peg$currPos = s0; s0 = peg$FAILED; } } else { peg$currPos = s0; s0 = peg$FAILED; } } else { peg$currPos = s0; s0 = peg$FAILED; } } else { peg$currPos = s0; s0 = peg$FAILED; } } else { peg$currPos = s0; s0 = peg$FAILED; } return s0; } function peg$parsestatement() { var s0, s1, s2, s3, s4; s0 = peg$currPos; s1 = peg$parsesubshell(); if (s1 === peg$FAILED) { s1 = peg$parsebashExtensions(); if (s1 === peg$FAILED) { s1 = peg$parsecommand(); if (s1 === peg$FAILED) { s1 = peg$parsevariableAssignment(); if (s1 === peg$FAILED) { s1 = peg$parseifBlock(); if (s1 === peg$FAILED) { s1 = peg$parseconditionalLoop(); if (s1 === peg$FAILED) { s1 = peg$parseforLoop(); } } } } } } 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$FAILED; } } else { peg$currPos = s2; s2 = peg$FAILED; } if (s2 === peg$FAILED) { s2 = null; } if (s2 !== peg$FAILED) { peg$savedPos = s0; s1 = peg$c2(s1, s2); s0 = s1; } else { peg$currPos = s0; s0 = peg$FAILED; } } else { peg$currPos = s0; s0 = peg$FAILED; } return s0; } function peg$parsechainedStatement() { var s0, s1, s2, s3; s0 = peg$currPos; if (input.substr(peg$currPos, 2) === peg$c3) { s1 = peg$c3; peg$currPos += 2; } else { s1 = peg$FAILED; if (peg$silentFails === 0) { peg$fail(peg$c4); } } if (s1 === peg$FAILED) { if (input.substr(peg$currPos, 2) === peg$c5) { s1 = peg$c5; peg$currPos += 2; } else { s1 = peg$FAILED; if (peg$silentFails === 0) { peg$fail(peg$c6); } } } 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$savedPos = s0; s1 = peg$c7(s1, s3); s0 = s1; } else { peg$currPos = s0; s0 = peg$FAILED; } } else { peg$currPos = s0; s0 = peg$FAILED; } } else { peg$currPos = s0; s0 = peg$FAILED; } return s0; } function peg$parsesubshell() { var s0, s1, s2, s3, s4, s5; peg$silentFails++; s0 = peg$currPos; if (input.charCodeAt(peg$currPos) === 40) { s1 = peg$c9; peg$currPos++; } else { s1 = peg$FAILED; if (peg$silentFails === 0) { peg$fail(peg$c10); } } if (s1 !== peg$FAILED) { s2 = []; s3 = peg$parsespace(); while (s3 !== peg$FAILED) { s2.push(s3); s3 = peg$parsespace(); } if (s2 !== peg$FAILED) { s3 = peg$parsestatementList(); if (s3 !== peg$FAILED) { s4 = []; s5 = peg$parsespace(); while (s5 !== peg$FAILED) { s4.push(s5); s5 = peg$parsespace(); } if (s4 !== peg$FAILED) { if (input.charCodeAt(peg$currPos) === 41) { s5 = peg$c11; peg$currPos++; } else { s5 = peg$FAILED; if (peg$silentFails === 0) { peg$fail(peg$c12); } } if (s5 !== peg$FAILED) { peg$savedPos = s0; s1 = peg$c13(s3); s0 = s1; } else { peg$currPos = s0; s0 = peg$FAILED; } } else { peg$currPos = s0; s0 = peg$FAILED; } } else { peg$currPos = s0; s0 = peg$FAILED; } } else { peg$currPos = s0; s0 = peg$FAILED; } } else { peg$currPos = s0; s0 = peg$FAILED; } peg$silentFails--; if (s0 === peg$FAILED) { s1 = peg$FAILED; if (peg$silentFails === 0) { peg$fail(peg$c8); } } 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$FAILED; } if (s4 !== peg$FAILED) { s3 = [s3, s4]; s2 = s3; } else { peg$currPos = s2; s2 = peg$FAILED; } } else { peg$currPos = s2; s2 = peg$FAILED; } 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$FAILED; } if (s4 !== peg$FAILED) { s3 = [s3, s4]; s2 = s3; } else { peg$currPos = s2; s2 = peg$FAILED; } } else { peg$currPos = s2; s2 = peg$FAILED; } } 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$FAILED; } 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$FAILED; } } else { peg$currPos = s4; s4 = peg$FAILED; } 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$FAILED; } 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$FAILED; } } else { peg$currPos = s4; s4 = peg$FAILED; } } 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$FAILED; } } else { peg$currPos = s4; s4 = peg$FAILED; } if (s4 === peg$FAILED) { s4 = null; } if (s4 !== peg$FAILED) { peg$savedPos = s0; s1 = peg$c15(s1, s2, s3, s4); s0 = s1; } else { peg$currPos = s0; s0 = peg$FAILED; } } else { peg$currPos = s0; s0 = peg$FAILED; } } else { peg$currPos = s0; s0 = peg$FAILED; } } else { peg$currPos = s0; s0 = peg$FAILED; } peg$silentFails--; if (s0 === peg$FAILED) { s1 = peg$FAILED; if (peg$silentFails === 0) { peg$fail(peg$c14); } } return s0; } function peg$parsecondition() { var s0, s1; s0 = peg$currPos; s1 = peg$parsescript(); if (s1 !== peg$FAILED) { peg$savedPos = s0; s1 = peg$c16(s1); } s0 = s1; return s0; } function peg$parseifBlock() { var s0, s1, s2, s3, s4, s5, s6, s7, s8, s9, s10; peg$silentFails++; s0 = peg$currPos; if (input.substr(peg$currPos, 2) === peg$c18) { s1 = peg$c18; peg$currPos += 2; } else { s1 = peg$FAILED; if (peg$silentFails === 0) { peg$fail(peg$c19); } } 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$FAILED; } if (s2 !== peg$FAILED) { s3 = peg$parsecondition(); if (s3 !== peg$FAILED) { if (input.substr(peg$currPos, 4) === peg$c20) { s4 = peg$c20; peg$currPos += 4; } else { s4 = peg$FAILED; if (peg$silentFails === 0) { peg$fail(peg$c21); } } 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$FAILED; } 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$c22) { s9 = peg$c22; peg$currPos += 4; } else { s9 = peg$FAILED; if (peg$silentFails === 0) { peg$fail(peg$c23); } } if (s9 !== peg$FAILED) { s10 = peg$parsescript(); if (s10 !== peg$FAILED) { s9 = [s9, s10]; s8 = s9; } else { peg$currPos = s8; s8 = peg$FAILED; } } else { peg$currPos = s8; s8 = peg$FAILED; } if (s8 === peg$FAILED) { s8 = null; } if (s8 !== peg$FAILED) { if (input.substr(peg$currPos, 2) === peg$c24) { s9 = peg$c24; peg$currPos += 2; } else { s9 = peg$FAILED; if (peg$silentFails === 0) { peg$fail(peg$c25); } } if (s9 !== peg$FAILED) { peg$savedPos = s0; s1 = peg$c26(s3, s6, s7, s8); s0 = s1; } else { peg$currPos = s0; s0 = peg$FAILED; } } else { peg$currPos = s0; s0 = peg$FAILED; } } else { peg$currPos = s0; s0 = peg$FAILED; } } else { peg$currPos = s0; s0 = peg$FAILED; } } else { peg$currPos = s0; s0 = peg$FAILED; } } else { peg$currPos = s0; s0 = peg$FAILED; } } else { peg$currPos = s0; s0 = peg$FAILED; } } else { peg$currPos = s0; s0 = peg$FAILED; } } else { peg$currPos = s0; s0 = peg$FAILED; } peg$silentFails--; if (s0 === peg$FAILED) { s1 = peg$FAILED; if (peg$silentFails === 0) { peg$fail(peg$c17); } } return s0; } function peg$parseelifBlock() { var s0, s1, s2, s3, s4, s5, s6; s0 = peg$currPos; 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) { s2 = []; s3 = peg$parsespaceNL(); if (s3 !== peg$FAILED) { while (s3 !== peg$FAILED) { s2.push(s3); s3 = peg$parsespaceNL(); } } else { s2 = peg$FAILED; } if (s2 !== peg$FAILED) { s3 = peg$parsecondition(); if (s3 !== peg$FAILED) { if (input.substr(peg$currPos, 4) === peg$c20) { s4 = peg$c20; peg$currPos += 4; } else { s4 = peg$FAILED; if (peg$silentFails === 0) { peg$fail(peg$c21); } } 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$FAILED; } if (s5 !== peg$FAILED) { s6 = peg$parsescript(); if (s6 !== peg$FAILED) { peg$savedPos = s0; s1 = peg$c29(s3, s6); s0 = s1; } else { peg$currPos = s0; s0 = peg$FAILED; } } else { peg$currPos = s0; s0 = peg$FAILED; } } else { peg$currPos = s0; s0 = peg$FAILED; } } else { peg$currPos = s0; s0 = peg$FAILED; } } else { peg$currPos = s0; s0 = peg$FAILED; } } else { peg$currPos = s0; s0 = peg$FAILED; } return s0; } function peg$parseconditionalLoop() { var s0, s1, s2, s3, s4, s5, s6, s7; peg$silentFails++; s0 = peg$currPos; if (input.substr(peg$currPos, 5) === peg$c31) { s1 = peg$c31; peg$currPos += 5; } else { s1 = peg$FAILED; if (peg$silentFails === 0) { peg$fail(peg$c32); } } if (s1 === peg$FAILED) { if (input.substr(peg$currPos, 5) === peg$c33) { s1 = peg$c33; peg$currPos += 5; } else { s1 = peg$FAILED; if (peg$silentFails === 0) { peg$fail(peg$c34); } } } 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$FAILED; } if (s2 !== peg$FAILED) { s3 = peg$parsecondition(); if (s3 !== peg$FAILED) { if (input.substr(peg$currPos, 2) === peg$c35) { s4 = peg$c35; peg$currPos += 2; } else { s4 = peg$FAILED; if (peg$silentFails === 0) { peg$fail(peg$c36); } } 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$FAILED; } if (s5 !== peg$FAILED) { s6 = peg$parsescript(); if (s6 !== peg$FAILED) { if (input.substr(peg$currPos, 4) === peg$c37) { s7 = peg$c37; peg$currPos += 4; } else { s7 = peg$FAILED; if (peg$silentFails === 0) { peg$fail(peg$c38); } } if (s7 !== peg$FAILED) { peg$savedPos = s0; s1 = peg$c39(s1, s3, s6); s0 = s1; } else { peg$currPos = s0; s0 = peg$FAILED; } } else { peg$currPos = s0; s0 = peg$FAILED; } } else { peg$currPos = s0; s0 = peg$FAILED; } } else { peg$currPos = s0; s0 = peg$FAILED; } } else { peg$currPos = s0; s0 = peg$FAILED; } } else { peg$currPos = s0; s0 = peg$FAILED; } } else { peg$currPos = s0; s0 = peg$FAILED; } peg$silentFails--; if (s0 === peg$FAILED) { s1 = peg$FAILED; if (peg$silentFails === 0) { peg$fail(peg$c30); } } return s0; } function peg$parseforLoop() { var s0, s1, s2, s3, s4, s5, s6, s7, s8, s9, s10, s11, s12, s13; peg$silentFails++; s0 = peg$currPos; if (input.substr(peg$currPos, 3) === peg$c41) { s1 = peg$c41; peg$currPos += 3; } else { s1 = peg$FAILED; if (peg$silentFails === 0) { peg$fail(peg$c42); } } if (s1 !== peg$FAILED) { s2 = []; s3 = peg$parsespace(); if (s3 !== peg$FAILED) { while (s3 !== peg$FAILED) { s2.push(s3); s3 = peg$parsespace(); } } else { s2 = peg$FAILED; } if (s2 !== peg$FAILED) { s3 = peg$parsewritableVariableName(); if (s3 !== peg$FAILED) { s4 = []; s5 = peg$parsespaceNL(); if (s5 !== peg$FAILED) { while (s5 !== peg$FAILED) { s4.push(s5); s5 = peg$parsespaceNL(); } } else { s4 = peg$FAILED; } if (s4 !== peg$FAILED) { s5 = peg$currPos; if (input.substr(peg$currPos, 2) === peg$c43) { s6 = peg$c43; peg$currPos += 2; } else { s6 = peg$FAILED; if (peg$silentFails === 0) { peg$fail(peg$c44); } } if (s6 !== peg$FAILED) { s7 = []; s8 = peg$currPos; s9 = []; s10 = peg$parsespace(); if (s10 !== peg$FAILED) { while (s10 !== peg$FAILED) { s9.push(s10); s10 = peg$parsespace(); } } else { s9 = peg$FAILED; } if (s9 !== peg$FAILED) { s10 = peg$parseargument(); if (s10 !== peg$FAILED) { s9 = [s9, s10]; s8 = s9; } else { peg$currPos = s8; s8 = peg$FAILED; } } else { peg$currPos = s8; s8 = peg$FAILED; } while (s8 !== peg$FAILED) { s7.push(s8); s8 = peg$currPos; s9 = []; s10 = peg$parsespace(); if (s10 !== peg$FAILED) { while (s10 !== peg$FAILED) { s9.push(s10); s10 = peg$parsespace(); } } else { s9 = peg$FAILED; } if (s9 !== peg$FAILED) { s10 = peg$parseargument(); if (s10 !== peg$FAILED) { s9 = [s9, s10]; s8 = s9; } else { peg$currPos = s8; s8 = peg$FAILED; } } else { peg$currPos = s8; s8 = peg$FAILED; } } if (s7 !== peg$FAILED) { s6 = [s6, s7]; s5 = s6; } else { peg$currPos = s5; s5 = peg$FAILED; } } else { peg$currPos = s5; s5 = peg$FAILED; } if (s5 === peg$FAILED) { s5 = null; } if (s5 !== peg$FAILED) { s6 = []; s7 = peg$parsespace(); while (s7 !== peg$FAILED) { s6.push(s7); s7 = peg$parsespace(); } if (s6 !== peg$FAILED) { if (input.charCodeAt(peg$currPos) === 59) { s7 = peg$c45; peg$currPos++; } else { s7 = peg$FAILED; if (peg$silentFails === 0) { peg$fail(peg$c46); } } if (s7 === peg$FAILED) { if (input.charCodeAt(peg$currPos) === 10) { s7 = peg$c47; peg$currPos++; } else { s7 = peg$FAILED; if (peg$silentFails === 0) { peg$fail(peg$c48); } } } if (s7 !== peg$FAILED) { s8 = []; s9 = peg$parsespaceNL(); while (s9 !== peg$FAILED) { s8.push(s9); s9 = peg$parsespaceNL(); } if (s8 !== peg$FAILED) { if (input.substr(peg$currPos, 2) === peg$c35) { s9 = peg$c35; peg$currPos += 2; } else { s9 = peg$FAILED; if (peg$silentFails === 0) { peg$fail(peg$c36); } } if (s9 !== peg$FAILED) { s10 = []; s11 = peg$parsespaceNL(); if (s11 !== peg$FAILED) { while (s11 !== peg$FAILED) { s10.push(s11); s11 = peg$parsespaceNL(); } } else { s10 = peg$FAILED; } if (s10 !== peg$FAILED) { s11 = peg$parsestatementList(); if (s11 !== peg$FAILED) { s12 = []; s13 = peg$parsespaceNL(); while (s13 !== peg$FAILED) { s12.push(s13); s13 = peg$parsespaceNL(); } if (s12 !== peg$FAILED) { if (input.substr(peg$currPos, 4) === peg$c37) { s13 = peg$c37; peg$currPos += 4; } else { s13 = peg$FAILED; if (peg$silentFails === 0) { peg$fail(peg$c38); } } if (s13 !== peg$FAILED) { peg$savedPos = s0; s1 = peg$c49(s3, s5, s11); s0 = s1; } else { peg$currPos = s0; s0 = peg$FAILED; } } else { peg$currPos = s0; s0 = peg$FAILED; } } else { peg$currPos = s0; s0 = peg$FAILED; } } else { peg$currPos = s0; s0 = peg$FAILED; } } else { peg$currPos = s0; s0 = peg$FAILED; } } else { peg$currPos = s0; s0 = peg$FAILED; } } else { peg$currPos = s0; s0 = peg$FAILED; } } else { peg$currPos = s0; s0 = peg$FAILED; } } else { peg$currPos = s0; s0 = peg$FAILED; } } else { peg$currPos = s0; s0 = peg$FAILED; } } else { peg$currPos = s0; s0 = peg$FAILED; } } else { peg$currPos = s0; s0 = peg$FAILED; } } else { peg$currPos = s0; s0 = peg$FAILED; } peg$silentFails--; if (s0 === peg$FAILED) { s1 = peg$FAILED; if (peg$silentFails === 0) { peg$fail(peg$c40); } } return s0; } function peg$parsebashExtensions() { var s0; s0 = peg$parsetime(); if (s0 === peg$FAILED) { s0 = peg$parsedeclare(); } return s0; } function peg$parsetime() { var s0, s1, s2, s3, s4, s5, s6, s7, s8; peg$silentFails++; s0 = peg$currPos; if (input.substr(peg$currPos, 4) === peg$c51) { s1 = peg$c51; peg$currPos += 4; } else { s1 = peg$FAILED; if (peg$silentFails === 0) { peg$fail(peg$c52); } } if (s1 !== peg$FAILED) { s2 = []; s3 = peg$parsespace(); if (s3 !== peg$FAILED) { while (s3 !== peg$FAILED) { s2.push(s3); s3 = peg$parsespace(); } } else { s2 = peg$FAILED; } if (s2 !== peg$FAILED) { s3 = []; s4 = peg$currPos; if (input.charCodeAt(peg$currPos) === 45) { s5 = peg$c53; peg$currPos++; } else { s5 = peg$FAILED; if (peg$silentFails === 0) { peg$fail(peg$c54); } } if (s5 !== peg$FAILED) { s6 = []; if (peg$c55.test(input.charAt(peg$currPos))) { s7 = input.charAt(peg$currPos); peg$currPos++; } else { s7 = peg$FAILED; if (peg$silentFails === 0) { peg$fail(peg$c56); } } if (s7 !== peg$FAILED) { while (s7 !== peg$FAILED) { s6.push(s7); if (peg$c55.test(input.charAt(peg$currPos))) { s7 = input.charAt(peg$currPos); peg$currPos++; } else { s7 = peg$FAILED; if (peg$silentFails === 0) { peg$fail(peg$c56); } } } } else { s6 = peg$FAILED; } if (s6 !== peg$FAILED) { s7 = []; s8 = peg$parsespace(); if (s8 !== peg$FAILED) { while (s8 !== peg$FAILED) { s7.push(s8); s8 = peg$parsespace(); } } else { s7 = peg$FAILED; } if (s7 !== peg$FAILED) { s5 = [s5, s6, s7]; s4 = s5; } else { peg$currPos = s4; s4 = peg$FAILED; } } else { peg$currPos = s4; s4 = peg$FAILED; } } else { peg$currPos = s4; s4 = peg$FAILED; } while (s4 !== peg$FAILED) { s3.push(s4); s4 = peg$currPos; if (input.charCodeAt(peg$currPos) === 45) { s5 = peg$c53; peg$currPos++; } else { s5 = peg$FAILED; if (peg$silentFails === 0) { peg$fail(peg$c54); } } if (s5 !== peg$FAILED) { s6 = []; if (peg$c55.test(input.charAt(peg$currPos))) { s7 = input.charAt(peg$currPos); peg$currPos++; } else { s7 = peg$FAILED; if (peg$silentFails === 0) { peg$fail(peg$c56); } } if (s7 !== peg$FAILED) { while (s7 !== peg$FAILED) { s6.push(s7); if (peg$c55.test(input.charAt(peg$currPos))) { s7 = input.charAt(peg$currPos); peg$currPos++; } else { s7 = peg$FAILED; if (peg$silentFails === 0) { peg$fail(peg$c56); } } } } else { s6 = peg$FAILED; } if (s6 !== peg$FAILED) { s7 = []; s8 = peg$parsespace(); if (s8 !== peg$FAILED) { while (s8 !== peg$FAILED) { s7.push(s8); s8 = peg$parsespace(); } } else { s7 = peg$FAILED; } if (s7 !== peg$FAILED) { s5 = [s5, s6, s7]; s4 = s5; } else { peg$currPos = s4; s4 = peg$FAILED; } } else { peg$currPos = s4; s4 = peg$FAILED; } } else { peg$currPos = s4; s4 = peg$FAILED; } } if (s3 !== peg$FAILED) { s4 = peg$parsestatementList(); if (s4 !== peg$FAILED) { peg$savedPos = s0; s1 = peg$c57(s3, s4); s0 = s1; } else { peg$currPos = s0; s0 = peg$FAILED; } } else { peg$currPos = s0; s0 = peg$FAILED; } } else { peg$currPos = s0; s0 = peg$FAILED; } } else { peg$currPos = s0; s0 = peg$FAILED; } peg$silentFails--; if (s0 === peg$FAILED) { s1 = peg$FAILED; if (peg$silentFails === 0) { peg$fail(peg$c50); } } return s0; } function peg$parsedeclare() { var s0, s1, s2, s3; peg$silentFails++; s0 = peg$currPos; if (input.substr(peg$currPos, 7) === peg$c59) { s1 = peg$c59; peg$currPos += 7; } else { s1 = peg$FAILED; if (peg$silentFails === 0) { peg$fail(peg$c60); } } if (s1 === peg$FAILED) { if (input.substr(peg$currPos, 7) === peg$c61) { s1 = peg$c61; peg$currPos += 7; } else { s1 = peg$FAILED; if (peg$silentFails === 0) { peg$fail(peg$c62); } } } if (s1 !== peg$FAILED) { s2 = []; if (peg$c63.test(input.charAt(peg$currPos))) { s3 = input.charAt(peg$currPos); peg$currPos++; } else { s3 = peg$FAILED; if (peg$silentFails === 0) { peg$fail(peg$c64); } } if (s3 !== peg$FAILED) { while (s3 !== peg$FAILED) { s2.push(s3); if (peg$c63.test(input.charAt(peg$currPos))) { s3 = input.charAt(peg$currPos); peg$currPos++; } else { s3 = peg$FAILED; if (peg$silentFails === 0) { peg$fail(peg$c64); } } } } else { s2 = peg$FAILED; } if (s2 !== peg$FAILED) { if (input.charCodeAt(peg$currPos) === 59) { s3 = peg$c45; peg$currPos++; } else { s3 = peg$FAILED; if (peg$silentFails === 0) { peg$fail(peg$c46); } } if (s3 === peg$FAILED) { if (input.charCodeAt(peg$currPos) === 10) { s3 = peg$c47; peg$currPos++; } else { s3 = peg$FAILED; if (peg$silentFails === 0) { peg$fail(peg$c48); } } } if (s3 !== peg$FAILED) { s1 = [s1, s2, s3]; s0 = s1; } else { peg$currPos = s0; s0 = peg$FAILED; } } else { peg$currPos = s0; s0 = peg$FAILED; } } else { peg$currPos = s0; s0 = peg$FAILED; } peg$silentFails--; if (s0 === peg$FAILED) { s1 = peg$FAILED; if (peg$silentFails === 0) { peg$fail(peg$c58); } } return s0; } function peg$parsevariableAssignment() { var s0, s1, s2, s3; peg$silentFails++; s0 = peg$currPos; s1 = peg$parsewritableVariableName(); if (s1 !== peg$FAILED) { if (input.charCodeAt(peg$currPos) === 61) { s2 = peg$c66; peg$currPos++; } else { s2 = peg$FAILED; if (peg$silentFails === 0) { peg$fail(peg$c67); } } if (s2 !== peg$FAILED) { s3 = peg$parseargument(); if (s3 === peg$FAILED) { s3 = null; } if (s3 !== peg$FAILED) { peg$savedPos = s0; s1 = peg$c68(s1, s3); s0 = s1; } else { peg$currPos = s0; s0 = peg$FAILED; } } else { peg$currPos = s0; s0 = peg$FAILED; } } else { peg$currPos = s0; s0 = peg$FAILED; } peg$silentFails--; if (s0 === peg$FAILED) { s1 = peg$FAILED; if (peg$silentFails === 0) { peg$fail(peg$c65); } } 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 = void 0; } else { peg$currPos = s1; s1 = peg$FAILED; } if (s1 !== peg$FAILED) { s2 = peg$currPos; peg$silentFails++; s3 = peg$parsekeyword(); peg$silentFails--; if (s3 === peg$FAILED) { s2 = void 0; } else { peg$currPos = s2; s2 = peg$FAILED; } if (s2 !== peg$FAILED) { s3 = peg$currPos; peg$silentFails++; s4 = peg$parsevariableAssignment(); peg$silentFails--; if (s4 === peg$FAILED) { s3 = void 0; } else { peg$currPos = s3; s3 = peg$FAILED; } if (s3 !== peg$FAILED) { s4 = peg$parseconcatenation(); if (s4 === peg$FAILED) { s4 = peg$parsebuiltinCommandName(); } if (s4 !== peg$FAILED) { peg$savedPos = s0; s1 = peg$c70(s4); s0 = s1; } else { peg$currPos = s0; s0 = peg$FAILED; } } else { peg$currPos = s0; s0 = peg$FAILED; } } else { peg$currPos = s0; s0 = peg$FAILED; } } else { peg$currPos = s0; s0 = peg$FAILED; } peg$silentFails--; if (s0 === peg$FAILED) { s1 = peg$FAILED; if (peg$silentFails === 0) { peg$fail(peg$c69); } } return s0; } function peg$parsebuiltinCommandName() { var s0; if (input.substr(peg$currPos, 2) === peg$c71) { s0 = peg$c71; peg$currPos += 2; } else { s0 = peg$FAILED; if (peg$silentFails === 0) { peg$fail(peg$c72); } } if (s0 === peg$FAILED) { if (input.charCodeAt(peg$currPos) === 91) { s0 = peg$c73; peg$currPos++; } else { s0 = peg$FAILED; if (peg$silentFails === 0) { peg$fail(peg$c74); } } } 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$c75); } } return s0; } function peg$parseconcatenation() { var s0, s1, s2; peg$silentFails++; 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$FAILED; } if (s1 !== peg$FAILED) { peg$savedPos = s0; s1 = peg$c77(s1); } s0 = s1; peg$silentFails--; if (s0 === peg$FAILED) { s1 = peg$FAILED; if (peg$silentFails === 0) { peg$fail(peg$c76); } } return s0; } function peg$parsebareword() { var s0, s1, s2, s3; peg$silentFails++; s0 = peg$currPos; s1 = peg$currPos; peg$silentFails++; if (input.charCodeAt(peg$currPos) === 35) { s2 = peg$c79; peg$currPos++; } else { s2 = peg$FAILED; if (peg$silentFails === 0) { peg$fail(peg$c80); } } peg$silentFails--; if (s2 === peg$FAILED) { s1 = void 0; } else { peg$currPos = s1; s1 = peg$FAILED; } if (s1 !== peg$FAILED) { s2 = []; s3 = peg$parsebarewordChar(); if (s3 !== peg$FAILED) { while (s3 !== peg$FAILED) { s2.push(s3); s3 = peg$parsebarewordChar(); } } else { s2 = peg$FAILED; } if (s2 !== peg$FAILED) { peg$savedPos = s0; s1 = peg$c81(s2); s0 = s1; } else { peg$currPos = s0; s0 = peg$FAILED; } } else { peg$currPos = s0; s0 = peg$FAILED; } peg$silentFails--; if (s0 === peg$FAILED) { s1 = peg$FAILED; if (peg$silentFails === 0) { peg$fail(peg$c78); } } return s0; } function peg$parsebarewordChar() { var s0, s1, s2; s0 = peg$currPos; if (input.charCodeAt(peg$currPos) === 92) { s1 = peg$c82; peg$currPos++; } else { s1 = peg$FAILED; if (peg$silentFails === 0) { peg$fail(peg$c83); } } if (s1 !== peg$FAILED) { s2 = peg$parsebarewordMeta(); if (s2 !== peg$FAILED) { peg$savedPos = s0; s1 = peg$c84(s2); s0 = s1; } else { peg$currPos = s0; s0 = peg$FAILED; } } else { peg$currPos = s0; s0 = peg$FAILED; } if (s0 === peg$FAILED) { s0 = peg$currPos; s1 = peg$currPos; peg$silentFails++; s2 = peg$parsebarewordMeta(); peg$silentFails--; if (s2 === peg$FAILED) { s1 = void 0; } else { peg$currPos = s1; s1 = peg$FAILED; } 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$c85); } } if (s2 !== peg$FAILED) { peg$savedPos = s0; s1 = peg$c84(s2); s0 = s1; } else { peg$currPos = s0; s0 = peg$FAILED; } } else { peg$currPos = s0; s0 = peg$FAILED; } } return s0; } function peg$parsebarewordMeta() { var s0; if (peg$c86.test(input.charAt(peg$currPos))) { s0 = input.charAt(peg$currPos); peg$currPos++; } else { s0 = peg$FAILED; if (peg$silentFails === 0) { peg$fail(peg$c87); } } 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$c88; peg$currPos++; } else { s3 = peg$FAILED; if (peg$silentFails === 0) { peg$fail(peg$c89); } } if (s3 === peg$FAILED) { if (input.charCodeAt(peg$currPos) === 63) { s3 = peg$c90; peg$currPos++; } else { s3 = peg$FAILED; if (peg$silentFails === 0) { peg$fail(peg$c91); } } 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$c88; peg$currPos++; } else { s3 = peg$FAILED; if (peg$silentFails === 0) { peg$fail(peg$c89); } } if (s3 === peg$FAILED) { if (input.charCodeAt(peg$currPos) === 63) { s3 = peg$c90; peg$currPos++; } else { s3 = peg$FAILED; if (peg$silentFails === 0) { peg$fail(peg$c91); } } if (s3 === peg$FAILED) { s3 = peg$parsecharacterRange(); if (s3 === peg$FAILED) { s3 = peg$parsebraceExpansion(); } } } } } else { s2 = peg$FAILED; } if (s2 !== peg$FAILED) { s3 = []; s4 = peg$parsebarewordChar(); while (s4 !== peg$FAILED) { s3.push(s4); s4 = peg$parsebarewordChar(); } if (s3 !== peg$FAILED) { peg$savedPos = s0; s1 = peg$c92(); s0 = s1; } else { peg$currPos = s0; s0 = peg$FAILED; } } else { peg$currPos = s0; s0 = peg$FAILED; } } else { peg$currPos = s0; s0 = peg$FAILED; } 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$c73; peg$currPos++; } else { s2 = peg$FAILED; if (peg$silentFails === 0) { peg$fail(peg$c74); } } if (s2 !== peg$FAILED) { s3 = peg$currPos; peg$silentFails++; if (input.charCodeAt(peg$currPos) === 45) { s4 = peg$c53; peg$currPos++; } else { s4 = peg$FAILED; if (peg$silentFails === 0) { peg$fail(peg$c54); } } peg$silentFails--; if (s4 === peg$FAILED) { s3 = void 0; } else { peg$currPos = s3; s3 = peg$FAILED; } 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$c85); } } if (s4 !== peg$FAILED) { if (input.charCodeAt(peg$currPos) === 45) { s5 = peg$c53; peg$currPos++; } else { s5 = peg$FAILED; if (peg$silentFails === 0) { peg$fail(peg$c54); } } if (s5 !== peg$FAILED) { s6 = peg$currPos; peg$silentFails++; if (input.charCodeAt(peg$currPos) === 45) { s7 = peg$c53; peg$currPos++; } else { s7 = peg$FAILED; if (peg$silentFails === 0) { peg$fail(peg$c54); } } peg$silentFails--; if (s7 === peg$FAILED) { s6 = void 0; } else { peg$currPos = s6; s6 = peg$FAILED; } 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$c85); } } if (s7 !== peg$FAILED) { if (input.charCodeAt(peg$currPos) === 93) { s8 = peg$c93; peg$currPos++; } else { s8 = peg$FAILED; if (peg$silentFails === 0) { peg$fail(peg$c94); } } if (s8 !== peg$FAILED) { s2 = [s2, s3, s4, s5, s6, s7, s8]; s1 = s2; } else { peg$currPos = s1; s1 = peg$FAILED; } } else { peg$currPos = s1; s1 = peg$FAILED; } } else { peg$currPos = s1; s1 = peg$FAILED; } } else { peg$currPos = s1; s1 = peg$FAILED; } } else { peg$currPos = s1; s1 = peg$FAILED; } } else { peg$currPos = s1; s1 = peg$FAILED; } } else { peg$currPos = s1; s1 = peg$FAILED; } if (s1 !== peg$FAILED) { s0 = input.substring(s0, peg$currPos); } else { 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$c85); } } if (s2 === peg$FAILED) { s2 = null; } if (s2 !== peg$FAILED) { s3 = peg$currPos; peg$silentFails++; if (input.charCodeAt(peg$currPos) === 36) { s4 = peg$c95; peg$currPos++; } else { s4 = peg$FAILED; if (peg$silentFails === 0) { peg$fail(peg$c96); } } peg$silentFails--; if (s4 === peg$FAILED) { s3 = void 0; } else { peg$currPos = s3; s3 = peg$FAILED; } if (s3 !== peg$FAILED) { s2 = [s2, s3]; s1 = s2; } else { peg$currPos = s1; s1 = peg$FAILED; } } else { peg$currPos = s1; s1 = peg$FAILED; } if (s1 !== peg$FAILED) { if (input.charCodeAt(peg$currPos) === 123) { s2 = peg$c97; peg$currPos++; } else { s2 = peg$FAILED; if (peg$silentFails === 0) { peg$fail(peg$c98); } } 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$FAILED; } if (s3 !== peg$FAILED) { if (input.charCodeAt(peg$currPos) === 125) { s4 = peg$c99; peg$currPos++; } else { s4 = peg$FAILED; if (peg$silentFails === 0) { peg$fail(peg$c100); } } if (s4 !== peg$FAILED) { s1 = [s1, s2, s3, s4]; s0 = s1; } else { peg$currPos = s0; s0 = peg$FAILED; } } else { peg$currPos = s0; s0 = peg$FAILED; } } else { peg$currPos = s0; s0 = peg$FAILED; } } else { peg$currPos = s0; s0 = peg$FAILED; } return s0; } function peg$parsesingleQuote() { var s0, s1, s2, s3, s4; s0 = peg$currPos; if (input.charCodeAt(peg$currPos) === 39) { s1 = peg$c101; peg$currPos++; } else { s1 = peg$FAILED; if (peg$silentFails === 0) { peg$fail(peg$c102); } } if (s1 !== peg$FAILED) { s2 = peg$currPos; s3 = []; if (peg$c103.test(input.charAt(peg$currPos))) { s4 = input.charAt(peg$currPos); peg$currPos++; } else { s4 = peg$FAILED; if (peg$silentFails === 0) { peg$fail(peg$c104); } } while (s4 !== peg$FAILED) { s3.push(s4); if (peg$c103.test(input.charAt(peg$currPos))) { s4 = input.charAt(peg$currPos); peg$currPos++; } else { s4 = peg$FAILED; if (peg$silentFails === 0) { peg$fail(peg$c104); } } } if (s3 !== peg$FAILED) { s2 = input.substring(s2, peg$currPos); } else { s2 = s3; } if (s2 !== peg$FAILED) { if (input.charCodeAt(peg$currPos) === 39) { s3 = peg$c101; peg$currPos++; } else { s3 = peg$FAILED; if (peg$silentFails === 0) { peg$fail(peg$c102); } } if (s3 !== peg$FAILED) { peg$savedPos = s0; s1 = peg$c105(s2); s0 = s1; } else { peg$currPos = s0; s0 = peg$FAILED; } } else { peg$currPos = s0; s0 = peg$FAILED; } } else { peg$currPos = s0; s0 = peg$FAILED; } return s0; } function peg$parsedoubleQuote() { var s0, s1, s2, s3, s4; s0 = peg$currPos; if (input.charCodeAt(peg$currPos) === 34) { s1 = peg$c106; peg$currPos++; } else { s1 = peg$FAILED; if (peg$silentFails === 0) { peg$fail(peg$c107); } } 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$FAILED; } } 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$FAILED; } } } if (s2 !== peg$FAILED) { if (input.charCodeAt(peg$currPos) === 34) { s3 = peg$c106; peg$currPos++; } else { s3 = peg$FAILED; if (peg$silentFails === 0) { peg$fail(peg$c107); } } if (s3 !== peg$FAILED) { peg$savedPos = s0; s1 = peg$c108(s2); s0 = s1; } else { peg$currPos = s0; s0 = peg$FAILED; } } else { peg$currPos = s0; s0 = peg$FAILED; } } else { peg$currPos = s0; s0 = peg$FAILED; } return s0; } function peg$parsedoubleQuoteChar() { var s0, s1, s2; s0 = peg$currPos; if (input.charCodeAt(peg$currPos) === 92) { s1 = peg$c82; peg$currPos++; } else { s1 = peg$FAILED; if (peg$silentFails === 0) { peg$fail(peg$c83); } } if (s1 !== peg$FAILED) { s2 = peg$parsedoubleQuoteMeta(); if (s2 !== peg$FAILED) { peg$savedPos = s0; s1 = peg$c84(s2); s0 = s1; } else { peg$currPos = s0; s0 = peg$FAILED; } } else { peg$currPos = s0; s0 = peg$FAILED; } if (s0 === peg$FAILED) { s0 = peg$currPos; if (input.substr(peg$currPos, 2) === peg$c109) { s1 = peg$c109; peg$currPos += 2; } else { s1 = peg$FAILED; if (peg$silentFails === 0) { peg$fail(peg$c110); } } if (s1 !== peg$FAILED) { peg$savedPos = s0; s1 = peg$c111(); } s0 = s1; if (s0 === peg$FAILED) { s0 = peg$currPos; s1 = peg$currPos; peg$silentFails++; s2 = peg$parsedoubleQuoteMeta(); peg$silentFails--; if (s2 === peg$FAILED) { s1 = void 0; } else { peg$currPos = s1; s1 = peg$FAILED; } 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$c85); } } if (s2 !== peg$FAILED) { peg$savedPos = s0; s1 = peg$c84(s2); s0 = s1; } else { peg$currPos = s0; s0 = peg$FAILED; } } else { peg$currPos = s0; s0 = peg$FAILED; } } } return s0; } function peg$parsedoubleQuoteMeta() { var s0; if (input.charCodeAt(peg$currPos) === 34) { s0 = peg$c106; peg$currPos++; } else { s0 = peg$FAILED; if (peg$silentFails === 0) { peg$fail(peg$c107); } } if (s0 === peg$FAILED) { if (input.charCodeAt(peg$currPos) === 36) { s0 = peg$c95; peg$currPos++; } else { s0 = peg$FAILED; if (peg$silentFails === 0) { peg$fail(peg$c96); } } if (s0 === peg$FAILED) { if (input.charCodeAt(peg$currPos) === 96) { s0 = peg$c112; peg$currPos++; } else { s0 = peg$FAILED; if (peg$silentFails === 0) { peg$fail(peg$c113); } } } } 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$c95; peg$currPos++; } else { s1 = peg$FAILED; if (peg$silentFails === 0) { peg$fail(peg$c96); } } if (s1 !== peg$FAILED) { s2 = peg$parsereadableVariableName(); if (s2 !== peg$FAILED) { peg$savedPos = s0; s1 = peg$c114(s2); s0 = s1; } else { peg$currPos = s0; s0 = peg$FAILED; } } else { peg$currPos = s0; s0 = peg$FAILED; } return s0; } function peg$parsewritableVariableName() { var s0, s1, s2; s0 = peg$currPos; s1 = []; if (peg$c115.test(input.charAt(peg$currPos))) { s2 = input.charAt(peg$currPos); peg$currPos++; } else { s2 = peg$FAILED; if (peg$silentFails === 0) { peg$fail(peg$c116); } } if (s2 !== peg$FAILED) { while (s2 !== peg$FAILED) { s1.push(s2); if (peg$c115.test(input.charAt(peg$currPos))) { s2 = input.charAt(peg$currPos); peg$currPos++; } else { s2 = peg$FAILED; if (peg$silentFails === 0) { peg$fail(peg$c116); } } } } else { s1 = peg$FAILED; } if (s1 !== peg$FAILED) { peg$savedPos = s0; s1 = peg$c117(); } s0 = s1; return s0; } function peg$parsereadableVariableName() { var s0; s0 = peg$parsewritableVariableName(); if (s0 === peg$FAILED) { if (input.charCodeAt(peg$currPos) === 63) { s0 = peg$c90; peg$currPos++; } else { s0 = peg$FAILED; if (peg$silentFails === 0) { peg$fail(peg$c91); } } } return s0; } function peg$parsevariableSubstitution() { var s0, s1, s2, s3; s0 = peg$currPos; if (input.substr(peg$currPos, 2) === peg$c118) { s1 = peg$c118; peg$currPos += 2; } else { s1 = peg$FAILED; if (peg$silentFails === 0) { peg$fail(peg$c119); } } if (s1 !== peg$FAILED) { s2 = []; if (peg$c120.test(input.charAt(peg$currPos))) { s3 = input.charAt(peg$currPos); peg$currPos++; } else { s3 = peg$FAILED; if (peg$silentFails === 0) { peg$fail(peg$c121); } } while (s3 !== peg$FAILED) { s2.push(s3); if (peg$c120.test(input.charAt(peg$currPos))) { s3 = input.charAt(peg$currPos); peg$currPos++; } else { s3 = peg$FAILED; if (peg$silentFails === 0) { peg$fail(peg$c121); } } } if (s2 !== peg$FAILED) { if (input.charCodeAt(peg$currPos) === 125) { s3 = peg$c99; peg$currPos++; } else { s3 = peg$FAILED; if (peg$silentFails === 0) { peg$fail(peg$c100); } } if (s3 !== peg$FAILED) { peg$savedPos = s0; s1 = peg$c122(s2); s0 = s1; } else { peg$currPos = s0; s0 = peg$FAILED; } } else { peg$currPos = s0; s0 = peg$FAILED; } } else { peg$currPos = s0; s0 = peg$FAILED; } 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$c123) { s1 = peg$c123; peg$currPos += 2; } else { s1 = peg$FAILED; if (peg$silentFails === 0) { peg$fail(peg$c124); } } if (s1 !== peg$FAILED) { s2 = peg$parsestatementList(); if (s2 !== peg$FAILED) { if (input.charCodeAt(peg$currPos) === 41) { s3 = peg$c11; peg$currPos++; } else { s3 = peg$FAILED; if (peg$silentFails === 0) { peg$fail(peg$c12); } } if (s3 !== peg$FAILED) { peg$savedPos = s0; s1 = peg$c125(s2); s0 = s1; } else { peg$currPos = s0; s0 = peg$FAILED; } } else { peg$currPos = s0; s0 = peg$FAILED; } } else { peg$currPos = s0; s0 = peg$FAILED; } return s0; } function peg$parsebackQuote() { var s0, s1, s2, s3; s0 = peg$currPos; if (input.charCodeAt(peg$currPos) === 96) { s1 = peg$c112; peg$currPos++; } else { s1 = peg$FAILED; if (peg$silentFails === 0) { peg$fail(peg$c113); } } 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$FAILED; } if (s2 !== peg$FAILED) { if (input.charCodeAt(peg$currPos) === 96) { s3 = peg$c112; peg$currPos++; } else { s3 = peg$FAILED; if (peg$silentFails === 0) { peg$fail(peg$c113); } } if (s3 !== peg$FAILED) { peg$savedPos = s0; s1 = peg$c126(s2); s0 = s1; } else { peg$currPos = s0; s0 = peg$FAILED; } } else { peg$currPos = s0; s0 = peg$FAILED; } } else { peg$currPos = s0; s0 = peg$FAILED; } return s0; } function peg$parsebackQuoteChar() { var s0, s1, s2; s0 = peg$currPos; if (input.substr(peg$currPos, 2) === peg$c127) { s1 = peg$c127; peg$currPos += 2; } else { s1 = peg$FAILED; if (peg$silentFails === 0) { peg$fail(peg$c128); } } if (s1 !== peg$FAILED) { peg$savedPos = s0; s1 = peg$c129(); } s0 = s1; if (s0 === peg$FAILED) { s0 = peg$currPos; if (input.substr(peg$currPos, 2) === peg$c109) { s1 = peg$c109; peg$currPos += 2; } else { s1 = peg$FAILED; if (peg$silentFails === 0) { peg$fail(peg$c110); } } if (s1 !== peg$FAILED) { peg$savedPos = s0; s1 = peg$c111(); } s0 = s1; if (s0 === peg$FAILED) { s0 = peg$currPos; s1 = peg$currPos; peg$silentFails++; if (input.charCodeAt(peg$currPos) === 96) { s2 = peg$c112; peg$currPos++; } else { s2 = peg$FAILED; if (peg$silentFails === 0) { peg$fail(peg$c113); } } peg$silentFails--; if (s2 === peg$FAILED) { s1 = void 0; } else { peg$currPos = s1; s1 = peg$FAILED; } 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$c85); } } if (s2 !== peg$FAILED) { peg$savedPos = s0; s1 = peg$c84(s2); s0 = s1; } else { peg$currPos = s0; s0 = peg$FAILED; } } else { peg$currPos = s0; s0 = peg$FAILED; } } } return s0; } function peg$parseprocessSubstitution() { var s0, s1, s2, s3, s4; s0 = peg$currPos; if (peg$c130.test(input.charAt(peg$currPos))) { s1 = input.charAt(peg$currPos); peg$currPos++; } else { s1 = peg$FAILED; if (peg$silentFails === 0) { peg$fail(peg$c131); } } if (s1 !== peg$FAILED) { if (input.charCodeAt(peg$currPos) === 40) { s2 = peg$c9; peg$currPos++; } else { s2 = peg$FAILED; if (peg$silentFails === 0) { peg$fail(peg$c10); } } if (s2 !== peg$FAILED) { s3 = peg$parsestatementList(); if (s3 !== peg$FAILED) { if (input.charCodeAt(peg$currPos) === 41) { s4 = peg$c11; peg$currPos++; } else { s4 = peg$FAILED; if (peg$silentFails === 0) { peg$fail(peg$c12); } } if (s4 !== peg$FAILED) { peg$savedPos = s0; s1 = peg$c132(s1, s3); s0 = s1; } else { peg$currPos = s0; s0 = peg$FAILED; } } else { peg$currPos = s0; s0 = peg$FAILED; } } else { peg$currPos = s0; s0 = peg$FAILED; } } else { peg$currPos = s0; s0 = peg$FAILED; } 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$parsemoveFd() { var s0, s1, s2, s3, s4; s0 = peg$currPos; s1 = peg$parsefd(); if (s1 === peg$FAILED) { s1 = null; } if (s1 !== peg$FAILED) { if (input.substr(peg$currPos, 2) === peg$c133) { s2 = peg$c133; peg$currPos += 2; } else { s2 = peg$FAILED; if (peg$silentFails === 0) { peg$fail(peg$c134); } } if (s2 === peg$FAILED) { if (input.substr(peg$currPos, 2) === peg$c135) { s2 = peg$c135; peg$currPos += 2; } else { s2 = peg$FAILED; if (peg$silentFails === 0) { peg$fail(peg$c136); } } } if (s2 !== peg$FAILED) { s3 = peg$parsefd(); if (s3 !== peg$FAILED) { if (input.charCodeAt(peg$currPos) === 45) { s4 = peg$c53; peg$currPos++; } else { s4 = peg$FAILED; if (peg$silentFails === 0) { peg$fail(peg$c54); } } if (s4 !== peg$FAILED) { peg$savedPos = s0; s1 = peg$c137(s1, s2, s3); s0 = s1; } else { peg$currPos = s0; s0 = peg$FAILED; } } else { peg$currPos = s0; s0 = peg$FAILED; } } else { peg$currPos = s0; s0 = peg$FAILED; } } else { peg$currPos = s0; s0 = peg$FAILED; } return s0; } function peg$parseduplicateFd() { var s0, s1, s2, s3, s4; s0 = peg$currPos; s1 = peg$parsefd(); if (s1 === peg$FAILED) { s1 = null; } if (s1 !== peg$FAILED) { if (input.substr(peg$currPos, 2) === peg$c133) { s2 = peg$c133; peg$currPos += 2; } else { s2 = peg$FAILED; if (peg$silentFails === 0) { peg$fail(peg$c134); } } if (s2 === peg$FAILED) { if (input.substr(peg$currPos, 2) === peg$c135) { s2 = peg$c135; peg$currPos += 2; } else { s2 = peg$FAILED; if (peg$silentFails === 0) { peg$fail(peg$c136); } } } 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$savedPos = s0; s1 = peg$c138(s1, s2, s4); s0 = s1; } else { peg$currPos = s0; s0 = peg$FAILED; } } else { peg$currPos = s0; s0 = peg$FAILED; } } else { peg$currPos = s0; s0 = peg$FAILED; } } else { peg$currPos = s0; s0 = peg$FAILED; } return s0; } function peg$parseredirectFd() { var s0, s1, s2, s3, s4; s0 = peg$currPos; s1 = peg$parsefd(); if (s1 === peg$FAILED) { s1 = null; } 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$savedPos = s0; s1 = peg$c139(s1, s2, s4); s0 = s1; } else { peg$currPos = s0; s0 = peg$FAILED; } } else { peg$currPos = s0; s0 = peg$FAILED; } } else { peg$currPos = s0; s0 = peg$FAILED; } } else { peg$currPos = s0; s0 = peg$FAILED; } return s0; } function peg$parseredirectionOperator() { var s0; if (input.substr(peg$currPos, 2) === peg$c140) { s0 = peg$c140; peg$currPos += 2; } else { s0 = peg$FAILED; if (peg$silentFails === 0) { peg$fail(peg$c141); } } if (s0 === peg$FAILED) { if (input.substr(peg$currPos, 2) === peg$c142) { s0 = peg$c142; peg$currPos += 2; } else { s0 = peg$FAILED; if (peg$silentFails === 0) { peg$fail(peg$c143); } } if (s0 === peg$FAILED) { if (input.substr(peg$currPos, 3) === peg$c144) { s0 = peg$c144; peg$currPos += 3; } else { s0 = peg$FAILED; if (peg$silentFails === 0) { peg$fail(peg$c145); } } if (s0 === peg$FAILED) { if (input.substr(peg$currPos, 2) === peg$c146) { s0 = peg$c146; peg$currPos += 2; } else { s0 = peg$FAILED; if (peg$silentFails === 0) { peg$fail(peg$c147); } } if (s0 === peg$FAILED) { if (input.charCodeAt(peg$currPos) === 60) { s0 = peg$c148; peg$currPos++; } else { s0 = peg$FAILED; if (peg$silentFails === 0) { peg$fail(peg$c149); } } if (s0 === peg$FAILED) { if (input.charCodeAt(peg$currPos) === 62) { s0 = peg$c150; peg$currPos++; } else { s0 = peg$FAILED; if (peg$silentFails === 0) { peg$fail(peg$c151); } } } } } } } return s0; } function peg$parsefd() { var s0, s1, s2; s0 = peg$currPos; s1 = []; if (peg$c152.test(input.charAt(peg$currPos))) { s2 = input.charAt(peg$currPos); peg$currPos++; } else { s2 = peg$FAILED; if (peg$silentFails === 0) { peg$fail(peg$c153); } } if (s2 !== peg$FAILED) { while (s2 !== peg$FAILED) { s1.push(s2); if (peg$c152.test(input.charAt(peg$currPos))) { s2 = input.charAt(peg$currPos); peg$currPos++; } else { s2 = peg$FAILED; if (peg$silentFails === 0) { peg$fail(peg$c153); } } } } else { s1 = peg$FAILED; } if (s1 !== peg$FAILED) { peg$savedPos = s0; s1 = peg$c154(s1); } s0 = s1; return s0; } function peg$parsecontrolOperator() { var s0, s1, s2; s0 = peg$currPos; s1 = []; s2 = peg$parsespace(); while (s2 !== peg$FAILED) { s1.push(s2); s2 = peg$parsespace(); } if (s1 !== peg$FAILED) { if (input.charCodeAt(peg$currPos) === 38) { s2 = peg$c155; peg$currPos++; } else { s2 = peg$FAILED; if (peg$silentFails === 0) { peg$fail(peg$c156); } } if (s2 === peg$FAILED) { if (input.charCodeAt(peg$currPos) === 59) { s2 = peg$c45; peg$currPos++; } else { s2 = peg$FAILED; if (peg$silentFails === 0) { peg$fail(peg$c46); } } if (s2 === peg$FAILED) { if (input.charCodeAt(peg$currPos) === 10) { s2 = peg$c47; peg$currPos++; } else { s2 = peg$FAILED; if (peg$silentFails === 0) { peg$fail(peg$c48); } } } } if (s2 !== peg$FAILED) { peg$savedPos = s0; s1 = peg$c157(s2); s0 = s1; } else { peg$currPos = s0; s0 = peg$FAILED; } } else { peg$currPos = s0; s0 = peg$FAILED; } return s0; } function peg$parsepipe() { var s0, s1, s2, s3; s0 = peg$currPos; if (input.charCodeAt(peg$currPos) === 124) { s1 = peg$c158; peg$currPos++; } else { s1 = peg$FAILED; if (peg$silentFails === 0) { peg$fail(peg$c159); } } 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$savedPos = s0; s1 = peg$c160(s3); s0 = s1; } else { peg$currPos = s0; s0 = peg$FAILED; } } else { peg$currPos = s0; s0 = peg$FAILED; } } else { peg$currPos = s0; s0 = peg$FAILED; } return s0; } function peg$parsespace() { var s0, s1; peg$silentFails++; if (input.charCodeAt(peg$currPos) === 32) { s0 = peg$c162; peg$currPos++; } else { s0 = peg$FAILED; if (peg$silentFails === 0) { peg$fail(peg$c163); } } if (s0 === peg$FAILED) { if (input.charCodeAt(peg$currPos) === 9) { s0 = peg$c164; peg$currPos++; } else { s0 = peg$FAILED; if (peg$silentFails === 0) { peg$fail(peg$c165); } } } peg$silentFails--; if (s0 === peg$FAILED) { s1 = peg$FAILED; if (peg$silentFails === 0) { peg$fail(peg$c161); } } return s0; } function peg$parsespaceNL() { var s0; s0 = peg$parsespace(); if (s0 === peg$FAILED) { if (input.charCodeAt(peg$currPos) === 10) { s0 = peg$c47; peg$currPos++; } else { s0 = peg$FAILED; if (peg$silentFails === 0) { peg$fail(peg$c48); } } if (s0 === peg$FAILED) { s0 = peg$parsecomment(); } } return s0; } function peg$parsecomment() { var s0, s1, s2, s3; peg$silentFails++; s0 = peg$currPos; if (input.charCodeAt(peg$currPos) === 35) { s1 = peg$c79; peg$currPos++; } else { s1 = peg$FAILED; if (peg$silentFails === 0) { peg$fail(peg$c80); } } if (s1 !== peg$FAILED) { s2 = []; if (peg$c63.test(input.charAt(peg$currPos))) { s3 = input.charAt(peg$currPos); peg$currPos++; } else { s3 = peg$FAILED; if (peg$silentFails === 0) { peg$fail(peg$c64); } } while (s3 !== peg$FAILED) { s2.push(s3); if (peg$c63.test(input.charAt(peg$currPos))) { s3 = input.charAt(peg$currPos); peg$currPos++; } else { s3 = peg$FAILED; if (peg$silentFails === 0) { peg$fail(peg$c64); } } } if (s2 !== peg$FAILED) { if (input.charCodeAt(peg$currPos) === 10) { s3 = peg$c47; peg$currPos++; } else { s3 = peg$FAILED; if (peg$silentFails === 0) { peg$fail(peg$c48); } } if (s3 === peg$FAILED) { s3 = peg$parseEOF(); } if (s3 !== peg$FAILED) { s1 = [s1, s2, s3]; s0 = s1; } else { peg$currPos = s0; s0 = peg$FAILED; } } else { peg$currPos = s0; s0 = peg$FAILED; } } else { peg$currPos = s0; s0 = peg$FAILED; } peg$silentFails--; if (s0 === peg$FAILED) { s1 = peg$FAILED; if (peg$silentFails === 0) { peg$fail(peg$c166); } } return s0; } function peg$parsekeyword() { var s0, s1, s2, s3; s0 = peg$currPos; if (input.substr(peg$currPos, 5) === peg$c31) { s1 = peg$c31; peg$currPos += 5; } else { s1 = peg$FAILED; if (peg$silentFails === 0) { peg$fail(peg$c32); } } if (s1 === peg$FAILED) { if (input.substr(peg$currPos, 5) === peg$c33) { s1 = peg$c33; peg$currPos += 5; } else { s1 = peg$FAILED; if (peg$silentFails === 0) { peg$fail(peg$c34); } } if (s1 === peg$FAILED) { if (input.substr(peg$currPos, 3) === peg$c41) { s1 = peg$c41; peg$currPos += 3; } else { s1 = peg$FAILED; if (peg$silentFails === 0) { peg$fail(peg$c42); } } if (s1 === peg$FAILED) { if (input.substr(peg$currPos, 4) === peg$c37) { s1 = peg$c37; peg$currPos += 4; } else { s1 = peg$FAILED; if (peg$silentFails === 0) { peg$fail(peg$c38); } } if (s1 === peg$FAILED) { if (input.substr(peg$currPos, 2) === peg$c35) { s1 = peg$c35; peg$currPos += 2; } else { s1 = peg$FAILED; if (peg$silentFails === 0) { peg$fail(peg$c36); } } if (s1 === peg$FAILED) { if (input.substr(peg$currPos, 4) === peg$c167) { s1 = peg$c167; peg$currPos += 4; } else { s1 = peg$FAILED; if (peg$silentFails === 0) { peg$fail(peg$c168); } } if (s1 === peg$FAILED) { if (input.substr(peg$currPos, 4) === peg$c169) { s1 = peg$c169; peg$currPos += 4; } else { s1 = peg$FAILED; if (peg$silentFails === 0) { peg$fail(peg$c170); } } if (s1 === peg$FAILED) { if (input.substr(peg$currPos, 2) === peg$c18) { s1 = peg$c18; peg$currPos += 2; } else { s1 = peg$FAILED; if (peg$silentFails === 0) { peg$fail(peg$c19); } } if (s1 === peg$FAILED) { if (input.substr(peg$currPos, 4) === peg$c20) { s1 = peg$c20; peg$currPos += 4; } else { s1 = peg$FAILED; if (peg$silentFails === 0) { peg$fail(peg$c21); } } if (s1 === peg$FAILED) { if (input.substr(peg$currPos, 4) === peg$c22) { s1 = peg$c22; peg$currPos += 4; } else { s1 = peg$FAILED; if (peg$silentFails === 0) { peg$fail(peg$c23); } } 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$c24) { s1 = peg$c24; peg$currPos += 2; } else { s1 = peg$FAILED; if (peg$silentFails === 0) { peg$fail(peg$c25); } } if (s1 === peg$FAILED) { if (input.substr(peg$currPos, 2) === peg$c71) { s1 = peg$c71; peg$currPos += 2; } else { s1 = peg$FAILED; if (peg$silentFails === 0) { peg$fail(peg$c72); } } } } } } } } } } } } } } 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$FAILED; } if (s2 === peg$FAILED) { s2 = peg$parseEOF(); } if (s2 !== peg$FAILED) { s1 = [s1, s2]; s0 = s1; } else { peg$currPos = s0; s0 = peg$FAILED; } } else { peg$currPos = s0; s0 = peg$FAILED; } 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$c106; peg$currPos++; } else { s2 = peg$FAILED; if (peg$silentFails === 0) { peg$fail(peg$c107); } } if (s2 === peg$FAILED) { if (input.charCodeAt(peg$currPos) === 39) { s2 = peg$c101; peg$currPos++; } else { s2 = peg$FAILED; if (peg$silentFails === 0) { peg$fail(peg$c102); } } if (s2 === peg$FAILED) { if (input.charCodeAt(peg$currPos) === 96) { s2 = peg$c112; peg$currPos++; } else { s2 = peg$FAILED; if (peg$silentFails === 0) { peg$fail(peg$c113); } } if (s2 === peg$FAILED) { if (input.substr(peg$currPos, 2) === peg$c123) { s2 = peg$c123; peg$currPos += 2; } else { s2 = peg$FAILED; if (peg$silentFails === 0) { peg$fail(peg$c124); } } 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); } } } } } } } peg$silentFails--; if (s2 !== peg$FAILED) { peg$currPos = s1; s1 = void 0; } else { s1 = peg$FAILED; } 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$c85); } } 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$c85); } } } if (s2 !== peg$FAILED) { s1 = [s1, s2]; s0 = s1; } else { peg$currPos = s0; s0 = peg$FAILED; } } else { peg$currPos = s0; s0 = peg$FAILED; } 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$c85); } } peg$silentFails--; if (s1 === peg$FAILED) { s0 = void 0; } else { peg$currPos = s0; s0 = peg$FAILED; } 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 < input.length ? input.charAt(peg$maxFailPos) : null, peg$maxFailPos < input.length ? peg$computeLocation(peg$maxFailPos, peg$maxFailPos + 1) : peg$computeLocation(peg$maxFailPos, peg$maxFailPos) ); } } return { SyntaxError: peg$SyntaxError, parse: peg$parse }; })() module.exports.SyntaxError = parser.SyntaxError