diff --git a/docs/_snowpack/link/repl/krill-parser.js b/docs/_snowpack/link/repl/krill-parser.js new file mode 100644 index 00000000..db17b13f --- /dev/null +++ b/docs/_snowpack/link/repl/krill-parser.js @@ -0,0 +1,1916 @@ +// Generated by Peggy 1.2.0. +// +// https://peggyjs.org/ + +function peg$subclass(child, parent) { + function C() { this.constructor = child; } + C.prototype = parent.prototype; + child.prototype = new C(); +} + +function peg$SyntaxError(message, expected, found, location) { + var self = Error.call(this, message); + if (Object.setPrototypeOf) { + Object.setPrototypeOf(self, peg$SyntaxError.prototype); + } + self.expected = expected; + self.found = found; + self.location = location; + self.name = "SyntaxError"; + return self; +} + +peg$subclass(peg$SyntaxError, Error); + +function peg$padEnd(str, targetLength, padString) { + padString = padString || " "; + if (str.length > targetLength) { return str; } + targetLength -= str.length; + padString += padString.repeat(targetLength); + return str + padString.slice(0, targetLength); +} + +peg$SyntaxError.prototype.format = function(sources) { + var str = "Error: " + this.message; + if (this.location) { + var src = null; + var k; + for (k = 0; k < sources.length; k++) { + if (sources[k].source === this.location.source) { + src = sources[k].text.split(/\r\n|\n|\r/g); + break; + } + } + var s = this.location.start; + var loc = this.location.source + ":" + s.line + ":" + s.column; + if (src) { + var e = this.location.end; + var filler = peg$padEnd("", s.line.toString().length); + var line = src[s.line - 1]; + var last = s.line === e.line ? e.column : line.length + 1; + str += "\n --> " + loc + "\n" + + filler + " |\n" + + s.line + " | " + line + "\n" + + filler + " | " + peg$padEnd("", s.column - 1) + + peg$padEnd("", last - s.column, "^"); + } else { + str += "\n at " + loc; + } + } + return str; +}; + +peg$SyntaxError.buildMessage = function(expected, found) { + var DESCRIBE_EXPECTATION_FNS = { + literal: function(expectation) { + return "\"" + literalEscape(expectation.text) + "\""; + }, + + class: function(expectation) { + var escapedParts = expectation.parts.map(function(part) { + return Array.isArray(part) + ? classEscape(part[0]) + "-" + classEscape(part[1]) + : classEscape(part); + }); + + return "[" + (expectation.inverted ? "^" : "") + escapedParts + "]"; + }, + + any: function() { + return "any character"; + }, + + end: function() { + return "end of input"; + }, + + other: function(expectation) { + return expectation.description; + } + }; + + function hex(ch) { + return ch.charCodeAt(0).toString(16).toUpperCase(); + } + + function literalEscape(s) { + return s + .replace(/\\/g, "\\\\") + .replace(/"/g, "\\\"") + .replace(/\0/g, "\\0") + .replace(/\t/g, "\\t") + .replace(/\n/g, "\\n") + .replace(/\r/g, "\\r") + .replace(/[\x00-\x0F]/g, function(ch) { return "\\x0" + hex(ch); }) + .replace(/[\x10-\x1F\x7F-\x9F]/g, function(ch) { return "\\x" + hex(ch); }); + } + + function classEscape(s) { + return s + .replace(/\\/g, "\\\\") + .replace(/\]/g, "\\]") + .replace(/\^/g, "\\^") + .replace(/-/g, "\\-") + .replace(/\0/g, "\\0") + .replace(/\t/g, "\\t") + .replace(/\n/g, "\\n") + .replace(/\r/g, "\\r") + .replace(/[\x00-\x0F]/g, function(ch) { return "\\x0" + hex(ch); }) + .replace(/[\x10-\x1F\x7F-\x9F]/g, function(ch) { return "\\x" + hex(ch); }); + } + + function describeExpectation(expectation) { + return DESCRIBE_EXPECTATION_FNS[expectation.type](expectation); + } + + function describeExpected(expected) { + var descriptions = expected.map(describeExpectation); + var i, j; + + descriptions.sort(); + + if (descriptions.length > 0) { + for (i = 1, j = 1; i < descriptions.length; i++) { + if (descriptions[i - 1] !== descriptions[i]) { + descriptions[j] = descriptions[i]; + j++; + } + } + descriptions.length = j; + } + + switch (descriptions.length) { + case 1: + return descriptions[0]; + + case 2: + return descriptions[0] + " or " + descriptions[1]; + + default: + return descriptions.slice(0, -1).join(", ") + + ", or " + + descriptions[descriptions.length - 1]; + } + } + + function describeFound(found) { + return found ? "\"" + literalEscape(found) + "\"" : "end of input"; + } + + return "Expected " + describeExpected(expected) + " but " + describeFound(found) + " found."; +}; + +function peg$parse(input, options) { + options = options !== undefined ? options : {}; + + var peg$FAILED = {}; + var peg$source = options.grammarSource; + + var peg$startRuleFunctions = { start: peg$parsestart }; + var peg$startRuleFunction = peg$parsestart; + + var peg$c0 = "."; + var peg$c1 = "-"; + var peg$c2 = "+"; + var peg$c3 = "0"; + var peg$c4 = ","; + var peg$c5 = "\""; + var peg$c6 = "'"; + var peg$c7 = "#"; + var peg$c8 = "["; + var peg$c9 = "]"; + var peg$c10 = "<"; + var peg$c11 = ">"; + var peg$c12 = "@"; + var peg$c13 = "("; + var peg$c14 = ")"; + var peg$c15 = "/"; + var peg$c16 = "*"; + var peg$c17 = "%"; + var peg$c18 = "struct"; + var peg$c19 = "target"; + var peg$c20 = "euclid"; + var peg$c21 = "slow"; + var peg$c22 = "rotL"; + var peg$c23 = "rotR"; + var peg$c24 = "fast"; + var peg$c25 = "scale"; + var peg$c26 = "//"; + var peg$c27 = "cat"; + var peg$c28 = "$"; + var peg$c29 = "setcps"; + var peg$c30 = "setbpm"; + var peg$c31 = "hush"; + + var peg$r0 = /^[1-9]/; + var peg$r1 = /^[eE]/; + var peg$r2 = /^[0-9]/; + var peg$r3 = /^[ \n\r\t]/; + var peg$r4 = /^[0-9a-zA-Z~]/; + var peg$r5 = /^[^\n]/; + + var peg$e0 = peg$otherExpectation("number"); + var peg$e1 = peg$literalExpectation(".", false); + var peg$e2 = peg$classExpectation([["1", "9"]], false, false); + var peg$e3 = peg$classExpectation(["e", "E"], false, false); + var peg$e4 = peg$literalExpectation("-", false); + var peg$e5 = peg$literalExpectation("+", false); + var peg$e6 = peg$literalExpectation("0", false); + var peg$e7 = peg$classExpectation([["0", "9"]], false, false); + var peg$e8 = peg$otherExpectation("whitespace"); + var peg$e9 = peg$classExpectation([" ", "\n", "\r", "\t"], false, false); + var peg$e10 = peg$literalExpectation(",", false); + var peg$e11 = peg$literalExpectation("\"", false); + var peg$e12 = peg$literalExpectation("'", false); + var peg$e13 = peg$classExpectation([["0", "9"], ["a", "z"], ["A", "Z"], "~"], false, false); + var peg$e14 = peg$literalExpectation("#", false); + var peg$e15 = peg$literalExpectation("[", false); + var peg$e16 = peg$literalExpectation("]", false); + var peg$e17 = peg$literalExpectation("<", false); + var peg$e18 = peg$literalExpectation(">", false); + var peg$e19 = peg$literalExpectation("@", false); + var peg$e20 = peg$literalExpectation("(", false); + var peg$e21 = peg$literalExpectation(")", false); + var peg$e22 = peg$literalExpectation("/", false); + var peg$e23 = peg$literalExpectation("*", false); + var peg$e24 = peg$literalExpectation("%", false); + var peg$e25 = peg$literalExpectation("struct", false); + var peg$e26 = peg$literalExpectation("target", false); + var peg$e27 = peg$literalExpectation("euclid", false); + var peg$e28 = peg$literalExpectation("slow", false); + var peg$e29 = peg$literalExpectation("rotL", false); + var peg$e30 = peg$literalExpectation("rotR", false); + var peg$e31 = peg$literalExpectation("fast", false); + var peg$e32 = peg$literalExpectation("scale", false); + var peg$e33 = peg$literalExpectation("//", false); + var peg$e34 = peg$classExpectation(["\n"], true, false); + var peg$e35 = peg$literalExpectation("cat", false); + var peg$e36 = peg$literalExpectation("$", false); + var peg$e37 = peg$literalExpectation("setcps", false); + var peg$e38 = peg$literalExpectation("setbpm", false); + var peg$e39 = peg$literalExpectation("hush", false); + + var peg$f0 = function() { return parseFloat(text()); }; + var peg$f1 = function(chars) { return chars.join("") }; + var peg$f2 = function(s) { return s}; + var peg$f3 = function(sc) { sc.arguments_.alignment = "t"; return sc;}; + var peg$f4 = function(a) { return { weight: a} }; + var peg$f5 = function(p, s) { return { operator : { type_: "bjorklund", arguments_ :{ pulse: p, step:s } } } }; + var peg$f6 = function(a) { return { operator : { type_: "stretch", arguments_ :{ amount:a } } } }; + var peg$f7 = function(a) { return { operator : { type_: "stretch", arguments_ :{ amount:"1/"+a } } } }; + var peg$f8 = function(a) { return { operator : { type_: "fixed-step", arguments_ :{ amount:a } } } }; + var peg$f9 = function(s, o) { return new ElementStub(s, o);}; + var peg$f10 = function(s) { return new PatternStub(s,"h"); }; + var peg$f11 = function(c, v) { return v}; + var peg$f12 = function(c, cs) { if (cs.length == 0 && c instanceof Object) { return c;} else { cs.unshift(c); return new PatternStub(cs,"v");} }; + var peg$f13 = function(s) { return s; }; + var peg$f14 = function(s) { return { name: "struct", args: { sequence:s }}}; + var peg$f15 = function(s) { return { name: "target", args : { name:s}}}; + var peg$f16 = function(p, s) { return { name: "bjorklund", args :{ pulse: parseInt(p), step:parseInt(s) }}}; + var peg$f17 = function(a) { return { name: "stretch", args :{ amount: a}}}; + var peg$f18 = function(a) { return { name: "shift", args :{ amount: "-"+a}}}; + var peg$f19 = function(a) { return { name: "shift", args :{ amount: a}}}; + var peg$f20 = function(a) { return { name: "stretch", args :{ amount: "1/"+a}}}; + var peg$f21 = function(s) { return { name: "scale", args :{ scale: s.join("")}}}; + var peg$f22 = function(s, v) { return v}; + var peg$f23 = function(s, ss) { ss.unshift(s); return new PatternStub(ss,"t"); }; + var peg$f24 = function(sg) {return sg}; + var peg$f25 = function(o, soc) { return new OperatorStub(o.name,o.args,soc)}; + var peg$f26 = function(sc) { return sc }; + var peg$f27 = function(c) { return c }; + var peg$f28 = function(v) { return new CommandStub("setcps", { value: v})}; + var peg$f29 = function(v) { return new CommandStub("setcps", { value: (v/120/2)})}; + var peg$f30 = function() { return new CommandStub("hush")}; + + var peg$currPos = 0; + var peg$savedPos = 0; + var peg$posDetailsCache = [{ line: 1, column: 1 }]; + var peg$maxFailPos = 0; + var peg$maxFailExpected = []; + var peg$silentFails = 0; + + var peg$result; + + if ("startRule" in options) { + if (!(options.startRule in peg$startRuleFunctions)) { + throw new Error("Can't start parsing from rule \"" + options.startRule + "\"."); + } + + peg$startRuleFunction = peg$startRuleFunctions[options.startRule]; + } + + function text() { + return input.substring(peg$savedPos, peg$currPos); + } + + function offset() { + return peg$savedPos; + } + + function range() { + return { + source: peg$source, + start: peg$savedPos, + end: peg$currPos + }; + } + + function location() { + return peg$computeLocation(peg$savedPos, peg$currPos); + } + + function expected(description, location) { + location = location !== undefined + ? location + : peg$computeLocation(peg$savedPos, peg$currPos); + + throw peg$buildStructuredError( + [peg$otherExpectation(description)], + input.substring(peg$savedPos, peg$currPos), + location + ); + } + + function error(message, location) { + location = location !== undefined + ? location + : peg$computeLocation(peg$savedPos, peg$currPos); + + throw peg$buildSimpleError(message, location); + } + + function peg$literalExpectation(text, ignoreCase) { + return { type: "literal", text: text, ignoreCase: ignoreCase }; + } + + function peg$classExpectation(parts, inverted, ignoreCase) { + return { type: "class", parts: parts, inverted: inverted, ignoreCase: ignoreCase }; + } + + function peg$anyExpectation() { + return { type: "any" }; + } + + function peg$endExpectation() { + return { type: "end" }; + } + + function peg$otherExpectation(description) { + return { type: "other", description: description }; + } + + function peg$computePosDetails(pos) { + var details = peg$posDetailsCache[pos]; + var p; + + if (details) { + return details; + } else { + p = pos - 1; + while (!peg$posDetailsCache[p]) { + p--; + } + + details = peg$posDetailsCache[p]; + details = { + line: details.line, + column: details.column + }; + + while (p < pos) { + if (input.charCodeAt(p) === 10) { + details.line++; + details.column = 1; + } else { + details.column++; + } + + p++; + } + + peg$posDetailsCache[pos] = details; + + return details; + } + } + + function peg$computeLocation(startPos, endPos) { + var startPosDetails = peg$computePosDetails(startPos); + var endPosDetails = peg$computePosDetails(endPos); + + return { + source: peg$source, + start: { + offset: startPos, + line: startPosDetails.line, + column: startPosDetails.column + }, + end: { + offset: endPos, + line: endPosDetails.line, + column: endPosDetails.column + } + }; + } + + function peg$fail(expected) { + if (peg$currPos < peg$maxFailPos) { return; } + + if (peg$currPos > peg$maxFailPos) { + peg$maxFailPos = peg$currPos; + peg$maxFailExpected = []; + } + + peg$maxFailExpected.push(expected); + } + + function peg$buildSimpleError(message, location) { + return new peg$SyntaxError(message, null, null, location); + } + + function peg$buildStructuredError(expected, found, location) { + return new peg$SyntaxError( + peg$SyntaxError.buildMessage(expected, found), + expected, + found, + location + ); + } + + function peg$parsestart() { + var s0; + + s0 = peg$parsestatement(); + + return s0; + } + + function peg$parsenumber() { + var s0, s1, s2, s3, s4; + + peg$silentFails++; + s0 = peg$currPos; + s1 = peg$parseminus(); + if (s1 === peg$FAILED) { + s1 = null; + } + s2 = peg$parseint(); + if (s2 !== peg$FAILED) { + s3 = peg$parsefrac(); + if (s3 === peg$FAILED) { + s3 = null; + } + s4 = peg$parseexp(); + if (s4 === peg$FAILED) { + s4 = null; + } + peg$savedPos = s0; + s0 = peg$f0(); + } else { + peg$currPos = s0; + s0 = peg$FAILED; + } + peg$silentFails--; + if (s0 === peg$FAILED) { + s1 = peg$FAILED; + if (peg$silentFails === 0) { peg$fail(peg$e0); } + } + + return s0; + } + + function peg$parsedecimal_point() { + var s0; + + if (input.charCodeAt(peg$currPos) === 46) { + s0 = peg$c0; + peg$currPos++; + } else { + s0 = peg$FAILED; + if (peg$silentFails === 0) { peg$fail(peg$e1); } + } + + return s0; + } + + function peg$parsedigit1_9() { + var s0; + + if (peg$r0.test(input.charAt(peg$currPos))) { + s0 = input.charAt(peg$currPos); + peg$currPos++; + } else { + s0 = peg$FAILED; + if (peg$silentFails === 0) { peg$fail(peg$e2); } + } + + return s0; + } + + function peg$parsee() { + var s0; + + if (peg$r1.test(input.charAt(peg$currPos))) { + s0 = input.charAt(peg$currPos); + peg$currPos++; + } else { + s0 = peg$FAILED; + if (peg$silentFails === 0) { peg$fail(peg$e3); } + } + + return s0; + } + + function peg$parseexp() { + var s0, s1, s2, s3, s4; + + s0 = peg$currPos; + s1 = peg$parsee(); + if (s1 !== peg$FAILED) { + s2 = peg$parseminus(); + if (s2 === peg$FAILED) { + s2 = peg$parseplus(); + } + if (s2 === peg$FAILED) { + s2 = null; + } + s3 = []; + s4 = peg$parseDIGIT(); + if (s4 !== peg$FAILED) { + while (s4 !== peg$FAILED) { + s3.push(s4); + s4 = peg$parseDIGIT(); + } + } else { + s3 = peg$FAILED; + } + if (s3 !== peg$FAILED) { + s1 = [s1, s2, s3]; + s0 = s1; + } else { + peg$currPos = s0; + s0 = peg$FAILED; + } + } else { + peg$currPos = s0; + s0 = peg$FAILED; + } + + return s0; + } + + function peg$parsefrac() { + var s0, s1, s2, s3; + + s0 = peg$currPos; + s1 = peg$parsedecimal_point(); + if (s1 !== peg$FAILED) { + s2 = []; + s3 = peg$parseDIGIT(); + if (s3 !== peg$FAILED) { + while (s3 !== peg$FAILED) { + s2.push(s3); + s3 = peg$parseDIGIT(); + } + } else { + s2 = peg$FAILED; + } + if (s2 !== peg$FAILED) { + s1 = [s1, s2]; + s0 = s1; + } else { + peg$currPos = s0; + s0 = peg$FAILED; + } + } else { + peg$currPos = s0; + s0 = peg$FAILED; + } + + return s0; + } + + function peg$parseint() { + var s0, s1, s2, s3; + + s0 = peg$parsezero(); + if (s0 === peg$FAILED) { + s0 = peg$currPos; + s1 = peg$parsedigit1_9(); + if (s1 !== peg$FAILED) { + s2 = []; + s3 = peg$parseDIGIT(); + while (s3 !== peg$FAILED) { + s2.push(s3); + s3 = peg$parseDIGIT(); + } + s1 = [s1, s2]; + s0 = s1; + } else { + peg$currPos = s0; + s0 = peg$FAILED; + } + } + + return s0; + } + + function peg$parseminus() { + var s0; + + if (input.charCodeAt(peg$currPos) === 45) { + s0 = peg$c1; + peg$currPos++; + } else { + s0 = peg$FAILED; + if (peg$silentFails === 0) { peg$fail(peg$e4); } + } + + return s0; + } + + function peg$parseplus() { + var s0; + + if (input.charCodeAt(peg$currPos) === 43) { + s0 = peg$c2; + peg$currPos++; + } else { + s0 = peg$FAILED; + if (peg$silentFails === 0) { peg$fail(peg$e5); } + } + + return s0; + } + + function peg$parsezero() { + var s0; + + if (input.charCodeAt(peg$currPos) === 48) { + s0 = peg$c3; + peg$currPos++; + } else { + s0 = peg$FAILED; + if (peg$silentFails === 0) { peg$fail(peg$e6); } + } + + return s0; + } + + function peg$parseDIGIT() { + var s0; + + if (peg$r2.test(input.charAt(peg$currPos))) { + s0 = input.charAt(peg$currPos); + peg$currPos++; + } else { + s0 = peg$FAILED; + if (peg$silentFails === 0) { peg$fail(peg$e7); } + } + + return s0; + } + + function peg$parsews() { + var s0, s1; + + peg$silentFails++; + s0 = []; + if (peg$r3.test(input.charAt(peg$currPos))) { + s1 = input.charAt(peg$currPos); + peg$currPos++; + } else { + s1 = peg$FAILED; + if (peg$silentFails === 0) { peg$fail(peg$e9); } + } + while (s1 !== peg$FAILED) { + s0.push(s1); + if (peg$r3.test(input.charAt(peg$currPos))) { + s1 = input.charAt(peg$currPos); + peg$currPos++; + } else { + s1 = peg$FAILED; + if (peg$silentFails === 0) { peg$fail(peg$e9); } + } + } + peg$silentFails--; + s1 = peg$FAILED; + if (peg$silentFails === 0) { peg$fail(peg$e8); } + + return s0; + } + + function peg$parsecomma() { + var s0, s1, s2, s3; + + s0 = peg$currPos; + s1 = peg$parsews(); + if (input.charCodeAt(peg$currPos) === 44) { + s2 = peg$c4; + peg$currPos++; + } else { + s2 = peg$FAILED; + if (peg$silentFails === 0) { peg$fail(peg$e10); } + } + if (s2 !== peg$FAILED) { + s3 = peg$parsews(); + s1 = [s1, s2, s3]; + s0 = s1; + } else { + peg$currPos = s0; + s0 = peg$FAILED; + } + + return s0; + } + + function peg$parsequote() { + var s0; + + if (input.charCodeAt(peg$currPos) === 34) { + s0 = peg$c5; + peg$currPos++; + } else { + s0 = peg$FAILED; + if (peg$silentFails === 0) { peg$fail(peg$e11); } + } + if (s0 === peg$FAILED) { + if (input.charCodeAt(peg$currPos) === 39) { + s0 = peg$c6; + peg$currPos++; + } else { + s0 = peg$FAILED; + if (peg$silentFails === 0) { peg$fail(peg$e12); } + } + } + + return s0; + } + + function peg$parsestep_char() { + var s0; + + if (peg$r4.test(input.charAt(peg$currPos))) { + s0 = input.charAt(peg$currPos); + peg$currPos++; + } else { + s0 = peg$FAILED; + if (peg$silentFails === 0) { peg$fail(peg$e13); } + } + if (s0 === peg$FAILED) { + if (input.charCodeAt(peg$currPos) === 45) { + s0 = peg$c1; + peg$currPos++; + } else { + s0 = peg$FAILED; + if (peg$silentFails === 0) { peg$fail(peg$e4); } + } + if (s0 === peg$FAILED) { + if (input.charCodeAt(peg$currPos) === 35) { + s0 = peg$c7; + peg$currPos++; + } else { + s0 = peg$FAILED; + if (peg$silentFails === 0) { peg$fail(peg$e14); } + } + if (s0 === peg$FAILED) { + if (input.charCodeAt(peg$currPos) === 46) { + s0 = peg$c0; + peg$currPos++; + } else { + s0 = peg$FAILED; + if (peg$silentFails === 0) { peg$fail(peg$e1); } + } + } + } + } + + return s0; + } + + function peg$parsestep() { + var s0, s1, s2, s3; + + s0 = peg$currPos; + s1 = peg$parsews(); + s2 = []; + s3 = peg$parsestep_char(); + if (s3 !== peg$FAILED) { + while (s3 !== peg$FAILED) { + s2.push(s3); + s3 = peg$parsestep_char(); + } + } else { + s2 = peg$FAILED; + } + if (s2 !== peg$FAILED) { + s3 = peg$parsews(); + peg$savedPos = s0; + s0 = peg$f1(s2); + } else { + peg$currPos = s0; + s0 = peg$FAILED; + } + + return s0; + } + + function peg$parsesub_cycle() { + var s0, s1, s2, s3, s4, s5, s6, s7; + + s0 = peg$currPos; + s1 = peg$parsews(); + if (input.charCodeAt(peg$currPos) === 91) { + s2 = peg$c8; + peg$currPos++; + } else { + s2 = peg$FAILED; + if (peg$silentFails === 0) { peg$fail(peg$e15); } + } + if (s2 !== peg$FAILED) { + s3 = peg$parsews(); + s4 = peg$parsestack(); + if (s4 !== peg$FAILED) { + s5 = peg$parsews(); + if (input.charCodeAt(peg$currPos) === 93) { + s6 = peg$c9; + peg$currPos++; + } else { + s6 = peg$FAILED; + if (peg$silentFails === 0) { peg$fail(peg$e16); } + } + if (s6 !== peg$FAILED) { + s7 = peg$parsews(); + peg$savedPos = s0; + s0 = peg$f2(s4); + } else { + peg$currPos = s0; + s0 = peg$FAILED; + } + } else { + peg$currPos = s0; + s0 = peg$FAILED; + } + } else { + peg$currPos = s0; + s0 = peg$FAILED; + } + + return s0; + } + + function peg$parsetimeline() { + var s0, s1, s2, s3, s4, s5, s6, s7; + + s0 = peg$currPos; + s1 = peg$parsews(); + if (input.charCodeAt(peg$currPos) === 60) { + s2 = peg$c10; + peg$currPos++; + } else { + s2 = peg$FAILED; + if (peg$silentFails === 0) { peg$fail(peg$e17); } + } + if (s2 !== peg$FAILED) { + s3 = peg$parsews(); + s4 = peg$parsesingle_cycle(); + if (s4 !== peg$FAILED) { + s5 = peg$parsews(); + if (input.charCodeAt(peg$currPos) === 62) { + s6 = peg$c11; + peg$currPos++; + } else { + s6 = peg$FAILED; + if (peg$silentFails === 0) { peg$fail(peg$e18); } + } + if (s6 !== peg$FAILED) { + s7 = peg$parsews(); + peg$savedPos = s0; + s0 = peg$f3(s4); + } else { + peg$currPos = s0; + s0 = peg$FAILED; + } + } else { + peg$currPos = s0; + s0 = peg$FAILED; + } + } else { + peg$currPos = s0; + s0 = peg$FAILED; + } + + return s0; + } + + function peg$parseslice() { + var s0; + + s0 = peg$parsestep(); + if (s0 === peg$FAILED) { + s0 = peg$parsesub_cycle(); + if (s0 === peg$FAILED) { + s0 = peg$parsetimeline(); + } + } + + return s0; + } + + function peg$parseslice_modifier() { + var s0; + + s0 = peg$parseslice_weight(); + if (s0 === peg$FAILED) { + s0 = peg$parseslice_bjorklund(); + if (s0 === peg$FAILED) { + s0 = peg$parseslice_slow(); + if (s0 === peg$FAILED) { + s0 = peg$parseslice_fast(); + if (s0 === peg$FAILED) { + s0 = peg$parseslice_fixed_step(); + } + } + } + } + + return s0; + } + + function peg$parseslice_weight() { + var s0, s1, s2; + + s0 = peg$currPos; + if (input.charCodeAt(peg$currPos) === 64) { + s1 = peg$c12; + peg$currPos++; + } else { + s1 = peg$FAILED; + if (peg$silentFails === 0) { peg$fail(peg$e19); } + } + if (s1 !== peg$FAILED) { + s2 = peg$parsenumber(); + if (s2 !== peg$FAILED) { + peg$savedPos = s0; + s0 = peg$f4(s2); + } else { + peg$currPos = s0; + s0 = peg$FAILED; + } + } else { + peg$currPos = s0; + s0 = peg$FAILED; + } + + return s0; + } + + function peg$parseslice_bjorklund() { + var s0, s1, s2, s3, s4, s5, s6, s7, s8, s9; + + s0 = peg$currPos; + if (input.charCodeAt(peg$currPos) === 40) { + s1 = peg$c13; + peg$currPos++; + } else { + s1 = peg$FAILED; + if (peg$silentFails === 0) { peg$fail(peg$e20); } + } + if (s1 !== peg$FAILED) { + s2 = peg$parsews(); + s3 = peg$parsenumber(); + if (s3 !== peg$FAILED) { + s4 = peg$parsews(); + s5 = peg$parsecomma(); + if (s5 !== peg$FAILED) { + s6 = peg$parsews(); + s7 = peg$parsenumber(); + if (s7 !== peg$FAILED) { + s8 = peg$parsews(); + if (input.charCodeAt(peg$currPos) === 41) { + s9 = peg$c14; + peg$currPos++; + } else { + s9 = peg$FAILED; + if (peg$silentFails === 0) { peg$fail(peg$e21); } + } + if (s9 !== peg$FAILED) { + peg$savedPos = s0; + s0 = peg$f5(s3, s7); + } else { + peg$currPos = s0; + s0 = peg$FAILED; + } + } else { + peg$currPos = s0; + s0 = peg$FAILED; + } + } else { + peg$currPos = s0; + s0 = peg$FAILED; + } + } else { + peg$currPos = s0; + s0 = peg$FAILED; + } + } else { + peg$currPos = s0; + s0 = peg$FAILED; + } + + return s0; + } + + function peg$parseslice_slow() { + var s0, s1, s2; + + s0 = peg$currPos; + if (input.charCodeAt(peg$currPos) === 47) { + s1 = peg$c15; + peg$currPos++; + } else { + s1 = peg$FAILED; + if (peg$silentFails === 0) { peg$fail(peg$e22); } + } + if (s1 !== peg$FAILED) { + s2 = peg$parsenumber(); + if (s2 !== peg$FAILED) { + peg$savedPos = s0; + s0 = peg$f6(s2); + } else { + peg$currPos = s0; + s0 = peg$FAILED; + } + } else { + peg$currPos = s0; + s0 = peg$FAILED; + } + + return s0; + } + + function peg$parseslice_fast() { + var s0, s1, s2; + + s0 = peg$currPos; + if (input.charCodeAt(peg$currPos) === 42) { + s1 = peg$c16; + peg$currPos++; + } else { + s1 = peg$FAILED; + if (peg$silentFails === 0) { peg$fail(peg$e23); } + } + if (s1 !== peg$FAILED) { + s2 = peg$parsenumber(); + if (s2 !== peg$FAILED) { + peg$savedPos = s0; + s0 = peg$f7(s2); + } else { + peg$currPos = s0; + s0 = peg$FAILED; + } + } else { + peg$currPos = s0; + s0 = peg$FAILED; + } + + return s0; + } + + function peg$parseslice_fixed_step() { + var s0, s1, s2; + + s0 = peg$currPos; + if (input.charCodeAt(peg$currPos) === 37) { + s1 = peg$c17; + peg$currPos++; + } else { + s1 = peg$FAILED; + if (peg$silentFails === 0) { peg$fail(peg$e24); } + } + if (s1 !== peg$FAILED) { + s2 = peg$parsenumber(); + if (s2 !== peg$FAILED) { + peg$savedPos = s0; + s0 = peg$f8(s2); + } else { + peg$currPos = s0; + s0 = peg$FAILED; + } + } else { + peg$currPos = s0; + s0 = peg$FAILED; + } + + return s0; + } + + function peg$parseslice_with_modifier() { + var s0, s1, s2; + + s0 = peg$currPos; + s1 = peg$parseslice(); + if (s1 !== peg$FAILED) { + s2 = peg$parseslice_modifier(); + if (s2 === peg$FAILED) { + s2 = null; + } + peg$savedPos = s0; + s0 = peg$f9(s1, s2); + } else { + peg$currPos = s0; + s0 = peg$FAILED; + } + + return s0; + } + + function peg$parsesingle_cycle() { + var s0, s1, s2; + + s0 = peg$currPos; + s1 = []; + s2 = peg$parseslice_with_modifier(); + if (s2 !== peg$FAILED) { + while (s2 !== peg$FAILED) { + s1.push(s2); + s2 = peg$parseslice_with_modifier(); + } + } else { + s1 = peg$FAILED; + } + if (s1 !== peg$FAILED) { + peg$savedPos = s0; + s1 = peg$f10(s1); + } + s0 = s1; + + return s0; + } + + function peg$parsestack() { + var s0, s1, s2, s3, s4, s5; + + s0 = peg$currPos; + s1 = peg$parsesingle_cycle(); + if (s1 !== peg$FAILED) { + s2 = []; + s3 = peg$currPos; + s4 = peg$parsecomma(); + if (s4 !== peg$FAILED) { + s5 = peg$parsesingle_cycle(); + if (s5 !== peg$FAILED) { + peg$savedPos = s3; + s3 = peg$f11(s1, s5); + } else { + peg$currPos = s3; + s3 = peg$FAILED; + } + } else { + peg$currPos = s3; + s3 = peg$FAILED; + } + while (s3 !== peg$FAILED) { + s2.push(s3); + s3 = peg$currPos; + s4 = peg$parsecomma(); + if (s4 !== peg$FAILED) { + s5 = peg$parsesingle_cycle(); + if (s5 !== peg$FAILED) { + peg$savedPos = s3; + s3 = peg$f11(s1, s5); + } else { + peg$currPos = s3; + s3 = peg$FAILED; + } + } else { + peg$currPos = s3; + s3 = peg$FAILED; + } + } + peg$savedPos = s0; + s0 = peg$f12(s1, s2); + } else { + peg$currPos = s0; + s0 = peg$FAILED; + } + + return s0; + } + + function peg$parsesequence() { + var s0, s1, s2, s3, s4; + + s0 = peg$currPos; + s1 = peg$parsews(); + s2 = peg$parsequote(); + if (s2 !== peg$FAILED) { + s3 = peg$parsestack(); + if (s3 !== peg$FAILED) { + s4 = peg$parsequote(); + if (s4 !== peg$FAILED) { + peg$savedPos = s0; + s0 = peg$f13(s3); + } else { + peg$currPos = s0; + s0 = peg$FAILED; + } + } else { + peg$currPos = s0; + s0 = peg$FAILED; + } + } else { + peg$currPos = s0; + s0 = peg$FAILED; + } + + return s0; + } + + function peg$parseoperator() { + var s0; + + s0 = peg$parsescale(); + if (s0 === peg$FAILED) { + s0 = peg$parseslow(); + if (s0 === peg$FAILED) { + s0 = peg$parsefast(); + if (s0 === peg$FAILED) { + s0 = peg$parsetarget(); + if (s0 === peg$FAILED) { + s0 = peg$parsebjorklund(); + if (s0 === peg$FAILED) { + s0 = peg$parsestruct(); + if (s0 === peg$FAILED) { + s0 = peg$parserotR(); + if (s0 === peg$FAILED) { + s0 = peg$parserotL(); + } + } + } + } + } + } + } + + return s0; + } + + function peg$parsestruct() { + var s0, s1, s2, s3; + + s0 = peg$currPos; + if (input.substr(peg$currPos, 6) === peg$c18) { + s1 = peg$c18; + peg$currPos += 6; + } else { + s1 = peg$FAILED; + if (peg$silentFails === 0) { peg$fail(peg$e25); } + } + if (s1 !== peg$FAILED) { + s2 = peg$parsews(); + s3 = peg$parsesequence_or_operator(); + if (s3 !== peg$FAILED) { + peg$savedPos = s0; + s0 = peg$f14(s3); + } else { + peg$currPos = s0; + s0 = peg$FAILED; + } + } else { + peg$currPos = s0; + s0 = peg$FAILED; + } + + return s0; + } + + function peg$parsetarget() { + var s0, s1, s2, s3, s4, s5; + + s0 = peg$currPos; + if (input.substr(peg$currPos, 6) === peg$c19) { + s1 = peg$c19; + peg$currPos += 6; + } else { + s1 = peg$FAILED; + if (peg$silentFails === 0) { peg$fail(peg$e26); } + } + if (s1 !== peg$FAILED) { + s2 = peg$parsews(); + s3 = peg$parsequote(); + if (s3 !== peg$FAILED) { + s4 = peg$parsestep(); + if (s4 !== peg$FAILED) { + s5 = peg$parsequote(); + if (s5 !== peg$FAILED) { + peg$savedPos = s0; + s0 = peg$f15(s4); + } else { + peg$currPos = s0; + s0 = peg$FAILED; + } + } else { + peg$currPos = s0; + s0 = peg$FAILED; + } + } else { + peg$currPos = s0; + s0 = peg$FAILED; + } + } else { + peg$currPos = s0; + s0 = peg$FAILED; + } + + return s0; + } + + function peg$parsebjorklund() { + var s0, s1, s2, s3, s4, s5; + + s0 = peg$currPos; + if (input.substr(peg$currPos, 6) === peg$c20) { + s1 = peg$c20; + peg$currPos += 6; + } else { + s1 = peg$FAILED; + if (peg$silentFails === 0) { peg$fail(peg$e27); } + } + if (s1 !== peg$FAILED) { + s2 = peg$parsews(); + s3 = peg$parseint(); + if (s3 !== peg$FAILED) { + s4 = peg$parsews(); + s5 = peg$parseint(); + if (s5 !== peg$FAILED) { + peg$savedPos = s0; + s0 = peg$f16(s3, s5); + } else { + peg$currPos = s0; + s0 = peg$FAILED; + } + } else { + peg$currPos = s0; + s0 = peg$FAILED; + } + } else { + peg$currPos = s0; + s0 = peg$FAILED; + } + + return s0; + } + + function peg$parseslow() { + var s0, s1, s2, s3; + + s0 = peg$currPos; + if (input.substr(peg$currPos, 4) === peg$c21) { + s1 = peg$c21; + peg$currPos += 4; + } else { + s1 = peg$FAILED; + if (peg$silentFails === 0) { peg$fail(peg$e28); } + } + if (s1 !== peg$FAILED) { + s2 = peg$parsews(); + s3 = peg$parsenumber(); + if (s3 !== peg$FAILED) { + peg$savedPos = s0; + s0 = peg$f17(s3); + } else { + peg$currPos = s0; + s0 = peg$FAILED; + } + } else { + peg$currPos = s0; + s0 = peg$FAILED; + } + + return s0; + } + + function peg$parserotL() { + var s0, s1, s2, s3; + + s0 = peg$currPos; + if (input.substr(peg$currPos, 4) === peg$c22) { + s1 = peg$c22; + peg$currPos += 4; + } else { + s1 = peg$FAILED; + if (peg$silentFails === 0) { peg$fail(peg$e29); } + } + if (s1 !== peg$FAILED) { + s2 = peg$parsews(); + s3 = peg$parsenumber(); + if (s3 !== peg$FAILED) { + peg$savedPos = s0; + s0 = peg$f18(s3); + } else { + peg$currPos = s0; + s0 = peg$FAILED; + } + } else { + peg$currPos = s0; + s0 = peg$FAILED; + } + + return s0; + } + + function peg$parserotR() { + var s0, s1, s2, s3; + + s0 = peg$currPos; + if (input.substr(peg$currPos, 4) === peg$c23) { + s1 = peg$c23; + peg$currPos += 4; + } else { + s1 = peg$FAILED; + if (peg$silentFails === 0) { peg$fail(peg$e30); } + } + if (s1 !== peg$FAILED) { + s2 = peg$parsews(); + s3 = peg$parsenumber(); + if (s3 !== peg$FAILED) { + peg$savedPos = s0; + s0 = peg$f19(s3); + } else { + peg$currPos = s0; + s0 = peg$FAILED; + } + } else { + peg$currPos = s0; + s0 = peg$FAILED; + } + + return s0; + } + + function peg$parsefast() { + var s0, s1, s2, s3; + + s0 = peg$currPos; + if (input.substr(peg$currPos, 4) === peg$c24) { + s1 = peg$c24; + peg$currPos += 4; + } else { + s1 = peg$FAILED; + if (peg$silentFails === 0) { peg$fail(peg$e31); } + } + if (s1 !== peg$FAILED) { + s2 = peg$parsews(); + s3 = peg$parsenumber(); + if (s3 !== peg$FAILED) { + peg$savedPos = s0; + s0 = peg$f20(s3); + } else { + peg$currPos = s0; + s0 = peg$FAILED; + } + } else { + peg$currPos = s0; + s0 = peg$FAILED; + } + + return s0; + } + + function peg$parsescale() { + var s0, s1, s2, s3, s4, s5; + + s0 = peg$currPos; + if (input.substr(peg$currPos, 5) === peg$c25) { + s1 = peg$c25; + peg$currPos += 5; + } else { + s1 = peg$FAILED; + if (peg$silentFails === 0) { peg$fail(peg$e32); } + } + if (s1 !== peg$FAILED) { + s2 = peg$parsews(); + s3 = peg$parsequote(); + if (s3 !== peg$FAILED) { + s4 = []; + s5 = peg$parsestep_char(); + if (s5 !== peg$FAILED) { + while (s5 !== peg$FAILED) { + s4.push(s5); + s5 = peg$parsestep_char(); + } + } else { + s4 = peg$FAILED; + } + if (s4 !== peg$FAILED) { + s5 = peg$parsequote(); + if (s5 !== peg$FAILED) { + peg$savedPos = s0; + s0 = peg$f21(s4); + } else { + peg$currPos = s0; + s0 = peg$FAILED; + } + } else { + peg$currPos = s0; + s0 = peg$FAILED; + } + } else { + peg$currPos = s0; + s0 = peg$FAILED; + } + } else { + peg$currPos = s0; + s0 = peg$FAILED; + } + + return s0; + } + + function peg$parsecomment() { + var s0, s1, s2, s3; + + s0 = peg$currPos; + if (input.substr(peg$currPos, 2) === peg$c26) { + s1 = peg$c26; + peg$currPos += 2; + } else { + s1 = peg$FAILED; + if (peg$silentFails === 0) { peg$fail(peg$e33); } + } + if (s1 !== peg$FAILED) { + s2 = []; + if (peg$r5.test(input.charAt(peg$currPos))) { + s3 = input.charAt(peg$currPos); + peg$currPos++; + } else { + s3 = peg$FAILED; + if (peg$silentFails === 0) { peg$fail(peg$e34); } + } + while (s3 !== peg$FAILED) { + s2.push(s3); + if (peg$r5.test(input.charAt(peg$currPos))) { + s3 = input.charAt(peg$currPos); + peg$currPos++; + } else { + s3 = peg$FAILED; + if (peg$silentFails === 0) { peg$fail(peg$e34); } + } + } + s1 = [s1, s2]; + s0 = s1; + } else { + peg$currPos = s0; + s0 = peg$FAILED; + } + + return s0; + } + + function peg$parsecat() { + var s0, s1, s2, s3, s4, s5, s6, s7, s8, s9; + + s0 = peg$currPos; + if (input.substr(peg$currPos, 3) === peg$c27) { + s1 = peg$c27; + peg$currPos += 3; + } else { + s1 = peg$FAILED; + if (peg$silentFails === 0) { peg$fail(peg$e35); } + } + if (s1 !== peg$FAILED) { + s2 = peg$parsews(); + if (input.charCodeAt(peg$currPos) === 91) { + s3 = peg$c8; + peg$currPos++; + } else { + s3 = peg$FAILED; + if (peg$silentFails === 0) { peg$fail(peg$e15); } + } + if (s3 !== peg$FAILED) { + s4 = peg$parsews(); + s5 = peg$parsesequence_or_operator(); + if (s5 !== peg$FAILED) { + s6 = []; + s7 = peg$currPos; + s8 = peg$parsecomma(); + if (s8 !== peg$FAILED) { + s9 = peg$parsesequence_or_operator(); + if (s9 !== peg$FAILED) { + peg$savedPos = s7; + s7 = peg$f22(s5, s9); + } else { + peg$currPos = s7; + s7 = peg$FAILED; + } + } else { + peg$currPos = s7; + s7 = peg$FAILED; + } + while (s7 !== peg$FAILED) { + s6.push(s7); + s7 = peg$currPos; + s8 = peg$parsecomma(); + if (s8 !== peg$FAILED) { + s9 = peg$parsesequence_or_operator(); + if (s9 !== peg$FAILED) { + peg$savedPos = s7; + s7 = peg$f22(s5, s9); + } else { + peg$currPos = s7; + s7 = peg$FAILED; + } + } else { + peg$currPos = s7; + s7 = peg$FAILED; + } + } + s7 = peg$parsews(); + if (input.charCodeAt(peg$currPos) === 93) { + s8 = peg$c9; + peg$currPos++; + } else { + s8 = peg$FAILED; + if (peg$silentFails === 0) { peg$fail(peg$e16); } + } + if (s8 !== peg$FAILED) { + peg$savedPos = s0; + s0 = peg$f23(s5, s6); + } else { + peg$currPos = s0; + s0 = peg$FAILED; + } + } else { + peg$currPos = s0; + s0 = peg$FAILED; + } + } else { + peg$currPos = s0; + s0 = peg$FAILED; + } + } else { + peg$currPos = s0; + s0 = peg$FAILED; + } + + return s0; + } + + function peg$parsesequence_or_group() { + var s0; + + s0 = peg$parsecat(); + if (s0 === peg$FAILED) { + s0 = peg$parsesequence(); + } + + return s0; + } + + function peg$parsesequence_or_operator() { + var s0, s1, s2, s3, s4, s5; + + s0 = peg$currPos; + s1 = peg$parsesequence_or_group(); + if (s1 !== peg$FAILED) { + s2 = peg$parsews(); + s3 = []; + s4 = peg$parsecomment(); + while (s4 !== peg$FAILED) { + s3.push(s4); + s4 = peg$parsecomment(); + } + peg$savedPos = s0; + s0 = peg$f24(s1); + } else { + peg$currPos = s0; + s0 = peg$FAILED; + } + if (s0 === peg$FAILED) { + s0 = peg$currPos; + s1 = peg$parseoperator(); + if (s1 !== peg$FAILED) { + s2 = peg$parsews(); + if (input.charCodeAt(peg$currPos) === 36) { + s3 = peg$c28; + peg$currPos++; + } else { + s3 = peg$FAILED; + if (peg$silentFails === 0) { peg$fail(peg$e36); } + } + if (s3 !== peg$FAILED) { + s4 = peg$parsews(); + s5 = peg$parsesequence_or_operator(); + if (s5 !== peg$FAILED) { + peg$savedPos = s0; + s0 = peg$f25(s1, s5); + } else { + peg$currPos = s0; + s0 = peg$FAILED; + } + } else { + peg$currPos = s0; + s0 = peg$FAILED; + } + } else { + peg$currPos = s0; + s0 = peg$FAILED; + } + } + + return s0; + } + + function peg$parsesequ_or_operator_or_comment() { + var s0, s1; + + s0 = peg$currPos; + s1 = peg$parsesequence_or_operator(); + if (s1 !== peg$FAILED) { + peg$savedPos = s0; + s1 = peg$f26(s1); + } + s0 = s1; + if (s0 === peg$FAILED) { + s0 = peg$parsecomment(); + } + + return s0; + } + + function peg$parsesequence_definition() { + var s0; + + s0 = peg$parsesequ_or_operator_or_comment(); + + return s0; + } + + function peg$parsecommand() { + var s0, s1, s2, s3; + + s0 = peg$currPos; + s1 = peg$parsews(); + s2 = peg$parsesetcps(); + if (s2 === peg$FAILED) { + s2 = peg$parsesetbpm(); + if (s2 === peg$FAILED) { + s2 = peg$parsehush(); + } + } + if (s2 !== peg$FAILED) { + s3 = peg$parsews(); + peg$savedPos = s0; + s0 = peg$f27(s2); + } else { + peg$currPos = s0; + s0 = peg$FAILED; + } + + return s0; + } + + function peg$parsesetcps() { + var s0, s1, s2, s3; + + s0 = peg$currPos; + if (input.substr(peg$currPos, 6) === peg$c29) { + s1 = peg$c29; + peg$currPos += 6; + } else { + s1 = peg$FAILED; + if (peg$silentFails === 0) { peg$fail(peg$e37); } + } + if (s1 !== peg$FAILED) { + s2 = peg$parsews(); + s3 = peg$parsenumber(); + if (s3 !== peg$FAILED) { + peg$savedPos = s0; + s0 = peg$f28(s3); + } else { + peg$currPos = s0; + s0 = peg$FAILED; + } + } else { + peg$currPos = s0; + s0 = peg$FAILED; + } + + return s0; + } + + function peg$parsesetbpm() { + var s0, s1, s2, s3; + + s0 = peg$currPos; + if (input.substr(peg$currPos, 6) === peg$c30) { + s1 = peg$c30; + peg$currPos += 6; + } else { + s1 = peg$FAILED; + if (peg$silentFails === 0) { peg$fail(peg$e38); } + } + if (s1 !== peg$FAILED) { + s2 = peg$parsews(); + s3 = peg$parsenumber(); + if (s3 !== peg$FAILED) { + peg$savedPos = s0; + s0 = peg$f29(s3); + } else { + peg$currPos = s0; + s0 = peg$FAILED; + } + } else { + peg$currPos = s0; + s0 = peg$FAILED; + } + + return s0; + } + + function peg$parsehush() { + var s0, s1; + + s0 = peg$currPos; + if (input.substr(peg$currPos, 4) === peg$c31) { + s1 = peg$c31; + peg$currPos += 4; + } else { + s1 = peg$FAILED; + if (peg$silentFails === 0) { peg$fail(peg$e39); } + } + if (s1 !== peg$FAILED) { + peg$savedPos = s0; + s1 = peg$f30(); + } + s0 = s1; + + return s0; + } + + function peg$parsestatement() { + var s0; + + s0 = peg$parsesequence_definition(); + if (s0 === peg$FAILED) { + s0 = peg$parsecommand(); + } + + return s0; + } + + + var PatternStub = function(source, alignment) + { + this.type_ = "pattern"; + this.arguments_ = { alignment : alignment}; + this.source_ = source; + } + + var OperatorStub = function(name, args, source) + { + this.type_ = name; + this.arguments_ = args; + this.source_ = source; + } + + var ElementStub = function(source, options) + { + this.type_ = "element"; + this.source_ = source; + this.options_ = options; + } + + var CommandStub = function(name, options) + { + this.type_ = "command"; + this.name_ = name; + this.options_ = options; + } + + + + peg$result = peg$startRuleFunction(); + + if (peg$result !== peg$FAILED && peg$currPos === input.length) { + return peg$result; + } else { + if (peg$result !== peg$FAILED && peg$currPos < input.length) { + peg$fail(peg$endExpectation()); + } + + throw peg$buildStructuredError( + peg$maxFailExpected, + peg$maxFailPos < input.length ? input.charAt(peg$maxFailPos) : null, + peg$maxFailPos < input.length + ? peg$computeLocation(peg$maxFailPos, peg$maxFailPos + 1) + : peg$computeLocation(peg$maxFailPos, peg$maxFailPos) + ); + } +} + +export { + peg$SyntaxError as SyntaxError, + peg$parse as parse +}; diff --git a/docs/_snowpack/link/strudel.js b/docs/_snowpack/link/strudel.js index 3934b8e4..0d6867c8 100644 --- a/docs/_snowpack/link/strudel.js +++ b/docs/_snowpack/link/strudel.js @@ -292,20 +292,40 @@ class Pattern { outerJoin() { return this.outerBind(id); } + _patternify(func) { + const pat = this; + const patterned = function(...args) { + const pat_arg = sequence(...args); + return pat_arg.fmap((arg) => func.call(pat, arg)).outerJoin(); + }; + return patterned; + } _fast(factor) { var fastQuery = this.withQueryTime((t) => t.mul(factor)); return fastQuery.withEventTime((t) => t.div(factor)); } + fast(factor) { + return this._patternify(Pattern.prototype._fast)(factor); + } _slow(factor) { return this._fast(1 / factor); } + slow(factor) { + return this._patternify(Pattern.prototype._slow)(factor); + } _early(offset) { offset = Fraction(offset); return this.withQueryTime((t) => t.add(offset)).withEventTime((t) => t.sub(offset)); } + early(factor) { + return this._patternify(Pattern.prototype._early)(factor); + } _late(offset) { return this._early(0 - offset); } + late(factor) { + return this._patternify(Pattern.prototype._late)(factor); + } when(binary_pat, func) { var true_pat = binary_pat._filterValues(id); var false_pat = binary_pat._filterValues((val) => !val); diff --git a/docs/dist/App.js b/docs/dist/App.js index 4284e687..92ad6e4a 100644 --- a/docs/dist/App.js +++ b/docs/dist/App.js @@ -5,13 +5,10 @@ import cx from "./cx.js"; import * as Tone from "../_snowpack/pkg/tone.js"; import useCycle from "./useCycle.js"; import {tetris} from "./tunes.js"; -const {Fraction, TimeSpan} = strudel; -const fr = (v) => new Fraction(v); -const ts = (start, end) => new TimeSpan(fr(start), fr(end)); -const parse = (code) => { - const {sequence, pure, reify, slowcat, fastcat, cat, stack, silence} = strudel; - return eval(code); -}; +import _mini from "./mini.js"; +const {sequence, pure, reify, slowcat, fastcat, cat, stack, silence} = strudel; +const mini = _mini; +const parse = (code) => eval(code); const synth = new Tone.PolySynth().toDestination(); synth.set({ oscillator: {type: "triangle"}, diff --git a/docs/dist/mini.js b/docs/dist/mini.js new file mode 100644 index 00000000..15b82788 --- /dev/null +++ b/docs/dist/mini.js @@ -0,0 +1,20 @@ +import * as krill from "../_snowpack/link/repl/krill-parser.js"; +import * as strudel from "../_snowpack/link/strudel.js"; +const {sequence, silence} = strudel; +export function patternifyAST(ast) { + switch (ast.type_) { + case "pattern": + return sequence(...ast.source_.map(patternifyAST)); + case "element": + if (ast.source_ === "~") { + return silence; + } + if (typeof ast.source_ !== "object") { + return ast.source_; + } + return patternifyAST(ast.source_); + } +} +export default (...strings) => { + return sequence(...strings.map((str) => patternifyAST(krill.parse(`"${str}"`)))); +}; diff --git a/docs/dist/tunes.js b/docs/dist/tunes.js index 3e9dd75d..4d71f41f 100644 --- a/docs/dist/tunes.js +++ b/docs/dist/tunes.js @@ -1,4 +1,4 @@ -export const tetris = `stack(sequence( +export const tetrisWithFunctions = `stack(sequence( 'e5', sequence('b4', 'c5'), 'd5', sequence('c5', 'b4'), 'a4', sequence('a4', 'c5'), 'e5', sequence('d5', 'c5'), 'b4', sequence(silence, 'c5'), 'd5', 'e5', @@ -18,6 +18,32 @@ export const tetris = `stack(sequence( 'a1', 'a2', 'a1', 'a2', 'a1', 'a2', 'a1', 'a2', ) )._slow(16)`; +export const tetris = `stack( + sequence( + mini( + 'e5 [b4 c5] d5 [c5 b4]', + 'a4 [a4 c5] e5 [d5 c5]', + 'b4 [~ c5] d5 e5', + 'c5 a4 a4 ~', + '[~ d5] [~ f5] a5 [g5 f5]', + 'e5 [~ c5] e5 [d5 c5]', + 'b4 [b4 c5] d5 e5', + 'c5 a4 a4 ~' + ) + ), + sequence( + mini( + 'e2 e3 e2 e3 e2 e3 e2 e3', + 'a2 a3 a2 a3 a2 a3 a2 a3', + 'g#2 g#3 g#2 g#3 e2 e3 e2 e3', + 'a2 a3 a2 a3 a2 a3 b1 c2', + 'd2 d3 d2 d3 d2 d3 d2 d3', + 'c2 c3 c2 c3 c2 c3 c2 c3', + 'b1 b2 b1 b2 e2 e3 e2 e3', + 'a1 a2 a1 a2 a1 a2 a1 a2' + ) + ) +)._slow(16);`; export const spanish = `slowcat( stack('c4','eb4','g4'), stack('bb3','d4','f4'),