How to use fails method in pytest-benchmark

Best Python code snippet using pytest-benchmark

parser.js

Source:parser.js Github

copy

Full Screen

1module.exports = parse2function parse(input, opts) {3 // Wrap parser.parse to allow specifying the start rule4 // as a shorthand option5 if (!opts) {6 opts = {}7 }8 else if (typeof opts == 'string') {9 opts = { startRule: opts }10 }11 return parser.parse(input, opts)12}13var parser=(function() {14 "use strict";15 /*16 * Generated by PEG.js 0.9.0.17 *18 * http://pegjs.org/19 */20 function peg$subclass(child, parent) {21 function ctor() { this.constructor = child; }22 ctor.prototype = parent.prototype;23 child.prototype = new ctor();24 }25 function peg$SyntaxError(message, expected, found, location) {26 this.message = message;27 this.expected = expected;28 this.found = found;29 this.location = location;30 this.name = "SyntaxError";31 if (typeof Error.captureStackTrace === "function") {32 Error.captureStackTrace(this, peg$SyntaxError);33 }34 }35 peg$subclass(peg$SyntaxError, Error);36 function peg$parse(input) {37 var options = arguments.length > 1 ? arguments[1] : {},38 parser = this,39 peg$FAILED = {},40 peg$startRuleFunctions = { script: peg$parsescript, command: peg$parsecommand, argument: peg$parseargument, continuationStart: peg$parsecontinuationStart },41 peg$startRuleFunction = peg$parsescript,42 peg$c0 = function(statements) {43 return statements || []44 },45 peg$c1 = function(head, tail, last) {46 var statements = [head]47 var prev = head48 map(tail, function (spaceOpSpaceCmd, i, cmds) {49 setOperator(spaceOpSpaceCmd[0], prev)50 statements.push(prev = spaceOpSpaceCmd[2])51 })52 if (last) {53 if (!prev) { debugger }54 setOperator(last, prev)55 }56 return statements57 function setOperator(operator, command) {58 while (command.next) {59 command = command.next60 }61 command.control = operator62 }63 },64 peg$c2 = function(statement, next) {65 if (typeof next !== 'undefined' && next) {66 next = next[1]67 statement.control = next[0]68 statement.next = next[1]69 } else {70 statement.control = ';'71 statement.next = null72 }73 return statement74 },75 peg$c3 = "&&",76 peg$c4 = { type: "literal", value: "&&", description: "\"&&\"" },77 peg$c5 = "||",78 peg$c6 = { type: "literal", value: "||", description: "\"||\"" },79 peg$c7 = function(operator, statement) {80 return [operator, statement]81 },82 peg$c8 = { type: "other", description: "a subshell" },83 peg$c9 = "(",84 peg$c10 = { type: "literal", value: "(", description: "\"(\"" },85 peg$c11 = ")",86 peg$c12 = { type: "literal", value: ")", description: "\")\"" },87 peg$c13 = function(statements) {88 return {89 type: 'subshell',90 statements: statements,91 }92 },93 peg$c14 = { type: "other", description: "a single command" },94 peg$c15 = function(pre, name, post, pipe) {95 var command = {96 type: 'command',97 command: name,98 args: [],99 redirects: [],100 env: {},101 control: ';',102 next: null,103 }104 map(pre, first).concat(map(post, second)).forEach(function (token) {105 if (!token || !token.type) return106 switch (token.type) {107 case 'moveFd':108 case 'duplicateFd':109 case 'redirectFd':110 return command.redirects.push(token)111 case 'variableAssignment':112 return command.env[token.name] = token.value113 default:114 command.args.push(token)115 }116 })117 if (pipe) {118 command.redirects.push(pipe[1])119 }120 return command121 },122 peg$c16 = function(test) {123 return test124 },125 peg$c17 = { type: "other", description: "an if/elif/else statement" },126 peg$c18 = "if",127 peg$c19 = { type: "literal", value: "if", description: "\"if\"" },128 peg$c20 = "then",129 peg$c21 = { type: "literal", value: "then", description: "\"then\"" },130 peg$c22 = "else",131 peg$c23 = { type: "literal", value: "else", description: "\"else\"" },132 peg$c24 = "fi",133 peg$c25 = { type: "literal", value: "fi", description: "\"fi\"" },134 peg$c26 = function(test, body, elifBlocks, elseBody) {135 return {136 type: 'ifElse',137 test: test,138 body: body,139 elifBlocks: elifBlocks.length ? elifBlocks : null,140 elseBody: elseBody ? elseBody[1] : null,141 }142 },143 peg$c27 = "elif",144 peg$c28 = { type: "literal", value: "elif", description: "\"elif\"" },145 peg$c29 = function(test, body) {146 return {147 type: 'ifElse',148 test: test,149 body: body150 }151 },152 peg$c30 = { type: "other", description: "a while/until loop" },153 peg$c31 = "while",154 peg$c32 = { type: "literal", value: "while", description: "\"while\"" },155 peg$c33 = "until",156 peg$c34 = { type: "literal", value: "until", description: "\"until\"" },157 peg$c35 = "do",158 peg$c36 = { type: "literal", value: "do", description: "\"do\"" },159 peg$c37 = "done",160 peg$c38 = { type: "literal", value: "done", description: "\"done\"" },161 peg$c39 = function(kind, test, body) {162 return {163 type: kind + 'Loop',164 test: test,165 body: body166 }167 },168 peg$c40 = { type: "other", description: "a for loop" },169 peg$c41 = "for",170 peg$c42 = { type: "literal", value: "for", description: "\"for\"" },171 peg$c43 = "in",172 peg$c44 = { type: "literal", value: "in", description: "\"in\"" },173 peg$c45 = ";",174 peg$c46 = { type: "literal", value: ";", description: "\";\"" },175 peg$c47 = "\n",176 peg$c48 = { type: "literal", value: "\n", description: "\"\\n\"" },177 peg$c49 = function(loopVar, subjects, body) {178 return {179 type: 'forLoop',180 loopVariable: loopVar,181 subjects: subjects[1].map(second),182 body: body183 }184 },185 peg$c50 = { type: "other", description: "time builtin" },186 peg$c51 = "time",187 peg$c52 = { type: "literal", value: "time", description: "\"time\"" },188 peg$c53 = "-",189 peg$c54 = { type: "literal", value: "-", description: "\"-\"" },190 peg$c55 = /^[a-z]/,191 peg$c56 = { type: "class", value: "[a-z]", description: "[a-z]" },192 peg$c57 = function(flags, statements) {193 return {194 type: 'time',195 flags: flags,196 command: statements197 }198 },199 peg$c58 = { type: "other", description: "declare builtin" },200 peg$c59 = "declare",201 peg$c60 = { type: "literal", value: "declare", description: "\"declare\"" },202 peg$c61 = "typeset",203 peg$c62 = { type: "literal", value: "typeset", description: "\"typeset\"" },204 peg$c63 = /^[^\n]/,205 peg$c64 = { type: "class", value: "[^\\n]", description: "[^\\n]" },206 peg$c65 = { type: "other", description: "a variable assignment" },207 peg$c66 = "=",208 peg$c67 = { type: "literal", value: "=", description: "\"=\"" },209 peg$c68 = function(name, value) {210 return {type: 'variableAssignment', name: name, value: value}211 },212 peg$c69 = { type: "other", description: "command name" },213 peg$c70 = function(name) {214 return name215 },216 peg$c71 = "[[",217 peg$c72 = { type: "literal", value: "[[", description: "\"[[\"" },218 peg$c73 = "[",219 peg$c74 = { type: "literal", value: "[", description: "\"[\"" },220 peg$c75 = { type: "other", description: "command argument" },221 peg$c76 = { type: "other", description: "concatenation of strings and/or variables" },222 peg$c77 = function(pieces) {223 return flattenConcatenation(pieces)224 },225 peg$c78 = { type: "other", description: "bareword" },226 peg$c79 = "#",227 peg$c80 = { type: "literal", value: "#", description: "\"#\"" },228 peg$c81 = function(cs) { return literal(cs) },229 peg$c82 = "\\",230 peg$c83 = { type: "literal", value: "\\", description: "\"\\\\\"" },231 peg$c84 = function(chr) { return chr },232 peg$c85 = { type: "any", description: "any character" },233 peg$c86 = /^[$"';&<>\n()[*?|` ]/,234 peg$c87 = { type: "class", value: "[$\"';&<>\\n()\\[*?|` ]", description: "[$\"';&<>\\n()\\[*?|` ]" },235 peg$c88 = "*",236 peg$c89 = { type: "literal", value: "*", description: "\"*\"" },237 peg$c90 = "?",238 peg$c91 = { type: "literal", value: "?", description: "\"?\"" },239 peg$c92 = function() {240 return {241 type: 'glob',242 value: text()243 }244 },245 peg$c93 = "]",246 peg$c94 = { type: "literal", value: "]", description: "\"]\"" },247 peg$c95 = "$",248 peg$c96 = { type: "literal", value: "$", description: "\"$\"" },249 peg$c97 = "{",250 peg$c98 = { type: "literal", value: "{", description: "\"{\"" },251 peg$c99 = "}",252 peg$c100 = { type: "literal", value: "}", description: "\"}\"" },253 peg$c101 = "'",254 peg$c102 = { type: "literal", value: "'", description: "\"'\"" },255 peg$c103 = /^[^']/,256 peg$c104 = { type: "class", value: "[^']", description: "[^']" },257 peg$c105 = function(inner) { return literal(inner) },258 peg$c106 = "\"",259 peg$c107 = { type: "literal", value: "\"", description: "\"\\\"\"" },260 peg$c108 = function(contents) {261 var pieces = contents.map(function (it) {262 return isArray(it) ? literal(it) : it263 })264 return flattenConcatenation(pieces)265 },266 peg$c109 = "\\\\",267 peg$c110 = { type: "literal", value: "\\\\", description: "\"\\\\\\\\\"" },268 peg$c111 = function() { return '\\' },269 peg$c112 = "`",270 peg$c113 = { type: "literal", value: "`", description: "\"`\"" },271 peg$c114 = function(name) {272 return {type: 'variable', name: name}273 },274 peg$c115 = /^[a-zA-Z0-9_]/,275 peg$c116 = { type: "class", value: "[a-zA-Z0-9_]", description: "[a-zA-Z0-9_]" },276 peg$c117 = function() { return text() },277 peg$c118 = "${",278 peg$c119 = { type: "literal", value: "${", description: "\"${\"" },279 peg$c120 = /^[^}]/,280 peg$c121 = { type: "class", value: "[^}]", description: "[^}]" },281 peg$c122 = function(expr) {282 return {283 type: 'variableSubstitution',284 expression: join(expr), // TODO subParser285 }286 },287 peg$c123 = "$(",288 peg$c124 = { type: "literal", value: "$(", description: "\"$(\"" },289 peg$c125 = function(commands) {290 return {291 type: 'commandSubstitution',292 commands: commands293 }294 },295 peg$c126 = function(input) {296 return { type: 'commandSubstitution', commands: parse(input.join('')) }297 },298 peg$c127 = "\\`",299 peg$c128 = { type: "literal", value: "\\`", description: "\"\\\\`\"" },300 peg$c129 = function() { return '`' },301 peg$c130 = /^[<>]/,302 peg$c131 = { type: "class", value: "[<>]", description: "[<>]" },303 peg$c132 = function(rw, commands) {304 return {305 type: 'processSubstitution',306 readWrite: rw,307 commands: commands,308 }309 },310 peg$c133 = "<&",311 peg$c134 = { type: "literal", value: "<&", description: "\"<&\"" },312 peg$c135 = ">&",313 peg$c136 = { type: "literal", value: ">&", description: "\">&\"" },314 peg$c137 = function(fd, op, dest) {315 if (fd == null) fd = op[0] == '<' ? 0 : 1;316 return {317 type: 'moveFd',318 fd: fd,319 op: op,320 dest: dest321 }322 },323 peg$c138 = function(src, op, dest) {324 if (src == null) src = op[0] == '<' ? 0 : 1;325 return {326 type: 'duplicateFd',327 srcFd: src,328 op: op,329 destFd: dest,330 }331 },332 peg$c139 = function(fd, op, filename) {333 if (fd == null) fd = op[0] == '<' ? 0 : 1;334 return {335 type: 'redirectFd',336 fd: fd,337 op: op,338 filename: filename339 }340 },341 peg$c140 = ">|",342 peg$c141 = { type: "literal", value: ">|", description: "\">|\"" },343 peg$c142 = ">>",344 peg$c143 = { type: "literal", value: ">>", description: "\">>\"" },345 peg$c144 = "&>>",346 peg$c145 = { type: "literal", value: "&>>", description: "\"&>>\"" },347 peg$c146 = "&>",348 peg$c147 = { type: "literal", value: "&>", description: "\"&>\"" },349 peg$c148 = "<",350 peg$c149 = { type: "literal", value: "<", description: "\"<\"" },351 peg$c150 = ">",352 peg$c151 = { type: "literal", value: ">", description: "\">\"" },353 peg$c152 = /^[0-9]/,354 peg$c153 = { type: "class", value: "[0-9]", description: "[0-9]" },355 peg$c154 = function(digits) { return parseInt(join(digits), 10) },356 peg$c155 = "&",357 peg$c156 = { type: "literal", value: "&", description: "\"&\"" },358 peg$c157 = function(op) {359 return op == '\n' ? ';' : op360 },361 peg$c158 = "|",362 peg$c159 = { type: "literal", value: "|", description: "\"|\"" },363 peg$c160 = function(command) {364 return {type: 'pipe', command: command}365 },366 peg$c161 = { type: "other", description: "whitespace" },367 peg$c162 = " ",368 peg$c163 = { type: "literal", value: " ", description: "\" \"" },369 peg$c164 = "\t",370 peg$c165 = { type: "literal", value: "\t", description: "\"\\t\"" },371 peg$c166 = { type: "other", description: "a comment" },372 peg$c167 = "case",373 peg$c168 = { type: "literal", value: "case", description: "\"case\"" },374 peg$c169 = "esac",375 peg$c170 = { type: "literal", value: "esac", description: "\"esac\"" },376 peg$currPos = 0,377 peg$savedPos = 0,378 peg$posDetailsCache = [{ line: 1, column: 1, seenCR: false }],379 peg$maxFailPos = 0,380 peg$maxFailExpected = [],381 peg$silentFails = 0,382 peg$result;383 if ("startRule" in options) {384 if (!(options.startRule in peg$startRuleFunctions)) {385 throw new Error("Can't start parsing from rule \"" + options.startRule + "\".");386 }387 peg$startRuleFunction = peg$startRuleFunctions[options.startRule];388 }389 function text() {390 return input.substring(peg$savedPos, peg$currPos);391 }392 function location() {393 return peg$computeLocation(peg$savedPos, peg$currPos);394 }395 function expected(description) {396 throw peg$buildException(397 null,398 [{ type: "other", description: description }],399 input.substring(peg$savedPos, peg$currPos),400 peg$computeLocation(peg$savedPos, peg$currPos)401 );402 }403 function error(message) {404 throw peg$buildException(405 message,406 null,407 input.substring(peg$savedPos, peg$currPos),408 peg$computeLocation(peg$savedPos, peg$currPos)409 );410 }411 function peg$computePosDetails(pos) {412 var details = peg$posDetailsCache[pos],413 p, ch;414 if (details) {415 return details;416 } else {417 p = pos - 1;418 while (!peg$posDetailsCache[p]) {419 p--;420 }421 details = peg$posDetailsCache[p];422 details = {423 line: details.line,424 column: details.column,425 seenCR: details.seenCR426 };427 while (p < pos) {428 ch = input.charAt(p);429 if (ch === "\n") {430 if (!details.seenCR) { details.line++; }431 details.column = 1;432 details.seenCR = false;433 } else if (ch === "\r" || ch === "\u2028" || ch === "\u2029") {434 details.line++;435 details.column = 1;436 details.seenCR = true;437 } else {438 details.column++;439 details.seenCR = false;440 }441 p++;442 }443 peg$posDetailsCache[pos] = details;444 return details;445 }446 }447 function peg$computeLocation(startPos, endPos) {448 var startPosDetails = peg$computePosDetails(startPos),449 endPosDetails = peg$computePosDetails(endPos);450 return {451 start: {452 offset: startPos,453 line: startPosDetails.line,454 column: startPosDetails.column455 },456 end: {457 offset: endPos,458 line: endPosDetails.line,459 column: endPosDetails.column460 }461 };462 }463 function peg$fail(expected) {464 if (peg$currPos < peg$maxFailPos) { return; }465 if (peg$currPos > peg$maxFailPos) {466 peg$maxFailPos = peg$currPos;467 peg$maxFailExpected = [];468 }469 peg$maxFailExpected.push(expected);470 }471 function peg$buildException(message, expected, found, location) {472 function cleanupExpected(expected) {473 var i = 1;474 expected.sort(function(a, b) {475 if (a.description < b.description) {476 return -1;477 } else if (a.description > b.description) {478 return 1;479 } else {480 return 0;481 }482 });483 while (i < expected.length) {484 if (expected[i - 1] === expected[i]) {485 expected.splice(i, 1);486 } else {487 i++;488 }489 }490 }491 function buildMessage(expected, found) {492 function stringEscape(s) {493 function hex(ch) { return ch.charCodeAt(0).toString(16).toUpperCase(); }494 return s495 .replace(/\\/g, '\\\\')496 .replace(/"/g, '\\"')497 .replace(/\x08/g, '\\b')498 .replace(/\t/g, '\\t')499 .replace(/\n/g, '\\n')500 .replace(/\f/g, '\\f')501 .replace(/\r/g, '\\r')502 .replace(/[\x00-\x07\x0B\x0E\x0F]/g, function(ch) { return '\\x0' + hex(ch); })503 .replace(/[\x10-\x1F\x80-\xFF]/g, function(ch) { return '\\x' + hex(ch); })504 .replace(/[\u0100-\u0FFF]/g, function(ch) { return '\\u0' + hex(ch); })505 .replace(/[\u1000-\uFFFF]/g, function(ch) { return '\\u' + hex(ch); });506 }507 var expectedDescs = new Array(expected.length),508 expectedDesc, foundDesc, i;509 for (i = 0; i < expected.length; i++) {510 expectedDescs[i] = expected[i].description;511 }512 expectedDesc = expected.length > 1513 ? expectedDescs.slice(0, -1).join(", ")514 + " or "515 + expectedDescs[expected.length - 1]516 : expectedDescs[0];517 foundDesc = found ? "\"" + stringEscape(found) + "\"" : "end of input";518 return "Expected " + expectedDesc + " but " + foundDesc + " found.";519 }520 if (expected !== null) {521 cleanupExpected(expected);522 }523 return new peg$SyntaxError(524 message !== null ? message : buildMessage(expected, found),525 expected,526 found,527 location528 );529 }530 function peg$parsescript() {531 var s0, s1, s2;532 s0 = peg$currPos;533 s1 = [];534 s2 = peg$parsespaceNL();535 while (s2 !== peg$FAILED) {536 s1.push(s2);537 s2 = peg$parsespaceNL();538 }539 if (s1 !== peg$FAILED) {540 s2 = peg$parsestatementList();541 if (s2 === peg$FAILED) {542 s2 = null;543 }544 if (s2 !== peg$FAILED) {545 peg$savedPos = s0;546 s1 = peg$c0(s2);547 s0 = s1;548 } else {549 peg$currPos = s0;550 s0 = peg$FAILED;551 }552 } else {553 peg$currPos = s0;554 s0 = peg$FAILED;555 }556 return s0;557 }558 function peg$parsestatementList() {559 var s0, s1, s2, s3, s4, s5, s6;560 s0 = peg$currPos;561 s1 = peg$parsestatement();562 if (s1 !== peg$FAILED) {563 s2 = [];564 s3 = peg$currPos;565 s4 = peg$parsecontrolOperator();566 if (s4 !== peg$FAILED) {567 s5 = [];568 s6 = peg$parsespaceNL();569 while (s6 !== peg$FAILED) {570 s5.push(s6);571 s6 = peg$parsespaceNL();572 }573 if (s5 !== peg$FAILED) {574 s6 = peg$parsestatement();575 if (s6 !== peg$FAILED) {576 s4 = [s4, s5, s6];577 s3 = s4;578 } else {579 peg$currPos = s3;580 s3 = peg$FAILED;581 }582 } else {583 peg$currPos = s3;584 s3 = peg$FAILED;585 }586 } else {587 peg$currPos = s3;588 s3 = peg$FAILED;589 }590 while (s3 !== peg$FAILED) {591 s2.push(s3);592 s3 = peg$currPos;593 s4 = peg$parsecontrolOperator();594 if (s4 !== peg$FAILED) {595 s5 = [];596 s6 = peg$parsespaceNL();597 while (s6 !== peg$FAILED) {598 s5.push(s6);599 s6 = peg$parsespaceNL();600 }601 if (s5 !== peg$FAILED) {602 s6 = peg$parsestatement();603 if (s6 !== peg$FAILED) {604 s4 = [s4, s5, s6];605 s3 = s4;606 } else {607 peg$currPos = s3;608 s3 = peg$FAILED;609 }610 } else {611 peg$currPos = s3;612 s3 = peg$FAILED;613 }614 } else {615 peg$currPos = s3;616 s3 = peg$FAILED;617 }618 }619 if (s2 !== peg$FAILED) {620 s3 = [];621 s4 = peg$parsespace();622 while (s4 !== peg$FAILED) {623 s3.push(s4);624 s4 = peg$parsespace();625 }626 if (s3 !== peg$FAILED) {627 s4 = peg$parsecontrolOperator();628 if (s4 === peg$FAILED) {629 s4 = null;630 }631 if (s4 !== peg$FAILED) {632 s5 = [];633 s6 = peg$parsespaceNL();634 while (s6 !== peg$FAILED) {635 s5.push(s6);636 s6 = peg$parsespaceNL();637 }638 if (s5 !== peg$FAILED) {639 peg$savedPos = s0;640 s1 = peg$c1(s1, s2, s4);641 s0 = s1;642 } else {643 peg$currPos = s0;644 s0 = peg$FAILED;645 }646 } else {647 peg$currPos = s0;648 s0 = peg$FAILED;649 }650 } else {651 peg$currPos = s0;652 s0 = peg$FAILED;653 }654 } else {655 peg$currPos = s0;656 s0 = peg$FAILED;657 }658 } else {659 peg$currPos = s0;660 s0 = peg$FAILED;661 }662 return s0;663 }664 function peg$parsestatement() {665 var s0, s1, s2, s3, s4;666 s0 = peg$currPos;667 s1 = peg$parsesubshell();668 if (s1 === peg$FAILED) {669 s1 = peg$parsebashExtensions();670 if (s1 === peg$FAILED) {671 s1 = peg$parsecommand();672 if (s1 === peg$FAILED) {673 s1 = peg$parsevariableAssignment();674 if (s1 === peg$FAILED) {675 s1 = peg$parseifBlock();676 if (s1 === peg$FAILED) {677 s1 = peg$parseconditionalLoop();678 if (s1 === peg$FAILED) {679 s1 = peg$parseforLoop();680 }681 }682 }683 }684 }685 }686 if (s1 !== peg$FAILED) {687 s2 = peg$currPos;688 s3 = [];689 s4 = peg$parsespace();690 while (s4 !== peg$FAILED) {691 s3.push(s4);692 s4 = peg$parsespace();693 }694 if (s3 !== peg$FAILED) {695 s4 = peg$parsechainedStatement();696 if (s4 !== peg$FAILED) {697 s3 = [s3, s4];698 s2 = s3;699 } else {700 peg$currPos = s2;701 s2 = peg$FAILED;702 }703 } else {704 peg$currPos = s2;705 s2 = peg$FAILED;706 }707 if (s2 === peg$FAILED) {708 s2 = null;709 }710 if (s2 !== peg$FAILED) {711 peg$savedPos = s0;712 s1 = peg$c2(s1, s2);713 s0 = s1;714 } else {715 peg$currPos = s0;716 s0 = peg$FAILED;717 }718 } else {719 peg$currPos = s0;720 s0 = peg$FAILED;721 }722 return s0;723 }724 function peg$parsechainedStatement() {725 var s0, s1, s2, s3;726 s0 = peg$currPos;727 if (input.substr(peg$currPos, 2) === peg$c3) {728 s1 = peg$c3;729 peg$currPos += 2;730 } else {731 s1 = peg$FAILED;732 if (peg$silentFails === 0) { peg$fail(peg$c4); }733 }734 if (s1 === peg$FAILED) {735 if (input.substr(peg$currPos, 2) === peg$c5) {736 s1 = peg$c5;737 peg$currPos += 2;738 } else {739 s1 = peg$FAILED;740 if (peg$silentFails === 0) { peg$fail(peg$c6); }741 }742 }743 if (s1 !== peg$FAILED) {744 s2 = [];745 s3 = peg$parsespaceNL();746 while (s3 !== peg$FAILED) {747 s2.push(s3);748 s3 = peg$parsespaceNL();749 }750 if (s2 !== peg$FAILED) {751 s3 = peg$parsestatement();752 if (s3 !== peg$FAILED) {753 peg$savedPos = s0;754 s1 = peg$c7(s1, s3);755 s0 = s1;756 } else {757 peg$currPos = s0;758 s0 = peg$FAILED;759 }760 } else {761 peg$currPos = s0;762 s0 = peg$FAILED;763 }764 } else {765 peg$currPos = s0;766 s0 = peg$FAILED;767 }768 return s0;769 }770 function peg$parsesubshell() {771 var s0, s1, s2, s3, s4, s5;772 peg$silentFails++;773 s0 = peg$currPos;774 if (input.charCodeAt(peg$currPos) === 40) {775 s1 = peg$c9;776 peg$currPos++;777 } else {778 s1 = peg$FAILED;779 if (peg$silentFails === 0) { peg$fail(peg$c10); }780 }781 if (s1 !== peg$FAILED) {782 s2 = [];783 s3 = peg$parsespace();784 while (s3 !== peg$FAILED) {785 s2.push(s3);786 s3 = peg$parsespace();787 }788 if (s2 !== peg$FAILED) {789 s3 = peg$parsestatementList();790 if (s3 !== peg$FAILED) {791 s4 = [];792 s5 = peg$parsespace();793 while (s5 !== peg$FAILED) {794 s4.push(s5);795 s5 = peg$parsespace();796 }797 if (s4 !== peg$FAILED) {798 if (input.charCodeAt(peg$currPos) === 41) {799 s5 = peg$c11;800 peg$currPos++;801 } else {802 s5 = peg$FAILED;803 if (peg$silentFails === 0) { peg$fail(peg$c12); }804 }805 if (s5 !== peg$FAILED) {806 peg$savedPos = s0;807 s1 = peg$c13(s3);808 s0 = s1;809 } else {810 peg$currPos = s0;811 s0 = peg$FAILED;812 }813 } else {814 peg$currPos = s0;815 s0 = peg$FAILED;816 }817 } else {818 peg$currPos = s0;819 s0 = peg$FAILED;820 }821 } else {822 peg$currPos = s0;823 s0 = peg$FAILED;824 }825 } else {826 peg$currPos = s0;827 s0 = peg$FAILED;828 }829 peg$silentFails--;830 if (s0 === peg$FAILED) {831 s1 = peg$FAILED;832 if (peg$silentFails === 0) { peg$fail(peg$c8); }833 }834 return s0;835 }836 function peg$parsecommand() {837 var s0, s1, s2, s3, s4, s5, s6;838 peg$silentFails++;839 s0 = peg$currPos;840 s1 = [];841 s2 = peg$currPos;842 s3 = peg$parsevariableAssignment();843 if (s3 === peg$FAILED) {844 s3 = peg$parseredirect();845 }846 if (s3 !== peg$FAILED) {847 s4 = [];848 s5 = peg$parsespace();849 if (s5 !== peg$FAILED) {850 while (s5 !== peg$FAILED) {851 s4.push(s5);852 s5 = peg$parsespace();853 }854 } else {855 s4 = peg$FAILED;856 }857 if (s4 !== peg$FAILED) {858 s3 = [s3, s4];859 s2 = s3;860 } else {861 peg$currPos = s2;862 s2 = peg$FAILED;863 }864 } else {865 peg$currPos = s2;866 s2 = peg$FAILED;867 }868 while (s2 !== peg$FAILED) {869 s1.push(s2);870 s2 = peg$currPos;871 s3 = peg$parsevariableAssignment();872 if (s3 === peg$FAILED) {873 s3 = peg$parseredirect();874 }875 if (s3 !== peg$FAILED) {876 s4 = [];877 s5 = peg$parsespace();878 if (s5 !== peg$FAILED) {879 while (s5 !== peg$FAILED) {880 s4.push(s5);881 s5 = peg$parsespace();882 }883 } else {884 s4 = peg$FAILED;885 }886 if (s4 !== peg$FAILED) {887 s3 = [s3, s4];888 s2 = s3;889 } else {890 peg$currPos = s2;891 s2 = peg$FAILED;892 }893 } else {894 peg$currPos = s2;895 s2 = peg$FAILED;896 }897 }898 if (s1 !== peg$FAILED) {899 s2 = peg$parsecommandName();900 if (s2 === peg$FAILED) {901 s2 = peg$parsebuiltinCommandName();902 }903 if (s2 !== peg$FAILED) {904 s3 = [];905 s4 = peg$currPos;906 s5 = [];907 s6 = peg$parsespace();908 if (s6 !== peg$FAILED) {909 while (s6 !== peg$FAILED) {910 s5.push(s6);911 s6 = peg$parsespace();912 }913 } else {914 s5 = peg$FAILED;915 }916 if (s5 !== peg$FAILED) {917 s6 = peg$parseredirect();918 if (s6 === peg$FAILED) {919 s6 = peg$parseargument();920 }921 if (s6 !== peg$FAILED) {922 s5 = [s5, s6];923 s4 = s5;924 } else {925 peg$currPos = s4;926 s4 = peg$FAILED;927 }928 } else {929 peg$currPos = s4;930 s4 = peg$FAILED;931 }932 while (s4 !== peg$FAILED) {933 s3.push(s4);934 s4 = peg$currPos;935 s5 = [];936 s6 = peg$parsespace();937 if (s6 !== peg$FAILED) {938 while (s6 !== peg$FAILED) {939 s5.push(s6);940 s6 = peg$parsespace();941 }942 } else {943 s5 = peg$FAILED;944 }945 if (s5 !== peg$FAILED) {946 s6 = peg$parseredirect();947 if (s6 === peg$FAILED) {948 s6 = peg$parseargument();949 }950 if (s6 !== peg$FAILED) {951 s5 = [s5, s6];952 s4 = s5;953 } else {954 peg$currPos = s4;955 s4 = peg$FAILED;956 }957 } else {958 peg$currPos = s4;959 s4 = peg$FAILED;960 }961 }962 if (s3 !== peg$FAILED) {963 s4 = peg$currPos;964 s5 = [];965 s6 = peg$parsespace();966 while (s6 !== peg$FAILED) {967 s5.push(s6);968 s6 = peg$parsespace();969 }970 if (s5 !== peg$FAILED) {971 s6 = peg$parsepipe();972 if (s6 !== peg$FAILED) {973 s5 = [s5, s6];974 s4 = s5;975 } else {976 peg$currPos = s4;977 s4 = peg$FAILED;978 }979 } else {980 peg$currPos = s4;981 s4 = peg$FAILED;982 }983 if (s4 === peg$FAILED) {984 s4 = null;985 }986 if (s4 !== peg$FAILED) {987 peg$savedPos = s0;988 s1 = peg$c15(s1, s2, s3, s4);989 s0 = s1;990 } else {991 peg$currPos = s0;992 s0 = peg$FAILED;993 }994 } else {995 peg$currPos = s0;996 s0 = peg$FAILED;997 }998 } else {999 peg$currPos = s0;1000 s0 = peg$FAILED;1001 }1002 } else {1003 peg$currPos = s0;1004 s0 = peg$FAILED;1005 }1006 peg$silentFails--;1007 if (s0 === peg$FAILED) {1008 s1 = peg$FAILED;1009 if (peg$silentFails === 0) { peg$fail(peg$c14); }1010 }1011 return s0;1012 }1013 function peg$parsecondition() {1014 var s0, s1;1015 s0 = peg$currPos;1016 s1 = peg$parsescript();1017 if (s1 !== peg$FAILED) {1018 peg$savedPos = s0;1019 s1 = peg$c16(s1);1020 }1021 s0 = s1;1022 return s0;1023 }1024 function peg$parseifBlock() {1025 var s0, s1, s2, s3, s4, s5, s6, s7, s8, s9, s10;1026 peg$silentFails++;1027 s0 = peg$currPos;1028 if (input.substr(peg$currPos, 2) === peg$c18) {1029 s1 = peg$c18;1030 peg$currPos += 2;1031 } else {1032 s1 = peg$FAILED;1033 if (peg$silentFails === 0) { peg$fail(peg$c19); }1034 }1035 if (s1 !== peg$FAILED) {1036 s2 = [];1037 s3 = peg$parsespaceNL();1038 if (s3 !== peg$FAILED) {1039 while (s3 !== peg$FAILED) {1040 s2.push(s3);1041 s3 = peg$parsespaceNL();1042 }1043 } else {1044 s2 = peg$FAILED;1045 }1046 if (s2 !== peg$FAILED) {1047 s3 = peg$parsecondition();1048 if (s3 !== peg$FAILED) {1049 if (input.substr(peg$currPos, 4) === peg$c20) {1050 s4 = peg$c20;1051 peg$currPos += 4;1052 } else {1053 s4 = peg$FAILED;1054 if (peg$silentFails === 0) { peg$fail(peg$c21); }1055 }1056 if (s4 !== peg$FAILED) {1057 s5 = [];1058 s6 = peg$parsespaceNL();1059 if (s6 !== peg$FAILED) {1060 while (s6 !== peg$FAILED) {1061 s5.push(s6);1062 s6 = peg$parsespaceNL();1063 }1064 } else {1065 s5 = peg$FAILED;1066 }1067 if (s5 !== peg$FAILED) {1068 s6 = peg$parsescript();1069 if (s6 !== peg$FAILED) {1070 s7 = [];1071 s8 = peg$parseelifBlock();1072 while (s8 !== peg$FAILED) {1073 s7.push(s8);1074 s8 = peg$parseelifBlock();1075 }1076 if (s7 !== peg$FAILED) {1077 s8 = peg$currPos;1078 if (input.substr(peg$currPos, 4) === peg$c22) {1079 s9 = peg$c22;1080 peg$currPos += 4;1081 } else {1082 s9 = peg$FAILED;1083 if (peg$silentFails === 0) { peg$fail(peg$c23); }1084 }1085 if (s9 !== peg$FAILED) {1086 s10 = peg$parsescript();1087 if (s10 !== peg$FAILED) {1088 s9 = [s9, s10];1089 s8 = s9;1090 } else {1091 peg$currPos = s8;1092 s8 = peg$FAILED;1093 }1094 } else {1095 peg$currPos = s8;1096 s8 = peg$FAILED;1097 }1098 if (s8 === peg$FAILED) {1099 s8 = null;1100 }1101 if (s8 !== peg$FAILED) {1102 if (input.substr(peg$currPos, 2) === peg$c24) {1103 s9 = peg$c24;1104 peg$currPos += 2;1105 } else {1106 s9 = peg$FAILED;1107 if (peg$silentFails === 0) { peg$fail(peg$c25); }1108 }1109 if (s9 !== peg$FAILED) {1110 peg$savedPos = s0;1111 s1 = peg$c26(s3, s6, s7, s8);1112 s0 = s1;1113 } else {1114 peg$currPos = s0;1115 s0 = peg$FAILED;1116 }1117 } else {1118 peg$currPos = s0;1119 s0 = peg$FAILED;1120 }1121 } else {1122 peg$currPos = s0;1123 s0 = peg$FAILED;1124 }1125 } else {1126 peg$currPos = s0;1127 s0 = peg$FAILED;1128 }1129 } else {1130 peg$currPos = s0;1131 s0 = peg$FAILED;1132 }1133 } else {1134 peg$currPos = s0;1135 s0 = peg$FAILED;1136 }1137 } else {1138 peg$currPos = s0;1139 s0 = peg$FAILED;1140 }1141 } else {1142 peg$currPos = s0;1143 s0 = peg$FAILED;1144 }1145 } else {1146 peg$currPos = s0;1147 s0 = peg$FAILED;1148 }1149 peg$silentFails--;1150 if (s0 === peg$FAILED) {1151 s1 = peg$FAILED;1152 if (peg$silentFails === 0) { peg$fail(peg$c17); }1153 }1154 return s0;1155 }1156 function peg$parseelifBlock() {1157 var s0, s1, s2, s3, s4, s5, s6;1158 s0 = peg$currPos;1159 if (input.substr(peg$currPos, 4) === peg$c27) {1160 s1 = peg$c27;1161 peg$currPos += 4;1162 } else {1163 s1 = peg$FAILED;1164 if (peg$silentFails === 0) { peg$fail(peg$c28); }1165 }1166 if (s1 !== peg$FAILED) {1167 s2 = [];1168 s3 = peg$parsespaceNL();1169 if (s3 !== peg$FAILED) {1170 while (s3 !== peg$FAILED) {1171 s2.push(s3);1172 s3 = peg$parsespaceNL();1173 }1174 } else {1175 s2 = peg$FAILED;1176 }1177 if (s2 !== peg$FAILED) {1178 s3 = peg$parsecondition();1179 if (s3 !== peg$FAILED) {1180 if (input.substr(peg$currPos, 4) === peg$c20) {1181 s4 = peg$c20;1182 peg$currPos += 4;1183 } else {1184 s4 = peg$FAILED;1185 if (peg$silentFails === 0) { peg$fail(peg$c21); }1186 }1187 if (s4 !== peg$FAILED) {1188 s5 = [];1189 s6 = peg$parsespaceNL();1190 if (s6 !== peg$FAILED) {1191 while (s6 !== peg$FAILED) {1192 s5.push(s6);1193 s6 = peg$parsespaceNL();1194 }1195 } else {1196 s5 = peg$FAILED;1197 }1198 if (s5 !== peg$FAILED) {1199 s6 = peg$parsescript();1200 if (s6 !== peg$FAILED) {1201 peg$savedPos = s0;1202 s1 = peg$c29(s3, s6);1203 s0 = s1;1204 } else {1205 peg$currPos = s0;1206 s0 = peg$FAILED;1207 }1208 } else {1209 peg$currPos = s0;1210 s0 = peg$FAILED;1211 }1212 } else {1213 peg$currPos = s0;1214 s0 = peg$FAILED;1215 }1216 } else {1217 peg$currPos = s0;1218 s0 = peg$FAILED;1219 }1220 } else {1221 peg$currPos = s0;1222 s0 = peg$FAILED;1223 }1224 } else {1225 peg$currPos = s0;1226 s0 = peg$FAILED;1227 }1228 return s0;1229 }1230 function peg$parseconditionalLoop() {1231 var s0, s1, s2, s3, s4, s5, s6, s7;1232 peg$silentFails++;1233 s0 = peg$currPos;1234 if (input.substr(peg$currPos, 5) === peg$c31) {1235 s1 = peg$c31;1236 peg$currPos += 5;1237 } else {1238 s1 = peg$FAILED;1239 if (peg$silentFails === 0) { peg$fail(peg$c32); }1240 }1241 if (s1 === peg$FAILED) {1242 if (input.substr(peg$currPos, 5) === peg$c33) {1243 s1 = peg$c33;1244 peg$currPos += 5;1245 } else {1246 s1 = peg$FAILED;1247 if (peg$silentFails === 0) { peg$fail(peg$c34); }1248 }1249 }1250 if (s1 !== peg$FAILED) {1251 s2 = [];1252 s3 = peg$parsespaceNL();1253 if (s3 !== peg$FAILED) {1254 while (s3 !== peg$FAILED) {1255 s2.push(s3);1256 s3 = peg$parsespaceNL();1257 }1258 } else {1259 s2 = peg$FAILED;1260 }1261 if (s2 !== peg$FAILED) {1262 s3 = peg$parsecondition();1263 if (s3 !== peg$FAILED) {1264 if (input.substr(peg$currPos, 2) === peg$c35) {1265 s4 = peg$c35;1266 peg$currPos += 2;1267 } else {1268 s4 = peg$FAILED;1269 if (peg$silentFails === 0) { peg$fail(peg$c36); }1270 }1271 if (s4 !== peg$FAILED) {1272 s5 = [];1273 s6 = peg$parsespaceNL();1274 if (s6 !== peg$FAILED) {1275 while (s6 !== peg$FAILED) {1276 s5.push(s6);1277 s6 = peg$parsespaceNL();1278 }1279 } else {1280 s5 = peg$FAILED;1281 }1282 if (s5 !== peg$FAILED) {1283 s6 = peg$parsescript();1284 if (s6 !== peg$FAILED) {1285 if (input.substr(peg$currPos, 4) === peg$c37) {1286 s7 = peg$c37;1287 peg$currPos += 4;1288 } else {1289 s7 = peg$FAILED;1290 if (peg$silentFails === 0) { peg$fail(peg$c38); }1291 }1292 if (s7 !== peg$FAILED) {1293 peg$savedPos = s0;1294 s1 = peg$c39(s1, s3, s6);1295 s0 = s1;1296 } else {1297 peg$currPos = s0;1298 s0 = peg$FAILED;1299 }1300 } else {1301 peg$currPos = s0;1302 s0 = peg$FAILED;1303 }1304 } else {1305 peg$currPos = s0;1306 s0 = peg$FAILED;1307 }1308 } else {1309 peg$currPos = s0;1310 s0 = peg$FAILED;1311 }1312 } else {1313 peg$currPos = s0;1314 s0 = peg$FAILED;1315 }1316 } else {1317 peg$currPos = s0;1318 s0 = peg$FAILED;1319 }1320 } else {1321 peg$currPos = s0;1322 s0 = peg$FAILED;1323 }1324 peg$silentFails--;1325 if (s0 === peg$FAILED) {1326 s1 = peg$FAILED;1327 if (peg$silentFails === 0) { peg$fail(peg$c30); }1328 }1329 return s0;1330 }1331 function peg$parseforLoop() {1332 var s0, s1, s2, s3, s4, s5, s6, s7, s8, s9, s10, s11, s12, s13;1333 peg$silentFails++;1334 s0 = peg$currPos;1335 if (input.substr(peg$currPos, 3) === peg$c41) {1336 s1 = peg$c41;1337 peg$currPos += 3;1338 } else {1339 s1 = peg$FAILED;1340 if (peg$silentFails === 0) { peg$fail(peg$c42); }1341 }1342 if (s1 !== peg$FAILED) {1343 s2 = [];1344 s3 = peg$parsespace();1345 if (s3 !== peg$FAILED) {1346 while (s3 !== peg$FAILED) {1347 s2.push(s3);1348 s3 = peg$parsespace();1349 }1350 } else {1351 s2 = peg$FAILED;1352 }1353 if (s2 !== peg$FAILED) {1354 s3 = peg$parsewritableVariableName();1355 if (s3 !== peg$FAILED) {1356 s4 = [];1357 s5 = peg$parsespaceNL();1358 if (s5 !== peg$FAILED) {1359 while (s5 !== peg$FAILED) {1360 s4.push(s5);1361 s5 = peg$parsespaceNL();1362 }1363 } else {1364 s4 = peg$FAILED;1365 }1366 if (s4 !== peg$FAILED) {1367 s5 = peg$currPos;1368 if (input.substr(peg$currPos, 2) === peg$c43) {1369 s6 = peg$c43;1370 peg$currPos += 2;1371 } else {1372 s6 = peg$FAILED;1373 if (peg$silentFails === 0) { peg$fail(peg$c44); }1374 }1375 if (s6 !== peg$FAILED) {1376 s7 = [];1377 s8 = peg$currPos;1378 s9 = [];1379 s10 = peg$parsespace();1380 if (s10 !== peg$FAILED) {1381 while (s10 !== peg$FAILED) {1382 s9.push(s10);1383 s10 = peg$parsespace();1384 }1385 } else {1386 s9 = peg$FAILED;1387 }1388 if (s9 !== peg$FAILED) {1389 s10 = peg$parseargument();1390 if (s10 !== peg$FAILED) {1391 s9 = [s9, s10];1392 s8 = s9;1393 } else {1394 peg$currPos = s8;1395 s8 = peg$FAILED;1396 }1397 } else {1398 peg$currPos = s8;1399 s8 = peg$FAILED;1400 }1401 while (s8 !== peg$FAILED) {1402 s7.push(s8);1403 s8 = peg$currPos;1404 s9 = [];1405 s10 = peg$parsespace();1406 if (s10 !== peg$FAILED) {1407 while (s10 !== peg$FAILED) {1408 s9.push(s10);1409 s10 = peg$parsespace();1410 }1411 } else {1412 s9 = peg$FAILED;1413 }1414 if (s9 !== peg$FAILED) {1415 s10 = peg$parseargument();1416 if (s10 !== peg$FAILED) {1417 s9 = [s9, s10];1418 s8 = s9;1419 } else {1420 peg$currPos = s8;1421 s8 = peg$FAILED;1422 }1423 } else {1424 peg$currPos = s8;1425 s8 = peg$FAILED;1426 }1427 }1428 if (s7 !== peg$FAILED) {1429 s6 = [s6, s7];1430 s5 = s6;1431 } else {1432 peg$currPos = s5;1433 s5 = peg$FAILED;1434 }1435 } else {1436 peg$currPos = s5;1437 s5 = peg$FAILED;1438 }1439 if (s5 === peg$FAILED) {1440 s5 = null;1441 }1442 if (s5 !== peg$FAILED) {1443 s6 = [];1444 s7 = peg$parsespace();1445 while (s7 !== peg$FAILED) {1446 s6.push(s7);1447 s7 = peg$parsespace();1448 }1449 if (s6 !== peg$FAILED) {1450 if (input.charCodeAt(peg$currPos) === 59) {1451 s7 = peg$c45;1452 peg$currPos++;1453 } else {1454 s7 = peg$FAILED;1455 if (peg$silentFails === 0) { peg$fail(peg$c46); }1456 }1457 if (s7 === peg$FAILED) {1458 if (input.charCodeAt(peg$currPos) === 10) {1459 s7 = peg$c47;1460 peg$currPos++;1461 } else {1462 s7 = peg$FAILED;1463 if (peg$silentFails === 0) { peg$fail(peg$c48); }1464 }1465 }1466 if (s7 !== peg$FAILED) {1467 s8 = [];1468 s9 = peg$parsespaceNL();1469 while (s9 !== peg$FAILED) {1470 s8.push(s9);1471 s9 = peg$parsespaceNL();1472 }1473 if (s8 !== peg$FAILED) {1474 if (input.substr(peg$currPos, 2) === peg$c35) {1475 s9 = peg$c35;1476 peg$currPos += 2;1477 } else {1478 s9 = peg$FAILED;1479 if (peg$silentFails === 0) { peg$fail(peg$c36); }1480 }1481 if (s9 !== peg$FAILED) {1482 s10 = [];1483 s11 = peg$parsespaceNL();1484 if (s11 !== peg$FAILED) {1485 while (s11 !== peg$FAILED) {1486 s10.push(s11);1487 s11 = peg$parsespaceNL();1488 }1489 } else {1490 s10 = peg$FAILED;1491 }1492 if (s10 !== peg$FAILED) {1493 s11 = peg$parsestatementList();1494 if (s11 !== peg$FAILED) {1495 s12 = [];1496 s13 = peg$parsespaceNL();1497 while (s13 !== peg$FAILED) {1498 s12.push(s13);1499 s13 = peg$parsespaceNL();1500 }1501 if (s12 !== peg$FAILED) {1502 if (input.substr(peg$currPos, 4) === peg$c37) {1503 s13 = peg$c37;1504 peg$currPos += 4;1505 } else {1506 s13 = peg$FAILED;1507 if (peg$silentFails === 0) { peg$fail(peg$c38); }1508 }1509 if (s13 !== peg$FAILED) {1510 peg$savedPos = s0;1511 s1 = peg$c49(s3, s5, s11);1512 s0 = s1;1513 } else {1514 peg$currPos = s0;1515 s0 = peg$FAILED;1516 }1517 } else {1518 peg$currPos = s0;1519 s0 = peg$FAILED;1520 }1521 } else {1522 peg$currPos = s0;1523 s0 = peg$FAILED;1524 }1525 } else {1526 peg$currPos = s0;1527 s0 = peg$FAILED;1528 }1529 } else {1530 peg$currPos = s0;1531 s0 = peg$FAILED;1532 }1533 } else {1534 peg$currPos = s0;1535 s0 = peg$FAILED;1536 }1537 } else {1538 peg$currPos = s0;1539 s0 = peg$FAILED;1540 }1541 } else {1542 peg$currPos = s0;1543 s0 = peg$FAILED;1544 }1545 } else {1546 peg$currPos = s0;1547 s0 = peg$FAILED;1548 }1549 } else {1550 peg$currPos = s0;1551 s0 = peg$FAILED;1552 }1553 } else {1554 peg$currPos = s0;1555 s0 = peg$FAILED;1556 }1557 } else {1558 peg$currPos = s0;1559 s0 = peg$FAILED;1560 }1561 } else {1562 peg$currPos = s0;1563 s0 = peg$FAILED;1564 }1565 peg$silentFails--;1566 if (s0 === peg$FAILED) {1567 s1 = peg$FAILED;1568 if (peg$silentFails === 0) { peg$fail(peg$c40); }1569 }1570 return s0;1571 }1572 function peg$parsebashExtensions() {1573 var s0;1574 s0 = peg$parsetime();1575 if (s0 === peg$FAILED) {1576 s0 = peg$parsedeclare();1577 }1578 return s0;1579 }1580 function peg$parsetime() {1581 var s0, s1, s2, s3, s4, s5, s6, s7, s8;1582 peg$silentFails++;1583 s0 = peg$currPos;1584 if (input.substr(peg$currPos, 4) === peg$c51) {1585 s1 = peg$c51;1586 peg$currPos += 4;1587 } else {1588 s1 = peg$FAILED;1589 if (peg$silentFails === 0) { peg$fail(peg$c52); }1590 }1591 if (s1 !== peg$FAILED) {1592 s2 = [];1593 s3 = peg$parsespace();1594 if (s3 !== peg$FAILED) {1595 while (s3 !== peg$FAILED) {1596 s2.push(s3);1597 s3 = peg$parsespace();1598 }1599 } else {1600 s2 = peg$FAILED;1601 }1602 if (s2 !== peg$FAILED) {1603 s3 = [];1604 s4 = peg$currPos;1605 if (input.charCodeAt(peg$currPos) === 45) {1606 s5 = peg$c53;1607 peg$currPos++;1608 } else {1609 s5 = peg$FAILED;1610 if (peg$silentFails === 0) { peg$fail(peg$c54); }1611 }1612 if (s5 !== peg$FAILED) {1613 s6 = [];1614 if (peg$c55.test(input.charAt(peg$currPos))) {1615 s7 = input.charAt(peg$currPos);1616 peg$currPos++;1617 } else {1618 s7 = peg$FAILED;1619 if (peg$silentFails === 0) { peg$fail(peg$c56); }1620 }1621 if (s7 !== peg$FAILED) {1622 while (s7 !== peg$FAILED) {1623 s6.push(s7);1624 if (peg$c55.test(input.charAt(peg$currPos))) {1625 s7 = input.charAt(peg$currPos);1626 peg$currPos++;1627 } else {1628 s7 = peg$FAILED;1629 if (peg$silentFails === 0) { peg$fail(peg$c56); }1630 }1631 }1632 } else {1633 s6 = peg$FAILED;1634 }1635 if (s6 !== peg$FAILED) {1636 s7 = [];1637 s8 = peg$parsespace();1638 if (s8 !== peg$FAILED) {1639 while (s8 !== peg$FAILED) {1640 s7.push(s8);1641 s8 = peg$parsespace();1642 }1643 } else {1644 s7 = peg$FAILED;1645 }1646 if (s7 !== peg$FAILED) {1647 s5 = [s5, s6, s7];1648 s4 = s5;1649 } else {1650 peg$currPos = s4;1651 s4 = peg$FAILED;1652 }1653 } else {1654 peg$currPos = s4;1655 s4 = peg$FAILED;1656 }1657 } else {1658 peg$currPos = s4;1659 s4 = peg$FAILED;1660 }1661 while (s4 !== peg$FAILED) {1662 s3.push(s4);1663 s4 = peg$currPos;1664 if (input.charCodeAt(peg$currPos) === 45) {1665 s5 = peg$c53;1666 peg$currPos++;1667 } else {1668 s5 = peg$FAILED;1669 if (peg$silentFails === 0) { peg$fail(peg$c54); }1670 }1671 if (s5 !== peg$FAILED) {1672 s6 = [];1673 if (peg$c55.test(input.charAt(peg$currPos))) {1674 s7 = input.charAt(peg$currPos);1675 peg$currPos++;1676 } else {1677 s7 = peg$FAILED;1678 if (peg$silentFails === 0) { peg$fail(peg$c56); }1679 }1680 if (s7 !== peg$FAILED) {1681 while (s7 !== peg$FAILED) {1682 s6.push(s7);1683 if (peg$c55.test(input.charAt(peg$currPos))) {1684 s7 = input.charAt(peg$currPos);1685 peg$currPos++;1686 } else {1687 s7 = peg$FAILED;1688 if (peg$silentFails === 0) { peg$fail(peg$c56); }1689 }1690 }1691 } else {1692 s6 = peg$FAILED;1693 }1694 if (s6 !== peg$FAILED) {1695 s7 = [];1696 s8 = peg$parsespace();1697 if (s8 !== peg$FAILED) {1698 while (s8 !== peg$FAILED) {1699 s7.push(s8);1700 s8 = peg$parsespace();1701 }1702 } else {1703 s7 = peg$FAILED;1704 }1705 if (s7 !== peg$FAILED) {1706 s5 = [s5, s6, s7];1707 s4 = s5;1708 } else {1709 peg$currPos = s4;1710 s4 = peg$FAILED;1711 }1712 } else {1713 peg$currPos = s4;1714 s4 = peg$FAILED;1715 }1716 } else {1717 peg$currPos = s4;1718 s4 = peg$FAILED;1719 }1720 }1721 if (s3 !== peg$FAILED) {1722 s4 = peg$parsestatementList();1723 if (s4 !== peg$FAILED) {1724 peg$savedPos = s0;1725 s1 = peg$c57(s3, s4);1726 s0 = s1;1727 } else {1728 peg$currPos = s0;1729 s0 = peg$FAILED;1730 }1731 } else {1732 peg$currPos = s0;1733 s0 = peg$FAILED;1734 }1735 } else {1736 peg$currPos = s0;1737 s0 = peg$FAILED;1738 }1739 } else {1740 peg$currPos = s0;1741 s0 = peg$FAILED;1742 }1743 peg$silentFails--;1744 if (s0 === peg$FAILED) {1745 s1 = peg$FAILED;1746 if (peg$silentFails === 0) { peg$fail(peg$c50); }1747 }1748 return s0;1749 }1750 function peg$parsedeclare() {1751 var s0, s1, s2, s3;1752 peg$silentFails++;1753 s0 = peg$currPos;1754 if (input.substr(peg$currPos, 7) === peg$c59) {1755 s1 = peg$c59;1756 peg$currPos += 7;1757 } else {1758 s1 = peg$FAILED;1759 if (peg$silentFails === 0) { peg$fail(peg$c60); }1760 }1761 if (s1 === peg$FAILED) {1762 if (input.substr(peg$currPos, 7) === peg$c61) {1763 s1 = peg$c61;1764 peg$currPos += 7;1765 } else {1766 s1 = peg$FAILED;1767 if (peg$silentFails === 0) { peg$fail(peg$c62); }1768 }1769 }1770 if (s1 !== peg$FAILED) {1771 s2 = [];1772 if (peg$c63.test(input.charAt(peg$currPos))) {1773 s3 = input.charAt(peg$currPos);1774 peg$currPos++;1775 } else {1776 s3 = peg$FAILED;1777 if (peg$silentFails === 0) { peg$fail(peg$c64); }1778 }1779 if (s3 !== peg$FAILED) {1780 while (s3 !== peg$FAILED) {1781 s2.push(s3);1782 if (peg$c63.test(input.charAt(peg$currPos))) {1783 s3 = input.charAt(peg$currPos);1784 peg$currPos++;1785 } else {1786 s3 = peg$FAILED;1787 if (peg$silentFails === 0) { peg$fail(peg$c64); }1788 }1789 }1790 } else {1791 s2 = peg$FAILED;1792 }1793 if (s2 !== peg$FAILED) {1794 if (input.charCodeAt(peg$currPos) === 59) {1795 s3 = peg$c45;1796 peg$currPos++;1797 } else {1798 s3 = peg$FAILED;1799 if (peg$silentFails === 0) { peg$fail(peg$c46); }1800 }1801 if (s3 === peg$FAILED) {1802 if (input.charCodeAt(peg$currPos) === 10) {1803 s3 = peg$c47;1804 peg$currPos++;1805 } else {1806 s3 = peg$FAILED;1807 if (peg$silentFails === 0) { peg$fail(peg$c48); }1808 }1809 }1810 if (s3 !== peg$FAILED) {1811 s1 = [s1, s2, s3];1812 s0 = s1;1813 } else {1814 peg$currPos = s0;1815 s0 = peg$FAILED;1816 }1817 } else {1818 peg$currPos = s0;1819 s0 = peg$FAILED;1820 }1821 } else {1822 peg$currPos = s0;1823 s0 = peg$FAILED;1824 }1825 peg$silentFails--;1826 if (s0 === peg$FAILED) {1827 s1 = peg$FAILED;1828 if (peg$silentFails === 0) { peg$fail(peg$c58); }1829 }1830 return s0;1831 }1832 function peg$parsevariableAssignment() {1833 var s0, s1, s2, s3;1834 peg$silentFails++;1835 s0 = peg$currPos;1836 s1 = peg$parsewritableVariableName();1837 if (s1 !== peg$FAILED) {1838 if (input.charCodeAt(peg$currPos) === 61) {1839 s2 = peg$c66;1840 peg$currPos++;1841 } else {1842 s2 = peg$FAILED;1843 if (peg$silentFails === 0) { peg$fail(peg$c67); }1844 }1845 if (s2 !== peg$FAILED) {1846 s3 = peg$parseargument();1847 if (s3 === peg$FAILED) {1848 s3 = null;1849 }1850 if (s3 !== peg$FAILED) {1851 peg$savedPos = s0;1852 s1 = peg$c68(s1, s3);1853 s0 = s1;1854 } else {1855 peg$currPos = s0;1856 s0 = peg$FAILED;1857 }1858 } else {1859 peg$currPos = s0;1860 s0 = peg$FAILED;1861 }1862 } else {1863 peg$currPos = s0;1864 s0 = peg$FAILED;1865 }1866 peg$silentFails--;1867 if (s0 === peg$FAILED) {1868 s1 = peg$FAILED;1869 if (peg$silentFails === 0) { peg$fail(peg$c65); }1870 }1871 return s0;1872 }1873 function peg$parsecommandName() {1874 var s0, s1, s2, s3, s4;1875 peg$silentFails++;1876 s0 = peg$currPos;1877 s1 = peg$currPos;1878 peg$silentFails++;1879 s2 = peg$parseredirect();1880 peg$silentFails--;1881 if (s2 === peg$FAILED) {1882 s1 = void 0;1883 } else {1884 peg$currPos = s1;1885 s1 = peg$FAILED;1886 }1887 if (s1 !== peg$FAILED) {1888 s2 = peg$currPos;1889 peg$silentFails++;1890 s3 = peg$parsekeyword();1891 peg$silentFails--;1892 if (s3 === peg$FAILED) {1893 s2 = void 0;1894 } else {1895 peg$currPos = s2;1896 s2 = peg$FAILED;1897 }1898 if (s2 !== peg$FAILED) {1899 s3 = peg$currPos;1900 peg$silentFails++;1901 s4 = peg$parsevariableAssignment();1902 peg$silentFails--;1903 if (s4 === peg$FAILED) {1904 s3 = void 0;1905 } else {1906 peg$currPos = s3;1907 s3 = peg$FAILED;1908 }1909 if (s3 !== peg$FAILED) {1910 s4 = peg$parseconcatenation();1911 if (s4 === peg$FAILED) {1912 s4 = peg$parsebuiltinCommandName();1913 }1914 if (s4 !== peg$FAILED) {1915 peg$savedPos = s0;1916 s1 = peg$c70(s4);1917 s0 = s1;1918 } else {1919 peg$currPos = s0;1920 s0 = peg$FAILED;1921 }1922 } else {1923 peg$currPos = s0;1924 s0 = peg$FAILED;1925 }1926 } else {1927 peg$currPos = s0;1928 s0 = peg$FAILED;1929 }1930 } else {1931 peg$currPos = s0;1932 s0 = peg$FAILED;1933 }1934 peg$silentFails--;1935 if (s0 === peg$FAILED) {1936 s1 = peg$FAILED;1937 if (peg$silentFails === 0) { peg$fail(peg$c69); }1938 }1939 return s0;1940 }1941 function peg$parsebuiltinCommandName() {1942 var s0;1943 if (input.substr(peg$currPos, 2) === peg$c71) {1944 s0 = peg$c71;1945 peg$currPos += 2;1946 } else {1947 s0 = peg$FAILED;1948 if (peg$silentFails === 0) { peg$fail(peg$c72); }1949 }1950 if (s0 === peg$FAILED) {1951 if (input.charCodeAt(peg$currPos) === 91) {1952 s0 = peg$c73;1953 peg$currPos++;1954 } else {1955 s0 = peg$FAILED;1956 if (peg$silentFails === 0) { peg$fail(peg$c74); }1957 }1958 }1959 return s0;1960 }1961 function peg$parseargument() {1962 var s0, s1;1963 peg$silentFails++;1964 s0 = peg$parsecommandName();1965 if (s0 === peg$FAILED) {1966 s0 = peg$parseprocessSubstitution();1967 }1968 peg$silentFails--;1969 if (s0 === peg$FAILED) {1970 s1 = peg$FAILED;1971 if (peg$silentFails === 0) { peg$fail(peg$c75); }1972 }1973 return s0;1974 }1975 function peg$parseconcatenation() {1976 var s0, s1, s2;1977 peg$silentFails++;1978 s0 = peg$currPos;1979 s1 = [];1980 s2 = peg$parseglob();1981 if (s2 === peg$FAILED) {1982 s2 = peg$parsebareword();1983 if (s2 === peg$FAILED) {1984 s2 = peg$parseenvironmentVariable();1985 if (s2 === peg$FAILED) {1986 s2 = peg$parsevariableSubstitution();1987 if (s2 === peg$FAILED) {1988 s2 = peg$parsecommandSubstitution();1989 if (s2 === peg$FAILED) {1990 s2 = peg$parsesingleQuote();1991 if (s2 === peg$FAILED) {1992 s2 = peg$parsedoubleQuote();1993 }1994 }1995 }1996 }1997 }1998 }1999 if (s2 !== peg$FAILED) {2000 while (s2 !== peg$FAILED) {2001 s1.push(s2);2002 s2 = peg$parseglob();2003 if (s2 === peg$FAILED) {2004 s2 = peg$parsebareword();2005 if (s2 === peg$FAILED) {2006 s2 = peg$parseenvironmentVariable();2007 if (s2 === peg$FAILED) {2008 s2 = peg$parsevariableSubstitution();2009 if (s2 === peg$FAILED) {2010 s2 = peg$parsecommandSubstitution();2011 if (s2 === peg$FAILED) {2012 s2 = peg$parsesingleQuote();2013 if (s2 === peg$FAILED) {2014 s2 = peg$parsedoubleQuote();2015 }2016 }2017 }2018 }2019 }2020 }2021 }2022 } else {2023 s1 = peg$FAILED;2024 }2025 if (s1 !== peg$FAILED) {2026 peg$savedPos = s0;2027 s1 = peg$c77(s1);2028 }2029 s0 = s1;2030 peg$silentFails--;2031 if (s0 === peg$FAILED) {2032 s1 = peg$FAILED;2033 if (peg$silentFails === 0) { peg$fail(peg$c76); }2034 }2035 return s0;2036 }2037 function peg$parsebareword() {2038 var s0, s1, s2, s3;2039 peg$silentFails++;2040 s0 = peg$currPos;2041 s1 = peg$currPos;2042 peg$silentFails++;2043 if (input.charCodeAt(peg$currPos) === 35) {2044 s2 = peg$c79;2045 peg$currPos++;2046 } else {2047 s2 = peg$FAILED;2048 if (peg$silentFails === 0) { peg$fail(peg$c80); }2049 }2050 peg$silentFails--;2051 if (s2 === peg$FAILED) {2052 s1 = void 0;2053 } else {2054 peg$currPos = s1;2055 s1 = peg$FAILED;2056 }2057 if (s1 !== peg$FAILED) {2058 s2 = [];2059 s3 = peg$parsebarewordChar();2060 if (s3 !== peg$FAILED) {2061 while (s3 !== peg$FAILED) {2062 s2.push(s3);2063 s3 = peg$parsebarewordChar();2064 }2065 } else {2066 s2 = peg$FAILED;2067 }2068 if (s2 !== peg$FAILED) {2069 peg$savedPos = s0;2070 s1 = peg$c81(s2);2071 s0 = s1;2072 } else {2073 peg$currPos = s0;2074 s0 = peg$FAILED;2075 }2076 } else {2077 peg$currPos = s0;2078 s0 = peg$FAILED;2079 }2080 peg$silentFails--;2081 if (s0 === peg$FAILED) {2082 s1 = peg$FAILED;2083 if (peg$silentFails === 0) { peg$fail(peg$c78); }2084 }2085 return s0;2086 }2087 function peg$parsebarewordChar() {2088 var s0, s1, s2;2089 s0 = peg$currPos;2090 if (input.charCodeAt(peg$currPos) === 92) {2091 s1 = peg$c82;2092 peg$currPos++;2093 } else {2094 s1 = peg$FAILED;2095 if (peg$silentFails === 0) { peg$fail(peg$c83); }2096 }2097 if (s1 !== peg$FAILED) {2098 s2 = peg$parsebarewordMeta();2099 if (s2 !== peg$FAILED) {2100 peg$savedPos = s0;2101 s1 = peg$c84(s2);2102 s0 = s1;2103 } else {2104 peg$currPos = s0;2105 s0 = peg$FAILED;2106 }2107 } else {2108 peg$currPos = s0;2109 s0 = peg$FAILED;2110 }2111 if (s0 === peg$FAILED) {2112 s0 = peg$currPos;2113 s1 = peg$currPos;2114 peg$silentFails++;2115 s2 = peg$parsebarewordMeta();2116 peg$silentFails--;2117 if (s2 === peg$FAILED) {2118 s1 = void 0;2119 } else {2120 peg$currPos = s1;2121 s1 = peg$FAILED;2122 }2123 if (s1 !== peg$FAILED) {2124 if (input.length > peg$currPos) {2125 s2 = input.charAt(peg$currPos);2126 peg$currPos++;2127 } else {2128 s2 = peg$FAILED;2129 if (peg$silentFails === 0) { peg$fail(peg$c85); }2130 }2131 if (s2 !== peg$FAILED) {2132 peg$savedPos = s0;2133 s1 = peg$c84(s2);2134 s0 = s1;2135 } else {2136 peg$currPos = s0;2137 s0 = peg$FAILED;2138 }2139 } else {2140 peg$currPos = s0;2141 s0 = peg$FAILED;2142 }2143 }2144 return s0;2145 }2146 function peg$parsebarewordMeta() {2147 var s0;2148 if (peg$c86.test(input.charAt(peg$currPos))) {2149 s0 = input.charAt(peg$currPos);2150 peg$currPos++;2151 } else {2152 s0 = peg$FAILED;2153 if (peg$silentFails === 0) { peg$fail(peg$c87); }2154 }2155 return s0;2156 }2157 function peg$parseglob() {2158 var s0, s1, s2, s3, s4;2159 s0 = peg$currPos;2160 s1 = [];2161 s2 = peg$parsebarewordChar();2162 while (s2 !== peg$FAILED) {2163 s1.push(s2);2164 s2 = peg$parsebarewordChar();2165 }2166 if (s1 !== peg$FAILED) {2167 s2 = [];2168 if (input.charCodeAt(peg$currPos) === 42) {2169 s3 = peg$c88;2170 peg$currPos++;2171 } else {2172 s3 = peg$FAILED;2173 if (peg$silentFails === 0) { peg$fail(peg$c89); }2174 }2175 if (s3 === peg$FAILED) {2176 if (input.charCodeAt(peg$currPos) === 63) {2177 s3 = peg$c90;2178 peg$currPos++;2179 } else {2180 s3 = peg$FAILED;2181 if (peg$silentFails === 0) { peg$fail(peg$c91); }2182 }2183 if (s3 === peg$FAILED) {2184 s3 = peg$parsecharacterRange();2185 if (s3 === peg$FAILED) {2186 s3 = peg$parsebraceExpansion();2187 }2188 }2189 }2190 if (s3 !== peg$FAILED) {2191 while (s3 !== peg$FAILED) {2192 s2.push(s3);2193 if (input.charCodeAt(peg$currPos) === 42) {2194 s3 = peg$c88;2195 peg$currPos++;2196 } else {2197 s3 = peg$FAILED;2198 if (peg$silentFails === 0) { peg$fail(peg$c89); }2199 }2200 if (s3 === peg$FAILED) {2201 if (input.charCodeAt(peg$currPos) === 63) {2202 s3 = peg$c90;2203 peg$currPos++;2204 } else {2205 s3 = peg$FAILED;2206 if (peg$silentFails === 0) { peg$fail(peg$c91); }2207 }2208 if (s3 === peg$FAILED) {2209 s3 = peg$parsecharacterRange();2210 if (s3 === peg$FAILED) {2211 s3 = peg$parsebraceExpansion();2212 }2213 }2214 }2215 }2216 } else {2217 s2 = peg$FAILED;2218 }2219 if (s2 !== peg$FAILED) {2220 s3 = [];2221 s4 = peg$parsebarewordChar();2222 while (s4 !== peg$FAILED) {2223 s3.push(s4);2224 s4 = peg$parsebarewordChar();2225 }2226 if (s3 !== peg$FAILED) {2227 peg$savedPos = s0;2228 s1 = peg$c92();2229 s0 = s1;2230 } else {2231 peg$currPos = s0;2232 s0 = peg$FAILED;2233 }2234 } else {2235 peg$currPos = s0;2236 s0 = peg$FAILED;2237 }2238 } else {2239 peg$currPos = s0;2240 s0 = peg$FAILED;2241 }2242 return s0;2243 }2244 function peg$parsecharacterRange() {2245 var s0, s1, s2, s3, s4, s5, s6, s7, s8;2246 s0 = peg$currPos;2247 s1 = peg$currPos;2248 if (input.charCodeAt(peg$currPos) === 91) {2249 s2 = peg$c73;2250 peg$currPos++;2251 } else {2252 s2 = peg$FAILED;2253 if (peg$silentFails === 0) { peg$fail(peg$c74); }2254 }2255 if (s2 !== peg$FAILED) {2256 s3 = peg$currPos;2257 peg$silentFails++;2258 if (input.charCodeAt(peg$currPos) === 45) {2259 s4 = peg$c53;2260 peg$currPos++;2261 } else {2262 s4 = peg$FAILED;2263 if (peg$silentFails === 0) { peg$fail(peg$c54); }2264 }2265 peg$silentFails--;2266 if (s4 === peg$FAILED) {2267 s3 = void 0;2268 } else {2269 peg$currPos = s3;2270 s3 = peg$FAILED;2271 }2272 if (s3 !== peg$FAILED) {2273 if (input.length > peg$currPos) {2274 s4 = input.charAt(peg$currPos);2275 peg$currPos++;2276 } else {2277 s4 = peg$FAILED;2278 if (peg$silentFails === 0) { peg$fail(peg$c85); }2279 }2280 if (s4 !== peg$FAILED) {2281 if (input.charCodeAt(peg$currPos) === 45) {2282 s5 = peg$c53;2283 peg$currPos++;2284 } else {2285 s5 = peg$FAILED;2286 if (peg$silentFails === 0) { peg$fail(peg$c54); }2287 }2288 if (s5 !== peg$FAILED) {2289 s6 = peg$currPos;2290 peg$silentFails++;2291 if (input.charCodeAt(peg$currPos) === 45) {2292 s7 = peg$c53;2293 peg$currPos++;2294 } else {2295 s7 = peg$FAILED;2296 if (peg$silentFails === 0) { peg$fail(peg$c54); }2297 }2298 peg$silentFails--;2299 if (s7 === peg$FAILED) {2300 s6 = void 0;2301 } else {2302 peg$currPos = s6;2303 s6 = peg$FAILED;2304 }2305 if (s6 !== peg$FAILED) {2306 if (input.length > peg$currPos) {2307 s7 = input.charAt(peg$currPos);2308 peg$currPos++;2309 } else {2310 s7 = peg$FAILED;2311 if (peg$silentFails === 0) { peg$fail(peg$c85); }2312 }2313 if (s7 !== peg$FAILED) {2314 if (input.charCodeAt(peg$currPos) === 93) {2315 s8 = peg$c93;2316 peg$currPos++;2317 } else {2318 s8 = peg$FAILED;2319 if (peg$silentFails === 0) { peg$fail(peg$c94); }2320 }2321 if (s8 !== peg$FAILED) {2322 s2 = [s2, s3, s4, s5, s6, s7, s8];2323 s1 = s2;2324 } else {2325 peg$currPos = s1;2326 s1 = peg$FAILED;2327 }2328 } else {2329 peg$currPos = s1;2330 s1 = peg$FAILED;2331 }2332 } else {2333 peg$currPos = s1;2334 s1 = peg$FAILED;2335 }2336 } else {2337 peg$currPos = s1;2338 s1 = peg$FAILED;2339 }2340 } else {2341 peg$currPos = s1;2342 s1 = peg$FAILED;2343 }2344 } else {2345 peg$currPos = s1;2346 s1 = peg$FAILED;2347 }2348 } else {2349 peg$currPos = s1;2350 s1 = peg$FAILED;2351 }2352 if (s1 !== peg$FAILED) {2353 s0 = input.substring(s0, peg$currPos);2354 } else {2355 s0 = s1;2356 }2357 return s0;2358 }2359 function peg$parsebraceExpansion() {2360 var s0, s1, s2, s3, s4;2361 s0 = peg$currPos;2362 s1 = peg$currPos;2363 if (input.length > peg$currPos) {2364 s2 = input.charAt(peg$currPos);2365 peg$currPos++;2366 } else {2367 s2 = peg$FAILED;2368 if (peg$silentFails === 0) { peg$fail(peg$c85); }2369 }2370 if (s2 === peg$FAILED) {2371 s2 = null;2372 }2373 if (s2 !== peg$FAILED) {2374 s3 = peg$currPos;2375 peg$silentFails++;2376 if (input.charCodeAt(peg$currPos) === 36) {2377 s4 = peg$c95;2378 peg$currPos++;2379 } else {2380 s4 = peg$FAILED;2381 if (peg$silentFails === 0) { peg$fail(peg$c96); }2382 }2383 peg$silentFails--;2384 if (s4 === peg$FAILED) {2385 s3 = void 0;2386 } else {2387 peg$currPos = s3;2388 s3 = peg$FAILED;2389 }2390 if (s3 !== peg$FAILED) {2391 s2 = [s2, s3];2392 s1 = s2;2393 } else {2394 peg$currPos = s1;2395 s1 = peg$FAILED;2396 }2397 } else {2398 peg$currPos = s1;2399 s1 = peg$FAILED;2400 }2401 if (s1 !== peg$FAILED) {2402 if (input.charCodeAt(peg$currPos) === 123) {2403 s2 = peg$c97;2404 peg$currPos++;2405 } else {2406 s2 = peg$FAILED;2407 if (peg$silentFails === 0) { peg$fail(peg$c98); }2408 }2409 if (s2 !== peg$FAILED) {2410 s3 = [];2411 s4 = peg$parsebarewordChar();2412 if (s4 !== peg$FAILED) {2413 while (s4 !== peg$FAILED) {2414 s3.push(s4);2415 s4 = peg$parsebarewordChar();2416 }2417 } else {2418 s3 = peg$FAILED;2419 }2420 if (s3 !== peg$FAILED) {2421 if (input.charCodeAt(peg$currPos) === 125) {2422 s4 = peg$c99;2423 peg$currPos++;2424 } else {2425 s4 = peg$FAILED;2426 if (peg$silentFails === 0) { peg$fail(peg$c100); }2427 }2428 if (s4 !== peg$FAILED) {2429 s1 = [s1, s2, s3, s4];2430 s0 = s1;2431 } else {2432 peg$currPos = s0;2433 s0 = peg$FAILED;2434 }2435 } else {2436 peg$currPos = s0;2437 s0 = peg$FAILED;2438 }2439 } else {2440 peg$currPos = s0;2441 s0 = peg$FAILED;2442 }2443 } else {2444 peg$currPos = s0;2445 s0 = peg$FAILED;2446 }2447 return s0;2448 }2449 function peg$parsesingleQuote() {2450 var s0, s1, s2, s3, s4;2451 s0 = peg$currPos;2452 if (input.charCodeAt(peg$currPos) === 39) {2453 s1 = peg$c101;2454 peg$currPos++;2455 } else {2456 s1 = peg$FAILED;2457 if (peg$silentFails === 0) { peg$fail(peg$c102); }2458 }2459 if (s1 !== peg$FAILED) {2460 s2 = peg$currPos;2461 s3 = [];2462 if (peg$c103.test(input.charAt(peg$currPos))) {2463 s4 = input.charAt(peg$currPos);2464 peg$currPos++;2465 } else {2466 s4 = peg$FAILED;2467 if (peg$silentFails === 0) { peg$fail(peg$c104); }2468 }2469 while (s4 !== peg$FAILED) {2470 s3.push(s4);2471 if (peg$c103.test(input.charAt(peg$currPos))) {2472 s4 = input.charAt(peg$currPos);2473 peg$currPos++;2474 } else {2475 s4 = peg$FAILED;2476 if (peg$silentFails === 0) { peg$fail(peg$c104); }2477 }2478 }2479 if (s3 !== peg$FAILED) {2480 s2 = input.substring(s2, peg$currPos);2481 } else {2482 s2 = s3;2483 }2484 if (s2 !== peg$FAILED) {2485 if (input.charCodeAt(peg$currPos) === 39) {2486 s3 = peg$c101;2487 peg$currPos++;2488 } else {2489 s3 = peg$FAILED;2490 if (peg$silentFails === 0) { peg$fail(peg$c102); }2491 }2492 if (s3 !== peg$FAILED) {2493 peg$savedPos = s0;2494 s1 = peg$c105(s2);2495 s0 = s1;2496 } else {2497 peg$currPos = s0;2498 s0 = peg$FAILED;2499 }2500 } else {2501 peg$currPos = s0;2502 s0 = peg$FAILED;2503 }2504 } else {2505 peg$currPos = s0;2506 s0 = peg$FAILED;2507 }2508 return s0;2509 }2510 function peg$parsedoubleQuote() {2511 var s0, s1, s2, s3, s4;2512 s0 = peg$currPos;2513 if (input.charCodeAt(peg$currPos) === 34) {2514 s1 = peg$c106;2515 peg$currPos++;2516 } else {2517 s1 = peg$FAILED;2518 if (peg$silentFails === 0) { peg$fail(peg$c107); }2519 }2520 if (s1 !== peg$FAILED) {2521 s2 = [];2522 s3 = peg$parseexpandsInQuotes();2523 if (s3 === peg$FAILED) {2524 s3 = [];2525 s4 = peg$parsedoubleQuoteChar();2526 if (s4 !== peg$FAILED) {2527 while (s4 !== peg$FAILED) {2528 s3.push(s4);2529 s4 = peg$parsedoubleQuoteChar();2530 }2531 } else {2532 s3 = peg$FAILED;2533 }2534 }2535 while (s3 !== peg$FAILED) {2536 s2.push(s3);2537 s3 = peg$parseexpandsInQuotes();2538 if (s3 === peg$FAILED) {2539 s3 = [];2540 s4 = peg$parsedoubleQuoteChar();2541 if (s4 !== peg$FAILED) {2542 while (s4 !== peg$FAILED) {2543 s3.push(s4);2544 s4 = peg$parsedoubleQuoteChar();2545 }2546 } else {2547 s3 = peg$FAILED;2548 }2549 }2550 }2551 if (s2 !== peg$FAILED) {2552 if (input.charCodeAt(peg$currPos) === 34) {2553 s3 = peg$c106;2554 peg$currPos++;2555 } else {2556 s3 = peg$FAILED;2557 if (peg$silentFails === 0) { peg$fail(peg$c107); }2558 }2559 if (s3 !== peg$FAILED) {2560 peg$savedPos = s0;2561 s1 = peg$c108(s2);2562 s0 = s1;2563 } else {2564 peg$currPos = s0;2565 s0 = peg$FAILED;2566 }2567 } else {2568 peg$currPos = s0;2569 s0 = peg$FAILED;2570 }2571 } else {2572 peg$currPos = s0;2573 s0 = peg$FAILED;2574 }2575 return s0;2576 }2577 function peg$parsedoubleQuoteChar() {2578 var s0, s1, s2;2579 s0 = peg$currPos;2580 if (input.charCodeAt(peg$currPos) === 92) {2581 s1 = peg$c82;2582 peg$currPos++;2583 } else {2584 s1 = peg$FAILED;2585 if (peg$silentFails === 0) { peg$fail(peg$c83); }2586 }2587 if (s1 !== peg$FAILED) {2588 s2 = peg$parsedoubleQuoteMeta();2589 if (s2 !== peg$FAILED) {2590 peg$savedPos = s0;2591 s1 = peg$c84(s2);2592 s0 = s1;2593 } else {2594 peg$currPos = s0;2595 s0 = peg$FAILED;2596 }2597 } else {2598 peg$currPos = s0;2599 s0 = peg$FAILED;2600 }2601 if (s0 === peg$FAILED) {2602 s0 = peg$currPos;2603 if (input.substr(peg$currPos, 2) === peg$c109) {2604 s1 = peg$c109;2605 peg$currPos += 2;2606 } else {2607 s1 = peg$FAILED;2608 if (peg$silentFails === 0) { peg$fail(peg$c110); }2609 }2610 if (s1 !== peg$FAILED) {2611 peg$savedPos = s0;2612 s1 = peg$c111();2613 }2614 s0 = s1;2615 if (s0 === peg$FAILED) {2616 s0 = peg$currPos;2617 s1 = peg$currPos;2618 peg$silentFails++;2619 s2 = peg$parsedoubleQuoteMeta();2620 peg$silentFails--;2621 if (s2 === peg$FAILED) {2622 s1 = void 0;2623 } else {2624 peg$currPos = s1;2625 s1 = peg$FAILED;2626 }2627 if (s1 !== peg$FAILED) {2628 if (input.length > peg$currPos) {2629 s2 = input.charAt(peg$currPos);2630 peg$currPos++;2631 } else {2632 s2 = peg$FAILED;2633 if (peg$silentFails === 0) { peg$fail(peg$c85); }2634 }2635 if (s2 !== peg$FAILED) {2636 peg$savedPos = s0;2637 s1 = peg$c84(s2);2638 s0 = s1;2639 } else {2640 peg$currPos = s0;2641 s0 = peg$FAILED;2642 }2643 } else {2644 peg$currPos = s0;2645 s0 = peg$FAILED;2646 }2647 }2648 }2649 return s0;2650 }2651 function peg$parsedoubleQuoteMeta() {2652 var s0;2653 if (input.charCodeAt(peg$currPos) === 34) {2654 s0 = peg$c106;2655 peg$currPos++;2656 } else {2657 s0 = peg$FAILED;2658 if (peg$silentFails === 0) { peg$fail(peg$c107); }2659 }2660 if (s0 === peg$FAILED) {2661 if (input.charCodeAt(peg$currPos) === 36) {2662 s0 = peg$c95;2663 peg$currPos++;2664 } else {2665 s0 = peg$FAILED;2666 if (peg$silentFails === 0) { peg$fail(peg$c96); }2667 }2668 if (s0 === peg$FAILED) {2669 if (input.charCodeAt(peg$currPos) === 96) {2670 s0 = peg$c112;2671 peg$currPos++;2672 } else {2673 s0 = peg$FAILED;2674 if (peg$silentFails === 0) { peg$fail(peg$c113); }2675 }2676 }2677 }2678 return s0;2679 }2680 function peg$parseexpandsInQuotes() {2681 var s0;2682 s0 = peg$parsecommandSubstitution();2683 if (s0 === peg$FAILED) {2684 s0 = peg$parseenvironmentVariable();2685 if (s0 === peg$FAILED) {2686 s0 = peg$parsevariableSubstitution();2687 }2688 }2689 return s0;2690 }2691 function peg$parseenvironmentVariable() {2692 var s0, s1, s2;2693 s0 = peg$currPos;2694 if (input.charCodeAt(peg$currPos) === 36) {2695 s1 = peg$c95;2696 peg$currPos++;2697 } else {2698 s1 = peg$FAILED;2699 if (peg$silentFails === 0) { peg$fail(peg$c96); }2700 }2701 if (s1 !== peg$FAILED) {2702 s2 = peg$parsereadableVariableName();2703 if (s2 !== peg$FAILED) {2704 peg$savedPos = s0;2705 s1 = peg$c114(s2);2706 s0 = s1;2707 } else {2708 peg$currPos = s0;2709 s0 = peg$FAILED;2710 }2711 } else {2712 peg$currPos = s0;2713 s0 = peg$FAILED;2714 }2715 return s0;2716 }2717 function peg$parsewritableVariableName() {2718 var s0, s1, s2;2719 s0 = peg$currPos;2720 s1 = [];2721 if (peg$c115.test(input.charAt(peg$currPos))) {2722 s2 = input.charAt(peg$currPos);2723 peg$currPos++;2724 } else {2725 s2 = peg$FAILED;2726 if (peg$silentFails === 0) { peg$fail(peg$c116); }2727 }2728 if (s2 !== peg$FAILED) {2729 while (s2 !== peg$FAILED) {2730 s1.push(s2);2731 if (peg$c115.test(input.charAt(peg$currPos))) {2732 s2 = input.charAt(peg$currPos);2733 peg$currPos++;2734 } else {2735 s2 = peg$FAILED;2736 if (peg$silentFails === 0) { peg$fail(peg$c116); }2737 }2738 }2739 } else {2740 s1 = peg$FAILED;2741 }2742 if (s1 !== peg$FAILED) {2743 peg$savedPos = s0;2744 s1 = peg$c117();2745 }2746 s0 = s1;2747 return s0;2748 }2749 function peg$parsereadableVariableName() {2750 var s0;2751 s0 = peg$parsewritableVariableName();2752 if (s0 === peg$FAILED) {2753 if (input.charCodeAt(peg$currPos) === 63) {2754 s0 = peg$c90;2755 peg$currPos++;2756 } else {2757 s0 = peg$FAILED;2758 if (peg$silentFails === 0) { peg$fail(peg$c91); }2759 }2760 }2761 return s0;2762 }2763 function peg$parsevariableSubstitution() {2764 var s0, s1, s2, s3;2765 s0 = peg$currPos;2766 if (input.substr(peg$currPos, 2) === peg$c118) {2767 s1 = peg$c118;2768 peg$currPos += 2;2769 } else {2770 s1 = peg$FAILED;2771 if (peg$silentFails === 0) { peg$fail(peg$c119); }2772 }2773 if (s1 !== peg$FAILED) {2774 s2 = [];2775 if (peg$c120.test(input.charAt(peg$currPos))) {2776 s3 = input.charAt(peg$currPos);2777 peg$currPos++;2778 } else {2779 s3 = peg$FAILED;2780 if (peg$silentFails === 0) { peg$fail(peg$c121); }2781 }2782 while (s3 !== peg$FAILED) {2783 s2.push(s3);2784 if (peg$c120.test(input.charAt(peg$currPos))) {2785 s3 = input.charAt(peg$currPos);2786 peg$currPos++;2787 } else {2788 s3 = peg$FAILED;2789 if (peg$silentFails === 0) { peg$fail(peg$c121); }2790 }2791 }2792 if (s2 !== peg$FAILED) {2793 if (input.charCodeAt(peg$currPos) === 125) {2794 s3 = peg$c99;2795 peg$currPos++;2796 } else {2797 s3 = peg$FAILED;2798 if (peg$silentFails === 0) { peg$fail(peg$c100); }2799 }2800 if (s3 !== peg$FAILED) {2801 peg$savedPos = s0;2802 s1 = peg$c122(s2);2803 s0 = s1;2804 } else {2805 peg$currPos = s0;2806 s0 = peg$FAILED;2807 }2808 } else {2809 peg$currPos = s0;2810 s0 = peg$FAILED;2811 }2812 } else {2813 peg$currPos = s0;2814 s0 = peg$FAILED;2815 }2816 return s0;2817 }2818 function peg$parsecommandSubstitution() {2819 var s0;2820 s0 = peg$parseparenCommandSubstitution();2821 if (s0 === peg$FAILED) {2822 s0 = peg$parsebackQuote();2823 }2824 return s0;2825 }2826 function peg$parseparenCommandSubstitution() {2827 var s0, s1, s2, s3;2828 s0 = peg$currPos;2829 if (input.substr(peg$currPos, 2) === peg$c123) {2830 s1 = peg$c123;2831 peg$currPos += 2;2832 } else {2833 s1 = peg$FAILED;2834 if (peg$silentFails === 0) { peg$fail(peg$c124); }2835 }2836 if (s1 !== peg$FAILED) {2837 s2 = peg$parsestatementList();2838 if (s2 !== peg$FAILED) {2839 if (input.charCodeAt(peg$currPos) === 41) {2840 s3 = peg$c11;2841 peg$currPos++;2842 } else {2843 s3 = peg$FAILED;2844 if (peg$silentFails === 0) { peg$fail(peg$c12); }2845 }2846 if (s3 !== peg$FAILED) {2847 peg$savedPos = s0;2848 s1 = peg$c125(s2);2849 s0 = s1;2850 } else {2851 peg$currPos = s0;2852 s0 = peg$FAILED;2853 }2854 } else {2855 peg$currPos = s0;2856 s0 = peg$FAILED;2857 }2858 } else {2859 peg$currPos = s0;2860 s0 = peg$FAILED;2861 }2862 return s0;2863 }2864 function peg$parsebackQuote() {2865 var s0, s1, s2, s3;2866 s0 = peg$currPos;2867 if (input.charCodeAt(peg$currPos) === 96) {2868 s1 = peg$c112;2869 peg$currPos++;2870 } else {2871 s1 = peg$FAILED;2872 if (peg$silentFails === 0) { peg$fail(peg$c113); }2873 }2874 if (s1 !== peg$FAILED) {2875 s2 = [];2876 s3 = peg$parsebackQuoteChar();2877 if (s3 !== peg$FAILED) {2878 while (s3 !== peg$FAILED) {2879 s2.push(s3);2880 s3 = peg$parsebackQuoteChar();2881 }2882 } else {2883 s2 = peg$FAILED;2884 }2885 if (s2 !== peg$FAILED) {2886 if (input.charCodeAt(peg$currPos) === 96) {2887 s3 = peg$c112;2888 peg$currPos++;2889 } else {2890 s3 = peg$FAILED;2891 if (peg$silentFails === 0) { peg$fail(peg$c113); }2892 }2893 if (s3 !== peg$FAILED) {2894 peg$savedPos = s0;2895 s1 = peg$c126(s2);2896 s0 = s1;2897 } else {2898 peg$currPos = s0;2899 s0 = peg$FAILED;2900 }2901 } else {2902 peg$currPos = s0;2903 s0 = peg$FAILED;2904 }2905 } else {2906 peg$currPos = s0;2907 s0 = peg$FAILED;2908 }2909 return s0;2910 }2911 function peg$parsebackQuoteChar() {2912 var s0, s1, s2;2913 s0 = peg$currPos;2914 if (input.substr(peg$currPos, 2) === peg$c127) {2915 s1 = peg$c127;2916 peg$currPos += 2;2917 } else {2918 s1 = peg$FAILED;2919 if (peg$silentFails === 0) { peg$fail(peg$c128); }2920 }2921 if (s1 !== peg$FAILED) {2922 peg$savedPos = s0;2923 s1 = peg$c129();2924 }2925 s0 = s1;2926 if (s0 === peg$FAILED) {2927 s0 = peg$currPos;2928 if (input.substr(peg$currPos, 2) === peg$c109) {2929 s1 = peg$c109;2930 peg$currPos += 2;2931 } else {2932 s1 = peg$FAILED;2933 if (peg$silentFails === 0) { peg$fail(peg$c110); }2934 }2935 if (s1 !== peg$FAILED) {2936 peg$savedPos = s0;2937 s1 = peg$c111();2938 }2939 s0 = s1;2940 if (s0 === peg$FAILED) {2941 s0 = peg$currPos;2942 s1 = peg$currPos;2943 peg$silentFails++;2944 if (input.charCodeAt(peg$currPos) === 96) {2945 s2 = peg$c112;2946 peg$currPos++;2947 } else {2948 s2 = peg$FAILED;2949 if (peg$silentFails === 0) { peg$fail(peg$c113); }2950 }2951 peg$silentFails--;2952 if (s2 === peg$FAILED) {2953 s1 = void 0;2954 } else {2955 peg$currPos = s1;2956 s1 = peg$FAILED;2957 }2958 if (s1 !== peg$FAILED) {2959 if (input.length > peg$currPos) {2960 s2 = input.charAt(peg$currPos);2961 peg$currPos++;2962 } else {2963 s2 = peg$FAILED;2964 if (peg$silentFails === 0) { peg$fail(peg$c85); }2965 }2966 if (s2 !== peg$FAILED) {2967 peg$savedPos = s0;2968 s1 = peg$c84(s2);2969 s0 = s1;2970 } else {2971 peg$currPos = s0;2972 s0 = peg$FAILED;2973 }2974 } else {2975 peg$currPos = s0;2976 s0 = peg$FAILED;2977 }2978 }2979 }2980 return s0;2981 }2982 function peg$parseprocessSubstitution() {2983 var s0, s1, s2, s3, s4;2984 s0 = peg$currPos;2985 if (peg$c130.test(input.charAt(peg$currPos))) {2986 s1 = input.charAt(peg$currPos);2987 peg$currPos++;2988 } else {2989 s1 = peg$FAILED;2990 if (peg$silentFails === 0) { peg$fail(peg$c131); }2991 }2992 if (s1 !== peg$FAILED) {2993 if (input.charCodeAt(peg$currPos) === 40) {2994 s2 = peg$c9;2995 peg$currPos++;2996 } else {2997 s2 = peg$FAILED;2998 if (peg$silentFails === 0) { peg$fail(peg$c10); }2999 }3000 if (s2 !== peg$FAILED) {3001 s3 = peg$parsestatementList();3002 if (s3 !== peg$FAILED) {3003 if (input.charCodeAt(peg$currPos) === 41) {3004 s4 = peg$c11;3005 peg$currPos++;3006 } else {3007 s4 = peg$FAILED;3008 if (peg$silentFails === 0) { peg$fail(peg$c12); }3009 }3010 if (s4 !== peg$FAILED) {3011 peg$savedPos = s0;3012 s1 = peg$c132(s1, s3);3013 s0 = s1;3014 } else {3015 peg$currPos = s0;3016 s0 = peg$FAILED;3017 }3018 } else {3019 peg$currPos = s0;3020 s0 = peg$FAILED;3021 }3022 } else {3023 peg$currPos = s0;3024 s0 = peg$FAILED;3025 }3026 } else {3027 peg$currPos = s0;3028 s0 = peg$FAILED;3029 }3030 return s0;3031 }3032 function peg$parseredirect() {3033 var s0;3034 s0 = peg$parsemoveFd();3035 if (s0 === peg$FAILED) {3036 s0 = peg$parseduplicateFd();3037 if (s0 === peg$FAILED) {3038 s0 = peg$parseredirectFd();3039 }3040 }3041 return s0;3042 }3043 function peg$parsemoveFd() {3044 var s0, s1, s2, s3, s4;3045 s0 = peg$currPos;3046 s1 = peg$parsefd();3047 if (s1 === peg$FAILED) {3048 s1 = null;3049 }3050 if (s1 !== peg$FAILED) {3051 if (input.substr(peg$currPos, 2) === peg$c133) {3052 s2 = peg$c133;3053 peg$currPos += 2;3054 } else {3055 s2 = peg$FAILED;3056 if (peg$silentFails === 0) { peg$fail(peg$c134); }3057 }3058 if (s2 === peg$FAILED) {3059 if (input.substr(peg$currPos, 2) === peg$c135) {3060 s2 = peg$c135;3061 peg$currPos += 2;3062 } else {3063 s2 = peg$FAILED;3064 if (peg$silentFails === 0) { peg$fail(peg$c136); }3065 }3066 }3067 if (s2 !== peg$FAILED) {3068 s3 = peg$parsefd();3069 if (s3 !== peg$FAILED) {3070 if (input.charCodeAt(peg$currPos) === 45) {3071 s4 = peg$c53;3072 peg$currPos++;3073 } else {3074 s4 = peg$FAILED;3075 if (peg$silentFails === 0) { peg$fail(peg$c54); }3076 }3077 if (s4 !== peg$FAILED) {3078 peg$savedPos = s0;3079 s1 = peg$c137(s1, s2, s3);3080 s0 = s1;3081 } else {3082 peg$currPos = s0;3083 s0 = peg$FAILED;3084 }3085 } else {3086 peg$currPos = s0;3087 s0 = peg$FAILED;3088 }3089 } else {3090 peg$currPos = s0;3091 s0 = peg$FAILED;3092 }3093 } else {3094 peg$currPos = s0;3095 s0 = peg$FAILED;3096 }3097 return s0;3098 }3099 function peg$parseduplicateFd() {3100 var s0, s1, s2, s3, s4;3101 s0 = peg$currPos;3102 s1 = peg$parsefd();3103 if (s1 === peg$FAILED) {3104 s1 = null;3105 }3106 if (s1 !== peg$FAILED) {3107 if (input.substr(peg$currPos, 2) === peg$c133) {3108 s2 = peg$c133;3109 peg$currPos += 2;3110 } else {3111 s2 = peg$FAILED;3112 if (peg$silentFails === 0) { peg$fail(peg$c134); }3113 }3114 if (s2 === peg$FAILED) {3115 if (input.substr(peg$currPos, 2) === peg$c135) {3116 s2 = peg$c135;3117 peg$currPos += 2;3118 } else {3119 s2 = peg$FAILED;3120 if (peg$silentFails === 0) { peg$fail(peg$c136); }3121 }3122 }3123 if (s2 !== peg$FAILED) {3124 s3 = [];3125 s4 = peg$parsespace();3126 while (s4 !== peg$FAILED) {3127 s3.push(s4);3128 s4 = peg$parsespace();3129 }3130 if (s3 !== peg$FAILED) {3131 s4 = peg$parsefd();3132 if (s4 !== peg$FAILED) {3133 peg$savedPos = s0;3134 s1 = peg$c138(s1, s2, s4);3135 s0 = s1;3136 } else {3137 peg$currPos = s0;3138 s0 = peg$FAILED;3139 }3140 } else {3141 peg$currPos = s0;3142 s0 = peg$FAILED;3143 }3144 } else {3145 peg$currPos = s0;3146 s0 = peg$FAILED;3147 }3148 } else {3149 peg$currPos = s0;3150 s0 = peg$FAILED;3151 }3152 return s0;3153 }3154 function peg$parseredirectFd() {3155 var s0, s1, s2, s3, s4;3156 s0 = peg$currPos;3157 s1 = peg$parsefd();3158 if (s1 === peg$FAILED) {3159 s1 = null;3160 }3161 if (s1 !== peg$FAILED) {3162 s2 = peg$parseredirectionOperator();3163 if (s2 !== peg$FAILED) {3164 s3 = [];3165 s4 = peg$parsespace();3166 while (s4 !== peg$FAILED) {3167 s3.push(s4);3168 s4 = peg$parsespace();3169 }3170 if (s3 !== peg$FAILED) {3171 s4 = peg$parseargument();3172 if (s4 !== peg$FAILED) {3173 peg$savedPos = s0;3174 s1 = peg$c139(s1, s2, s4);3175 s0 = s1;3176 } else {3177 peg$currPos = s0;3178 s0 = peg$FAILED;3179 }3180 } else {3181 peg$currPos = s0;3182 s0 = peg$FAILED;3183 }3184 } else {3185 peg$currPos = s0;3186 s0 = peg$FAILED;3187 }3188 } else {3189 peg$currPos = s0;3190 s0 = peg$FAILED;3191 }3192 return s0;3193 }3194 function peg$parseredirectionOperator() {3195 var s0;3196 if (input.substr(peg$currPos, 2) === peg$c140) {3197 s0 = peg$c140;3198 peg$currPos += 2;3199 } else {3200 s0 = peg$FAILED;3201 if (peg$silentFails === 0) { peg$fail(peg$c141); }3202 }3203 if (s0 === peg$FAILED) {3204 if (input.substr(peg$currPos, 2) === peg$c142) {3205 s0 = peg$c142;3206 peg$currPos += 2;3207 } else {3208 s0 = peg$FAILED;3209 if (peg$silentFails === 0) { peg$fail(peg$c143); }3210 }3211 if (s0 === peg$FAILED) {3212 if (input.substr(peg$currPos, 3) === peg$c144) {3213 s0 = peg$c144;3214 peg$currPos += 3;3215 } else {3216 s0 = peg$FAILED;3217 if (peg$silentFails === 0) { peg$fail(peg$c145); }3218 }3219 if (s0 === peg$FAILED) {3220 if (input.substr(peg$currPos, 2) === peg$c146) {3221 s0 = peg$c146;3222 peg$currPos += 2;3223 } else {3224 s0 = peg$FAILED;3225 if (peg$silentFails === 0) { peg$fail(peg$c147); }3226 }3227 if (s0 === peg$FAILED) {3228 if (input.charCodeAt(peg$currPos) === 60) {3229 s0 = peg$c148;3230 peg$currPos++;3231 } else {3232 s0 = peg$FAILED;3233 if (peg$silentFails === 0) { peg$fail(peg$c149); }3234 }3235 if (s0 === peg$FAILED) {3236 if (input.charCodeAt(peg$currPos) === 62) {3237 s0 = peg$c150;3238 peg$currPos++;3239 } else {3240 s0 = peg$FAILED;3241 if (peg$silentFails === 0) { peg$fail(peg$c151); }3242 }3243 }3244 }3245 }3246 }3247 }3248 return s0;3249 }3250 function peg$parsefd() {3251 var s0, s1, s2;3252 s0 = peg$currPos;3253 s1 = [];3254 if (peg$c152.test(input.charAt(peg$currPos))) {3255 s2 = input.charAt(peg$currPos);3256 peg$currPos++;3257 } else {3258 s2 = peg$FAILED;3259 if (peg$silentFails === 0) { peg$fail(peg$c153); }3260 }3261 if (s2 !== peg$FAILED) {3262 while (s2 !== peg$FAILED) {3263 s1.push(s2);3264 if (peg$c152.test(input.charAt(peg$currPos))) {3265 s2 = input.charAt(peg$currPos);3266 peg$currPos++;3267 } else {3268 s2 = peg$FAILED;3269 if (peg$silentFails === 0) { peg$fail(peg$c153); }3270 }3271 }3272 } else {3273 s1 = peg$FAILED;3274 }3275 if (s1 !== peg$FAILED) {3276 peg$savedPos = s0;3277 s1 = peg$c154(s1);3278 }3279 s0 = s1;3280 return s0;3281 }3282 function peg$parsecontrolOperator() {3283 var s0, s1, s2;3284 s0 = peg$currPos;3285 s1 = [];3286 s2 = peg$parsespace();3287 while (s2 !== peg$FAILED) {3288 s1.push(s2);3289 s2 = peg$parsespace();3290 }3291 if (s1 !== peg$FAILED) {3292 if (input.charCodeAt(peg$currPos) === 38) {3293 s2 = peg$c155;3294 peg$currPos++;3295 } else {3296 s2 = peg$FAILED;3297 if (peg$silentFails === 0) { peg$fail(peg$c156); }3298 }3299 if (s2 === peg$FAILED) {3300 if (input.charCodeAt(peg$currPos) === 59) {3301 s2 = peg$c45;3302 peg$currPos++;3303 } else {3304 s2 = peg$FAILED;3305 if (peg$silentFails === 0) { peg$fail(peg$c46); }3306 }3307 if (s2 === peg$FAILED) {3308 if (input.charCodeAt(peg$currPos) === 10) {3309 s2 = peg$c47;3310 peg$currPos++;3311 } else {3312 s2 = peg$FAILED;3313 if (peg$silentFails === 0) { peg$fail(peg$c48); }3314 }3315 }3316 }3317 if (s2 !== peg$FAILED) {3318 peg$savedPos = s0;3319 s1 = peg$c157(s2);3320 s0 = s1;3321 } else {3322 peg$currPos = s0;3323 s0 = peg$FAILED;3324 }3325 } else {3326 peg$currPos = s0;3327 s0 = peg$FAILED;3328 }3329 return s0;3330 }3331 function peg$parsepipe() {3332 var s0, s1, s2, s3;3333 s0 = peg$currPos;3334 if (input.charCodeAt(peg$currPos) === 124) {3335 s1 = peg$c158;3336 peg$currPos++;3337 } else {3338 s1 = peg$FAILED;3339 if (peg$silentFails === 0) { peg$fail(peg$c159); }3340 }3341 if (s1 !== peg$FAILED) {3342 s2 = [];3343 s3 = peg$parsespaceNL();3344 while (s3 !== peg$FAILED) {3345 s2.push(s3);3346 s3 = peg$parsespaceNL();3347 }3348 if (s2 !== peg$FAILED) {3349 s3 = peg$parsecommand();3350 if (s3 !== peg$FAILED) {3351 peg$savedPos = s0;3352 s1 = peg$c160(s3);3353 s0 = s1;3354 } else {3355 peg$currPos = s0;3356 s0 = peg$FAILED;3357 }3358 } else {3359 peg$currPos = s0;3360 s0 = peg$FAILED;3361 }3362 } else {3363 peg$currPos = s0;3364 s0 = peg$FAILED;3365 }3366 return s0;3367 }3368 function peg$parsespace() {3369 var s0, s1;3370 peg$silentFails++;3371 if (input.charCodeAt(peg$currPos) === 32) {3372 s0 = peg$c162;3373 peg$currPos++;3374 } else {3375 s0 = peg$FAILED;3376 if (peg$silentFails === 0) { peg$fail(peg$c163); }3377 }3378 if (s0 === peg$FAILED) {3379 if (input.charCodeAt(peg$currPos) === 9) {3380 s0 = peg$c164;3381 peg$currPos++;3382 } else {3383 s0 = peg$FAILED;3384 if (peg$silentFails === 0) { peg$fail(peg$c165); }3385 }3386 }3387 peg$silentFails--;3388 if (s0 === peg$FAILED) {3389 s1 = peg$FAILED;3390 if (peg$silentFails === 0) { peg$fail(peg$c161); }3391 }3392 return s0;3393 }3394 function peg$parsespaceNL() {3395 var s0;3396 s0 = peg$parsespace();3397 if (s0 === peg$FAILED) {3398 if (input.charCodeAt(peg$currPos) === 10) {3399 s0 = peg$c47;3400 peg$currPos++;3401 } else {3402 s0 = peg$FAILED;3403 if (peg$silentFails === 0) { peg$fail(peg$c48); }3404 }3405 if (s0 === peg$FAILED) {3406 s0 = peg$parsecomment();3407 }3408 }3409 return s0;3410 }3411 function peg$parsecomment() {3412 var s0, s1, s2, s3;3413 peg$silentFails++;3414 s0 = peg$currPos;3415 if (input.charCodeAt(peg$currPos) === 35) {3416 s1 = peg$c79;3417 peg$currPos++;3418 } else {3419 s1 = peg$FAILED;3420 if (peg$silentFails === 0) { peg$fail(peg$c80); }3421 }3422 if (s1 !== peg$FAILED) {3423 s2 = [];3424 if (peg$c63.test(input.charAt(peg$currPos))) {3425 s3 = input.charAt(peg$currPos);3426 peg$currPos++;3427 } else {3428 s3 = peg$FAILED;3429 if (peg$silentFails === 0) { peg$fail(peg$c64); }3430 }3431 while (s3 !== peg$FAILED) {3432 s2.push(s3);3433 if (peg$c63.test(input.charAt(peg$currPos))) {3434 s3 = input.charAt(peg$currPos);3435 peg$currPos++;3436 } else {3437 s3 = peg$FAILED;3438 if (peg$silentFails === 0) { peg$fail(peg$c64); }3439 }3440 }3441 if (s2 !== peg$FAILED) {3442 if (input.charCodeAt(peg$currPos) === 10) {3443 s3 = peg$c47;3444 peg$currPos++;3445 } else {3446 s3 = peg$FAILED;3447 if (peg$silentFails === 0) { peg$fail(peg$c48); }3448 }3449 if (s3 === peg$FAILED) {3450 s3 = peg$parseEOF();3451 }3452 if (s3 !== peg$FAILED) {3453 s1 = [s1, s2, s3];3454 s0 = s1;3455 } else {3456 peg$currPos = s0;3457 s0 = peg$FAILED;3458 }3459 } else {3460 peg$currPos = s0;3461 s0 = peg$FAILED;3462 }3463 } else {3464 peg$currPos = s0;3465 s0 = peg$FAILED;3466 }3467 peg$silentFails--;3468 if (s0 === peg$FAILED) {3469 s1 = peg$FAILED;3470 if (peg$silentFails === 0) { peg$fail(peg$c166); }3471 }3472 return s0;3473 }3474 function peg$parsekeyword() {3475 var s0, s1, s2, s3;3476 s0 = peg$currPos;3477 if (input.substr(peg$currPos, 5) === peg$c31) {3478 s1 = peg$c31;3479 peg$currPos += 5;3480 } else {3481 s1 = peg$FAILED;3482 if (peg$silentFails === 0) { peg$fail(peg$c32); }3483 }3484 if (s1 === peg$FAILED) {3485 if (input.substr(peg$currPos, 5) === peg$c33) {3486 s1 = peg$c33;3487 peg$currPos += 5;3488 } else {3489 s1 = peg$FAILED;3490 if (peg$silentFails === 0) { peg$fail(peg$c34); }3491 }3492 if (s1 === peg$FAILED) {3493 if (input.substr(peg$currPos, 3) === peg$c41) {3494 s1 = peg$c41;3495 peg$currPos += 3;3496 } else {3497 s1 = peg$FAILED;3498 if (peg$silentFails === 0) { peg$fail(peg$c42); }3499 }3500 if (s1 === peg$FAILED) {3501 if (input.substr(peg$currPos, 4) === peg$c37) {3502 s1 = peg$c37;3503 peg$currPos += 4;3504 } else {3505 s1 = peg$FAILED;3506 if (peg$silentFails === 0) { peg$fail(peg$c38); }3507 }3508 if (s1 === peg$FAILED) {3509 if (input.substr(peg$currPos, 2) === peg$c35) {3510 s1 = peg$c35;3511 peg$currPos += 2;3512 } else {3513 s1 = peg$FAILED;3514 if (peg$silentFails === 0) { peg$fail(peg$c36); }3515 }3516 if (s1 === peg$FAILED) {3517 if (input.substr(peg$currPos, 4) === peg$c167) {3518 s1 = peg$c167;3519 peg$currPos += 4;3520 } else {3521 s1 = peg$FAILED;3522 if (peg$silentFails === 0) { peg$fail(peg$c168); }3523 }3524 if (s1 === peg$FAILED) {3525 if (input.substr(peg$currPos, 4) === peg$c169) {3526 s1 = peg$c169;3527 peg$currPos += 4;3528 } else {3529 s1 = peg$FAILED;3530 if (peg$silentFails === 0) { peg$fail(peg$c170); }3531 }3532 if (s1 === peg$FAILED) {3533 if (input.substr(peg$currPos, 2) === peg$c18) {3534 s1 = peg$c18;3535 peg$currPos += 2;3536 } else {3537 s1 = peg$FAILED;3538 if (peg$silentFails === 0) { peg$fail(peg$c19); }3539 }3540 if (s1 === peg$FAILED) {3541 if (input.substr(peg$currPos, 4) === peg$c20) {3542 s1 = peg$c20;3543 peg$currPos += 4;3544 } else {3545 s1 = peg$FAILED;3546 if (peg$silentFails === 0) { peg$fail(peg$c21); }3547 }3548 if (s1 === peg$FAILED) {3549 if (input.substr(peg$currPos, 4) === peg$c22) {3550 s1 = peg$c22;3551 peg$currPos += 4;3552 } else {3553 s1 = peg$FAILED;3554 if (peg$silentFails === 0) { peg$fail(peg$c23); }3555 }3556 if (s1 === peg$FAILED) {3557 if (input.substr(peg$currPos, 4) === peg$c27) {3558 s1 = peg$c27;3559 peg$currPos += 4;3560 } else {3561 s1 = peg$FAILED;3562 if (peg$silentFails === 0) { peg$fail(peg$c28); }3563 }3564 if (s1 === peg$FAILED) {3565 if (input.substr(peg$currPos, 2) === peg$c24) {3566 s1 = peg$c24;3567 peg$currPos += 2;3568 } else {3569 s1 = peg$FAILED;3570 if (peg$silentFails === 0) { peg$fail(peg$c25); }3571 }3572 if (s1 === peg$FAILED) {3573 if (input.substr(peg$currPos, 2) === peg$c71) {3574 s1 = peg$c71;3575 peg$currPos += 2;3576 } else {3577 s1 = peg$FAILED;3578 if (peg$silentFails === 0) { peg$fail(peg$c72); }3579 }3580 }3581 }3582 }3583 }3584 }3585 }3586 }3587 }3588 }3589 }3590 }3591 }3592 if (s1 !== peg$FAILED) {3593 s2 = [];3594 s3 = peg$parsespaceNL();3595 if (s3 !== peg$FAILED) {3596 while (s3 !== peg$FAILED) {3597 s2.push(s3);3598 s3 = peg$parsespaceNL();3599 }3600 } else {3601 s2 = peg$FAILED;3602 }3603 if (s2 === peg$FAILED) {3604 s2 = peg$parseEOF();3605 }3606 if (s2 !== peg$FAILED) {3607 s1 = [s1, s2];3608 s0 = s1;3609 } else {3610 peg$currPos = s0;3611 s0 = peg$FAILED;3612 }3613 } else {3614 peg$currPos = s0;3615 s0 = peg$FAILED;3616 }3617 return s0;3618 }3619 function peg$parsecontinuationStart() {3620 var s0, s1, s2, s3;3621 s0 = peg$currPos;3622 s1 = peg$currPos;3623 peg$silentFails++;3624 s2 = peg$parsekeyword();3625 if (s2 === peg$FAILED) {3626 if (input.charCodeAt(peg$currPos) === 34) {3627 s2 = peg$c106;3628 peg$currPos++;3629 } else {3630 s2 = peg$FAILED;3631 if (peg$silentFails === 0) { peg$fail(peg$c107); }3632 }3633 if (s2 === peg$FAILED) {3634 if (input.charCodeAt(peg$currPos) === 39) {3635 s2 = peg$c101;3636 peg$currPos++;3637 } else {3638 s2 = peg$FAILED;3639 if (peg$silentFails === 0) { peg$fail(peg$c102); }3640 }3641 if (s2 === peg$FAILED) {3642 if (input.charCodeAt(peg$currPos) === 96) {3643 s2 = peg$c112;3644 peg$currPos++;3645 } else {3646 s2 = peg$FAILED;3647 if (peg$silentFails === 0) { peg$fail(peg$c113); }3648 }3649 if (s2 === peg$FAILED) {3650 if (input.substr(peg$currPos, 2) === peg$c123) {3651 s2 = peg$c123;3652 peg$currPos += 2;3653 } else {3654 s2 = peg$FAILED;3655 if (peg$silentFails === 0) { peg$fail(peg$c124); }3656 }3657 if (s2 === peg$FAILED) {3658 if (input.substr(peg$currPos, 2) === peg$c118) {3659 s2 = peg$c118;3660 peg$currPos += 2;3661 } else {3662 s2 = peg$FAILED;3663 if (peg$silentFails === 0) { peg$fail(peg$c119); }3664 }3665 }3666 }3667 }3668 }3669 }3670 peg$silentFails--;3671 if (s2 !== peg$FAILED) {3672 peg$currPos = s1;3673 s1 = void 0;3674 } else {3675 s1 = peg$FAILED;3676 }3677 if (s1 !== peg$FAILED) {3678 s2 = [];3679 if (input.length > peg$currPos) {3680 s3 = input.charAt(peg$currPos);3681 peg$currPos++;3682 } else {3683 s3 = peg$FAILED;3684 if (peg$silentFails === 0) { peg$fail(peg$c85); }3685 }3686 while (s3 !== peg$FAILED) {3687 s2.push(s3);3688 if (input.length > peg$currPos) {3689 s3 = input.charAt(peg$currPos);3690 peg$currPos++;3691 } else {3692 s3 = peg$FAILED;3693 if (peg$silentFails === 0) { peg$fail(peg$c85); }3694 }3695 }3696 if (s2 !== peg$FAILED) {3697 s1 = [s1, s2];3698 s0 = s1;3699 } else {3700 peg$currPos = s0;3701 s0 = peg$FAILED;3702 }3703 } else {3704 peg$currPos = s0;3705 s0 = peg$FAILED;3706 }3707 return s0;3708 }3709 function peg$parseEOF() {3710 var s0, s1;3711 s0 = peg$currPos;3712 peg$silentFails++;3713 if (input.length > peg$currPos) {3714 s1 = input.charAt(peg$currPos);3715 peg$currPos++;3716 } else {3717 s1 = peg$FAILED;3718 if (peg$silentFails === 0) { peg$fail(peg$c85); }3719 }3720 peg$silentFails--;3721 if (s1 === peg$FAILED) {3722 s0 = void 0;3723 } else {3724 peg$currPos = s0;3725 s0 = peg$FAILED;3726 }3727 return s0;3728 }3729 var isArray = require("isarray")3730 var map = require("array-map")3731 function join(arr) {3732 return arr.join("")3733 }3734 function literal(string) {3735 return {3736 type: 'literal',3737 value: isArray(string) ? string.join('') : string3738 }3739 }3740 function first(arr) {3741 return arr[0]3742 }3743 function second(arr) {3744 return arr[1]3745 }3746 function flattenConcatenation(pieces) {3747 // TODO - this algo sucks, it's probably on the order of n^43748 var result = [pieces[0]]3749 , len = pieces.length3750 , prev = pieces[0]3751 , current3752 for (var i = 1; i < len; i++) {3753 current = pieces[i]3754 if (current.type == 'concatenation') {3755 current = flattenConcatenation(current.pieces)3756 }3757 if (current.type == 'concatenation') {3758 // it's still a concatenation, append it's pieces to ours3759 result = result.concat(current.pieces)3760 }3761 else if ((current.type == 'literal' || current.type == 'glob')3762 && (prev.type == 'literal' || prev.type == 'glob')) {3763 // globs & literals can be merged3764 prev.value += current.value3765 if (prev.type != 'glob' && current.type == 'glob') {3766 // globs are infectious3767 prev.type = 'glob'3768 }3769 }3770 else {3771 result.push(current)3772 prev = current3773 }3774 }3775 return result.length == 1 ? result[0] : {3776 type: 'concatenation',3777 pieces: result3778 }3779 }3780 peg$result = peg$startRuleFunction();3781 if (peg$result !== peg$FAILED && peg$currPos === input.length) {3782 return peg$result;3783 } else {3784 if (peg$result !== peg$FAILED && peg$currPos < input.length) {3785 peg$fail({ type: "end", description: "end of input" });3786 }3787 throw peg$buildException(3788 null,3789 peg$maxFailExpected,3790 peg$maxFailPos < input.length ? input.charAt(peg$maxFailPos) : null,3791 peg$maxFailPos < input.length3792 ? peg$computeLocation(peg$maxFailPos, peg$maxFailPos + 1)3793 : peg$computeLocation(peg$maxFailPos, peg$maxFailPos)3794 );3795 }3796 }3797 return {3798 SyntaxError: peg$SyntaxError,3799 parse: peg$parse3800 };3801})()...

Full Screen

Full Screen

test_univ.py

Source:test_univ.py Github

copy

Full Screen

1from pyasn1.type import univ, tag, constraint, namedtype, namedval, error2from pyasn1.compat.octets import str2octs, ints2octs3from pyasn1.error import PyAsn1Error4from sys import version_info5if version_info[0:2] < (2, 7) or \6 version_info[0:2] in ( (3, 0), (3, 1) ):7 try:8 import unittest2 as unittest9 except ImportError:10 import unittest11else:12 import unittest13class IntegerTestCase(unittest.TestCase):14 def testStr(self): assert str(univ.Integer(1)) in ('1','1L'),'str() fails'15 def testAnd(self): assert univ.Integer(1) & 0 == 0, '__and__() fails'16 def testOr(self): assert univ.Integer(1) | 0 == 1, '__or__() fails'17 def testXor(self): assert univ.Integer(1) ^ 0 == 1, '__xor__() fails'18 def testRand(self): assert 0 & univ.Integer(1) == 0, '__rand__() fails'19 def testRor(self): assert 0 | univ.Integer(1) == 1, '__ror__() fails'20 def testRxor(self): assert 0 ^ univ.Integer(1) == 1, '__rxor__() fails' 21 def testAdd(self): assert univ.Integer(-4) + 6 == 2, '__add__() fails'22 def testRadd(self): assert 4 + univ.Integer(5) == 9, '__radd__() fails'23 def testSub(self): assert univ.Integer(3) - 6 == -3, '__sub__() fails'24 def testRsub(self): assert 6 - univ.Integer(3) == 3, '__rsub__() fails'25 def testMul(self): assert univ.Integer(3) * -3 == -9, '__mul__() fails'26 def testRmul(self): assert 2 * univ.Integer(3) == 6, '__rmul__() fails'27 def testDiv(self): assert univ.Integer(3) / 2 == 1, '__div__() fails'28 def testRdiv(self): assert 6 / univ.Integer(3) == 2, '__rdiv__() fails'29 def testMod(self): assert univ.Integer(3) % 2 == 1, '__mod__() fails'30 def testRmod(self): assert 4 % univ.Integer(3) == 1, '__rmod__() fails'31 def testPow(self): assert univ.Integer(3) ** 2 == 9, '__pow__() fails'32 def testRpow(self): assert 2 ** univ.Integer(2) == 4, '__rpow__() fails'33 def testLshift(self): assert univ.Integer(1) << 1 == 2, '<< fails'34 def testRshift(self): assert univ.Integer(2) >> 1 == 1, '>> fails'35 def testInt(self): assert int(univ.Integer(3)) == 3, '__int__() fails'36 def testLong(self): assert int(univ.Integer(8)) == 8, '__long__() fails'37 def testFloat(self): assert float(univ.Integer(4))==4.0,'__float__() fails'38 def testPrettyIn(self): assert univ.Integer('3') == 3, 'prettyIn() fails'39 def testTag(self):40 assert univ.Integer().getTagSet() == tag.TagSet(41 (),42 tag.Tag(tag.tagClassUniversal, tag.tagFormatSimple, 0x02)43 )44 def testNamedVals(self):45 i = univ.Integer(46 'asn1', namedValues=univ.Integer.namedValues.clone(('asn1', 1))47 )48 assert i == 1, 'named val fails'49 assert str(i) != 'asn1', 'named val __str__() fails'50class BooleanTestCase(unittest.TestCase):51 def testTruth(self):52 assert univ.Boolean(True) and univ.Boolean(1), 'Truth initializer fails'53 def testFalse(self):54 assert not univ.Boolean(False) and not univ.Boolean(0), 'False initializer fails'55 def testStr(self):56 assert str(univ.Boolean(1)) in ('1', '1L'), 'str() fails'57 def testTag(self):58 assert univ.Boolean().getTagSet() == tag.TagSet(59 (),60 tag.Tag(tag.tagClassUniversal, tag.tagFormatSimple, 0x01)61 )62 def testConstraints(self):63 try:64 univ.Boolean(2)65 except error.ValueConstraintError:66 pass67 else:68 assert 0, 'constraint fail'69 def testSubtype(self):70 assert univ.Integer().subtype(71 value=1,72 implicitTag=tag.Tag(tag.tagClassPrivate,tag.tagFormatSimple,2),73 subtypeSpec=constraint.SingleValueConstraint(1,3)74 ) == univ.Integer(75 value=1,76 tagSet=tag.TagSet(tag.Tag(tag.tagClassPrivate,77 tag.tagFormatSimple,2)),78 subtypeSpec=constraint.ConstraintsIntersection(constraint.SingleValueConstraint(1,3))79 )80class BitStringTestCase(unittest.TestCase):81 def setUp(self):82 self.b = univ.BitString(83 namedValues=namedval.NamedValues(('Active', 0), ('Urgent', 1))84 )85 def testSet(self):86 assert self.b.clone('Active') == (1,)87 assert self.b.clone("'1010100110001010'B") == (1,0,1,0,1,0,0,1,1,0,0,0,1,0,1,0)88 assert self.b.clone("'A98A'H") == (1,0,1,0,1,0,0,1,1,0,0,0,1,0,1,0)89 assert self.b.clone((1,0,1)) == (1,0,1)90 def testStr(self):91 assert str(self.b.clone('Urgent,Active')) == '(1, 1)'92 def testRepr(self):93 assert repr(self.b.clone('Urgent,Active')) == 'BitString("\'11\'B")'94 def testTag(self):95 assert univ.BitString().getTagSet() == tag.TagSet(96 (),97 tag.Tag(tag.tagClassUniversal, tag.tagFormatSimple, 0x03)98 )99 def testLen(self): assert len(self.b.clone("'A98A'H")) == 16100 def testIter(self):101 assert self.b.clone("'A98A'H")[0] == 1102 assert self.b.clone("'A98A'H")[1] == 0103 assert self.b.clone("'A98A'H")[2] == 1104 105class OctetStringTestCase(unittest.TestCase):106 def testInit(self):107 assert univ.OctetString(str2octs('abcd')) == str2octs('abcd'), '__init__() fails'108 def testBinStr(self):109 assert univ.OctetString(binValue="1000010111101110101111000000111011") == ints2octs((133, 238, 188, 14, 192)), 'bin init fails'110 def testHexStr(self):111 assert univ.OctetString(hexValue="FA9823C43E43510DE3422") == ints2octs((250, 152, 35, 196, 62, 67, 81, 13, 227, 66, 32)), 'hex init fails'112 def testTuple(self):113 assert univ.OctetString((1,2,3,4,5)) == ints2octs((1,2,3,4,5)), 'tuple init failed'114 def testStr(self):115 assert str(univ.OctetString('q')) == 'q', '__str__() fails'116 def testSeq(self):117 assert univ.OctetString('q')[0] == str2octs('q')[0],'__getitem__() fails'118 def testAsOctets(self):119 assert univ.OctetString('abcd').asOctets() == str2octs('abcd'), 'testAsOctets() fails'120 def testAsInts(self):121 assert univ.OctetString('abcd').asNumbers() == (97, 98, 99, 100), 'testAsNumbers() fails'122 def testEmpty(self):123 try:124 str(univ.OctetString())125 except PyAsn1Error:126 pass127 else:128 assert 0, 'empty OctetString() not reported'129 130 def testAdd(self):131 assert univ.OctetString('') + 'q' == str2octs('q'), '__add__() fails'132 def testRadd(self):133 assert 'b' + univ.OctetString('q') == str2octs('bq'), '__radd__() fails'134 def testMul(self):135 assert univ.OctetString('a') * 2 == str2octs('aa'), '__mul__() fails'136 def testRmul(self):137 assert 2 * univ.OctetString('b') == str2octs('bb'), '__rmul__() fails'138 def testTag(self):139 assert univ.OctetString().getTagSet() == tag.TagSet(140 (),141 tag.Tag(tag.tagClassUniversal, tag.tagFormatSimple, 0x04)142 )143class Null(unittest.TestCase):144 def testStr(self): assert str(univ.Null('')) == '', 'str() fails'145 def testTag(self):146 assert univ.Null().getTagSet() == tag.TagSet(147 (),148 tag.Tag(tag.tagClassUniversal, tag.tagFormatSimple, 0x05)149 )150 def testConstraints(self):151 try:152 univ.Null(2)153 except error.ValueConstraintError:154 pass155 else:156 assert 0, 'constraint fail'157class RealTestCase(unittest.TestCase):158 def testStr(self): assert str(univ.Real(1.0)) == '1.0','str() fails'159 def testRepr(self): assert repr(univ.Real(-4.1)) == 'Real((-41, 10, -1))','repr() fails'160 def testAdd(self): assert univ.Real(-4.1) + 1.4 == -2.7, '__add__() fails'161 def testRadd(self): assert 4 + univ.Real(0.5) == 4.5, '__radd__() fails'162 def testSub(self): assert univ.Real(3.9) - 1.7 == 2.2, '__sub__() fails'163 def testRsub(self): assert 6.1 - univ.Real(0.1) == 6, '__rsub__() fails'164 def testMul(self): assert univ.Real(3.0) * -3 == -9, '__mul__() fails'165 def testRmul(self): assert 2 * univ.Real(3.0) == 6, '__rmul__() fails'166 def testDiv(self): assert univ.Real(3.0) / 2 == 1.5, '__div__() fails'167 def testRdiv(self): assert 6 / univ.Real(3.0) == 2, '__rdiv__() fails'168 def testMod(self): assert univ.Real(3.0) % 2 == 1, '__mod__() fails'169 def testRmod(self): assert 4 % univ.Real(3.0) == 1, '__rmod__() fails'170 def testPow(self): assert univ.Real(3.0) ** 2 == 9, '__pow__() fails'171 def testRpow(self): assert 2 ** univ.Real(2.0) == 4, '__rpow__() fails'172 def testInt(self): assert int(univ.Real(3.0)) == 3, '__int__() fails'173 def testLong(self): assert int(univ.Real(8.0)) == 8, '__long__() fails'174 def testFloat(self): assert float(univ.Real(4.0))==4.0,'__float__() fails'175 def testPrettyIn(self): assert univ.Real((3,10,0)) == 3, 'prettyIn() fails'176 # infinite float values177 def testStrInf(self):178 assert str(univ.Real('inf')) == 'inf','str() fails'179 def testReprInf(self):180 assert repr(univ.Real('inf')) == 'Real(\'inf\')','repr() fails'181 def testAddInf(self):182 assert univ.Real('inf') + 1 == float('inf'), '__add__() fails'183 def testRaddInf(self):184 assert 1 + univ.Real('inf') == float('inf'), '__radd__() fails'185 def testIntInf(self):186 try:187 assert int(univ.Real('inf'))188 except OverflowError:189 pass190 else:191 assert 0, '__int__() fails'192 def testLongInf(self):193 try:194 assert int(univ.Real('inf'))195 except OverflowError:196 pass197 else:198 assert 0, '__long__() fails' 199 assert int(univ.Real(8.0)) == 8, '__long__() fails'200 def testFloatInf(self):201 assert float(univ.Real('-inf')) == float('-inf'),'__float__() fails'202 def testPrettyInInf(self):203 assert univ.Real(float('inf')) == float('inf'), 'prettyIn() fails'204 def testPlusInf(self):205 assert univ.Real('inf').isPlusInfinity(), 'isPlusInfinity failed'206 def testMinusInf(self):207 assert univ.Real('-inf').isMinusInfinity(), 'isMinusInfinity failed'208 def testTag(self):209 assert univ.Real().getTagSet() == tag.TagSet(210 (),211 tag.Tag(tag.tagClassUniversal, tag.tagFormatSimple, 0x09)212 )213class ObjectIdentifier(unittest.TestCase):214 def testStr(self):215 assert str(univ.ObjectIdentifier((1,3,6))) == '1.3.6'216 def testEq(self):217 assert univ.ObjectIdentifier((1,3,6)) == (1,3,6), '__cmp__() fails'218 def testAdd(self):219 assert univ.ObjectIdentifier((1,3)) + (6,)==(1,3,6),'__add__() fails'220 def testRadd(self):221 assert (1,) + univ.ObjectIdentifier((3,6))==(1,3,6),'__radd__() fails'222 def testLen(self):223 assert len(univ.ObjectIdentifier((1,3))) == 2,'__len__() fails'224 def testPrefix(self):225 o = univ.ObjectIdentifier('1.3.6')226 assert o.isPrefixOf((1,3,6)), 'isPrefixOf() fails'227 assert o.isPrefixOf((1,3,6,1)), 'isPrefixOf() fails'228 assert not o.isPrefixOf((1,3)), 'isPrefixOf() fails' 229 def testInput(self):230 assert univ.ObjectIdentifier('1.3.6')==(1,3,6),'prettyIn() fails'231 def testTag(self):232 assert univ.ObjectIdentifier().getTagSet() == tag.TagSet(233 (),234 tag.Tag(tag.tagClassUniversal, tag.tagFormatSimple, 0x06)235 )236class SequenceOf(unittest.TestCase):237 def setUp(self):238 self.s1 = univ.SequenceOf(239 componentType=univ.OctetString('')240 )241 self.s2 = self.s1.clone()242 def testTag(self):243 assert self.s1.getTagSet() == tag.TagSet(244 (),245 tag.Tag(tag.tagClassUniversal, tag.tagFormatConstructed, 0x10)246 ), 'wrong tagSet'247 def testSeq(self):248 self.s1.setComponentByPosition(0, univ.OctetString('abc'))249 assert self.s1[0] == str2octs('abc'), 'set by idx fails'250 self.s1[0] = 'cba'251 assert self.s1[0] == str2octs('cba'), 'set by idx fails'252 def testCmp(self):253 self.s1.clear()254 self.s1.setComponentByPosition(0, 'abc')255 self.s2.clear()256 self.s2.setComponentByPosition(0, univ.OctetString('abc'))257 assert self.s1 == self.s2, '__cmp__() fails'258 def testSubtypeSpec(self):259 s = self.s1.clone(subtypeSpec=constraint.ConstraintsUnion(260 constraint.SingleValueConstraint(str2octs('abc'))261 ))262 try:263 s.setComponentByPosition(0, univ.OctetString('abc'))264 except:265 assert 0, 'constraint fails'266 try:267 s.setComponentByPosition(1, univ.OctetString('Abc'))268 except:269 pass270 else:271 assert 0, 'constraint fails'272 def testSizeSpec(self):273 s = self.s1.clone(sizeSpec=constraint.ConstraintsUnion(274 constraint.ValueSizeConstraint(1,1)275 ))276 s.setComponentByPosition(0, univ.OctetString('abc'))277 try:278 s.verifySizeSpec()279 except:280 assert 0, 'size spec fails'281 s.setComponentByPosition(1, univ.OctetString('abc'))282 try:283 s.verifySizeSpec()284 except:285 pass286 else:287 assert 0, 'size spec fails'288 def testGetComponentTagMap(self):289 assert self.s1.getComponentTagMap().getPosMap() == {290 univ.OctetString.tagSet: univ.OctetString('')291 }292 def testSubtype(self):293 self.s1.clear()294 assert self.s1.subtype(295 implicitTag=tag.Tag(tag.tagClassPrivate,tag.tagFormatSimple,2),296 subtypeSpec=constraint.SingleValueConstraint(1,3),297 sizeSpec=constraint.ValueSizeConstraint(0,1)298 ) == self.s1.clone(299 tagSet=tag.TagSet(tag.Tag(tag.tagClassPrivate,300 tag.tagFormatSimple,2)),301 subtypeSpec=constraint.ConstraintsIntersection(constraint.SingleValueConstraint(1,3)),302 sizeSpec=constraint.ValueSizeConstraint(0,1)303 )304 def testClone(self):305 self.s1.setComponentByPosition(0, univ.OctetString('abc'))306 s = self.s1.clone()307 assert len(s) == 0308 s = self.s1.clone(cloneValueFlag=1)309 assert len(s) == 1310 assert s.getComponentByPosition(0) == self.s1.getComponentByPosition(0)311 312class Sequence(unittest.TestCase):313 def setUp(self):314 self.s1 = univ.Sequence(componentType=namedtype.NamedTypes(315 namedtype.NamedType('name', univ.OctetString('')),316 namedtype.OptionalNamedType('nick', univ.OctetString('')),317 namedtype.DefaultedNamedType('age', univ.Integer(34))318 ))319 def testTag(self):320 assert self.s1.getTagSet() == tag.TagSet(321 (),322 tag.Tag(tag.tagClassUniversal, tag.tagFormatConstructed, 0x10)323 ), 'wrong tagSet'324 def testById(self):325 self.s1.setComponentByName('name', univ.OctetString('abc'))326 assert self.s1.getComponentByName('name') == str2octs('abc'), 'set by name fails'327 def testByKey(self):328 self.s1['name'] = 'abc'329 assert self.s1['name'] == str2octs('abc'), 'set by key fails'330 def testGetNearPosition(self):331 assert self.s1.getComponentTagMapNearPosition(1).getPosMap() == {332 univ.OctetString.tagSet: univ.OctetString(''),333 univ.Integer.tagSet: univ.Integer(34)334 }335 assert self.s1.getComponentPositionNearType(336 univ.OctetString.tagSet, 1337 ) == 1338 def testGetDefaultComponentByPosition(self):339 self.s1.clear()340 assert self.s1.getDefaultComponentByPosition(0) == None341 assert self.s1.getDefaultComponentByPosition(2) == univ.Integer(34)342 def testSetDefaultComponents(self):343 self.s1.clear()344 assert self.s1.getComponentByPosition(2) == None345 self.s1.setComponentByPosition(0, univ.OctetString('Ping'))346 self.s1.setComponentByPosition(1, univ.OctetString('Pong'))347 self.s1.setDefaultComponents()348 assert self.s1.getComponentByPosition(2) == 34349 def testClone(self):350 self.s1.setComponentByPosition(0, univ.OctetString('abc'))351 self.s1.setComponentByPosition(1, univ.OctetString('def'))352 self.s1.setComponentByPosition(2, univ.Integer(123))353 s = self.s1.clone()354 assert s.getComponentByPosition(0) != self.s1.getComponentByPosition(0)355 assert s.getComponentByPosition(1) != self.s1.getComponentByPosition(1)356 assert s.getComponentByPosition(2) != self.s1.getComponentByPosition(2)357 s = self.s1.clone(cloneValueFlag=1)358 assert s.getComponentByPosition(0) == self.s1.getComponentByPosition(0)359 assert s.getComponentByPosition(1) == self.s1.getComponentByPosition(1)360 assert s.getComponentByPosition(2) == self.s1.getComponentByPosition(2)361class SetOf(unittest.TestCase):362 def setUp(self):363 self.s1 = univ.SetOf(componentType=univ.OctetString(''))364 def testTag(self):365 assert self.s1.getTagSet() == tag.TagSet(366 (),367 tag.Tag(tag.tagClassUniversal, tag.tagFormatConstructed, 0x11)368 ), 'wrong tagSet'369 def testSeq(self):370 self.s1.setComponentByPosition(0, univ.OctetString('abc'))371 assert self.s1[0] == str2octs('abc'), 'set by idx fails'372 self.s1.setComponentByPosition(0, self.s1[0].clone('cba'))373 assert self.s1[0] == str2octs('cba'), 'set by idx fails'374class Set(unittest.TestCase):375 def setUp(self):376 self.s1 = univ.Set(componentType=namedtype.NamedTypes(377 namedtype.NamedType('name', univ.OctetString('')),378 namedtype.OptionalNamedType('null', univ.Null('')),379 namedtype.DefaultedNamedType('age', univ.Integer(34))380 ))381 self.s2 = self.s1.clone()382 def testTag(self):383 assert self.s1.getTagSet() == tag.TagSet(384 (),385 tag.Tag(tag.tagClassUniversal, tag.tagFormatConstructed, 0x11)386 ), 'wrong tagSet'387 def testByTypeWithPythonValue(self):388 self.s1.setComponentByType(univ.OctetString.tagSet, 'abc')389 assert self.s1.getComponentByType(390 univ.OctetString.tagSet391 ) == str2octs('abc'), 'set by name fails'392 def testByTypeWithInstance(self):393 self.s1.setComponentByType(univ.OctetString.tagSet, univ.OctetString('abc'))394 assert self.s1.getComponentByType(395 univ.OctetString.tagSet396 ) == str2octs('abc'), 'set by name fails'397 def testGetTagMap(self):398 assert self.s1.getTagMap().getPosMap() == {399 univ.Set.tagSet: univ.Set()400 }401 def testGetComponentTagMap(self):402 assert self.s1.getComponentTagMap().getPosMap() == {403 univ.OctetString.tagSet: univ.OctetString(''),404 univ.Null.tagSet: univ.Null(''),405 univ.Integer.tagSet: univ.Integer(34)406 }407 def testGetPositionByType(self):408 assert self.s1.getComponentPositionByType(409 univ.Null().getTagSet()410 ) == 1411class Choice(unittest.TestCase):412 def setUp(self):413 innerComp = univ.Choice(componentType=namedtype.NamedTypes(414 namedtype.NamedType('count', univ.Integer()),415 namedtype.NamedType('flag', univ.Boolean())416 ))417 self.s1 = univ.Choice(componentType=namedtype.NamedTypes(418 namedtype.NamedType('name', univ.OctetString()),419 namedtype.NamedType('sex', innerComp)420 ))421 def testTag(self):422 assert self.s1.getTagSet() == tag.TagSet(), 'wrong tagSet'423 def testOuterByTypeWithPythonValue(self):424 self.s1.setComponentByType(univ.OctetString.tagSet, 'abc')425 assert self.s1.getComponentByType(426 univ.OctetString.tagSet427 ) == str2octs('abc')428 def testOuterByTypeWithInstanceValue(self):429 self.s1.setComponentByType(430 univ.OctetString.tagSet, univ.OctetString('abc')431 )432 assert self.s1.getComponentByType(433 univ.OctetString.tagSet434 ) == str2octs('abc')435 def testInnerByTypeWithPythonValue(self):436 self.s1.setComponentByType(univ.Integer.tagSet, 123, 1)437 assert self.s1.getComponentByType(438 univ.Integer.tagSet, 1439 ) == 123440 def testInnerByTypeWithInstanceValue(self):441 self.s1.setComponentByType(442 univ.Integer.tagSet, univ.Integer(123), 1443 )444 assert self.s1.getComponentByType(445 univ.Integer.tagSet, 1446 ) == 123447 def testCmp(self):448 self.s1.setComponentByName('name', univ.OctetString('abc'))449 assert self.s1 == str2octs('abc'), '__cmp__() fails'450 def testGetComponent(self):451 self.s1.setComponentByType(univ.OctetString.tagSet, 'abc')452 assert self.s1.getComponent() == str2octs('abc'), 'getComponent() fails'453 def testGetName(self):454 self.s1.setComponentByType(univ.OctetString.tagSet, 'abc')455 assert self.s1.getName() == 'name', 'getName() fails'456 def testSetComponentByPosition(self):457 self.s1.setComponentByPosition(0, univ.OctetString('Jim'))458 assert self.s1 == str2octs('Jim')459 def testClone(self):460 self.s1.setComponentByPosition(0, univ.OctetString('abc'))461 s = self.s1.clone()462 assert len(s) == 0463 s = self.s1.clone(cloneValueFlag=1)464 assert len(s) == 1465 assert s.getComponentByPosition(0) == self.s1.getComponentByPosition(0)466 ...

Full Screen

Full Screen

w1_unittest.py

Source:w1_unittest.py Github

copy

Full Screen

1import numpy as np2import trax3from trax import layers as tl4from trax.fastmath import numpy as fastnp5from trax.supervised import training6VOCAB_FILE = 'ende_32k.subword'7VOCAB_DIR = 'data/'8def jaccard_similarity(candidate, reference):9 """Returns the Jaccard similarity between two token lists10 Args:11 candidate (list of int): tokenized version of the candidate translation12 reference (list of int): tokenized version of the reference translation13 Returns:14 float: overlap between the two token lists15 """16 17 # convert the lists to a set to get the unique tokens18 can_unigram_set, ref_unigram_set = set(candidate), set(reference) 19 20 # get the set of tokens common to both candidate and reference21 joint_elems = can_unigram_set.intersection(ref_unigram_set)22 23 # get the set of all tokens found in either candidate or reference24 all_elems = can_unigram_set.union(ref_unigram_set)25 26 # divide the number of joint elements by the number of all elements27 overlap = len(joint_elems) / len(all_elems)28 29 return overlap30def weighted_avg_overlap(similarity_fn, samples, log_probs):31 """Returns the weighted mean of each candidate sentence in the samples32 Args:33 samples (list of lists): tokenized version of the translated sentences34 log_probs (list of float): log probability of the translated sentences35 Returns:36 dict: scores of each sample37 key: index of the sample38 value: score of the sample39 """40 41 # initialize dictionary42 scores = {}43 44 # run a for loop for each sample45 for index_candidate, candidate in enumerate(samples): 46 47 # initialize overlap and weighted sum48 overlap, weight_sum = 0.0, 0.049 50 # run a for loop for each sample51 for index_sample, (sample, logp) in enumerate(zip(samples, log_probs)):52 # skip if the candidate index is the same as the sample index 53 if index_candidate == index_sample:54 continue55 56 # convert log probability to linear scale57 sample_p = float(np.exp(logp))58 # update the weighted sum59 weight_sum += sample_p60 # get the unigram overlap between candidate and sample61 sample_overlap = similarity_fn(candidate, sample)62 63 # update the overlap64 overlap += sample_p * sample_overlap65 66 # get the score for the candidate67 score = overlap / weight_sum68 69 # save the score in the dictionary. use index as the key.70 scores[index_candidate] = score71 72 return scores73# UNIT TEST for UNQ_C174def test_input_encoder_fn(input_encoder_fn):75 target = input_encoder_fn76 success = 077 fails = 078 79 input_vocab_size = 1080 d_model = 281 n_encoder_layers = 682 83 encoder = target(input_vocab_size, d_model, n_encoder_layers)84 85 lstms = "\n".join([f' LSTM_{d_model}'] * n_encoder_layers)86 expected = f"Serial[\n Embedding_{input_vocab_size}_{d_model}\n{lstms}\n]"87 proposed = str(encoder)88 89 # Test all layers are in the expected sequence90 try:91 assert(proposed.replace(" ", "") == expected.replace(" ", ""))92 success += 193 except:94 fails += 195 print("Wrong model. \nProposed:\n%s" %proposed, "\nExpected:\n%s" %expected)96 97 # Test the output type98 try:99 assert(isinstance(encoder, trax.layers.combinators.Serial))100 success += 1101 # Test the number of layers102 try:103 # Test 104 assert len(encoder.sublayers) == (n_encoder_layers + 1)105 success += 1106 except:107 fails += 1108 print('The number of sublayers does not match %s <>' %len(encoder.sublayers), " %s" %(n_encoder_layers + 1))109 except:110 fails += 1111 print("The enconder is not an object of ", trax.layers.combinators.Serial)112 113 114 if fails == 0:115 print("\033[92m All tests passed")116 else:117 print('\033[92m', success," Tests passed")118 print('\033[91m', fails, " Tests failed")119 120# UNIT TEST for UNQ_C2121def test_pre_attention_decoder_fn(pre_attention_decoder_fn):122 target = pre_attention_decoder_fn123 success = 0124 fails = 0125 126 mode = 'train'127 target_vocab_size = 10128 d_model = 2129 130 decoder = target(mode, target_vocab_size, d_model)131 132 expected = f"Serial[\n ShiftRight(1)\n Embedding_{target_vocab_size}_{d_model}\n LSTM_{d_model}\n]"133 proposed = str(decoder)134 135 # Test all layers are in the expected sequence136 try:137 assert(proposed.replace(" ", "") == expected.replace(" ", ""))138 success += 1139 except:140 fails += 1141 print("Wrong model. \nProposed:\n%s" %proposed, "\nExpected:\n%s" %expected)142 143 # Test the output type144 try:145 assert(isinstance(decoder, trax.layers.combinators.Serial))146 success += 1147 # Test the number of layers148 try:149 # Test 150 assert len(decoder.sublayers) == 3151 success += 1152 except:153 fails += 1154 print('The number of sublayers does not match %s <>' %len(decoder.sublayers), " %s" %3)155 except:156 fails += 1157 print("The enconder is not an object of ", trax.layers.combinators.Serial)158 159 160 if fails == 0:161 print("\033[92m All tests passed")162 else:163 print('\033[92m', success," Tests passed")164 print('\033[91m', fails, " Tests failed")165 166# UNIT TEST for UNQ_C3167def test_prepare_attention_input(prepare_attention_input):168 target = prepare_attention_input169 success = 0170 fails = 0171 172 #This unit test consider a batch size = 2, number_of_tokens = 3 and embedding_size = 4173 174 enc_act = fastnp.array([[[1, 0, 0, 0], [0, 1, 0, 0], [0, 0, 1, 0]],175 [[1, 0, 1, 0], [0, 1, 0, 1], [0, 0, 0, 0]]])176 dec_act = fastnp.array([[[2, 0, 0, 0], [0, 2, 0, 0], [0, 0, 2, 0]], 177 [[2, 0, 2, 0], [0, 2, 0, 2], [0, 0, 0, 0]]])178 inputs = fastnp.array([[1, 2, 3], [1, 4, 0]])179 180 exp_mask = fastnp.array([[[[1., 1., 1.], [1., 1., 1.], [1., 1., 1.]]], 181 [[[1., 1., 0.], [1., 1., 0.], [1., 1., 0.]]]])182 183 exp_type = type(enc_act)184 185 queries, keys, values, mask = target(enc_act, dec_act, inputs)186 187 try:188 assert(fastnp.allclose(queries, dec_act))189 success += 1190 except:191 fails += 1192 print("Queries does not match the decoder activations")193 try:194 assert(fastnp.allclose(keys, enc_act))195 success += 1196 except:197 fails += 1198 print("Keys does not match the encoder activations")199 try:200 assert(fastnp.allclose(values, enc_act))201 success += 1202 except:203 fails += 1204 print("Values does not match the encoder activations")205 try:206 assert(fastnp.allclose(mask, exp_mask))207 success += 1208 except:209 fails += 1210 print("Mask does not match expected tensor. \nExpected:\n%s" %exp_mask, "\nOutput:\n%s" %mask)211 212 # Test the output type213 try:214 assert(isinstance(queries, exp_type))215 assert(isinstance(keys, exp_type))216 assert(isinstance(values, exp_type))217 assert(isinstance(mask, exp_type))218 success += 1219 except:220 fails += 1221 print("One of the output object are not of type ", jax.interpreters.xla.DeviceArray)222 223 if fails == 0:224 print("\033[92m All tests passed")225 else:226 print('\033[92m', success," Tests passed")227 print('\033[91m', fails, " Tests failed")228 229# UNIT TEST for UNQ_C4230def test_NMTAttn(NMTAttn):231 test_cases = [232 {233 "name":"simple_test_check",234 "expected":"Serial_in2_out2[\n Select[0,1,0,1]_in2_out4\n Parallel_in2_out2[\n Serial[\n Embedding_33300_1024\n LSTM_1024\n LSTM_1024\n ]\n Serial[\n ShiftRight(1)\n Embedding_33300_1024\n LSTM_1024\n ]\n ]\n PrepareAttentionInput_in3_out4\n Serial_in4_out2[\n Branch_in4_out3[\n None\n Serial_in4_out2[\n Parallel_in3_out3[\n Dense_1024\n Dense_1024\n Dense_1024\n ]\n PureAttention_in4_out2\n Dense_1024\n ]\n ]\n Add_in2\n ]\n Select[0,2]_in3_out2\n LSTM_1024\n LSTM_1024\n Dense_33300\n LogSoftmax\n]",235 "error":"The NMTAttn is not defined properly."236 },237 {238 "name":"layer_len_check",239 "expected":9,240 "error":"We found {} layers in your model. It should be 9.\nCheck the LSTM stack before the dense layer"241 },242 {243 "name":"selection_layer_check",244 "expected":["Select[0,1,0,1]_in2_out4", "Select[0,2]_in3_out2"],245 "error":"Look at your selection layers."246 }247 ]248 249 success = 0250 fails = 0251 252 for test_case in test_cases:253 try:254 if test_case['name'] == "simple_test_check":255 assert test_case["expected"] == str(NMTAttn())256 success += 1257 if test_case['name'] == "layer_len_check":258 if test_case["expected"] == len(NMTAttn().sublayers):259 success += 1260 else:261 print(test_case["error"].format(len(NMTAttn().sublayers))) 262 fails += 1263 if test_case['name'] == "selection_layer_check":264 model = NMTAttn()265 output = [str(model.sublayers[0]),str(model.sublayers[4])]266 check_count = 0267 for i in range(2):268 if test_case["expected"][i] != output[i]:269 print(test_case["error"])270 fails += 1271 break272 else:273 check_count += 1274 if check_count == 2:275 success += 1276 except:277 print(test_case['error'])278 fails += 1279 280 if fails == 0:281 print("\033[92m All tests passed")282 else:283 print('\033[92m', success," Tests passed")284 print('\033[91m', fails, " Tests failed")285# UNIT TEST for UNQ_C5286def test_train_task(train_task):287 target = train_task288 success = 0289 fails = 0290 291 # Test the labeled data parameter292 try:293 strlabel = str(target._labeled_data)294 assert(strlabel.find("generator") and strlabel.find('add_loss_weights'))295 success += 1296 except:297 fails += 1298 print("Wrong labeled data parameter")299 300 # Test the cross entropy loss data parameter301 try:302 strlabel = str(target._loss_layer)303 assert(strlabel == "CrossEntropyLoss_in3")304 success += 1305 except:306 fails += 1307 print("Wrong loss functions. CrossEntropyLoss_in3 was expected")308 309 # Test the optimizer parameter310 try:311 assert(isinstance(target.optimizer, trax.optimizers.adam.Adam))312 success += 1313 except:314 fails += 1315 print("Wrong optimizer")316 317 # Test the schedule parameter318 try:319 assert(isinstance(target._lr_schedule,trax.supervised.lr_schedules._BodyAndTail))320 success += 1321 except:322 fails += 1323 print("Wrong learning rate schedule type")324 325 # Test the _n_steps_per_checkpoint parameter326 try:327 assert(target._n_steps_per_checkpoint==10)328 success += 1329 except:330 fails += 1331 print("Wrong checkpoint step frequency")332 333 if fails == 0:334 print("\033[92m All tests passed")335 else:336 print('\033[92m', success," Tests passed")337 print('\033[91m', fails, " Tests failed")338# UNIT TEST for UNQ_C6339def test_next_symbol(next_symbol, model):340 target = next_symbol341 the_model = model342 success = 0343 fails = 0344 345 tokens_en = np.array([[17332, 140, 172, 207, 1]])346 347 # Test the type and size of output348 try:349 next_de_tokens = target(the_model, tokens_en, [], 0.0) 350 assert(isinstance(next_de_tokens, tuple))351 assert(len(next_de_tokens) == 2)352 assert(type(next_de_tokens[0]) == int and type(next_de_tokens[1]) == float)353 success += 1354 except:355 fails += 1356 print("Output must be a tuple of size 2 containing a integer and a float number")357 358 # Test an output359 try:360 next_de_tokens = target(the_model, tokens_en, [18477], 0.0)361 assert(np.allclose([next_de_tokens[0], next_de_tokens[1]], [140, -0.000217437744]))362 success += 1363 except:364 fails += 1365 print("Expected output: ", [140, -0.000217437744])366 367 368 if fails == 0:369 print("\033[92m All tests passed")370 else:371 print('\033[92m', success," Tests passed")372 print('\033[91m', fails, " Tests failed")373# UNIT TEST for UNQ_C7374def test_sampling_decode(sampling_decode, model):375 target = sampling_decode376 the_model = model377 success = 0378 fails = 0379 380 try:381 output = target("I eat soup.", model, temperature=0, vocab_file=VOCAB_FILE, vocab_dir=VOCAB_DIR)382 expected = ([161, 15103, 5, 25132, 35, 3, 1], -0.0003108978271484375, 'Ich iss Suppe.')383 assert(output[2] == expected[2])384 success += 1385 except:386 fails += 1387 print("Test 1 fails")388 389 try:390 output = target("I like your shoes.", model, temperature=0, vocab_file=VOCAB_FILE, vocab_dir=VOCAB_DIR)391 expected = ([161, 15103, 5, 25132, 35, 3, 1], -0.0003108978271484375, 'Ich mag Ihre Schuhe.')392 assert(output[2] == expected[2])393 success += 1394 except:395 fails += 1396 print("Test 2 fails")397 398 if fails == 0:399 print("\033[92m All tests passed")400 else:401 print('\033[92m', success," Tests passed")402 print('\033[91m', fails, " Tests failed")403 404# UNIT TEST for UNQ_C8405def test_rouge1_similarity(rouge1_similarity):406 target = rouge1_similarity407 success = 0408 fails = 0409 n_samples = 10410 411 test_cases = [412 413 {414 "name":"simple_test_check",415 "input": [[1, 2, 3], [1, 2, 3, 4]],416 "expected":0.8571428571428571,417 "error":"Expected similarity: 0.8571428571428571"418 },419 {420 "name":"simple_test_check",421 "input":[[2, 1], [3, 1]],422 "expected":0.5,423 "error":"Expected similarity: 0.5"424 },425 {426 "name":"simple_test_check",427 "input":[[2], [3]],428 "expected":0,429 "error":"Expected similarity: 0"430 },431 {432 "name":"simple_test_check",433 "input":[[0] * 100 + [2] * 100, [0] * 100 + [1] * 100],434 "expected":0.5,435 "error":"Expected similarity: 0.5"436 }437 ]438 for test_case in test_cases:439 440 try:441 if test_case['name'] == "simple_test_check":442 assert abs(test_case["expected"] -target(*test_case['input'])) < 1e-6443 success += 1444 except:445 print(test_case['error'])446 fails += 1447 448 if fails == 0:449 print("\033[92m All tests passed")450 else:451 print('\033[92m', success," Tests passed")452 print('\033[91m', fails, " Tests failed")453 454# UNIT TEST for UNQ_C9455def test_average_overlap(average_overlap):456 target = average_overlap457 success = 0458 fails = 0459 460 test_cases = [461 462 {463 "name":"dict_test_check",464 "input": [jaccard_similarity, [[1, 2], [3, 4], [1, 2], [3, 5]]],465 "expected":{0: 0.3333333333333333,466 1: 0.1111111111111111,467 2: 0.3333333333333333,468 3: 0.1111111111111111},469 "error":"Expected output does not match"470 },471 {472 "name":"dict_test_check",473 "input":[jaccard_similarity, [[1, 2], [3, 4], [1, 2, 5], [3, 5], [3, 4, 1]]],474 "expected":{0: 0.22916666666666666,475 1: 0.25,476 2: 0.2791666666666667,477 3: 0.20833333333333331,478 4: 0.3416666666666667},479 "error":"Expected output does not match"480 }481 ]482 for test_case in test_cases:483 try:484 if test_case['name'] == "dict_test_check":485 output = target(*test_case['input'])486 for x in output:487 assert (abs(output[x] - test_case['expected'][x]) < 1e-5)488 success += 1489 except:490 print(test_case['error'])491 fails += 1492 493 if fails == 0:494 print("\033[92m All tests passed")495 else:496 print('\033[92m', success," Tests passed")497 print('\033[91m', fails, " Tests failed")498# UNIT TEST for UNQ_C10499def test_mbr_decode(mbr_decode, model):500 target = mbr_decode501 success = 0502 fails = 0503 504 TEMPERATURE = 0.0505 506 test_cases = [507 508 {509 "name":"simple_test_check",510 "input": "I am hungry",511 "expected":"Ich bin hungrig.",512 "error":"Expected output does not match"513 },514 {515 "name":"simple_test_check",516 "input":'Congratulations!',517 "expected":'Herzlichen Glückwunsch!',518 "error":"Expected output does not match"519 },520 {521 "name":"simple_test_check",522 "input":'You have completed the assignment!',523 "expected":'Sie haben die Abtretung abgeschlossen!',524 "error":"Expected output does not match"525 }526 ]527 for test_case in test_cases:528 try:529 result = target(test_case['input'], 4, weighted_avg_overlap, jaccard_similarity, 530 model, TEMPERATURE, vocab_file=VOCAB_FILE, vocab_dir=VOCAB_DIR) 531 output = result[0]532 if test_case['name'] == "simple_test_check":533 assert(output == test_case['expected'])534 success += 1535 except:536 print(test_case['error'])537 fails += 1538 539 # Test that function return the most likely translation540 TEMPERATURE = 0.5541 test_case = test_cases[0]542 try:543 result = target(test_case['input'], 4, weighted_avg_overlap, jaccard_similarity, 544 model, TEMPERATURE, vocab_file=VOCAB_FILE, vocab_dir=VOCAB_DIR) 545 assert max(result[2], key=result[2].get) == result[1]546 success += 1547 except:548 print('Use max function to select max_index')549 fails += 1550 551 if fails == 0:552 print("\033[92m All tests passed")553 else:554 print('\033[92m', success," Tests passed")...

Full Screen

Full Screen

herd.py

Source:herd.py Github

copy

Full Screen

...252 # wrapper253 def dump(self):254 out=self.get_stat()255 self.format(out)256 def list_fails(self):257 options = self.ufonet.options258 if self.total_connections==0:259 return260 if self.zombies_ready == None: # if not herd return261 return262 if not options.forceyes:263 print '-'*25264 update_reply = raw_input("Do you want to update your army (Y/n)")265 print '-'*25266 else:267 update_reply = "Y"268 if update_reply == "n" or update_reply == "N":269 print "\nBye!\n"270 return...

Full Screen

Full Screen

Automation Testing Tutorials

Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run pytest-benchmark automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful