UNPKG

doremi-script

Version:

Letter music notation processor

1,573 lines (1,489 loc) 236 kB
DoremiScriptParser = (function(){ /* Generated by PEG.js 0.6.2 (http://pegjs.majda.cz/). */ var result = { /* * Parses the input with a generated parser. If the parsing is successfull, * returns a value explicitly or implicitly specified by the grammar from * which the parser was generated (see |PEG.buildParser|). If the parsing is * unsuccessful, throws |PEG.parser.SyntaxError| describing the error. */ parse: function(input, startRule) { var parseFunctions = { "ABC_A": parse_ABC_A, "ABC_AFLAT": parse_ABC_AFLAT, "ABC_ASHARP": parse_ABC_ASHARP, "ABC_B": parse_ABC_B, "ABC_BEAT_DELIMITED": parse_ABC_BEAT_DELIMITED, "ABC_BEAT_DELIMITED_ITEM": parse_ABC_BEAT_DELIMITED_ITEM, "ABC_BEAT_UNDELIMITED": parse_ABC_BEAT_UNDELIMITED, "ABC_BEAT_UNDELIMITED_ITEM": parse_ABC_BEAT_UNDELIMITED_ITEM, "ABC_BFLAT": parse_ABC_BFLAT, "ABC_BSHARP": parse_ABC_BSHARP, "ABC_C": parse_ABC_C, "ABC_CFLAT": parse_ABC_CFLAT, "ABC_CSHARP": parse_ABC_CSHARP, "ABC_D": parse_ABC_D, "ABC_DFLAT": parse_ABC_DFLAT, "ABC_DSHARP": parse_ABC_DSHARP, "ABC_E": parse_ABC_E, "ABC_EFLAT": parse_ABC_EFLAT, "ABC_F": parse_ABC_F, "ABC_FSHARP": parse_ABC_FSHARP, "ABC_G": parse_ABC_G, "ABC_GFLAT": parse_ABC_GFLAT, "ABC_GSHARP": parse_ABC_GSHARP, "ABC_MEASURE": parse_ABC_MEASURE, "ABC_MUSICAL_CHAR": parse_ABC_MUSICAL_CHAR, "ABC_NON_BARLINE": parse_ABC_NON_BARLINE, "ABC_SARGAM_CHAR": parse_ABC_SARGAM_CHAR, "ABC_SARGAM_LINE": parse_ABC_SARGAM_LINE, "ABC_SARGAM_PITCH": parse_ABC_SARGAM_PITCH, "ALTERNATE_ENDING_INDICATOR": parse_ALTERNATE_ENDING_INDICATOR, "ATTRIBUTE_LINE": parse_ATTRIBUTE_LINE, "BARLINE": parse_BARLINE, "BEAT_DELIMITED": parse_BEAT_DELIMITED, "BEAT_DELIMITED_ITEM": parse_BEAT_DELIMITED_ITEM, "BEAT_UNDELIMITED": parse_BEAT_UNDELIMITED, "BEAT_UNDELIMITED_ITEM": parse_BEAT_UNDELIMITED_ITEM, "BEGIN_BEAT_SYMBOL": parse_BEGIN_BEAT_SYMBOL, "BEGIN_SLUR_OF_PITCH": parse_BEGIN_SLUR_OF_PITCH, "CHORD_SYMBOL": parse_CHORD_SYMBOL, "CHORD_SYMBOL_CHAR": parse_CHORD_SYMBOL_CHAR, "CHORD_SYMBOL_INITIAL_CHAR": parse_CHORD_SYMBOL_INITIAL_CHAR, "COMPOSITION": parse_COMPOSITION, "COMPOUND_LINE": parse_COMPOUND_LINE, "DELIMITED_SARGAM_ORNAMENT": parse_DELIMITED_SARGAM_ORNAMENT, "DEVANAGRI_BEAT_DELIMITED": parse_DEVANAGRI_BEAT_DELIMITED, "DEVANAGRI_BEAT_DELIMITED_ITEM": parse_DEVANAGRI_BEAT_DELIMITED_ITEM, "DEVANAGRI_BEAT_UNDELIMITED": parse_DEVANAGRI_BEAT_UNDELIMITED, "DEVANAGRI_BEAT_UNDELIMITED_ITEM": parse_DEVANAGRI_BEAT_UNDELIMITED_ITEM, "DEVANAGRI_DHA": parse_DEVANAGRI_DHA, "DEVANAGRI_GA": parse_DEVANAGRI_GA, "DEVANAGRI_MA": parse_DEVANAGRI_MA, "DEVANAGRI_MA_SHARP": parse_DEVANAGRI_MA_SHARP, "DEVANAGRI_MEASURE": parse_DEVANAGRI_MEASURE, "DEVANAGRI_MUSICAL_CHAR": parse_DEVANAGRI_MUSICAL_CHAR, "DEVANAGRI_NI": parse_DEVANAGRI_NI, "DEVANAGRI_NON_BARLINE": parse_DEVANAGRI_NON_BARLINE, "DEVANAGRI_PA": parse_DEVANAGRI_PA, "DEVANAGRI_RE": parse_DEVANAGRI_RE, "DEVANAGRI_SA": parse_DEVANAGRI_SA, "DEVANAGRI_SARGAM_LINE": parse_DEVANAGRI_SARGAM_LINE, "DEVANAGRI_SARGAM_PITCH": parse_DEVANAGRI_SARGAM_PITCH, "DOUBLE_BARLINE": parse_DOUBLE_BARLINE, "EMPTY_LINE": parse_EMPTY_LINE, "END_BEAT_SYMBOL": parse_END_BEAT_SYMBOL, "END_SLUR": parse_END_SLUR, "END_SLUR_OF_PITCH": parse_END_SLUR_OF_PITCH, "EOF": parse_EOF, "EOL": parse_EOL, "FINAL_BARLINE": parse_FINAL_BARLINE, "FORWARD_SLASH_CHAR": parse_FORWARD_SLASH_CHAR, "HEADER_SECTION": parse_HEADER_SECTION, "KOMMAL_INDICATOR": parse_KOMMAL_INDICATOR, "LEFT_REPEAT": parse_LEFT_REPEAT, "LINE": parse_LINE, "LINE_END": parse_LINE_END, "LINE_END_CHAR": parse_LINE_END_CHAR, "LINE_NUMBER": parse_LINE_NUMBER, "LOWER_LOWER_OCTAVE_SYMBOL": parse_LOWER_LOWER_OCTAVE_SYMBOL, "LOWER_OCTAVE_DOT": parse_LOWER_OCTAVE_DOT, "LOWER_OCTAVE_LINE": parse_LOWER_OCTAVE_LINE, "LOWER_OCTAVE_LINE_ITEM": parse_LOWER_OCTAVE_LINE_ITEM, "LYRICS_LINE": parse_LYRICS_LINE, "MEASURE": parse_MEASURE, "MORDENT": parse_MORDENT, "NON_BARLINE": parse_NON_BARLINE, "NUMBER_A": parse_NUMBER_A, "NUMBER_AFLAT": parse_NUMBER_AFLAT, "NUMBER_ASHARP": parse_NUMBER_ASHARP, "NUMBER_B": parse_NUMBER_B, "NUMBER_BEAT_DELIMITED": parse_NUMBER_BEAT_DELIMITED, "NUMBER_BEAT_DELIMITED_ITEM": parse_NUMBER_BEAT_DELIMITED_ITEM, "NUMBER_BEAT_UNDELIMITED": parse_NUMBER_BEAT_UNDELIMITED, "NUMBER_BEAT_UNDELIMITED_ITEM": parse_NUMBER_BEAT_UNDELIMITED_ITEM, "NUMBER_BFLAT": parse_NUMBER_BFLAT, "NUMBER_BSHARP": parse_NUMBER_BSHARP, "NUMBER_C": parse_NUMBER_C, "NUMBER_CFLAT": parse_NUMBER_CFLAT, "NUMBER_CSHARP": parse_NUMBER_CSHARP, "NUMBER_D": parse_NUMBER_D, "NUMBER_DFLAT": parse_NUMBER_DFLAT, "NUMBER_DSHARP": parse_NUMBER_DSHARP, "NUMBER_E": parse_NUMBER_E, "NUMBER_EFLAT": parse_NUMBER_EFLAT, "NUMBER_ESHARP": parse_NUMBER_ESHARP, "NUMBER_F": parse_NUMBER_F, "NUMBER_FFLAT": parse_NUMBER_FFLAT, "NUMBER_FSHARP": parse_NUMBER_FSHARP, "NUMBER_G": parse_NUMBER_G, "NUMBER_GFLAT": parse_NUMBER_GFLAT, "NUMBER_GSHARP": parse_NUMBER_GSHARP, "NUMBER_MEASURE": parse_NUMBER_MEASURE, "NUMBER_MUSICAL_CHAR": parse_NUMBER_MUSICAL_CHAR, "NUMBER_NON_BARLINE": parse_NUMBER_NON_BARLINE, "NUMBER_SARGAM_LINE": parse_NUMBER_SARGAM_LINE, "NUMBER_SARGAM_PITCH": parse_NUMBER_SARGAM_PITCH, "REPEAT_SYMBOL": parse_REPEAT_SYMBOL, "REVERSE_FINAL_BARLINE": parse_REVERSE_FINAL_BARLINE, "RHYTHMICAL_DASH": parse_RHYTHMICAL_DASH, "RIGHT_REPEAT": parse_RIGHT_REPEAT, "SARGAM_DHA": parse_SARGAM_DHA, "SARGAM_DHA_FLAT": parse_SARGAM_DHA_FLAT, "SARGAM_DHA_SHARP": parse_SARGAM_DHA_SHARP, "SARGAM_GA": parse_SARGAM_GA, "SARGAM_GA_FLAT": parse_SARGAM_GA_FLAT, "SARGAM_GA_SHARP": parse_SARGAM_GA_SHARP, "SARGAM_LINE": parse_SARGAM_LINE, "SARGAM_LINE_ITEM": parse_SARGAM_LINE_ITEM, "SARGAM_MA": parse_SARGAM_MA, "SARGAM_MA_SHARP": parse_SARGAM_MA_SHARP, "SARGAM_MUSICAL_CHAR": parse_SARGAM_MUSICAL_CHAR, "SARGAM_NI": parse_SARGAM_NI, "SARGAM_NI_FLAT": parse_SARGAM_NI_FLAT, "SARGAM_NI_SHARP": parse_SARGAM_NI_SHARP, "SARGAM_ORNAMENT": parse_SARGAM_ORNAMENT, "SARGAM_PA": parse_SARGAM_PA, "SARGAM_PA_FLAT": parse_SARGAM_PA_FLAT, "SARGAM_PA_SHARP": parse_SARGAM_PA_SHARP, "SARGAM_PITCH": parse_SARGAM_PITCH, "SARGAM_RE": parse_SARGAM_RE, "SARGAM_RE_FLAT": parse_SARGAM_RE_FLAT, "SARGAM_RE_SHARP": parse_SARGAM_RE_SHARP, "SARGAM_SA": parse_SARGAM_SA, "SARGAM_SA_FLAT": parse_SARGAM_SA_FLAT, "SARGAM_SA_SHARP": parse_SARGAM_SA_SHARP, "SIMPLE_LINE": parse_SIMPLE_LINE, "SINGLE_BARLINE": parse_SINGLE_BARLINE, "SPACE": parse_SPACE, "SYLLABLE": parse_SYLLABLE, "TALA": parse_TALA, "UNDELIMITED_SARGAM_PITCH_WITH_DASHES": parse_UNDELIMITED_SARGAM_PITCH_WITH_DASHES, "UPPER_OCTAVE_DOT": parse_UPPER_OCTAVE_DOT, "UPPER_OCTAVE_LINE": parse_UPPER_OCTAVE_LINE, "UPPER_OCTAVE_LINE_ITEM": parse_UPPER_OCTAVE_LINE_ITEM, "UPPER_UPPER_OCTAVE_SYMBOL": parse_UPPER_UPPER_OCTAVE_SYMBOL, "WHITE_SPACE": parse_WHITE_SPACE, "WORD": parse_WORD, "_": parse__ }; if (startRule !== undefined) { if (parseFunctions[startRule] === undefined) { throw new Error("Invalid rule name: " + quote(startRule) + "."); } } else { startRule = "COMPOSITION"; } var pos = 0; var reportFailures = 0; var rightmostFailuresPos = 0; var rightmostFailuresExpected = []; var cache = {}; var _chunk = {"pos":-1,"end":-1,"match":""}; function padLeft(input, padding, length) { var result = input; var padLength = length - input.length; for (var i = 0; i < padLength; i++) { result = padding + result; } return result; } function escape(ch) { var charCode = ch.charCodeAt(0); var escapeChar; var length; if (charCode <= 0xFF) { escapeChar = 'x'; length = 2; } else { escapeChar = 'u'; length = 4; } return '\\' + escapeChar + padLeft(charCode.toString(16).toUpperCase(), '0', length); } function quote(s) { /* * ECMA-262, 5th ed., 7.8.4: All characters may appear literally in a * string literal except for the closing quote character, backslash, * carriage return, line separator, paragraph separator, and line feed. * Any character may appear in the form of an escape sequence. * * For portability, we also escape escape all control and non-ASCII * characters. Note that "\0" and "\v" escape sequences are not used * because JSHint does not like the first and IE the second. */ return '"' + s .replace(/\\/g, '\\\\') // backslash .replace(/"/g, '\\"') // closing quote character .replace(/\x08/g, '\\b') // backspace .replace(/\t/g, '\\t') // horizontal tab .replace(/\n/g, '\\n') // line feed .replace(/\f/g, '\\f') // form feed .replace(/\r/g, '\\r') // carriage return .replace(/[\x00-\x07\x0B\x0E-\x1F\x80-\uFFFF]/g, escape) + '"'; } function matchFailed(failure) { if (pos < rightmostFailuresPos) { return; } if (pos > rightmostFailuresPos) { rightmostFailuresPos = pos; rightmostFailuresExpected = []; } rightmostFailuresExpected.push(failure); } function parse_EMPTY_LINE() { var cacheKey = "EMPTY_LINE@" + pos; var cachedResult = cache[cacheKey]; if (cachedResult) { pos = cachedResult.nextPos; return cachedResult.result; } var result0, result1, result2, result3, result4; var pos0, pos1, pos2; if (input.charCodeAt(pos) === 10) { result0 = "\n"; pos += 1; } else { result0 = null; if (reportFailures === 0) { matchFailed("\"\\n\""); } } if (result0 === null) { pos0 = pos; pos1 = pos; result0 = []; if (input.charCodeAt(pos) === 32) { result1 = " "; pos += 1; } else { result1 = null; if (reportFailures === 0) { matchFailed("\" \""); } } while (result1 !== null) { result0.push(result1); if (input.charCodeAt(pos) === 32) { result1 = " "; pos += 1; } else { result1 = null; if (reportFailures === 0) { matchFailed("\" \""); } } } if (result0 !== null) { result1 = parse_LINE_END_CHAR(); if (result1 !== null) { result2 = []; pos2 = pos; result3 = []; if (input.charCodeAt(pos) === 32) { result4 = " "; pos += 1; } else { result4 = null; if (reportFailures === 0) { matchFailed("\" \""); } } while (result4 !== null) { result3.push(result4); if (input.charCodeAt(pos) === 32) { result4 = " "; pos += 1; } else { result4 = null; if (reportFailures === 0) { matchFailed("\" \""); } } } if (result3 !== null) { result4 = parse_LINE_END_CHAR(); if (result4 !== null) { result3 = [result3, result4]; } else { result3 = null; pos = pos2; } } else { result3 = null; pos = pos2; } while (result3 !== null) { result2.push(result3); pos2 = pos; result3 = []; if (input.charCodeAt(pos) === 32) { result4 = " "; pos += 1; } else { result4 = null; if (reportFailures === 0) { matchFailed("\" \""); } } while (result4 !== null) { result3.push(result4); if (input.charCodeAt(pos) === 32) { result4 = " "; pos += 1; } else { result4 = null; if (reportFailures === 0) { matchFailed("\" \""); } } } if (result3 !== null) { result4 = parse_LINE_END_CHAR(); if (result4 !== null) { result3 = [result3, result4]; } else { result3 = null; pos = pos2; } } else { result3 = null; pos = pos2; } } if (result2 !== null) { result0 = [result0, result1, result2]; } else { result0 = null; pos = pos1; } } else { result0 = null; pos = pos1; } } else { result0 = null; pos = pos1; } _chunk.pos = pos0; _chunk.end = pos; _chunk.match = input.substring(pos0,pos); if (result0 !== null) { result0 = (function(_chunk) { return {my_type: "line_end"} })(_chunk); } if (result0 === null) { pos = pos0; } } cache[cacheKey] = { nextPos: pos, result: result0 }; return result0; } function parse_HEADER_SECTION() { var cacheKey = "HEADER_SECTION@" + pos; var cachedResult = cache[cacheKey]; if (cachedResult) { pos = cachedResult.nextPos; return cachedResult.result; } var result0, result1, result2; var pos0, pos1, pos2; reportFailures++; pos0 = pos; pos1 = pos; result1 = parse_ATTRIBUTE_LINE(); if (result1 !== null) { result0 = []; while (result1 !== null) { result0.push(result1); result1 = parse_ATTRIBUTE_LINE(); } } else { result0 = null; } if (result0 !== null) { result2 = parse_EMPTY_LINE(); if (result2 !== null) { result1 = []; while (result2 !== null) { result1.push(result2); result2 = parse_EMPTY_LINE(); } } else { result1 = null; } if (result1 === null) { result1 = parse_EOF(); if (result1 === null) { if (input.substr(pos, 2) === "/n") { result1 = "/n"; pos += 2; } else { result1 = null; if (reportFailures === 0) { matchFailed("\"/n\""); } } if (result1 === null) { pos2 = pos; reportFailures++; result1 = parse_LINE(); reportFailures--; if (result1 !== null) { result1 = ""; pos = pos2; } else { result1 = null; } } } } if (result1 !== null) { result0 = [result0, result1]; } else { result0 = null; pos = pos1; } } else { result0 = null; pos = pos1; } _chunk.pos = pos0; _chunk.end = pos; _chunk.match = input.substring(pos0,pos); if (result0 !== null) { result0 = (function(attributes, _chunk) { return { my_type:"attributes", items: attributes, source: "TODO" }})(result0[0], _chunk); } if (result0 === null) { pos = pos0; } reportFailures--; if (reportFailures === 0 && result0 === null) { matchFailed("Headers followed by blank lines or a line"); } cache[cacheKey] = { nextPos: pos, result: result0 }; return result0; } function parse_COMPOSITION() { var cacheKey = "COMPOSITION@" + pos; var cachedResult = cache[cacheKey]; if (cachedResult) { pos = cachedResult.nextPos; return cachedResult.result; } var result0, result1, result2, result3, result4; var pos0, pos1; reportFailures++; pos0 = pos; pos1 = pos; result0 = []; result1 = parse_LINE_END_CHAR(); while (result1 !== null) { result0.push(result1); result1 = parse_LINE_END_CHAR(); } if (result0 !== null) { result1 = []; result2 = parse_EMPTY_LINE(); while (result2 !== null) { result1.push(result2); result2 = parse_EMPTY_LINE(); } if (result1 !== null) { result2 = parse_HEADER_SECTION(); result2 = result2 !== null ? result2 : ""; if (result2 !== null) { result3 = []; result4 = parse_LINE(); while (result4 !== null) { result3.push(result4); result4 = parse_LINE(); } if (result3 !== null) { result4 = parse_EOF(); if (result4 === null) { result4 = parse_EMPTY_LINE(); } if (result4 !== null) { result0 = [result0, result1, result2, result3, result4]; } else { result0 = null; pos = pos1; } } else { result0 = null; pos = pos1; } } else { result0 = null; pos = pos1; } } else { result0 = null; pos = pos1; } } else { result0 = null; pos = pos1; } _chunk.pos = pos0; _chunk.end = pos; _chunk.match = input.substring(pos0,pos); if (result0 !== null) { result0 = (function(attributes, lines, _chunk) { return parse_composition(attributes,lines) })(result0[2], result0[3], _chunk); } if (result0 === null) { pos = pos0; } reportFailures--; if (reportFailures === 0 && result0 === null) { matchFailed("a musical piece lines:LINE+ "); } cache[cacheKey] = { nextPos: pos, result: result0 }; return result0; } function parse_ATTRIBUTE_LINE() { var cacheKey = "ATTRIBUTE_LINE@" + pos; var cachedResult = cache[cacheKey]; if (cachedResult) { pos = cachedResult.nextPos; return cachedResult.result; } var result0, result1, result2, result3, result4, result5, result6; var pos0, pos1, pos2; reportFailures++; pos0 = pos; pos1 = pos; if (/^[a-zA-Z_\-0-9]/.test(input.charAt(pos))) { result1 = input.charAt(pos); pos++; } else { result1 = null; if (reportFailures === 0) { matchFailed("[a-zA-Z_\\-0-9]"); } } if (result1 !== null) { result0 = []; while (result1 !== null) { result0.push(result1); if (/^[a-zA-Z_\-0-9]/.test(input.charAt(pos))) { result1 = input.charAt(pos); pos++; } else { result1 = null; if (reportFailures === 0) { matchFailed("[a-zA-Z_\\-0-9]"); } } } } else { result0 = null; } if (result0 !== null) { result1 = ""; result1 = result1 !== null ? result1 : ""; if (result1 !== null) { if (input.charCodeAt(pos) === 58) { result2 = ":"; pos += 1; } else { result2 = null; if (reportFailures === 0) { matchFailed("\":\""); } } if (result2 !== null) { result3 = parse__(); if (result3 !== null) { if (/^[^\n\r]/.test(input.charAt(pos))) { result5 = input.charAt(pos); pos++; } else { result5 = null; if (reportFailures === 0) { matchFailed("[^\\n\\r]"); } } if (result5 !== null) { result4 = []; while (result5 !== null) { result4.push(result5); if (/^[^\n\r]/.test(input.charAt(pos))) { result5 = input.charAt(pos); pos++; } else { result5 = null; if (reportFailures === 0) { matchFailed("[^\\n\\r]"); } } } } else { result4 = null; } if (result4 !== null) { result5 = parse__(); if (result5 !== null) { result6 = parse_LINE_END_CHAR(); if (result6 === null) { pos2 = pos; reportFailures++; result6 = parse_EOF(); reportFailures--; if (result6 !== null) { result6 = ""; pos = pos2; } else { result6 = null; } } if (result6 !== null) { result0 = [result0, result1, result2, result3, result4, result5, result6]; } else { result0 = null; pos = pos1; } } else { result0 = null; pos = pos1; } } else { result0 = null; pos = pos1; } } else { result0 = null; pos = pos1; } } else { result0 = null; pos = pos1; } } else { result0 = null; pos = pos1; } } else { result0 = null; pos = pos1; } _chunk.pos = pos0; _chunk.end = pos; _chunk.match = input.substring(pos0,pos); if (result0 !== null) { result0 = (function(key_chars, blanks, value_chars, _chunk) { return { my_type:"attribute", key: key_chars.join(''), value:this.trim(value_chars.join('')), source: "todo" }})(result0[0], result0[3], result0[4], _chunk); } if (result0 === null) { pos = pos0; } reportFailures--; if (reportFailures === 0 && result0 === null) { matchFailed("ie Author: John Rothfield"); } cache[cacheKey] = { nextPos: pos, result: result0 }; return result0; } function parse_LINE_END() { var cacheKey = "LINE_END@" + pos; var cachedResult = cache[cacheKey]; if (cachedResult) { pos = cachedResult.nextPos; return cachedResult.result; } var result0; var pos0; reportFailures++; pos0 = pos; reportFailures++; result0 = parse_EOF(); reportFailures--; if (result0 !== null) { result0 = ""; pos = pos0; } else { result0 = null; } if (result0 === null) { result0 = parse_EOL(); } reportFailures--; if (reportFailures === 0 && result0 === null) { matchFailed("eol or eof"); } cache[cacheKey] = { nextPos: pos, result: result0 }; return result0; } function parse_COMPOUND_LINE() { var cacheKey = "COMPOUND_LINE@" + pos; var cachedResult = cache[cacheKey]; if (cachedResult) { pos = cachedResult.nextPos; return cachedResult.result; } var result0, result1, result2, result3, result4, result5, result6; var pos0, pos1; pos0 = pos; pos1 = pos; result0 = []; result1 = parse_UPPER_OCTAVE_LINE(); while (result1 !== null) { result0.push(result1); result1 = parse_UPPER_OCTAVE_LINE(); } if (result0 !== null) { result1 = parse_DEVANAGRI_SARGAM_LINE(); if (result1 === null) { result1 = parse_SARGAM_LINE(); if (result1 === null) { result1 = parse_ABC_SARGAM_LINE(); if (result1 === null) { result1 = parse_NUMBER_SARGAM_LINE(); } } } if (result1 !== null) { result2 = []; result3 = parse_LOWER_OCTAVE_LINE(); while (result3 !== null) { result2.push(result3); result3 = parse_LOWER_OCTAVE_LINE(); } if (result2 !== null) { result3 = parse_LYRICS_LINE(); result3 = result3 !== null ? result3 : ""; if (result3 !== null) { result4 = parse_LINE_END(); if (result4 !== null) { result5 = []; result6 = parse_EMPTY_LINE(); while (result6 !== null) { result5.push(result6); result6 = parse_EMPTY_LINE(); } if (result5 !== null) { result0 = [result0, result1, result2, result3, result4, result5]; } else { result0 = null; pos = pos1; } } else { result0 = null; pos = pos1; } } else { result0 = null; pos = pos1; } } else { result0 = null; pos = pos1; } } else { result0 = null; pos = pos1; } } else { result0 = null; pos = pos1; } _chunk.pos = pos0; _chunk.end = pos; _chunk.match = input.substring(pos0,pos); if (result0 !== null) { result0 = (function(uppers, sargam, lowers, lyrics, _chunk) { return parse_line(uppers,sargam,lowers,lyrics) })(result0[0], result0[1], result0[2], result0[3], _chunk); } if (result0 === null) { pos = pos0; } cache[cacheKey] = { nextPos: pos, result: result0 }; return result0; } function parse_LINE() { var cacheKey = "LINE@" + pos; var cachedResult = cache[cacheKey]; if (cachedResult) { pos = cachedResult.nextPos; return cachedResult.result; } var result0; reportFailures++; result0 = parse_COMPOUND_LINE(); if (result0 === null) { result0 = parse_SIMPLE_LINE(); } reportFailures--; if (reportFailures === 0 && result0 === null) { matchFailed("main line of music. multiple lines including syllables etc,delimited by empty line. There is an order, optional upper octave lines followed by main line of sargam followed by optional lyrics line"); } cache[cacheKey] = { nextPos: pos, result: result0 }; return result0; } function parse_SIMPLE_LINE() { var cacheKey = "SIMPLE_LINE@" + pos; var cachedResult = cache[cacheKey]; if (cachedResult) { pos = cachedResult.nextPos; return cachedResult.result; } var result0, result1, result2, result3, result4, result5; var pos0, pos1; pos0 = pos; pos1 = pos; result0 = parse_DEVANAGRI_SARGAM_LINE(); if (result0 === null) { result0 = parse_SARGAM_LINE(); if (result0 === null) { result0 = parse_ABC_SARGAM_LINE(); if (result0 === null) { result0 = parse_NUMBER_SARGAM_LINE(); } } } if (result0 !== null) { result1 = []; result2 = parse_LOWER_OCTAVE_LINE(); while (result2 !== null) { result1.push(result2); result2 = parse_LOWER_OCTAVE_LINE(); } if (result1 !== null) { result2 = parse_LYRICS_LINE(); result2 = result2 !== null ? result2 : ""; if (result2 !== null) { result3 = parse_LINE_END(); if (result3 !== null) { result4 = []; result5 = parse_EMPTY_LINE(); while (result5 !== null) { result4.push(result5); result5 = parse_EMPTY_LINE(); } if (result4 !== null) { result0 = [result0, result1, result2, result3, result4]; } else { result0 = null; pos = pos1; } } else { result0 = null; pos = pos1; } } else { result0 = null; pos = pos1; } } else { result0 = null; pos = pos1; } } else { result0 = null; pos = pos1; } _chunk.pos = pos0; _chunk.end = pos; _chunk.match = input.substring(pos0,pos); if (result0 !== null) { result0 = (function(sargam, lowers, lyrics, _chunk) { uppers='' return parse_line(uppers,sargam,lowers,lyrics) })(result0[0], result0[1], result0[2], _chunk); } if (result0 === null) { pos = pos0; } cache[cacheKey] = { nextPos: pos, result: result0 }; return result0; } function parse_SARGAM_ORNAMENT() { var cacheKey = "SARGAM_ORNAMENT@" + pos; var cachedResult = cache[cacheKey]; if (cachedResult) { pos = cachedResult.nextPos; return cachedResult.result; } var result0, result1; var pos0; reportFailures++; pos0 = pos; result1 = parse_SARGAM_PITCH(); if (result1 !== null) { result0 = []; while (result1 !== null) { result0.push(result1); result1 = parse_SARGAM_PITCH(); } } else { result0 = null; } _chunk.pos = pos0; _chunk.end = pos; _chunk.match = input.substring(pos0,pos); if (result0 !== null) { result0 = (function(items, _chunk) { return parse_ornament("",items,"") })(result0, _chunk); } if (result0 === null) { pos = pos0; } reportFailures--; if (reportFailures === 0 && result0 === null) { matchFailed("in upper line NRSNS"); } cache[cacheKey] = { nextPos: pos, result: result0 }; return result0; } function parse_DELIMITED_SARGAM_ORNAMENT() { var cacheKey = "DELIMITED_SARGAM_ORNAMENT@" + pos; var cachedResult = cache[cacheKey]; if (cachedResult) { pos = cachedResult.nextPos; return cachedResult.result; } var result0, result1, result2; var pos0, pos1; reportFailures++; pos0 = pos; pos1 = pos; if (input.charCodeAt(pos) === 60) { result0 = "<"; pos += 1; } else { result0 = null; if (reportFailures === 0) { matchFailed("\"<\""); } } if (result0 !== null) { result2 = parse_SARGAM_PITCH(); if (result2 !== null) { result1 = []; while (result2 !== null) { result1.push(result2); result2 = parse_SARGAM_PITCH(); } } else { result1 = null; } if (result1 !== null) { if (input.charCodeAt(pos) === 62) { result2 = ">"; pos += 1; } else { result2 = null; if (reportFailures === 0) { matchFailed("\">\""); } } if (result2 !== null) { result0 = [result0, result1, result2]; } else { result0 = null; pos = pos1; } } else { result0 = null; pos = pos1; } } else { result0 = null; pos = pos1; } _chunk.pos = pos0; _chunk.end = pos; _chunk.match = input.substring(pos0,pos); if (result0 !== null) { result0 = (function(left_delimiter, items, right_delimiter, _chunk) { return parse_ornament(left_delimiter,items,right_delimiter) })(result0[0], result0[1], result0[2], _chunk); } if (result0 === null) { pos = pos0; } reportFailures--; if (reportFailures === 0 && result0 === null) { matchFailed("in upper line <NRSNS>"); } cache[cacheKey] = { nextPos: pos, result: result0 }; return result0; } function parse_UPPER_OCTAVE_LINE() { var cacheKey = "UPPER_OCTAVE_LINE@" + pos; var cachedResult = cache[cacheKey]; if (cachedResult) { pos = cachedResult.nextPos; return cachedResult.result; } var result0, result1, result2, result3; var pos0, pos1; reportFailures++; pos0 = pos; pos1 = pos; result0 = parse_WHITE_SPACE(); result0 = result0 !== null ? result0 : ""; if (result0 !== null) { result2 = parse_UPPER_OCTAVE_LINE_ITEM(); if (result2 !== null) { result1 = []; while (result2 !== null) { result1.push(result2); result2 = parse_UPPER_OCTAVE_LINE_ITEM(); } } else { result1 = null; } if (result1 !== null) { result2 = parse_WHITE_SPACE(); result2 = result2 !== null ? result2 : ""; if (result2 !== null) { result3 = parse_LINE_END(); if (result3 !== null) { result0 = [result0, result1, result2, result3]; } else { result0 = null; pos = pos1; } } else { result0 = null; pos = pos1; } } else { result0 = null; pos = pos1; } } else { result0 = null; pos = pos1; } _chunk.pos = pos0; _chunk.end = pos; _chunk.match = input.substring(pos0,pos); if (result0 !== null) { result0 = (function(begin_white_space, items, end_white_space, _chunk) { my_items = _.compact(_.flatten([begin_white_space, items,end_white_space])) return { my_type:"upper_octave_line", source: this.get_source_for_items(my_items), items: my_items } })(result0[0], result0[1], result0[2], _chunk); } if (result0 === null) { pos = pos0; } reportFailures--; if (reportFailures === 0 && result0 === null) { matchFailed("can put upper octave dots or semicolons for upper upper octave (. or :). Also tala symbols +203"); } cache[cacheKey] = { nextPos: pos, result: result0 }; return result0; } function parse_FORWARD_SLASH_CHAR() { var cacheKey = "FORWARD_SLASH_CHAR@" + pos; var cachedResult = cache[cacheKey]; if (cachedResult) { pos = cachedResult.nextPos; return cachedResult.result; } var result0; reportFailures++; if (input.charCodeAt(pos) === 47) { result0 = "/"; pos += 1; } else { result0 = null; if (reportFailures === 0) { matchFailed("\"/\""); } } reportFailures--; if (reportFailures === 0 && result0 === null) { matchFailed("note that putting forward slash in regex doesn't seem to work"); } cache[cacheKey] = { nextPos: pos, result: result0 }; return result0; } function parse_CHORD_SYMBOL_CHAR() { var cacheKey = "CHORD_SYMBOL_CHAR@" + pos; var cachedResult = cache[cacheKey]; if (cachedResult) { pos = cachedResult.nextPos; return cachedResult.result; } var result0; if (/^[a-gA-GmiMaIivV0-9+]/.test(input.charAt(pos))) { result0 = input.charAt(pos); pos++; } else { result0 = null; if (reportFailures === 0) { matchFailed("[a-gA-GmiMaIivV0-9+]"); } } if (result0 === null) { result0 = parse_FORWARD_SLASH_CHAR(); } cache[cacheKey] = { nextPos: pos, result: result0 }; return result0; } function parse_CHORD_SYMBOL_INITIAL_CHAR() { var cacheKey = "CHORD_SYMBOL_INITIAL_CHAR@" + pos; var cachedResult = cache[cacheKey]; if (cachedResult) { pos = cachedResult.nextPos; return cachedResult.result; } var result0; if (/^[a-gA-GvViI]/.test(input.charAt(pos))) { result0 = input.charAt(pos); pos++; } else { result0 = null; if (reportFailures === 0) { matchFailed("[a-gA-GvViI]"); } } cache[cacheKey] = { nextPos: pos, result: result0 }; return result0; } function parse_CHORD_SYMBOL() { var cacheKey = "CHORD_SYMBOL@" + pos; var cachedResult = cache[cacheKey]; if (cachedResult) { pos = cachedResult.nextPos; return cachedResult.result; } var result0, result1, result2, result3; var pos0, pos1, pos2, pos3; reportFailures++; pos0 = pos; pos1 = pos; pos2 = pos; reportFailures++; pos3 = pos; if (/^[SrRgGmMPdDnN]/.test(input.charAt(pos))) { result0 = input.charAt(pos); pos++; } else { result0 = null; if (reportFailures === 0) { matchFailed("[SrRgGmMPdDnN]"); } } if (result0 !== null) { if (/^[SrRgGmMPdDnN]/.test(input.charAt(pos))) { result1 = input.charAt(pos); pos++; } else { result1 = null; if (reportFailures === 0) { matchFailed("[SrRgGmMPdDnN]"); } } if (result1 !== null) { if (/^[SrRgGmMPdDnN]/.test(input.charAt(pos))) { result2 = input.charAt(pos); pos++; } else { result2 = null; if (reportFailures === 0) { matchFailed("[SrRgGmMPdDnN]"); } } if (result2 !== null) { result0 = [result0, result1, result2]; } else { result0 = null; pos = pos3; } } else { result0 = null; pos = pos3; } } else { result0 = null; pos = pos3; } reportFailures--; if (result0 === null) { result0 = ""; } else { result0 = null; pos = pos2; } if (result0 !== null) { result1 = parse_CHORD_SYMBOL_INITIAL_CHAR(); if (result1 !== null) { result2 = []; result3 = parse_CHORD_SYMBOL_CHAR(); while (result3 !== null) { result2.push(result3); result3 = parse_CHORD_SYMBOL_CHAR(); } if (result2 !== null) { result0 = [result0, result1, result2]; } else { result0 = null; pos = pos1; } } else { result0 = null; pos = pos1; } } else { result0 = null; pos = pos1; } _chunk.pos = pos0; _chunk.end = pos; _chunk.match = input.substring(pos0,pos); if (result0 !== null) { result0 = (function(initial, chars, _chunk) { source=initial + chars.join('') return { my_type:"chord_symbol", source: source, } })(result0[1], result0[2], _chunk); } if (result0 === null) { pos = pos0; } reportFailures--; if (reportFailures === 0 && result0 === null) { matchFailed("I IV V. Put in lookahead for 3 sargam chars. "); } cache[cacheKey] = { nextPos: pos, result: result0 }; return result0; } function parse_ALTERNATE_ENDING_INDICATOR() { var cacheKey = "ALTERNATE_ENDING_INDICATOR@" + pos; var cachedResult = cache[cacheKey]; if (cachedResult) { pos = cachedResult.nextPos; return cachedResult.result; } var result0, result1, result2; var pos0, pos1; reportFailures++; pos0 = pos; pos1 = pos; if (/^[1-3]/.test(input.charAt(pos))) { result0 = input.charAt(pos); pos++; } else { result0 = null; if (reportFailures === 0) { matchFailed("[1-3]"); } } if (result0 !== null) { if (/^[._]/.test(input.charAt(pos))) { result2 = input.charAt(pos); pos++; } else { result2 = null; if (reportFailures === 0) { matchFailed("[._]"); } } if (result2 !== null) { result1 = []; while (result2 !== null) { result1.push(result2); if (/^[._]/.test(input.charAt(pos))) { result2 = input.charAt(pos); pos++; } else { result2 = null; if (reportFailures === 0) { matchFailed("[._]"); } } } } else { result1 = null; } if (result1 !== null) { result0 = [result0, result1]; } else { result0 = null; pos = pos1; } } else { result0 = null; pos = pos1; } _chunk.pos = pos0; _chunk.end = pos; _chunk.match = input.substring(pos0,pos); if (result0 !== null) { result0 = (function(num, underscores, _chunk) { if (typeof(dot) == 'undefined') { dot='' } if (typeof(underscores) == 'undefined') { underscores=[] } source=_.flatten([num,dot,underscores]).join('') return { my_type: "ending", source:source, num:parseInt(num) } })(result0[0], result0[1], _chunk); } if (result0 === null) { pos = pos0; } reportFailures--; if (reportFailures === 0 && result0 === null) { matchFailed("1._______ 2.___ etc. The period is optional. Must have either dot or underscores. TODO: accepts 1_.___ which is not exactly what I want."); } cache[cacheKey] = { nextPos: pos, result: result0 }; return result0; } function parse_UPPER_OCTAVE_LINE_ITEM() { var cacheKey = "UPPER_OCTAVE_LINE_ITEM@" + pos; var cachedResult = cache[cacheKey]; if (cachedResult) { pos = cachedResult.nextPos; return cachedResult.result; } var result0; reportFailures++; result0 = parse_DELIMITED_SARGAM_ORNAMENT(); if (result0 === null) { result0 = parse_WHITE_SPACE(); if (result0 === null) { result0 = parse_UPPER_OCTAVE_DOT(); if (result0 === null) { result0 = parse_ALTERNATE_ENDING_INDICATOR(); if (result0 === null) { result0 = parse_TALA(); if (result0 === null) { result0 = parse_MORDENT(); if (result0 === null) { result0 = parse_UPPER_UPPER_OCTAVE_SYMBOL(); if (result0 === null) { result0 = parse_CHORD_SYMBOL(); if (result0 === null) { result0 = parse_SARGAM_ORNAMENT(); } } } } } } } } reportFailures--; if (reportFailures === 0 && result0 === null) { matchFailed("Things above notes, including talas, octaves,chords, and 1st and second ending symbols"); } cache[cacheKey] = { nextPos: pos, result: result0 }; return result0; } function parse_LOWER_OCTAVE_LINE() { var cacheKey = "LOWER_OCTAVE_LINE@" + pos; var cachedResult = cache[cacheKey]; if (cachedResult) { pos = cachedResult.nextPos; return cachedResult.result; } var result0, result1; var pos0, pos1; reportFailures++; pos0 = pos; pos1 = pos; result1 = parse_LOWER_OCTAVE_LINE_ITEM(); if (result1 !== null) { result0 = []; while (result1 !== null) { result0.push(result1); result1 = parse_LOWER_OCTAVE_LINE_ITEM(); } } else { result0 = null; } if (result0 !== null) { result1 = parse_LINE_END(); if (result1 !== null) { result0 = [result0, result1]; } else { result0 = null; pos = pos1; } } else { result0 = null; pos = pos1; } _chunk.pos = pos0; _chunk.end = pos; _chunk.match = input.subst