From ad20ce8eecfcb03bdc76dc842ae4927d084029c6 Mon Sep 17 00:00:00 2001 From: Jordan Klassen Date: Tue, 15 Mar 2016 07:47:12 -0700 Subject: [PATCH 01/20] wip: adding arithmetic statement support --- grammar.pegjs | 10 + parser.js | 1086 +++++++++++++++++++++++++++---------------------- 2 files changed, 601 insertions(+), 495 deletions(-) diff --git a/grammar.pegjs b/grammar.pegjs index 0de4795..428c8fc 100644 --- a/grammar.pegjs +++ b/grammar.pegjs @@ -8,6 +8,7 @@ statementList statement = statement:( subshell + / arithmeticStatement / bashExtensions / command / variableAssignment @@ -23,6 +24,9 @@ chainedStatement subshell "a subshell" = "(" space* statements:statementList space* ")" +arithmeticStatement "an arithmetic statement" + = "((" expression:arithmetic "))" + command "a single command" = pre:((variableAssignment / redirect) space+)* name:(commandName / builtinCommandName) @@ -140,6 +144,9 @@ commandSubstitution parenCommandSubstitution = '$(' commands:statementList ')' +arithmeticSubstitution + = '$((' expression:arithmetic '))' + backQuote = '`' input:backQuoteChar+ '`' @@ -200,6 +207,9 @@ keyword ) ( spaceNL+ / EOF ) +arithmetic + = commandName + continuationStart = &( keyword / '"' / "'" / '`' / "$(" / "${" ) .* diff --git a/parser.js b/parser.js index 48f4f91..6134340 100644 --- a/parser.js +++ b/parser.js @@ -103,8 +103,13 @@ var parser=(function() { statements: statements, } }, - peg$c14 = { type: "other", description: "a single command" }, - peg$c15 = function(pre, name, post, pipe) { + peg$c14 = { type: "other", description: "an arithmetic statement" }, + peg$c15 = "((", + peg$c16 = { type: "literal", value: "((", description: "\"((\"" }, + peg$c17 = "))", + peg$c18 = { type: "literal", value: "))", description: "\"))\"" }, + peg$c19 = { type: "other", description: "a single command" }, + peg$c20 = function(pre, name, post, pipe) { var command = { type: 'command', command: name, @@ -135,19 +140,19 @@ var parser=(function() { return command }, - peg$c16 = function(test) { + peg$c21 = 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) { + peg$c22 = { type: "other", description: "an if/elif/else statement" }, + peg$c23 = "if", + peg$c24 = { type: "literal", value: "if", description: "\"if\"" }, + peg$c25 = "then", + peg$c26 = { type: "literal", value: "then", description: "\"then\"" }, + peg$c27 = "else", + peg$c28 = { type: "literal", value: "else", description: "\"else\"" }, + peg$c29 = "fi", + peg$c30 = { type: "literal", value: "fi", description: "\"fi\"" }, + peg$c31 = function(test, body, elifBlocks, elseBody) { return { type: 'ifElse', test: test, @@ -156,41 +161,41 @@ var parser=(function() { elseBody: elseBody ? elseBody[1] : null, } }, - peg$c27 = "elif", - peg$c28 = { type: "literal", value: "elif", description: "\"elif\"" }, - peg$c29 = function(test, body) { + peg$c32 = "elif", + peg$c33 = { type: "literal", value: "elif", description: "\"elif\"" }, + peg$c34 = 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) { + peg$c35 = { type: "other", description: "a while/until loop" }, + peg$c36 = "while", + peg$c37 = { type: "literal", value: "while", description: "\"while\"" }, + peg$c38 = "until", + peg$c39 = { type: "literal", value: "until", description: "\"until\"" }, + peg$c40 = "do", + peg$c41 = { type: "literal", value: "do", description: "\"do\"" }, + peg$c42 = "done", + peg$c43 = { type: "literal", value: "done", description: "\"done\"" }, + peg$c44 = 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) { + peg$c45 = { type: "other", description: "a for loop" }, + peg$c46 = "for", + peg$c47 = { type: "literal", value: "for", description: "\"for\"" }, + peg$c48 = "in", + peg$c49 = { type: "literal", value: "in", description: "\"in\"" }, + peg$c50 = ";", + peg$c51 = { type: "literal", value: ";", description: "\";\"" }, + peg$c52 = "\n", + peg$c53 = { type: "literal", value: "\n", description: "\"\\n\"" }, + peg$c54 = function(loopVar, subjects, body) { return { type: 'forLoop', loopVariable: loopVar, @@ -198,136 +203,138 @@ var parser=(function() { 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) { + peg$c55 = { type: "other", description: "time builtin" }, + peg$c56 = "time", + peg$c57 = { type: "literal", value: "time", description: "\"time\"" }, + peg$c58 = "-", + peg$c59 = { type: "literal", value: "-", description: "\"-\"" }, + peg$c60 = /^[a-z]/, + peg$c61 = { type: "class", value: "[a-z]", description: "[a-z]" }, + peg$c62 = 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) { + peg$c63 = { type: "other", description: "declare builtin" }, + peg$c64 = "declare", + peg$c65 = { type: "literal", value: "declare", description: "\"declare\"" }, + peg$c66 = "typeset", + peg$c67 = { type: "literal", value: "typeset", description: "\"typeset\"" }, + peg$c68 = /^[^\n]/, + peg$c69 = { type: "class", value: "[^\\n]", description: "[^\\n]" }, + peg$c70 = { type: "other", description: "a variable assignment" }, + peg$c71 = "=", + peg$c72 = { type: "literal", value: "=", description: "\"=\"" }, + peg$c73 = function(name, value) { return {type: 'variableAssignment', name: name, value: value} }, - peg$c69 = { type: "other", description: "command name" }, - peg$c70 = function(name) { + peg$c74 = { type: "other", description: "command name" }, + peg$c75 = 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) { + peg$c76 = "[[", + peg$c77 = { type: "literal", value: "[[", description: "\"[[\"" }, + peg$c78 = "[", + peg$c79 = { type: "literal", value: "[", description: "\"[\"" }, + peg$c80 = { type: "other", description: "command argument" }, + peg$c81 = { type: "other", description: "concatenation of strings and/or variables" }, + peg$c82 = 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() { + peg$c83 = { type: "other", description: "bareword" }, + peg$c84 = "#", + peg$c85 = { type: "literal", value: "#", description: "\"#\"" }, + peg$c86 = function(cs) { return literal(cs) }, + peg$c87 = "\\", + peg$c88 = { type: "literal", value: "\\", description: "\"\\\\\"" }, + peg$c89 = function(chr) { return chr }, + peg$c90 = { type: "any", description: "any character" }, + peg$c91 = /^[$"';&<>\n()[*?|` ]/, + peg$c92 = { type: "class", value: "[$\"';&<>\\n()\\[*?|` ]", description: "[$\"';&<>\\n()\\[*?|` ]" }, + peg$c93 = "*", + peg$c94 = { type: "literal", value: "*", description: "\"*\"" }, + peg$c95 = "?", + peg$c96 = { type: "literal", value: "?", description: "\"?\"" }, + peg$c97 = 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) { + peg$c98 = "]", + peg$c99 = { type: "literal", value: "]", description: "\"]\"" }, + peg$c100 = "$", + peg$c101 = { type: "literal", value: "$", description: "\"$\"" }, + peg$c102 = "{", + peg$c103 = { type: "literal", value: "{", description: "\"{\"" }, + peg$c104 = "}", + peg$c105 = { type: "literal", value: "}", description: "\"}\"" }, + peg$c106 = "'", + peg$c107 = { type: "literal", value: "'", description: "\"'\"" }, + peg$c108 = /^[^']/, + peg$c109 = { type: "class", value: "[^']", description: "[^']" }, + peg$c110 = function(inner) { return literal(inner) }, + peg$c111 = "\"", + peg$c112 = { type: "literal", value: "\"", description: "\"\\\"\"" }, + peg$c113 = 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) { + peg$c114 = "\\\\", + peg$c115 = { type: "literal", value: "\\\\", description: "\"\\\\\\\\\"" }, + peg$c116 = function() { return '\\' }, + peg$c117 = "`", + peg$c118 = { type: "literal", value: "`", description: "\"`\"" }, + peg$c119 = 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) { + peg$c120 = /^[a-zA-Z0-9_]/, + peg$c121 = { type: "class", value: "[a-zA-Z0-9_]", description: "[a-zA-Z0-9_]" }, + peg$c122 = function() { return text() }, + peg$c123 = "${", + peg$c124 = { type: "literal", value: "${", description: "\"${\"" }, + peg$c125 = /^[^}]/, + peg$c126 = { type: "class", value: "[^}]", description: "[^}]" }, + peg$c127 = function(expr) { return { type: 'variableSubstitution', expression: join(expr), // TODO subParser } }, - peg$c123 = "$(", - peg$c124 = { type: "literal", value: "$(", description: "\"$(\"" }, - peg$c125 = function(commands) { + peg$c128 = "$(", + peg$c129 = { type: "literal", value: "$(", description: "\"$(\"" }, + peg$c130 = function(commands) { return { type: 'commandSubstitution', commands: commands } }, - peg$c126 = function(input) { + peg$c131 = "$((", + peg$c132 = { type: "literal", value: "$((", description: "\"$((\"" }, + peg$c133 = 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) { + peg$c134 = "\\`", + peg$c135 = { type: "literal", value: "\\`", description: "\"\\\\`\"" }, + peg$c136 = function() { return '`' }, + peg$c137 = /^[<>]/, + peg$c138 = { type: "class", value: "[<>]", description: "[<>]" }, + peg$c139 = 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) { + peg$c140 = "<&", + peg$c141 = { type: "literal", value: "<&", description: "\"<&\"" }, + peg$c142 = ">&", + peg$c143 = { type: "literal", value: ">&", description: "\">&\"" }, + peg$c144 = function(fd, op, dest) { if (fd == null) fd = op[0] == '<' ? 0 : 1; return { type: 'moveFd', @@ -336,7 +343,7 @@ var parser=(function() { dest: dest } }, - peg$c138 = function(src, op, dest) { + peg$c145 = function(src, op, dest) { if (src == null) src = op[0] == '<' ? 0 : 1; return { type: 'duplicateFd', @@ -345,7 +352,7 @@ var parser=(function() { destFd: dest, } }, - peg$c139 = function(fd, op, filename) { + peg$c146 = function(fd, op, filename) { if (fd == null) fd = op[0] == '<' ? 0 : 1; return { type: 'redirectFd', @@ -354,41 +361,41 @@ var parser=(function() { 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) { + peg$c147 = ">|", + peg$c148 = { type: "literal", value: ">|", description: "\">|\"" }, + peg$c149 = ">>", + peg$c150 = { type: "literal", value: ">>", description: "\">>\"" }, + peg$c151 = "&>>", + peg$c152 = { type: "literal", value: "&>>", description: "\"&>>\"" }, + peg$c153 = "&>", + peg$c154 = { type: "literal", value: "&>", description: "\"&>\"" }, + peg$c155 = "<", + peg$c156 = { type: "literal", value: "<", description: "\"<\"" }, + peg$c157 = ">", + peg$c158 = { type: "literal", value: ">", description: "\">\"" }, + peg$c159 = /^[0-9]/, + peg$c160 = { type: "class", value: "[0-9]", description: "[0-9]" }, + peg$c161 = function(digits) { return parseInt(join(digits), 10) }, + peg$c162 = "&", + peg$c163 = { type: "literal", value: "&", description: "\"&\"" }, + peg$c164 = function(op) { return op == '\n' ? ';' : op }, - peg$c158 = "|", - peg$c159 = { type: "literal", value: "|", description: "\"|\"" }, - peg$c160 = function(command) { + peg$c165 = "|", + peg$c166 = { type: "literal", value: "|", description: "\"|\"" }, + peg$c167 = 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$c168 = { type: "other", description: "whitespace" }, + peg$c169 = " ", + peg$c170 = { type: "literal", value: " ", description: "\" \"" }, + peg$c171 = "\t", + peg$c172 = { type: "literal", value: "\t", description: "\"\\t\"" }, + peg$c173 = { type: "other", description: "a comment" }, + peg$c174 = "case", + peg$c175 = { type: "literal", value: "case", description: "\"case\"" }, + peg$c176 = "esac", + peg$c177 = { type: "literal", value: "esac", description: "\"esac\"" }, peg$currPos = 0, peg$savedPos = 0, @@ -721,17 +728,20 @@ var parser=(function() { s0 = peg$currPos; s1 = peg$parsesubshell(); if (s1 === peg$FAILED) { - s1 = peg$parsebashExtensions(); + s1 = peg$parsearithmeticStatement(); if (s1 === peg$FAILED) { - s1 = peg$parsecommand(); + s1 = peg$parsebashExtensions(); if (s1 === peg$FAILED) { - s1 = peg$parsevariableAssignment(); + s1 = peg$parsecommand(); if (s1 === peg$FAILED) { - s1 = peg$parseifBlock(); + s1 = peg$parsevariableAssignment(); if (s1 === peg$FAILED) { - s1 = peg$parseconditionalLoop(); + s1 = peg$parseifBlock(); if (s1 === peg$FAILED) { - s1 = peg$parseforLoop(); + s1 = peg$parseconditionalLoop(); + if (s1 === peg$FAILED) { + s1 = peg$parseforLoop(); + } } } } @@ -896,6 +906,52 @@ var parser=(function() { return s0; } + function peg$parsearithmeticStatement() { + var s0, s1, s2, s3; + + peg$silentFails++; + s0 = peg$currPos; + if (input.substr(peg$currPos, 2) === peg$c15) { + s1 = peg$c15; + peg$currPos += 2; + } else { + s1 = peg$FAILED; + if (peg$silentFails === 0) { peg$fail(peg$c16); } + } + if (s1 !== peg$FAILED) { + s2 = peg$parsecommandName(); + if (s2 !== peg$FAILED) { + if (input.substr(peg$currPos, 2) === peg$c17) { + s3 = peg$c17; + peg$currPos += 2; + } else { + s3 = peg$FAILED; + if (peg$silentFails === 0) { peg$fail(peg$c18); } + } + 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$c14); } + } + + return s0; + } + function peg$parsecommand() { var s0, s1, s2, s3, s4, s5, s6; @@ -1049,7 +1105,7 @@ var parser=(function() { } if (s4 !== peg$FAILED) { peg$savedPos = s0; - s1 = peg$c15(s1, s2, s3, s4); + s1 = peg$c20(s1, s2, s3, s4); s0 = s1; } else { peg$currPos = s0; @@ -1070,7 +1126,7 @@ var parser=(function() { peg$silentFails--; if (s0 === peg$FAILED) { s1 = peg$FAILED; - if (peg$silentFails === 0) { peg$fail(peg$c14); } + if (peg$silentFails === 0) { peg$fail(peg$c19); } } return s0; @@ -1083,7 +1139,7 @@ var parser=(function() { s1 = peg$parsescript(); if (s1 !== peg$FAILED) { peg$savedPos = s0; - s1 = peg$c16(s1); + s1 = peg$c21(s1); } s0 = s1; @@ -1095,12 +1151,12 @@ var parser=(function() { peg$silentFails++; s0 = peg$currPos; - if (input.substr(peg$currPos, 2) === peg$c18) { - s1 = peg$c18; + if (input.substr(peg$currPos, 2) === peg$c23) { + s1 = peg$c23; peg$currPos += 2; } else { s1 = peg$FAILED; - if (peg$silentFails === 0) { peg$fail(peg$c19); } + if (peg$silentFails === 0) { peg$fail(peg$c24); } } if (s1 !== peg$FAILED) { s2 = []; @@ -1116,12 +1172,12 @@ var parser=(function() { if (s2 !== peg$FAILED) { s3 = peg$parsecondition(); if (s3 !== peg$FAILED) { - if (input.substr(peg$currPos, 4) === peg$c20) { - s4 = peg$c20; + if (input.substr(peg$currPos, 4) === peg$c25) { + s4 = peg$c25; peg$currPos += 4; } else { s4 = peg$FAILED; - if (peg$silentFails === 0) { peg$fail(peg$c21); } + if (peg$silentFails === 0) { peg$fail(peg$c26); } } if (s4 !== peg$FAILED) { s5 = []; @@ -1145,12 +1201,12 @@ var parser=(function() { } if (s7 !== peg$FAILED) { s8 = peg$currPos; - if (input.substr(peg$currPos, 4) === peg$c22) { - s9 = peg$c22; + if (input.substr(peg$currPos, 4) === peg$c27) { + s9 = peg$c27; peg$currPos += 4; } else { s9 = peg$FAILED; - if (peg$silentFails === 0) { peg$fail(peg$c23); } + if (peg$silentFails === 0) { peg$fail(peg$c28); } } if (s9 !== peg$FAILED) { s10 = peg$parsescript(); @@ -1169,16 +1225,16 @@ var parser=(function() { s8 = null; } if (s8 !== peg$FAILED) { - if (input.substr(peg$currPos, 2) === peg$c24) { - s9 = peg$c24; + if (input.substr(peg$currPos, 2) === peg$c29) { + s9 = peg$c29; peg$currPos += 2; } else { s9 = peg$FAILED; - if (peg$silentFails === 0) { peg$fail(peg$c25); } + if (peg$silentFails === 0) { peg$fail(peg$c30); } } if (s9 !== peg$FAILED) { peg$savedPos = s0; - s1 = peg$c26(s3, s6, s7, s8); + s1 = peg$c31(s3, s6, s7, s8); s0 = s1; } else { peg$currPos = s0; @@ -1219,7 +1275,7 @@ var parser=(function() { peg$silentFails--; if (s0 === peg$FAILED) { s1 = peg$FAILED; - if (peg$silentFails === 0) { peg$fail(peg$c17); } + if (peg$silentFails === 0) { peg$fail(peg$c22); } } return s0; @@ -1229,12 +1285,12 @@ var parser=(function() { var s0, s1, s2, s3, s4, s5, s6; s0 = peg$currPos; - if (input.substr(peg$currPos, 4) === peg$c27) { - s1 = peg$c27; + 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$c28); } + if (peg$silentFails === 0) { peg$fail(peg$c33); } } if (s1 !== peg$FAILED) { s2 = []; @@ -1250,12 +1306,12 @@ var parser=(function() { if (s2 !== peg$FAILED) { s3 = peg$parsecondition(); if (s3 !== peg$FAILED) { - if (input.substr(peg$currPos, 4) === peg$c20) { - s4 = peg$c20; + if (input.substr(peg$currPos, 4) === peg$c25) { + s4 = peg$c25; peg$currPos += 4; } else { s4 = peg$FAILED; - if (peg$silentFails === 0) { peg$fail(peg$c21); } + if (peg$silentFails === 0) { peg$fail(peg$c26); } } if (s4 !== peg$FAILED) { s5 = []; @@ -1272,7 +1328,7 @@ var parser=(function() { s6 = peg$parsescript(); if (s6 !== peg$FAILED) { peg$savedPos = s0; - s1 = peg$c29(s3, s6); + s1 = peg$c34(s3, s6); s0 = s1; } else { peg$currPos = s0; @@ -1307,20 +1363,20 @@ var parser=(function() { peg$silentFails++; s0 = peg$currPos; - if (input.substr(peg$currPos, 5) === peg$c31) { - s1 = peg$c31; + if (input.substr(peg$currPos, 5) === peg$c36) { + s1 = peg$c36; peg$currPos += 5; } else { s1 = peg$FAILED; - if (peg$silentFails === 0) { peg$fail(peg$c32); } + if (peg$silentFails === 0) { peg$fail(peg$c37); } } if (s1 === peg$FAILED) { - if (input.substr(peg$currPos, 5) === peg$c33) { - s1 = peg$c33; + if (input.substr(peg$currPos, 5) === peg$c38) { + s1 = peg$c38; peg$currPos += 5; } else { s1 = peg$FAILED; - if (peg$silentFails === 0) { peg$fail(peg$c34); } + if (peg$silentFails === 0) { peg$fail(peg$c39); } } } if (s1 !== peg$FAILED) { @@ -1337,12 +1393,12 @@ var parser=(function() { if (s2 !== peg$FAILED) { s3 = peg$parsecondition(); if (s3 !== peg$FAILED) { - if (input.substr(peg$currPos, 2) === peg$c35) { - s4 = peg$c35; + if (input.substr(peg$currPos, 2) === peg$c40) { + s4 = peg$c40; peg$currPos += 2; } else { s4 = peg$FAILED; - if (peg$silentFails === 0) { peg$fail(peg$c36); } + if (peg$silentFails === 0) { peg$fail(peg$c41); } } if (s4 !== peg$FAILED) { s5 = []; @@ -1358,16 +1414,16 @@ var parser=(function() { if (s5 !== peg$FAILED) { s6 = peg$parsescript(); if (s6 !== peg$FAILED) { - if (input.substr(peg$currPos, 4) === peg$c37) { - s7 = peg$c37; + if (input.substr(peg$currPos, 4) === peg$c42) { + s7 = peg$c42; peg$currPos += 4; } else { s7 = peg$FAILED; - if (peg$silentFails === 0) { peg$fail(peg$c38); } + if (peg$silentFails === 0) { peg$fail(peg$c43); } } if (s7 !== peg$FAILED) { peg$savedPos = s0; - s1 = peg$c39(s1, s3, s6); + s1 = peg$c44(s1, s3, s6); s0 = s1; } else { peg$currPos = s0; @@ -1400,7 +1456,7 @@ var parser=(function() { peg$silentFails--; if (s0 === peg$FAILED) { s1 = peg$FAILED; - if (peg$silentFails === 0) { peg$fail(peg$c30); } + if (peg$silentFails === 0) { peg$fail(peg$c35); } } return s0; @@ -1411,12 +1467,12 @@ var parser=(function() { peg$silentFails++; s0 = peg$currPos; - if (input.substr(peg$currPos, 3) === peg$c41) { - s1 = peg$c41; + if (input.substr(peg$currPos, 3) === peg$c46) { + s1 = peg$c46; peg$currPos += 3; } else { s1 = peg$FAILED; - if (peg$silentFails === 0) { peg$fail(peg$c42); } + if (peg$silentFails === 0) { peg$fail(peg$c47); } } if (s1 !== peg$FAILED) { s2 = []; @@ -1444,12 +1500,12 @@ var parser=(function() { } if (s4 !== peg$FAILED) { s5 = peg$currPos; - if (input.substr(peg$currPos, 2) === peg$c43) { - s6 = peg$c43; + if (input.substr(peg$currPos, 2) === peg$c48) { + s6 = peg$c48; peg$currPos += 2; } else { s6 = peg$FAILED; - if (peg$silentFails === 0) { peg$fail(peg$c44); } + if (peg$silentFails === 0) { peg$fail(peg$c49); } } if (s6 !== peg$FAILED) { s7 = []; @@ -1527,19 +1583,19 @@ var parser=(function() { } if (s6 !== peg$FAILED) { if (input.charCodeAt(peg$currPos) === 59) { - s7 = peg$c45; + s7 = peg$c50; peg$currPos++; } else { s7 = peg$FAILED; - if (peg$silentFails === 0) { peg$fail(peg$c46); } + if (peg$silentFails === 0) { peg$fail(peg$c51); } } if (s7 === peg$FAILED) { if (input.charCodeAt(peg$currPos) === 10) { - s7 = peg$c47; + s7 = peg$c52; peg$currPos++; } else { s7 = peg$FAILED; - if (peg$silentFails === 0) { peg$fail(peg$c48); } + if (peg$silentFails === 0) { peg$fail(peg$c53); } } } if (s7 !== peg$FAILED) { @@ -1550,12 +1606,12 @@ var parser=(function() { s9 = peg$parsespaceNL(); } if (s8 !== peg$FAILED) { - if (input.substr(peg$currPos, 2) === peg$c35) { - s9 = peg$c35; + if (input.substr(peg$currPos, 2) === peg$c40) { + s9 = peg$c40; peg$currPos += 2; } else { s9 = peg$FAILED; - if (peg$silentFails === 0) { peg$fail(peg$c36); } + if (peg$silentFails === 0) { peg$fail(peg$c41); } } if (s9 !== peg$FAILED) { s10 = []; @@ -1578,16 +1634,16 @@ var parser=(function() { s13 = peg$parsespaceNL(); } if (s12 !== peg$FAILED) { - if (input.substr(peg$currPos, 4) === peg$c37) { - s13 = peg$c37; + if (input.substr(peg$currPos, 4) === peg$c42) { + s13 = peg$c42; peg$currPos += 4; } else { s13 = peg$FAILED; - if (peg$silentFails === 0) { peg$fail(peg$c38); } + if (peg$silentFails === 0) { peg$fail(peg$c43); } } if (s13 !== peg$FAILED) { peg$savedPos = s0; - s1 = peg$c49(s3, s5, s11); + s1 = peg$c54(s3, s5, s11); s0 = s1; } else { peg$currPos = s0; @@ -1644,7 +1700,7 @@ var parser=(function() { peg$silentFails--; if (s0 === peg$FAILED) { s1 = peg$FAILED; - if (peg$silentFails === 0) { peg$fail(peg$c40); } + if (peg$silentFails === 0) { peg$fail(peg$c45); } } return s0; @@ -1666,12 +1722,12 @@ var parser=(function() { peg$silentFails++; s0 = peg$currPos; - if (input.substr(peg$currPos, 4) === peg$c51) { - s1 = peg$c51; + if (input.substr(peg$currPos, 4) === peg$c56) { + s1 = peg$c56; peg$currPos += 4; } else { s1 = peg$FAILED; - if (peg$silentFails === 0) { peg$fail(peg$c52); } + if (peg$silentFails === 0) { peg$fail(peg$c57); } } if (s1 !== peg$FAILED) { s2 = []; @@ -1688,30 +1744,30 @@ var parser=(function() { s3 = []; s4 = peg$currPos; if (input.charCodeAt(peg$currPos) === 45) { - s5 = peg$c53; + s5 = peg$c58; peg$currPos++; } else { s5 = peg$FAILED; - if (peg$silentFails === 0) { peg$fail(peg$c54); } + if (peg$silentFails === 0) { peg$fail(peg$c59); } } if (s5 !== peg$FAILED) { s6 = []; - if (peg$c55.test(input.charAt(peg$currPos))) { + if (peg$c60.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 (peg$silentFails === 0) { peg$fail(peg$c61); } } if (s7 !== peg$FAILED) { while (s7 !== peg$FAILED) { s6.push(s7); - if (peg$c55.test(input.charAt(peg$currPos))) { + if (peg$c60.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 (peg$silentFails === 0) { peg$fail(peg$c61); } } } } else { @@ -1747,30 +1803,30 @@ var parser=(function() { s3.push(s4); s4 = peg$currPos; if (input.charCodeAt(peg$currPos) === 45) { - s5 = peg$c53; + s5 = peg$c58; peg$currPos++; } else { s5 = peg$FAILED; - if (peg$silentFails === 0) { peg$fail(peg$c54); } + if (peg$silentFails === 0) { peg$fail(peg$c59); } } if (s5 !== peg$FAILED) { s6 = []; - if (peg$c55.test(input.charAt(peg$currPos))) { + if (peg$c60.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 (peg$silentFails === 0) { peg$fail(peg$c61); } } if (s7 !== peg$FAILED) { while (s7 !== peg$FAILED) { s6.push(s7); - if (peg$c55.test(input.charAt(peg$currPos))) { + if (peg$c60.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 (peg$silentFails === 0) { peg$fail(peg$c61); } } } } else { @@ -1807,7 +1863,7 @@ var parser=(function() { s4 = peg$parsestatementList(); if (s4 !== peg$FAILED) { peg$savedPos = s0; - s1 = peg$c57(s3, s4); + s1 = peg$c62(s3, s4); s0 = s1; } else { peg$currPos = s0; @@ -1828,7 +1884,7 @@ var parser=(function() { peg$silentFails--; if (s0 === peg$FAILED) { s1 = peg$FAILED; - if (peg$silentFails === 0) { peg$fail(peg$c50); } + if (peg$silentFails === 0) { peg$fail(peg$c55); } } return s0; @@ -1839,40 +1895,40 @@ var parser=(function() { peg$silentFails++; s0 = peg$currPos; - if (input.substr(peg$currPos, 7) === peg$c59) { - s1 = peg$c59; + if (input.substr(peg$currPos, 7) === peg$c64) { + s1 = peg$c64; peg$currPos += 7; } else { s1 = peg$FAILED; - if (peg$silentFails === 0) { peg$fail(peg$c60); } + if (peg$silentFails === 0) { peg$fail(peg$c65); } } if (s1 === peg$FAILED) { - if (input.substr(peg$currPos, 7) === peg$c61) { - s1 = peg$c61; + if (input.substr(peg$currPos, 7) === peg$c66) { + s1 = peg$c66; peg$currPos += 7; } else { s1 = peg$FAILED; - if (peg$silentFails === 0) { peg$fail(peg$c62); } + if (peg$silentFails === 0) { peg$fail(peg$c67); } } } if (s1 !== peg$FAILED) { s2 = []; - if (peg$c63.test(input.charAt(peg$currPos))) { + if (peg$c68.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 (peg$silentFails === 0) { peg$fail(peg$c69); } } if (s3 !== peg$FAILED) { while (s3 !== peg$FAILED) { s2.push(s3); - if (peg$c63.test(input.charAt(peg$currPos))) { + if (peg$c68.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 (peg$silentFails === 0) { peg$fail(peg$c69); } } } } else { @@ -1880,19 +1936,19 @@ var parser=(function() { } if (s2 !== peg$FAILED) { if (input.charCodeAt(peg$currPos) === 59) { - s3 = peg$c45; + s3 = peg$c50; peg$currPos++; } else { s3 = peg$FAILED; - if (peg$silentFails === 0) { peg$fail(peg$c46); } + if (peg$silentFails === 0) { peg$fail(peg$c51); } } if (s3 === peg$FAILED) { if (input.charCodeAt(peg$currPos) === 10) { - s3 = peg$c47; + s3 = peg$c52; peg$currPos++; } else { s3 = peg$FAILED; - if (peg$silentFails === 0) { peg$fail(peg$c48); } + if (peg$silentFails === 0) { peg$fail(peg$c53); } } } if (s3 !== peg$FAILED) { @@ -1913,7 +1969,7 @@ var parser=(function() { peg$silentFails--; if (s0 === peg$FAILED) { s1 = peg$FAILED; - if (peg$silentFails === 0) { peg$fail(peg$c58); } + if (peg$silentFails === 0) { peg$fail(peg$c63); } } return s0; @@ -1927,11 +1983,11 @@ var parser=(function() { s1 = peg$parsewritableVariableName(); if (s1 !== peg$FAILED) { if (input.charCodeAt(peg$currPos) === 61) { - s2 = peg$c66; + s2 = peg$c71; peg$currPos++; } else { s2 = peg$FAILED; - if (peg$silentFails === 0) { peg$fail(peg$c67); } + if (peg$silentFails === 0) { peg$fail(peg$c72); } } if (s2 !== peg$FAILED) { s3 = peg$parseargument(); @@ -1940,7 +1996,7 @@ var parser=(function() { } if (s3 !== peg$FAILED) { peg$savedPos = s0; - s1 = peg$c68(s1, s3); + s1 = peg$c73(s1, s3); s0 = s1; } else { peg$currPos = s0; @@ -1957,7 +2013,7 @@ var parser=(function() { peg$silentFails--; if (s0 === peg$FAILED) { s1 = peg$FAILED; - if (peg$silentFails === 0) { peg$fail(peg$c65); } + if (peg$silentFails === 0) { peg$fail(peg$c70); } } return s0; @@ -2007,7 +2063,7 @@ var parser=(function() { } if (s4 !== peg$FAILED) { peg$savedPos = s0; - s1 = peg$c70(s4); + s1 = peg$c75(s4); s0 = s1; } else { peg$currPos = s0; @@ -2028,7 +2084,7 @@ var parser=(function() { peg$silentFails--; if (s0 === peg$FAILED) { s1 = peg$FAILED; - if (peg$silentFails === 0) { peg$fail(peg$c69); } + if (peg$silentFails === 0) { peg$fail(peg$c74); } } return s0; @@ -2037,20 +2093,20 @@ var parser=(function() { function peg$parsebuiltinCommandName() { var s0; - if (input.substr(peg$currPos, 2) === peg$c71) { - s0 = peg$c71; + if (input.substr(peg$currPos, 2) === peg$c76) { + s0 = peg$c76; peg$currPos += 2; } else { s0 = peg$FAILED; - if (peg$silentFails === 0) { peg$fail(peg$c72); } + if (peg$silentFails === 0) { peg$fail(peg$c77); } } if (s0 === peg$FAILED) { if (input.charCodeAt(peg$currPos) === 91) { - s0 = peg$c73; + s0 = peg$c78; peg$currPos++; } else { s0 = peg$FAILED; - if (peg$silentFails === 0) { peg$fail(peg$c74); } + if (peg$silentFails === 0) { peg$fail(peg$c79); } } } @@ -2068,7 +2124,7 @@ var parser=(function() { peg$silentFails--; if (s0 === peg$FAILED) { s1 = peg$FAILED; - if (peg$silentFails === 0) { peg$fail(peg$c75); } + if (peg$silentFails === 0) { peg$fail(peg$c80); } } return s0; @@ -2127,13 +2183,13 @@ var parser=(function() { } if (s1 !== peg$FAILED) { peg$savedPos = s0; - s1 = peg$c77(s1); + s1 = peg$c82(s1); } s0 = s1; peg$silentFails--; if (s0 === peg$FAILED) { s1 = peg$FAILED; - if (peg$silentFails === 0) { peg$fail(peg$c76); } + if (peg$silentFails === 0) { peg$fail(peg$c81); } } return s0; @@ -2147,11 +2203,11 @@ var parser=(function() { s1 = peg$currPos; peg$silentFails++; if (input.charCodeAt(peg$currPos) === 35) { - s2 = peg$c79; + s2 = peg$c84; peg$currPos++; } else { s2 = peg$FAILED; - if (peg$silentFails === 0) { peg$fail(peg$c80); } + if (peg$silentFails === 0) { peg$fail(peg$c85); } } peg$silentFails--; if (s2 === peg$FAILED) { @@ -2173,7 +2229,7 @@ var parser=(function() { } if (s2 !== peg$FAILED) { peg$savedPos = s0; - s1 = peg$c81(s2); + s1 = peg$c86(s2); s0 = s1; } else { peg$currPos = s0; @@ -2186,7 +2242,7 @@ var parser=(function() { peg$silentFails--; if (s0 === peg$FAILED) { s1 = peg$FAILED; - if (peg$silentFails === 0) { peg$fail(peg$c78); } + if (peg$silentFails === 0) { peg$fail(peg$c83); } } return s0; @@ -2197,17 +2253,17 @@ var parser=(function() { s0 = peg$currPos; if (input.charCodeAt(peg$currPos) === 92) { - s1 = peg$c82; + s1 = peg$c87; peg$currPos++; } else { s1 = peg$FAILED; - if (peg$silentFails === 0) { peg$fail(peg$c83); } + if (peg$silentFails === 0) { peg$fail(peg$c88); } } if (s1 !== peg$FAILED) { s2 = peg$parsebarewordMeta(); if (s2 !== peg$FAILED) { peg$savedPos = s0; - s1 = peg$c84(s2); + s1 = peg$c89(s2); s0 = s1; } else { peg$currPos = s0; @@ -2235,11 +2291,11 @@ var parser=(function() { peg$currPos++; } else { s2 = peg$FAILED; - if (peg$silentFails === 0) { peg$fail(peg$c85); } + if (peg$silentFails === 0) { peg$fail(peg$c90); } } if (s2 !== peg$FAILED) { peg$savedPos = s0; - s1 = peg$c84(s2); + s1 = peg$c89(s2); s0 = s1; } else { peg$currPos = s0; @@ -2257,12 +2313,12 @@ var parser=(function() { function peg$parsebarewordMeta() { var s0; - if (peg$c86.test(input.charAt(peg$currPos))) { + if (peg$c91.test(input.charAt(peg$currPos))) { s0 = input.charAt(peg$currPos); peg$currPos++; } else { s0 = peg$FAILED; - if (peg$silentFails === 0) { peg$fail(peg$c87); } + if (peg$silentFails === 0) { peg$fail(peg$c92); } } return s0; @@ -2281,19 +2337,19 @@ var parser=(function() { if (s1 !== peg$FAILED) { s2 = []; if (input.charCodeAt(peg$currPos) === 42) { - s3 = peg$c88; + s3 = peg$c93; peg$currPos++; } else { s3 = peg$FAILED; - if (peg$silentFails === 0) { peg$fail(peg$c89); } + if (peg$silentFails === 0) { peg$fail(peg$c94); } } if (s3 === peg$FAILED) { if (input.charCodeAt(peg$currPos) === 63) { - s3 = peg$c90; + s3 = peg$c95; peg$currPos++; } else { s3 = peg$FAILED; - if (peg$silentFails === 0) { peg$fail(peg$c91); } + if (peg$silentFails === 0) { peg$fail(peg$c96); } } if (s3 === peg$FAILED) { s3 = peg$parsecharacterRange(); @@ -2306,19 +2362,19 @@ var parser=(function() { while (s3 !== peg$FAILED) { s2.push(s3); if (input.charCodeAt(peg$currPos) === 42) { - s3 = peg$c88; + s3 = peg$c93; peg$currPos++; } else { s3 = peg$FAILED; - if (peg$silentFails === 0) { peg$fail(peg$c89); } + if (peg$silentFails === 0) { peg$fail(peg$c94); } } if (s3 === peg$FAILED) { if (input.charCodeAt(peg$currPos) === 63) { - s3 = peg$c90; + s3 = peg$c95; peg$currPos++; } else { s3 = peg$FAILED; - if (peg$silentFails === 0) { peg$fail(peg$c91); } + if (peg$silentFails === 0) { peg$fail(peg$c96); } } if (s3 === peg$FAILED) { s3 = peg$parsecharacterRange(); @@ -2340,7 +2396,7 @@ var parser=(function() { } if (s3 !== peg$FAILED) { peg$savedPos = s0; - s1 = peg$c92(); + s1 = peg$c97(); s0 = s1; } else { peg$currPos = s0; @@ -2364,21 +2420,21 @@ var parser=(function() { s0 = peg$currPos; s1 = peg$currPos; if (input.charCodeAt(peg$currPos) === 91) { - s2 = peg$c73; + s2 = peg$c78; peg$currPos++; } else { s2 = peg$FAILED; - if (peg$silentFails === 0) { peg$fail(peg$c74); } + if (peg$silentFails === 0) { peg$fail(peg$c79); } } if (s2 !== peg$FAILED) { s3 = peg$currPos; peg$silentFails++; if (input.charCodeAt(peg$currPos) === 45) { - s4 = peg$c53; + s4 = peg$c58; peg$currPos++; } else { s4 = peg$FAILED; - if (peg$silentFails === 0) { peg$fail(peg$c54); } + if (peg$silentFails === 0) { peg$fail(peg$c59); } } peg$silentFails--; if (s4 === peg$FAILED) { @@ -2393,25 +2449,25 @@ var parser=(function() { peg$currPos++; } else { s4 = peg$FAILED; - if (peg$silentFails === 0) { peg$fail(peg$c85); } + if (peg$silentFails === 0) { peg$fail(peg$c90); } } if (s4 !== peg$FAILED) { if (input.charCodeAt(peg$currPos) === 45) { - s5 = peg$c53; + s5 = peg$c58; peg$currPos++; } else { s5 = peg$FAILED; - if (peg$silentFails === 0) { peg$fail(peg$c54); } + if (peg$silentFails === 0) { peg$fail(peg$c59); } } if (s5 !== peg$FAILED) { s6 = peg$currPos; peg$silentFails++; if (input.charCodeAt(peg$currPos) === 45) { - s7 = peg$c53; + s7 = peg$c58; peg$currPos++; } else { s7 = peg$FAILED; - if (peg$silentFails === 0) { peg$fail(peg$c54); } + if (peg$silentFails === 0) { peg$fail(peg$c59); } } peg$silentFails--; if (s7 === peg$FAILED) { @@ -2426,15 +2482,15 @@ var parser=(function() { peg$currPos++; } else { s7 = peg$FAILED; - if (peg$silentFails === 0) { peg$fail(peg$c85); } + if (peg$silentFails === 0) { peg$fail(peg$c90); } } if (s7 !== peg$FAILED) { if (input.charCodeAt(peg$currPos) === 93) { - s8 = peg$c93; + s8 = peg$c98; peg$currPos++; } else { s8 = peg$FAILED; - if (peg$silentFails === 0) { peg$fail(peg$c94); } + if (peg$silentFails === 0) { peg$fail(peg$c99); } } if (s8 !== peg$FAILED) { s2 = [s2, s3, s4, s5, s6, s7, s8]; @@ -2486,7 +2542,7 @@ var parser=(function() { peg$currPos++; } else { s2 = peg$FAILED; - if (peg$silentFails === 0) { peg$fail(peg$c85); } + if (peg$silentFails === 0) { peg$fail(peg$c90); } } if (s2 === peg$FAILED) { s2 = null; @@ -2495,11 +2551,11 @@ var parser=(function() { s3 = peg$currPos; peg$silentFails++; if (input.charCodeAt(peg$currPos) === 36) { - s4 = peg$c95; + s4 = peg$c100; peg$currPos++; } else { s4 = peg$FAILED; - if (peg$silentFails === 0) { peg$fail(peg$c96); } + if (peg$silentFails === 0) { peg$fail(peg$c101); } } peg$silentFails--; if (s4 === peg$FAILED) { @@ -2521,11 +2577,11 @@ var parser=(function() { } if (s1 !== peg$FAILED) { if (input.charCodeAt(peg$currPos) === 123) { - s2 = peg$c97; + s2 = peg$c102; peg$currPos++; } else { s2 = peg$FAILED; - if (peg$silentFails === 0) { peg$fail(peg$c98); } + if (peg$silentFails === 0) { peg$fail(peg$c103); } } if (s2 !== peg$FAILED) { s3 = []; @@ -2540,11 +2596,11 @@ var parser=(function() { } if (s3 !== peg$FAILED) { if (input.charCodeAt(peg$currPos) === 125) { - s4 = peg$c99; + s4 = peg$c104; peg$currPos++; } else { s4 = peg$FAILED; - if (peg$silentFails === 0) { peg$fail(peg$c100); } + if (peg$silentFails === 0) { peg$fail(peg$c105); } } if (s4 !== peg$FAILED) { s1 = [s1, s2, s3, s4]; @@ -2574,30 +2630,30 @@ var parser=(function() { s0 = peg$currPos; if (input.charCodeAt(peg$currPos) === 39) { - s1 = peg$c101; + s1 = peg$c106; peg$currPos++; } else { s1 = peg$FAILED; - if (peg$silentFails === 0) { peg$fail(peg$c102); } + if (peg$silentFails === 0) { peg$fail(peg$c107); } } if (s1 !== peg$FAILED) { s2 = peg$currPos; s3 = []; - if (peg$c103.test(input.charAt(peg$currPos))) { + if (peg$c108.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 (peg$silentFails === 0) { peg$fail(peg$c109); } } while (s4 !== peg$FAILED) { s3.push(s4); - if (peg$c103.test(input.charAt(peg$currPos))) { + if (peg$c108.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 (peg$silentFails === 0) { peg$fail(peg$c109); } } } if (s3 !== peg$FAILED) { @@ -2607,15 +2663,15 @@ var parser=(function() { } if (s2 !== peg$FAILED) { if (input.charCodeAt(peg$currPos) === 39) { - s3 = peg$c101; + s3 = peg$c106; peg$currPos++; } else { s3 = peg$FAILED; - if (peg$silentFails === 0) { peg$fail(peg$c102); } + if (peg$silentFails === 0) { peg$fail(peg$c107); } } if (s3 !== peg$FAILED) { peg$savedPos = s0; - s1 = peg$c105(s2); + s1 = peg$c110(s2); s0 = s1; } else { peg$currPos = s0; @@ -2638,11 +2694,11 @@ var parser=(function() { s0 = peg$currPos; if (input.charCodeAt(peg$currPos) === 34) { - s1 = peg$c106; + s1 = peg$c111; peg$currPos++; } else { s1 = peg$FAILED; - if (peg$silentFails === 0) { peg$fail(peg$c107); } + if (peg$silentFails === 0) { peg$fail(peg$c112); } } if (s1 !== peg$FAILED) { s2 = []; @@ -2677,15 +2733,15 @@ var parser=(function() { } if (s2 !== peg$FAILED) { if (input.charCodeAt(peg$currPos) === 34) { - s3 = peg$c106; + s3 = peg$c111; peg$currPos++; } else { s3 = peg$FAILED; - if (peg$silentFails === 0) { peg$fail(peg$c107); } + if (peg$silentFails === 0) { peg$fail(peg$c112); } } if (s3 !== peg$FAILED) { peg$savedPos = s0; - s1 = peg$c108(s2); + s1 = peg$c113(s2); s0 = s1; } else { peg$currPos = s0; @@ -2708,17 +2764,17 @@ var parser=(function() { s0 = peg$currPos; if (input.charCodeAt(peg$currPos) === 92) { - s1 = peg$c82; + s1 = peg$c87; peg$currPos++; } else { s1 = peg$FAILED; - if (peg$silentFails === 0) { peg$fail(peg$c83); } + if (peg$silentFails === 0) { peg$fail(peg$c88); } } if (s1 !== peg$FAILED) { s2 = peg$parsedoubleQuoteMeta(); if (s2 !== peg$FAILED) { peg$savedPos = s0; - s1 = peg$c84(s2); + s1 = peg$c89(s2); s0 = s1; } else { peg$currPos = s0; @@ -2730,16 +2786,16 @@ var parser=(function() { } if (s0 === peg$FAILED) { s0 = peg$currPos; - if (input.substr(peg$currPos, 2) === peg$c109) { - s1 = peg$c109; + if (input.substr(peg$currPos, 2) === peg$c114) { + s1 = peg$c114; peg$currPos += 2; } else { s1 = peg$FAILED; - if (peg$silentFails === 0) { peg$fail(peg$c110); } + if (peg$silentFails === 0) { peg$fail(peg$c115); } } if (s1 !== peg$FAILED) { peg$savedPos = s0; - s1 = peg$c111(); + s1 = peg$c116(); } s0 = s1; if (s0 === peg$FAILED) { @@ -2760,11 +2816,11 @@ var parser=(function() { peg$currPos++; } else { s2 = peg$FAILED; - if (peg$silentFails === 0) { peg$fail(peg$c85); } + if (peg$silentFails === 0) { peg$fail(peg$c90); } } if (s2 !== peg$FAILED) { peg$savedPos = s0; - s1 = peg$c84(s2); + s1 = peg$c89(s2); s0 = s1; } else { peg$currPos = s0; @@ -2784,27 +2840,27 @@ var parser=(function() { var s0; if (input.charCodeAt(peg$currPos) === 34) { - s0 = peg$c106; + s0 = peg$c111; peg$currPos++; } else { s0 = peg$FAILED; - if (peg$silentFails === 0) { peg$fail(peg$c107); } + if (peg$silentFails === 0) { peg$fail(peg$c112); } } if (s0 === peg$FAILED) { if (input.charCodeAt(peg$currPos) === 36) { - s0 = peg$c95; + s0 = peg$c100; peg$currPos++; } else { s0 = peg$FAILED; - if (peg$silentFails === 0) { peg$fail(peg$c96); } + if (peg$silentFails === 0) { peg$fail(peg$c101); } } if (s0 === peg$FAILED) { if (input.charCodeAt(peg$currPos) === 96) { - s0 = peg$c112; + s0 = peg$c117; peg$currPos++; } else { s0 = peg$FAILED; - if (peg$silentFails === 0) { peg$fail(peg$c113); } + if (peg$silentFails === 0) { peg$fail(peg$c118); } } } } @@ -2831,17 +2887,17 @@ var parser=(function() { s0 = peg$currPos; if (input.charCodeAt(peg$currPos) === 36) { - s1 = peg$c95; + s1 = peg$c100; peg$currPos++; } else { s1 = peg$FAILED; - if (peg$silentFails === 0) { peg$fail(peg$c96); } + if (peg$silentFails === 0) { peg$fail(peg$c101); } } if (s1 !== peg$FAILED) { s2 = peg$parsereadableVariableName(); if (s2 !== peg$FAILED) { peg$savedPos = s0; - s1 = peg$c114(s2); + s1 = peg$c119(s2); s0 = s1; } else { peg$currPos = s0; @@ -2860,22 +2916,22 @@ var parser=(function() { s0 = peg$currPos; s1 = []; - if (peg$c115.test(input.charAt(peg$currPos))) { + if (peg$c120.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 (peg$silentFails === 0) { peg$fail(peg$c121); } } if (s2 !== peg$FAILED) { while (s2 !== peg$FAILED) { s1.push(s2); - if (peg$c115.test(input.charAt(peg$currPos))) { + if (peg$c120.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 (peg$silentFails === 0) { peg$fail(peg$c121); } } } } else { @@ -2883,7 +2939,7 @@ var parser=(function() { } if (s1 !== peg$FAILED) { peg$savedPos = s0; - s1 = peg$c117(); + s1 = peg$c122(); } s0 = s1; @@ -2896,11 +2952,11 @@ var parser=(function() { s0 = peg$parsewritableVariableName(); if (s0 === peg$FAILED) { if (input.charCodeAt(peg$currPos) === 63) { - s0 = peg$c90; + s0 = peg$c95; peg$currPos++; } else { s0 = peg$FAILED; - if (peg$silentFails === 0) { peg$fail(peg$c91); } + if (peg$silentFails === 0) { peg$fail(peg$c96); } } } @@ -2911,43 +2967,43 @@ var parser=(function() { var s0, s1, s2, s3; s0 = peg$currPos; - if (input.substr(peg$currPos, 2) === peg$c118) { - s1 = peg$c118; + 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$c119); } + if (peg$silentFails === 0) { peg$fail(peg$c124); } } if (s1 !== peg$FAILED) { s2 = []; - if (peg$c120.test(input.charAt(peg$currPos))) { + if (peg$c125.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 (peg$silentFails === 0) { peg$fail(peg$c126); } } while (s3 !== peg$FAILED) { s2.push(s3); - if (peg$c120.test(input.charAt(peg$currPos))) { + if (peg$c125.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 (peg$silentFails === 0) { peg$fail(peg$c126); } } } if (s2 !== peg$FAILED) { if (input.charCodeAt(peg$currPos) === 125) { - s3 = peg$c99; + s3 = peg$c104; peg$currPos++; } else { s3 = peg$FAILED; - if (peg$silentFails === 0) { peg$fail(peg$c100); } + if (peg$silentFails === 0) { peg$fail(peg$c105); } } if (s3 !== peg$FAILED) { peg$savedPos = s0; - s1 = peg$c122(s2); + s1 = peg$c127(s2); s0 = s1; } else { peg$currPos = s0; @@ -2980,12 +3036,12 @@ var parser=(function() { var s0, s1, s2, s3; s0 = peg$currPos; - if (input.substr(peg$currPos, 2) === peg$c123) { - s1 = peg$c123; + if (input.substr(peg$currPos, 2) === peg$c128) { + s1 = peg$c128; peg$currPos += 2; } else { s1 = peg$FAILED; - if (peg$silentFails === 0) { peg$fail(peg$c124); } + if (peg$silentFails === 0) { peg$fail(peg$c129); } } if (s1 !== peg$FAILED) { s2 = peg$parsestatementList(); @@ -2999,7 +3055,47 @@ var parser=(function() { } if (s3 !== peg$FAILED) { peg$savedPos = s0; - s1 = peg$c125(s2); + s1 = peg$c130(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$parsearithmeticSubstitution() { + var s0, s1, s2, s3; + + s0 = peg$currPos; + if (input.substr(peg$currPos, 3) === peg$c131) { + s1 = peg$c131; + peg$currPos += 3; + } else { + s1 = peg$FAILED; + if (peg$silentFails === 0) { peg$fail(peg$c132); } + } + if (s1 !== peg$FAILED) { + s2 = peg$parsecommandName(); + if (s2 !== peg$FAILED) { + if (input.substr(peg$currPos, 2) === peg$c17) { + s3 = peg$c17; + peg$currPos += 2; + } else { + s3 = peg$FAILED; + if (peg$silentFails === 0) { peg$fail(peg$c18); } + } + if (s3 !== peg$FAILED) { + s1 = [s1, s2, s3]; s0 = s1; } else { peg$currPos = s0; @@ -3022,11 +3118,11 @@ var parser=(function() { s0 = peg$currPos; if (input.charCodeAt(peg$currPos) === 96) { - s1 = peg$c112; + s1 = peg$c117; peg$currPos++; } else { s1 = peg$FAILED; - if (peg$silentFails === 0) { peg$fail(peg$c113); } + if (peg$silentFails === 0) { peg$fail(peg$c118); } } if (s1 !== peg$FAILED) { s2 = []; @@ -3041,15 +3137,15 @@ var parser=(function() { } if (s2 !== peg$FAILED) { if (input.charCodeAt(peg$currPos) === 96) { - s3 = peg$c112; + s3 = peg$c117; peg$currPos++; } else { s3 = peg$FAILED; - if (peg$silentFails === 0) { peg$fail(peg$c113); } + if (peg$silentFails === 0) { peg$fail(peg$c118); } } if (s3 !== peg$FAILED) { peg$savedPos = s0; - s1 = peg$c126(s2); + s1 = peg$c133(s2); s0 = s1; } else { peg$currPos = s0; @@ -3071,30 +3167,30 @@ var parser=(function() { var s0, s1, s2; s0 = peg$currPos; - if (input.substr(peg$currPos, 2) === peg$c127) { - s1 = peg$c127; + if (input.substr(peg$currPos, 2) === peg$c134) { + s1 = peg$c134; peg$currPos += 2; } else { s1 = peg$FAILED; - if (peg$silentFails === 0) { peg$fail(peg$c128); } + if (peg$silentFails === 0) { peg$fail(peg$c135); } } if (s1 !== peg$FAILED) { peg$savedPos = s0; - s1 = peg$c129(); + s1 = peg$c136(); } s0 = s1; if (s0 === peg$FAILED) { s0 = peg$currPos; - if (input.substr(peg$currPos, 2) === peg$c109) { - s1 = peg$c109; + if (input.substr(peg$currPos, 2) === peg$c114) { + s1 = peg$c114; peg$currPos += 2; } else { s1 = peg$FAILED; - if (peg$silentFails === 0) { peg$fail(peg$c110); } + if (peg$silentFails === 0) { peg$fail(peg$c115); } } if (s1 !== peg$FAILED) { peg$savedPos = s0; - s1 = peg$c111(); + s1 = peg$c116(); } s0 = s1; if (s0 === peg$FAILED) { @@ -3102,11 +3198,11 @@ var parser=(function() { s1 = peg$currPos; peg$silentFails++; if (input.charCodeAt(peg$currPos) === 96) { - s2 = peg$c112; + s2 = peg$c117; peg$currPos++; } else { s2 = peg$FAILED; - if (peg$silentFails === 0) { peg$fail(peg$c113); } + if (peg$silentFails === 0) { peg$fail(peg$c118); } } peg$silentFails--; if (s2 === peg$FAILED) { @@ -3121,11 +3217,11 @@ var parser=(function() { peg$currPos++; } else { s2 = peg$FAILED; - if (peg$silentFails === 0) { peg$fail(peg$c85); } + if (peg$silentFails === 0) { peg$fail(peg$c90); } } if (s2 !== peg$FAILED) { peg$savedPos = s0; - s1 = peg$c84(s2); + s1 = peg$c89(s2); s0 = s1; } else { peg$currPos = s0; @@ -3145,12 +3241,12 @@ var parser=(function() { var s0, s1, s2, s3, s4; s0 = peg$currPos; - if (peg$c130.test(input.charAt(peg$currPos))) { + if (peg$c137.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 (peg$silentFails === 0) { peg$fail(peg$c138); } } if (s1 !== peg$FAILED) { if (input.charCodeAt(peg$currPos) === 40) { @@ -3172,7 +3268,7 @@ var parser=(function() { } if (s4 !== peg$FAILED) { peg$savedPos = s0; - s1 = peg$c132(s1, s3); + s1 = peg$c139(s1, s3); s0 = s1; } else { peg$currPos = s0; @@ -3217,35 +3313,35 @@ var parser=(function() { s1 = null; } if (s1 !== peg$FAILED) { - if (input.substr(peg$currPos, 2) === peg$c133) { - s2 = peg$c133; + if (input.substr(peg$currPos, 2) === peg$c140) { + s2 = peg$c140; peg$currPos += 2; } else { s2 = peg$FAILED; - if (peg$silentFails === 0) { peg$fail(peg$c134); } + if (peg$silentFails === 0) { peg$fail(peg$c141); } } if (s2 === peg$FAILED) { - if (input.substr(peg$currPos, 2) === peg$c135) { - s2 = peg$c135; + if (input.substr(peg$currPos, 2) === peg$c142) { + s2 = peg$c142; peg$currPos += 2; } else { s2 = peg$FAILED; - if (peg$silentFails === 0) { peg$fail(peg$c136); } + if (peg$silentFails === 0) { peg$fail(peg$c143); } } } if (s2 !== peg$FAILED) { s3 = peg$parsefd(); if (s3 !== peg$FAILED) { if (input.charCodeAt(peg$currPos) === 45) { - s4 = peg$c53; + s4 = peg$c58; peg$currPos++; } else { s4 = peg$FAILED; - if (peg$silentFails === 0) { peg$fail(peg$c54); } + if (peg$silentFails === 0) { peg$fail(peg$c59); } } if (s4 !== peg$FAILED) { peg$savedPos = s0; - s1 = peg$c137(s1, s2, s3); + s1 = peg$c144(s1, s2, s3); s0 = s1; } else { peg$currPos = s0; @@ -3276,20 +3372,20 @@ var parser=(function() { s1 = null; } if (s1 !== peg$FAILED) { - if (input.substr(peg$currPos, 2) === peg$c133) { - s2 = peg$c133; + if (input.substr(peg$currPos, 2) === peg$c140) { + s2 = peg$c140; peg$currPos += 2; } else { s2 = peg$FAILED; - if (peg$silentFails === 0) { peg$fail(peg$c134); } + if (peg$silentFails === 0) { peg$fail(peg$c141); } } if (s2 === peg$FAILED) { - if (input.substr(peg$currPos, 2) === peg$c135) { - s2 = peg$c135; + if (input.substr(peg$currPos, 2) === peg$c142) { + s2 = peg$c142; peg$currPos += 2; } else { s2 = peg$FAILED; - if (peg$silentFails === 0) { peg$fail(peg$c136); } + if (peg$silentFails === 0) { peg$fail(peg$c143); } } } if (s2 !== peg$FAILED) { @@ -3303,7 +3399,7 @@ var parser=(function() { s4 = peg$parsefd(); if (s4 !== peg$FAILED) { peg$savedPos = s0; - s1 = peg$c138(s1, s2, s4); + s1 = peg$c145(s1, s2, s4); s0 = s1; } else { peg$currPos = s0; @@ -3346,7 +3442,7 @@ var parser=(function() { s4 = peg$parseargument(); if (s4 !== peg$FAILED) { peg$savedPos = s0; - s1 = peg$c139(s1, s2, s4); + s1 = peg$c146(s1, s2, s4); s0 = s1; } else { peg$currPos = s0; @@ -3371,52 +3467,52 @@ var parser=(function() { function peg$parseredirectionOperator() { var s0; - if (input.substr(peg$currPos, 2) === peg$c140) { - s0 = peg$c140; + if (input.substr(peg$currPos, 2) === peg$c147) { + s0 = peg$c147; peg$currPos += 2; } else { s0 = peg$FAILED; - if (peg$silentFails === 0) { peg$fail(peg$c141); } + if (peg$silentFails === 0) { peg$fail(peg$c148); } } if (s0 === peg$FAILED) { - if (input.substr(peg$currPos, 2) === peg$c142) { - s0 = peg$c142; + if (input.substr(peg$currPos, 2) === peg$c149) { + s0 = peg$c149; peg$currPos += 2; } else { s0 = peg$FAILED; - if (peg$silentFails === 0) { peg$fail(peg$c143); } + if (peg$silentFails === 0) { peg$fail(peg$c150); } } if (s0 === peg$FAILED) { - if (input.substr(peg$currPos, 3) === peg$c144) { - s0 = peg$c144; + if (input.substr(peg$currPos, 3) === peg$c151) { + s0 = peg$c151; peg$currPos += 3; } else { s0 = peg$FAILED; - if (peg$silentFails === 0) { peg$fail(peg$c145); } + if (peg$silentFails === 0) { peg$fail(peg$c152); } } if (s0 === peg$FAILED) { - if (input.substr(peg$currPos, 2) === peg$c146) { - s0 = peg$c146; + if (input.substr(peg$currPos, 2) === peg$c153) { + s0 = peg$c153; peg$currPos += 2; } else { s0 = peg$FAILED; - if (peg$silentFails === 0) { peg$fail(peg$c147); } + if (peg$silentFails === 0) { peg$fail(peg$c154); } } if (s0 === peg$FAILED) { if (input.charCodeAt(peg$currPos) === 60) { - s0 = peg$c148; + s0 = peg$c155; peg$currPos++; } else { s0 = peg$FAILED; - if (peg$silentFails === 0) { peg$fail(peg$c149); } + if (peg$silentFails === 0) { peg$fail(peg$c156); } } if (s0 === peg$FAILED) { if (input.charCodeAt(peg$currPos) === 62) { - s0 = peg$c150; + s0 = peg$c157; peg$currPos++; } else { s0 = peg$FAILED; - if (peg$silentFails === 0) { peg$fail(peg$c151); } + if (peg$silentFails === 0) { peg$fail(peg$c158); } } } } @@ -3432,22 +3528,22 @@ var parser=(function() { s0 = peg$currPos; s1 = []; - if (peg$c152.test(input.charAt(peg$currPos))) { + if (peg$c159.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 (peg$silentFails === 0) { peg$fail(peg$c160); } } if (s2 !== peg$FAILED) { while (s2 !== peg$FAILED) { s1.push(s2); - if (peg$c152.test(input.charAt(peg$currPos))) { + if (peg$c159.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 (peg$silentFails === 0) { peg$fail(peg$c160); } } } } else { @@ -3455,7 +3551,7 @@ var parser=(function() { } if (s1 !== peg$FAILED) { peg$savedPos = s0; - s1 = peg$c154(s1); + s1 = peg$c161(s1); } s0 = s1; @@ -3474,33 +3570,33 @@ var parser=(function() { } if (s1 !== peg$FAILED) { if (input.charCodeAt(peg$currPos) === 38) { - s2 = peg$c155; + s2 = peg$c162; peg$currPos++; } else { s2 = peg$FAILED; - if (peg$silentFails === 0) { peg$fail(peg$c156); } + if (peg$silentFails === 0) { peg$fail(peg$c163); } } if (s2 === peg$FAILED) { if (input.charCodeAt(peg$currPos) === 59) { - s2 = peg$c45; + s2 = peg$c50; peg$currPos++; } else { s2 = peg$FAILED; - if (peg$silentFails === 0) { peg$fail(peg$c46); } + if (peg$silentFails === 0) { peg$fail(peg$c51); } } if (s2 === peg$FAILED) { if (input.charCodeAt(peg$currPos) === 10) { - s2 = peg$c47; + s2 = peg$c52; peg$currPos++; } else { s2 = peg$FAILED; - if (peg$silentFails === 0) { peg$fail(peg$c48); } + if (peg$silentFails === 0) { peg$fail(peg$c53); } } } } if (s2 !== peg$FAILED) { peg$savedPos = s0; - s1 = peg$c157(s2); + s1 = peg$c164(s2); s0 = s1; } else { peg$currPos = s0; @@ -3519,11 +3615,11 @@ var parser=(function() { s0 = peg$currPos; if (input.charCodeAt(peg$currPos) === 124) { - s1 = peg$c158; + s1 = peg$c165; peg$currPos++; } else { s1 = peg$FAILED; - if (peg$silentFails === 0) { peg$fail(peg$c159); } + if (peg$silentFails === 0) { peg$fail(peg$c166); } } if (s1 !== peg$FAILED) { s2 = []; @@ -3536,7 +3632,7 @@ var parser=(function() { s3 = peg$parsecommand(); if (s3 !== peg$FAILED) { peg$savedPos = s0; - s1 = peg$c160(s3); + s1 = peg$c167(s3); s0 = s1; } else { peg$currPos = s0; @@ -3559,25 +3655,25 @@ var parser=(function() { peg$silentFails++; if (input.charCodeAt(peg$currPos) === 32) { - s0 = peg$c162; + s0 = peg$c169; peg$currPos++; } else { s0 = peg$FAILED; - if (peg$silentFails === 0) { peg$fail(peg$c163); } + if (peg$silentFails === 0) { peg$fail(peg$c170); } } if (s0 === peg$FAILED) { if (input.charCodeAt(peg$currPos) === 9) { - s0 = peg$c164; + s0 = peg$c171; peg$currPos++; } else { s0 = peg$FAILED; - if (peg$silentFails === 0) { peg$fail(peg$c165); } + if (peg$silentFails === 0) { peg$fail(peg$c172); } } } peg$silentFails--; if (s0 === peg$FAILED) { s1 = peg$FAILED; - if (peg$silentFails === 0) { peg$fail(peg$c161); } + if (peg$silentFails === 0) { peg$fail(peg$c168); } } return s0; @@ -3589,11 +3685,11 @@ var parser=(function() { s0 = peg$parsespace(); if (s0 === peg$FAILED) { if (input.charCodeAt(peg$currPos) === 10) { - s0 = peg$c47; + s0 = peg$c52; peg$currPos++; } else { s0 = peg$FAILED; - if (peg$silentFails === 0) { peg$fail(peg$c48); } + if (peg$silentFails === 0) { peg$fail(peg$c53); } } if (s0 === peg$FAILED) { s0 = peg$parsecomment(); @@ -3609,38 +3705,38 @@ var parser=(function() { peg$silentFails++; s0 = peg$currPos; if (input.charCodeAt(peg$currPos) === 35) { - s1 = peg$c79; + s1 = peg$c84; peg$currPos++; } else { s1 = peg$FAILED; - if (peg$silentFails === 0) { peg$fail(peg$c80); } + if (peg$silentFails === 0) { peg$fail(peg$c85); } } if (s1 !== peg$FAILED) { s2 = []; - if (peg$c63.test(input.charAt(peg$currPos))) { + if (peg$c68.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 (peg$silentFails === 0) { peg$fail(peg$c69); } } while (s3 !== peg$FAILED) { s2.push(s3); - if (peg$c63.test(input.charAt(peg$currPos))) { + if (peg$c68.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 (peg$silentFails === 0) { peg$fail(peg$c69); } } } if (s2 !== peg$FAILED) { if (input.charCodeAt(peg$currPos) === 10) { - s3 = peg$c47; + s3 = peg$c52; peg$currPos++; } else { s3 = peg$FAILED; - if (peg$silentFails === 0) { peg$fail(peg$c48); } + if (peg$silentFails === 0) { peg$fail(peg$c53); } } if (s3 === peg$FAILED) { s3 = peg$parseEOF(); @@ -3663,7 +3759,7 @@ var parser=(function() { peg$silentFails--; if (s0 === peg$FAILED) { s1 = peg$FAILED; - if (peg$silentFails === 0) { peg$fail(peg$c166); } + if (peg$silentFails === 0) { peg$fail(peg$c173); } } return s0; @@ -3673,108 +3769,108 @@ var parser=(function() { var s0, s1, s2, s3; s0 = peg$currPos; - if (input.substr(peg$currPos, 5) === peg$c31) { - s1 = peg$c31; + if (input.substr(peg$currPos, 5) === peg$c36) { + s1 = peg$c36; peg$currPos += 5; } else { s1 = peg$FAILED; - if (peg$silentFails === 0) { peg$fail(peg$c32); } + if (peg$silentFails === 0) { peg$fail(peg$c37); } } if (s1 === peg$FAILED) { - if (input.substr(peg$currPos, 5) === peg$c33) { - s1 = peg$c33; + if (input.substr(peg$currPos, 5) === peg$c38) { + s1 = peg$c38; peg$currPos += 5; } else { s1 = peg$FAILED; - if (peg$silentFails === 0) { peg$fail(peg$c34); } + if (peg$silentFails === 0) { peg$fail(peg$c39); } } if (s1 === peg$FAILED) { - if (input.substr(peg$currPos, 3) === peg$c41) { - s1 = peg$c41; + if (input.substr(peg$currPos, 3) === peg$c46) { + s1 = peg$c46; peg$currPos += 3; } else { s1 = peg$FAILED; - if (peg$silentFails === 0) { peg$fail(peg$c42); } + if (peg$silentFails === 0) { peg$fail(peg$c47); } } if (s1 === peg$FAILED) { - if (input.substr(peg$currPos, 4) === peg$c37) { - s1 = peg$c37; + if (input.substr(peg$currPos, 4) === peg$c42) { + s1 = peg$c42; peg$currPos += 4; } else { s1 = peg$FAILED; - if (peg$silentFails === 0) { peg$fail(peg$c38); } + if (peg$silentFails === 0) { peg$fail(peg$c43); } } if (s1 === peg$FAILED) { - if (input.substr(peg$currPos, 2) === peg$c35) { - s1 = peg$c35; + if (input.substr(peg$currPos, 2) === peg$c40) { + s1 = peg$c40; peg$currPos += 2; } else { s1 = peg$FAILED; - if (peg$silentFails === 0) { peg$fail(peg$c36); } + if (peg$silentFails === 0) { peg$fail(peg$c41); } } if (s1 === peg$FAILED) { - if (input.substr(peg$currPos, 4) === peg$c167) { - s1 = peg$c167; + if (input.substr(peg$currPos, 4) === peg$c174) { + s1 = peg$c174; peg$currPos += 4; } else { s1 = peg$FAILED; - if (peg$silentFails === 0) { peg$fail(peg$c168); } + if (peg$silentFails === 0) { peg$fail(peg$c175); } } if (s1 === peg$FAILED) { - if (input.substr(peg$currPos, 4) === peg$c169) { - s1 = peg$c169; + if (input.substr(peg$currPos, 4) === peg$c176) { + s1 = peg$c176; peg$currPos += 4; } else { s1 = peg$FAILED; - if (peg$silentFails === 0) { peg$fail(peg$c170); } + if (peg$silentFails === 0) { peg$fail(peg$c177); } } if (s1 === peg$FAILED) { - if (input.substr(peg$currPos, 2) === peg$c18) { - s1 = peg$c18; + if (input.substr(peg$currPos, 2) === peg$c23) { + s1 = peg$c23; peg$currPos += 2; } else { s1 = peg$FAILED; - if (peg$silentFails === 0) { peg$fail(peg$c19); } + if (peg$silentFails === 0) { peg$fail(peg$c24); } } if (s1 === peg$FAILED) { - if (input.substr(peg$currPos, 4) === peg$c20) { - s1 = peg$c20; + if (input.substr(peg$currPos, 4) === peg$c25) { + s1 = peg$c25; peg$currPos += 4; } else { s1 = peg$FAILED; - if (peg$silentFails === 0) { peg$fail(peg$c21); } + if (peg$silentFails === 0) { peg$fail(peg$c26); } } if (s1 === peg$FAILED) { - if (input.substr(peg$currPos, 4) === peg$c22) { - s1 = peg$c22; + 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$c23); } + if (peg$silentFails === 0) { peg$fail(peg$c28); } } if (s1 === peg$FAILED) { - if (input.substr(peg$currPos, 4) === peg$c27) { - s1 = peg$c27; + 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$c28); } + if (peg$silentFails === 0) { peg$fail(peg$c33); } } if (s1 === peg$FAILED) { - if (input.substr(peg$currPos, 2) === peg$c24) { - s1 = peg$c24; + if (input.substr(peg$currPos, 2) === peg$c29) { + s1 = peg$c29; peg$currPos += 2; } else { s1 = peg$FAILED; - if (peg$silentFails === 0) { peg$fail(peg$c25); } + if (peg$silentFails === 0) { peg$fail(peg$c30); } } if (s1 === peg$FAILED) { - if (input.substr(peg$currPos, 2) === peg$c71) { - s1 = peg$c71; + if (input.substr(peg$currPos, 2) === peg$c76) { + s1 = peg$c76; peg$currPos += 2; } else { s1 = peg$FAILED; - if (peg$silentFails === 0) { peg$fail(peg$c72); } + if (peg$silentFails === 0) { peg$fail(peg$c77); } } } } @@ -3826,43 +3922,43 @@ var parser=(function() { s2 = peg$parsekeyword(); if (s2 === peg$FAILED) { if (input.charCodeAt(peg$currPos) === 34) { - s2 = peg$c106; + s2 = peg$c111; peg$currPos++; } else { s2 = peg$FAILED; - if (peg$silentFails === 0) { peg$fail(peg$c107); } + if (peg$silentFails === 0) { peg$fail(peg$c112); } } if (s2 === peg$FAILED) { if (input.charCodeAt(peg$currPos) === 39) { - s2 = peg$c101; + s2 = peg$c106; peg$currPos++; } else { s2 = peg$FAILED; - if (peg$silentFails === 0) { peg$fail(peg$c102); } + if (peg$silentFails === 0) { peg$fail(peg$c107); } } if (s2 === peg$FAILED) { if (input.charCodeAt(peg$currPos) === 96) { - s2 = peg$c112; + s2 = peg$c117; peg$currPos++; } else { s2 = peg$FAILED; - if (peg$silentFails === 0) { peg$fail(peg$c113); } + if (peg$silentFails === 0) { peg$fail(peg$c118); } } if (s2 === peg$FAILED) { - if (input.substr(peg$currPos, 2) === peg$c123) { - s2 = peg$c123; + if (input.substr(peg$currPos, 2) === peg$c128) { + s2 = peg$c128; peg$currPos += 2; } else { s2 = peg$FAILED; - if (peg$silentFails === 0) { peg$fail(peg$c124); } + if (peg$silentFails === 0) { peg$fail(peg$c129); } } if (s2 === peg$FAILED) { - if (input.substr(peg$currPos, 2) === peg$c118) { - s2 = peg$c118; + 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$c119); } + if (peg$silentFails === 0) { peg$fail(peg$c124); } } } } @@ -3883,7 +3979,7 @@ var parser=(function() { peg$currPos++; } else { s3 = peg$FAILED; - if (peg$silentFails === 0) { peg$fail(peg$c85); } + if (peg$silentFails === 0) { peg$fail(peg$c90); } } while (s3 !== peg$FAILED) { s2.push(s3); @@ -3892,7 +3988,7 @@ var parser=(function() { peg$currPos++; } else { s3 = peg$FAILED; - if (peg$silentFails === 0) { peg$fail(peg$c85); } + if (peg$silentFails === 0) { peg$fail(peg$c90); } } } if (s2 !== peg$FAILED) { @@ -3920,7 +4016,7 @@ var parser=(function() { peg$currPos++; } else { s1 = peg$FAILED; - if (peg$silentFails === 0) { peg$fail(peg$c85); } + if (peg$silentFails === 0) { peg$fail(peg$c90); } } peg$silentFails--; if (s1 === peg$FAILED) { From c4e5fdc891e80b107dd36d0ff766849aade7560c Mon Sep 17 00:00:00 2001 From: Jordan Klassen Date: Tue, 15 Mar 2016 23:37:42 -0700 Subject: [PATCH 02/20] Parse arithmetics --- grammar.pegjs | 87 +++++++++++++++++++++++++++++++++--- overrides.js | 7 +++ package.json | 2 +- tests/shellcheck-fixtures.js | 17 ++++--- 4 files changed, 99 insertions(+), 14 deletions(-) diff --git a/grammar.pegjs b/grammar.pegjs index 428c8fc..7ff862f 100644 --- a/grammar.pegjs +++ b/grammar.pegjs @@ -7,8 +7,8 @@ statementList space* last:controlOperator? spaceNL* statement - = statement:( subshell - / arithmeticStatement + = statement:(arithmeticStatement + / subshell / bashExtensions / command / variableAssignment @@ -21,12 +21,12 @@ statement chainedStatement = operator:('&&' / '||') spaceNL* statement:statement +arithmeticStatement "an arithmetic statement" + = "((" space* expression:arithmetic space* "))" + subshell "a subshell" = "(" space* statements:statementList space* ")" -arithmeticStatement "an arithmetic statement" - = "((" expression:arithmetic "))" - command "a single command" = pre:((variableAssignment / redirect) space+)* name:(commandName / builtinCommandName) @@ -207,8 +207,81 @@ keyword ) ( spaceNL+ / EOF ) -arithmetic - = commandName +// http://www.gnu.org/software/bash/manual/html_node/Shell-Arithmetic.html +arithmetic "an arithmetic expression" + = aComma + +aComma "a sequence of arithmetic expressions" + = head:aAssign tail:( space* "," space* aComma )* + +aAssign "an arithmetic assignment" + = writableVariableName space* ( "=" / "*=" / "/=" / "%=" / "+=" / "-=" / "<<=" / ">>=" / "&=" / "^=" / "|=" ) space* aAssign + / aCond + +aCond "an arithmetic conditional expression" + = aLogicalOr space* "?" space* aCond space* ":" space* aCond + / aLogicalOr + +aLogicalOr "an arithmetic logical or" + = aLogicalAnd space* "||" space* aLogicalOr + / aLogicalAnd + +aLogicalAnd "an arithmetic logical and" + = aBitwiseOr space* "&&" space* aLogicalAnd + / aBitwiseOr + +aBitwiseOr + = aBitwiseXor space* "|" space* aBitwiseOr + / aBitwiseXor + +aBitwiseXor + = aBitwiseAnd space* "^" space* aBitwiseXor + / aBitwiseAnd + +aBitwiseAnd + = aEquality space* "&" space* aBitwiseAnd + / aEquality + +aEquality + = aComparison space* ( "==" / "!=" ) space* aEquality + / aComparison + +aComparison + = aBitwiseShift space* ( "<=" / ">=" / "<" / ">" ) space* aComparison + / aBitwiseShift + +aBitwiseShift + = aAddSubtract space* ( "<<" / ">>" ) space* aBitwiseShift + / aAddSubtract + +aAddSubtract + = aMultDivModulo space* ( "+" / "-" ) space* aAddSubtract + / aMultDivModulo + +aMultDivModulo + = aExponent space* ( "*" / "/" ) space* aMultDivModulo + / aExponent + +aExponent + = aNegation space* "**" space* aExponent + / aNegation + +aNegation + = ( "!" / "~" ) space* aNegation + / aUnary + +aUnary + = ( "+" / "-" ) space* aUnary + / aPreIncDec + +aPreIncDec + = ( "++" / "--" ) space* aPreIncDec + / aPostIncDec + +aPostIncDec + // = aPostIncDec space* ( "++" / "--" ) // TODO: figure out how to do this + = writableVariableName space* ( "++" / "--" ) // TODO: figure out how to do this + / writableVariableName continuationStart = &( keyword / '"' / "'" / '`' / "$(" / "${" ) .* diff --git a/overrides.js b/overrides.js index 3c024ee..ed0c81f 100644 --- a/overrides.js +++ b/overrides.js @@ -97,6 +97,13 @@ rules.statementList = function (first, tail, last) { } } +rules.arithmeticStatement = function (expression) { + return { + type: 'arithmeticStatement', + expression: expression, + } +} + rules.subshell = function (statements) { return { type: 'subshell', diff --git a/package.json b/package.json index 734be20..224a5e6 100644 --- a/package.json +++ b/package.json @@ -35,10 +35,10 @@ } }, "devDependencies": { + "markdown-code-blocks": "0.0.1", "pegjs": "~0.9.0", "pegjs-override-action": "0.2.3", "tape": "^4.5.1", - "markdown-code-blocks": "0.0.1", "xtend": "~2.1.1" }, "repository": { diff --git a/tests/shellcheck-fixtures.js b/tests/shellcheck-fixtures.js index 439f4cd..616c00d 100644 --- a/tests/shellcheck-fixtures.js +++ b/tests/shellcheck-fixtures.js @@ -24,6 +24,7 @@ test('shellcheck fixtures', function(t) { t.plan(fixtureDirs.length) fixtureDirs.forEach(function (fixtureDir) { + var fixtureName = fixtureDir.replace(fixturesDir + '/', '') var source = fs.readFileSync(path.join(fixtureDir, 'source.sh'), 'utf8') var error, ast; @@ -37,15 +38,19 @@ test('shellcheck fixtures', function(t) { parse(source) }, error.message ? new RegExp(error.message) : undefined, fixtureDir + ' errored') } else if (ast) { - t.deepEqual(parse(source), ast, dir) + t.deepEqual(parse(source), ast, fixtureName) } else { try { - parse(source) - t.pass(fixtureDir.replace(fixturesDir + '/', '') + ': parsed sucessfully') + ast = parse(source) + if (process.env.write_shellcheck_fixture_ast) { + fs.writeFileSync(path.join(fixtureDir, 'ast.json'), JSON.stringify(ast, null, ' ') + '\n', 'utf8') + } + t.pass(fixtureName + ': parsed sucessfully') } catch (e) { if (e instanceof parse.SyntaxError) { - t.fail('parse failed') - formatParseError(fixtureDir, source, e) + var formattedErr = formatParseError(fixtureDir, source, e) + t.fail('parse failed: ' + formattedErr) + console.error(formattedErr + '\n' + e.stack) } else { throw e } @@ -63,5 +68,5 @@ function formatParseError (dir, source, err) { msg += '\n ' + source.slice(start, start + 10).trim() + '\n' for (var i = 0; i <= (err.column - start); i++) msg += '-'; msg += '^' - console.error(msg) + return msg } From 17bb06afae31f5f3d778769981c75ea83d858187 Mon Sep 17 00:00:00 2001 From: Jordan Klassen Date: Tue, 22 Mar 2016 21:15:07 -0700 Subject: [PATCH 03/20] Properly parse arithmetic expressions into simple ast --- grammar.pegjs | 75 +++++------ overrides.js | 118 ++++++++++++++++++ .../arithmetic-expression/ast.json | 22 ++++ 3 files changed, 179 insertions(+), 36 deletions(-) create mode 100644 tests/fixtures/shellcheck-tests/arithmetic-expression/ast.json diff --git a/grammar.pegjs b/grammar.pegjs index 7ff862f..900c968 100644 --- a/grammar.pegjs +++ b/grammar.pegjs @@ -209,79 +209,82 @@ keyword // http://www.gnu.org/software/bash/manual/html_node/Shell-Arithmetic.html arithmetic "an arithmetic expression" - = aComma + = expression:aComma aComma "a sequence of arithmetic expressions" = head:aAssign tail:( space* "," space* aComma )* aAssign "an arithmetic assignment" - = writableVariableName space* ( "=" / "*=" / "/=" / "%=" / "+=" / "-=" / "<<=" / ">>=" / "&=" / "^=" / "|=" ) space* aAssign - / aCond + = left:aVariable space* operator:( "=" / "*=" / "/=" / "%=" / "+=" / "-=" / "<<=" / ">>=" / "&=" / "^=" / "|=" ) space* right:aAssign + / other:aCond aCond "an arithmetic conditional expression" - = aLogicalOr space* "?" space* aCond space* ":" space* aCond - / aLogicalOr + = test:aLogicalOr space* "?" space* consequent:aCond space* ":" space* alternate:aCond + / other:aLogicalOr aLogicalOr "an arithmetic logical or" - = aLogicalAnd space* "||" space* aLogicalOr - / aLogicalAnd + = left:aLogicalAnd space* "||" space* right:aLogicalOr + / other:aLogicalAnd aLogicalAnd "an arithmetic logical and" - = aBitwiseOr space* "&&" space* aLogicalAnd - / aBitwiseOr + = left:aBitwiseOr space* "&&" space* right:aLogicalAnd + / other:aBitwiseOr aBitwiseOr - = aBitwiseXor space* "|" space* aBitwiseOr - / aBitwiseXor + = left:aBitwiseXor space* operator:"|" space* right:aBitwiseOr + / other:aBitwiseXor aBitwiseXor - = aBitwiseAnd space* "^" space* aBitwiseXor - / aBitwiseAnd + = left:aBitwiseAnd space* operator:"^" space* right:aBitwiseXor + / other:aBitwiseAnd aBitwiseAnd - = aEquality space* "&" space* aBitwiseAnd - / aEquality + = left:aEquality space* operator:"&" space* right:aBitwiseAnd + / other:aEquality aEquality - = aComparison space* ( "==" / "!=" ) space* aEquality - / aComparison + = left:aComparison space* operator:( "==" / "!=" ) space* right:aEquality + / other:aComparison aComparison - = aBitwiseShift space* ( "<=" / ">=" / "<" / ">" ) space* aComparison - / aBitwiseShift + = left:aBitwiseShift space* operator:( "<=" / ">=" / "<" / ">" ) space* right:aComparison + / other:aBitwiseShift aBitwiseShift - = aAddSubtract space* ( "<<" / ">>" ) space* aBitwiseShift - / aAddSubtract + = left:aAddSubtract space* operator:( "<<" / ">>" ) space* right:aBitwiseShift + / other:aAddSubtract aAddSubtract - = aMultDivModulo space* ( "+" / "-" ) space* aAddSubtract - / aMultDivModulo + = left:aMultDivModulo space* operator:( "+" / "-" ) space* right:aAddSubtract + / other:aMultDivModulo aMultDivModulo - = aExponent space* ( "*" / "/" ) space* aMultDivModulo - / aExponent + = left:aExponent space* operator:( "*" / "/" ) space* right:aMultDivModulo + / other:aExponent aExponent - = aNegation space* "**" space* aExponent - / aNegation + = left:aNegation space* operator:"**" space* right:aExponent + / other:aNegation aNegation - = ( "!" / "~" ) space* aNegation - / aUnary + = operator:( "!" / "~" ) space* argument:aNegation + / other:aUnary aUnary - = ( "+" / "-" ) space* aUnary - / aPreIncDec + = operator:( "+" / "-" ) space* argument:aUnary + / other:aPreIncDec aPreIncDec - = ( "++" / "--" ) space* aPreIncDec - / aPostIncDec + = operator:( "++" / "--" ) space* argument:aPreIncDec + / other:aPostIncDec aPostIncDec - // = aPostIncDec space* ( "++" / "--" ) // TODO: figure out how to do this - = writableVariableName space* ( "++" / "--" ) // TODO: figure out how to do this - / writableVariableName + // = argument:aPostIncDec space* operator:( "++" / "--" ) // TODO: figure out how to do this + = argument:aVariable space* operator:( "++" / "--" ) // TODO: figure out how to do this + / other:aVariable + +aVariable + = name:writableVariableName continuationStart = &( keyword / '"' / "'" / '`' / "$(" / "${" ) .* diff --git a/overrides.js b/overrides.js index ed0c81f..6de1ac1 100644 --- a/overrides.js +++ b/overrides.js @@ -311,3 +311,121 @@ rules.redirectFd = function (fd, op, filename) { filename: filename } } + +rules.arithmetic = function (expression) { + return expression +} + +rules.aVariable = function () { + return {type: 'arithmeticVariable', name: name} +} + +rules.aComma = function (head, tail) { + if (tail.length) { + return { + type: 'arithmeticSequence', + expressions: [head].concat(tail) + } + } + return head +} + +function other(other) { return other } + +rules.aCond = [ + function (test, consequent, alternate) { + return { + type: 'arithmeticConditional', + test: test, + consequent: consequent, + alternate: alternate + } + }, other +] + +rules.aAssign = [ + function (left, operator, right) { + return { + type: 'arithmeticAssignment', + left: left, + operator: operator, + right: right + } + }, other +] + +rules.aLogicalOr = [ + function (left, right) { + return { + type: 'arithmeticLogical', + operator: '||', + left: left, + right: right + } + }, other +] + +rules.aLogicalAnd = [ + function (left, right) { + return { + type: 'arithmeticLogical', + operator: '&&', + left: left, + right: right + } + }, other +] + +rules.aBitwiseOr = +rules.aLogicalAnd = +rules.aBitwiseOr = +rules.aBitwiseXor = +rules.aBitwiseAnd = +rules.aEquality = +rules.aComparison = +rules.aBitwiseShift = +rules.aAddSubtract = +rules.aMultDivModulo = +rules.aExponent = +[ + function arithmeticBinary(left, operator, right) { + return { + type: 'arithmeticBinary', + operator: operator, + left: left, + right: right + } +}, other] + +rules.aNegation = rules.aNegation = +[ + function (operator, argument) { + return { + type: 'arithmeticUnary', + operator: operator, + argument: argument + } + }, other +] + +rules.aPreIncDec = [ + function (operator, argument) { + return { + type: 'arithmeticUpdate', + operator: operator, + argument: argument, + prefix: true + } + }, other +] + +rules.aPostIncDec = [ + function (argument) { + return { + type: 'arithmeticUpdate', + operator: operator, + argument: argument, + prefix: false + } + }, other +] diff --git a/tests/fixtures/shellcheck-tests/arithmetic-expression/ast.json b/tests/fixtures/shellcheck-tests/arithmetic-expression/ast.json new file mode 100644 index 0000000..70252f3 --- /dev/null +++ b/tests/fixtures/shellcheck-tests/arithmetic-expression/ast.json @@ -0,0 +1,22 @@ +[ + { + "type": "arithmeticStatement", + "expression": { + "type": "arithmeticConditional", + "test": { + "type": "arithmeticVariable", + "name": "a" + }, + "consequent": { + "type": "arithmeticVariable", + "name": "b" + }, + "alternate": { + "type": "arithmeticVariable", + "name": "c" + } + }, + "control": ";", + "next": null + } +] From 27abac856d13d1c96ac528f2f3f59dd157854eec Mon Sep 17 00:00:00 2001 From: Jordan Klassen Date: Tue, 22 Mar 2016 21:20:44 -0700 Subject: [PATCH 04/20] Add test asts And a small fix to the previous commit --- overrides.js | 2 +- .../shellcheck-tests/allspacing/ast.json | 1 + .../shellcheck-tests/allspacing2/ast.json | 1 + .../shellcheck-tests/allspacing3/ast.json | 1 + .../fixtures/shellcheck-tests/and-or/ast.json | 43 +++++++++++++++++++ .../shellcheck-tests/arithmetic1/ast.json | 29 +++++++++++++ 6 files changed, 76 insertions(+), 1 deletion(-) create mode 100644 tests/fixtures/shellcheck-tests/allspacing/ast.json create mode 100644 tests/fixtures/shellcheck-tests/allspacing2/ast.json create mode 100644 tests/fixtures/shellcheck-tests/allspacing3/ast.json create mode 100644 tests/fixtures/shellcheck-tests/and-or/ast.json create mode 100644 tests/fixtures/shellcheck-tests/arithmetic1/ast.json diff --git a/overrides.js b/overrides.js index 6de1ac1..c1e99c6 100644 --- a/overrides.js +++ b/overrides.js @@ -397,7 +397,7 @@ rules.aExponent = } }, other] -rules.aNegation = rules.aNegation = +rules.aNegation = rules.aUnary = [ function (operator, argument) { return { diff --git a/tests/fixtures/shellcheck-tests/allspacing/ast.json b/tests/fixtures/shellcheck-tests/allspacing/ast.json new file mode 100644 index 0000000..fe51488 --- /dev/null +++ b/tests/fixtures/shellcheck-tests/allspacing/ast.json @@ -0,0 +1 @@ +[] diff --git a/tests/fixtures/shellcheck-tests/allspacing2/ast.json b/tests/fixtures/shellcheck-tests/allspacing2/ast.json new file mode 100644 index 0000000..fe51488 --- /dev/null +++ b/tests/fixtures/shellcheck-tests/allspacing2/ast.json @@ -0,0 +1 @@ +[] diff --git a/tests/fixtures/shellcheck-tests/allspacing3/ast.json b/tests/fixtures/shellcheck-tests/allspacing3/ast.json new file mode 100644 index 0000000..fe51488 --- /dev/null +++ b/tests/fixtures/shellcheck-tests/allspacing3/ast.json @@ -0,0 +1 @@ +[] diff --git a/tests/fixtures/shellcheck-tests/and-or/ast.json b/tests/fixtures/shellcheck-tests/and-or/ast.json new file mode 100644 index 0000000..c22415b --- /dev/null +++ b/tests/fixtures/shellcheck-tests/and-or/ast.json @@ -0,0 +1,43 @@ +[ + { + "type": "command", + "command": { + "type": "literal", + "value": "grep" + }, + "args": [ + { + "type": "literal", + "value": "-i" + }, + { + "type": "literal", + "value": "lol" + }, + { + "type": "literal", + "value": "foo" + } + ], + "redirects": [], + "env": {}, + "control": "||", + "next": { + "type": "command", + "command": { + "type": "literal", + "value": "exit" + }, + "args": [ + { + "type": "literal", + "value": "1" + } + ], + "redirects": [], + "env": {}, + "control": ";", + "next": null + } + } +] diff --git a/tests/fixtures/shellcheck-tests/arithmetic1/ast.json b/tests/fixtures/shellcheck-tests/arithmetic1/ast.json new file mode 100644 index 0000000..367dfd6 --- /dev/null +++ b/tests/fixtures/shellcheck-tests/arithmetic1/ast.json @@ -0,0 +1,29 @@ +[ + { + "type": "arithmeticStatement", + "expression": { + "type": "arithmeticBinary", + "operator": "+", + "left": { + "type": "arithmeticUpdate", + "operator": "++", + "argument": { + "type": "arithmeticVariable", + "name": "n" + }, + "prefix": false + }, + "right": { + "type": "arithmeticUpdate", + "operator": "+", + "argument": { + "type": "arithmeticVariable", + "name": "c" + }, + "prefix": true + } + }, + "control": ";", + "next": null + } +] From f9445c51c48b38d00986057a8ae8625acbb6d04c Mon Sep 17 00:00:00 2001 From: Jordan Klassen Date: Tue, 22 Mar 2016 21:24:40 -0700 Subject: [PATCH 05/20] Fix incorrect lexing w.r.t prefix ++/-- --- grammar.pegjs | 2 +- tests/fixtures/shellcheck-tests/arithmetic1/ast.json | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/grammar.pegjs b/grammar.pegjs index 900c968..861141a 100644 --- a/grammar.pegjs +++ b/grammar.pegjs @@ -271,7 +271,7 @@ aNegation / other:aUnary aUnary - = operator:( "+" / "-" ) space* argument:aUnary + = operator:( "+" !"+" / "-" !"-" ) space* argument:aUnary / other:aPreIncDec aPreIncDec diff --git a/tests/fixtures/shellcheck-tests/arithmetic1/ast.json b/tests/fixtures/shellcheck-tests/arithmetic1/ast.json index 367dfd6..27f6994 100644 --- a/tests/fixtures/shellcheck-tests/arithmetic1/ast.json +++ b/tests/fixtures/shellcheck-tests/arithmetic1/ast.json @@ -15,7 +15,7 @@ }, "right": { "type": "arithmeticUpdate", - "operator": "+", + "operator": "++", "argument": { "type": "arithmeticVariable", "name": "c" From f72e34dde2879049eb7243a97275b76bc98ceaf1 Mon Sep 17 00:00:00 2001 From: Jordan Klassen Date: Tue, 22 Mar 2016 21:51:56 -0700 Subject: [PATCH 06/20] Improve variable parsing, wip number parsing --- grammar.pegjs | 8 ++++++++ overrides.js | 19 ++++++++++++++++++- .../shellcheck-tests/arithmetic10/ast.json | 15 +++++++++++++++ 3 files changed, 41 insertions(+), 1 deletion(-) create mode 100644 tests/fixtures/shellcheck-tests/arithmetic10/ast.json diff --git a/grammar.pegjs b/grammar.pegjs index 861141a..28d7299 100644 --- a/grammar.pegjs +++ b/grammar.pegjs @@ -285,6 +285,14 @@ aPostIncDec aVariable = name:writableVariableName + / "$" name:("?") /* todo, other special vars */ + / other:aNumber + +aNumber + = "0" [xX] digits:[0-9a-fA-Z]+ + / base:[0-9]+ "#" digits:[0-9a-zA-Z]+ + / "0" digits:[0-7]+ + / digits:[0-9]+ continuationStart = &( keyword / '"' / "'" / '`' / "$(" / "${" ) .* diff --git a/overrides.js b/overrides.js index c1e99c6..f3aa49b 100644 --- a/overrides.js +++ b/overrides.js @@ -316,10 +316,27 @@ rules.arithmetic = function (expression) { return expression } -rules.aVariable = function () { +function aVariable (name) { return {type: 'arithmeticVariable', name: name} } +rules.aVariable = [aVariable, aVariable, other] + +rules.aNumber = [ + function (digits) { + return {type: 'number', value: parseInt(digits, 16)} + }, + function (base, digits) { + return {type: 'number', value: parseInt(digits, parseInt(base, 10))} + }, + function (digits) { + return {type: 'number', value: parseInt(digits, 8)} + }, + function (digits) { + return {type: 'number', value: parseInt(digits, 10)} + } +] + rules.aComma = function (head, tail) { if (tail.length) { return { diff --git a/tests/fixtures/shellcheck-tests/arithmetic10/ast.json b/tests/fixtures/shellcheck-tests/arithmetic10/ast.json new file mode 100644 index 0000000..be9b6c5 --- /dev/null +++ b/tests/fixtures/shellcheck-tests/arithmetic10/ast.json @@ -0,0 +1,15 @@ +[ + { + "type": "arithmeticStatement", + "expression": { + "type": "arithmeticUnary", + "operator": "!", + "argument": { + "type": "arithmeticVariable", + "name": "?" + } + }, + "control": ";", + "next": null + } +] From b328fd1562b344bb9fb909e1e4d2b9d3cfae4eef Mon Sep 17 00:00:00 2001 From: Jordan Klassen Date: Fri, 25 Mar 2016 00:05:32 -0700 Subject: [PATCH 07/20] Properly parse numbers --- build.js | 3 ++ grammar.pegjs | 13 +++-- overrides.js | 10 ++-- quickcheck.js | 4 ++ .../shellcheck-tests/arithmetic11/ast.json | 19 ++++++++ .../shellcheck-tests/arithmetic12/ast.json | 47 +++++++++++++++++++ 6 files changed, 86 insertions(+), 10 deletions(-) create mode 100644 quickcheck.js create mode 100644 tests/fixtures/shellcheck-tests/arithmetic11/ast.json create mode 100644 tests/fixtures/shellcheck-tests/arithmetic12/ast.json diff --git a/build.js b/build.js index d0302e2..5d50b92 100644 --- a/build.js +++ b/build.js @@ -6,10 +6,12 @@ var input = __dirname + '/grammar.pegjs' var output = __dirname + '/parser.js' var overrides = __dirname + '/overrides.js' +var trace = false; if (require.main === module) { if (process.argv[2] == '-w') { watch() } else { + if (process.argv[2] == '-t') trace = true; console.log(getSource()) } } @@ -19,6 +21,7 @@ function getSource () { var grammar = fs.readFileSync(input, 'utf8') var parserSource = pegjs.buildParser(grammar, { output: "source", + trace: trace, allowedStartRules: [ 'script', 'command', diff --git a/grammar.pegjs b/grammar.pegjs index 28d7299..37d6f88 100644 --- a/grammar.pegjs +++ b/grammar.pegjs @@ -215,7 +215,7 @@ aComma "a sequence of arithmetic expressions" = head:aAssign tail:( space* "," space* aComma )* aAssign "an arithmetic assignment" - = left:aVariable space* operator:( "=" / "*=" / "/=" / "%=" / "+=" / "-=" / "<<=" / ">>=" / "&=" / "^=" / "|=" ) space* right:aAssign + = left:aLiteral space* operator:( "=" / "*=" / "/=" / "%=" / "+=" / "-=" / "<<=" / ">>=" / "&=" / "^=" / "|=" ) space* right:aAssign / other:aCond aCond "an arithmetic conditional expression" @@ -280,13 +280,16 @@ aPreIncDec aPostIncDec // = argument:aPostIncDec space* operator:( "++" / "--" ) // TODO: figure out how to do this - = argument:aVariable space* operator:( "++" / "--" ) // TODO: figure out how to do this - / other:aVariable + = argument:aLiteral space* operator:( "++" / "--" ) // TODO: figure out how to do this + / other:aLiteral aVariable = name:writableVariableName - / "$" name:("?") /* todo, other special vars */ - / other:aNumber + / "$" name:"?" /* todo, other special vars */ + +aLiteral + = val:aNumber { return val } + / val:aVariable { return val } aNumber = "0" [xX] digits:[0-9a-fA-Z]+ diff --git a/overrides.js b/overrides.js index f3aa49b..f55f6d3 100644 --- a/overrides.js +++ b/overrides.js @@ -320,20 +320,20 @@ function aVariable (name) { return {type: 'arithmeticVariable', name: name} } -rules.aVariable = [aVariable, aVariable, other] +rules.aVariable = [aVariable, aVariable] rules.aNumber = [ function (digits) { - return {type: 'number', value: parseInt(digits, 16)} + return {type: 'number', value: parseInt(digits.join(''), 16)} }, function (base, digits) { - return {type: 'number', value: parseInt(digits, parseInt(base, 10))} + return {type: 'number', value: parseInt(digits.join(''), parseInt(base.join(''), 10))} }, function (digits) { - return {type: 'number', value: parseInt(digits, 8)} + return {type: 'number', value: parseInt(digits.join(''), 8)} }, function (digits) { - return {type: 'number', value: parseInt(digits, 10)} + return {type: 'number', value: parseInt(digits.join(''), 10)} } ] diff --git a/quickcheck.js b/quickcheck.js new file mode 100644 index 0000000..0b375ce --- /dev/null +++ b/quickcheck.js @@ -0,0 +1,4 @@ +const util = require('util') +var parser = require("./" + process.argv[2]) +var parse = parser.parse || parser; +process.stdout.write(util.inspect(parse(process.argv[3]), {depth: null})) diff --git a/tests/fixtures/shellcheck-tests/arithmetic11/ast.json b/tests/fixtures/shellcheck-tests/arithmetic11/ast.json new file mode 100644 index 0000000..e37377b --- /dev/null +++ b/tests/fixtures/shellcheck-tests/arithmetic11/ast.json @@ -0,0 +1,19 @@ +[ + { + "type": "arithmeticStatement", + "expression": { + "type": "arithmeticBinary", + "left": { + "type": "number", + "value": 8 + }, + "operator": "*", + "right": { + "type": "number", + "value": 15 + } + }, + "control": ";", + "next": null + } +] diff --git a/tests/fixtures/shellcheck-tests/arithmetic12/ast.json b/tests/fixtures/shellcheck-tests/arithmetic12/ast.json new file mode 100644 index 0000000..1fce0b5 --- /dev/null +++ b/tests/fixtures/shellcheck-tests/arithmetic12/ast.json @@ -0,0 +1,47 @@ +[ + { + "type": "arithmeticStatement", + "expression": { + "type": "arithmeticBinary", + "operator": "+", + "left": { + "type": "commandSubstitution", + "commands": [ + { + "type": "subshell", + "statements": [ + { + "type": "command", + "command": { + "type": "arithmeticBinary", + "operator": "+", + "left": { + "type": "number", + "value": 3 + }, + "right": { + "type": "number", + "value": 2 + } + }, + "args": [], + "redirects": [], + "env": {}, + "control": ";", + "next": null + } + ], + "control": ";", + "next": null + } + ] + }, + "right": { + "type": "number", + "value": "37" + } + }, + "control": ";", + "next": null + } +] From fe6548ef5d4438ee27b752f0f6bb5849ac183d5b Mon Sep 17 00:00:00 2001 From: Jordan Klassen Date: Fri, 25 Mar 2016 18:16:10 -0700 Subject: [PATCH 08/20] wip additional parsing --- build.js | 2 + grammar.pegjs | 51 +++++++++++-------- overrides.js | 2 - package.json | 2 +- quickcheck.js | 2 + .../shellcheck-tests/arithmetic3/ast.json | 27 ++++++++++ .../shellcheck-tests/arithmetic4/ast.json | 27 ++++++++++ tests/shellcheck-fixtures.js | 4 +- 8 files changed, 91 insertions(+), 26 deletions(-) mode change 100644 => 100755 build.js mode change 100644 => 100755 quickcheck.js create mode 100644 tests/fixtures/shellcheck-tests/arithmetic3/ast.json create mode 100644 tests/fixtures/shellcheck-tests/arithmetic4/ast.json diff --git a/build.js b/build.js old mode 100644 new mode 100755 index 5d50b92..8f82ffb --- a/build.js +++ b/build.js @@ -1,3 +1,5 @@ +#!/usr/bin/env node + var fs = require('fs') var pegjs = require('pegjs') var overrideAction = require('pegjs-override-action') diff --git a/grammar.pegjs b/grammar.pegjs index 37d6f88..0c75524 100644 --- a/grammar.pegjs +++ b/grammar.pegjs @@ -212,83 +212,92 @@ arithmetic "an arithmetic expression" = expression:aComma aComma "a sequence of arithmetic expressions" - = head:aAssign tail:( space* "," space* aComma )* + = head:aAssign tail:( spaceNL* "," spaceNL* aComma )* aAssign "an arithmetic assignment" - = left:aLiteral space* operator:( "=" / "*=" / "/=" / "%=" / "+=" / "-=" / "<<=" / ">>=" / "&=" / "^=" / "|=" ) space* right:aAssign + = left:aCond spaceNL* operator:( "=" / "*=" / "/=" / "%=" / "+=" / "-=" / "<<=" / ">>=" / "&=" / "^=" / "|=" ) spaceNL* right:aAssign / other:aCond aCond "an arithmetic conditional expression" - = test:aLogicalOr space* "?" space* consequent:aCond space* ":" space* alternate:aCond + = test:aLogicalOr spaceNL* "?" spaceNL* consequent:aCond spaceNL* ":" spaceNL* alternate:aCond / other:aLogicalOr aLogicalOr "an arithmetic logical or" - = left:aLogicalAnd space* "||" space* right:aLogicalOr + = left:aLogicalAnd spaceNL* "||" spaceNL* right:aLogicalOr / other:aLogicalAnd aLogicalAnd "an arithmetic logical and" - = left:aBitwiseOr space* "&&" space* right:aLogicalAnd + = left:aBitwiseOr spaceNL* "&&" spaceNL* right:aLogicalAnd / other:aBitwiseOr aBitwiseOr - = left:aBitwiseXor space* operator:"|" space* right:aBitwiseOr + = left:aBitwiseXor spaceNL* operator:"|" spaceNL* right:aBitwiseOr / other:aBitwiseXor aBitwiseXor - = left:aBitwiseAnd space* operator:"^" space* right:aBitwiseXor + = left:aBitwiseAnd spaceNL* operator:"^" spaceNL* right:aBitwiseXor / other:aBitwiseAnd aBitwiseAnd - = left:aEquality space* operator:"&" space* right:aBitwiseAnd + = left:aEquality spaceNL* operator:"&" spaceNL* right:aBitwiseAnd / other:aEquality aEquality - = left:aComparison space* operator:( "==" / "!=" ) space* right:aEquality + = left:aComparison spaceNL* operator:( "==" / "!=" ) spaceNL* right:aEquality / other:aComparison aComparison - = left:aBitwiseShift space* operator:( "<=" / ">=" / "<" / ">" ) space* right:aComparison + = left:aBitwiseShift spaceNL* operator:( "<=" / ">=" / "<" / ">" ) spaceNL* right:aComparison / other:aBitwiseShift aBitwiseShift - = left:aAddSubtract space* operator:( "<<" / ">>" ) space* right:aBitwiseShift + = left:aAddSubtract spaceNL* operator:( "<<" / ">>" ) spaceNL* right:aBitwiseShift / other:aAddSubtract aAddSubtract - = left:aMultDivModulo space* operator:( "+" / "-" ) space* right:aAddSubtract + = left:aMultDivModulo spaceNL* operator:( "+" / "-" ) spaceNL* right:aAddSubtract / other:aMultDivModulo aMultDivModulo - = left:aExponent space* operator:( "*" / "/" ) space* right:aMultDivModulo + = left:aExponent spaceNL* operator:( "*" / "/" ) spaceNL* right:aMultDivModulo / other:aExponent aExponent - = left:aNegation space* operator:"**" space* right:aExponent + = left:aNegation spaceNL* operator:"**" spaceNL* right:aExponent / other:aNegation aNegation - = operator:( "!" / "~" ) space* argument:aNegation + = operator:( "!" / "~" ) spaceNL* argument:aNegation / other:aUnary aUnary - = operator:( "+" !"+" / "-" !"-" ) space* argument:aUnary + = operator:( "+" !"+" / "-" !"-" ) spaceNL* argument:aUnary / other:aPreIncDec aPreIncDec - = operator:( "++" / "--" ) space* argument:aPreIncDec + = operator:( "++" / "--" ) spaceNL* argument:aPreIncDec / other:aPostIncDec aPostIncDec - // = argument:aPostIncDec space* operator:( "++" / "--" ) // TODO: figure out how to do this - = argument:aLiteral space* operator:( "++" / "--" ) // TODO: figure out how to do this - / other:aLiteral + // = argument:aPostIncDec spaceNL* operator:( "++" / "--" ) // TODO: figure out how to do this + = argument:aParenExpr spaceNL* operator:( "++" / "--" ) // TODO: figure out how to do this + / other:aParenExpr + +aParenExpr + = '(' spaceNL* value:arithmetic spaceNL* ')' { return value } + / other:aLiteral { return other } aVariable = name:writableVariableName - / "$" name:"?" /* todo, other special vars */ + / '$' name:readableVariableName + +aConcatenation + = singleQuote + / doubleQuote aLiteral = val:aNumber { return val } + / val:aConcatenation { return val } / val:aVariable { return val } aNumber diff --git a/overrides.js b/overrides.js index f55f6d3..7b7c155 100644 --- a/overrides.js +++ b/overrides.js @@ -393,8 +393,6 @@ rules.aLogicalAnd = [ }, other ] -rules.aBitwiseOr = -rules.aLogicalAnd = rules.aBitwiseOr = rules.aBitwiseXor = rules.aBitwiseAnd = diff --git a/package.json b/package.json index 224a5e6..b9db322 100644 --- a/package.json +++ b/package.json @@ -10,7 +10,7 @@ }, "scripts": { "test": "tape tests/*.js", - "watch": "npm run prepublish && node build.js -w", + "watch": "npm run prepublish && echo watching... && node build.js -w", "prepublish": "node build.js > parser.js" }, "testling": { diff --git a/quickcheck.js b/quickcheck.js old mode 100644 new mode 100755 index 0b375ce..6731ba9 --- a/quickcheck.js +++ b/quickcheck.js @@ -1,3 +1,5 @@ +#!/usr/bin/env node + const util = require('util') var parser = require("./" + process.argv[2]) var parse = parser.parse || parser; diff --git a/tests/fixtures/shellcheck-tests/arithmetic3/ast.json b/tests/fixtures/shellcheck-tests/arithmetic3/ast.json new file mode 100644 index 0000000..8d032ef --- /dev/null +++ b/tests/fixtures/shellcheck-tests/arithmetic3/ast.json @@ -0,0 +1,27 @@ +[ + { + "type": "arithmeticStatement", + "expression": { + "type": "arithmeticAssignment", + "left": { + "type": "arithmeticVariable", + "name": "n" + }, + "operator": "|=", + "right": { + "type": "arithmeticBinary", + "operator": "<<", + "left": { + "type": "number", + "value": 2 + }, + "right": { + "type": "number", + "value": 1 + } + } + }, + "control": ";", + "next": null + } +] diff --git a/tests/fixtures/shellcheck-tests/arithmetic4/ast.json b/tests/fixtures/shellcheck-tests/arithmetic4/ast.json new file mode 100644 index 0000000..09dc0f0 --- /dev/null +++ b/tests/fixtures/shellcheck-tests/arithmetic4/ast.json @@ -0,0 +1,27 @@ +[ + { + "type": "arithmeticStatement", + "expression": { + "type": "arithmeticAssignment", + "left": { + "type": "arithmeticVariable", + "name": "n" + }, + "operator": "&=", + "right": { + "type": "arithmeticBinary", + "operator": "**", + "left": { + "type": "number", + "value": 2 + }, + "right": { + "type": "number", + "value": 3 + } + } + }, + "control": ";", + "next": null + } +] diff --git a/tests/shellcheck-fixtures.js b/tests/shellcheck-fixtures.js index 616c00d..faa20ad 100644 --- a/tests/shellcheck-fixtures.js +++ b/tests/shellcheck-fixtures.js @@ -28,9 +28,9 @@ test('shellcheck fixtures', function(t) { var source = fs.readFileSync(path.join(fixtureDir, 'source.sh'), 'utf8') var error, ast; - try { error = require(path.join(fixtureDir, 'error.json')) } catch (e) {} + try { error = require(path.resolve(fixtureDir, 'error.json')) } catch (e) {} if (!error) { - try { ast = require(path.join(fixtureDir, 'ast.json')) } catch (e) {} + try { ast = require(path.resolve(fixtureDir, 'ast.json')) } catch (e) {} } if (error) { From 8feab218a1777a513be72e2772de58c1a4f71265 Mon Sep 17 00:00:00 2001 From: Jordan Klassen Date: Fri, 25 Mar 2016 18:27:04 -0700 Subject: [PATCH 09/20] More work on arithmetic expressions (:squash) --- grammar.pegjs | 2 +- .../shellcheck-tests/arithmetic5/.error.json | 3 ++ .../shellcheck-tests/arithmetic5/ast.json | 35 +++++++++++++++++++ .../shellcheck-tests/arithmetic6/ast.json | 35 +++++++++++++++++++ .../shellcheck-tests/arithmetic7/ast.json | 27 ++++++++++++++ .../shellcheck-tests/arithmetic8/ast.json | 11 ++++++ .../shellcheck-tests/arithmetic9/ast.json | 27 ++++++++++++++ 7 files changed, 139 insertions(+), 1 deletion(-) create mode 100644 tests/fixtures/shellcheck-tests/arithmetic5/.error.json create mode 100644 tests/fixtures/shellcheck-tests/arithmetic5/ast.json create mode 100644 tests/fixtures/shellcheck-tests/arithmetic6/ast.json create mode 100644 tests/fixtures/shellcheck-tests/arithmetic7/ast.json create mode 100644 tests/fixtures/shellcheck-tests/arithmetic8/ast.json create mode 100644 tests/fixtures/shellcheck-tests/arithmetic9/ast.json diff --git a/grammar.pegjs b/grammar.pegjs index 0c75524..16810b5 100644 --- a/grammar.pegjs +++ b/grammar.pegjs @@ -271,7 +271,7 @@ aNegation / other:aUnary aUnary - = operator:( "+" !"+" / "-" !"-" ) spaceNL* argument:aUnary + = operator:( (op:"+" !"+") { return op } / (op:"-" !"-") { return op } ) spaceNL* argument:aUnary / other:aPreIncDec aPreIncDec diff --git a/tests/fixtures/shellcheck-tests/arithmetic5/.error.json b/tests/fixtures/shellcheck-tests/arithmetic5/.error.json new file mode 100644 index 0000000..66c96cc --- /dev/null +++ b/tests/fixtures/shellcheck-tests/arithmetic5/.error.json @@ -0,0 +1,3 @@ +{ + "bash_message": "attempted assignment to non-variable" +} diff --git a/tests/fixtures/shellcheck-tests/arithmetic5/ast.json b/tests/fixtures/shellcheck-tests/arithmetic5/ast.json new file mode 100644 index 0000000..6fad7c5 --- /dev/null +++ b/tests/fixtures/shellcheck-tests/arithmetic5/ast.json @@ -0,0 +1,35 @@ +[ + { + "type": "arithmeticStatement", + "expression": { + "type": "arithmeticAssignment", + "left": { + "type": "number", + "value": 1 + }, + "operator": "|=", + "right": { + "type": "arithmeticAssignment", + "left": { + "type": "arithmeticLogical", + "operator": "&&", + "left": { + "type": "number", + "value": 4 + }, + "right": { + "type": "arithmeticVariable", + "name": "n" + } + }, + "operator": ">>=", + "right": { + "type": "number", + "value": 4 + } + } + }, + "control": ";", + "next": null + } +] diff --git a/tests/fixtures/shellcheck-tests/arithmetic6/ast.json b/tests/fixtures/shellcheck-tests/arithmetic6/ast.json new file mode 100644 index 0000000..d9936c4 --- /dev/null +++ b/tests/fixtures/shellcheck-tests/arithmetic6/ast.json @@ -0,0 +1,35 @@ +[ + { + "type": "arithmeticStatement", + "expression": { + "type": "arithmeticLogical", + "operator": "||", + "left": { + "type": "arithmeticBinary", + "operator": "|", + "left": { + "type": "number", + "value": 1 + }, + "right": { + "type": "number", + "value": 2 + } + }, + "right": { + "type": "arithmeticBinary", + "operator": "|", + "left": { + "type": "number", + "value": 3 + }, + "right": { + "type": "number", + "value": 4 + } + } + }, + "control": ";", + "next": null + } +] diff --git a/tests/fixtures/shellcheck-tests/arithmetic7/ast.json b/tests/fixtures/shellcheck-tests/arithmetic7/ast.json new file mode 100644 index 0000000..5bffb8e --- /dev/null +++ b/tests/fixtures/shellcheck-tests/arithmetic7/ast.json @@ -0,0 +1,27 @@ +[ + { + "type": "arithmeticStatement", + "expression": { + "type": "arithmeticBinary", + "operator": "*", + "left": { + "type": "number", + "value": 3 + }, + "right": { + "type": "arithmeticBinary", + "operator": "**", + "left": { + "type": "number", + "value": 2 + }, + "right": { + "type": "number", + "value": 10 + } + } + }, + "control": ";", + "next": null + } +] diff --git a/tests/fixtures/shellcheck-tests/arithmetic8/ast.json b/tests/fixtures/shellcheck-tests/arithmetic8/ast.json new file mode 100644 index 0000000..5010a8e --- /dev/null +++ b/tests/fixtures/shellcheck-tests/arithmetic8/ast.json @@ -0,0 +1,11 @@ +[ + { + "type": "arithmeticStatement", + "expression": { + "type": "number", + "value": 3 + }, + "control": ";", + "next": null + } +] diff --git a/tests/fixtures/shellcheck-tests/arithmetic9/ast.json b/tests/fixtures/shellcheck-tests/arithmetic9/ast.json new file mode 100644 index 0000000..a4a379e --- /dev/null +++ b/tests/fixtures/shellcheck-tests/arithmetic9/ast.json @@ -0,0 +1,27 @@ +[ + { + "type": "arithmeticStatement", + "expression": { + "type": "arithmeticBinary", + "operator": "^", + "left": { + "type": "arithmeticVariable", + "name": "a" + }, + "right": { + "type": "arithmeticUnary", + "operator": "!", + "argument": { + "type": "arithmeticUnary", + "operator": "-", + "argument": { + "type": "arithmeticVariable", + "name": "b" + } + } + } + }, + "control": ";", + "next": null + } +] From d5fa2c45378c7813a9dbaa7e3453a4d58ec54a5f Mon Sep 17 00:00:00 2001 From: Jordan Klassen Date: Tue, 5 Apr 2016 19:23:34 -0700 Subject: [PATCH 10/20] Implement recursive postfix parsing --- grammar.pegjs | 3 +-- overrides.js | 17 +++++++++++------ 2 files changed, 12 insertions(+), 8 deletions(-) diff --git a/grammar.pegjs b/grammar.pegjs index 16810b5..9695e73 100644 --- a/grammar.pegjs +++ b/grammar.pegjs @@ -279,8 +279,7 @@ aPreIncDec / other:aPostIncDec aPostIncDec - // = argument:aPostIncDec spaceNL* operator:( "++" / "--" ) // TODO: figure out how to do this - = argument:aParenExpr spaceNL* operator:( "++" / "--" ) // TODO: figure out how to do this + = argument:aParenExpr operators:(spaceNL* op:( "++" / "--" ) { return op })+ / other:aParenExpr aParenExpr diff --git a/overrides.js b/overrides.js index 7b7c155..f0f1a69 100644 --- a/overrides.js +++ b/overrides.js @@ -435,12 +435,17 @@ rules.aPreIncDec = [ ] rules.aPostIncDec = [ - function (argument) { - return { - type: 'arithmeticUpdate', - operator: operator, - argument: argument, - prefix: false + function (argument, operators) { + var node = argument; + // build the recursive structure from the list of suffix operators + for (var i = 0, l = operators.length; i < l; i++) { + node = { + type: 'arithmeticUpdate', + operator: operators[i], + argument: node, + prefix: false + } } + return node; }, other ] From 23087754b5ad175b974683fb9ccf7376ef4144f8 Mon Sep 17 00:00:00 2001 From: Jordan Klassen Date: Thu, 7 Apr 2016 19:50:04 -0700 Subject: [PATCH 11/20] fix infix parsing recursion --- grammar.pegjs | 41 +++++++++++++----------------------- overrides.js | 58 ++++++++++++++++++++++++--------------------------- 2 files changed, 42 insertions(+), 57 deletions(-) diff --git a/grammar.pegjs b/grammar.pegjs index 9695e73..4b822e1 100644 --- a/grammar.pegjs +++ b/grammar.pegjs @@ -209,62 +209,51 @@ keyword // http://www.gnu.org/software/bash/manual/html_node/Shell-Arithmetic.html arithmetic "an arithmetic expression" - = expression:aComma + = expression:aComma { return expression } aComma "a sequence of arithmetic expressions" - = head:aAssign tail:( spaceNL* "," spaceNL* aComma )* + = head:aAssign tail:( spaceNL* "," spaceNL* aAssign )* aAssign "an arithmetic assignment" - = left:aCond spaceNL* operator:( "=" / "*=" / "/=" / "%=" / "+=" / "-=" / "<<=" / ">>=" / "&=" / "^=" / "|=" ) spaceNL* right:aAssign + = left:aCond spaceNL* operator:( "=" !"=" / "*=" / "/=" / "%=" / "+=" / "-=" / "<<=" / ">>=" / "&=" / "^=" / "|=" ) spaceNL* right:aAssign / other:aCond aCond "an arithmetic conditional expression" - = test:aLogicalOr spaceNL* "?" spaceNL* consequent:aCond spaceNL* ":" spaceNL* alternate:aCond + = test:aLogicalOr spaceNL* "?" spaceNL* consequent:aAssign spaceNL* ":" spaceNL* alternate:aAssign / other:aLogicalOr aLogicalOr "an arithmetic logical or" - = left:aLogicalAnd spaceNL* "||" spaceNL* right:aLogicalOr - / other:aLogicalAnd + = head:aLogicalAnd tail:(spaceNL* op:"||" spaceNL* node:aLogicalAnd { return {op: op, node: node} })* aLogicalAnd "an arithmetic logical and" - = left:aBitwiseOr spaceNL* "&&" spaceNL* right:aLogicalAnd - / other:aBitwiseOr + = head:aBitwiseOr tail:(spaceNL* op:"&&" spaceNL* node:aBitwiseOr { return {op: op, node: node} })* aBitwiseOr - = left:aBitwiseXor spaceNL* operator:"|" spaceNL* right:aBitwiseOr - / other:aBitwiseXor + = head:aBitwiseXor tail:(spaceNL* op:("|" ![|=]) spaceNL* node:aBitwiseXor { return {op: op, node: node} })* aBitwiseXor - = left:aBitwiseAnd spaceNL* operator:"^" spaceNL* right:aBitwiseXor - / other:aBitwiseAnd + = head:aBitwiseAnd tail:(spaceNL* op:"^" spaceNL* node:aBitwiseAnd { return {op: op, node: node} })* aBitwiseAnd - = left:aEquality spaceNL* operator:"&" spaceNL* right:aBitwiseAnd - / other:aEquality + = head:aEquality tail:(spaceNL* op:"&" spaceNL* node:aEquality { return {op: op, node: node} })* aEquality - = left:aComparison spaceNL* operator:( "==" / "!=" ) spaceNL* right:aEquality - / other:aComparison + = head:aComparison tail:(spaceNL* op:( "==" / "!=" ) spaceNL* node:aComparison { return {op: op, node: node} })* aComparison - = left:aBitwiseShift spaceNL* operator:( "<=" / ">=" / "<" / ">" ) spaceNL* right:aComparison - / other:aBitwiseShift + = head:aBitwiseShift tail:(spaceNL* op:( "<=" / ">=" / "<" / ">" ) spaceNL* node:aBitwiseShift { return {op: op, node: node} })* aBitwiseShift - = left:aAddSubtract spaceNL* operator:( "<<" / ">>" ) spaceNL* right:aBitwiseShift - / other:aAddSubtract + = head:aAddSubtract tail:(spaceNL* op:( "<<" / ">>" ) spaceNL* node:aAddSubtract { return {op: op, node: node} })* aAddSubtract - = left:aMultDivModulo spaceNL* operator:( "+" / "-" ) spaceNL* right:aAddSubtract - / other:aMultDivModulo + = head:aMultDivModulo tail:(spaceNL* op:( "+" / "-" ) spaceNL* node:aMultDivModulo { return {op: op, node: node} })* aMultDivModulo - = left:aExponent spaceNL* operator:( "*" / "/" ) spaceNL* right:aMultDivModulo - / other:aExponent + = head:aExponent tail:(spaceNL* op:( "*" / "/" ) spaceNL* node:aExponent { return {op: op, node: node} })* aExponent - = left:aNegation spaceNL* operator:"**" spaceNL* right:aExponent - / other:aNegation + = head:aNegation tail:(spaceNL* op:"**" spaceNL* node:aNegation { return {op: op, node: node} })* aNegation = operator:( "!" / "~" ) spaceNL* argument:aNegation diff --git a/overrides.js b/overrides.js index f0f1a69..039bc91 100644 --- a/overrides.js +++ b/overrides.js @@ -67,6 +67,14 @@ exports.initializer = [ type: 'concatenation', pieces: result } + }, + // create a nested tree from a list of same-precedence operators + function buildTree(head, tail, createNode) { + var result = head; + for (var i = 0, l = tail.length; i < l; i++) { + result = createNode(result, tail[i]); + } + return result; } ].join('\n') @@ -312,10 +320,6 @@ rules.redirectFd = function (fd, op, filename) { } } -rules.arithmetic = function (expression) { - return expression -} - function aVariable (name) { return {type: 'arithmeticVariable', name: name} } @@ -371,27 +375,18 @@ rules.aAssign = [ }, other ] -rules.aLogicalOr = [ - function (left, right) { +rules.aLogicalOr = +rules.aLogicalAnd = +function (head, tail) { + return buildTree(head, tail, function (child, current) { return { type: 'arithmeticLogical', - operator: '||', - left: left, - right: right + operator: current.op, + left: child, + right: current.node } - }, other -] - -rules.aLogicalAnd = [ - function (left, right) { - return { - type: 'arithmeticLogical', - operator: '&&', - left: left, - right: right - } - }, other -] + }); +} rules.aBitwiseOr = rules.aBitwiseXor = @@ -402,15 +397,16 @@ rules.aBitwiseShift = rules.aAddSubtract = rules.aMultDivModulo = rules.aExponent = -[ - function arithmeticBinary(left, operator, right) { - return { - type: 'arithmeticBinary', - operator: operator, - left: left, - right: right - } -}, other] +function (head, tail) { + return buildTree(head, tail, function (child, current) { + return { + type: 'arithmeticBinary', + operator: current.op, + left: child, + right: current.node + } + }); +} rules.aNegation = rules.aUnary = [ From f9c9f584c5b87f8a3ff5fe54d91aba5af5c1655b Mon Sep 17 00:00:00 2001 From: Jordan Klassen Date: Thu, 7 Apr 2016 20:26:53 -0700 Subject: [PATCH 12/20] use buildtree for postfix incdec --- overrides.js | 11 ++++------- 1 file changed, 4 insertions(+), 7 deletions(-) diff --git a/overrides.js b/overrides.js index 039bc91..ac5869a 100644 --- a/overrides.js +++ b/overrides.js @@ -432,16 +432,13 @@ rules.aPreIncDec = [ rules.aPostIncDec = [ function (argument, operators) { - var node = argument; - // build the recursive structure from the list of suffix operators - for (var i = 0, l = operators.length; i < l; i++) { - node = { + return buildTree(argument, operators, function (node, operator) { + return { type: 'arithmeticUpdate', - operator: operators[i], + operator: operator, argument: node, prefix: false } - } - return node; + }); }, other ] From b7f342faac004d526361e61d61be0ddfd225ee30 Mon Sep 17 00:00:00 2001 From: Jordan Klassen Date: Thu, 7 Apr 2016 20:38:53 -0700 Subject: [PATCH 13/20] protect against bad tokenization --- grammar.pegjs | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/grammar.pegjs b/grammar.pegjs index 4b822e1..42ccb92 100644 --- a/grammar.pegjs +++ b/grammar.pegjs @@ -229,28 +229,28 @@ aLogicalAnd "an arithmetic logical and" = head:aBitwiseOr tail:(spaceNL* op:"&&" spaceNL* node:aBitwiseOr { return {op: op, node: node} })* aBitwiseOr - = head:aBitwiseXor tail:(spaceNL* op:("|" ![|=]) spaceNL* node:aBitwiseXor { return {op: op, node: node} })* + = head:aBitwiseXor tail:(spaceNL* op:"|" ![|=] spaceNL* node:aBitwiseXor { return {op: op, node: node} })* aBitwiseXor - = head:aBitwiseAnd tail:(spaceNL* op:"^" spaceNL* node:aBitwiseAnd { return {op: op, node: node} })* + = head:aBitwiseAnd tail:(spaceNL* op:"^" !"=" spaceNL* node:aBitwiseAnd { return {op: op, node: node} })* aBitwiseAnd - = head:aEquality tail:(spaceNL* op:"&" spaceNL* node:aEquality { return {op: op, node: node} })* + = head:aEquality tail:(spaceNL* op:"&" ![&=] spaceNL* node:aEquality { return {op: op, node: node} })* aEquality = head:aComparison tail:(spaceNL* op:( "==" / "!=" ) spaceNL* node:aComparison { return {op: op, node: node} })* aComparison - = head:aBitwiseShift tail:(spaceNL* op:( "<=" / ">=" / "<" / ">" ) spaceNL* node:aBitwiseShift { return {op: op, node: node} })* + = head:aBitwiseShift tail:(spaceNL* op:( "<=" / ">=" / (v:"<" !"<" { return v }) / (v:">" !">" { return v }) ) spaceNL* node:aBitwiseShift { return {op: op, node: node} })* aBitwiseShift - = head:aAddSubtract tail:(spaceNL* op:( "<<" / ">>" ) spaceNL* node:aAddSubtract { return {op: op, node: node} })* + = head:aAddSubtract tail:(spaceNL* op:( "<<" / ">>" ) !"=" spaceNL* node:aAddSubtract { return {op: op, node: node} })* aAddSubtract - = head:aMultDivModulo tail:(spaceNL* op:( "+" / "-" ) spaceNL* node:aMultDivModulo { return {op: op, node: node} })* + = head:aMultDivModulo tail:(spaceNL* op:( "+" / "-" ) !"=" spaceNL* node:aMultDivModulo { return {op: op, node: node} })* aMultDivModulo - = head:aExponent tail:(spaceNL* op:( "*" / "/" ) spaceNL* node:aExponent { return {op: op, node: node} })* + = head:aExponent tail:(spaceNL* op:( (v:"*" !"*" { return v }) / "/" / "%") !"=" spaceNL* node:aExponent { return {op: op, node: node} })* aExponent = head:aNegation tail:(spaceNL* op:"**" spaceNL* node:aNegation { return {op: op, node: node} })* @@ -260,7 +260,7 @@ aNegation / other:aUnary aUnary - = operator:( (op:"+" !"+") { return op } / (op:"-" !"-") { return op } ) spaceNL* argument:aUnary + = operator:( (op:"+" ![+=]) { return op } / (op:"-" ![-=]) { return op } ) spaceNL* argument:aUnary / other:aPreIncDec aPreIncDec From 91318434b823060a79711b2f3431098708571715 Mon Sep 17 00:00:00 2001 From: Jordan Klassen Date: Fri, 8 Apr 2016 19:45:22 -0700 Subject: [PATCH 14/20] properly parse arithmeticcomma, generate arithmeticSeq node --- grammar.pegjs | 8 ++-- overrides.js | 7 +++ .../shellcheck-tests/arithmetic12/ast.json | 43 ++++++------------- .../shellcheck-tests/arithmetic2/ast.json | 36 ++++++++++++++++ 4 files changed, 61 insertions(+), 33 deletions(-) create mode 100644 tests/fixtures/shellcheck-tests/arithmetic2/ast.json diff --git a/grammar.pegjs b/grammar.pegjs index 42ccb92..bc655ae 100644 --- a/grammar.pegjs +++ b/grammar.pegjs @@ -89,6 +89,7 @@ concatenation "concatenation of strings and/or variables" / bareword / environmentVariable / variableSubstitution + / arithmeticSubstitution / commandSubstitution / singleQuote / doubleQuote @@ -127,7 +128,8 @@ doubleQuoteMeta = '"' / '$' / '`' expandsInQuotes - = commandSubstitution + = arithmeticSubstitution + / commandSubstitution / environmentVariable / variableSubstitution @@ -212,7 +214,7 @@ arithmetic "an arithmetic expression" = expression:aComma { return expression } aComma "a sequence of arithmetic expressions" - = head:aAssign tail:( spaceNL* "," spaceNL* aAssign )* + = head:aAssign tail:( spaceNL* "," spaceNL* expr:aAssign { return expr } )* aAssign "an arithmetic assignment" = left:aCond spaceNL* operator:( "=" !"=" / "*=" / "/=" / "%=" / "+=" / "-=" / "<<=" / ">>=" / "&=" / "^=" / "|=" ) spaceNL* right:aAssign @@ -295,7 +297,7 @@ aNumber / digits:[0-9]+ continuationStart - = &( keyword / '"' / "'" / '`' / "$(" / "${" ) .* + = &( keyword / '"' / "'" / '`' / "$(" / "$((" / "${" ) .* EOF = !. diff --git a/overrides.js b/overrides.js index ac5869a..4ab2961 100644 --- a/overrides.js +++ b/overrides.js @@ -282,6 +282,13 @@ rules.parenCommandSubstitution = function (commands) { } } +rules.arithmeticSubstitution = function (expression) { + return { + type: 'arithmeticSubstitution', + expression: expression + }; +} + rules.backQuote = function (input) { return { type: 'commandSubstitution', commands: parse(input.join('')) } } diff --git a/tests/fixtures/shellcheck-tests/arithmetic12/ast.json b/tests/fixtures/shellcheck-tests/arithmetic12/ast.json index 1fce0b5..d059078 100644 --- a/tests/fixtures/shellcheck-tests/arithmetic12/ast.json +++ b/tests/fixtures/shellcheck-tests/arithmetic12/ast.json @@ -5,39 +5,22 @@ "type": "arithmeticBinary", "operator": "+", "left": { - "type": "commandSubstitution", - "commands": [ - { - "type": "subshell", - "statements": [ - { - "type": "command", - "command": { - "type": "arithmeticBinary", - "operator": "+", - "left": { - "type": "number", - "value": 3 - }, - "right": { - "type": "number", - "value": 2 - } - }, - "args": [], - "redirects": [], - "env": {}, - "control": ";", - "next": null - } - ], - "control": ";", - "next": null + "type": "arithmeticSubstitution", + "expression": { + "type": "arithmeticBinary", + "operator": "+", + "left": { + "type": "number", + "value": 3 + }, + "right": { + "type": "number", + "value": 2 } - ] + } }, "right": { - "type": "number", + "type": "literal", "value": "37" } }, diff --git a/tests/fixtures/shellcheck-tests/arithmetic2/ast.json b/tests/fixtures/shellcheck-tests/arithmetic2/ast.json new file mode 100644 index 0000000..eaef1f2 --- /dev/null +++ b/tests/fixtures/shellcheck-tests/arithmetic2/ast.json @@ -0,0 +1,36 @@ +[ + { + "type": "arithmeticStatement", + "expression": { + "type": "arithmeticBinary", + "operator": "-", + "left": { + "type": "arithmeticBinary", + "operator": "*", + "left": { + "type": "arithmeticVariable", + "name": "N" + }, + "right": { + "type": "number", + "value": 4 + } + }, + "right": { + "type": "arithmeticSequence", + "expressions": [ + { + "type": "number", + "value": 3 + }, + { + "type": "number", + "value": 2 + } + ] + } + }, + "control": ";", + "next": null + } +] From 55e6430b9914a12ad2f1dcfa5b9563d35c457dce Mon Sep 17 00:00:00 2001 From: Jordan Klassen Date: Fri, 8 Apr 2016 20:12:00 -0700 Subject: [PATCH 15/20] better concatenation parsing, rename arithmeticVariable -> variable --- grammar.pegjs | 24 ++++++++---- overrides.js | 10 +++-- .../arithmetic-expression/ast.json | 6 +-- .../shellcheck-tests/arithmetic1/ast.json | 4 +- .../shellcheck-tests/arithmetic10/ast.json | 2 +- .../shellcheck-tests/arithmetic14/ast.json | 37 +++++++++++++++++++ .../shellcheck-tests/arithmetic16/ast.json | 20 ++++++++++ .../shellcheck-tests/arithmetic2/ast.json | 2 +- .../shellcheck-tests/arithmetic3/ast.json | 2 +- .../shellcheck-tests/arithmetic4/ast.json | 2 +- .../shellcheck-tests/arithmetic5/ast.json | 2 +- .../shellcheck-tests/arithmetic9/ast.json | 4 +- 12 files changed, 93 insertions(+), 22 deletions(-) create mode 100644 tests/fixtures/shellcheck-tests/arithmetic14/ast.json create mode 100644 tests/fixtures/shellcheck-tests/arithmetic16/ast.json diff --git a/grammar.pegjs b/grammar.pegjs index bc655ae..46c019c 100644 --- a/grammar.pegjs +++ b/grammar.pegjs @@ -277,18 +277,28 @@ aParenExpr = '(' spaceNL* value:arithmetic spaceNL* ')' { return value } / other:aLiteral { return other } -aVariable - = name:writableVariableName - / '$' name:readableVariableName +aBareword "arithmetic variable" + = !'#' name:aBarewordChar+ -aConcatenation - = singleQuote - / doubleQuote +aBarewordChar + = '\\' chr:aBarewordMeta { return chr } + / !aBarewordMeta chr:. { return chr } + +aBarewordMeta = [$"';&<>\n()\[*?|`:+ ] + +aConcatenation "concatenation of strings and/or variables" + = pieces:( aBareword + / environmentVariable + / variableSubstitution + / arithmeticSubstitution + / commandSubstitution + / singleQuote + / doubleQuote + )+ aLiteral = val:aNumber { return val } / val:aConcatenation { return val } - / val:aVariable { return val } aNumber = "0" [xX] digits:[0-9a-fA-Z]+ diff --git a/overrides.js b/overrides.js index 4ab2961..84bcddd 100644 --- a/overrides.js +++ b/overrides.js @@ -327,11 +327,15 @@ rules.redirectFd = function (fd, op, filename) { } } -function aVariable (name) { - return {type: 'arithmeticVariable', name: name} +rules.aBareword = function (name) { + // TODO: check if array + return {type: 'variable', name: name.join('')} } -rules.aVariable = [aVariable, aVariable] +rules.aConcatenation = function (pieces) { + // TODO: if it's an array, nest it + return flattenConcatenation(pieces) +} rules.aNumber = [ function (digits) { diff --git a/tests/fixtures/shellcheck-tests/arithmetic-expression/ast.json b/tests/fixtures/shellcheck-tests/arithmetic-expression/ast.json index 70252f3..3fea4e5 100644 --- a/tests/fixtures/shellcheck-tests/arithmetic-expression/ast.json +++ b/tests/fixtures/shellcheck-tests/arithmetic-expression/ast.json @@ -4,15 +4,15 @@ "expression": { "type": "arithmeticConditional", "test": { - "type": "arithmeticVariable", + "type": "variable", "name": "a" }, "consequent": { - "type": "arithmeticVariable", + "type": "variable", "name": "b" }, "alternate": { - "type": "arithmeticVariable", + "type": "variable", "name": "c" } }, diff --git a/tests/fixtures/shellcheck-tests/arithmetic1/ast.json b/tests/fixtures/shellcheck-tests/arithmetic1/ast.json index 27f6994..d0d94d1 100644 --- a/tests/fixtures/shellcheck-tests/arithmetic1/ast.json +++ b/tests/fixtures/shellcheck-tests/arithmetic1/ast.json @@ -8,7 +8,7 @@ "type": "arithmeticUpdate", "operator": "++", "argument": { - "type": "arithmeticVariable", + "type": "variable", "name": "n" }, "prefix": false @@ -17,7 +17,7 @@ "type": "arithmeticUpdate", "operator": "++", "argument": { - "type": "arithmeticVariable", + "type": "variable", "name": "c" }, "prefix": true diff --git a/tests/fixtures/shellcheck-tests/arithmetic10/ast.json b/tests/fixtures/shellcheck-tests/arithmetic10/ast.json index be9b6c5..e2fa118 100644 --- a/tests/fixtures/shellcheck-tests/arithmetic10/ast.json +++ b/tests/fixtures/shellcheck-tests/arithmetic10/ast.json @@ -5,7 +5,7 @@ "type": "arithmeticUnary", "operator": "!", "argument": { - "type": "arithmeticVariable", + "type": "variable", "name": "?" } }, diff --git a/tests/fixtures/shellcheck-tests/arithmetic14/ast.json b/tests/fixtures/shellcheck-tests/arithmetic14/ast.json new file mode 100644 index 0000000..1292dfe --- /dev/null +++ b/tests/fixtures/shellcheck-tests/arithmetic14/ast.json @@ -0,0 +1,37 @@ +[ + { + "type": "arithmeticStatement", + "expression": { + "type": "arithmeticBinary", + "operator": "+", + "left": { + "type": "number", + "value": 1 + }, + "right": { + "type": "commandSubstitution", + "commands": [ + { + "type": "command", + "command": { + "type": "literal", + "value": "echo" + }, + "args": [ + { + "type": "literal", + "value": "2" + } + ], + "redirects": [], + "env": {}, + "control": ";", + "next": null + } + ] + } + }, + "control": ";", + "next": null + } +] diff --git a/tests/fixtures/shellcheck-tests/arithmetic16/ast.json b/tests/fixtures/shellcheck-tests/arithmetic16/ast.json new file mode 100644 index 0000000..bfd6e93 --- /dev/null +++ b/tests/fixtures/shellcheck-tests/arithmetic16/ast.json @@ -0,0 +1,20 @@ +[ + { + "type": "arithmeticStatement", + "expression": { + "type": "concatenation", + "pieces": [ + { + "type": "variable", + "name": "foo" + }, + { + "type": "variable", + "name": "bar" + } + ] + }, + "control": ";", + "next": null + } +] diff --git a/tests/fixtures/shellcheck-tests/arithmetic2/ast.json b/tests/fixtures/shellcheck-tests/arithmetic2/ast.json index eaef1f2..a3c376a 100644 --- a/tests/fixtures/shellcheck-tests/arithmetic2/ast.json +++ b/tests/fixtures/shellcheck-tests/arithmetic2/ast.json @@ -8,7 +8,7 @@ "type": "arithmeticBinary", "operator": "*", "left": { - "type": "arithmeticVariable", + "type": "variable", "name": "N" }, "right": { diff --git a/tests/fixtures/shellcheck-tests/arithmetic3/ast.json b/tests/fixtures/shellcheck-tests/arithmetic3/ast.json index 8d032ef..7895898 100644 --- a/tests/fixtures/shellcheck-tests/arithmetic3/ast.json +++ b/tests/fixtures/shellcheck-tests/arithmetic3/ast.json @@ -4,7 +4,7 @@ "expression": { "type": "arithmeticAssignment", "left": { - "type": "arithmeticVariable", + "type": "variable", "name": "n" }, "operator": "|=", diff --git a/tests/fixtures/shellcheck-tests/arithmetic4/ast.json b/tests/fixtures/shellcheck-tests/arithmetic4/ast.json index 09dc0f0..4b77d73 100644 --- a/tests/fixtures/shellcheck-tests/arithmetic4/ast.json +++ b/tests/fixtures/shellcheck-tests/arithmetic4/ast.json @@ -4,7 +4,7 @@ "expression": { "type": "arithmeticAssignment", "left": { - "type": "arithmeticVariable", + "type": "variable", "name": "n" }, "operator": "&=", diff --git a/tests/fixtures/shellcheck-tests/arithmetic5/ast.json b/tests/fixtures/shellcheck-tests/arithmetic5/ast.json index 6fad7c5..c9c5935 100644 --- a/tests/fixtures/shellcheck-tests/arithmetic5/ast.json +++ b/tests/fixtures/shellcheck-tests/arithmetic5/ast.json @@ -18,7 +18,7 @@ "value": 4 }, "right": { - "type": "arithmeticVariable", + "type": "variable", "name": "n" } }, diff --git a/tests/fixtures/shellcheck-tests/arithmetic9/ast.json b/tests/fixtures/shellcheck-tests/arithmetic9/ast.json index a4a379e..8e9d0a7 100644 --- a/tests/fixtures/shellcheck-tests/arithmetic9/ast.json +++ b/tests/fixtures/shellcheck-tests/arithmetic9/ast.json @@ -5,7 +5,7 @@ "type": "arithmeticBinary", "operator": "^", "left": { - "type": "arithmeticVariable", + "type": "variable", "name": "a" }, "right": { @@ -15,7 +15,7 @@ "type": "arithmeticUnary", "operator": "-", "argument": { - "type": "arithmeticVariable", + "type": "variable", "name": "b" } } From a8dcd918222b2c748bc83928a1128d0dd1fb1276 Mon Sep 17 00:00:00 2001 From: Jordan Klassen Date: Fri, 8 Apr 2016 20:16:53 -0700 Subject: [PATCH 16/20] add passing fixture asts --- .../arithmetic-expression/source.sh | 1 - .../shellcheck-tests/arithmetic17/ast.json | 35 +++++++++++++++++++ .../ast.json | 0 .../shellcheck-tests/arithmetic20/ast.json | 33 +++++++++++++++++ .../shellcheck-tests/arithmetic21/ast.json | 33 +++++++++++++++++ .../shellcheck-tests/arithmetic22/ast.json | 19 ++++++++++ 6 files changed, 120 insertions(+), 1 deletion(-) delete mode 100644 tests/fixtures/shellcheck-tests/arithmetic-expression/source.sh create mode 100644 tests/fixtures/shellcheck-tests/arithmetic17/ast.json rename tests/fixtures/shellcheck-tests/{arithmetic-expression => arithmetic18}/ast.json (100%) create mode 100644 tests/fixtures/shellcheck-tests/arithmetic20/ast.json create mode 100644 tests/fixtures/shellcheck-tests/arithmetic21/ast.json create mode 100644 tests/fixtures/shellcheck-tests/arithmetic22/ast.json diff --git a/tests/fixtures/shellcheck-tests/arithmetic-expression/source.sh b/tests/fixtures/shellcheck-tests/arithmetic-expression/source.sh deleted file mode 100644 index 703a0db..0000000 --- a/tests/fixtures/shellcheck-tests/arithmetic-expression/source.sh +++ /dev/null @@ -1 +0,0 @@ -((a?b:c)) \ No newline at end of file diff --git a/tests/fixtures/shellcheck-tests/arithmetic17/ast.json b/tests/fixtures/shellcheck-tests/arithmetic17/ast.json new file mode 100644 index 0000000..4503489 --- /dev/null +++ b/tests/fixtures/shellcheck-tests/arithmetic17/ast.json @@ -0,0 +1,35 @@ +[ + { + "type": "arithmeticStatement", + "expression": { + "type": "arithmeticBinary", + "operator": "<", + "left": { + "type": "variable", + "name": "i" + }, + "right": { + "type": "arithmeticBinary", + "operator": "+", + "left": { + "type": "number", + "value": 0 + }, + "right": { + "type": "arithmeticBinary", + "operator": "+", + "left": { + "type": "number", + "value": 1 + }, + "right": { + "type": "number", + "value": 1 + } + } + } + }, + "control": ";", + "next": null + } +] diff --git a/tests/fixtures/shellcheck-tests/arithmetic-expression/ast.json b/tests/fixtures/shellcheck-tests/arithmetic18/ast.json similarity index 100% rename from tests/fixtures/shellcheck-tests/arithmetic-expression/ast.json rename to tests/fixtures/shellcheck-tests/arithmetic18/ast.json diff --git a/tests/fixtures/shellcheck-tests/arithmetic20/ast.json b/tests/fixtures/shellcheck-tests/arithmetic20/ast.json new file mode 100644 index 0000000..1420dda --- /dev/null +++ b/tests/fixtures/shellcheck-tests/arithmetic20/ast.json @@ -0,0 +1,33 @@ +[ + { + "type": "arithmeticStatement", + "expression": { + "type": "arithmeticConditional", + "test": { + "type": "variable", + "name": "a" + }, + "consequent": { + "type": "arithmeticConditional", + "test": { + "type": "variable", + "name": "b" + }, + "consequent": { + "type": "variable", + "name": "c" + }, + "alternate": { + "type": "variable", + "name": "d" + } + }, + "alternate": { + "type": "variable", + "name": "e" + } + }, + "control": ";", + "next": null + } +] diff --git a/tests/fixtures/shellcheck-tests/arithmetic21/ast.json b/tests/fixtures/shellcheck-tests/arithmetic21/ast.json new file mode 100644 index 0000000..d8871b1 --- /dev/null +++ b/tests/fixtures/shellcheck-tests/arithmetic21/ast.json @@ -0,0 +1,33 @@ +[ + { + "type": "arithmeticStatement", + "expression": { + "type": "arithmeticConditional", + "test": { + "type": "variable", + "name": "a" + }, + "consequent": { + "type": "variable", + "name": "b" + }, + "alternate": { + "type": "arithmeticConditional", + "test": { + "type": "variable", + "name": "c" + }, + "consequent": { + "type": "variable", + "name": "d" + }, + "alternate": { + "type": "variable", + "name": "e" + } + } + }, + "control": ";", + "next": null + } +] diff --git a/tests/fixtures/shellcheck-tests/arithmetic22/ast.json b/tests/fixtures/shellcheck-tests/arithmetic22/ast.json new file mode 100644 index 0000000..81dbb95 --- /dev/null +++ b/tests/fixtures/shellcheck-tests/arithmetic22/ast.json @@ -0,0 +1,19 @@ +[ + { + "type": "arithmeticStatement", + "expression": { + "type": "arithmeticUnary", + "operator": "!", + "argument": { + "type": "arithmeticUnary", + "operator": "!", + "argument": { + "type": "variable", + "name": "a" + } + } + }, + "control": ";", + "next": null + } +] From 687dada7b42bd42bb2bf8757cad3381eebca6d9e Mon Sep 17 00:00:00 2001 From: Jordan Klassen Date: Fri, 8 Apr 2016 20:19:53 -0700 Subject: [PATCH 17/20] better arithmetic variable name parsing --- grammar.pegjs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/grammar.pegjs b/grammar.pegjs index 46c019c..f158243 100644 --- a/grammar.pegjs +++ b/grammar.pegjs @@ -284,7 +284,7 @@ aBarewordChar = '\\' chr:aBarewordMeta { return chr } / !aBarewordMeta chr:. { return chr } -aBarewordMeta = [$"';&<>\n()\[*?|`:+ ] +aBarewordMeta = [$"';&<>\n()\[\]*?|`:+^\- ] aConcatenation "concatenation of strings and/or variables" = pieces:( aBareword From f3e2780ea16dc17a4d371cec229d9ea1540c0ab3 Mon Sep 17 00:00:00 2001 From: Jordan Klassen Date: Sat, 9 Apr 2016 17:29:21 -0700 Subject: [PATCH 18/20] implement member expression parsing --- grammar.pegjs | 8 ++++++-- overrides.js | 10 ++++++++++ quickcheck.js | 2 +- 3 files changed, 17 insertions(+), 3 deletions(-) diff --git a/grammar.pegjs b/grammar.pegjs index f158243..c099b6d 100644 --- a/grammar.pegjs +++ b/grammar.pegjs @@ -270,8 +270,12 @@ aPreIncDec / other:aPostIncDec aPostIncDec - = argument:aParenExpr operators:(spaceNL* op:( "++" / "--" ) { return op })+ - / other:aParenExpr + = argument:aMemberExpr operators:(spaceNL* op:( "++" / "--" ) { return op })+ + / other:aMemberExpr + + +aMemberExpr + = head:aParenExpr tail:(spaceNL* "[" property:arithmetic "]" { return property })* aParenExpr = '(' spaceNL* value:arithmetic spaceNL* ')' { return value } diff --git a/overrides.js b/overrides.js index 84bcddd..c4707da 100644 --- a/overrides.js +++ b/overrides.js @@ -453,3 +453,13 @@ rules.aPostIncDec = [ }); }, other ] + +rules.aMemberExpr = function (head, tail) { + return buildTree(head, tail, function (child, current) { + return { + type: 'arithmeticMemberExpression', + array: child, + property: current + } + }); +} diff --git a/quickcheck.js b/quickcheck.js index 6731ba9..36c1c86 100755 --- a/quickcheck.js +++ b/quickcheck.js @@ -3,4 +3,4 @@ const util = require('util') var parser = require("./" + process.argv[2]) var parse = parser.parse || parser; -process.stdout.write(util.inspect(parse(process.argv[3]), {depth: null})) +process.stdout.write(JSON.stringify(parse(process.argv[3]), null, ' ')) From 70df2a203f5b748d946f7ef456f6d969c978a63a Mon Sep 17 00:00:00 2001 From: Jordan Klassen Date: Sat, 9 Apr 2016 17:54:18 -0700 Subject: [PATCH 19/20] add asts for fixtures --- .../shellcheck-tests/arithmetic13/ast.json | 39 ++++++++++ .../shellcheck-tests/arithmetic15/ast.json | 73 +++++++++++++++++++ .../shellcheck-tests/arithmetic19/ast.json | 19 +++++ 3 files changed, 131 insertions(+) create mode 100644 tests/fixtures/shellcheck-tests/arithmetic13/ast.json create mode 100644 tests/fixtures/shellcheck-tests/arithmetic15/ast.json create mode 100644 tests/fixtures/shellcheck-tests/arithmetic19/ast.json diff --git a/tests/fixtures/shellcheck-tests/arithmetic13/ast.json b/tests/fixtures/shellcheck-tests/arithmetic13/ast.json new file mode 100644 index 0000000..fbb025d --- /dev/null +++ b/tests/fixtures/shellcheck-tests/arithmetic13/ast.json @@ -0,0 +1,39 @@ +[ + { + "type": "arithmeticStatement", + "expression": { + "type": "arithmeticUpdate", + "operator": "++", + "argument": { + "type": "arithmeticMemberExpression", + "array": { + "type": "variable", + "name": "foo" + }, + "property": { + "type": "arithmeticBinary", + "operator": "+", + "left": { + "type": "arithmeticBinary", + "operator": "*", + "left": { + "type": "number", + "value": 9 + }, + "right": { + "type": "variable", + "name": "y" + } + }, + "right": { + "type": "variable", + "name": "x" + } + } + }, + "prefix": false + }, + "control": ";", + "next": null + } +] diff --git a/tests/fixtures/shellcheck-tests/arithmetic15/ast.json b/tests/fixtures/shellcheck-tests/arithmetic15/ast.json new file mode 100644 index 0000000..66347f6 --- /dev/null +++ b/tests/fixtures/shellcheck-tests/arithmetic15/ast.json @@ -0,0 +1,73 @@ +[ + { + "type": "arithmeticStatement", + "expression": { + "type": "arithmeticBinary", + "operator": "+", + "left": { + "type": "arithmeticMemberExpression", + "array": { + "type": "variable", + "name": "foo" + }, + "property": { + "type": "arithmeticBinary", + "operator": "*", + "left": { + "type": "commandSubstitution", + "commands": [ + { + "type": "command", + "command": { + "type": "literal", + "value": "echo" + }, + "args": [ + { + "type": "literal", + "value": "foo" + } + ], + "redirects": [ + { + "type": "pipe", + "command": { + "type": "command", + "command": { + "type": "literal", + "value": "sed" + }, + "args": [ + { + "type": "literal", + "value": "s/foo/4/g" + } + ], + "redirects": [], + "env": {}, + "control": ";", + "next": null + } + } + ], + "env": {}, + "control": ";", + "next": null + } + ] + }, + "right": { + "type": "number", + "value": 3 + } + } + }, + "right": { + "type": "number", + "value": 4 + } + }, + "control": ";", + "next": null + } +] diff --git a/tests/fixtures/shellcheck-tests/arithmetic19/ast.json b/tests/fixtures/shellcheck-tests/arithmetic19/ast.json new file mode 100644 index 0000000..e6f3a68 --- /dev/null +++ b/tests/fixtures/shellcheck-tests/arithmetic19/ast.json @@ -0,0 +1,19 @@ +[ + { + "type": "arithmeticStatement", + "expression": { + "type": "arithmeticBinary", + "operator": "+", + "left": { + "type": "number", + "value": 3 + }, + "right": { + "type": "number", + "value": 2 + } + }, + "control": ";", + "next": null + } +] \ No newline at end of file From 979a4f69a5afbf793950307e8a9e327dcf958cd8 Mon Sep 17 00:00:00 2001 From: Jordan Klassen Date: Sat, 9 Apr 2016 18:51:09 -0700 Subject: [PATCH 20/20] build parser --- parser.js | 4745 ++++++++++++++++++++++++++++++++++++++++++++++------- 1 file changed, 4119 insertions(+), 626 deletions(-) diff --git a/parser.js b/parser.js index 6134340..4377d37 100644 --- a/parser.js +++ b/parser.js @@ -92,24 +92,30 @@ var parser=(function() { 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) { + peg$c8 = { type: "other", description: "an arithmetic statement" }, + peg$c9 = "((", + peg$c10 = { type: "literal", value: "((", description: "\"((\"" }, + peg$c11 = "))", + peg$c12 = { type: "literal", value: "))", description: "\"))\"" }, + peg$c13 = function(expression) { + return { + type: 'arithmeticStatement', + expression: expression, + } + }, + peg$c14 = { type: "other", description: "a subshell" }, + peg$c15 = "(", + peg$c16 = { type: "literal", value: "(", description: "\"(\"" }, + peg$c17 = ")", + peg$c18 = { type: "literal", value: ")", description: "\")\"" }, + peg$c19 = function(statements) { return { type: 'subshell', statements: statements, } }, - peg$c14 = { type: "other", description: "an arithmetic statement" }, - peg$c15 = "((", - peg$c16 = { type: "literal", value: "((", description: "\"((\"" }, - peg$c17 = "))", - peg$c18 = { type: "literal", value: "))", description: "\"))\"" }, - peg$c19 = { type: "other", description: "a single command" }, - peg$c20 = function(pre, name, post, pipe) { + peg$c20 = { type: "other", description: "a single command" }, + peg$c21 = function(pre, name, post, pipe) { var command = { type: 'command', command: name, @@ -140,19 +146,19 @@ var parser=(function() { return command }, - peg$c21 = function(test) { + peg$c22 = function(test) { return test }, - peg$c22 = { type: "other", description: "an if/elif/else statement" }, - peg$c23 = "if", - peg$c24 = { type: "literal", value: "if", description: "\"if\"" }, - peg$c25 = "then", - peg$c26 = { type: "literal", value: "then", description: "\"then\"" }, - peg$c27 = "else", - peg$c28 = { type: "literal", value: "else", description: "\"else\"" }, - peg$c29 = "fi", - peg$c30 = { type: "literal", value: "fi", description: "\"fi\"" }, - peg$c31 = function(test, body, elifBlocks, elseBody) { + peg$c23 = { type: "other", description: "an if/elif/else statement" }, + peg$c24 = "if", + peg$c25 = { type: "literal", value: "if", description: "\"if\"" }, + peg$c26 = "then", + peg$c27 = { type: "literal", value: "then", description: "\"then\"" }, + peg$c28 = "else", + peg$c29 = { type: "literal", value: "else", description: "\"else\"" }, + peg$c30 = "fi", + peg$c31 = { type: "literal", value: "fi", description: "\"fi\"" }, + peg$c32 = function(test, body, elifBlocks, elseBody) { return { type: 'ifElse', test: test, @@ -161,41 +167,41 @@ var parser=(function() { elseBody: elseBody ? elseBody[1] : null, } }, - peg$c32 = "elif", - peg$c33 = { type: "literal", value: "elif", description: "\"elif\"" }, - peg$c34 = function(test, body) { + peg$c33 = "elif", + peg$c34 = { type: "literal", value: "elif", description: "\"elif\"" }, + peg$c35 = function(test, body) { return { type: 'ifElse', test: test, body: body } }, - peg$c35 = { type: "other", description: "a while/until loop" }, - peg$c36 = "while", - peg$c37 = { type: "literal", value: "while", description: "\"while\"" }, - peg$c38 = "until", - peg$c39 = { type: "literal", value: "until", description: "\"until\"" }, - peg$c40 = "do", - peg$c41 = { type: "literal", value: "do", description: "\"do\"" }, - peg$c42 = "done", - peg$c43 = { type: "literal", value: "done", description: "\"done\"" }, - peg$c44 = function(kind, test, body) { + peg$c36 = { type: "other", description: "a while/until loop" }, + peg$c37 = "while", + peg$c38 = { type: "literal", value: "while", description: "\"while\"" }, + peg$c39 = "until", + peg$c40 = { type: "literal", value: "until", description: "\"until\"" }, + peg$c41 = "do", + peg$c42 = { type: "literal", value: "do", description: "\"do\"" }, + peg$c43 = "done", + peg$c44 = { type: "literal", value: "done", description: "\"done\"" }, + peg$c45 = function(kind, test, body) { return { type: kind + 'Loop', test: test, body: body } }, - peg$c45 = { type: "other", description: "a for loop" }, - peg$c46 = "for", - peg$c47 = { type: "literal", value: "for", description: "\"for\"" }, - peg$c48 = "in", - peg$c49 = { type: "literal", value: "in", description: "\"in\"" }, - peg$c50 = ";", - peg$c51 = { type: "literal", value: ";", description: "\";\"" }, - peg$c52 = "\n", - peg$c53 = { type: "literal", value: "\n", description: "\"\\n\"" }, - peg$c54 = function(loopVar, subjects, body) { + peg$c46 = { type: "other", description: "a for loop" }, + peg$c47 = "for", + peg$c48 = { type: "literal", value: "for", description: "\"for\"" }, + peg$c49 = "in", + peg$c50 = { type: "literal", value: "in", description: "\"in\"" }, + peg$c51 = ";", + peg$c52 = { type: "literal", value: ";", description: "\";\"" }, + peg$c53 = "\n", + peg$c54 = { type: "literal", value: "\n", description: "\"\\n\"" }, + peg$c55 = function(loopVar, subjects, body) { return { type: 'forLoop', loopVariable: loopVar, @@ -203,138 +209,144 @@ var parser=(function() { body: body } }, - peg$c55 = { type: "other", description: "time builtin" }, - peg$c56 = "time", - peg$c57 = { type: "literal", value: "time", description: "\"time\"" }, - peg$c58 = "-", - peg$c59 = { type: "literal", value: "-", description: "\"-\"" }, - peg$c60 = /^[a-z]/, - peg$c61 = { type: "class", value: "[a-z]", description: "[a-z]" }, - peg$c62 = function(flags, statements) { + peg$c56 = { type: "other", description: "time builtin" }, + peg$c57 = "time", + peg$c58 = { type: "literal", value: "time", description: "\"time\"" }, + peg$c59 = "-", + peg$c60 = { type: "literal", value: "-", description: "\"-\"" }, + peg$c61 = /^[a-z]/, + peg$c62 = { type: "class", value: "[a-z]", description: "[a-z]" }, + peg$c63 = function(flags, statements) { return { type: 'time', flags: flags, command: statements } }, - peg$c63 = { type: "other", description: "declare builtin" }, - peg$c64 = "declare", - peg$c65 = { type: "literal", value: "declare", description: "\"declare\"" }, - peg$c66 = "typeset", - peg$c67 = { type: "literal", value: "typeset", description: "\"typeset\"" }, - peg$c68 = /^[^\n]/, - peg$c69 = { type: "class", value: "[^\\n]", description: "[^\\n]" }, - peg$c70 = { type: "other", description: "a variable assignment" }, - peg$c71 = "=", - peg$c72 = { type: "literal", value: "=", description: "\"=\"" }, - peg$c73 = function(name, value) { + peg$c64 = { type: "other", description: "declare builtin" }, + peg$c65 = "declare", + peg$c66 = { type: "literal", value: "declare", description: "\"declare\"" }, + peg$c67 = "typeset", + peg$c68 = { type: "literal", value: "typeset", description: "\"typeset\"" }, + peg$c69 = /^[^\n]/, + peg$c70 = { type: "class", value: "[^\\n]", description: "[^\\n]" }, + peg$c71 = { type: "other", description: "a variable assignment" }, + peg$c72 = "=", + peg$c73 = { type: "literal", value: "=", description: "\"=\"" }, + peg$c74 = function(name, value) { return {type: 'variableAssignment', name: name, value: value} }, - peg$c74 = { type: "other", description: "command name" }, - peg$c75 = function(name) { + peg$c75 = { type: "other", description: "command name" }, + peg$c76 = function(name) { return name }, - peg$c76 = "[[", - peg$c77 = { type: "literal", value: "[[", description: "\"[[\"" }, - peg$c78 = "[", - peg$c79 = { type: "literal", value: "[", description: "\"[\"" }, - peg$c80 = { type: "other", description: "command argument" }, - peg$c81 = { type: "other", description: "concatenation of strings and/or variables" }, - peg$c82 = function(pieces) { + peg$c77 = "[[", + peg$c78 = { type: "literal", value: "[[", description: "\"[[\"" }, + peg$c79 = "[", + peg$c80 = { type: "literal", value: "[", description: "\"[\"" }, + peg$c81 = { type: "other", description: "command argument" }, + peg$c82 = { type: "other", description: "concatenation of strings and/or variables" }, + peg$c83 = function(pieces) { return flattenConcatenation(pieces) }, - peg$c83 = { type: "other", description: "bareword" }, - peg$c84 = "#", - peg$c85 = { type: "literal", value: "#", description: "\"#\"" }, - peg$c86 = function(cs) { return literal(cs) }, - peg$c87 = "\\", - peg$c88 = { type: "literal", value: "\\", description: "\"\\\\\"" }, - peg$c89 = function(chr) { return chr }, - peg$c90 = { type: "any", description: "any character" }, - peg$c91 = /^[$"';&<>\n()[*?|` ]/, - peg$c92 = { type: "class", value: "[$\"';&<>\\n()\\[*?|` ]", description: "[$\"';&<>\\n()\\[*?|` ]" }, - peg$c93 = "*", - peg$c94 = { type: "literal", value: "*", description: "\"*\"" }, - peg$c95 = "?", - peg$c96 = { type: "literal", value: "?", description: "\"?\"" }, - peg$c97 = function() { + peg$c84 = { type: "other", description: "bareword" }, + peg$c85 = "#", + peg$c86 = { type: "literal", value: "#", description: "\"#\"" }, + peg$c87 = function(cs) { return literal(cs) }, + peg$c88 = "\\", + peg$c89 = { type: "literal", value: "\\", description: "\"\\\\\"" }, + peg$c90 = function(chr) { return chr }, + peg$c91 = { type: "any", description: "any character" }, + peg$c92 = /^[$"';&<>\n()[*?|` ]/, + peg$c93 = { type: "class", value: "[$\"';&<>\\n()\\[*?|` ]", description: "[$\"';&<>\\n()\\[*?|` ]" }, + peg$c94 = "*", + peg$c95 = { type: "literal", value: "*", description: "\"*\"" }, + peg$c96 = "?", + peg$c97 = { type: "literal", value: "?", description: "\"?\"" }, + peg$c98 = function() { return { type: 'glob', value: text() } }, - peg$c98 = "]", - peg$c99 = { type: "literal", value: "]", description: "\"]\"" }, - peg$c100 = "$", - peg$c101 = { type: "literal", value: "$", description: "\"$\"" }, - peg$c102 = "{", - peg$c103 = { type: "literal", value: "{", description: "\"{\"" }, - peg$c104 = "}", - peg$c105 = { type: "literal", value: "}", description: "\"}\"" }, - peg$c106 = "'", - peg$c107 = { type: "literal", value: "'", description: "\"'\"" }, - peg$c108 = /^[^']/, - peg$c109 = { type: "class", value: "[^']", description: "[^']" }, - peg$c110 = function(inner) { return literal(inner) }, - peg$c111 = "\"", - peg$c112 = { type: "literal", value: "\"", description: "\"\\\"\"" }, - peg$c113 = function(contents) { + peg$c99 = "]", + peg$c100 = { type: "literal", value: "]", description: "\"]\"" }, + peg$c101 = "$", + peg$c102 = { type: "literal", value: "$", description: "\"$\"" }, + peg$c103 = "{", + peg$c104 = { type: "literal", value: "{", description: "\"{\"" }, + peg$c105 = "}", + peg$c106 = { type: "literal", value: "}", description: "\"}\"" }, + peg$c107 = "'", + peg$c108 = { type: "literal", value: "'", description: "\"'\"" }, + peg$c109 = /^[^']/, + peg$c110 = { type: "class", value: "[^']", description: "[^']" }, + peg$c111 = function(inner) { return literal(inner) }, + peg$c112 = "\"", + peg$c113 = { type: "literal", value: "\"", description: "\"\\\"\"" }, + peg$c114 = function(contents) { var pieces = contents.map(function (it) { return isArray(it) ? literal(it) : it }) return flattenConcatenation(pieces) }, - peg$c114 = "\\\\", - peg$c115 = { type: "literal", value: "\\\\", description: "\"\\\\\\\\\"" }, - peg$c116 = function() { return '\\' }, - peg$c117 = "`", - peg$c118 = { type: "literal", value: "`", description: "\"`\"" }, - peg$c119 = function(name) { + peg$c115 = "\\\\", + peg$c116 = { type: "literal", value: "\\\\", description: "\"\\\\\\\\\"" }, + peg$c117 = function() { return '\\' }, + peg$c118 = "`", + peg$c119 = { type: "literal", value: "`", description: "\"`\"" }, + peg$c120 = function(name) { return {type: 'variable', name: name} }, - peg$c120 = /^[a-zA-Z0-9_]/, - peg$c121 = { type: "class", value: "[a-zA-Z0-9_]", description: "[a-zA-Z0-9_]" }, - peg$c122 = function() { return text() }, - peg$c123 = "${", - peg$c124 = { type: "literal", value: "${", description: "\"${\"" }, - peg$c125 = /^[^}]/, - peg$c126 = { type: "class", value: "[^}]", description: "[^}]" }, - peg$c127 = function(expr) { + peg$c121 = /^[a-zA-Z0-9_]/, + peg$c122 = { type: "class", value: "[a-zA-Z0-9_]", description: "[a-zA-Z0-9_]" }, + peg$c123 = function() { return text() }, + peg$c124 = "${", + peg$c125 = { type: "literal", value: "${", description: "\"${\"" }, + peg$c126 = /^[^}]/, + peg$c127 = { type: "class", value: "[^}]", description: "[^}]" }, + peg$c128 = function(expr) { return { type: 'variableSubstitution', expression: join(expr), // TODO subParser } }, - peg$c128 = "$(", - peg$c129 = { type: "literal", value: "$(", description: "\"$(\"" }, - peg$c130 = function(commands) { + peg$c129 = "$(", + peg$c130 = { type: "literal", value: "$(", description: "\"$(\"" }, + peg$c131 = function(commands) { return { type: 'commandSubstitution', commands: commands } }, - peg$c131 = "$((", - peg$c132 = { type: "literal", value: "$((", description: "\"$((\"" }, - peg$c133 = function(input) { + peg$c132 = "$((", + peg$c133 = { type: "literal", value: "$((", description: "\"$((\"" }, + peg$c134 = function(expression) { + return { + type: 'arithmeticSubstitution', + expression: expression + }; + }, + peg$c135 = function(input) { return { type: 'commandSubstitution', commands: parse(input.join('')) } }, - peg$c134 = "\\`", - peg$c135 = { type: "literal", value: "\\`", description: "\"\\\\`\"" }, - peg$c136 = function() { return '`' }, - peg$c137 = /^[<>]/, - peg$c138 = { type: "class", value: "[<>]", description: "[<>]" }, - peg$c139 = function(rw, commands) { + peg$c136 = "\\`", + peg$c137 = { type: "literal", value: "\\`", description: "\"\\\\`\"" }, + peg$c138 = function() { return '`' }, + peg$c139 = /^[<>]/, + peg$c140 = { type: "class", value: "[<>]", description: "[<>]" }, + peg$c141 = function(rw, commands) { return { type: 'processSubstitution', readWrite: rw, commands: commands, } }, - peg$c140 = "<&", - peg$c141 = { type: "literal", value: "<&", description: "\"<&\"" }, - peg$c142 = ">&", - peg$c143 = { type: "literal", value: ">&", description: "\">&\"" }, - peg$c144 = function(fd, op, dest) { + peg$c142 = "<&", + peg$c143 = { type: "literal", value: "<&", description: "\"<&\"" }, + peg$c144 = ">&", + peg$c145 = { type: "literal", value: ">&", description: "\">&\"" }, + peg$c146 = function(fd, op, dest) { if (fd == null) fd = op[0] == '<' ? 0 : 1; return { type: 'moveFd', @@ -343,7 +355,7 @@ var parser=(function() { dest: dest } }, - peg$c145 = function(src, op, dest) { + peg$c147 = function(src, op, dest) { if (src == null) src = op[0] == '<' ? 0 : 1; return { type: 'duplicateFd', @@ -352,7 +364,7 @@ var parser=(function() { destFd: dest, } }, - peg$c146 = function(fd, op, filename) { + peg$c148 = function(fd, op, filename) { if (fd == null) fd = op[0] == '<' ? 0 : 1; return { type: 'redirectFd', @@ -361,41 +373,229 @@ var parser=(function() { filename: filename } }, - peg$c147 = ">|", - peg$c148 = { type: "literal", value: ">|", description: "\">|\"" }, - peg$c149 = ">>", - peg$c150 = { type: "literal", value: ">>", description: "\">>\"" }, - peg$c151 = "&>>", - peg$c152 = { type: "literal", value: "&>>", description: "\"&>>\"" }, - peg$c153 = "&>", - peg$c154 = { type: "literal", value: "&>", description: "\"&>\"" }, - peg$c155 = "<", - peg$c156 = { type: "literal", value: "<", description: "\"<\"" }, - peg$c157 = ">", - peg$c158 = { type: "literal", value: ">", description: "\">\"" }, - peg$c159 = /^[0-9]/, - peg$c160 = { type: "class", value: "[0-9]", description: "[0-9]" }, - peg$c161 = function(digits) { return parseInt(join(digits), 10) }, - peg$c162 = "&", - peg$c163 = { type: "literal", value: "&", description: "\"&\"" }, - peg$c164 = function(op) { + peg$c149 = ">|", + peg$c150 = { type: "literal", value: ">|", description: "\">|\"" }, + peg$c151 = ">>", + peg$c152 = { type: "literal", value: ">>", description: "\">>\"" }, + peg$c153 = "&>>", + peg$c154 = { type: "literal", value: "&>>", description: "\"&>>\"" }, + peg$c155 = "&>", + peg$c156 = { type: "literal", value: "&>", description: "\"&>\"" }, + peg$c157 = "<", + peg$c158 = { type: "literal", value: "<", description: "\"<\"" }, + peg$c159 = ">", + peg$c160 = { type: "literal", value: ">", description: "\">\"" }, + peg$c161 = /^[0-9]/, + peg$c162 = { type: "class", value: "[0-9]", description: "[0-9]" }, + peg$c163 = function(digits) { return parseInt(join(digits), 10) }, + peg$c164 = "&", + peg$c165 = { type: "literal", value: "&", description: "\"&\"" }, + peg$c166 = function(op) { return op == '\n' ? ';' : op }, - peg$c165 = "|", - peg$c166 = { type: "literal", value: "|", description: "\"|\"" }, - peg$c167 = function(command) { + peg$c167 = "|", + peg$c168 = { type: "literal", value: "|", description: "\"|\"" }, + peg$c169 = function(command) { return {type: 'pipe', command: command} }, - peg$c168 = { type: "other", description: "whitespace" }, - peg$c169 = " ", - peg$c170 = { type: "literal", value: " ", description: "\" \"" }, - peg$c171 = "\t", - peg$c172 = { type: "literal", value: "\t", description: "\"\\t\"" }, - peg$c173 = { type: "other", description: "a comment" }, - peg$c174 = "case", - peg$c175 = { type: "literal", value: "case", description: "\"case\"" }, - peg$c176 = "esac", - peg$c177 = { type: "literal", value: "esac", description: "\"esac\"" }, + peg$c170 = { type: "other", description: "whitespace" }, + peg$c171 = " ", + peg$c172 = { type: "literal", value: " ", description: "\" \"" }, + peg$c173 = "\t", + peg$c174 = { type: "literal", value: "\t", description: "\"\\t\"" }, + peg$c175 = { type: "other", description: "a comment" }, + peg$c176 = "case", + peg$c177 = { type: "literal", value: "case", description: "\"case\"" }, + peg$c178 = "esac", + peg$c179 = { type: "literal", value: "esac", description: "\"esac\"" }, + peg$c180 = { type: "other", description: "an arithmetic expression" }, + peg$c181 = function(expression) { return expression }, + peg$c182 = { type: "other", description: "a sequence of arithmetic expressions" }, + peg$c183 = ",", + peg$c184 = { type: "literal", value: ",", description: "\",\"" }, + peg$c185 = function(head, expr) { return expr }, + peg$c186 = function(head, tail) { + if (tail.length) { + return { + type: 'arithmeticSequence', + expressions: [head].concat(tail) + } + } + return head + }, + peg$c187 = { type: "other", description: "an arithmetic assignment" }, + peg$c188 = "*=", + peg$c189 = { type: "literal", value: "*=", description: "\"*=\"" }, + peg$c190 = "/=", + peg$c191 = { type: "literal", value: "/=", description: "\"/=\"" }, + peg$c192 = "%=", + peg$c193 = { type: "literal", value: "%=", description: "\"%=\"" }, + peg$c194 = "+=", + peg$c195 = { type: "literal", value: "+=", description: "\"+=\"" }, + peg$c196 = "-=", + peg$c197 = { type: "literal", value: "-=", description: "\"-=\"" }, + peg$c198 = "<<=", + peg$c199 = { type: "literal", value: "<<=", description: "\"<<=\"" }, + peg$c200 = ">>=", + peg$c201 = { type: "literal", value: ">>=", description: "\">>=\"" }, + peg$c202 = "&=", + peg$c203 = { type: "literal", value: "&=", description: "\"&=\"" }, + peg$c204 = "^=", + peg$c205 = { type: "literal", value: "^=", description: "\"^=\"" }, + peg$c206 = "|=", + peg$c207 = { type: "literal", value: "|=", description: "\"|=\"" }, + peg$c208 = function(left, operator, right) { + return { + type: 'arithmeticAssignment', + left: left, + operator: operator, + right: right + } + }, + peg$c209 = function(other) { return other }, + peg$c210 = { type: "other", description: "an arithmetic conditional expression" }, + peg$c211 = ":", + peg$c212 = { type: "literal", value: ":", description: "\":\"" }, + peg$c213 = function(test, consequent, alternate) { + return { + type: 'arithmeticConditional', + test: test, + consequent: consequent, + alternate: alternate + } + }, + peg$c214 = { type: "other", description: "an arithmetic logical or" }, + peg$c215 = function(head, op, node) { return {op: op, node: node} }, + peg$c216 = function(head, tail) { + return buildTree(head, tail, function (child, current) { + return { + type: 'arithmeticLogical', + operator: current.op, + left: child, + right: current.node + } + }); + }, + peg$c217 = { type: "other", description: "an arithmetic logical and" }, + peg$c218 = /^[|=]/, + peg$c219 = { type: "class", value: "[|=]", description: "[|=]" }, + peg$c220 = function(head, tail) { + return buildTree(head, tail, function (child, current) { + return { + type: 'arithmeticBinary', + operator: current.op, + left: child, + right: current.node + } + }); + }, + peg$c221 = "^", + peg$c222 = { type: "literal", value: "^", description: "\"^\"" }, + peg$c223 = /^[&=]/, + peg$c224 = { type: "class", value: "[&=]", description: "[&=]" }, + peg$c225 = "==", + peg$c226 = { type: "literal", value: "==", description: "\"==\"" }, + peg$c227 = "!=", + peg$c228 = { type: "literal", value: "!=", description: "\"!=\"" }, + peg$c229 = "<=", + peg$c230 = { type: "literal", value: "<=", description: "\"<=\"" }, + peg$c231 = ">=", + peg$c232 = { type: "literal", value: ">=", description: "\">=\"" }, + peg$c233 = function(head, v) { return v }, + peg$c234 = "<<", + peg$c235 = { type: "literal", value: "<<", description: "\"<<\"" }, + peg$c236 = "+", + peg$c237 = { type: "literal", value: "+", description: "\"+\"" }, + peg$c238 = "/", + peg$c239 = { type: "literal", value: "/", description: "\"/\"" }, + peg$c240 = "%", + peg$c241 = { type: "literal", value: "%", description: "\"%\"" }, + peg$c242 = "**", + peg$c243 = { type: "literal", value: "**", description: "\"**\"" }, + peg$c244 = "!", + peg$c245 = { type: "literal", value: "!", description: "\"!\"" }, + peg$c246 = "~", + peg$c247 = { type: "literal", value: "~", description: "\"~\"" }, + peg$c248 = function(operator, argument) { + return { + type: 'arithmeticUnary', + operator: operator, + argument: argument + } + }, + peg$c249 = /^[+=]/, + peg$c250 = { type: "class", value: "[+=]", description: "[+=]" }, + peg$c251 = function(op) { return op }, + peg$c252 = /^[\-=]/, + peg$c253 = { type: "class", value: "[-=]", description: "[-=]" }, + peg$c254 = "++", + peg$c255 = { type: "literal", value: "++", description: "\"++\"" }, + peg$c256 = "--", + peg$c257 = { type: "literal", value: "--", description: "\"--\"" }, + peg$c258 = function(operator, argument) { + return { + type: 'arithmeticUpdate', + operator: operator, + argument: argument, + prefix: true + } + }, + peg$c259 = function(argument, op) { return op }, + peg$c260 = function(argument, operators) { + return buildTree(argument, operators, function (node, operator) { + return { + type: 'arithmeticUpdate', + operator: operator, + argument: node, + prefix: false + } + }); + }, + peg$c261 = function(head, property) { return property }, + peg$c262 = function(head, tail) { + return buildTree(head, tail, function (child, current) { + return { + type: 'arithmeticMemberExpression', + array: child, + property: current + } + }); + }, + peg$c263 = function(value) { return value }, + peg$c264 = { type: "other", description: "arithmetic variable" }, + peg$c265 = function(name) { + // TODO: check if array + return {type: 'variable', name: name.join('')} + }, + peg$c266 = /^[$"';&<>\n()[\]*?|`:+\^\- ]/, + peg$c267 = { type: "class", value: "[$\"';&<>\\n()\\[\\]*?|`:+^\\- ]", description: "[$\"';&<>\\n()\\[\\]*?|`:+^\\- ]" }, + peg$c268 = function(pieces) { + // TODO: if it's an array, nest it + return flattenConcatenation(pieces) + }, + peg$c269 = function(val) { return val }, + peg$c270 = "0", + peg$c271 = { type: "literal", value: "0", description: "\"0\"" }, + peg$c272 = /^[xX]/, + peg$c273 = { type: "class", value: "[xX]", description: "[xX]" }, + peg$c274 = /^[0-9a-fA-Z]/, + peg$c275 = { type: "class", value: "[0-9a-fA-Z]", description: "[0-9a-fA-Z]" }, + peg$c276 = function(digits) { + return {type: 'number', value: parseInt(digits.join(''), 16)} + }, + peg$c277 = /^[0-9a-zA-Z]/, + peg$c278 = { type: "class", value: "[0-9a-zA-Z]", description: "[0-9a-zA-Z]" }, + peg$c279 = function(base, digits) { + return {type: 'number', value: parseInt(digits.join(''), parseInt(base.join(''), 10))} + }, + peg$c280 = /^[0-7]/, + peg$c281 = { type: "class", value: "[0-7]", description: "[0-7]" }, + peg$c282 = function(digits) { + return {type: 'number', value: parseInt(digits.join(''), 8)} + }, + peg$c283 = function(digits) { + return {type: 'number', value: parseInt(digits.join(''), 10)} + }, peg$currPos = 0, peg$savedPos = 0, @@ -726,9 +926,9 @@ var parser=(function() { var s0, s1, s2, s3, s4; s0 = peg$currPos; - s1 = peg$parsesubshell(); + s1 = peg$parsearithmeticStatement(); if (s1 === peg$FAILED) { - s1 = peg$parsearithmeticStatement(); + s1 = peg$parsesubshell(); if (s1 === peg$FAILED) { s1 = peg$parsebashExtensions(); if (s1 === peg$FAILED) { @@ -837,14 +1037,14 @@ var parser=(function() { return s0; } - function peg$parsesubshell() { + function peg$parsearithmeticStatement() { var s0, s1, s2, s3, s4, s5; peg$silentFails++; s0 = peg$currPos; - if (input.charCodeAt(peg$currPos) === 40) { + if (input.substr(peg$currPos, 2) === peg$c9) { s1 = peg$c9; - peg$currPos++; + peg$currPos += 2; } else { s1 = peg$FAILED; if (peg$silentFails === 0) { peg$fail(peg$c10); } @@ -857,7 +1057,7 @@ var parser=(function() { s3 = peg$parsespace(); } if (s2 !== peg$FAILED) { - s3 = peg$parsestatementList(); + s3 = peg$parsearithmetic(); if (s3 !== peg$FAILED) { s4 = []; s5 = peg$parsespace(); @@ -866,9 +1066,9 @@ var parser=(function() { s5 = peg$parsespace(); } if (s4 !== peg$FAILED) { - if (input.charCodeAt(peg$currPos) === 41) { + if (input.substr(peg$currPos, 2) === peg$c11) { s5 = peg$c11; - peg$currPos++; + peg$currPos += 2; } else { s5 = peg$FAILED; if (peg$silentFails === 0) { peg$fail(peg$c12); } @@ -906,31 +1106,54 @@ var parser=(function() { return s0; } - function peg$parsearithmeticStatement() { - var s0, s1, s2, s3; + function peg$parsesubshell() { + var s0, s1, s2, s3, s4, s5; peg$silentFails++; s0 = peg$currPos; - if (input.substr(peg$currPos, 2) === peg$c15) { + if (input.charCodeAt(peg$currPos) === 40) { s1 = peg$c15; - peg$currPos += 2; + peg$currPos++; } else { s1 = peg$FAILED; if (peg$silentFails === 0) { peg$fail(peg$c16); } } if (s1 !== peg$FAILED) { - s2 = peg$parsecommandName(); + s2 = []; + s3 = peg$parsespace(); + while (s3 !== peg$FAILED) { + s2.push(s3); + s3 = peg$parsespace(); + } if (s2 !== peg$FAILED) { - if (input.substr(peg$currPos, 2) === peg$c17) { - s3 = peg$c17; - peg$currPos += 2; - } else { - s3 = peg$FAILED; - if (peg$silentFails === 0) { peg$fail(peg$c18); } - } + s3 = peg$parsestatementList(); if (s3 !== peg$FAILED) { - s1 = [s1, s2, s3]; - s0 = s1; + 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$c17; + peg$currPos++; + } else { + s5 = peg$FAILED; + if (peg$silentFails === 0) { peg$fail(peg$c18); } + } + if (s5 !== peg$FAILED) { + peg$savedPos = s0; + s1 = peg$c19(s3); + s0 = s1; + } else { + peg$currPos = s0; + s0 = peg$FAILED; + } + } else { + peg$currPos = s0; + s0 = peg$FAILED; + } } else { peg$currPos = s0; s0 = peg$FAILED; @@ -1105,7 +1328,7 @@ var parser=(function() { } if (s4 !== peg$FAILED) { peg$savedPos = s0; - s1 = peg$c20(s1, s2, s3, s4); + s1 = peg$c21(s1, s2, s3, s4); s0 = s1; } else { peg$currPos = s0; @@ -1126,7 +1349,7 @@ var parser=(function() { peg$silentFails--; if (s0 === peg$FAILED) { s1 = peg$FAILED; - if (peg$silentFails === 0) { peg$fail(peg$c19); } + if (peg$silentFails === 0) { peg$fail(peg$c20); } } return s0; @@ -1139,7 +1362,7 @@ var parser=(function() { s1 = peg$parsescript(); if (s1 !== peg$FAILED) { peg$savedPos = s0; - s1 = peg$c21(s1); + s1 = peg$c22(s1); } s0 = s1; @@ -1151,12 +1374,12 @@ var parser=(function() { peg$silentFails++; s0 = peg$currPos; - if (input.substr(peg$currPos, 2) === peg$c23) { - s1 = peg$c23; + 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$c24); } + if (peg$silentFails === 0) { peg$fail(peg$c25); } } if (s1 !== peg$FAILED) { s2 = []; @@ -1172,12 +1395,12 @@ var parser=(function() { if (s2 !== peg$FAILED) { s3 = peg$parsecondition(); if (s3 !== peg$FAILED) { - if (input.substr(peg$currPos, 4) === peg$c25) { - s4 = peg$c25; + if (input.substr(peg$currPos, 4) === peg$c26) { + s4 = peg$c26; peg$currPos += 4; } else { s4 = peg$FAILED; - if (peg$silentFails === 0) { peg$fail(peg$c26); } + if (peg$silentFails === 0) { peg$fail(peg$c27); } } if (s4 !== peg$FAILED) { s5 = []; @@ -1201,12 +1424,12 @@ var parser=(function() { } if (s7 !== peg$FAILED) { s8 = peg$currPos; - if (input.substr(peg$currPos, 4) === peg$c27) { - s9 = peg$c27; + if (input.substr(peg$currPos, 4) === peg$c28) { + s9 = peg$c28; peg$currPos += 4; } else { s9 = peg$FAILED; - if (peg$silentFails === 0) { peg$fail(peg$c28); } + if (peg$silentFails === 0) { peg$fail(peg$c29); } } if (s9 !== peg$FAILED) { s10 = peg$parsescript(); @@ -1225,16 +1448,16 @@ var parser=(function() { s8 = null; } if (s8 !== peg$FAILED) { - if (input.substr(peg$currPos, 2) === peg$c29) { - s9 = peg$c29; + if (input.substr(peg$currPos, 2) === peg$c30) { + s9 = peg$c30; peg$currPos += 2; } else { s9 = peg$FAILED; - if (peg$silentFails === 0) { peg$fail(peg$c30); } + if (peg$silentFails === 0) { peg$fail(peg$c31); } } if (s9 !== peg$FAILED) { peg$savedPos = s0; - s1 = peg$c31(s3, s6, s7, s8); + s1 = peg$c32(s3, s6, s7, s8); s0 = s1; } else { peg$currPos = s0; @@ -1275,7 +1498,7 @@ var parser=(function() { peg$silentFails--; if (s0 === peg$FAILED) { s1 = peg$FAILED; - if (peg$silentFails === 0) { peg$fail(peg$c22); } + if (peg$silentFails === 0) { peg$fail(peg$c23); } } return s0; @@ -1285,12 +1508,12 @@ var parser=(function() { var s0, s1, s2, s3, s4, s5, s6; s0 = peg$currPos; - if (input.substr(peg$currPos, 4) === peg$c32) { - s1 = peg$c32; + if (input.substr(peg$currPos, 4) === peg$c33) { + s1 = peg$c33; peg$currPos += 4; } else { s1 = peg$FAILED; - if (peg$silentFails === 0) { peg$fail(peg$c33); } + if (peg$silentFails === 0) { peg$fail(peg$c34); } } if (s1 !== peg$FAILED) { s2 = []; @@ -1306,12 +1529,12 @@ var parser=(function() { if (s2 !== peg$FAILED) { s3 = peg$parsecondition(); if (s3 !== peg$FAILED) { - if (input.substr(peg$currPos, 4) === peg$c25) { - s4 = peg$c25; + if (input.substr(peg$currPos, 4) === peg$c26) { + s4 = peg$c26; peg$currPos += 4; } else { s4 = peg$FAILED; - if (peg$silentFails === 0) { peg$fail(peg$c26); } + if (peg$silentFails === 0) { peg$fail(peg$c27); } } if (s4 !== peg$FAILED) { s5 = []; @@ -1328,7 +1551,7 @@ var parser=(function() { s6 = peg$parsescript(); if (s6 !== peg$FAILED) { peg$savedPos = s0; - s1 = peg$c34(s3, s6); + s1 = peg$c35(s3, s6); s0 = s1; } else { peg$currPos = s0; @@ -1363,20 +1586,20 @@ var parser=(function() { peg$silentFails++; s0 = peg$currPos; - if (input.substr(peg$currPos, 5) === peg$c36) { - s1 = peg$c36; + if (input.substr(peg$currPos, 5) === peg$c37) { + s1 = peg$c37; peg$currPos += 5; } else { s1 = peg$FAILED; - if (peg$silentFails === 0) { peg$fail(peg$c37); } + if (peg$silentFails === 0) { peg$fail(peg$c38); } } if (s1 === peg$FAILED) { - if (input.substr(peg$currPos, 5) === peg$c38) { - s1 = peg$c38; + if (input.substr(peg$currPos, 5) === peg$c39) { + s1 = peg$c39; peg$currPos += 5; } else { s1 = peg$FAILED; - if (peg$silentFails === 0) { peg$fail(peg$c39); } + if (peg$silentFails === 0) { peg$fail(peg$c40); } } } if (s1 !== peg$FAILED) { @@ -1393,12 +1616,12 @@ var parser=(function() { if (s2 !== peg$FAILED) { s3 = peg$parsecondition(); if (s3 !== peg$FAILED) { - if (input.substr(peg$currPos, 2) === peg$c40) { - s4 = peg$c40; + if (input.substr(peg$currPos, 2) === peg$c41) { + s4 = peg$c41; peg$currPos += 2; } else { s4 = peg$FAILED; - if (peg$silentFails === 0) { peg$fail(peg$c41); } + if (peg$silentFails === 0) { peg$fail(peg$c42); } } if (s4 !== peg$FAILED) { s5 = []; @@ -1414,16 +1637,16 @@ var parser=(function() { if (s5 !== peg$FAILED) { s6 = peg$parsescript(); if (s6 !== peg$FAILED) { - if (input.substr(peg$currPos, 4) === peg$c42) { - s7 = peg$c42; + if (input.substr(peg$currPos, 4) === peg$c43) { + s7 = peg$c43; peg$currPos += 4; } else { s7 = peg$FAILED; - if (peg$silentFails === 0) { peg$fail(peg$c43); } + if (peg$silentFails === 0) { peg$fail(peg$c44); } } if (s7 !== peg$FAILED) { peg$savedPos = s0; - s1 = peg$c44(s1, s3, s6); + s1 = peg$c45(s1, s3, s6); s0 = s1; } else { peg$currPos = s0; @@ -1456,7 +1679,7 @@ var parser=(function() { peg$silentFails--; if (s0 === peg$FAILED) { s1 = peg$FAILED; - if (peg$silentFails === 0) { peg$fail(peg$c35); } + if (peg$silentFails === 0) { peg$fail(peg$c36); } } return s0; @@ -1467,12 +1690,12 @@ var parser=(function() { peg$silentFails++; s0 = peg$currPos; - if (input.substr(peg$currPos, 3) === peg$c46) { - s1 = peg$c46; + if (input.substr(peg$currPos, 3) === peg$c47) { + s1 = peg$c47; peg$currPos += 3; } else { s1 = peg$FAILED; - if (peg$silentFails === 0) { peg$fail(peg$c47); } + if (peg$silentFails === 0) { peg$fail(peg$c48); } } if (s1 !== peg$FAILED) { s2 = []; @@ -1500,12 +1723,12 @@ var parser=(function() { } if (s4 !== peg$FAILED) { s5 = peg$currPos; - if (input.substr(peg$currPos, 2) === peg$c48) { - s6 = peg$c48; + if (input.substr(peg$currPos, 2) === peg$c49) { + s6 = peg$c49; peg$currPos += 2; } else { s6 = peg$FAILED; - if (peg$silentFails === 0) { peg$fail(peg$c49); } + if (peg$silentFails === 0) { peg$fail(peg$c50); } } if (s6 !== peg$FAILED) { s7 = []; @@ -1583,19 +1806,19 @@ var parser=(function() { } if (s6 !== peg$FAILED) { if (input.charCodeAt(peg$currPos) === 59) { - s7 = peg$c50; + s7 = peg$c51; peg$currPos++; } else { s7 = peg$FAILED; - if (peg$silentFails === 0) { peg$fail(peg$c51); } + if (peg$silentFails === 0) { peg$fail(peg$c52); } } if (s7 === peg$FAILED) { if (input.charCodeAt(peg$currPos) === 10) { - s7 = peg$c52; + s7 = peg$c53; peg$currPos++; } else { s7 = peg$FAILED; - if (peg$silentFails === 0) { peg$fail(peg$c53); } + if (peg$silentFails === 0) { peg$fail(peg$c54); } } } if (s7 !== peg$FAILED) { @@ -1606,12 +1829,12 @@ var parser=(function() { s9 = peg$parsespaceNL(); } if (s8 !== peg$FAILED) { - if (input.substr(peg$currPos, 2) === peg$c40) { - s9 = peg$c40; + if (input.substr(peg$currPos, 2) === peg$c41) { + s9 = peg$c41; peg$currPos += 2; } else { s9 = peg$FAILED; - if (peg$silentFails === 0) { peg$fail(peg$c41); } + if (peg$silentFails === 0) { peg$fail(peg$c42); } } if (s9 !== peg$FAILED) { s10 = []; @@ -1634,16 +1857,16 @@ var parser=(function() { s13 = peg$parsespaceNL(); } if (s12 !== peg$FAILED) { - if (input.substr(peg$currPos, 4) === peg$c42) { - s13 = peg$c42; + if (input.substr(peg$currPos, 4) === peg$c43) { + s13 = peg$c43; peg$currPos += 4; } else { s13 = peg$FAILED; - if (peg$silentFails === 0) { peg$fail(peg$c43); } + if (peg$silentFails === 0) { peg$fail(peg$c44); } } if (s13 !== peg$FAILED) { peg$savedPos = s0; - s1 = peg$c54(s3, s5, s11); + s1 = peg$c55(s3, s5, s11); s0 = s1; } else { peg$currPos = s0; @@ -1700,7 +1923,7 @@ var parser=(function() { peg$silentFails--; if (s0 === peg$FAILED) { s1 = peg$FAILED; - if (peg$silentFails === 0) { peg$fail(peg$c45); } + if (peg$silentFails === 0) { peg$fail(peg$c46); } } return s0; @@ -1722,12 +1945,12 @@ var parser=(function() { peg$silentFails++; s0 = peg$currPos; - if (input.substr(peg$currPos, 4) === peg$c56) { - s1 = peg$c56; + if (input.substr(peg$currPos, 4) === peg$c57) { + s1 = peg$c57; peg$currPos += 4; } else { s1 = peg$FAILED; - if (peg$silentFails === 0) { peg$fail(peg$c57); } + if (peg$silentFails === 0) { peg$fail(peg$c58); } } if (s1 !== peg$FAILED) { s2 = []; @@ -1744,30 +1967,30 @@ var parser=(function() { s3 = []; s4 = peg$currPos; if (input.charCodeAt(peg$currPos) === 45) { - s5 = peg$c58; + s5 = peg$c59; peg$currPos++; } else { s5 = peg$FAILED; - if (peg$silentFails === 0) { peg$fail(peg$c59); } + if (peg$silentFails === 0) { peg$fail(peg$c60); } } if (s5 !== peg$FAILED) { s6 = []; - if (peg$c60.test(input.charAt(peg$currPos))) { + if (peg$c61.test(input.charAt(peg$currPos))) { s7 = input.charAt(peg$currPos); peg$currPos++; } else { s7 = peg$FAILED; - if (peg$silentFails === 0) { peg$fail(peg$c61); } + if (peg$silentFails === 0) { peg$fail(peg$c62); } } if (s7 !== peg$FAILED) { while (s7 !== peg$FAILED) { s6.push(s7); - if (peg$c60.test(input.charAt(peg$currPos))) { + if (peg$c61.test(input.charAt(peg$currPos))) { s7 = input.charAt(peg$currPos); peg$currPos++; } else { s7 = peg$FAILED; - if (peg$silentFails === 0) { peg$fail(peg$c61); } + if (peg$silentFails === 0) { peg$fail(peg$c62); } } } } else { @@ -1803,30 +2026,30 @@ var parser=(function() { s3.push(s4); s4 = peg$currPos; if (input.charCodeAt(peg$currPos) === 45) { - s5 = peg$c58; + s5 = peg$c59; peg$currPos++; } else { s5 = peg$FAILED; - if (peg$silentFails === 0) { peg$fail(peg$c59); } + if (peg$silentFails === 0) { peg$fail(peg$c60); } } if (s5 !== peg$FAILED) { s6 = []; - if (peg$c60.test(input.charAt(peg$currPos))) { + if (peg$c61.test(input.charAt(peg$currPos))) { s7 = input.charAt(peg$currPos); peg$currPos++; } else { s7 = peg$FAILED; - if (peg$silentFails === 0) { peg$fail(peg$c61); } + if (peg$silentFails === 0) { peg$fail(peg$c62); } } if (s7 !== peg$FAILED) { while (s7 !== peg$FAILED) { s6.push(s7); - if (peg$c60.test(input.charAt(peg$currPos))) { + if (peg$c61.test(input.charAt(peg$currPos))) { s7 = input.charAt(peg$currPos); peg$currPos++; } else { s7 = peg$FAILED; - if (peg$silentFails === 0) { peg$fail(peg$c61); } + if (peg$silentFails === 0) { peg$fail(peg$c62); } } } } else { @@ -1863,7 +2086,7 @@ var parser=(function() { s4 = peg$parsestatementList(); if (s4 !== peg$FAILED) { peg$savedPos = s0; - s1 = peg$c62(s3, s4); + s1 = peg$c63(s3, s4); s0 = s1; } else { peg$currPos = s0; @@ -1884,7 +2107,7 @@ var parser=(function() { peg$silentFails--; if (s0 === peg$FAILED) { s1 = peg$FAILED; - if (peg$silentFails === 0) { peg$fail(peg$c55); } + if (peg$silentFails === 0) { peg$fail(peg$c56); } } return s0; @@ -1895,40 +2118,40 @@ var parser=(function() { peg$silentFails++; s0 = peg$currPos; - if (input.substr(peg$currPos, 7) === peg$c64) { - s1 = peg$c64; + if (input.substr(peg$currPos, 7) === peg$c65) { + s1 = peg$c65; peg$currPos += 7; } else { s1 = peg$FAILED; - if (peg$silentFails === 0) { peg$fail(peg$c65); } + if (peg$silentFails === 0) { peg$fail(peg$c66); } } if (s1 === peg$FAILED) { - if (input.substr(peg$currPos, 7) === peg$c66) { - s1 = peg$c66; + if (input.substr(peg$currPos, 7) === peg$c67) { + s1 = peg$c67; peg$currPos += 7; } else { s1 = peg$FAILED; - if (peg$silentFails === 0) { peg$fail(peg$c67); } + if (peg$silentFails === 0) { peg$fail(peg$c68); } } } if (s1 !== peg$FAILED) { s2 = []; - if (peg$c68.test(input.charAt(peg$currPos))) { + if (peg$c69.test(input.charAt(peg$currPos))) { s3 = input.charAt(peg$currPos); peg$currPos++; } else { s3 = peg$FAILED; - if (peg$silentFails === 0) { peg$fail(peg$c69); } + if (peg$silentFails === 0) { peg$fail(peg$c70); } } if (s3 !== peg$FAILED) { while (s3 !== peg$FAILED) { s2.push(s3); - if (peg$c68.test(input.charAt(peg$currPos))) { + if (peg$c69.test(input.charAt(peg$currPos))) { s3 = input.charAt(peg$currPos); peg$currPos++; } else { s3 = peg$FAILED; - if (peg$silentFails === 0) { peg$fail(peg$c69); } + if (peg$silentFails === 0) { peg$fail(peg$c70); } } } } else { @@ -1936,19 +2159,19 @@ var parser=(function() { } if (s2 !== peg$FAILED) { if (input.charCodeAt(peg$currPos) === 59) { - s3 = peg$c50; + s3 = peg$c51; peg$currPos++; } else { s3 = peg$FAILED; - if (peg$silentFails === 0) { peg$fail(peg$c51); } + if (peg$silentFails === 0) { peg$fail(peg$c52); } } if (s3 === peg$FAILED) { if (input.charCodeAt(peg$currPos) === 10) { - s3 = peg$c52; + s3 = peg$c53; peg$currPos++; } else { s3 = peg$FAILED; - if (peg$silentFails === 0) { peg$fail(peg$c53); } + if (peg$silentFails === 0) { peg$fail(peg$c54); } } } if (s3 !== peg$FAILED) { @@ -1969,7 +2192,7 @@ var parser=(function() { peg$silentFails--; if (s0 === peg$FAILED) { s1 = peg$FAILED; - if (peg$silentFails === 0) { peg$fail(peg$c63); } + if (peg$silentFails === 0) { peg$fail(peg$c64); } } return s0; @@ -1983,11 +2206,11 @@ var parser=(function() { s1 = peg$parsewritableVariableName(); if (s1 !== peg$FAILED) { if (input.charCodeAt(peg$currPos) === 61) { - s2 = peg$c71; + s2 = peg$c72; peg$currPos++; } else { s2 = peg$FAILED; - if (peg$silentFails === 0) { peg$fail(peg$c72); } + if (peg$silentFails === 0) { peg$fail(peg$c73); } } if (s2 !== peg$FAILED) { s3 = peg$parseargument(); @@ -1996,7 +2219,7 @@ var parser=(function() { } if (s3 !== peg$FAILED) { peg$savedPos = s0; - s1 = peg$c73(s1, s3); + s1 = peg$c74(s1, s3); s0 = s1; } else { peg$currPos = s0; @@ -2013,7 +2236,7 @@ var parser=(function() { peg$silentFails--; if (s0 === peg$FAILED) { s1 = peg$FAILED; - if (peg$silentFails === 0) { peg$fail(peg$c70); } + if (peg$silentFails === 0) { peg$fail(peg$c71); } } return s0; @@ -2063,7 +2286,7 @@ var parser=(function() { } if (s4 !== peg$FAILED) { peg$savedPos = s0; - s1 = peg$c75(s4); + s1 = peg$c76(s4); s0 = s1; } else { peg$currPos = s0; @@ -2084,7 +2307,7 @@ var parser=(function() { peg$silentFails--; if (s0 === peg$FAILED) { s1 = peg$FAILED; - if (peg$silentFails === 0) { peg$fail(peg$c74); } + if (peg$silentFails === 0) { peg$fail(peg$c75); } } return s0; @@ -2093,20 +2316,20 @@ var parser=(function() { function peg$parsebuiltinCommandName() { var s0; - if (input.substr(peg$currPos, 2) === peg$c76) { - s0 = peg$c76; + if (input.substr(peg$currPos, 2) === peg$c77) { + s0 = peg$c77; peg$currPos += 2; } else { s0 = peg$FAILED; - if (peg$silentFails === 0) { peg$fail(peg$c77); } + if (peg$silentFails === 0) { peg$fail(peg$c78); } } if (s0 === peg$FAILED) { if (input.charCodeAt(peg$currPos) === 91) { - s0 = peg$c78; + s0 = peg$c79; peg$currPos++; } else { s0 = peg$FAILED; - if (peg$silentFails === 0) { peg$fail(peg$c79); } + if (peg$silentFails === 0) { peg$fail(peg$c80); } } } @@ -2124,7 +2347,7 @@ var parser=(function() { peg$silentFails--; if (s0 === peg$FAILED) { s1 = peg$FAILED; - if (peg$silentFails === 0) { peg$fail(peg$c80); } + if (peg$silentFails === 0) { peg$fail(peg$c81); } } return s0; @@ -2144,11 +2367,14 @@ var parser=(function() { if (s2 === peg$FAILED) { s2 = peg$parsevariableSubstitution(); if (s2 === peg$FAILED) { - s2 = peg$parsecommandSubstitution(); + s2 = peg$parsearithmeticSubstitution(); if (s2 === peg$FAILED) { - s2 = peg$parsesingleQuote(); + s2 = peg$parsecommandSubstitution(); if (s2 === peg$FAILED) { - s2 = peg$parsedoubleQuote(); + s2 = peg$parsesingleQuote(); + if (s2 === peg$FAILED) { + s2 = peg$parsedoubleQuote(); + } } } } @@ -2166,11 +2392,14 @@ var parser=(function() { if (s2 === peg$FAILED) { s2 = peg$parsevariableSubstitution(); if (s2 === peg$FAILED) { - s2 = peg$parsecommandSubstitution(); + s2 = peg$parsearithmeticSubstitution(); if (s2 === peg$FAILED) { - s2 = peg$parsesingleQuote(); + s2 = peg$parsecommandSubstitution(); if (s2 === peg$FAILED) { - s2 = peg$parsedoubleQuote(); + s2 = peg$parsesingleQuote(); + if (s2 === peg$FAILED) { + s2 = peg$parsedoubleQuote(); + } } } } @@ -2183,13 +2412,13 @@ var parser=(function() { } if (s1 !== peg$FAILED) { peg$savedPos = s0; - s1 = peg$c82(s1); + s1 = peg$c83(s1); } s0 = s1; peg$silentFails--; if (s0 === peg$FAILED) { s1 = peg$FAILED; - if (peg$silentFails === 0) { peg$fail(peg$c81); } + if (peg$silentFails === 0) { peg$fail(peg$c82); } } return s0; @@ -2203,11 +2432,11 @@ var parser=(function() { s1 = peg$currPos; peg$silentFails++; if (input.charCodeAt(peg$currPos) === 35) { - s2 = peg$c84; + s2 = peg$c85; peg$currPos++; } else { s2 = peg$FAILED; - if (peg$silentFails === 0) { peg$fail(peg$c85); } + if (peg$silentFails === 0) { peg$fail(peg$c86); } } peg$silentFails--; if (s2 === peg$FAILED) { @@ -2229,7 +2458,7 @@ var parser=(function() { } if (s2 !== peg$FAILED) { peg$savedPos = s0; - s1 = peg$c86(s2); + s1 = peg$c87(s2); s0 = s1; } else { peg$currPos = s0; @@ -2242,7 +2471,7 @@ var parser=(function() { peg$silentFails--; if (s0 === peg$FAILED) { s1 = peg$FAILED; - if (peg$silentFails === 0) { peg$fail(peg$c83); } + if (peg$silentFails === 0) { peg$fail(peg$c84); } } return s0; @@ -2253,17 +2482,17 @@ var parser=(function() { s0 = peg$currPos; if (input.charCodeAt(peg$currPos) === 92) { - s1 = peg$c87; + s1 = peg$c88; peg$currPos++; } else { s1 = peg$FAILED; - if (peg$silentFails === 0) { peg$fail(peg$c88); } + if (peg$silentFails === 0) { peg$fail(peg$c89); } } if (s1 !== peg$FAILED) { s2 = peg$parsebarewordMeta(); if (s2 !== peg$FAILED) { peg$savedPos = s0; - s1 = peg$c89(s2); + s1 = peg$c90(s2); s0 = s1; } else { peg$currPos = s0; @@ -2291,11 +2520,11 @@ var parser=(function() { peg$currPos++; } else { s2 = peg$FAILED; - if (peg$silentFails === 0) { peg$fail(peg$c90); } + if (peg$silentFails === 0) { peg$fail(peg$c91); } } if (s2 !== peg$FAILED) { peg$savedPos = s0; - s1 = peg$c89(s2); + s1 = peg$c90(s2); s0 = s1; } else { peg$currPos = s0; @@ -2313,12 +2542,12 @@ var parser=(function() { function peg$parsebarewordMeta() { var s0; - if (peg$c91.test(input.charAt(peg$currPos))) { + if (peg$c92.test(input.charAt(peg$currPos))) { s0 = input.charAt(peg$currPos); peg$currPos++; } else { s0 = peg$FAILED; - if (peg$silentFails === 0) { peg$fail(peg$c92); } + if (peg$silentFails === 0) { peg$fail(peg$c93); } } return s0; @@ -2337,19 +2566,19 @@ var parser=(function() { if (s1 !== peg$FAILED) { s2 = []; if (input.charCodeAt(peg$currPos) === 42) { - s3 = peg$c93; + s3 = peg$c94; peg$currPos++; } else { s3 = peg$FAILED; - if (peg$silentFails === 0) { peg$fail(peg$c94); } + if (peg$silentFails === 0) { peg$fail(peg$c95); } } if (s3 === peg$FAILED) { if (input.charCodeAt(peg$currPos) === 63) { - s3 = peg$c95; + s3 = peg$c96; peg$currPos++; } else { s3 = peg$FAILED; - if (peg$silentFails === 0) { peg$fail(peg$c96); } + if (peg$silentFails === 0) { peg$fail(peg$c97); } } if (s3 === peg$FAILED) { s3 = peg$parsecharacterRange(); @@ -2362,19 +2591,19 @@ var parser=(function() { while (s3 !== peg$FAILED) { s2.push(s3); if (input.charCodeAt(peg$currPos) === 42) { - s3 = peg$c93; + s3 = peg$c94; peg$currPos++; } else { s3 = peg$FAILED; - if (peg$silentFails === 0) { peg$fail(peg$c94); } + if (peg$silentFails === 0) { peg$fail(peg$c95); } } if (s3 === peg$FAILED) { if (input.charCodeAt(peg$currPos) === 63) { - s3 = peg$c95; + s3 = peg$c96; peg$currPos++; } else { s3 = peg$FAILED; - if (peg$silentFails === 0) { peg$fail(peg$c96); } + if (peg$silentFails === 0) { peg$fail(peg$c97); } } if (s3 === peg$FAILED) { s3 = peg$parsecharacterRange(); @@ -2396,7 +2625,7 @@ var parser=(function() { } if (s3 !== peg$FAILED) { peg$savedPos = s0; - s1 = peg$c97(); + s1 = peg$c98(); s0 = s1; } else { peg$currPos = s0; @@ -2420,21 +2649,21 @@ var parser=(function() { s0 = peg$currPos; s1 = peg$currPos; if (input.charCodeAt(peg$currPos) === 91) { - s2 = peg$c78; + s2 = peg$c79; peg$currPos++; } else { s2 = peg$FAILED; - if (peg$silentFails === 0) { peg$fail(peg$c79); } + if (peg$silentFails === 0) { peg$fail(peg$c80); } } if (s2 !== peg$FAILED) { s3 = peg$currPos; peg$silentFails++; if (input.charCodeAt(peg$currPos) === 45) { - s4 = peg$c58; + s4 = peg$c59; peg$currPos++; } else { s4 = peg$FAILED; - if (peg$silentFails === 0) { peg$fail(peg$c59); } + if (peg$silentFails === 0) { peg$fail(peg$c60); } } peg$silentFails--; if (s4 === peg$FAILED) { @@ -2449,25 +2678,25 @@ var parser=(function() { peg$currPos++; } else { s4 = peg$FAILED; - if (peg$silentFails === 0) { peg$fail(peg$c90); } + if (peg$silentFails === 0) { peg$fail(peg$c91); } } if (s4 !== peg$FAILED) { if (input.charCodeAt(peg$currPos) === 45) { - s5 = peg$c58; + s5 = peg$c59; peg$currPos++; } else { s5 = peg$FAILED; - if (peg$silentFails === 0) { peg$fail(peg$c59); } + if (peg$silentFails === 0) { peg$fail(peg$c60); } } if (s5 !== peg$FAILED) { s6 = peg$currPos; peg$silentFails++; if (input.charCodeAt(peg$currPos) === 45) { - s7 = peg$c58; + s7 = peg$c59; peg$currPos++; } else { s7 = peg$FAILED; - if (peg$silentFails === 0) { peg$fail(peg$c59); } + if (peg$silentFails === 0) { peg$fail(peg$c60); } } peg$silentFails--; if (s7 === peg$FAILED) { @@ -2482,15 +2711,15 @@ var parser=(function() { peg$currPos++; } else { s7 = peg$FAILED; - if (peg$silentFails === 0) { peg$fail(peg$c90); } + if (peg$silentFails === 0) { peg$fail(peg$c91); } } if (s7 !== peg$FAILED) { if (input.charCodeAt(peg$currPos) === 93) { - s8 = peg$c98; + s8 = peg$c99; peg$currPos++; } else { s8 = peg$FAILED; - if (peg$silentFails === 0) { peg$fail(peg$c99); } + if (peg$silentFails === 0) { peg$fail(peg$c100); } } if (s8 !== peg$FAILED) { s2 = [s2, s3, s4, s5, s6, s7, s8]; @@ -2542,7 +2771,7 @@ var parser=(function() { peg$currPos++; } else { s2 = peg$FAILED; - if (peg$silentFails === 0) { peg$fail(peg$c90); } + if (peg$silentFails === 0) { peg$fail(peg$c91); } } if (s2 === peg$FAILED) { s2 = null; @@ -2551,11 +2780,11 @@ var parser=(function() { s3 = peg$currPos; peg$silentFails++; if (input.charCodeAt(peg$currPos) === 36) { - s4 = peg$c100; + s4 = peg$c101; peg$currPos++; } else { s4 = peg$FAILED; - if (peg$silentFails === 0) { peg$fail(peg$c101); } + if (peg$silentFails === 0) { peg$fail(peg$c102); } } peg$silentFails--; if (s4 === peg$FAILED) { @@ -2577,11 +2806,11 @@ var parser=(function() { } if (s1 !== peg$FAILED) { if (input.charCodeAt(peg$currPos) === 123) { - s2 = peg$c102; + s2 = peg$c103; peg$currPos++; } else { s2 = peg$FAILED; - if (peg$silentFails === 0) { peg$fail(peg$c103); } + if (peg$silentFails === 0) { peg$fail(peg$c104); } } if (s2 !== peg$FAILED) { s3 = []; @@ -2596,11 +2825,11 @@ var parser=(function() { } if (s3 !== peg$FAILED) { if (input.charCodeAt(peg$currPos) === 125) { - s4 = peg$c104; + s4 = peg$c105; peg$currPos++; } else { s4 = peg$FAILED; - if (peg$silentFails === 0) { peg$fail(peg$c105); } + if (peg$silentFails === 0) { peg$fail(peg$c106); } } if (s4 !== peg$FAILED) { s1 = [s1, s2, s3, s4]; @@ -2630,30 +2859,30 @@ var parser=(function() { s0 = peg$currPos; if (input.charCodeAt(peg$currPos) === 39) { - s1 = peg$c106; + s1 = peg$c107; peg$currPos++; } else { s1 = peg$FAILED; - if (peg$silentFails === 0) { peg$fail(peg$c107); } + if (peg$silentFails === 0) { peg$fail(peg$c108); } } if (s1 !== peg$FAILED) { s2 = peg$currPos; s3 = []; - if (peg$c108.test(input.charAt(peg$currPos))) { + if (peg$c109.test(input.charAt(peg$currPos))) { s4 = input.charAt(peg$currPos); peg$currPos++; } else { s4 = peg$FAILED; - if (peg$silentFails === 0) { peg$fail(peg$c109); } + if (peg$silentFails === 0) { peg$fail(peg$c110); } } while (s4 !== peg$FAILED) { s3.push(s4); - if (peg$c108.test(input.charAt(peg$currPos))) { + if (peg$c109.test(input.charAt(peg$currPos))) { s4 = input.charAt(peg$currPos); peg$currPos++; } else { s4 = peg$FAILED; - if (peg$silentFails === 0) { peg$fail(peg$c109); } + if (peg$silentFails === 0) { peg$fail(peg$c110); } } } if (s3 !== peg$FAILED) { @@ -2663,15 +2892,15 @@ var parser=(function() { } if (s2 !== peg$FAILED) { if (input.charCodeAt(peg$currPos) === 39) { - s3 = peg$c106; + s3 = peg$c107; peg$currPos++; } else { s3 = peg$FAILED; - if (peg$silentFails === 0) { peg$fail(peg$c107); } + if (peg$silentFails === 0) { peg$fail(peg$c108); } } if (s3 !== peg$FAILED) { peg$savedPos = s0; - s1 = peg$c110(s2); + s1 = peg$c111(s2); s0 = s1; } else { peg$currPos = s0; @@ -2694,11 +2923,11 @@ var parser=(function() { s0 = peg$currPos; if (input.charCodeAt(peg$currPos) === 34) { - s1 = peg$c111; + s1 = peg$c112; peg$currPos++; } else { s1 = peg$FAILED; - if (peg$silentFails === 0) { peg$fail(peg$c112); } + if (peg$silentFails === 0) { peg$fail(peg$c113); } } if (s1 !== peg$FAILED) { s2 = []; @@ -2733,15 +2962,15 @@ var parser=(function() { } if (s2 !== peg$FAILED) { if (input.charCodeAt(peg$currPos) === 34) { - s3 = peg$c111; + s3 = peg$c112; peg$currPos++; } else { s3 = peg$FAILED; - if (peg$silentFails === 0) { peg$fail(peg$c112); } + if (peg$silentFails === 0) { peg$fail(peg$c113); } } if (s3 !== peg$FAILED) { peg$savedPos = s0; - s1 = peg$c113(s2); + s1 = peg$c114(s2); s0 = s1; } else { peg$currPos = s0; @@ -2764,17 +2993,17 @@ var parser=(function() { s0 = peg$currPos; if (input.charCodeAt(peg$currPos) === 92) { - s1 = peg$c87; + s1 = peg$c88; peg$currPos++; } else { s1 = peg$FAILED; - if (peg$silentFails === 0) { peg$fail(peg$c88); } + if (peg$silentFails === 0) { peg$fail(peg$c89); } } if (s1 !== peg$FAILED) { s2 = peg$parsedoubleQuoteMeta(); if (s2 !== peg$FAILED) { peg$savedPos = s0; - s1 = peg$c89(s2); + s1 = peg$c90(s2); s0 = s1; } else { peg$currPos = s0; @@ -2786,16 +3015,16 @@ var parser=(function() { } if (s0 === peg$FAILED) { s0 = peg$currPos; - if (input.substr(peg$currPos, 2) === peg$c114) { - s1 = peg$c114; + if (input.substr(peg$currPos, 2) === peg$c115) { + s1 = peg$c115; peg$currPos += 2; } else { s1 = peg$FAILED; - if (peg$silentFails === 0) { peg$fail(peg$c115); } + if (peg$silentFails === 0) { peg$fail(peg$c116); } } if (s1 !== peg$FAILED) { peg$savedPos = s0; - s1 = peg$c116(); + s1 = peg$c117(); } s0 = s1; if (s0 === peg$FAILED) { @@ -2816,11 +3045,11 @@ var parser=(function() { peg$currPos++; } else { s2 = peg$FAILED; - if (peg$silentFails === 0) { peg$fail(peg$c90); } + if (peg$silentFails === 0) { peg$fail(peg$c91); } } if (s2 !== peg$FAILED) { peg$savedPos = s0; - s1 = peg$c89(s2); + s1 = peg$c90(s2); s0 = s1; } else { peg$currPos = s0; @@ -2840,27 +3069,27 @@ var parser=(function() { var s0; if (input.charCodeAt(peg$currPos) === 34) { - s0 = peg$c111; + s0 = peg$c112; peg$currPos++; } else { s0 = peg$FAILED; - if (peg$silentFails === 0) { peg$fail(peg$c112); } + if (peg$silentFails === 0) { peg$fail(peg$c113); } } if (s0 === peg$FAILED) { if (input.charCodeAt(peg$currPos) === 36) { - s0 = peg$c100; + s0 = peg$c101; peg$currPos++; } else { s0 = peg$FAILED; - if (peg$silentFails === 0) { peg$fail(peg$c101); } + if (peg$silentFails === 0) { peg$fail(peg$c102); } } if (s0 === peg$FAILED) { if (input.charCodeAt(peg$currPos) === 96) { - s0 = peg$c117; + s0 = peg$c118; peg$currPos++; } else { s0 = peg$FAILED; - if (peg$silentFails === 0) { peg$fail(peg$c118); } + if (peg$silentFails === 0) { peg$fail(peg$c119); } } } } @@ -2871,11 +3100,14 @@ var parser=(function() { function peg$parseexpandsInQuotes() { var s0; - s0 = peg$parsecommandSubstitution(); + s0 = peg$parsearithmeticSubstitution(); if (s0 === peg$FAILED) { - s0 = peg$parseenvironmentVariable(); + s0 = peg$parsecommandSubstitution(); if (s0 === peg$FAILED) { - s0 = peg$parsevariableSubstitution(); + s0 = peg$parseenvironmentVariable(); + if (s0 === peg$FAILED) { + s0 = peg$parsevariableSubstitution(); + } } } @@ -2887,17 +3119,17 @@ var parser=(function() { s0 = peg$currPos; if (input.charCodeAt(peg$currPos) === 36) { - s1 = peg$c100; + s1 = peg$c101; peg$currPos++; } else { s1 = peg$FAILED; - if (peg$silentFails === 0) { peg$fail(peg$c101); } + if (peg$silentFails === 0) { peg$fail(peg$c102); } } if (s1 !== peg$FAILED) { s2 = peg$parsereadableVariableName(); if (s2 !== peg$FAILED) { peg$savedPos = s0; - s1 = peg$c119(s2); + s1 = peg$c120(s2); s0 = s1; } else { peg$currPos = s0; @@ -2916,22 +3148,22 @@ var parser=(function() { s0 = peg$currPos; s1 = []; - if (peg$c120.test(input.charAt(peg$currPos))) { + if (peg$c121.test(input.charAt(peg$currPos))) { s2 = input.charAt(peg$currPos); peg$currPos++; } else { s2 = peg$FAILED; - if (peg$silentFails === 0) { peg$fail(peg$c121); } + if (peg$silentFails === 0) { peg$fail(peg$c122); } } if (s2 !== peg$FAILED) { while (s2 !== peg$FAILED) { s1.push(s2); - if (peg$c120.test(input.charAt(peg$currPos))) { + if (peg$c121.test(input.charAt(peg$currPos))) { s2 = input.charAt(peg$currPos); peg$currPos++; } else { s2 = peg$FAILED; - if (peg$silentFails === 0) { peg$fail(peg$c121); } + if (peg$silentFails === 0) { peg$fail(peg$c122); } } } } else { @@ -2939,7 +3171,7 @@ var parser=(function() { } if (s1 !== peg$FAILED) { peg$savedPos = s0; - s1 = peg$c122(); + s1 = peg$c123(); } s0 = s1; @@ -2952,11 +3184,11 @@ var parser=(function() { s0 = peg$parsewritableVariableName(); if (s0 === peg$FAILED) { if (input.charCodeAt(peg$currPos) === 63) { - s0 = peg$c95; + s0 = peg$c96; peg$currPos++; } else { s0 = peg$FAILED; - if (peg$silentFails === 0) { peg$fail(peg$c96); } + if (peg$silentFails === 0) { peg$fail(peg$c97); } } } @@ -2967,43 +3199,43 @@ var parser=(function() { var s0, s1, s2, s3; s0 = peg$currPos; - if (input.substr(peg$currPos, 2) === peg$c123) { - s1 = peg$c123; + if (input.substr(peg$currPos, 2) === peg$c124) { + s1 = peg$c124; peg$currPos += 2; } else { s1 = peg$FAILED; - if (peg$silentFails === 0) { peg$fail(peg$c124); } + if (peg$silentFails === 0) { peg$fail(peg$c125); } } if (s1 !== peg$FAILED) { s2 = []; - if (peg$c125.test(input.charAt(peg$currPos))) { + if (peg$c126.test(input.charAt(peg$currPos))) { s3 = input.charAt(peg$currPos); peg$currPos++; } else { s3 = peg$FAILED; - if (peg$silentFails === 0) { peg$fail(peg$c126); } + if (peg$silentFails === 0) { peg$fail(peg$c127); } } while (s3 !== peg$FAILED) { s2.push(s3); - if (peg$c125.test(input.charAt(peg$currPos))) { + if (peg$c126.test(input.charAt(peg$currPos))) { s3 = input.charAt(peg$currPos); peg$currPos++; } else { s3 = peg$FAILED; - if (peg$silentFails === 0) { peg$fail(peg$c126); } + if (peg$silentFails === 0) { peg$fail(peg$c127); } } } if (s2 !== peg$FAILED) { if (input.charCodeAt(peg$currPos) === 125) { - s3 = peg$c104; + s3 = peg$c105; peg$currPos++; } else { s3 = peg$FAILED; - if (peg$silentFails === 0) { peg$fail(peg$c105); } + if (peg$silentFails === 0) { peg$fail(peg$c106); } } if (s3 !== peg$FAILED) { peg$savedPos = s0; - s1 = peg$c127(s2); + s1 = peg$c128(s2); s0 = s1; } else { peg$currPos = s0; @@ -3036,26 +3268,26 @@ var parser=(function() { var s0, s1, s2, s3; s0 = peg$currPos; - if (input.substr(peg$currPos, 2) === peg$c128) { - s1 = peg$c128; + if (input.substr(peg$currPos, 2) === peg$c129) { + s1 = peg$c129; peg$currPos += 2; } else { s1 = peg$FAILED; - if (peg$silentFails === 0) { peg$fail(peg$c129); } + if (peg$silentFails === 0) { peg$fail(peg$c130); } } if (s1 !== peg$FAILED) { s2 = peg$parsestatementList(); if (s2 !== peg$FAILED) { if (input.charCodeAt(peg$currPos) === 41) { - s3 = peg$c11; + s3 = peg$c17; peg$currPos++; } else { s3 = peg$FAILED; - if (peg$silentFails === 0) { peg$fail(peg$c12); } + if (peg$silentFails === 0) { peg$fail(peg$c18); } } if (s3 !== peg$FAILED) { peg$savedPos = s0; - s1 = peg$c130(s2); + s1 = peg$c131(s2); s0 = s1; } else { peg$currPos = s0; @@ -3077,25 +3309,26 @@ var parser=(function() { var s0, s1, s2, s3; s0 = peg$currPos; - if (input.substr(peg$currPos, 3) === peg$c131) { - s1 = peg$c131; + if (input.substr(peg$currPos, 3) === peg$c132) { + s1 = peg$c132; peg$currPos += 3; } else { s1 = peg$FAILED; - if (peg$silentFails === 0) { peg$fail(peg$c132); } + if (peg$silentFails === 0) { peg$fail(peg$c133); } } if (s1 !== peg$FAILED) { - s2 = peg$parsecommandName(); + s2 = peg$parsearithmetic(); if (s2 !== peg$FAILED) { - if (input.substr(peg$currPos, 2) === peg$c17) { - s3 = peg$c17; + if (input.substr(peg$currPos, 2) === peg$c11) { + s3 = peg$c11; peg$currPos += 2; } else { s3 = peg$FAILED; - if (peg$silentFails === 0) { peg$fail(peg$c18); } + if (peg$silentFails === 0) { peg$fail(peg$c12); } } if (s3 !== peg$FAILED) { - s1 = [s1, s2, s3]; + peg$savedPos = s0; + s1 = peg$c134(s2); s0 = s1; } else { peg$currPos = s0; @@ -3118,11 +3351,11 @@ var parser=(function() { s0 = peg$currPos; if (input.charCodeAt(peg$currPos) === 96) { - s1 = peg$c117; + s1 = peg$c118; peg$currPos++; } else { s1 = peg$FAILED; - if (peg$silentFails === 0) { peg$fail(peg$c118); } + if (peg$silentFails === 0) { peg$fail(peg$c119); } } if (s1 !== peg$FAILED) { s2 = []; @@ -3137,15 +3370,15 @@ var parser=(function() { } if (s2 !== peg$FAILED) { if (input.charCodeAt(peg$currPos) === 96) { - s3 = peg$c117; + s3 = peg$c118; peg$currPos++; } else { s3 = peg$FAILED; - if (peg$silentFails === 0) { peg$fail(peg$c118); } + if (peg$silentFails === 0) { peg$fail(peg$c119); } } if (s3 !== peg$FAILED) { peg$savedPos = s0; - s1 = peg$c133(s2); + s1 = peg$c135(s2); s0 = s1; } else { peg$currPos = s0; @@ -3167,30 +3400,30 @@ var parser=(function() { var s0, s1, s2; s0 = peg$currPos; - if (input.substr(peg$currPos, 2) === peg$c134) { - s1 = peg$c134; + if (input.substr(peg$currPos, 2) === peg$c136) { + s1 = peg$c136; peg$currPos += 2; } else { s1 = peg$FAILED; - if (peg$silentFails === 0) { peg$fail(peg$c135); } + if (peg$silentFails === 0) { peg$fail(peg$c137); } } if (s1 !== peg$FAILED) { peg$savedPos = s0; - s1 = peg$c136(); + s1 = peg$c138(); } s0 = s1; if (s0 === peg$FAILED) { s0 = peg$currPos; - if (input.substr(peg$currPos, 2) === peg$c114) { - s1 = peg$c114; + if (input.substr(peg$currPos, 2) === peg$c115) { + s1 = peg$c115; peg$currPos += 2; } else { s1 = peg$FAILED; - if (peg$silentFails === 0) { peg$fail(peg$c115); } + if (peg$silentFails === 0) { peg$fail(peg$c116); } } if (s1 !== peg$FAILED) { peg$savedPos = s0; - s1 = peg$c116(); + s1 = peg$c117(); } s0 = s1; if (s0 === peg$FAILED) { @@ -3198,11 +3431,11 @@ var parser=(function() { s1 = peg$currPos; peg$silentFails++; if (input.charCodeAt(peg$currPos) === 96) { - s2 = peg$c117; + s2 = peg$c118; peg$currPos++; } else { s2 = peg$FAILED; - if (peg$silentFails === 0) { peg$fail(peg$c118); } + if (peg$silentFails === 0) { peg$fail(peg$c119); } } peg$silentFails--; if (s2 === peg$FAILED) { @@ -3217,11 +3450,11 @@ var parser=(function() { peg$currPos++; } else { s2 = peg$FAILED; - if (peg$silentFails === 0) { peg$fail(peg$c90); } + if (peg$silentFails === 0) { peg$fail(peg$c91); } } if (s2 !== peg$FAILED) { peg$savedPos = s0; - s1 = peg$c89(s2); + s1 = peg$c90(s2); s0 = s1; } else { peg$currPos = s0; @@ -3241,34 +3474,34 @@ var parser=(function() { var s0, s1, s2, s3, s4; s0 = peg$currPos; - if (peg$c137.test(input.charAt(peg$currPos))) { + if (peg$c139.test(input.charAt(peg$currPos))) { s1 = input.charAt(peg$currPos); peg$currPos++; } else { s1 = peg$FAILED; - if (peg$silentFails === 0) { peg$fail(peg$c138); } + if (peg$silentFails === 0) { peg$fail(peg$c140); } } if (s1 !== peg$FAILED) { if (input.charCodeAt(peg$currPos) === 40) { - s2 = peg$c9; + s2 = peg$c15; peg$currPos++; } else { s2 = peg$FAILED; - if (peg$silentFails === 0) { peg$fail(peg$c10); } + if (peg$silentFails === 0) { peg$fail(peg$c16); } } if (s2 !== peg$FAILED) { s3 = peg$parsestatementList(); if (s3 !== peg$FAILED) { if (input.charCodeAt(peg$currPos) === 41) { - s4 = peg$c11; + s4 = peg$c17; peg$currPos++; } else { s4 = peg$FAILED; - if (peg$silentFails === 0) { peg$fail(peg$c12); } + if (peg$silentFails === 0) { peg$fail(peg$c18); } } if (s4 !== peg$FAILED) { peg$savedPos = s0; - s1 = peg$c139(s1, s3); + s1 = peg$c141(s1, s3); s0 = s1; } else { peg$currPos = s0; @@ -3313,35 +3546,35 @@ var parser=(function() { s1 = null; } if (s1 !== peg$FAILED) { - if (input.substr(peg$currPos, 2) === peg$c140) { - s2 = peg$c140; + if (input.substr(peg$currPos, 2) === peg$c142) { + s2 = peg$c142; peg$currPos += 2; } else { s2 = peg$FAILED; - if (peg$silentFails === 0) { peg$fail(peg$c141); } + if (peg$silentFails === 0) { peg$fail(peg$c143); } } if (s2 === peg$FAILED) { - if (input.substr(peg$currPos, 2) === peg$c142) { - s2 = peg$c142; + if (input.substr(peg$currPos, 2) === peg$c144) { + s2 = peg$c144; peg$currPos += 2; } else { s2 = peg$FAILED; - if (peg$silentFails === 0) { peg$fail(peg$c143); } + if (peg$silentFails === 0) { peg$fail(peg$c145); } } } if (s2 !== peg$FAILED) { s3 = peg$parsefd(); if (s3 !== peg$FAILED) { if (input.charCodeAt(peg$currPos) === 45) { - s4 = peg$c58; + s4 = peg$c59; peg$currPos++; } else { s4 = peg$FAILED; - if (peg$silentFails === 0) { peg$fail(peg$c59); } + if (peg$silentFails === 0) { peg$fail(peg$c60); } } if (s4 !== peg$FAILED) { peg$savedPos = s0; - s1 = peg$c144(s1, s2, s3); + s1 = peg$c146(s1, s2, s3); s0 = s1; } else { peg$currPos = s0; @@ -3372,20 +3605,20 @@ var parser=(function() { s1 = null; } if (s1 !== peg$FAILED) { - if (input.substr(peg$currPos, 2) === peg$c140) { - s2 = peg$c140; + if (input.substr(peg$currPos, 2) === peg$c142) { + s2 = peg$c142; peg$currPos += 2; } else { s2 = peg$FAILED; - if (peg$silentFails === 0) { peg$fail(peg$c141); } + if (peg$silentFails === 0) { peg$fail(peg$c143); } } if (s2 === peg$FAILED) { - if (input.substr(peg$currPos, 2) === peg$c142) { - s2 = peg$c142; + if (input.substr(peg$currPos, 2) === peg$c144) { + s2 = peg$c144; peg$currPos += 2; } else { s2 = peg$FAILED; - if (peg$silentFails === 0) { peg$fail(peg$c143); } + if (peg$silentFails === 0) { peg$fail(peg$c145); } } } if (s2 !== peg$FAILED) { @@ -3399,7 +3632,7 @@ var parser=(function() { s4 = peg$parsefd(); if (s4 !== peg$FAILED) { peg$savedPos = s0; - s1 = peg$c145(s1, s2, s4); + s1 = peg$c147(s1, s2, s4); s0 = s1; } else { peg$currPos = s0; @@ -3442,7 +3675,7 @@ var parser=(function() { s4 = peg$parseargument(); if (s4 !== peg$FAILED) { peg$savedPos = s0; - s1 = peg$c146(s1, s2, s4); + s1 = peg$c148(s1, s2, s4); s0 = s1; } else { peg$currPos = s0; @@ -3467,52 +3700,52 @@ var parser=(function() { function peg$parseredirectionOperator() { var s0; - if (input.substr(peg$currPos, 2) === peg$c147) { - s0 = peg$c147; + if (input.substr(peg$currPos, 2) === peg$c149) { + s0 = peg$c149; peg$currPos += 2; } else { s0 = peg$FAILED; - if (peg$silentFails === 0) { peg$fail(peg$c148); } + if (peg$silentFails === 0) { peg$fail(peg$c150); } } if (s0 === peg$FAILED) { - if (input.substr(peg$currPos, 2) === peg$c149) { - s0 = peg$c149; + if (input.substr(peg$currPos, 2) === peg$c151) { + s0 = peg$c151; peg$currPos += 2; } else { s0 = peg$FAILED; - if (peg$silentFails === 0) { peg$fail(peg$c150); } + if (peg$silentFails === 0) { peg$fail(peg$c152); } } if (s0 === peg$FAILED) { - if (input.substr(peg$currPos, 3) === peg$c151) { - s0 = peg$c151; + if (input.substr(peg$currPos, 3) === peg$c153) { + s0 = peg$c153; peg$currPos += 3; } else { s0 = peg$FAILED; - if (peg$silentFails === 0) { peg$fail(peg$c152); } + if (peg$silentFails === 0) { peg$fail(peg$c154); } } if (s0 === peg$FAILED) { - if (input.substr(peg$currPos, 2) === peg$c153) { - s0 = peg$c153; + if (input.substr(peg$currPos, 2) === peg$c155) { + s0 = peg$c155; peg$currPos += 2; } else { s0 = peg$FAILED; - if (peg$silentFails === 0) { peg$fail(peg$c154); } + if (peg$silentFails === 0) { peg$fail(peg$c156); } } if (s0 === peg$FAILED) { if (input.charCodeAt(peg$currPos) === 60) { - s0 = peg$c155; + s0 = peg$c157; peg$currPos++; } else { s0 = peg$FAILED; - if (peg$silentFails === 0) { peg$fail(peg$c156); } + if (peg$silentFails === 0) { peg$fail(peg$c158); } } if (s0 === peg$FAILED) { if (input.charCodeAt(peg$currPos) === 62) { - s0 = peg$c157; + s0 = peg$c159; peg$currPos++; } else { s0 = peg$FAILED; - if (peg$silentFails === 0) { peg$fail(peg$c158); } + if (peg$silentFails === 0) { peg$fail(peg$c160); } } } } @@ -3528,22 +3761,22 @@ var parser=(function() { s0 = peg$currPos; s1 = []; - if (peg$c159.test(input.charAt(peg$currPos))) { + if (peg$c161.test(input.charAt(peg$currPos))) { s2 = input.charAt(peg$currPos); peg$currPos++; } else { s2 = peg$FAILED; - if (peg$silentFails === 0) { peg$fail(peg$c160); } + if (peg$silentFails === 0) { peg$fail(peg$c162); } } if (s2 !== peg$FAILED) { while (s2 !== peg$FAILED) { s1.push(s2); - if (peg$c159.test(input.charAt(peg$currPos))) { + if (peg$c161.test(input.charAt(peg$currPos))) { s2 = input.charAt(peg$currPos); peg$currPos++; } else { s2 = peg$FAILED; - if (peg$silentFails === 0) { peg$fail(peg$c160); } + if (peg$silentFails === 0) { peg$fail(peg$c162); } } } } else { @@ -3551,7 +3784,7 @@ var parser=(function() { } if (s1 !== peg$FAILED) { peg$savedPos = s0; - s1 = peg$c161(s1); + s1 = peg$c163(s1); } s0 = s1; @@ -3570,33 +3803,33 @@ var parser=(function() { } if (s1 !== peg$FAILED) { if (input.charCodeAt(peg$currPos) === 38) { - s2 = peg$c162; + s2 = peg$c164; peg$currPos++; } else { s2 = peg$FAILED; - if (peg$silentFails === 0) { peg$fail(peg$c163); } + if (peg$silentFails === 0) { peg$fail(peg$c165); } } if (s2 === peg$FAILED) { if (input.charCodeAt(peg$currPos) === 59) { - s2 = peg$c50; + s2 = peg$c51; peg$currPos++; } else { s2 = peg$FAILED; - if (peg$silentFails === 0) { peg$fail(peg$c51); } + if (peg$silentFails === 0) { peg$fail(peg$c52); } } if (s2 === peg$FAILED) { if (input.charCodeAt(peg$currPos) === 10) { - s2 = peg$c52; + s2 = peg$c53; peg$currPos++; } else { s2 = peg$FAILED; - if (peg$silentFails === 0) { peg$fail(peg$c53); } + if (peg$silentFails === 0) { peg$fail(peg$c54); } } } } if (s2 !== peg$FAILED) { peg$savedPos = s0; - s1 = peg$c164(s2); + s1 = peg$c166(s2); s0 = s1; } else { peg$currPos = s0; @@ -3615,11 +3848,11 @@ var parser=(function() { s0 = peg$currPos; if (input.charCodeAt(peg$currPos) === 124) { - s1 = peg$c165; + s1 = peg$c167; peg$currPos++; } else { s1 = peg$FAILED; - if (peg$silentFails === 0) { peg$fail(peg$c166); } + if (peg$silentFails === 0) { peg$fail(peg$c168); } } if (s1 !== peg$FAILED) { s2 = []; @@ -3632,7 +3865,7 @@ var parser=(function() { s3 = peg$parsecommand(); if (s3 !== peg$FAILED) { peg$savedPos = s0; - s1 = peg$c167(s3); + s1 = peg$c169(s3); s0 = s1; } else { peg$currPos = s0; @@ -3655,25 +3888,25 @@ var parser=(function() { peg$silentFails++; if (input.charCodeAt(peg$currPos) === 32) { - s0 = peg$c169; + s0 = peg$c171; peg$currPos++; } else { s0 = peg$FAILED; - if (peg$silentFails === 0) { peg$fail(peg$c170); } + if (peg$silentFails === 0) { peg$fail(peg$c172); } } if (s0 === peg$FAILED) { if (input.charCodeAt(peg$currPos) === 9) { - s0 = peg$c171; + s0 = peg$c173; peg$currPos++; } else { s0 = peg$FAILED; - if (peg$silentFails === 0) { peg$fail(peg$c172); } + if (peg$silentFails === 0) { peg$fail(peg$c174); } } } peg$silentFails--; if (s0 === peg$FAILED) { s1 = peg$FAILED; - if (peg$silentFails === 0) { peg$fail(peg$c168); } + if (peg$silentFails === 0) { peg$fail(peg$c170); } } return s0; @@ -3685,11 +3918,11 @@ var parser=(function() { s0 = peg$parsespace(); if (s0 === peg$FAILED) { if (input.charCodeAt(peg$currPos) === 10) { - s0 = peg$c52; + s0 = peg$c53; peg$currPos++; } else { s0 = peg$FAILED; - if (peg$silentFails === 0) { peg$fail(peg$c53); } + if (peg$silentFails === 0) { peg$fail(peg$c54); } } if (s0 === peg$FAILED) { s0 = peg$parsecomment(); @@ -3705,38 +3938,38 @@ var parser=(function() { peg$silentFails++; s0 = peg$currPos; if (input.charCodeAt(peg$currPos) === 35) { - s1 = peg$c84; + s1 = peg$c85; peg$currPos++; } else { s1 = peg$FAILED; - if (peg$silentFails === 0) { peg$fail(peg$c85); } + if (peg$silentFails === 0) { peg$fail(peg$c86); } } if (s1 !== peg$FAILED) { s2 = []; - if (peg$c68.test(input.charAt(peg$currPos))) { + if (peg$c69.test(input.charAt(peg$currPos))) { s3 = input.charAt(peg$currPos); peg$currPos++; } else { s3 = peg$FAILED; - if (peg$silentFails === 0) { peg$fail(peg$c69); } + if (peg$silentFails === 0) { peg$fail(peg$c70); } } while (s3 !== peg$FAILED) { s2.push(s3); - if (peg$c68.test(input.charAt(peg$currPos))) { + if (peg$c69.test(input.charAt(peg$currPos))) { s3 = input.charAt(peg$currPos); peg$currPos++; } else { s3 = peg$FAILED; - if (peg$silentFails === 0) { peg$fail(peg$c69); } + if (peg$silentFails === 0) { peg$fail(peg$c70); } } } if (s2 !== peg$FAILED) { if (input.charCodeAt(peg$currPos) === 10) { - s3 = peg$c52; + s3 = peg$c53; peg$currPos++; } else { s3 = peg$FAILED; - if (peg$silentFails === 0) { peg$fail(peg$c53); } + if (peg$silentFails === 0) { peg$fail(peg$c54); } } if (s3 === peg$FAILED) { s3 = peg$parseEOF(); @@ -3759,7 +3992,7 @@ var parser=(function() { peg$silentFails--; if (s0 === peg$FAILED) { s1 = peg$FAILED; - if (peg$silentFails === 0) { peg$fail(peg$c173); } + if (peg$silentFails === 0) { peg$fail(peg$c175); } } return s0; @@ -3769,108 +4002,108 @@ var parser=(function() { var s0, s1, s2, s3; s0 = peg$currPos; - if (input.substr(peg$currPos, 5) === peg$c36) { - s1 = peg$c36; + if (input.substr(peg$currPos, 5) === peg$c37) { + s1 = peg$c37; peg$currPos += 5; } else { s1 = peg$FAILED; - if (peg$silentFails === 0) { peg$fail(peg$c37); } + if (peg$silentFails === 0) { peg$fail(peg$c38); } } if (s1 === peg$FAILED) { - if (input.substr(peg$currPos, 5) === peg$c38) { - s1 = peg$c38; + if (input.substr(peg$currPos, 5) === peg$c39) { + s1 = peg$c39; peg$currPos += 5; } else { s1 = peg$FAILED; - if (peg$silentFails === 0) { peg$fail(peg$c39); } + if (peg$silentFails === 0) { peg$fail(peg$c40); } } if (s1 === peg$FAILED) { - if (input.substr(peg$currPos, 3) === peg$c46) { - s1 = peg$c46; + if (input.substr(peg$currPos, 3) === peg$c47) { + s1 = peg$c47; peg$currPos += 3; } else { s1 = peg$FAILED; - if (peg$silentFails === 0) { peg$fail(peg$c47); } + if (peg$silentFails === 0) { peg$fail(peg$c48); } } if (s1 === peg$FAILED) { - if (input.substr(peg$currPos, 4) === peg$c42) { - s1 = peg$c42; + if (input.substr(peg$currPos, 4) === peg$c43) { + s1 = peg$c43; peg$currPos += 4; } else { s1 = peg$FAILED; - if (peg$silentFails === 0) { peg$fail(peg$c43); } + if (peg$silentFails === 0) { peg$fail(peg$c44); } } if (s1 === peg$FAILED) { - if (input.substr(peg$currPos, 2) === peg$c40) { - s1 = peg$c40; + if (input.substr(peg$currPos, 2) === peg$c41) { + s1 = peg$c41; peg$currPos += 2; } else { s1 = peg$FAILED; - if (peg$silentFails === 0) { peg$fail(peg$c41); } + if (peg$silentFails === 0) { peg$fail(peg$c42); } } if (s1 === peg$FAILED) { - if (input.substr(peg$currPos, 4) === peg$c174) { - s1 = peg$c174; + if (input.substr(peg$currPos, 4) === peg$c176) { + s1 = peg$c176; peg$currPos += 4; } else { s1 = peg$FAILED; - if (peg$silentFails === 0) { peg$fail(peg$c175); } + if (peg$silentFails === 0) { peg$fail(peg$c177); } } if (s1 === peg$FAILED) { - if (input.substr(peg$currPos, 4) === peg$c176) { - s1 = peg$c176; + if (input.substr(peg$currPos, 4) === peg$c178) { + s1 = peg$c178; peg$currPos += 4; } else { s1 = peg$FAILED; - if (peg$silentFails === 0) { peg$fail(peg$c177); } + if (peg$silentFails === 0) { peg$fail(peg$c179); } } if (s1 === peg$FAILED) { - if (input.substr(peg$currPos, 2) === peg$c23) { - s1 = peg$c23; + 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$c24); } + if (peg$silentFails === 0) { peg$fail(peg$c25); } } if (s1 === peg$FAILED) { - if (input.substr(peg$currPos, 4) === peg$c25) { - s1 = peg$c25; + if (input.substr(peg$currPos, 4) === peg$c26) { + s1 = peg$c26; peg$currPos += 4; } else { s1 = peg$FAILED; - if (peg$silentFails === 0) { peg$fail(peg$c26); } + if (peg$silentFails === 0) { peg$fail(peg$c27); } } if (s1 === peg$FAILED) { - if (input.substr(peg$currPos, 4) === peg$c27) { - s1 = peg$c27; + if (input.substr(peg$currPos, 4) === peg$c28) { + s1 = peg$c28; peg$currPos += 4; } else { s1 = peg$FAILED; - if (peg$silentFails === 0) { peg$fail(peg$c28); } + if (peg$silentFails === 0) { peg$fail(peg$c29); } } if (s1 === peg$FAILED) { - if (input.substr(peg$currPos, 4) === peg$c32) { - s1 = peg$c32; + if (input.substr(peg$currPos, 4) === peg$c33) { + s1 = peg$c33; peg$currPos += 4; } else { s1 = peg$FAILED; - if (peg$silentFails === 0) { peg$fail(peg$c33); } + if (peg$silentFails === 0) { peg$fail(peg$c34); } } if (s1 === peg$FAILED) { - if (input.substr(peg$currPos, 2) === peg$c29) { - s1 = peg$c29; + 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$c30); } + if (peg$silentFails === 0) { peg$fail(peg$c31); } } if (s1 === peg$FAILED) { - if (input.substr(peg$currPos, 2) === peg$c76) { - s1 = peg$c76; + if (input.substr(peg$currPos, 2) === peg$c77) { + s1 = peg$c77; peg$currPos += 2; } else { s1 = peg$FAILED; - if (peg$silentFails === 0) { peg$fail(peg$c77); } + if (peg$silentFails === 0) { peg$fail(peg$c78); } } } } @@ -3913,86 +4146,128 @@ var parser=(function() { return s0; } - function peg$parsecontinuationStart() { - var s0, s1, s2, s3; + function peg$parsearithmetic() { + var s0, s1; + peg$silentFails++; s0 = peg$currPos; - s1 = peg$currPos; + s1 = peg$parseaComma(); + if (s1 !== peg$FAILED) { + peg$savedPos = s0; + s1 = peg$c181(s1); + } + s0 = s1; + peg$silentFails--; + if (s0 === peg$FAILED) { + s1 = peg$FAILED; + if (peg$silentFails === 0) { peg$fail(peg$c180); } + } + + return s0; + } + + function peg$parseaComma() { + var s0, s1, s2, s3, s4, s5, s6, s7; + peg$silentFails++; - s2 = peg$parsekeyword(); - if (s2 === peg$FAILED) { - if (input.charCodeAt(peg$currPos) === 34) { - s2 = peg$c111; - peg$currPos++; - } else { - s2 = peg$FAILED; - if (peg$silentFails === 0) { peg$fail(peg$c112); } + s0 = peg$currPos; + s1 = peg$parseaAssign(); + if (s1 !== peg$FAILED) { + s2 = []; + s3 = peg$currPos; + s4 = []; + s5 = peg$parsespaceNL(); + while (s5 !== peg$FAILED) { + s4.push(s5); + s5 = peg$parsespaceNL(); } - if (s2 === peg$FAILED) { - if (input.charCodeAt(peg$currPos) === 39) { - s2 = peg$c106; + if (s4 !== peg$FAILED) { + if (input.charCodeAt(peg$currPos) === 44) { + s5 = peg$c183; peg$currPos++; } else { - s2 = peg$FAILED; - if (peg$silentFails === 0) { peg$fail(peg$c107); } + s5 = peg$FAILED; + if (peg$silentFails === 0) { peg$fail(peg$c184); } } - if (s2 === peg$FAILED) { - if (input.charCodeAt(peg$currPos) === 96) { - s2 = peg$c117; - peg$currPos++; - } else { - s2 = peg$FAILED; - if (peg$silentFails === 0) { peg$fail(peg$c118); } + if (s5 !== peg$FAILED) { + s6 = []; + s7 = peg$parsespaceNL(); + while (s7 !== peg$FAILED) { + s6.push(s7); + s7 = peg$parsespaceNL(); } - if (s2 === peg$FAILED) { - if (input.substr(peg$currPos, 2) === peg$c128) { - s2 = peg$c128; - peg$currPos += 2; + if (s6 !== peg$FAILED) { + s7 = peg$parseaAssign(); + if (s7 !== peg$FAILED) { + peg$savedPos = s3; + s4 = peg$c185(s1, s7); + s3 = s4; } else { - s2 = peg$FAILED; - if (peg$silentFails === 0) { peg$fail(peg$c129); } - } - 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); } - } + peg$currPos = s3; + s3 = peg$FAILED; } + } else { + peg$currPos = s3; + s3 = peg$FAILED; } + } else { + peg$currPos = s3; + s3 = peg$FAILED; } - } - } - 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 { + peg$currPos = s3; s3 = peg$FAILED; - if (peg$silentFails === 0) { peg$fail(peg$c90); } } while (s3 !== peg$FAILED) { s2.push(s3); - if (input.length > peg$currPos) { - s3 = input.charAt(peg$currPos); - peg$currPos++; + s3 = peg$currPos; + s4 = []; + s5 = peg$parsespaceNL(); + while (s5 !== peg$FAILED) { + s4.push(s5); + s5 = peg$parsespaceNL(); + } + if (s4 !== peg$FAILED) { + if (input.charCodeAt(peg$currPos) === 44) { + s5 = peg$c183; + peg$currPos++; + } else { + s5 = peg$FAILED; + if (peg$silentFails === 0) { peg$fail(peg$c184); } + } + if (s5 !== peg$FAILED) { + s6 = []; + s7 = peg$parsespaceNL(); + while (s7 !== peg$FAILED) { + s6.push(s7); + s7 = peg$parsespaceNL(); + } + if (s6 !== peg$FAILED) { + s7 = peg$parseaAssign(); + if (s7 !== peg$FAILED) { + peg$savedPos = s3; + s4 = peg$c185(s1, s7); + s3 = s4; + } else { + peg$currPos = s3; + s3 = peg$FAILED; + } + } else { + peg$currPos = s3; + s3 = peg$FAILED; + } + } else { + peg$currPos = s3; + s3 = peg$FAILED; + } } else { + peg$currPos = s3; s3 = peg$FAILED; - if (peg$silentFails === 0) { peg$fail(peg$c90); } } } if (s2 !== peg$FAILED) { - s1 = [s1, s2]; + peg$savedPos = s0; + s1 = peg$c186(s1, s2); s0 = s1; } else { peg$currPos = s0; @@ -4002,48 +4277,3259 @@ var parser=(function() { 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$c90); } - } peg$silentFails--; - if (s1 === peg$FAILED) { - s0 = void 0; - } else { - peg$currPos = s0; - s0 = peg$FAILED; + if (s0 === peg$FAILED) { + s1 = peg$FAILED; + if (peg$silentFails === 0) { peg$fail(peg$c182); } } 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) { + function peg$parseaAssign() { + var s0, s1, s2, s3, s4, s5, s6; + + peg$silentFails++; + s0 = peg$currPos; + s1 = peg$parseaCond(); + if (s1 !== peg$FAILED) { + s2 = []; + s3 = peg$parsespaceNL(); + while (s3 !== peg$FAILED) { + s2.push(s3); + s3 = peg$parsespaceNL(); + } + if (s2 !== peg$FAILED) { + s3 = peg$currPos; + if (input.charCodeAt(peg$currPos) === 61) { + s4 = peg$c72; + peg$currPos++; + } else { + s4 = peg$FAILED; + if (peg$silentFails === 0) { peg$fail(peg$c73); } + } + if (s4 !== peg$FAILED) { + s5 = peg$currPos; + peg$silentFails++; + if (input.charCodeAt(peg$currPos) === 61) { + s6 = peg$c72; + peg$currPos++; + } else { + s6 = peg$FAILED; + if (peg$silentFails === 0) { peg$fail(peg$c73); } + } + peg$silentFails--; + if (s6 === peg$FAILED) { + s5 = void 0; + } else { + peg$currPos = s5; + s5 = peg$FAILED; + } + if (s5 !== peg$FAILED) { + s4 = [s4, s5]; + s3 = s4; + } else { + peg$currPos = s3; + s3 = peg$FAILED; + } + } else { + peg$currPos = s3; + s3 = peg$FAILED; + } + if (s3 === peg$FAILED) { + if (input.substr(peg$currPos, 2) === peg$c188) { + s3 = peg$c188; + peg$currPos += 2; + } else { + s3 = peg$FAILED; + if (peg$silentFails === 0) { peg$fail(peg$c189); } + } + if (s3 === peg$FAILED) { + if (input.substr(peg$currPos, 2) === peg$c190) { + s3 = peg$c190; + peg$currPos += 2; + } else { + s3 = peg$FAILED; + if (peg$silentFails === 0) { peg$fail(peg$c191); } + } + if (s3 === peg$FAILED) { + if (input.substr(peg$currPos, 2) === peg$c192) { + s3 = peg$c192; + peg$currPos += 2; + } else { + s3 = peg$FAILED; + if (peg$silentFails === 0) { peg$fail(peg$c193); } + } + if (s3 === peg$FAILED) { + if (input.substr(peg$currPos, 2) === peg$c194) { + s3 = peg$c194; + peg$currPos += 2; + } else { + s3 = peg$FAILED; + if (peg$silentFails === 0) { peg$fail(peg$c195); } + } + if (s3 === peg$FAILED) { + if (input.substr(peg$currPos, 2) === peg$c196) { + s3 = peg$c196; + peg$currPos += 2; + } else { + s3 = peg$FAILED; + if (peg$silentFails === 0) { peg$fail(peg$c197); } + } + if (s3 === peg$FAILED) { + if (input.substr(peg$currPos, 3) === peg$c198) { + s3 = peg$c198; + peg$currPos += 3; + } else { + s3 = peg$FAILED; + if (peg$silentFails === 0) { peg$fail(peg$c199); } + } + if (s3 === peg$FAILED) { + if (input.substr(peg$currPos, 3) === peg$c200) { + s3 = peg$c200; + peg$currPos += 3; + } else { + s3 = peg$FAILED; + if (peg$silentFails === 0) { peg$fail(peg$c201); } + } + if (s3 === peg$FAILED) { + if (input.substr(peg$currPos, 2) === peg$c202) { + s3 = peg$c202; + peg$currPos += 2; + } else { + s3 = peg$FAILED; + if (peg$silentFails === 0) { peg$fail(peg$c203); } + } + if (s3 === peg$FAILED) { + if (input.substr(peg$currPos, 2) === peg$c204) { + s3 = peg$c204; + peg$currPos += 2; + } else { + s3 = peg$FAILED; + if (peg$silentFails === 0) { peg$fail(peg$c205); } + } + if (s3 === peg$FAILED) { + if (input.substr(peg$currPos, 2) === peg$c206) { + s3 = peg$c206; + peg$currPos += 2; + } else { + s3 = peg$FAILED; + if (peg$silentFails === 0) { peg$fail(peg$c207); } + } + } + } + } + } + } + } + } + } + } + } + if (s3 !== peg$FAILED) { + s4 = []; + s5 = peg$parsespaceNL(); + while (s5 !== peg$FAILED) { + s4.push(s5); + s5 = peg$parsespaceNL(); + } + if (s4 !== peg$FAILED) { + s5 = peg$parseaAssign(); + if (s5 !== peg$FAILED) { + peg$savedPos = s0; + s1 = peg$c208(s1, s3, s5); + 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; + } + if (s0 === peg$FAILED) { + s0 = peg$currPos; + s1 = peg$parseaCond(); + if (s1 !== peg$FAILED) { + peg$savedPos = s0; + s1 = peg$c209(s1); + } + s0 = s1; + } + peg$silentFails--; + if (s0 === peg$FAILED) { + s1 = peg$FAILED; + if (peg$silentFails === 0) { peg$fail(peg$c187); } + } + + return s0; + } + + function peg$parseaCond() { + var s0, s1, s2, s3, s4, s5, s6, s7, s8, s9; + + peg$silentFails++; + s0 = peg$currPos; + s1 = peg$parseaLogicalOr(); + if (s1 !== peg$FAILED) { + s2 = []; + s3 = peg$parsespaceNL(); + while (s3 !== peg$FAILED) { + s2.push(s3); + s3 = peg$parsespaceNL(); + } + if (s2 !== peg$FAILED) { + if (input.charCodeAt(peg$currPos) === 63) { + s3 = peg$c96; + peg$currPos++; + } else { + s3 = peg$FAILED; + if (peg$silentFails === 0) { peg$fail(peg$c97); } + } + if (s3 !== peg$FAILED) { + s4 = []; + s5 = peg$parsespaceNL(); + while (s5 !== peg$FAILED) { + s4.push(s5); + s5 = peg$parsespaceNL(); + } + if (s4 !== peg$FAILED) { + s5 = peg$parseaAssign(); + if (s5 !== peg$FAILED) { + s6 = []; + s7 = peg$parsespaceNL(); + while (s7 !== peg$FAILED) { + s6.push(s7); + s7 = peg$parsespaceNL(); + } + if (s6 !== peg$FAILED) { + if (input.charCodeAt(peg$currPos) === 58) { + s7 = peg$c211; + peg$currPos++; + } else { + s7 = peg$FAILED; + if (peg$silentFails === 0) { peg$fail(peg$c212); } + } + if (s7 !== peg$FAILED) { + s8 = []; + s9 = peg$parsespaceNL(); + while (s9 !== peg$FAILED) { + s8.push(s9); + s9 = peg$parsespaceNL(); + } + if (s8 !== peg$FAILED) { + s9 = peg$parseaAssign(); + if (s9 !== peg$FAILED) { + peg$savedPos = s0; + s1 = peg$c213(s1, s5, s9); + 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; + } + if (s0 === peg$FAILED) { + s0 = peg$currPos; + s1 = peg$parseaLogicalOr(); + if (s1 !== peg$FAILED) { + peg$savedPos = s0; + s1 = peg$c209(s1); + } + s0 = s1; + } + peg$silentFails--; + if (s0 === peg$FAILED) { + s1 = peg$FAILED; + if (peg$silentFails === 0) { peg$fail(peg$c210); } + } + + return s0; + } + + function peg$parseaLogicalOr() { + var s0, s1, s2, s3, s4, s5, s6, s7; + + peg$silentFails++; + s0 = peg$currPos; + s1 = peg$parseaLogicalAnd(); + if (s1 !== peg$FAILED) { + s2 = []; + s3 = peg$currPos; + 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$c5) { + s5 = peg$c5; + peg$currPos += 2; + } else { + s5 = peg$FAILED; + if (peg$silentFails === 0) { peg$fail(peg$c6); } + } + if (s5 !== peg$FAILED) { + s6 = []; + s7 = peg$parsespaceNL(); + while (s7 !== peg$FAILED) { + s6.push(s7); + s7 = peg$parsespaceNL(); + } + if (s6 !== peg$FAILED) { + s7 = peg$parseaLogicalAnd(); + if (s7 !== peg$FAILED) { + peg$savedPos = s3; + s4 = peg$c215(s1, s5, s7); + s3 = s4; + } else { + peg$currPos = s3; + s3 = peg$FAILED; + } + } 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 = []; + s5 = peg$parsespaceNL(); + while (s5 !== peg$FAILED) { + s4.push(s5); + s5 = peg$parsespaceNL(); + } + if (s4 !== peg$FAILED) { + if (input.substr(peg$currPos, 2) === peg$c5) { + s5 = peg$c5; + peg$currPos += 2; + } else { + s5 = peg$FAILED; + if (peg$silentFails === 0) { peg$fail(peg$c6); } + } + if (s5 !== peg$FAILED) { + s6 = []; + s7 = peg$parsespaceNL(); + while (s7 !== peg$FAILED) { + s6.push(s7); + s7 = peg$parsespaceNL(); + } + if (s6 !== peg$FAILED) { + s7 = peg$parseaLogicalAnd(); + if (s7 !== peg$FAILED) { + peg$savedPos = s3; + s4 = peg$c215(s1, s5, s7); + s3 = s4; + } else { + peg$currPos = s3; + s3 = peg$FAILED; + } + } 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) { + peg$savedPos = s0; + s1 = peg$c216(s1, 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$c214); } + } + + return s0; + } + + function peg$parseaLogicalAnd() { + var s0, s1, s2, s3, s4, s5, s6, s7; + + peg$silentFails++; + s0 = peg$currPos; + s1 = peg$parseaBitwiseOr(); + if (s1 !== peg$FAILED) { + s2 = []; + s3 = peg$currPos; + 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$c3) { + s5 = peg$c3; + peg$currPos += 2; + } else { + s5 = peg$FAILED; + if (peg$silentFails === 0) { peg$fail(peg$c4); } + } + if (s5 !== peg$FAILED) { + s6 = []; + s7 = peg$parsespaceNL(); + while (s7 !== peg$FAILED) { + s6.push(s7); + s7 = peg$parsespaceNL(); + } + if (s6 !== peg$FAILED) { + s7 = peg$parseaBitwiseOr(); + if (s7 !== peg$FAILED) { + peg$savedPos = s3; + s4 = peg$c215(s1, s5, s7); + s3 = s4; + } else { + peg$currPos = s3; + s3 = peg$FAILED; + } + } 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 = []; + s5 = peg$parsespaceNL(); + while (s5 !== peg$FAILED) { + s4.push(s5); + s5 = peg$parsespaceNL(); + } + if (s4 !== peg$FAILED) { + if (input.substr(peg$currPos, 2) === peg$c3) { + s5 = peg$c3; + peg$currPos += 2; + } else { + s5 = peg$FAILED; + if (peg$silentFails === 0) { peg$fail(peg$c4); } + } + if (s5 !== peg$FAILED) { + s6 = []; + s7 = peg$parsespaceNL(); + while (s7 !== peg$FAILED) { + s6.push(s7); + s7 = peg$parsespaceNL(); + } + if (s6 !== peg$FAILED) { + s7 = peg$parseaBitwiseOr(); + if (s7 !== peg$FAILED) { + peg$savedPos = s3; + s4 = peg$c215(s1, s5, s7); + s3 = s4; + } else { + peg$currPos = s3; + s3 = peg$FAILED; + } + } 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) { + peg$savedPos = s0; + s1 = peg$c216(s1, 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$c217); } + } + + return s0; + } + + function peg$parseaBitwiseOr() { + var s0, s1, s2, s3, s4, s5, s6, s7, s8; + + s0 = peg$currPos; + s1 = peg$parseaBitwiseXor(); + if (s1 !== peg$FAILED) { + s2 = []; + s3 = peg$currPos; + s4 = []; + s5 = peg$parsespaceNL(); + while (s5 !== peg$FAILED) { + s4.push(s5); + s5 = peg$parsespaceNL(); + } + if (s4 !== peg$FAILED) { + if (input.charCodeAt(peg$currPos) === 124) { + s5 = peg$c167; + peg$currPos++; + } else { + s5 = peg$FAILED; + if (peg$silentFails === 0) { peg$fail(peg$c168); } + } + if (s5 !== peg$FAILED) { + s6 = peg$currPos; + peg$silentFails++; + if (peg$c218.test(input.charAt(peg$currPos))) { + s7 = input.charAt(peg$currPos); + peg$currPos++; + } else { + s7 = peg$FAILED; + if (peg$silentFails === 0) { peg$fail(peg$c219); } + } + peg$silentFails--; + if (s7 === peg$FAILED) { + s6 = void 0; + } else { + peg$currPos = s6; + s6 = peg$FAILED; + } + if (s6 !== peg$FAILED) { + s7 = []; + s8 = peg$parsespaceNL(); + while (s8 !== peg$FAILED) { + s7.push(s8); + s8 = peg$parsespaceNL(); + } + if (s7 !== peg$FAILED) { + s8 = peg$parseaBitwiseXor(); + if (s8 !== peg$FAILED) { + peg$savedPos = s3; + s4 = peg$c215(s1, s5, s8); + s3 = s4; + } else { + peg$currPos = s3; + s3 = peg$FAILED; + } + } else { + peg$currPos = s3; + s3 = peg$FAILED; + } + } 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 = []; + s5 = peg$parsespaceNL(); + while (s5 !== peg$FAILED) { + s4.push(s5); + s5 = peg$parsespaceNL(); + } + if (s4 !== peg$FAILED) { + if (input.charCodeAt(peg$currPos) === 124) { + s5 = peg$c167; + peg$currPos++; + } else { + s5 = peg$FAILED; + if (peg$silentFails === 0) { peg$fail(peg$c168); } + } + if (s5 !== peg$FAILED) { + s6 = peg$currPos; + peg$silentFails++; + if (peg$c218.test(input.charAt(peg$currPos))) { + s7 = input.charAt(peg$currPos); + peg$currPos++; + } else { + s7 = peg$FAILED; + if (peg$silentFails === 0) { peg$fail(peg$c219); } + } + peg$silentFails--; + if (s7 === peg$FAILED) { + s6 = void 0; + } else { + peg$currPos = s6; + s6 = peg$FAILED; + } + if (s6 !== peg$FAILED) { + s7 = []; + s8 = peg$parsespaceNL(); + while (s8 !== peg$FAILED) { + s7.push(s8); + s8 = peg$parsespaceNL(); + } + if (s7 !== peg$FAILED) { + s8 = peg$parseaBitwiseXor(); + if (s8 !== peg$FAILED) { + peg$savedPos = s3; + s4 = peg$c215(s1, s5, s8); + s3 = s4; + } else { + peg$currPos = s3; + s3 = peg$FAILED; + } + } else { + peg$currPos = s3; + s3 = peg$FAILED; + } + } 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) { + peg$savedPos = s0; + s1 = peg$c220(s1, s2); + s0 = s1; + } else { + peg$currPos = s0; + s0 = peg$FAILED; + } + } else { + peg$currPos = s0; + s0 = peg$FAILED; + } + + return s0; + } + + function peg$parseaBitwiseXor() { + var s0, s1, s2, s3, s4, s5, s6, s7, s8; + + s0 = peg$currPos; + s1 = peg$parseaBitwiseAnd(); + if (s1 !== peg$FAILED) { + s2 = []; + s3 = peg$currPos; + s4 = []; + s5 = peg$parsespaceNL(); + while (s5 !== peg$FAILED) { + s4.push(s5); + s5 = peg$parsespaceNL(); + } + if (s4 !== peg$FAILED) { + if (input.charCodeAt(peg$currPos) === 94) { + s5 = peg$c221; + peg$currPos++; + } else { + s5 = peg$FAILED; + if (peg$silentFails === 0) { peg$fail(peg$c222); } + } + if (s5 !== peg$FAILED) { + s6 = peg$currPos; + peg$silentFails++; + if (input.charCodeAt(peg$currPos) === 61) { + s7 = peg$c72; + peg$currPos++; + } else { + s7 = peg$FAILED; + if (peg$silentFails === 0) { peg$fail(peg$c73); } + } + peg$silentFails--; + if (s7 === peg$FAILED) { + s6 = void 0; + } else { + peg$currPos = s6; + s6 = peg$FAILED; + } + if (s6 !== peg$FAILED) { + s7 = []; + s8 = peg$parsespaceNL(); + while (s8 !== peg$FAILED) { + s7.push(s8); + s8 = peg$parsespaceNL(); + } + if (s7 !== peg$FAILED) { + s8 = peg$parseaBitwiseAnd(); + if (s8 !== peg$FAILED) { + peg$savedPos = s3; + s4 = peg$c215(s1, s5, s8); + s3 = s4; + } else { + peg$currPos = s3; + s3 = peg$FAILED; + } + } else { + peg$currPos = s3; + s3 = peg$FAILED; + } + } 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 = []; + s5 = peg$parsespaceNL(); + while (s5 !== peg$FAILED) { + s4.push(s5); + s5 = peg$parsespaceNL(); + } + if (s4 !== peg$FAILED) { + if (input.charCodeAt(peg$currPos) === 94) { + s5 = peg$c221; + peg$currPos++; + } else { + s5 = peg$FAILED; + if (peg$silentFails === 0) { peg$fail(peg$c222); } + } + if (s5 !== peg$FAILED) { + s6 = peg$currPos; + peg$silentFails++; + if (input.charCodeAt(peg$currPos) === 61) { + s7 = peg$c72; + peg$currPos++; + } else { + s7 = peg$FAILED; + if (peg$silentFails === 0) { peg$fail(peg$c73); } + } + peg$silentFails--; + if (s7 === peg$FAILED) { + s6 = void 0; + } else { + peg$currPos = s6; + s6 = peg$FAILED; + } + if (s6 !== peg$FAILED) { + s7 = []; + s8 = peg$parsespaceNL(); + while (s8 !== peg$FAILED) { + s7.push(s8); + s8 = peg$parsespaceNL(); + } + if (s7 !== peg$FAILED) { + s8 = peg$parseaBitwiseAnd(); + if (s8 !== peg$FAILED) { + peg$savedPos = s3; + s4 = peg$c215(s1, s5, s8); + s3 = s4; + } else { + peg$currPos = s3; + s3 = peg$FAILED; + } + } else { + peg$currPos = s3; + s3 = peg$FAILED; + } + } 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) { + peg$savedPos = s0; + s1 = peg$c220(s1, s2); + s0 = s1; + } else { + peg$currPos = s0; + s0 = peg$FAILED; + } + } else { + peg$currPos = s0; + s0 = peg$FAILED; + } + + return s0; + } + + function peg$parseaBitwiseAnd() { + var s0, s1, s2, s3, s4, s5, s6, s7, s8; + + s0 = peg$currPos; + s1 = peg$parseaEquality(); + if (s1 !== peg$FAILED) { + s2 = []; + s3 = peg$currPos; + s4 = []; + s5 = peg$parsespaceNL(); + while (s5 !== peg$FAILED) { + s4.push(s5); + s5 = peg$parsespaceNL(); + } + if (s4 !== peg$FAILED) { + if (input.charCodeAt(peg$currPos) === 38) { + s5 = peg$c164; + peg$currPos++; + } else { + s5 = peg$FAILED; + if (peg$silentFails === 0) { peg$fail(peg$c165); } + } + if (s5 !== peg$FAILED) { + s6 = peg$currPos; + peg$silentFails++; + if (peg$c223.test(input.charAt(peg$currPos))) { + s7 = input.charAt(peg$currPos); + peg$currPos++; + } else { + s7 = peg$FAILED; + if (peg$silentFails === 0) { peg$fail(peg$c224); } + } + peg$silentFails--; + if (s7 === peg$FAILED) { + s6 = void 0; + } else { + peg$currPos = s6; + s6 = peg$FAILED; + } + if (s6 !== peg$FAILED) { + s7 = []; + s8 = peg$parsespaceNL(); + while (s8 !== peg$FAILED) { + s7.push(s8); + s8 = peg$parsespaceNL(); + } + if (s7 !== peg$FAILED) { + s8 = peg$parseaEquality(); + if (s8 !== peg$FAILED) { + peg$savedPos = s3; + s4 = peg$c215(s1, s5, s8); + s3 = s4; + } else { + peg$currPos = s3; + s3 = peg$FAILED; + } + } else { + peg$currPos = s3; + s3 = peg$FAILED; + } + } 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 = []; + s5 = peg$parsespaceNL(); + while (s5 !== peg$FAILED) { + s4.push(s5); + s5 = peg$parsespaceNL(); + } + if (s4 !== peg$FAILED) { + if (input.charCodeAt(peg$currPos) === 38) { + s5 = peg$c164; + peg$currPos++; + } else { + s5 = peg$FAILED; + if (peg$silentFails === 0) { peg$fail(peg$c165); } + } + if (s5 !== peg$FAILED) { + s6 = peg$currPos; + peg$silentFails++; + if (peg$c223.test(input.charAt(peg$currPos))) { + s7 = input.charAt(peg$currPos); + peg$currPos++; + } else { + s7 = peg$FAILED; + if (peg$silentFails === 0) { peg$fail(peg$c224); } + } + peg$silentFails--; + if (s7 === peg$FAILED) { + s6 = void 0; + } else { + peg$currPos = s6; + s6 = peg$FAILED; + } + if (s6 !== peg$FAILED) { + s7 = []; + s8 = peg$parsespaceNL(); + while (s8 !== peg$FAILED) { + s7.push(s8); + s8 = peg$parsespaceNL(); + } + if (s7 !== peg$FAILED) { + s8 = peg$parseaEquality(); + if (s8 !== peg$FAILED) { + peg$savedPos = s3; + s4 = peg$c215(s1, s5, s8); + s3 = s4; + } else { + peg$currPos = s3; + s3 = peg$FAILED; + } + } else { + peg$currPos = s3; + s3 = peg$FAILED; + } + } 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) { + peg$savedPos = s0; + s1 = peg$c220(s1, s2); + s0 = s1; + } else { + peg$currPos = s0; + s0 = peg$FAILED; + } + } else { + peg$currPos = s0; + s0 = peg$FAILED; + } + + return s0; + } + + function peg$parseaEquality() { + var s0, s1, s2, s3, s4, s5, s6, s7; + + s0 = peg$currPos; + s1 = peg$parseaComparison(); + if (s1 !== peg$FAILED) { + s2 = []; + s3 = peg$currPos; + 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$c225) { + s5 = peg$c225; + peg$currPos += 2; + } else { + s5 = peg$FAILED; + if (peg$silentFails === 0) { peg$fail(peg$c226); } + } + if (s5 === peg$FAILED) { + if (input.substr(peg$currPos, 2) === peg$c227) { + s5 = peg$c227; + peg$currPos += 2; + } else { + s5 = peg$FAILED; + if (peg$silentFails === 0) { peg$fail(peg$c228); } + } + } + if (s5 !== peg$FAILED) { + s6 = []; + s7 = peg$parsespaceNL(); + while (s7 !== peg$FAILED) { + s6.push(s7); + s7 = peg$parsespaceNL(); + } + if (s6 !== peg$FAILED) { + s7 = peg$parseaComparison(); + if (s7 !== peg$FAILED) { + peg$savedPos = s3; + s4 = peg$c215(s1, s5, s7); + s3 = s4; + } else { + peg$currPos = s3; + s3 = peg$FAILED; + } + } 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 = []; + s5 = peg$parsespaceNL(); + while (s5 !== peg$FAILED) { + s4.push(s5); + s5 = peg$parsespaceNL(); + } + if (s4 !== peg$FAILED) { + if (input.substr(peg$currPos, 2) === peg$c225) { + s5 = peg$c225; + peg$currPos += 2; + } else { + s5 = peg$FAILED; + if (peg$silentFails === 0) { peg$fail(peg$c226); } + } + if (s5 === peg$FAILED) { + if (input.substr(peg$currPos, 2) === peg$c227) { + s5 = peg$c227; + peg$currPos += 2; + } else { + s5 = peg$FAILED; + if (peg$silentFails === 0) { peg$fail(peg$c228); } + } + } + if (s5 !== peg$FAILED) { + s6 = []; + s7 = peg$parsespaceNL(); + while (s7 !== peg$FAILED) { + s6.push(s7); + s7 = peg$parsespaceNL(); + } + if (s6 !== peg$FAILED) { + s7 = peg$parseaComparison(); + if (s7 !== peg$FAILED) { + peg$savedPos = s3; + s4 = peg$c215(s1, s5, s7); + s3 = s4; + } else { + peg$currPos = s3; + s3 = peg$FAILED; + } + } 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) { + peg$savedPos = s0; + s1 = peg$c220(s1, s2); + s0 = s1; + } else { + peg$currPos = s0; + s0 = peg$FAILED; + } + } else { + peg$currPos = s0; + s0 = peg$FAILED; + } + + return s0; + } + + function peg$parseaComparison() { + var s0, s1, s2, s3, s4, s5, s6, s7, s8; + + s0 = peg$currPos; + s1 = peg$parseaBitwiseShift(); + if (s1 !== peg$FAILED) { + s2 = []; + s3 = peg$currPos; + 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$c229) { + s5 = peg$c229; + peg$currPos += 2; + } else { + s5 = peg$FAILED; + if (peg$silentFails === 0) { peg$fail(peg$c230); } + } + if (s5 === peg$FAILED) { + if (input.substr(peg$currPos, 2) === peg$c231) { + s5 = peg$c231; + peg$currPos += 2; + } else { + s5 = peg$FAILED; + if (peg$silentFails === 0) { peg$fail(peg$c232); } + } + if (s5 === peg$FAILED) { + s5 = peg$currPos; + if (input.charCodeAt(peg$currPos) === 60) { + s6 = peg$c157; + peg$currPos++; + } else { + s6 = peg$FAILED; + if (peg$silentFails === 0) { peg$fail(peg$c158); } + } + if (s6 !== peg$FAILED) { + s7 = peg$currPos; + peg$silentFails++; + if (input.charCodeAt(peg$currPos) === 60) { + s8 = peg$c157; + peg$currPos++; + } else { + s8 = peg$FAILED; + if (peg$silentFails === 0) { peg$fail(peg$c158); } + } + peg$silentFails--; + if (s8 === peg$FAILED) { + s7 = void 0; + } else { + peg$currPos = s7; + s7 = peg$FAILED; + } + if (s7 !== peg$FAILED) { + peg$savedPos = s5; + s6 = peg$c233(s1, s6); + s5 = s6; + } else { + peg$currPos = s5; + s5 = peg$FAILED; + } + } else { + peg$currPos = s5; + s5 = peg$FAILED; + } + if (s5 === peg$FAILED) { + s5 = peg$currPos; + if (input.charCodeAt(peg$currPos) === 62) { + s6 = peg$c159; + peg$currPos++; + } else { + s6 = peg$FAILED; + if (peg$silentFails === 0) { peg$fail(peg$c160); } + } + if (s6 !== peg$FAILED) { + s7 = peg$currPos; + peg$silentFails++; + if (input.charCodeAt(peg$currPos) === 62) { + s8 = peg$c159; + peg$currPos++; + } else { + s8 = peg$FAILED; + if (peg$silentFails === 0) { peg$fail(peg$c160); } + } + peg$silentFails--; + if (s8 === peg$FAILED) { + s7 = void 0; + } else { + peg$currPos = s7; + s7 = peg$FAILED; + } + if (s7 !== peg$FAILED) { + peg$savedPos = s5; + s6 = peg$c233(s1, s6); + s5 = s6; + } else { + peg$currPos = s5; + s5 = peg$FAILED; + } + } else { + peg$currPos = s5; + s5 = peg$FAILED; + } + } + } + } + if (s5 !== peg$FAILED) { + s6 = []; + s7 = peg$parsespaceNL(); + while (s7 !== peg$FAILED) { + s6.push(s7); + s7 = peg$parsespaceNL(); + } + if (s6 !== peg$FAILED) { + s7 = peg$parseaBitwiseShift(); + if (s7 !== peg$FAILED) { + peg$savedPos = s3; + s4 = peg$c215(s1, s5, s7); + s3 = s4; + } else { + peg$currPos = s3; + s3 = peg$FAILED; + } + } 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 = []; + s5 = peg$parsespaceNL(); + while (s5 !== peg$FAILED) { + s4.push(s5); + s5 = peg$parsespaceNL(); + } + if (s4 !== peg$FAILED) { + if (input.substr(peg$currPos, 2) === peg$c229) { + s5 = peg$c229; + peg$currPos += 2; + } else { + s5 = peg$FAILED; + if (peg$silentFails === 0) { peg$fail(peg$c230); } + } + if (s5 === peg$FAILED) { + if (input.substr(peg$currPos, 2) === peg$c231) { + s5 = peg$c231; + peg$currPos += 2; + } else { + s5 = peg$FAILED; + if (peg$silentFails === 0) { peg$fail(peg$c232); } + } + if (s5 === peg$FAILED) { + s5 = peg$currPos; + if (input.charCodeAt(peg$currPos) === 60) { + s6 = peg$c157; + peg$currPos++; + } else { + s6 = peg$FAILED; + if (peg$silentFails === 0) { peg$fail(peg$c158); } + } + if (s6 !== peg$FAILED) { + s7 = peg$currPos; + peg$silentFails++; + if (input.charCodeAt(peg$currPos) === 60) { + s8 = peg$c157; + peg$currPos++; + } else { + s8 = peg$FAILED; + if (peg$silentFails === 0) { peg$fail(peg$c158); } + } + peg$silentFails--; + if (s8 === peg$FAILED) { + s7 = void 0; + } else { + peg$currPos = s7; + s7 = peg$FAILED; + } + if (s7 !== peg$FAILED) { + peg$savedPos = s5; + s6 = peg$c233(s1, s6); + s5 = s6; + } else { + peg$currPos = s5; + s5 = peg$FAILED; + } + } else { + peg$currPos = s5; + s5 = peg$FAILED; + } + if (s5 === peg$FAILED) { + s5 = peg$currPos; + if (input.charCodeAt(peg$currPos) === 62) { + s6 = peg$c159; + peg$currPos++; + } else { + s6 = peg$FAILED; + if (peg$silentFails === 0) { peg$fail(peg$c160); } + } + if (s6 !== peg$FAILED) { + s7 = peg$currPos; + peg$silentFails++; + if (input.charCodeAt(peg$currPos) === 62) { + s8 = peg$c159; + peg$currPos++; + } else { + s8 = peg$FAILED; + if (peg$silentFails === 0) { peg$fail(peg$c160); } + } + peg$silentFails--; + if (s8 === peg$FAILED) { + s7 = void 0; + } else { + peg$currPos = s7; + s7 = peg$FAILED; + } + if (s7 !== peg$FAILED) { + peg$savedPos = s5; + s6 = peg$c233(s1, s6); + s5 = s6; + } else { + peg$currPos = s5; + s5 = peg$FAILED; + } + } else { + peg$currPos = s5; + s5 = peg$FAILED; + } + } + } + } + if (s5 !== peg$FAILED) { + s6 = []; + s7 = peg$parsespaceNL(); + while (s7 !== peg$FAILED) { + s6.push(s7); + s7 = peg$parsespaceNL(); + } + if (s6 !== peg$FAILED) { + s7 = peg$parseaBitwiseShift(); + if (s7 !== peg$FAILED) { + peg$savedPos = s3; + s4 = peg$c215(s1, s5, s7); + s3 = s4; + } else { + peg$currPos = s3; + s3 = peg$FAILED; + } + } 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) { + peg$savedPos = s0; + s1 = peg$c220(s1, s2); + s0 = s1; + } else { + peg$currPos = s0; + s0 = peg$FAILED; + } + } else { + peg$currPos = s0; + s0 = peg$FAILED; + } + + return s0; + } + + function peg$parseaBitwiseShift() { + var s0, s1, s2, s3, s4, s5, s6, s7, s8; + + s0 = peg$currPos; + s1 = peg$parseaAddSubtract(); + if (s1 !== peg$FAILED) { + s2 = []; + s3 = peg$currPos; + 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$c234) { + s5 = peg$c234; + peg$currPos += 2; + } else { + s5 = peg$FAILED; + if (peg$silentFails === 0) { peg$fail(peg$c235); } + } + if (s5 === peg$FAILED) { + if (input.substr(peg$currPos, 2) === peg$c151) { + s5 = peg$c151; + peg$currPos += 2; + } else { + s5 = peg$FAILED; + if (peg$silentFails === 0) { peg$fail(peg$c152); } + } + } + if (s5 !== peg$FAILED) { + s6 = peg$currPos; + peg$silentFails++; + if (input.charCodeAt(peg$currPos) === 61) { + s7 = peg$c72; + peg$currPos++; + } else { + s7 = peg$FAILED; + if (peg$silentFails === 0) { peg$fail(peg$c73); } + } + peg$silentFails--; + if (s7 === peg$FAILED) { + s6 = void 0; + } else { + peg$currPos = s6; + s6 = peg$FAILED; + } + if (s6 !== peg$FAILED) { + s7 = []; + s8 = peg$parsespaceNL(); + while (s8 !== peg$FAILED) { + s7.push(s8); + s8 = peg$parsespaceNL(); + } + if (s7 !== peg$FAILED) { + s8 = peg$parseaAddSubtract(); + if (s8 !== peg$FAILED) { + peg$savedPos = s3; + s4 = peg$c215(s1, s5, s8); + s3 = s4; + } else { + peg$currPos = s3; + s3 = peg$FAILED; + } + } else { + peg$currPos = s3; + s3 = peg$FAILED; + } + } 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 = []; + s5 = peg$parsespaceNL(); + while (s5 !== peg$FAILED) { + s4.push(s5); + s5 = peg$parsespaceNL(); + } + if (s4 !== peg$FAILED) { + if (input.substr(peg$currPos, 2) === peg$c234) { + s5 = peg$c234; + peg$currPos += 2; + } else { + s5 = peg$FAILED; + if (peg$silentFails === 0) { peg$fail(peg$c235); } + } + if (s5 === peg$FAILED) { + if (input.substr(peg$currPos, 2) === peg$c151) { + s5 = peg$c151; + peg$currPos += 2; + } else { + s5 = peg$FAILED; + if (peg$silentFails === 0) { peg$fail(peg$c152); } + } + } + if (s5 !== peg$FAILED) { + s6 = peg$currPos; + peg$silentFails++; + if (input.charCodeAt(peg$currPos) === 61) { + s7 = peg$c72; + peg$currPos++; + } else { + s7 = peg$FAILED; + if (peg$silentFails === 0) { peg$fail(peg$c73); } + } + peg$silentFails--; + if (s7 === peg$FAILED) { + s6 = void 0; + } else { + peg$currPos = s6; + s6 = peg$FAILED; + } + if (s6 !== peg$FAILED) { + s7 = []; + s8 = peg$parsespaceNL(); + while (s8 !== peg$FAILED) { + s7.push(s8); + s8 = peg$parsespaceNL(); + } + if (s7 !== peg$FAILED) { + s8 = peg$parseaAddSubtract(); + if (s8 !== peg$FAILED) { + peg$savedPos = s3; + s4 = peg$c215(s1, s5, s8); + s3 = s4; + } else { + peg$currPos = s3; + s3 = peg$FAILED; + } + } else { + peg$currPos = s3; + s3 = peg$FAILED; + } + } 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) { + peg$savedPos = s0; + s1 = peg$c220(s1, s2); + s0 = s1; + } else { + peg$currPos = s0; + s0 = peg$FAILED; + } + } else { + peg$currPos = s0; + s0 = peg$FAILED; + } + + return s0; + } + + function peg$parseaAddSubtract() { + var s0, s1, s2, s3, s4, s5, s6, s7, s8; + + s0 = peg$currPos; + s1 = peg$parseaMultDivModulo(); + if (s1 !== peg$FAILED) { + s2 = []; + s3 = peg$currPos; + s4 = []; + s5 = peg$parsespaceNL(); + while (s5 !== peg$FAILED) { + s4.push(s5); + s5 = peg$parsespaceNL(); + } + if (s4 !== peg$FAILED) { + if (input.charCodeAt(peg$currPos) === 43) { + s5 = peg$c236; + peg$currPos++; + } else { + s5 = peg$FAILED; + if (peg$silentFails === 0) { peg$fail(peg$c237); } + } + if (s5 === peg$FAILED) { + if (input.charCodeAt(peg$currPos) === 45) { + s5 = peg$c59; + peg$currPos++; + } else { + s5 = peg$FAILED; + if (peg$silentFails === 0) { peg$fail(peg$c60); } + } + } + if (s5 !== peg$FAILED) { + s6 = peg$currPos; + peg$silentFails++; + if (input.charCodeAt(peg$currPos) === 61) { + s7 = peg$c72; + peg$currPos++; + } else { + s7 = peg$FAILED; + if (peg$silentFails === 0) { peg$fail(peg$c73); } + } + peg$silentFails--; + if (s7 === peg$FAILED) { + s6 = void 0; + } else { + peg$currPos = s6; + s6 = peg$FAILED; + } + if (s6 !== peg$FAILED) { + s7 = []; + s8 = peg$parsespaceNL(); + while (s8 !== peg$FAILED) { + s7.push(s8); + s8 = peg$parsespaceNL(); + } + if (s7 !== peg$FAILED) { + s8 = peg$parseaMultDivModulo(); + if (s8 !== peg$FAILED) { + peg$savedPos = s3; + s4 = peg$c215(s1, s5, s8); + s3 = s4; + } else { + peg$currPos = s3; + s3 = peg$FAILED; + } + } else { + peg$currPos = s3; + s3 = peg$FAILED; + } + } 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 = []; + s5 = peg$parsespaceNL(); + while (s5 !== peg$FAILED) { + s4.push(s5); + s5 = peg$parsespaceNL(); + } + if (s4 !== peg$FAILED) { + if (input.charCodeAt(peg$currPos) === 43) { + s5 = peg$c236; + peg$currPos++; + } else { + s5 = peg$FAILED; + if (peg$silentFails === 0) { peg$fail(peg$c237); } + } + if (s5 === peg$FAILED) { + if (input.charCodeAt(peg$currPos) === 45) { + s5 = peg$c59; + peg$currPos++; + } else { + s5 = peg$FAILED; + if (peg$silentFails === 0) { peg$fail(peg$c60); } + } + } + if (s5 !== peg$FAILED) { + s6 = peg$currPos; + peg$silentFails++; + if (input.charCodeAt(peg$currPos) === 61) { + s7 = peg$c72; + peg$currPos++; + } else { + s7 = peg$FAILED; + if (peg$silentFails === 0) { peg$fail(peg$c73); } + } + peg$silentFails--; + if (s7 === peg$FAILED) { + s6 = void 0; + } else { + peg$currPos = s6; + s6 = peg$FAILED; + } + if (s6 !== peg$FAILED) { + s7 = []; + s8 = peg$parsespaceNL(); + while (s8 !== peg$FAILED) { + s7.push(s8); + s8 = peg$parsespaceNL(); + } + if (s7 !== peg$FAILED) { + s8 = peg$parseaMultDivModulo(); + if (s8 !== peg$FAILED) { + peg$savedPos = s3; + s4 = peg$c215(s1, s5, s8); + s3 = s4; + } else { + peg$currPos = s3; + s3 = peg$FAILED; + } + } else { + peg$currPos = s3; + s3 = peg$FAILED; + } + } 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) { + peg$savedPos = s0; + s1 = peg$c220(s1, s2); + s0 = s1; + } else { + peg$currPos = s0; + s0 = peg$FAILED; + } + } else { + peg$currPos = s0; + s0 = peg$FAILED; + } + + return s0; + } + + function peg$parseaMultDivModulo() { + var s0, s1, s2, s3, s4, s5, s6, s7, s8; + + s0 = peg$currPos; + s1 = peg$parseaExponent(); + if (s1 !== peg$FAILED) { + s2 = []; + s3 = peg$currPos; + s4 = []; + s5 = peg$parsespaceNL(); + while (s5 !== peg$FAILED) { + s4.push(s5); + s5 = peg$parsespaceNL(); + } + if (s4 !== peg$FAILED) { + s5 = peg$currPos; + if (input.charCodeAt(peg$currPos) === 42) { + s6 = peg$c94; + peg$currPos++; + } else { + s6 = peg$FAILED; + if (peg$silentFails === 0) { peg$fail(peg$c95); } + } + if (s6 !== peg$FAILED) { + s7 = peg$currPos; + peg$silentFails++; + if (input.charCodeAt(peg$currPos) === 42) { + s8 = peg$c94; + peg$currPos++; + } else { + s8 = peg$FAILED; + if (peg$silentFails === 0) { peg$fail(peg$c95); } + } + peg$silentFails--; + if (s8 === peg$FAILED) { + s7 = void 0; + } else { + peg$currPos = s7; + s7 = peg$FAILED; + } + if (s7 !== peg$FAILED) { + peg$savedPos = s5; + s6 = peg$c233(s1, s6); + s5 = s6; + } else { + peg$currPos = s5; + s5 = peg$FAILED; + } + } else { + peg$currPos = s5; + s5 = peg$FAILED; + } + if (s5 === peg$FAILED) { + if (input.charCodeAt(peg$currPos) === 47) { + s5 = peg$c238; + peg$currPos++; + } else { + s5 = peg$FAILED; + if (peg$silentFails === 0) { peg$fail(peg$c239); } + } + if (s5 === peg$FAILED) { + if (input.charCodeAt(peg$currPos) === 37) { + s5 = peg$c240; + peg$currPos++; + } else { + s5 = peg$FAILED; + if (peg$silentFails === 0) { peg$fail(peg$c241); } + } + } + } + if (s5 !== peg$FAILED) { + s6 = peg$currPos; + peg$silentFails++; + if (input.charCodeAt(peg$currPos) === 61) { + s7 = peg$c72; + peg$currPos++; + } else { + s7 = peg$FAILED; + if (peg$silentFails === 0) { peg$fail(peg$c73); } + } + peg$silentFails--; + if (s7 === peg$FAILED) { + s6 = void 0; + } else { + peg$currPos = s6; + s6 = peg$FAILED; + } + if (s6 !== peg$FAILED) { + s7 = []; + s8 = peg$parsespaceNL(); + while (s8 !== peg$FAILED) { + s7.push(s8); + s8 = peg$parsespaceNL(); + } + if (s7 !== peg$FAILED) { + s8 = peg$parseaExponent(); + if (s8 !== peg$FAILED) { + peg$savedPos = s3; + s4 = peg$c215(s1, s5, s8); + s3 = s4; + } else { + peg$currPos = s3; + s3 = peg$FAILED; + } + } else { + peg$currPos = s3; + s3 = peg$FAILED; + } + } 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 = []; + s5 = peg$parsespaceNL(); + while (s5 !== peg$FAILED) { + s4.push(s5); + s5 = peg$parsespaceNL(); + } + if (s4 !== peg$FAILED) { + s5 = peg$currPos; + if (input.charCodeAt(peg$currPos) === 42) { + s6 = peg$c94; + peg$currPos++; + } else { + s6 = peg$FAILED; + if (peg$silentFails === 0) { peg$fail(peg$c95); } + } + if (s6 !== peg$FAILED) { + s7 = peg$currPos; + peg$silentFails++; + if (input.charCodeAt(peg$currPos) === 42) { + s8 = peg$c94; + peg$currPos++; + } else { + s8 = peg$FAILED; + if (peg$silentFails === 0) { peg$fail(peg$c95); } + } + peg$silentFails--; + if (s8 === peg$FAILED) { + s7 = void 0; + } else { + peg$currPos = s7; + s7 = peg$FAILED; + } + if (s7 !== peg$FAILED) { + peg$savedPos = s5; + s6 = peg$c233(s1, s6); + s5 = s6; + } else { + peg$currPos = s5; + s5 = peg$FAILED; + } + } else { + peg$currPos = s5; + s5 = peg$FAILED; + } + if (s5 === peg$FAILED) { + if (input.charCodeAt(peg$currPos) === 47) { + s5 = peg$c238; + peg$currPos++; + } else { + s5 = peg$FAILED; + if (peg$silentFails === 0) { peg$fail(peg$c239); } + } + if (s5 === peg$FAILED) { + if (input.charCodeAt(peg$currPos) === 37) { + s5 = peg$c240; + peg$currPos++; + } else { + s5 = peg$FAILED; + if (peg$silentFails === 0) { peg$fail(peg$c241); } + } + } + } + if (s5 !== peg$FAILED) { + s6 = peg$currPos; + peg$silentFails++; + if (input.charCodeAt(peg$currPos) === 61) { + s7 = peg$c72; + peg$currPos++; + } else { + s7 = peg$FAILED; + if (peg$silentFails === 0) { peg$fail(peg$c73); } + } + peg$silentFails--; + if (s7 === peg$FAILED) { + s6 = void 0; + } else { + peg$currPos = s6; + s6 = peg$FAILED; + } + if (s6 !== peg$FAILED) { + s7 = []; + s8 = peg$parsespaceNL(); + while (s8 !== peg$FAILED) { + s7.push(s8); + s8 = peg$parsespaceNL(); + } + if (s7 !== peg$FAILED) { + s8 = peg$parseaExponent(); + if (s8 !== peg$FAILED) { + peg$savedPos = s3; + s4 = peg$c215(s1, s5, s8); + s3 = s4; + } else { + peg$currPos = s3; + s3 = peg$FAILED; + } + } else { + peg$currPos = s3; + s3 = peg$FAILED; + } + } 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) { + peg$savedPos = s0; + s1 = peg$c220(s1, s2); + s0 = s1; + } else { + peg$currPos = s0; + s0 = peg$FAILED; + } + } else { + peg$currPos = s0; + s0 = peg$FAILED; + } + + return s0; + } + + function peg$parseaExponent() { + var s0, s1, s2, s3, s4, s5, s6, s7; + + s0 = peg$currPos; + s1 = peg$parseaNegation(); + if (s1 !== peg$FAILED) { + s2 = []; + s3 = peg$currPos; + 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$c242) { + s5 = peg$c242; + peg$currPos += 2; + } else { + s5 = peg$FAILED; + if (peg$silentFails === 0) { peg$fail(peg$c243); } + } + if (s5 !== peg$FAILED) { + s6 = []; + s7 = peg$parsespaceNL(); + while (s7 !== peg$FAILED) { + s6.push(s7); + s7 = peg$parsespaceNL(); + } + if (s6 !== peg$FAILED) { + s7 = peg$parseaNegation(); + if (s7 !== peg$FAILED) { + peg$savedPos = s3; + s4 = peg$c215(s1, s5, s7); + s3 = s4; + } else { + peg$currPos = s3; + s3 = peg$FAILED; + } + } 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 = []; + s5 = peg$parsespaceNL(); + while (s5 !== peg$FAILED) { + s4.push(s5); + s5 = peg$parsespaceNL(); + } + if (s4 !== peg$FAILED) { + if (input.substr(peg$currPos, 2) === peg$c242) { + s5 = peg$c242; + peg$currPos += 2; + } else { + s5 = peg$FAILED; + if (peg$silentFails === 0) { peg$fail(peg$c243); } + } + if (s5 !== peg$FAILED) { + s6 = []; + s7 = peg$parsespaceNL(); + while (s7 !== peg$FAILED) { + s6.push(s7); + s7 = peg$parsespaceNL(); + } + if (s6 !== peg$FAILED) { + s7 = peg$parseaNegation(); + if (s7 !== peg$FAILED) { + peg$savedPos = s3; + s4 = peg$c215(s1, s5, s7); + s3 = s4; + } else { + peg$currPos = s3; + s3 = peg$FAILED; + } + } 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) { + peg$savedPos = s0; + s1 = peg$c220(s1, s2); + s0 = s1; + } else { + peg$currPos = s0; + s0 = peg$FAILED; + } + } else { + peg$currPos = s0; + s0 = peg$FAILED; + } + + return s0; + } + + function peg$parseaNegation() { + var s0, s1, s2, s3; + + s0 = peg$currPos; + if (input.charCodeAt(peg$currPos) === 33) { + s1 = peg$c244; + peg$currPos++; + } else { + s1 = peg$FAILED; + if (peg$silentFails === 0) { peg$fail(peg$c245); } + } + if (s1 === peg$FAILED) { + if (input.charCodeAt(peg$currPos) === 126) { + s1 = peg$c246; + peg$currPos++; + } else { + s1 = peg$FAILED; + if (peg$silentFails === 0) { peg$fail(peg$c247); } + } + } + if (s1 !== peg$FAILED) { + s2 = []; + s3 = peg$parsespaceNL(); + while (s3 !== peg$FAILED) { + s2.push(s3); + s3 = peg$parsespaceNL(); + } + if (s2 !== peg$FAILED) { + s3 = peg$parseaNegation(); + if (s3 !== peg$FAILED) { + peg$savedPos = s0; + s1 = peg$c248(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; + } + if (s0 === peg$FAILED) { + s0 = peg$currPos; + s1 = peg$parseaUnary(); + if (s1 !== peg$FAILED) { + peg$savedPos = s0; + s1 = peg$c209(s1); + } + s0 = s1; + } + + return s0; + } + + function peg$parseaUnary() { + var s0, s1, s2, s3, s4; + + s0 = peg$currPos; + s1 = peg$currPos; + if (input.charCodeAt(peg$currPos) === 43) { + s2 = peg$c236; + peg$currPos++; + } else { + s2 = peg$FAILED; + if (peg$silentFails === 0) { peg$fail(peg$c237); } + } + if (s2 !== peg$FAILED) { + s3 = peg$currPos; + peg$silentFails++; + if (peg$c249.test(input.charAt(peg$currPos))) { + s4 = input.charAt(peg$currPos); + peg$currPos++; + } else { + s4 = peg$FAILED; + if (peg$silentFails === 0) { peg$fail(peg$c250); } + } + peg$silentFails--; + if (s4 === peg$FAILED) { + s3 = void 0; + } else { + peg$currPos = s3; + s3 = peg$FAILED; + } + if (s3 !== peg$FAILED) { + peg$savedPos = s1; + s2 = peg$c251(s2); + s1 = s2; + } else { + peg$currPos = s1; + s1 = peg$FAILED; + } + } else { + peg$currPos = s1; + s1 = peg$FAILED; + } + if (s1 === peg$FAILED) { + s1 = peg$currPos; + if (input.charCodeAt(peg$currPos) === 45) { + s2 = peg$c59; + peg$currPos++; + } else { + s2 = peg$FAILED; + if (peg$silentFails === 0) { peg$fail(peg$c60); } + } + if (s2 !== peg$FAILED) { + s3 = peg$currPos; + peg$silentFails++; + if (peg$c252.test(input.charAt(peg$currPos))) { + s4 = input.charAt(peg$currPos); + peg$currPos++; + } else { + s4 = peg$FAILED; + if (peg$silentFails === 0) { peg$fail(peg$c253); } + } + peg$silentFails--; + if (s4 === peg$FAILED) { + s3 = void 0; + } else { + peg$currPos = s3; + s3 = peg$FAILED; + } + if (s3 !== peg$FAILED) { + peg$savedPos = s1; + s2 = peg$c251(s2); + s1 = s2; + } else { + peg$currPos = s1; + s1 = peg$FAILED; + } + } else { + peg$currPos = s1; + s1 = peg$FAILED; + } + } + if (s1 !== peg$FAILED) { + s2 = []; + s3 = peg$parsespaceNL(); + while (s3 !== peg$FAILED) { + s2.push(s3); + s3 = peg$parsespaceNL(); + } + if (s2 !== peg$FAILED) { + s3 = peg$parseaUnary(); + if (s3 !== peg$FAILED) { + peg$savedPos = s0; + s1 = peg$c248(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; + } + if (s0 === peg$FAILED) { + s0 = peg$currPos; + s1 = peg$parseaPreIncDec(); + if (s1 !== peg$FAILED) { + peg$savedPos = s0; + s1 = peg$c209(s1); + } + s0 = s1; + } + + return s0; + } + + function peg$parseaPreIncDec() { + var s0, s1, s2, s3; + + s0 = peg$currPos; + if (input.substr(peg$currPos, 2) === peg$c254) { + s1 = peg$c254; + peg$currPos += 2; + } else { + s1 = peg$FAILED; + if (peg$silentFails === 0) { peg$fail(peg$c255); } + } + if (s1 === peg$FAILED) { + if (input.substr(peg$currPos, 2) === peg$c256) { + s1 = peg$c256; + peg$currPos += 2; + } else { + s1 = peg$FAILED; + if (peg$silentFails === 0) { peg$fail(peg$c257); } + } + } + if (s1 !== peg$FAILED) { + s2 = []; + s3 = peg$parsespaceNL(); + while (s3 !== peg$FAILED) { + s2.push(s3); + s3 = peg$parsespaceNL(); + } + if (s2 !== peg$FAILED) { + s3 = peg$parseaPreIncDec(); + if (s3 !== peg$FAILED) { + peg$savedPos = s0; + s1 = peg$c258(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; + } + if (s0 === peg$FAILED) { + s0 = peg$currPos; + s1 = peg$parseaPostIncDec(); + if (s1 !== peg$FAILED) { + peg$savedPos = s0; + s1 = peg$c209(s1); + } + s0 = s1; + } + + return s0; + } + + function peg$parseaPostIncDec() { + var s0, s1, s2, s3, s4, s5; + + s0 = peg$currPos; + s1 = peg$parseaMemberExpr(); + if (s1 !== peg$FAILED) { + s2 = []; + s3 = peg$currPos; + 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$c254) { + s5 = peg$c254; + peg$currPos += 2; + } else { + s5 = peg$FAILED; + if (peg$silentFails === 0) { peg$fail(peg$c255); } + } + if (s5 === peg$FAILED) { + if (input.substr(peg$currPos, 2) === peg$c256) { + s5 = peg$c256; + peg$currPos += 2; + } else { + s5 = peg$FAILED; + if (peg$silentFails === 0) { peg$fail(peg$c257); } + } + } + if (s5 !== peg$FAILED) { + peg$savedPos = s3; + s4 = peg$c259(s1, s5); + s3 = s4; + } else { + peg$currPos = s3; + s3 = peg$FAILED; + } + } else { + peg$currPos = s3; + s3 = peg$FAILED; + } + if (s3 !== peg$FAILED) { + while (s3 !== peg$FAILED) { + s2.push(s3); + s3 = peg$currPos; + 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$c254) { + s5 = peg$c254; + peg$currPos += 2; + } else { + s5 = peg$FAILED; + if (peg$silentFails === 0) { peg$fail(peg$c255); } + } + if (s5 === peg$FAILED) { + if (input.substr(peg$currPos, 2) === peg$c256) { + s5 = peg$c256; + peg$currPos += 2; + } else { + s5 = peg$FAILED; + if (peg$silentFails === 0) { peg$fail(peg$c257); } + } + } + if (s5 !== peg$FAILED) { + peg$savedPos = s3; + s4 = peg$c259(s1, s5); + s3 = s4; + } else { + peg$currPos = s3; + s3 = peg$FAILED; + } + } else { + peg$currPos = s3; + s3 = peg$FAILED; + } + } + } else { + s2 = peg$FAILED; + } + if (s2 !== peg$FAILED) { + peg$savedPos = s0; + s1 = peg$c260(s1, 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$parseaMemberExpr(); + if (s1 !== peg$FAILED) { + peg$savedPos = s0; + s1 = peg$c209(s1); + } + s0 = s1; + } + + return s0; + } + + function peg$parseaMemberExpr() { + var s0, s1, s2, s3, s4, s5, s6, s7; + + s0 = peg$currPos; + s1 = peg$parseaParenExpr(); + if (s1 !== peg$FAILED) { + s2 = []; + s3 = peg$currPos; + s4 = []; + s5 = peg$parsespaceNL(); + while (s5 !== peg$FAILED) { + s4.push(s5); + s5 = peg$parsespaceNL(); + } + if (s4 !== peg$FAILED) { + if (input.charCodeAt(peg$currPos) === 91) { + s5 = peg$c79; + peg$currPos++; + } else { + s5 = peg$FAILED; + if (peg$silentFails === 0) { peg$fail(peg$c80); } + } + if (s5 !== peg$FAILED) { + s6 = peg$parsearithmetic(); + if (s6 !== peg$FAILED) { + if (input.charCodeAt(peg$currPos) === 93) { + s7 = peg$c99; + peg$currPos++; + } else { + s7 = peg$FAILED; + if (peg$silentFails === 0) { peg$fail(peg$c100); } + } + if (s7 !== peg$FAILED) { + peg$savedPos = s3; + s4 = peg$c261(s1, s6); + s3 = s4; + } else { + peg$currPos = s3; + s3 = peg$FAILED; + } + } 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 = []; + s5 = peg$parsespaceNL(); + while (s5 !== peg$FAILED) { + s4.push(s5); + s5 = peg$parsespaceNL(); + } + if (s4 !== peg$FAILED) { + if (input.charCodeAt(peg$currPos) === 91) { + s5 = peg$c79; + peg$currPos++; + } else { + s5 = peg$FAILED; + if (peg$silentFails === 0) { peg$fail(peg$c80); } + } + if (s5 !== peg$FAILED) { + s6 = peg$parsearithmetic(); + if (s6 !== peg$FAILED) { + if (input.charCodeAt(peg$currPos) === 93) { + s7 = peg$c99; + peg$currPos++; + } else { + s7 = peg$FAILED; + if (peg$silentFails === 0) { peg$fail(peg$c100); } + } + if (s7 !== peg$FAILED) { + peg$savedPos = s3; + s4 = peg$c261(s1, s6); + s3 = s4; + } else { + peg$currPos = s3; + s3 = peg$FAILED; + } + } 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) { + peg$savedPos = s0; + s1 = peg$c262(s1, s2); + s0 = s1; + } else { + peg$currPos = s0; + s0 = peg$FAILED; + } + } else { + peg$currPos = s0; + s0 = peg$FAILED; + } + + return s0; + } + + function peg$parseaParenExpr() { + var s0, s1, s2, s3, s4, s5; + + s0 = peg$currPos; + if (input.charCodeAt(peg$currPos) === 40) { + s1 = peg$c15; + peg$currPos++; + } else { + s1 = peg$FAILED; + if (peg$silentFails === 0) { peg$fail(peg$c16); } + } + if (s1 !== peg$FAILED) { + s2 = []; + s3 = peg$parsespaceNL(); + while (s3 !== peg$FAILED) { + s2.push(s3); + s3 = peg$parsespaceNL(); + } + if (s2 !== peg$FAILED) { + s3 = peg$parsearithmetic(); + if (s3 !== peg$FAILED) { + s4 = []; + s5 = peg$parsespaceNL(); + while (s5 !== peg$FAILED) { + s4.push(s5); + s5 = peg$parsespaceNL(); + } + if (s4 !== peg$FAILED) { + if (input.charCodeAt(peg$currPos) === 41) { + s5 = peg$c17; + peg$currPos++; + } else { + s5 = peg$FAILED; + if (peg$silentFails === 0) { peg$fail(peg$c18); } + } + if (s5 !== peg$FAILED) { + peg$savedPos = s0; + s1 = peg$c263(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; + } + if (s0 === peg$FAILED) { + s0 = peg$currPos; + s1 = peg$parseaLiteral(); + if (s1 !== peg$FAILED) { + peg$savedPos = s0; + s1 = peg$c209(s1); + } + s0 = s1; + } + + return s0; + } + + function peg$parseaBareword() { + var s0, s1, s2, s3; + + peg$silentFails++; + s0 = peg$currPos; + s1 = peg$currPos; + peg$silentFails++; + if (input.charCodeAt(peg$currPos) === 35) { + s2 = peg$c85; + peg$currPos++; + } else { + s2 = peg$FAILED; + if (peg$silentFails === 0) { peg$fail(peg$c86); } + } + peg$silentFails--; + if (s2 === peg$FAILED) { + s1 = void 0; + } else { + peg$currPos = s1; + s1 = peg$FAILED; + } + if (s1 !== peg$FAILED) { + s2 = []; + s3 = peg$parseaBarewordChar(); + if (s3 !== peg$FAILED) { + while (s3 !== peg$FAILED) { + s2.push(s3); + s3 = peg$parseaBarewordChar(); + } + } else { + s2 = peg$FAILED; + } + if (s2 !== peg$FAILED) { + peg$savedPos = s0; + s1 = peg$c265(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$c264); } + } + + return s0; + } + + function peg$parseaBarewordChar() { + var s0, s1, s2; + + s0 = peg$currPos; + if (input.charCodeAt(peg$currPos) === 92) { + s1 = peg$c88; + peg$currPos++; + } else { + s1 = peg$FAILED; + if (peg$silentFails === 0) { peg$fail(peg$c89); } + } + if (s1 !== peg$FAILED) { + s2 = peg$parseaBarewordMeta(); + if (s2 !== peg$FAILED) { + peg$savedPos = s0; + s1 = peg$c90(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$parseaBarewordMeta(); + 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$c91); } + } + if (s2 !== peg$FAILED) { + peg$savedPos = s0; + s1 = peg$c90(s2); + s0 = s1; + } else { + peg$currPos = s0; + s0 = peg$FAILED; + } + } else { + peg$currPos = s0; + s0 = peg$FAILED; + } + } + + return s0; + } + + function peg$parseaBarewordMeta() { + var s0; + + if (peg$c266.test(input.charAt(peg$currPos))) { + s0 = input.charAt(peg$currPos); + peg$currPos++; + } else { + s0 = peg$FAILED; + if (peg$silentFails === 0) { peg$fail(peg$c267); } + } + + return s0; + } + + function peg$parseaConcatenation() { + var s0, s1, s2; + + peg$silentFails++; + s0 = peg$currPos; + s1 = []; + s2 = peg$parseaBareword(); + if (s2 === peg$FAILED) { + s2 = peg$parseenvironmentVariable(); + if (s2 === peg$FAILED) { + s2 = peg$parsevariableSubstitution(); + if (s2 === peg$FAILED) { + s2 = peg$parsearithmeticSubstitution(); + 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$parseaBareword(); + if (s2 === peg$FAILED) { + s2 = peg$parseenvironmentVariable(); + if (s2 === peg$FAILED) { + s2 = peg$parsevariableSubstitution(); + if (s2 === peg$FAILED) { + s2 = peg$parsearithmeticSubstitution(); + 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$c268(s1); + } + s0 = s1; + peg$silentFails--; + if (s0 === peg$FAILED) { + s1 = peg$FAILED; + if (peg$silentFails === 0) { peg$fail(peg$c82); } + } + + return s0; + } + + function peg$parseaLiteral() { + var s0, s1; + + s0 = peg$currPos; + s1 = peg$parseaNumber(); + if (s1 !== peg$FAILED) { + peg$savedPos = s0; + s1 = peg$c269(s1); + } + s0 = s1; + if (s0 === peg$FAILED) { + s0 = peg$currPos; + s1 = peg$parseaConcatenation(); + if (s1 !== peg$FAILED) { + peg$savedPos = s0; + s1 = peg$c269(s1); + } + s0 = s1; + } + + return s0; + } + + function peg$parseaNumber() { + var s0, s1, s2, s3, s4; + + s0 = peg$currPos; + if (input.charCodeAt(peg$currPos) === 48) { + s1 = peg$c270; + peg$currPos++; + } else { + s1 = peg$FAILED; + if (peg$silentFails === 0) { peg$fail(peg$c271); } + } + if (s1 !== peg$FAILED) { + if (peg$c272.test(input.charAt(peg$currPos))) { + s2 = input.charAt(peg$currPos); + peg$currPos++; + } else { + s2 = peg$FAILED; + if (peg$silentFails === 0) { peg$fail(peg$c273); } + } + if (s2 !== peg$FAILED) { + s3 = []; + if (peg$c274.test(input.charAt(peg$currPos))) { + s4 = input.charAt(peg$currPos); + peg$currPos++; + } else { + s4 = peg$FAILED; + if (peg$silentFails === 0) { peg$fail(peg$c275); } + } + if (s4 !== peg$FAILED) { + while (s4 !== peg$FAILED) { + s3.push(s4); + if (peg$c274.test(input.charAt(peg$currPos))) { + s4 = input.charAt(peg$currPos); + peg$currPos++; + } else { + s4 = peg$FAILED; + if (peg$silentFails === 0) { peg$fail(peg$c275); } + } + } + } else { + s3 = peg$FAILED; + } + if (s3 !== peg$FAILED) { + peg$savedPos = s0; + s1 = peg$c276(s3); + s0 = s1; + } else { + peg$currPos = s0; + s0 = peg$FAILED; + } + } else { + peg$currPos = s0; + s0 = peg$FAILED; + } + } else { + peg$currPos = s0; + s0 = peg$FAILED; + } + if (s0 === peg$FAILED) { + s0 = peg$currPos; + s1 = []; + if (peg$c161.test(input.charAt(peg$currPos))) { + s2 = input.charAt(peg$currPos); + peg$currPos++; + } else { + s2 = peg$FAILED; + if (peg$silentFails === 0) { peg$fail(peg$c162); } + } + if (s2 !== peg$FAILED) { + while (s2 !== peg$FAILED) { + s1.push(s2); + if (peg$c161.test(input.charAt(peg$currPos))) { + s2 = input.charAt(peg$currPos); + peg$currPos++; + } else { + s2 = peg$FAILED; + if (peg$silentFails === 0) { peg$fail(peg$c162); } + } + } + } else { + s1 = peg$FAILED; + } + if (s1 !== peg$FAILED) { + if (input.charCodeAt(peg$currPos) === 35) { + s2 = peg$c85; + peg$currPos++; + } else { + s2 = peg$FAILED; + if (peg$silentFails === 0) { peg$fail(peg$c86); } + } + if (s2 !== peg$FAILED) { + s3 = []; + if (peg$c277.test(input.charAt(peg$currPos))) { + s4 = input.charAt(peg$currPos); + peg$currPos++; + } else { + s4 = peg$FAILED; + if (peg$silentFails === 0) { peg$fail(peg$c278); } + } + if (s4 !== peg$FAILED) { + while (s4 !== peg$FAILED) { + s3.push(s4); + if (peg$c277.test(input.charAt(peg$currPos))) { + s4 = input.charAt(peg$currPos); + peg$currPos++; + } else { + s4 = peg$FAILED; + if (peg$silentFails === 0) { peg$fail(peg$c278); } + } + } + } else { + s3 = peg$FAILED; + } + if (s3 !== peg$FAILED) { + peg$savedPos = s0; + s1 = peg$c279(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; + } + if (s0 === peg$FAILED) { + s0 = peg$currPos; + if (input.charCodeAt(peg$currPos) === 48) { + s1 = peg$c270; + peg$currPos++; + } else { + s1 = peg$FAILED; + if (peg$silentFails === 0) { peg$fail(peg$c271); } + } + if (s1 !== peg$FAILED) { + s2 = []; + if (peg$c280.test(input.charAt(peg$currPos))) { + s3 = input.charAt(peg$currPos); + peg$currPos++; + } else { + s3 = peg$FAILED; + if (peg$silentFails === 0) { peg$fail(peg$c281); } + } + if (s3 !== peg$FAILED) { + while (s3 !== peg$FAILED) { + s2.push(s3); + if (peg$c280.test(input.charAt(peg$currPos))) { + s3 = input.charAt(peg$currPos); + peg$currPos++; + } else { + s3 = peg$FAILED; + if (peg$silentFails === 0) { peg$fail(peg$c281); } + } + } + } else { + s2 = peg$FAILED; + } + if (s2 !== peg$FAILED) { + peg$savedPos = s0; + s1 = peg$c282(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 = []; + if (peg$c161.test(input.charAt(peg$currPos))) { + s2 = input.charAt(peg$currPos); + peg$currPos++; + } else { + s2 = peg$FAILED; + if (peg$silentFails === 0) { peg$fail(peg$c162); } + } + if (s2 !== peg$FAILED) { + while (s2 !== peg$FAILED) { + s1.push(s2); + if (peg$c161.test(input.charAt(peg$currPos))) { + s2 = input.charAt(peg$currPos); + peg$currPos++; + } else { + s2 = peg$FAILED; + if (peg$silentFails === 0) { peg$fail(peg$c162); } + } + } + } else { + s1 = peg$FAILED; + } + if (s1 !== peg$FAILED) { + peg$savedPos = s0; + s1 = peg$c283(s1); + } + s0 = s1; + } + } + } + + 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$c112; + peg$currPos++; + } else { + s2 = peg$FAILED; + if (peg$silentFails === 0) { peg$fail(peg$c113); } + } + if (s2 === peg$FAILED) { + if (input.charCodeAt(peg$currPos) === 39) { + s2 = peg$c107; + peg$currPos++; + } else { + s2 = peg$FAILED; + if (peg$silentFails === 0) { peg$fail(peg$c108); } + } + if (s2 === peg$FAILED) { + if (input.charCodeAt(peg$currPos) === 96) { + s2 = peg$c118; + peg$currPos++; + } else { + s2 = peg$FAILED; + if (peg$silentFails === 0) { peg$fail(peg$c119); } + } + if (s2 === peg$FAILED) { + if (input.substr(peg$currPos, 2) === peg$c129) { + s2 = peg$c129; + peg$currPos += 2; + } else { + s2 = peg$FAILED; + if (peg$silentFails === 0) { peg$fail(peg$c130); } + } + if (s2 === peg$FAILED) { + if (input.substr(peg$currPos, 3) === peg$c132) { + s2 = peg$c132; + peg$currPos += 3; + } else { + s2 = peg$FAILED; + if (peg$silentFails === 0) { peg$fail(peg$c133); } + } + if (s2 === peg$FAILED) { + if (input.substr(peg$currPos, 2) === peg$c124) { + s2 = peg$c124; + peg$currPos += 2; + } else { + s2 = peg$FAILED; + if (peg$silentFails === 0) { peg$fail(peg$c125); } + } + } + } + } + } + } + } + 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$c91); } + } + 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$c91); } + } + } + 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$c91); } + } + 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) { @@ -4081,6 +7567,13 @@ var parser=(function() { pieces: result } } + function buildTree(head, tail, createNode) { + var result = head; + for (var i = 0, l = tail.length; i < l; i++) { + result = createNode(result, tail[i]); + } + return result; + } peg$result = peg$startRuleFunction();