notations 0.0.60 → 0.0.61

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/lib/cjs/loader.js CHANGED
@@ -27,16 +27,8 @@ exports.load = exports.parse = void 0;
27
27
  const TSU = __importStar(require("@panyam/tsutils"));
28
28
  const beats_1 = require("./beats");
29
29
  const parser_1 = require("./parser");
30
- const notation_1 = require("./notation");
31
30
  function parse(input) {
32
- const notation = new notation_1.Notation();
33
- const parser = new parser_1.Parser();
34
- const errors = [];
35
- parser.parse(input);
36
- errors.push(...parser.errors);
37
- for (const cmd of parser.commands)
38
- cmd.applyToNotation(notation);
39
- return [notation, errors];
31
+ return new parser_1.Parser().parseAndBuild(input);
40
32
  }
41
33
  exports.parse = parse;
42
34
  function load(codeText, config = {}) {
@@ -1 +1 @@
1
- {"version":3,"file":"loader.js","sourceRoot":"","sources":["../../src/loader.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,qDAAuC;AAGvC,mCAA2C;AAC3C,qCAAkC;AAClC,yCAAsC;AAEtC,SAAgB,KAAK,CAAC,KAAa;IACjC,MAAM,QAAQ,GAAG,IAAI,mBAAQ,EAAE,CAAC;IAChC,MAAM,MAAM,GAAG,IAAI,eAAM,EAAE,CAAC;IAC5B,MAAM,MAAM,GAAmB,EAAE,CAAC;IAClC,MAAM,CAAC,KAAK,CAAC,KAAK,CAAC,CAAC;IACpB,MAAM,CAAC,IAAI,CAAC,GAAG,MAAM,CAAC,MAAM,CAAC,CAAC;IAC9B,KAAK,MAAM,GAAG,IAAI,MAAM,CAAC,QAAQ;QAAE,GAAG,CAAC,eAAe,CAAC,QAAQ,CAAC,CAAC;IACjE,OAAO,CAAC,QAAQ,EAAE,MAAM,CAAC,CAAC;AAC5B,CAAC;AARD,sBAQC;AAED,SAAgB,IAAI,CAClB,QAAgB,EAChB,SAAc,EAAE;IAEhB,QAAQ,GAAG,QAAQ,IAAI,EAAE,CAAC;IAC1B,MAAM,UAAU,GAAG,IAAI,wBAAgB,EAAE,CAAC;IAC1C,MAAM,SAAS,GAAG,WAAW,CAAC,GAAG,EAAE,CAAC;IACpC,MAAM,CAAC,QAAQ,EAAE,MAAM,CAAC,GAAG,KAAK,CAAC,QAAQ,CAAC,CAAC;IAC3C,MAAM,SAAS,GAAG,WAAW,CAAC,GAAG,EAAE,CAAC;IAGpC,KAAK,MAAM,KAAK,IAAI,QAAQ,CAAC,MAAM,EAAE;QACnC,IAAI,KAAK,CAAC,IAAI,IAAI,MAAM,IAAI,CAAE,KAAc,CAAC,OAAO,EAAE;YACpD,MAAM,IAAI,GAAG,KAAa,CAAC;YAG3B,GAAG,CAAC,MAAM,CAAC,IAAI,CAAC,YAAY,IAAI,IAAI,EAAE,mDAAmD,CAAC,CAAC;YAC3F,UAAU,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC;SAC1B;KACF;IAED,MAAM,SAAS,GAAG,WAAW,CAAC,GAAG,EAAE,CAAC;IACpC,IAAI,MAAM,CAAC,GAAG,EAAE;QACd,OAAO,CAAC,GAAG,CAAC,4BAA4B,SAAS,GAAG,SAAS,mBAAmB,SAAS,GAAG,SAAS,IAAI,CAAC,CAAC;KAC5G;IACD,OAAO;QACL,QAAQ;QACR,UAAU;QACV,MAAM;QACN;YACE,SAAS,EAAE,SAAS,GAAG,SAAS;YAChC,SAAS,EAAE,SAAS,GAAG,SAAS;SACjC;KACF,CAAC;AACJ,CAAC;AAlCD,oBAkCC","sourcesContent":["import * as TSU from \"@panyam/tsutils\";\nimport * as G from \"galore\";\nimport { Line } from \"./core\";\nimport { GlobalBeatLayout } from \"./beats\";\nimport { Parser } from \"./parser\";\nimport { Notation } from \"./notation\";\n\nexport function parse(input: string): [Notation, G.ParseError[]] {\n const notation = new Notation();\n const parser = new Parser();\n const errors: G.ParseError[] = [];\n parser.parse(input);\n errors.push(...parser.errors);\n for (const cmd of parser.commands) cmd.applyToNotation(notation);\n return [notation, errors];\n}\n\nexport function load(\n codeText: string,\n config: any = {},\n): [Notation, GlobalBeatLayout, G.ParseError[], TSU.StringMap<number>] {\n codeText = codeText || \"\";\n const beatLayout = new GlobalBeatLayout();\n const startTime = performance.now();\n const [notation, errors] = parse(codeText);\n const parseTime = performance.now();\n\n // Create Line Beats\n for (const block of notation.blocks) {\n if (block.TYPE == \"Line\" && !(block as Line).isEmpty) {\n const line = block as Line;\n // LP should exist by now\n // Probably because this is an empty line and AddAtoms was not called\n TSU.assert(line.layoutParams != null, \"Layout params for a non empty line *SHOULD* exist\");\n beatLayout.addLine(line);\n }\n }\n\n const buildTime = performance.now();\n if (config.log) {\n console.log(`V4 Document, Parse Time: ${parseTime - startTime}ms, Build Time: ${buildTime - parseTime}ms`);\n }\n return [\n notation,\n beatLayout,\n errors,\n {\n parseTime: parseTime - startTime,\n buildTime: buildTime - parseTime,\n },\n ];\n}\n"]}
1
+ {"version":3,"file":"loader.js","sourceRoot":"","sources":["../../src/loader.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,qDAAuC;AAGvC,mCAA2C;AAC3C,qCAAkC;AAGlC,SAAgB,KAAK,CAAC,KAAa;IACjC,OAAO,IAAI,eAAM,EAAE,CAAC,aAAa,CAAC,KAAK,CAAC,CAAC;AAC3C,CAAC;AAFD,sBAEC;AAED,SAAgB,IAAI,CAClB,QAAgB,EAChB,SAAc,EAAE;IAEhB,QAAQ,GAAG,QAAQ,IAAI,EAAE,CAAC;IAC1B,MAAM,UAAU,GAAG,IAAI,wBAAgB,EAAE,CAAC;IAC1C,MAAM,SAAS,GAAG,WAAW,CAAC,GAAG,EAAE,CAAC;IACpC,MAAM,CAAC,QAAQ,EAAE,MAAM,CAAC,GAAG,KAAK,CAAC,QAAQ,CAAC,CAAC;IAC3C,MAAM,SAAS,GAAG,WAAW,CAAC,GAAG,EAAE,CAAC;IAGpC,KAAK,MAAM,KAAK,IAAI,QAAQ,CAAC,MAAM,EAAE;QACnC,IAAI,KAAK,CAAC,IAAI,IAAI,MAAM,IAAI,CAAE,KAAc,CAAC,OAAO,EAAE;YACpD,MAAM,IAAI,GAAG,KAAa,CAAC;YAG3B,GAAG,CAAC,MAAM,CAAC,IAAI,CAAC,YAAY,IAAI,IAAI,EAAE,mDAAmD,CAAC,CAAC;YAC3F,UAAU,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC;SAC1B;KACF;IAED,MAAM,SAAS,GAAG,WAAW,CAAC,GAAG,EAAE,CAAC;IACpC,IAAI,MAAM,CAAC,GAAG,EAAE;QACd,OAAO,CAAC,GAAG,CAAC,4BAA4B,SAAS,GAAG,SAAS,mBAAmB,SAAS,GAAG,SAAS,IAAI,CAAC,CAAC;KAC5G;IACD,OAAO;QACL,QAAQ;QACR,UAAU;QACV,MAAM;QACN;YACE,SAAS,EAAE,SAAS,GAAG,SAAS;YAChC,SAAS,EAAE,SAAS,GAAG,SAAS;SACjC;KACF,CAAC;AACJ,CAAC;AAlCD,oBAkCC","sourcesContent":["import * as TSU from \"@panyam/tsutils\";\nimport * as G from \"galore\";\nimport { Line } from \"./core\";\nimport { GlobalBeatLayout } from \"./beats\";\nimport { Parser } from \"./parser\";\nimport { Notation } from \"./notation\";\n\nexport function parse(input: string): [Notation, G.ParseError[]] {\n return new Parser().parseAndBuild(input);\n}\n\nexport function load(\n codeText: string,\n config: any = {},\n): [Notation, GlobalBeatLayout, G.ParseError[], TSU.StringMap<number>] {\n codeText = codeText || \"\";\n const beatLayout = new GlobalBeatLayout();\n const startTime = performance.now();\n const [notation, errors] = parse(codeText);\n const parseTime = performance.now();\n\n // Create Line Beats\n for (const block of notation.blocks) {\n if (block.TYPE == \"Line\" && !(block as Line).isEmpty) {\n const line = block as Line;\n // LP should exist by now\n // Probably because this is an empty line and AddAtoms was not called\n TSU.assert(line.layoutParams != null, \"Layout params for a non empty line *SHOULD* exist\");\n beatLayout.addLine(line);\n }\n }\n\n const buildTime = performance.now();\n if (config.log) {\n console.log(`V4 Document, Parse Time: ${parseTime - startTime}ms, Build Time: ${buildTime - parseTime}ms`);\n }\n return [\n notation,\n beatLayout,\n errors,\n {\n parseTime: parseTime - startTime,\n buildTime: buildTime - parseTime,\n },\n ];\n}\n"]}
@@ -56,7 +56,7 @@ export declare class Notation extends Entity {
56
56
  addLine(line: Line): void;
57
57
  removeLine(line: Line): number;
58
58
  addRawBlock(raw: RawBlock): void;
59
- addMetaData(meta: MetaData): void;
59
+ addMetaData(meta: MetaData, addBlock?: boolean): void;
60
60
  debugValue(): any;
61
61
  getRoleDef(name: string): TSU.Nullable<RoleDef>;
62
62
  newRoleDef(name: string, notesOnly?: boolean): RoleDef;
@@ -101,8 +101,8 @@ class Notation extends entity_1.Entity {
101
101
  this.blocks.push(raw);
102
102
  this.resetLine();
103
103
  }
104
- addMetaData(meta) {
105
- if (!this.metadata.has(meta.key)) {
104
+ addMetaData(meta, addBlock = true) {
105
+ if (addBlock && !this.metadata.has(meta.key)) {
106
106
  const raw = new RawBlock(meta.key, "metadata");
107
107
  this.addRawBlock(raw);
108
108
  }
@@ -1 +1 @@
1
- {"version":3,"file":"notation.js","sourceRoot":"","sources":["../../src/notation.ts"],"names":[],"mappings":";;;AACA,qCAAkC;AAClC,mCAAgC;AAChC,iCAA8B;AAC9B,uCAAyC;AAEzC,MAAa,OAAO;IAApB;QACE,SAAI,GAAG,EAAE,CAAC;QACV,cAAS,GAAG,KAAK,CAAC;QAClB,UAAK,GAAG,CAAC,CAAC;IACZ,CAAC;CAAA;AAJD,0BAIC;AAGD,MAAsB,OAAQ,SAAQ,eAAM;IAQ1C,YAAY,SAAqB,EAAE;QACjC,KAAK,EAAE,CAAC;QAPV,kBAAa,GAAG,KAAK,CAAC;QACtB,gBAAW,GAAmB,IAAI,CAAC;QACnC,gBAAW,GAAmB,IAAI,CAAC;QAMjC,IAAI,CAAC,MAAM,GAAG,MAAM,CAAC;QACrB,IAAI,CAAC,KAAK,GAAG,CAAC,CAAC;QACf,IAAI,CAAC,cAAc,EAAE,CAAC;IACxB,CAAC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,CAAC,aAAa,CAAC,CACvC,CAAC;QACJ,CAAC,CAAC,IAAI,IAAI,CACX,CAAC;IACJ,CAAC;CACF;AA1MD,4BA0MC","sourcesContent":["import * as TSU from \"@panyam/tsutils\";\nimport { Entity } from \"./entity\";\nimport { Cycle } from \"./cycle\";\nimport { Line } from \"./core\";\nimport { LayoutParams } from \"./layouts\";\n\nexport class RoleDef {\n name = \"\";\n notesOnly = false;\n index = 0;\n}\n\nexport type CmdParam = { key: TSU.Nullable<string>; value: any };\nexport abstract class Command extends Entity {\n // Commands that are auto generated are usually created by other commands\n autoGenerated = false;\n prevSibling: null | Command = null;\n nextSibling: null | Command = null;\n params: CmdParam[];\n index: number;\n\n constructor(params: CmdParam[] = []) {\n super();\n this.params = params;\n this.index = 0;\n this.validateParams();\n }\n\n /**\n * called to validate parameters.\n */\n validateParams(): void {\n //\n }\n\n get name(): string {\n return this.constructor.name;\n }\n\n debugValue(): any {\n return { name: this.name, index: this.index, params: this.params };\n }\n\n getParam(name: string): any {\n for (const param of this.params) {\n if (param.key == name) return param.value;\n }\n return null;\n }\n\n getParamAt(index: number): any {\n return index < this.params.length ? this.params[index].value : null;\n }\n abstract applyToNotation(notebook: Notation): void;\n}\n\nexport class RawBlock extends Entity {\n readonly TYPE: string = \"RawBlock\";\n constructor(public content: string, public contentType: string = \"md\") {\n super();\n }\n\n debugValue(): any {\n return { ...super.debugValue(), content: this.content, contentType: this.contentType };\n }\n}\n\nexport class MetaData {\n constructor(public readonly key: string, public readonly value: string, public readonly params?: any) {\n params = params || {};\n }\n}\n\nexport class Notation extends Entity {\n readonly TYPE = \"Notation\";\n private _unnamedLayoutParams: LayoutParams[] = [];\n private _namedLayoutParams = new Map<string, LayoutParams>();\n private _currRoleDef: TSU.Nullable<RoleDef> = null;\n roles: RoleDef[] = [];\n blocks: (Line | RawBlock)[] = [];\n currentAPB = 1;\n currentCycle: Cycle = Cycle.DEFAULT;\n currentBreaks: number[] = [];\n metadata = new Map<string, MetaData>();\n onMissingRole: (name: string) => RoleDef | null = (name) => this.newRoleDef(name, name == \"sw\");\n\n get unnamedLayoutParams(): ReadonlyArray<LayoutParams> {\n return this._unnamedLayoutParams;\n }\n\n get namedLayoutParams(): ReadonlyMap<string, LayoutParams> {\n return this._namedLayoutParams;\n }\n\n addLine(line: Line): void {\n this.blocks.push(line);\n }\n\n removeLine(line: Line): number {\n const index = this.blocks.findIndex((l) => l == line);\n if (index >= 0) {\n this.blocks.splice(index, 1);\n }\n return index;\n }\n\n addRawBlock(raw: RawBlock): void {\n this.blocks.push(raw);\n this.resetLine();\n }\n\n addMetaData(meta: MetaData): void {\n if (!this.metadata.has(meta.key)) {\n // Add a new raw block here\n // set this by key so even if metadata changes we can\n // get latest value of it\n const raw = new RawBlock(meta.key, \"metadata\");\n this.addRawBlock(raw);\n }\n this.metadata.set(meta.key, meta);\n }\n\n debugValue(): any {\n return {\n ...super.debugValue,\n roles: this.roles,\n blocks: this.blocks.map((b) => b.debugValue()),\n currentAPB: this.currentAPB,\n currentCycle: this.currentCycle?.uuid,\n currentBreaks: this.currentBreaks,\n };\n }\n\n getRoleDef(name: string): TSU.Nullable<RoleDef> {\n name = name.trim().toLowerCase();\n if (name == \"\") {\n return this.roles[this.roles.length - 1] || null;\n }\n for (let i = 0; i < this.roles.length; i++) {\n const rd = this.roles[i];\n if (name == rd.name) return rd;\n }\n return null;\n }\n\n newRoleDef(name: string, notesOnly = false): RoleDef {\n name = name.trim().toLowerCase();\n if (name.trim() == \"\") {\n throw new Error(\"Role name cannot be empty\");\n }\n const roleDef = this.getRoleDef(name);\n if (roleDef != null) {\n throw new Error(\"Role already exists\");\n // roleDef.notesOnly = notesOnly;\n // return roleDef;\n }\n // create new and add\n const rd = new RoleDef();\n rd.name = name;\n rd.notesOnly = notesOnly;\n rd.index = this.roles.length;\n this.roles.push(rd);\n\n return rd;\n }\n\n get currRoleDef(): RoleDef | null {\n if (this._currRoleDef == null) {\n if (this.roles.length == 0) {\n return null;\n } else {\n this._currRoleDef = this.roles[this.roles.length - 1];\n }\n }\n return this._currRoleDef;\n }\n\n setCurrRole(name: string): void {\n name = name.trim().toLowerCase();\n if (name.trim() == \"\") {\n throw new Error(\"Role name cannot be empty\");\n }\n const roleDef = this.getRoleDef(name) || (this.onMissingRole ? this.onMissingRole(name) || null : null);\n if (roleDef == null) {\n throw new Error(\"Role not found: \" + name);\n }\n this._currRoleDef = roleDef;\n }\n\n // Gets the current line, creating it if needed\n private _currentLine: Line | null = null;\n get currentLine(): Line {\n if (this._currentLine == null) {\n return this.newLine();\n }\n return this._currentLine;\n }\n\n resetLine(): void {\n this._currentLine = null;\n }\n\n newLine(): Line {\n if (this._currentLine && this._currentLine.isEmpty) {\n // then remove it first instead of adding another\n // so we dont have a string of empty lines\n this.removeLine(this._currentLine);\n }\n this._currentLine = new Line();\n this.addLine(this._currentLine);\n return this._currentLine;\n }\n\n private _layoutParams: LayoutParams | null = null;\n resetLayoutParams(): void {\n this._layoutParams = null;\n this.resetLine();\n }\n\n get layoutParams(): LayoutParams {\n if (this._layoutParams == null) {\n // create it or find one that matches current params\n this._layoutParams = this.findUnnamedLayoutParams();\n if (this._layoutParams == null) {\n this._layoutParams = this.snapshotLayoutParams();\n this._unnamedLayoutParams.push(this._layoutParams);\n }\n }\n return this._layoutParams;\n }\n\n ensureNamedLayoutParams(name: string): LayoutParams {\n let lp = this._namedLayoutParams.get(name) || null;\n if (lp == null || this._layoutParams != lp) {\n // no change so go ahead\n if (lp == null) {\n // does not exist so create one by re-snapshotting it\n // and saving it\n lp = this.snapshotLayoutParams();\n this._namedLayoutParams.set(name, lp);\n } else {\n // copy named LPs attributes into our locals\n this.currentCycle = lp.cycle;\n this.currentAPB = lp.beatDuration;\n this.currentBreaks = lp.lineBreaks;\n }\n this._layoutParams = lp;\n this.resetLine(); // since layout params have changed\n }\n return this._layoutParams;\n }\n\n protected snapshotLayoutParams(): LayoutParams {\n return new LayoutParams({\n cycle: this.currentCycle,\n beatDuration: this.currentAPB,\n layout: this.currentBreaks,\n });\n }\n\n /**\n * Find a layout params that is currently _unnamed but matches one\n * by current set of layout attributes.\n */\n protected findUnnamedLayoutParams(): LayoutParams | null {\n return (\n this._unnamedLayoutParams.find((lp) => {\n return (\n lp.beatDuration == this.currentAPB &&\n this.currentCycle.equals(lp.cycle) &&\n lp.lineBreaksEqual(this.currentBreaks)\n );\n }) || null\n );\n }\n}\n"]}
1
+ {"version":3,"file":"notation.js","sourceRoot":"","sources":["../../src/notation.ts"],"names":[],"mappings":";;;AACA,qCAAkC;AAClC,mCAAgC;AAChC,iCAA8B;AAC9B,uCAAyC;AAEzC,MAAa,OAAO;IAApB;QACE,SAAI,GAAG,EAAE,CAAC;QACV,cAAS,GAAG,KAAK,CAAC;QAClB,UAAK,GAAG,CAAC,CAAC;IACZ,CAAC;CAAA;AAJD,0BAIC;AAGD,MAAsB,OAAQ,SAAQ,eAAM;IAQ1C,YAAY,SAAqB,EAAE;QACjC,KAAK,EAAE,CAAC;QAPV,kBAAa,GAAG,KAAK,CAAC;QACtB,gBAAW,GAAmB,IAAI,CAAC;QACnC,gBAAW,GAAmB,IAAI,CAAC;QAMjC,IAAI,CAAC,MAAM,GAAG,MAAM,CAAC;QACrB,IAAI,CAAC,KAAK,GAAG,CAAC,CAAC;QACf,IAAI,CAAC,cAAc,EAAE,CAAC;IACxB,CAAC;IAKD,cAAc;IAEd,CAAC;IAED,IAAI,IAAI;QACN,OAAO,IAAI,CAAC,WAAW,CAAC,IAAI,CAAC;IAC/B,CAAC;IAED,UAAU;QACR,OAAO,EAAE,IAAI,EAAE,IAAI,CAAC,IAAI,EAAE,KAAK,EAAE,IAAI,CAAC,KAAK,EAAE,MAAM,EAAE,IAAI,CAAC,MAAM,EAAE,CAAC;IACrE,CAAC;IAED,QAAQ,CAAC,IAAY;QACnB,KAAK,MAAM,KAAK,IAAI,IAAI,CAAC,MAAM,EAAE;YAC/B,IAAI,KAAK,CAAC,GAAG,IAAI,IAAI;gBAAE,OAAO,KAAK,CAAC,KA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I,CAAC,oBAAoB,EAAE,CAAC;gBACjC,IAAI,CAAC,kBAAkB,CAAC,GAAG,CAAC,IAAI,EAAE,EAAE,CAAC,CAAC;aACvC;iBAAM;gBAEL,IAAI,CAAC,YAAY,GAAG,EAAE,CAAC,KAAK,CAAC;gBAC7B,IAAI,CAAC,UAAU,GAAG,EAAE,CAAC,YAAY,CAAC;gBAClC,IAAI,CAAC,aAAa,GAAG,EAAE,CAAC,UAAU,CAAC;aACpC;YACD,IAAI,CAAC,aAAa,GAAG,EAAE,CAAC;YACxB,IAAI,CAAC,SAAS,EAAE,CAAC;SAClB;QACD,OAAO,IAAI,CAAC,aAAa,CAAC;IAC5B,CAAC;IAES,oBAAoB;QAC5B,OAAO,IAAI,sBAAY,CAAC;YACtB,KAAK,EAAE,IAAI,CAAC,YAAY;YACxB,YAAY,EAAE,IAAI,CAAC,UAAU;YAC7B,MAAM,EAAE,IAAI,CAAC,aAAa;SAC3B,CAAC,CAAC;IACL,CAAC;IAMS,uBAAuB;QAC/B,OAAO,CACL,IAAI,CAAC,oBAAoB,CAAC,IAAI,CAAC,CAAC,EAAE,EAAE,EAAE;YACpC,OAAO,CACL,EAAE,CAAC,YAAY,IAAI,IAAI,CAAC,UAAU;gBAClC,IAAI,CAAC,YAAY,CAAC,MAAM,CAAC,EAAE,CAAC,KAAK,CAAC;gBAClC,EAAE,CAAC,eAAe,CAAC,IAAI,CAAC,aAAa,CAAC,CACvC,CAAC;QACJ,CAAC,CAAC,IAAI,IAAI,CACX,CAAC;IACJ,CAAC;CACF;AA1MD,4BA0MC","sourcesContent":["import * as TSU from \"@panyam/tsutils\";\nimport { Entity } from \"./entity\";\nimport { Cycle } from \"./cycle\";\nimport { Line } from \"./core\";\nimport { LayoutParams } from \"./layouts\";\n\nexport class RoleDef {\n name = \"\";\n notesOnly = false;\n index = 0;\n}\n\nexport type CmdParam = { key: TSU.Nullable<string>; value: any };\nexport abstract class Command extends Entity {\n // Commands that are auto generated are usually created by other commands\n autoGenerated = false;\n prevSibling: null | Command = null;\n nextSibling: null | Command = null;\n params: CmdParam[];\n index: number;\n\n constructor(params: CmdParam[] = []) {\n super();\n this.params = params;\n this.index = 0;\n this.validateParams();\n }\n\n /**\n * called to validate parameters.\n */\n validateParams(): void {\n //\n }\n\n get name(): string {\n return this.constructor.name;\n }\n\n debugValue(): any {\n return { name: this.name, index: this.index, params: this.params };\n }\n\n getParam(name: string): any {\n for (const param of this.params) {\n if (param.key == name) return param.value;\n }\n return null;\n }\n\n getParamAt(index: number): any {\n return index < this.params.length ? this.params[index].value : null;\n }\n abstract applyToNotation(notebook: Notation): void;\n}\n\nexport class RawBlock extends Entity {\n readonly TYPE: string = \"RawBlock\";\n constructor(public content: string, public contentType: string = \"md\") {\n super();\n }\n\n debugValue(): any {\n return { ...super.debugValue(), content: this.content, contentType: this.contentType };\n }\n}\n\nexport class MetaData {\n constructor(public readonly key: string, public readonly value: string, public readonly params?: any) {\n params = params || {};\n }\n}\n\nexport class Notation extends Entity {\n readonly TYPE = \"Notation\";\n private _unnamedLayoutParams: LayoutParams[] = [];\n private _namedLayoutParams = new Map<string, LayoutParams>();\n private _currRoleDef: TSU.Nullable<RoleDef> = null;\n roles: RoleDef[] = [];\n blocks: (Line | RawBlock)[] = [];\n currentAPB = 1;\n currentCycle: Cycle = Cycle.DEFAULT;\n currentBreaks: number[] = [];\n metadata = new Map<string, MetaData>();\n onMissingRole: (name: string) => RoleDef | null = (name) => this.newRoleDef(name, name == \"sw\");\n\n get unnamedLayoutParams(): ReadonlyArray<LayoutParams> {\n return this._unnamedLayoutParams;\n }\n\n get namedLayoutParams(): ReadonlyMap<string, LayoutParams> {\n return this._namedLayoutParams;\n }\n\n addLine(line: Line): void {\n this.blocks.push(line);\n }\n\n removeLine(line: Line): number {\n const index = this.blocks.findIndex((l) => l == line);\n if (index >= 0) {\n this.blocks.splice(index, 1);\n }\n return index;\n }\n\n addRawBlock(raw: RawBlock): void {\n this.blocks.push(raw);\n this.resetLine();\n }\n\n addMetaData(meta: MetaData, addBlock = true): void {\n if (addBlock && !this.metadata.has(meta.key)) {\n // Add a new raw block here\n // set this by key so even if metadata changes we can\n // get latest value of it\n const raw = new RawBlock(meta.key, \"metadata\");\n this.addRawBlock(raw);\n }\n this.metadata.set(meta.key, meta);\n }\n\n debugValue(): any {\n return {\n ...super.debugValue,\n roles: this.roles,\n blocks: this.blocks.map((b) => b.debugValue()),\n currentAPB: this.currentAPB,\n currentCycle: this.currentCycle?.uuid,\n currentBreaks: this.currentBreaks,\n };\n }\n\n getRoleDef(name: string): TSU.Nullable<RoleDef> {\n name = name.trim().toLowerCase();\n if (name == \"\") {\n return this.roles[this.roles.length - 1] || null;\n }\n for (let i = 0; i < this.roles.length; i++) {\n const rd = this.roles[i];\n if (name == rd.name) return rd;\n }\n return null;\n }\n\n newRoleDef(name: string, notesOnly = false): RoleDef {\n name = name.trim().toLowerCase();\n if (name.trim() == \"\") {\n throw new Error(\"Role name cannot be empty\");\n }\n const roleDef = this.getRoleDef(name);\n if (roleDef != null) {\n throw new Error(\"Role already exists\");\n // roleDef.notesOnly = notesOnly;\n // return roleDef;\n }\n // create new and add\n const rd = new RoleDef();\n rd.name = name;\n rd.notesOnly = notesOnly;\n rd.index = this.roles.length;\n this.roles.push(rd);\n\n return rd;\n }\n\n get currRoleDef(): RoleDef | null {\n if (this._currRoleDef == null) {\n if (this.roles.length == 0) {\n return null;\n } else {\n this._currRoleDef = this.roles[this.roles.length - 1];\n }\n }\n return this._currRoleDef;\n }\n\n setCurrRole(name: string): void {\n name = name.trim().toLowerCase();\n if (name.trim() == \"\") {\n throw new Error(\"Role name cannot be empty\");\n }\n const roleDef = this.getRoleDef(name) || (this.onMissingRole ? this.onMissingRole(name) || null : null);\n if (roleDef == null) {\n throw new Error(\"Role not found: \" + name);\n }\n this._currRoleDef = roleDef;\n }\n\n // Gets the current line, creating it if needed\n private _currentLine: Line | null = null;\n get currentLine(): Line {\n if (this._currentLine == null) {\n return this.newLine();\n }\n return this._currentLine;\n }\n\n resetLine(): void {\n this._currentLine = null;\n }\n\n newLine(): Line {\n if (this._currentLine && this._currentLine.isEmpty) {\n // then remove it first instead of adding another\n // so we dont have a string of empty lines\n this.removeLine(this._currentLine);\n }\n this._currentLine = new Line();\n this.addLine(this._currentLine);\n return this._currentLine;\n }\n\n private _layoutParams: LayoutParams | null = null;\n resetLayoutParams(): void {\n this._layoutParams = null;\n this.resetLine();\n }\n\n get layoutParams(): LayoutParams {\n if (this._layoutParams == null) {\n // create it or find one that matches current params\n this._layoutParams = this.findUnnamedLayoutParams();\n if (this._layoutParams == null) {\n this._layoutParams = this.snapshotLayoutParams();\n this._unnamedLayoutParams.push(this._layoutParams);\n }\n }\n return this._layoutParams;\n }\n\n ensureNamedLayoutParams(name: string): LayoutParams {\n let lp = this._namedLayoutParams.get(name) || null;\n if (lp == null || this._layoutParams != lp) {\n // no change so go ahead\n if (lp == null) {\n // does not exist so create one by re-snapshotting it\n // and saving it\n lp = this.snapshotLayoutParams();\n this._namedLayoutParams.set(name, lp);\n } else {\n // copy named LPs attributes into our locals\n this.currentCycle = lp.cycle;\n this.currentAPB = lp.beatDuration;\n this.currentBreaks = lp.lineBreaks;\n }\n this._layoutParams = lp;\n this.resetLine(); // since layout params have changed\n }\n return this._layoutParams;\n }\n\n protected snapshotLayoutParams(): LayoutParams {\n return new LayoutParams({\n cycle: this.currentCycle,\n beatDuration: this.currentAPB,\n layout: this.currentBreaks,\n });\n }\n\n /**\n * Find a layout params that is currently _unnamed but matches one\n * by current set of layout attributes.\n */\n protected findUnnamedLayoutParams(): LayoutParams | null {\n return (\n this._unnamedLayoutParams.find((lp) => {\n return (\n lp.beatDuration == this.currentAPB &&\n this.currentCycle.equals(lp.cycle) &&\n lp.lineBreaksEqual(this.currentBreaks)\n );\n }) || null\n );\n }\n}\n"]}
@@ -2,11 +2,11 @@ import * as TSU from "@panyam/tsutils";
2
2
  import * as G from "galore";
3
3
  import * as TLEX from "tlex";
4
4
  import { Literal, Note, Atom, Rest, Space, Group } from "./core";
5
- import { Command, CmdParam } from "./notation";
5
+ import { Notation, Command, CmdParam } from "./notation";
6
6
  export declare class Parser {
7
7
  errors: (TLEX.TokenizerError | G.ParseError)[];
8
+ metadata: any;
8
9
  readonly commands: Command[];
9
- private runCommandFound;
10
10
  protected ruleHandlers: {
11
11
  newFraction: (rule: G.Rule, parent: G.PTNode, ...children: G.PTNode[]) => TSU.Num.Fraction;
12
12
  newGroup: (rule: G.Rule, parent: G.PTNode, ...children: G.PTNode[]) => Group;
@@ -31,6 +31,7 @@ export declare class Parser {
31
31
  concatParamList: (rule: G.Rule, parent: G.PTNode, ...children: G.PTNode[]) => any;
32
32
  newCommand: (rule: G.Rule, parent: G.PTNode, ...children: G.PTNode[]) => Command;
33
33
  appendAtoms: (rule: G.Rule, parent: G.PTNode, ...children: G.PTNode[]) => null;
34
+ prependFrontMatter: (rule: G.Rule, parent: G.PTNode, ...children: G.PTNode[]) => any;
34
35
  appendCommand: (rule: G.Rule, parent: G.PTNode, ...children: G.PTNode[]) => null;
35
36
  appendRoleSelector: (rule: G.Rule, parent: G.PTNode, ...children: G.PTNode[]) => null;
36
37
  insertEmbedding: (rule: G.Rule, parent: G.PTNode, ...children: G.PTNode[]) => null;
@@ -39,5 +40,6 @@ export declare class Parser {
39
40
  createCommand(name: string, params: CmdParam[]): Command;
40
41
  addCommand(cmd: Command): void;
41
42
  parse(input: string): any;
43
+ parseAndBuild(input: string): [Notation, G.ParseError[]];
42
44
  parseEmbelishment(value: string): [any, boolean];
43
45
  }
package/lib/cjs/parser.js CHANGED
@@ -22,17 +22,22 @@ var __importStar = (this && this.__importStar) || function (mod) {
22
22
  __setModuleDefault(result, mod);
23
23
  return result;
24
24
  };
25
+ var __importDefault = (this && this.__importDefault) || function (mod) {
26
+ return (mod && mod.__esModule) ? mod : { "default": mod };
27
+ };
25
28
  Object.defineProperty(exports, "__esModule", { value: true });
26
29
  exports.Parser = void 0;
27
30
  const TSU = __importStar(require("@panyam/tsutils"));
28
31
  const G = __importStar(require("galore"));
29
32
  const TLEX = __importStar(require("tlex"));
33
+ const gray_matter_1 = __importDefault(require("gray-matter"));
30
34
  const core_1 = require("./core");
35
+ const notation_1 = require("./notation");
31
36
  const commands_1 = require("./commands");
32
37
  const carnatic = __importStar(require("./carnatic"));
33
38
  const ONE = TSU.Num.Fraction.ONE;
34
39
  const TWO = ONE.timesNum(2);
35
- const [parser, itemGraph] = G.newParser(String.raw `
40
+ const [parser] = G.newParser(String.raw `
36
41
  %define IdentChar /[^%!@$#&\^|\[\]={}()<>+\-,;~: \t\f\r\n\v\\\.\'\"]/
37
42
 
38
43
  %token BSLASH "\\"
@@ -51,6 +56,7 @@ const [parser, itemGraph] = G.newParser(String.raw `
51
56
  %token SEMI_COLON ";"
52
57
  %token COLON ":"
53
58
 
59
+ %token FRONT_MATTER /^---$/m { toFrontMatter }
54
60
  %token SINGLE_LINE_RAW_STRING />(.*)$/m { toSingleLineRawString }
55
61
  %token MULTI_LINE_RAW_STRING /r(#{0,})"/ { toMultiLineRawString }
56
62
 
@@ -74,6 +80,10 @@ const [parser, itemGraph] = G.newParser(String.raw `
74
80
  %skip_flex "//.*$"
75
81
  %skip /\/\*.*?\*\//
76
82
 
83
+ Document -> Elements
84
+ | FRONT_MATTER Elements { prependFrontMatter }
85
+ ;
86
+
77
87
  Elements -> Elements Command Atoms { appendCommand }
78
88
  | Elements RoleSelector Atoms { appendRoleSelector }
79
89
  | Elements Embedding Atoms { insertEmbedding }
@@ -218,13 +228,23 @@ const [parser, itemGraph] = G.newParser(String.raw `
218
228
  token.value = tape.substring(startPos, endPos);
219
229
  return token;
220
230
  },
231
+ toFrontMatter: (token, tape, owner) => {
232
+ const endPat = "\n---";
233
+ const startPos = tape.index;
234
+ const endPos = TLEX.TapeHelper.advanceAfter(tape, endPat) - endPat.length;
235
+ if (endPos < 0) {
236
+ throw new Error("EOF expected while finding end of front matter");
237
+ }
238
+ token.value = tape.substring(startPos, endPos);
239
+ return token;
240
+ },
221
241
  },
222
242
  });
223
243
  class Parser {
224
244
  constructor(config) {
225
245
  this.errors = [];
246
+ this.metadata = {};
226
247
  this.commands = [];
227
- this.runCommandFound = false;
228
248
  this.ruleHandlers = {
229
249
  newFraction: (rule, parent, ...children) => {
230
250
  if (children.length == 1) {
@@ -352,6 +372,13 @@ class Parser {
352
372
  }
353
373
  return null;
354
374
  },
375
+ prependFrontMatter: (rule, parent, ...children) => {
376
+ const fm = children[0].value;
377
+ const { data } = (0, gray_matter_1.default)("---\n" + fm + "\n---");
378
+ console.log("Parsed FM: ", data);
379
+ this.metadata = data;
380
+ return children[1].value;
381
+ },
355
382
  appendCommand: (rule, parent, ...children) => {
356
383
  const command = children[1].value;
357
384
  this.addCommand(command);
@@ -438,6 +465,17 @@ class Parser {
438
465
  }
439
466
  return null;
440
467
  }
468
+ parseAndBuild(input) {
469
+ this.parse(input);
470
+ const notation = new notation_1.Notation();
471
+ const errors = [];
472
+ errors.push(...this.errors);
473
+ for (const key in this.metadata)
474
+ notation.addMetaData(new notation_1.MetaData(key, this.metadata[key]));
475
+ for (const cmd of this.commands)
476
+ cmd.applyToNotation(notation);
477
+ return [notation, errors];
478
+ }
441
479
  parseEmbelishment(value) {
442
480
  return carnatic.parseEmbelishment(value);
443
481
  }
@@ -1 +1 @@
1
- {"version":3,"file":"parser.js","sourceRoot":"","sources":["../../src/parser.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,qDAAuC;AACvC,0CAA4B;AAC5B,2CAA6B;AAC7B,iCAA6F;AAE7F,yCAWoB;AAGpB,qDAAuC;AAEvC,MAAM,GAAG,GAAG,GAAG,CAAC,GAAG,CAAC,QAAQ,CAAC,GAAG,CAAC;AACjC,MAAM,GAAG,GAAG,GAAG,CAAC,QAAQ,CAAC,CAAC,CAAC,CAAC;AAW5B,MAAM,CAAC,MAAM,EAAE,SAAS,CAAC,GAAG,CAAC,CAAC,SAAS,CACrC,MAAM,CAAC,GAAG,CAAA;;;;;;;;;;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C,CAAC;SAC9C;IACH,CAAC;IAED,UAAU,CAAC,GAAY;QACrB,GAAG,CAAC,KAAK,GAAG,IAAI,CAAC,QAAQ,CAAC,MAAM,CAAC;QACjC,IAAI,CAAC,QAAQ,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;IAC1B,CAAC;IAED,KAAK,CAAC,KAAa;QACjB,IAAI,CAAC,MAAM,GAAG,EAAE,CAAC;QACjB,IAAI;YACF,MAAM,KAAK,GAAG,MAAM,CAAC,KAAK,CAAC,KAAK,EAAE;gBAChC,gBAAgB,EAAE,IAAI;gBACtB,YAAY,EAAE,IAAI,CAAC,YAAY;gBAC/B,YAAY,EAAE,CAAC,GAAwB,EAAE,EAAE;oBACzC,IAAI,CAAC,MAAM,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;oBACtB,OAAO,IAAI,CAAC;gBACd,CAAC;aACF,CAAC,CAAC;YACH,OAAO,KAAK,CAAC;SACd;QAAC,OAAO,GAAG,EAAE;YACZ,IAAI,GAAG,YAAY,CAAC,CAAC,UAAU,EAAE;gBAC/B,IAAI,CAAC,MAAM,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;aACvB;iBAAM;gBACL,MAAM,GAAG,CAAC;aACX;SACF;QACD,OAAO,IAAI,CAAC;IACd,CAAC;IAED,iBAAiB,CAAC,KAAa;QAC7B,OAAO,QAAQ,CAAC,iBAAiB,CAAC,KAAK,CAAC,CAAC;IAC3C,CAAC;CACF;AAjOD,wBAiOC","sourcesContent":["import * as TSU from \"@panyam/tsutils\";\nimport * as G from \"galore\";\nimport * as TLEX from \"tlex\";\nimport { Literal, AtomType, Note, Atom, Rest, Space, Syllable, Group, Marker } from \"./core\";\nimport { Command, CmdParam } from \"./notation\";\nimport {\n RawEmbedding,\n ApplyLayout,\n AddAtoms,\n SetCycle,\n SetBeatDuration,\n SetBreaks,\n ActivateRole,\n CreateRole,\n CreateLine,\n MetaData,\n} from \"./commands\";\n\n// TODO - Make this plugable from the client instead of hard coded\nimport * as carnatic from \"./carnatic\";\n\nconst ONE = TSU.Num.Fraction.ONE;\nconst TWO = ONE.timesNum(2);\n\n/**\n * V4 of our parser builds on V3 and has the following improvements:\n *\n * 1. Embedding Headings to demarcate sections so users dont have to use\n * explicit MD for headings.\n * 2. Unlike V3 here users break out *of* song instead instead break out \"into\"\n * song. So users spend more time writing notation and less worrying about\n * other things like headings etc.\n */\nconst [parser, itemGraph] = G.newParser(\n String.raw`\n %define IdentChar /[^%!@$#&\\^|\\[\\]={}()<>+\\-,;~: \\t\\f\\r\\n\\v\\\\\\.\\'\\\"]/\n\n %token BSLASH \"\\\\\"\n %token OPEN_SQ \"[\"\n %token CLOSE_SQ \"]\"\n %token EQUALS \"=\"\n %token OPEN_PAREN \"(\"\n %token CLOSE_PAREN \")\"\n %token OPEN_BRACE \"{\"\n %token CLOSE_BRACE \"}\"\n %token SLASH \"/\"\n %token STAR \"*\"\n %token CARET \"^\"\n // %skip \"-\"\n %token COMMA \",\"\n %token SEMI_COLON \";\"\n %token COLON \":\"\n\n %token SINGLE_LINE_RAW_STRING />(.*)$/m { toSingleLineRawString }\n %token MULTI_LINE_RAW_STRING /r(#{0,})\"/ { toMultiLineRawString }\n\n %token EMBELISHMENT /~[^\\s]*/ { toEmbelishment }\n %token NUMBER /-?\\d+/ { toNumber }\n %token BOOLEAN /true|false/ { toBoolean }\n %token POST_MARKER /<<\"(([^\"\\\\\\n]|\\\\.|\\\\\\n)*)\"/ { toMarker }\n %token POST_MARKER /<<'(([^'\\\\\\n]|\\\\.|\\\\\\n)*)'/ { toMarker }\n %token PRE_MARKER /\"(([^\"\\\\\\n]|\\\\.|\\\\\\n)*)\">>/ { toMarker }\n %token PRE_MARKER /'(([^'\\\\\\n]|\\\\.|\\\\\\n)*)'>>/ { toMarker }\n %token STRING /\"([^\"\\\\\\n]|\\\\.|\\\\\\n)*\"/ { toString }\n %token STRING /'([^'\\\\\\n]|\\\\.|\\\\\\n)*'/ { toString }\n %token DOTS_IDENT /(\\.+)({IdentChar}+)/ { toOctavedNote }\n %token IDENT_DOTS /({IdentChar}+)(\\.+)/ { toOctavedNote }\n %token IDENT_COLON /{IdentChar}+:/ { toRoleSelector }\n %token IDENT /{IdentChar}+/\n %token BSLASH_IDENT /\\\\{IDENT}/ { toCommandName }\n %token BSLASH_NUMBER /\\\\{NUMBER}/\n %token HYPHEN /-/\n %skip /[ \\t\\n\\f\\r]+/\n %skip_flex \"//.*$\"\n %skip /\\/\\*.*?\\*\\//\n\n Elements -> Elements Command Atoms { appendCommand } \n | Elements RoleSelector Atoms { appendRoleSelector } \n | Elements Embedding Atoms { insertEmbedding }\n | Atoms { appendAtoms }\n ;\n\n Embedding -> SINGLE_LINE_RAW_STRING | MULTI_LINE_RAW_STRING ;\n\n Command -> BSLASH_IDENT CommandParams ? { newCommand } ;\n CommandParams -> OPEN_PAREN ParamList ? CLOSE_PAREN { $2 } ;\n\n ParamList -> ParamList COMMA Param { concatParamList } ;\n ParamList -> Param { newParamList };\n Param -> ParamValue { newParam } ;\n Param -> ParamKey EQUALS ParamValue { newParam } ;\n ParamKey -> IDENT ;\n ParamValue -> ( STRING | Fraction | NUMBER | BOOLEAN ) ;\n\n RoleSelector -> IDENT_COLON ;\n\n Atoms -> Atoms Atom { concatAtoms } ;\n Atoms -> { newArray } ;\n\n Atom -> Atom POST_MARKER { applyPostMarker }\n | PreMarkedAtom\n ;\n PreMarkedAtom -> Leaf\n | PRE_MARKER PreMarkedAtom { applyPreMarker }\n ;\n\n Leaf -> Space | Lit | Group | Rest ;\n Leaf -> Duration Leaf { applyDuration } ;\n Rest -> HYPHEN { newRest };\n Space -> COMMA { newSpace } \n | SEMI_COLON { newDoubleSpace } \n | UNDER_SCORE { newSilentSpace } \n ;\n\n /* - An alternative representation to support both pre and\n * post embelishment operators. Here PRE_EMBs have a higher\n * associativity over POST_EMBs\n */\n Lit -> Lit POST_EMB { litWithPostEmb }\n | PreEmbLit\n ;\n\n PreEmbLit -> LitToken \n | LitToken CARET NUMBER { litWithCaret }\n | LitToken CARET STAR { litWithCaret }\n | PRE_EMB PreEmbLit { litWithPreEmb }\n ;\n \n LitToken -> DOTS_IDENT { litToAtom }\n | IDENT { litToAtom }\n | IDENT_DOTS { litToAtom }\n | STRING { litToAtom }\n ;\n\n Group -> OPEN_SQ Atoms CLOSE_SQ { newGroup };\n\n Duration -> Fraction | NUMBER;\n Fraction -> NUMBER SLASH NUMBER { newFraction } ;\n `,\n {\n allowLeftRecursion: true,\n debug: \"\",\n type: \"lalr\",\n tokenHandlers: {\n toEmbelishment: (token: TLEX.Token, tape: TLEX.Tape, owner: Parser) => {\n const [emb, pre] = owner.parseEmbelishment(token.value);\n if (emb == null) {\n console.log(\"Skipping Embelishment: \", token.value);\n owner.errors.push(\n new TLEX.TokenizerError(\n `Invalid embelishment: ${token.value}`,\n token.start,\n 1 + token.end - token.start,\n \"InvalidEmbelishment\",\n token.value,\n ),\n );\n return null;\n }\n token.value = emb;\n token.tag = pre ? \"PRE_EMB\" : \"POST_EMB\";\n return token;\n },\n toCommandName: (token: TLEX.Token, tape: TLEX.Tape, owner: any) => {\n token.value = token.value.substring(1);\n return token;\n },\n toBoolean: (token: TLEX.Token, tape: TLEX.Tape, owner: any) => {\n token.value = token.value == \"true\";\n return token;\n },\n toNumber: (token: TLEX.Token, tape: TLEX.Tape, owner: any) => {\n token.value = parseInt(token.value);\n return token;\n },\n toString: (token: TLEX.Token, tape: TLEX.Tape, owner: any) => {\n token.value = token.value.substring(1, token.value.length - 1);\n return token;\n },\n toMarker: (token: TLEX.Token, tape: TLEX.Tape, owner: any) => {\n if (token.tag != \"PRE_MARKER\" && token.tag != \"POST_MARKER\") {\n throw new Error(\"Invalid token for converting to note: \" + token.tag);\n }\n const isBefore = token.tag == \"PRE_MARKER\";\n const markerText = isBefore\n ? token.value.substring(1, token.value.length - 3)\n : token.value.substring(3, token.value.length - 1);\n // console.log(\"TokVal: \", token.value, token.positions);\n // console.log(\"Marker Text: \", markerText, isBefore);\n token.value = new Marker(markerText, isBefore);\n return token;\n },\n toOctavedNote: (token: TLEX.Token, tape: TLEX.Tape, owner: any) => {\n if (token.tag == \"DOTS_IDENT\") {\n const octave = token.positions[1][1] - token.positions[1][0];\n const note = token.value.substring(octave);\n token.value = new Note(note, ONE, -octave);\n } else if (token.tag == \"IDENT_DOTS\") {\n const octave = token.positions[2][1] - token.positions[2][0];\n const note = token.value.substring(0, token.value.length - octave);\n token.value = new Note(note, ONE, octave);\n } else {\n throw new Error(\"Invalid token for converting to note: \" + token.tag);\n }\n return token;\n },\n toRoleSelector: (token: TLEX.Token, tape: TLEX.Tape, owner: any) => {\n token.value = token.value.substring(0, token.value.length - 1);\n return token;\n },\n toLineAnnotation: (token: TLEX.Token, tape: TLEX.Tape, owner: any) => {\n // skip the initial \"!\"\n token.value = token.value.substring(1);\n return token;\n },\n toSingleLineRawString: (token: TLEX.Token, tape: TLEX.Tape, owner: any) => {\n // skip the initial \">\"\n token.value = token.value.substring(1);\n return token;\n },\n toMultiLineRawString: (token: TLEX.Token, tape: TLEX.Tape, owner: any) => {\n // consume everything until \"#<N times> as start\n const hashes = tape.substring(token.positions[1][0], token.positions[1][1]);\n const endPat = '\"' + hashes;\n const startPos = tape.index;\n const endPos = TLEX.TapeHelper.advanceAfter(tape, endPat) - endPat.length;\n if (endPos < 0) {\n throw new Error(\"EOF expected while finding end of Raw String Literal: '\" + endPat + \"'\");\n }\n token.value = tape.substring(startPos, endPos);\n return token;\n },\n },\n },\n);\n\n/**\n * A notation doc is a list of lines that are found in a single document.\n *\n * Since our document (md or html etc) can contain multiple snippets\n * all these snippets are related\n */\nexport class Parser {\n errors: (TLEX.TokenizerError | G.ParseError)[] = [];\n readonly commands: Command[] = [];\n // readonly notation: Notation = new Notation();\n private runCommandFound = false;\n // readonly parseTree = new PTNodeList(\"Snippet\", null);\n\n protected ruleHandlers = {\n newFraction: (rule: G.Rule, parent: G.PTNode, ...children: G.PTNode[]) => {\n if (children.length == 1) {\n return new TSU.Num.Fraction(children[0].value);\n } else {\n return new TSU.Num.Fraction(children[0].value, children[2].value);\n }\n },\n newGroup: (rule: G.Rule, parent: G.PTNode, ...children: G.PTNode[]) => {\n const out = new Group(...children[1].value).setDuration(TWO, true);\n return out;\n },\n litWithCaret: (rule: G.Rule, parent: G.PTNode, ...children: G.PTNode[]) => {\n const lit = Note.fromLit(children[0].value as Literal);\n const opnode = children[2];\n const shiftValue = opnode.sym.label == \"STAR\" ? true : opnode.value;\n lit.shift = shiftValue;\n return lit;\n },\n litWithPreEmb: (rule: G.Rule, parent: G.PTNode, ...children: G.PTNode[]) => {\n const emb = children[0];\n const lit = children[1].value as Literal;\n lit.embelishments.splice(0, 0, emb.value);\n return lit;\n },\n litWithPostEmb: (rule: G.Rule, parent: G.PTNode, ...children: G.PTNode[]) => {\n const lit = children[0].value as Literal;\n const emb = children[1];\n lit.embelishments.push(emb);\n return lit;\n },\n litToAtom: (rule: G.Rule, parent: G.PTNode, ...children: G.PTNode[]) => {\n const lit = children[0];\n if (lit.sym.label == \"DOTS_IDENT\" || lit.sym.label == \"IDENT_DOTS\") {\n return lit.value;\n } else if (lit.sym.label == \"IDENT\") {\n // Mark this as a Literal to be processed later\n return new Literal(lit.value);\n // return role.notesOnly ? new Note(lit.value) : new Syllable(lit.value);\n } else if (lit.sym.label == \"STRING\") {\n // const role = this.snippet.currRole;\n // if (role.notesOnly) throw new Error(\"Strings cannot appear in notes only mode\");\n return new Syllable(lit.value);\n } else {\n throw new Error(\"Invalid lit: \" + lit);\n }\n },\n newSpace: (rule: G.Rule, parent: G.PTNode, ...children: G.PTNode[]) => {\n return new Space();\n },\n newRest: (rule: G.Rule, parent: G.PTNode, ...children: G.PTNode[]) => {\n return new Rest();\n },\n newDoubleSpace: (rule: G.Rule, parent: G.PTNode, ...children: G.PTNode[]) => {\n return new Space(ONE.timesNum(2));\n },\n newSilentSpace: (rule: G.Rule, parent: G.PTNode, ...children: G.PTNode[]) => {\n return new Space(ONE, true);\n },\n applyPreMarker: (rule: G.Rule, parent: G.PTNode, ...children: G.PTNode[]) => {\n const marker = children[0].value as Marker;\n const leaf = children[1].value as Atom;\n // console.log(\"marker, leaf: \", marker, leaf);\n if (!leaf.markersBefore) {\n leaf.markersBefore = [];\n }\n leaf.markersBefore.splice(0, 0, marker);\n return leaf;\n },\n applyPostMarker: (rule: G.Rule, parent: G.PTNode, ...children: G.PTNode[]) => {\n const leaf = children[0].value as Atom;\n const marker = children[1].value as Marker;\n if (!leaf.markersAfter) {\n leaf.markersAfter = [];\n }\n leaf.markersAfter.push(marker);\n return leaf;\n },\n applyDuration: (rule: G.Rule, parent: G.PTNode, ...children: G.PTNode[]) => {\n let dur = children[0].value as TSU.Num.Fraction | number;\n const leaf = children[1].value as Atom;\n if (typeof dur === \"number\") {\n dur = ONE.timesNum(dur);\n }\n if (leaf.TYPE == AtomType.GROUP) {\n (leaf as Group).setDuration(dur, true);\n } else {\n leaf.duration = dur;\n }\n return leaf;\n },\n newArray: (rule: G.Rule, parent: G.PTNode, ...children: G.PTNode[]) => {\n // create an array of values from all the values of child nodes\n return children.map((c) => c.value);\n },\n concatAtoms: (rule: G.Rule, parent: G.PTNode, ...children: G.PTNode[]) => {\n const atoms = children[0].value;\n const atom = children[1].value;\n atoms.push(atom);\n return atoms;\n },\n newParam: (rule: G.Rule, parent: G.PTNode, ...children: G.PTNode[]) => {\n if (children.length == 1) {\n return { key: null, value: children[0].value };\n } else {\n return { key: children[0].value, value: children[2].value };\n }\n },\n newParamList: (rule: G.Rule, parent: G.PTNode, ...children: G.PTNode[]) => {\n return [children[0].value];\n },\n concatParamList: (rule: G.Rule, parent: G.PTNode, ...children: G.PTNode[]) => {\n const params = children[0].value;\n const newParam = children[2].value;\n params.push(newParam);\n return params;\n },\n newCommand: (rule: G.Rule, parent: G.PTNode, ...children: G.PTNode[]) => {\n return this.createCommand(children[0].value, children[1].value);\n },\n appendAtoms: (rule: G.Rule, parent: G.PTNode, ...children: G.PTNode[]) => {\n const atoms = children[0].value as Atom[];\n if (atoms.length > 0) {\n this.addCommand(new AddAtoms(...atoms));\n }\n return null;\n },\n appendCommand: (rule: G.Rule, parent: G.PTNode, ...children: G.PTNode[]) => {\n const command = children[1].value as Command;\n this.addCommand(command);\n\n const atoms = children[2].value as Atom[];\n if (atoms.length > 0) {\n this.addCommand(new AddAtoms(...atoms));\n }\n return null;\n },\n appendRoleSelector: (rule: G.Rule, parent: G.PTNode, ...children: G.PTNode[]) => {\n const roleName = children[1].value;\n const lName = roleName.toLowerCase().trim();\n this.addCommand(new ActivateRole([{ key: null, value: lName }]));\n\n const atoms = children[2].value as Atom[];\n if (atoms.length > 0) {\n this.addCommand(new AddAtoms(...atoms));\n }\n return null;\n },\n insertEmbedding: (rule: G.Rule, parent: G.PTNode, ...children: G.PTNode[]) => {\n // How to handle embeddings - these are just blocks\n // to escape out of song (most likely for some rendering of html/md etc)\n const rawVal = children[1].value;\n this.addCommand(new RawEmbedding([{ key: null, value: rawVal }]));\n const atoms = children[2].value as Atom[];\n if (atoms.length > 0) {\n this.addCommand(new AddAtoms(...atoms));\n }\n return null;\n },\n };\n\n constructor(config?: any) {\n config = config || {};\n }\n\n createCommand(name: string, params: CmdParam[]): Command {\n const lName = name.trim().toLowerCase();\n params = params || [];\n if (lName == \"line\") {\n return new CreateLine(params);\n } else if (lName == \"meta\") {\n return new MetaData(params);\n } else if (lName == \"role\") {\n return new CreateRole(params);\n } else if (lName == \"layout\") {\n return new ApplyLayout(params);\n } else if (lName == \"beatduration\") {\n return new SetBeatDuration(params);\n } else if (lName == \"breaks\") {\n return new SetBreaks(params);\n } else if (lName == \"cycle\") {\n return new SetCycle(params);\n } else {\n // Try to set this as the current role\n throw new Error(\"Invalid command: \" + lName);\n }\n }\n\n addCommand(cmd: Command): void {\n cmd.index = this.commands.length;\n this.commands.push(cmd);\n }\n\n parse(input: string): any {\n this.errors = [];\n try {\n const ptree = parser.parse(input, {\n tokenizerContext: this,\n ruleHandlers: this.ruleHandlers,\n onTokenError: (err: TLEX.TokenizerError) => {\n this.errors.push(err);\n return true;\n },\n });\n return ptree;\n } catch (err) {\n if (err instanceof G.ParseError) {\n this.errors.push(err);\n } else {\n throw err;\n }\n }\n return null;\n }\n\n parseEmbelishment(value: string): [any, boolean] {\n return carnatic.parseEmbelishment(value);\n }\n}\n"]}
1
+ {"version":3,"file":"parser.js","sourceRoot":"","sources":["../../src/parser.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,qDAAuC;AACvC,0CAA4B;AAC5B,2CAA6B;AAC7B,8DAAiC;AACjC,iCAA6F;AAC7F,yCAA2E;AAC3E,yCAWoB;AAGpB,qDAAuC;AAEvC,MAAM,GAAG,GAAG,GAAG,CAAC,GAAG,CAAC,QAAQ,CAAC,GAAG,CAAC;AACjC,MAAM,GAAG,GAAG,GAAG,CAAC,QAAQ,CAAC,CAAC,CAAC,CAAC;AAW5B,MAAM,CAAC,MAAM,CAAe,GAAG,CAAC,CAAC,SAAS,CACxC,MAAM,CAAC,GAAG,CAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;KA6GP,EACH;IACE,kBAAkB,EAAE,IAAI;IACxB,KAAK,EAAE,EAAE;IACT,IAAI,EAAE,MAAM;IACZ,aAAa,EAAE;QACb,cAAc,EAAE,CAAC,KAAiB,EAAE,IAAe,EAAE,KAAa,EAAE,EAAE;YACpE,MAAM,CAAC,GAAG,EAAE,GAAG,CAAC,GAAG,KAAK,CAAC,iBAAiB,CAAC,KAAK,CAAC,KAAK,CAAC,CAAC;YACxD,IAAI,GAAG,IAAI,IAAI,EAAE;gBACf,OAAO,CAAC,GAAG,CAAC,yBAAyB,EAAE,KAAK,CAAC,KAAK,CAAC,CAAC;gBACpD,KAAK,CAAC,MAAM,CAAC,IAAI,CACf,IAAI,IAAI,CAAC,cAAc,CACrB,yBAAyB,KAAK,CAAC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QAChC,MAAM,MAAM,GAAmB,EAAE,CAAC;QAClC,MAAM,CAAC,IAAI,CAAC,GAAG,IAAI,CAAC,MAAM,CAAC,CAAC;QAG5B,KAAK,MAAM,GAAG,IAAI,IAAI,CAAC,QAAQ;YAAE,QAAQ,CAAC,WAAW,CAAC,IAAI,mBAAI,CAAC,GAAG,EAAE,IAAI,CAAC,QAAQ,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC;QACzF,KAAK,MAAM,GAAG,IAAI,IAAI,CAAC,QAAQ;YAAE,GAAG,CAAC,eAAe,CAAC,QAAQ,CAAC,CAAC;QAC/D,OAAO,CAAC,QAAQ,EAAE,MAAM,CAAC,CAAC;IAC5B,CAAC;IAED,iBAAiB,CAAC,KAAa;QAC7B,OAAO,QAAQ,CAAC,iBAAiB,CAAC,KAAK,CAAC,CAAC;IAC3C,CAAC;CACF;AAvPD,wBAuPC","sourcesContent":["import * as TSU from \"@panyam/tsutils\";\nimport * as G from \"galore\";\nimport * as TLEX from \"tlex\";\nimport matter from \"gray-matter\";\nimport { Literal, AtomType, Note, Atom, Rest, Space, Syllable, Group, Marker } from \"./core\";\nimport { Notation, MetaData as Meta, Command, CmdParam } from \"./notation\";\nimport {\n RawEmbedding,\n ApplyLayout,\n AddAtoms,\n SetCycle,\n SetBeatDuration,\n SetBreaks,\n ActivateRole,\n CreateRole,\n CreateLine,\n MetaData,\n} from \"./commands\";\n\n// TODO - Make this plugable from the client instead of hard coded\nimport * as carnatic from \"./carnatic\";\n\nconst ONE = TSU.Num.Fraction.ONE;\nconst TWO = ONE.timesNum(2);\n\n/**\n * V4 of our parser builds on V3 and has the following improvements:\n *\n * 1. Embedding Headings to demarcate sections so users dont have to use\n * explicit MD for headings.\n * 2. Unlike V3 here users break out *of* song instead instead break out \"into\"\n * song. So users spend more time writing notation and less worrying about\n * other things like headings etc.\n */\nconst [parser /*itemGraph*/] = G.newParser(\n String.raw`\n %define IdentChar /[^%!@$#&\\^|\\[\\]={}()<>+\\-,;~: \\t\\f\\r\\n\\v\\\\\\.\\'\\\"]/\n\n %token BSLASH \"\\\\\"\n %token OPEN_SQ \"[\"\n %token CLOSE_SQ \"]\"\n %token EQUALS \"=\"\n %token OPEN_PAREN \"(\"\n %token CLOSE_PAREN \")\"\n %token OPEN_BRACE \"{\"\n %token CLOSE_BRACE \"}\"\n %token SLASH \"/\"\n %token STAR \"*\"\n %token CARET \"^\"\n // %skip \"-\"\n %token COMMA \",\"\n %token SEMI_COLON \";\"\n %token COLON \":\"\n\n %token FRONT_MATTER /^---$/m { toFrontMatter }\n %token SINGLE_LINE_RAW_STRING />(.*)$/m { toSingleLineRawString }\n %token MULTI_LINE_RAW_STRING /r(#{0,})\"/ { toMultiLineRawString }\n\n %token EMBELISHMENT /~[^\\s]*/ { toEmbelishment }\n %token NUMBER /-?\\d+/ { toNumber }\n %token BOOLEAN /true|false/ { toBoolean }\n %token POST_MARKER /<<\"(([^\"\\\\\\n]|\\\\.|\\\\\\n)*)\"/ { toMarker }\n %token POST_MARKER /<<'(([^'\\\\\\n]|\\\\.|\\\\\\n)*)'/ { toMarker }\n %token PRE_MARKER /\"(([^\"\\\\\\n]|\\\\.|\\\\\\n)*)\">>/ { toMarker }\n %token PRE_MARKER /'(([^'\\\\\\n]|\\\\.|\\\\\\n)*)'>>/ { toMarker }\n %token STRING /\"([^\"\\\\\\n]|\\\\.|\\\\\\n)*\"/ { toString }\n %token STRING /'([^'\\\\\\n]|\\\\.|\\\\\\n)*'/ { toString }\n %token DOTS_IDENT /(\\.+)({IdentChar}+)/ { toOctavedNote }\n %token IDENT_DOTS /({IdentChar}+)(\\.+)/ { toOctavedNote }\n %token IDENT_COLON /{IdentChar}+:/ { toRoleSelector }\n %token IDENT /{IdentChar}+/\n %token BSLASH_IDENT /\\\\{IDENT}/ { toCommandName }\n %token BSLASH_NUMBER /\\\\{NUMBER}/\n %token HYPHEN /-/\n %skip /[ \\t\\n\\f\\r]+/\n %skip_flex \"//.*$\"\n %skip /\\/\\*.*?\\*\\//\n\n Document -> Elements\n | FRONT_MATTER Elements { prependFrontMatter }\n ;\n\n Elements -> Elements Command Atoms { appendCommand } \n | Elements RoleSelector Atoms { appendRoleSelector } \n | Elements Embedding Atoms { insertEmbedding }\n | Atoms { appendAtoms }\n ;\n\n Embedding -> SINGLE_LINE_RAW_STRING | MULTI_LINE_RAW_STRING ;\n\n Command -> BSLASH_IDENT CommandParams ? { newCommand } ;\n CommandParams -> OPEN_PAREN ParamList ? CLOSE_PAREN { $2 } ;\n\n ParamList -> ParamList COMMA Param { concatParamList } ;\n ParamList -> Param { newParamList };\n Param -> ParamValue { newParam } ;\n Param -> ParamKey EQUALS ParamValue { newParam } ;\n ParamKey -> IDENT ;\n ParamValue -> ( STRING | Fraction | NUMBER | BOOLEAN ) ;\n\n RoleSelector -> IDENT_COLON ;\n\n Atoms -> Atoms Atom { concatAtoms } ;\n Atoms -> { newArray } ;\n\n Atom -> Atom POST_MARKER { applyPostMarker }\n | PreMarkedAtom\n ;\n PreMarkedAtom -> Leaf\n | PRE_MARKER PreMarkedAtom { applyPreMarker }\n ;\n\n Leaf -> Space | Lit | Group | Rest ;\n Leaf -> Duration Leaf { applyDuration } ;\n Rest -> HYPHEN { newRest };\n Space -> COMMA { newSpace } \n | SEMI_COLON { newDoubleSpace } \n | UNDER_SCORE { newSilentSpace } \n ;\n\n /* - An alternative representation to support both pre and\n * post embelishment operators. Here PRE_EMBs have a higher\n * associativity over POST_EMBs\n */\n Lit -> Lit POST_EMB { litWithPostEmb }\n | PreEmbLit\n ;\n\n PreEmbLit -> LitToken \n | LitToken CARET NUMBER { litWithCaret }\n | LitToken CARET STAR { litWithCaret }\n | PRE_EMB PreEmbLit { litWithPreEmb }\n ;\n \n LitToken -> DOTS_IDENT { litToAtom }\n | IDENT { litToAtom }\n | IDENT_DOTS { litToAtom }\n | STRING { litToAtom }\n ;\n\n Group -> OPEN_SQ Atoms CLOSE_SQ { newGroup };\n\n Duration -> Fraction | NUMBER;\n Fraction -> NUMBER SLASH NUMBER { newFraction } ;\n `,\n {\n allowLeftRecursion: true,\n debug: \"\",\n type: \"lalr\",\n tokenHandlers: {\n toEmbelishment: (token: TLEX.Token, tape: TLEX.Tape, owner: Parser) => {\n const [emb, pre] = owner.parseEmbelishment(token.value);\n if (emb == null) {\n console.log(\"Skipping Embelishment: \", token.value);\n owner.errors.push(\n new TLEX.TokenizerError(\n `Invalid embelishment: ${token.value}`,\n token.start,\n 1 + token.end - token.start,\n \"InvalidEmbelishment\",\n token.value,\n ),\n );\n return null;\n }\n token.value = emb;\n token.tag = pre ? \"PRE_EMB\" : \"POST_EMB\";\n return token;\n },\n toCommandName: (token: TLEX.Token, tape: TLEX.Tape, owner: any) => {\n token.value = token.value.substring(1);\n return token;\n },\n toBoolean: (token: TLEX.Token, tape: TLEX.Tape, owner: any) => {\n token.value = token.value == \"true\";\n return token;\n },\n toNumber: (token: TLEX.Token, tape: TLEX.Tape, owner: any) => {\n token.value = parseInt(token.value);\n return token;\n },\n toString: (token: TLEX.Token, tape: TLEX.Tape, owner: any) => {\n token.value = token.value.substring(1, token.value.length - 1);\n return token;\n },\n toMarker: (token: TLEX.Token, tape: TLEX.Tape, owner: any) => {\n if (token.tag != \"PRE_MARKER\" && token.tag != \"POST_MARKER\") {\n throw new Error(\"Invalid token for converting to note: \" + token.tag);\n }\n const isBefore = token.tag == \"PRE_MARKER\";\n const markerText = isBefore\n ? token.value.substring(1, token.value.length - 3)\n : token.value.substring(3, token.value.length - 1);\n // console.log(\"TokVal: \", token.value, token.positions);\n // console.log(\"Marker Text: \", markerText, isBefore);\n token.value = new Marker(markerText, isBefore);\n return token;\n },\n toOctavedNote: (token: TLEX.Token, tape: TLEX.Tape, owner: any) => {\n if (token.tag == \"DOTS_IDENT\") {\n const octave = token.positions[1][1] - token.positions[1][0];\n const note = token.value.substring(octave);\n token.value = new Note(note, ONE, -octave);\n } else if (token.tag == \"IDENT_DOTS\") {\n const octave = token.positions[2][1] - token.positions[2][0];\n const note = token.value.substring(0, token.value.length - octave);\n token.value = new Note(note, ONE, octave);\n } else {\n throw new Error(\"Invalid token for converting to note: \" + token.tag);\n }\n return token;\n },\n toRoleSelector: (token: TLEX.Token, tape: TLEX.Tape, owner: any) => {\n token.value = token.value.substring(0, token.value.length - 1);\n return token;\n },\n toLineAnnotation: (token: TLEX.Token, tape: TLEX.Tape, owner: any) => {\n // skip the initial \"!\"\n token.value = token.value.substring(1);\n return token;\n },\n toSingleLineRawString: (token: TLEX.Token, tape: TLEX.Tape, owner: any) => {\n // skip the initial \">\"\n token.value = token.value.substring(1);\n return token;\n },\n toMultiLineRawString: (token: TLEX.Token, tape: TLEX.Tape, owner: any) => {\n // consume everything until \"#<N times> as start\n const hashes = tape.substring(token.positions[1][0], token.positions[1][1]);\n const endPat = '\"' + hashes;\n const startPos = tape.index;\n const endPos = TLEX.TapeHelper.advanceAfter(tape, endPat) - endPat.length;\n if (endPos < 0) {\n throw new Error(\"EOF expected while finding end of Raw String Literal: '\" + endPat + \"'\");\n }\n token.value = tape.substring(startPos, endPos);\n return token;\n },\n toFrontMatter: (token: TLEX.Token, tape: TLEX.Tape, owner: any) => {\n // skip the initial \">\"\n const endPat = \"\\n---\";\n const startPos = tape.index;\n const endPos = TLEX.TapeHelper.advanceAfter(tape, endPat) - endPat.length;\n if (endPos < 0) {\n throw new Error(\"EOF expected while finding end of front matter\");\n }\n token.value = tape.substring(startPos, endPos);\n // console.log(\"Found FM: \", token.value);\n return token;\n },\n },\n },\n);\n\n/**\n * A notation doc is a list of lines that are found in a single document.\n *\n * Since our document (md or html etc) can contain multiple snippets\n * all these snippets are related\n */\nexport class Parser {\n errors: (TLEX.TokenizerError | G.ParseError)[] = [];\n metadata: any = {};\n readonly commands: Command[] = [];\n // readonly notation: Notation = new Notation();\n // private runCommandFound = false;\n // readonly parseTree = new PTNodeList(\"Snippet\", null);\n\n protected ruleHandlers = {\n newFraction: (rule: G.Rule, parent: G.PTNode, ...children: G.PTNode[]) => {\n if (children.length == 1) {\n return new TSU.Num.Fraction(children[0].value);\n } else {\n return new TSU.Num.Fraction(children[0].value, children[2].value);\n }\n },\n newGroup: (rule: G.Rule, parent: G.PTNode, ...children: G.PTNode[]) => {\n const out = new Group(...children[1].value).setDuration(TWO, true);\n return out;\n },\n litWithCaret: (rule: G.Rule, parent: G.PTNode, ...children: G.PTNode[]) => {\n const lit = Note.fromLit(children[0].value as Literal);\n const opnode = children[2];\n const shiftValue = opnode.sym.label == \"STAR\" ? true : opnode.value;\n lit.shift = shiftValue;\n return lit;\n },\n litWithPreEmb: (rule: G.Rule, parent: G.PTNode, ...children: G.PTNode[]) => {\n const emb = children[0];\n const lit = children[1].value as Literal;\n lit.embelishments.splice(0, 0, emb.value);\n return lit;\n },\n litWithPostEmb: (rule: G.Rule, parent: G.PTNode, ...children: G.PTNode[]) => {\n const lit = children[0].value as Literal;\n const emb = children[1];\n lit.embelishments.push(emb);\n return lit;\n },\n litToAtom: (rule: G.Rule, parent: G.PTNode, ...children: G.PTNode[]) => {\n const lit = children[0];\n if (lit.sym.label == \"DOTS_IDENT\" || lit.sym.label == \"IDENT_DOTS\") {\n return lit.value;\n } else if (lit.sym.label == \"IDENT\") {\n // Mark this as a Literal to be processed later\n return new Literal(lit.value);\n // return role.notesOnly ? new Note(lit.value) : new Syllable(lit.value);\n } else if (lit.sym.label == \"STRING\") {\n // const role = this.snippet.currRole;\n // if (role.notesOnly) throw new Error(\"Strings cannot appear in notes only mode\");\n return new Syllable(lit.value);\n } else {\n throw new Error(\"Invalid lit: \" + lit);\n }\n },\n newSpace: (rule: G.Rule, parent: G.PTNode, ...children: G.PTNode[]) => {\n return new Space();\n },\n newRest: (rule: G.Rule, parent: G.PTNode, ...children: G.PTNode[]) => {\n return new Rest();\n },\n newDoubleSpace: (rule: G.Rule, parent: G.PTNode, ...children: G.PTNode[]) => {\n return new Space(ONE.timesNum(2));\n },\n newSilentSpace: (rule: G.Rule, parent: G.PTNode, ...children: G.PTNode[]) => {\n return new Space(ONE, true);\n },\n applyPreMarker: (rule: G.Rule, parent: G.PTNode, ...children: G.PTNode[]) => {\n const marker = children[0].value as Marker;\n const leaf = children[1].value as Atom;\n // console.log(\"marker, leaf: \", marker, leaf);\n if (!leaf.markersBefore) {\n leaf.markersBefore = [];\n }\n leaf.markersBefore.splice(0, 0, marker);\n return leaf;\n },\n applyPostMarker: (rule: G.Rule, parent: G.PTNode, ...children: G.PTNode[]) => {\n const leaf = children[0].value as Atom;\n const marker = children[1].value as Marker;\n if (!leaf.markersAfter) {\n leaf.markersAfter = [];\n }\n leaf.markersAfter.push(marker);\n return leaf;\n },\n applyDuration: (rule: G.Rule, parent: G.PTNode, ...children: G.PTNode[]) => {\n let dur = children[0].value as TSU.Num.Fraction | number;\n const leaf = children[1].value as Atom;\n if (typeof dur === \"number\") {\n dur = ONE.timesNum(dur);\n }\n if (leaf.TYPE == AtomType.GROUP) {\n (leaf as Group).setDuration(dur, true);\n } else {\n leaf.duration = dur;\n }\n return leaf;\n },\n newArray: (rule: G.Rule, parent: G.PTNode, ...children: G.PTNode[]) => {\n // create an array of values from all the values of child nodes\n return children.map((c) => c.value);\n },\n concatAtoms: (rule: G.Rule, parent: G.PTNode, ...children: G.PTNode[]) => {\n const atoms = children[0].value;\n const atom = children[1].value;\n atoms.push(atom);\n return atoms;\n },\n newParam: (rule: G.Rule, parent: G.PTNode, ...children: G.PTNode[]) => {\n if (children.length == 1) {\n return { key: null, value: children[0].value };\n } else {\n return { key: children[0].value, value: children[2].value };\n }\n },\n newParamList: (rule: G.Rule, parent: G.PTNode, ...children: G.PTNode[]) => {\n return [children[0].value];\n },\n concatParamList: (rule: G.Rule, parent: G.PTNode, ...children: G.PTNode[]) => {\n const params = children[0].value;\n const newParam = children[2].value;\n params.push(newParam);\n return params;\n },\n newCommand: (rule: G.Rule, parent: G.PTNode, ...children: G.PTNode[]) => {\n return this.createCommand(children[0].value, children[1].value);\n },\n appendAtoms: (rule: G.Rule, parent: G.PTNode, ...children: G.PTNode[]) => {\n const atoms = children[0].value as Atom[];\n if (atoms.length > 0) {\n this.addCommand(new AddAtoms(...atoms));\n }\n return null;\n },\n prependFrontMatter: (rule: G.Rule, parent: G.PTNode, ...children: G.PTNode[]) => {\n const fm = children[0].value;\n // console.log(\"Child 0: \", fm);\n // console.log(\"Child 1: \", children[1].value);\n const { data } = matter(\"---\\n\" + fm + \"\\n---\");\n console.log(\"Parsed FM: \", data);\n this.metadata = data;\n return children[1].value;\n },\n appendCommand: (rule: G.Rule, parent: G.PTNode, ...children: G.PTNode[]) => {\n const command = children[1].value as Command;\n this.addCommand(command);\n\n const atoms = children[2].value as Atom[];\n if (atoms.length > 0) {\n this.addCommand(new AddAtoms(...atoms));\n }\n return null;\n },\n appendRoleSelector: (rule: G.Rule, parent: G.PTNode, ...children: G.PTNode[]) => {\n const roleName = children[1].value;\n const lName = roleName.toLowerCase().trim();\n this.addCommand(new ActivateRole([{ key: null, value: lName }]));\n\n const atoms = children[2].value as Atom[];\n if (atoms.length > 0) {\n this.addCommand(new AddAtoms(...atoms));\n }\n return null;\n },\n insertEmbedding: (rule: G.Rule, parent: G.PTNode, ...children: G.PTNode[]) => {\n // How to handle embeddings - these are just blocks\n // to escape out of song (most likely for some rendering of html/md etc)\n const rawVal = children[1].value;\n this.addCommand(new RawEmbedding([{ key: null, value: rawVal }]));\n const atoms = children[2].value as Atom[];\n if (atoms.length > 0) {\n this.addCommand(new AddAtoms(...atoms));\n }\n return null;\n },\n };\n\n constructor(config?: any) {\n config = config || {};\n }\n\n createCommand(name: string, params: CmdParam[]): Command {\n const lName = name.trim().toLowerCase();\n params = params || [];\n if (lName == \"line\") {\n return new CreateLine(params);\n } else if (lName == \"meta\") {\n return new MetaData(params);\n } else if (lName == \"role\") {\n return new CreateRole(params);\n } else if (lName == \"layout\") {\n return new ApplyLayout(params);\n } else if (lName == \"beatduration\") {\n return new SetBeatDuration(params);\n } else if (lName == \"breaks\") {\n return new SetBreaks(params);\n } else if (lName == \"cycle\") {\n return new SetCycle(params);\n } else {\n // Try to set this as the current role\n throw new Error(\"Invalid command: \" + lName);\n }\n }\n\n addCommand(cmd: Command): void {\n cmd.index = this.commands.length;\n this.commands.push(cmd);\n }\n\n parse(input: string): any {\n this.errors = [];\n try {\n const ptree = parser.parse(input, {\n tokenizerContext: this,\n ruleHandlers: this.ruleHandlers,\n onTokenError: (err: TLEX.TokenizerError) => {\n this.errors.push(err);\n return true;\n },\n });\n return ptree;\n } catch (err) {\n if (err instanceof G.ParseError) {\n this.errors.push(err);\n } else {\n throw err;\n }\n }\n return null;\n }\n\n parseAndBuild(input: string): [Notation, G.ParseError[]] {\n this.parse(input);\n const notation = new Notation();\n const errors: G.ParseError[] = [];\n errors.push(...this.errors);\n\n // First add the metadata then we can set it\n for (const key in this.metadata) notation.addMetaData(new Meta(key, this.metadata[key]));\n for (const cmd of this.commands) cmd.applyToNotation(notation);\n return [notation, errors];\n }\n\n parseEmbelishment(value: string): [any, boolean] {\n return carnatic.parseEmbelishment(value);\n }\n}\n"]}
package/lib/esm/loader.js CHANGED
@@ -1,16 +1,8 @@
1
1
  import * as TSU from "@panyam/tsutils";
2
2
  import { GlobalBeatLayout } from "./beats";
3
3
  import { Parser } from "./parser";
4
- import { Notation } from "./notation";
5
4
  export function parse(input) {
6
- const notation = new Notation();
7
- const parser = new Parser();
8
- const errors = [];
9
- parser.parse(input);
10
- errors.push(...parser.errors);
11
- for (const cmd of parser.commands)
12
- cmd.applyToNotation(notation);
13
- return [notation, errors];
5
+ return new Parser().parseAndBuild(input);
14
6
  }
15
7
  export function load(codeText, config = {}) {
16
8
  codeText = codeText || "";
@@ -1 +1 @@
1
- {"version":3,"file":"loader.js","sourceRoot":"","sources":["../../src/loader.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,GAAG,MAAM,iBAAiB,CAAC;AAGvC,OAAO,EAAE,gBAAgB,EAAE,MAAM,SAAS,CAAC;AAC3C,OAAO,EAAE,MAAM,EAAE,MAAM,UAAU,CAAC;AAClC,OAAO,EAAE,QAAQ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,OAAO,CAAC,GAAG,CAAC,4BAA4B,SAAS,GAAG,SAAS,mBAAmB,SAAS,GAAG,SAAS,IAAI,CAAC,CAAC;KAC5G;IACD,OAAO;QACL,QAAQ;QACR,UAAU;QACV,MAAM;QACN;YACE,SAAS,EAAE,SAAS,GAAG,SAAS;YAChC,SAAS,EAAE,SAAS,GAAG,SAAS;SACjC;KACF,CAAC;AACJ,CAAC","sourcesContent":["import * as TSU from \"@panyam/tsutils\";\nimport * as G from \"galore\";\nimport { Line } from \"./core\";\nimport { GlobalBeatLayout } from \"./beats\";\nimport { Parser } from \"./parser\";\nimport { Notation } from \"./notation\";\n\nexport function parse(input: string): [Notation, G.ParseError[]] {\n const notation = new Notation();\n const parser = new Parser();\n const errors: G.ParseError[] = [];\n parser.parse(input);\n errors.push(...parser.errors);\n for (const cmd of parser.commands) cmd.applyToNotation(notation);\n return [notation, errors];\n}\n\nexport function load(\n codeText: string,\n config: any = {},\n): [Notation, GlobalBeatLayout, G.ParseError[], TSU.StringMap<number>] {\n codeText = codeText || \"\";\n const beatLayout = new GlobalBeatLayout();\n const startTime = performance.now();\n const [notation, errors] = parse(codeText);\n const parseTime = performance.now();\n\n // Create Line Beats\n for (const block of notation.blocks) {\n if (block.TYPE == \"Line\" && !(block as Line).isEmpty) {\n const line = block as Line;\n // LP should exist by now\n // Probably because this is an empty line and AddAtoms was not called\n TSU.assert(line.layoutParams != null, \"Layout params for a non empty line *SHOULD* exist\");\n beatLayout.addLine(line);\n }\n }\n\n const buildTime = performance.now();\n if (config.log) {\n console.log(`V4 Document, Parse Time: ${parseTime - startTime}ms, Build Time: ${buildTime - parseTime}ms`);\n }\n return [\n notation,\n beatLayout,\n errors,\n {\n parseTime: parseTime - startTime,\n buildTime: buildTime - parseTime,\n },\n ];\n}\n"]}
1
+ {"version":3,"file":"loader.js","sourceRoot":"","sources":["../../src/loader.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,GAAG,MAAM,iBAAiB,CAAC;AAGvC,OAAO,E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@panyam/tsutils\";\nimport * as G from \"galore\";\nimport { Line } from \"./core\";\nimport { GlobalBeatLayout } from \"./beats\";\nimport { Parser } from \"./parser\";\nimport { Notation } from \"./notation\";\n\nexport function parse(input: string): [Notation, G.ParseError[]] {\n return new Parser().parseAndBuild(input);\n}\n\nexport function load(\n codeText: string,\n config: any = {},\n): [Notation, GlobalBeatLayout, G.ParseError[], TSU.StringMap<number>] {\n codeText = codeText || \"\";\n const beatLayout = new GlobalBeatLayout();\n const startTime = performance.now();\n const [notation, errors] = parse(codeText);\n const parseTime = performance.now();\n\n // Create Line Beats\n for (const block of notation.blocks) {\n if (block.TYPE == \"Line\" && !(block as Line).isEmpty) {\n const line = block as Line;\n // LP should exist by now\n // Probably because this is an empty line and AddAtoms was not called\n TSU.assert(line.layoutParams != null, \"Layout params for a non empty line *SHOULD* exist\");\n beatLayout.addLine(line);\n }\n }\n\n const buildTime = performance.now();\n if (config.log) {\n console.log(`V4 Document, Parse Time: ${parseTime - startTime}ms, Build Time: ${buildTime - parseTime}ms`);\n }\n return [\n notation,\n beatLayout,\n errors,\n {\n parseTime: parseTime - startTime,\n buildTime: buildTime - parseTime,\n },\n ];\n}\n"]}
@@ -56,7 +56,7 @@ export declare class Notation extends Entity {
56
56
  addLine(line: Line): void;
57
57
  removeLine(line: Line): number;
58
58
  addRawBlock(raw: RawBlock): void;
59
- addMetaData(meta: MetaData): void;
59
+ addMetaData(meta: MetaData, addBlock?: boolean): void;
60
60
  debugValue(): any;
61
61
  getRoleDef(name: string): TSU.Nullable<RoleDef>;
62
62
  newRoleDef(name: string, notesOnly?: boolean): RoleDef;
@@ -94,8 +94,8 @@ export class Notation extends Entity {
94
94
  this.blocks.push(raw);
95
95
  this.resetLine();
96
96
  }
97
- addMetaData(meta) {
98
- if (!this.metadata.has(meta.key)) {
97
+ addMetaData(meta, addBlock = true) {
98
+ if (addBlock && !this.metadata.has(meta.key)) {
99
99
  const raw = new RawBlock(meta.key, "metadata");
100
100
  this.addRawBlock(ra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G,EAAE,CAAC,KAAK,CAAC;gBAC7B,IAAI,CAAC,UAAU,GAAG,EAAE,CAAC,YAAY,CAAC;gBAClC,IAAI,CAAC,aAAa,GAAG,EAAE,CAAC,UAAU,CAAC;aACpC;YACD,IAAI,CAAC,aAAa,GAAG,EAAE,CAAC;YACxB,IAAI,CAAC,SAAS,EAAE,CAAC;SAClB;QACD,OAAO,IAAI,CAAC,aAAa,CAAC;IAC5B,CAAC;IAES,oBAAoB;QAC5B,OAAO,IAAI,YAAY,CAAC;YACtB,KAAK,EAAE,IAAI,CAAC,YAAY;YACxB,YAAY,EAAE,IAAI,CAAC,UAAU;YAC7B,MAAM,EAAE,IAAI,CAAC,aAAa;SAC3B,CAAC,CAAC;IACL,CAAC;IAMS,uBAAuB;QAC/B,OAAO,CACL,IAAI,CAAC,oBAAoB,CAAC,IAAI,CAAC,CAAC,EAAE,EAAE,EAAE;YACpC,OAAO,CACL,EAAE,CAAC,YAAY,IAAI,IAAI,CAAC,UAAU;gBAClC,IAAI,CAAC,YAAY,CAAC,MAAM,CAAC,EAAE,CAAC,KAAK,CAAC;gBAClC,EAAE,CAAC,eAAe,CAAC,IAAI,CAAC,aAAa,CAAC,CACvC,CAAC;QACJ,CAAC,CAAC,IAAI,IAAI,CACX,CAAC;IACJ,CAAC;CACF","sourcesContent":["import * as TSU from \"@panyam/tsutils\";\nimport { Entity } from \"./entity\";\nimport { Cycle } from \"./cycle\";\nimport { Line } from \"./core\";\nimport { LayoutParams } from \"./layouts\";\n\nexport class RoleDef {\n name = \"\";\n notesOnly = false;\n index = 0;\n}\n\nexport type CmdParam = { key: TSU.Nullable<string>; value: any };\nexport abstract class Command extends Entity {\n // Commands that are auto generated are usually created by other commands\n autoGenerated = false;\n prevSibling: null | Command = null;\n nextSibling: null | Command = null;\n params: CmdParam[];\n index: number;\n\n constructor(params: CmdParam[] = []) {\n super();\n this.params = params;\n this.index = 0;\n this.validateParams();\n }\n\n /**\n * called to validate parameters.\n */\n validateParams(): void {\n //\n }\n\n get name(): string {\n return this.constructor.name;\n }\n\n debugValue(): any {\n return { name: this.name, index: this.index, params: this.params };\n }\n\n getParam(name: string): any {\n for (const param of this.params) {\n if (param.key == name) return param.value;\n }\n return null;\n }\n\n getParamAt(index: number): any {\n return index < this.params.length ? this.params[index].value : null;\n }\n abstract applyToNotation(notebook: Notation): void;\n}\n\nexport class RawBlock extends Entity {\n readonly TYPE: string = \"RawBlock\";\n constructor(public content: string, public contentType: string = \"md\") {\n super();\n }\n\n debugValue(): any {\n return { ...super.debugValue(), content: this.content, contentType: this.contentType };\n }\n}\n\nexport class MetaData {\n constructor(public readonly key: string, public readonly value: string, public readonly params?: any) {\n params = params || {};\n }\n}\n\nexport class Notation extends Entity {\n readonly TYPE = \"Notation\";\n private _unnamedLayoutParams: LayoutParams[] = [];\n private _namedLayoutParams = new Map<string, LayoutParams>();\n private _currRoleDef: TSU.Nullable<RoleDef> = null;\n roles: RoleDef[] = [];\n blocks: (Line | RawBlock)[] = [];\n currentAPB = 1;\n currentCycle: Cycle = Cycle.DEFAULT;\n currentBreaks: number[] = [];\n metadata = new Map<string, MetaData>();\n onMissingRole: (name: string) => RoleDef | null = (name) => this.newRoleDef(name, name == \"sw\");\n\n get unnamedLayoutParams(): ReadonlyArray<LayoutParams> {\n return this._unnamedLayoutParams;\n }\n\n get namedLayoutParams(): ReadonlyMap<string, LayoutParams> {\n return this._namedLayoutParams;\n }\n\n addLine(line: Line): void {\n this.blocks.push(line);\n }\n\n removeLine(line: Line): number {\n const index = this.blocks.findIndex((l) => l == line);\n if (index >= 0) {\n this.blocks.splice(index, 1);\n }\n return index;\n }\n\n addRawBlock(raw: RawBlock): void {\n this.blocks.push(raw);\n this.resetLine();\n }\n\n addMetaData(meta: MetaData): void {\n if (!this.metadata.has(meta.key)) {\n // Add a new raw block here\n // set this by key so even if metadata changes we can\n // get latest value of it\n const raw = new RawBlock(meta.key, \"metadata\");\n this.addRawBlock(raw);\n }\n this.metadata.set(meta.key, meta);\n }\n\n debugValue(): any {\n return {\n ...super.debugValue,\n roles: this.roles,\n blocks: this.blocks.map((b) => b.debugValue()),\n currentAPB: this.currentAPB,\n currentCycle: this.currentCycle?.uuid,\n currentBreaks: this.currentBreaks,\n };\n }\n\n getRoleDef(name: string): TSU.Nullable<RoleDef> {\n name = name.trim().toLowerCase();\n if (name == \"\") {\n return this.roles[this.roles.length - 1] || null;\n }\n for (let i = 0; i < this.roles.length; i++) {\n const rd = this.roles[i];\n if (name == rd.name) return rd;\n }\n return null;\n }\n\n newRoleDef(name: string, notesOnly = false): RoleDef {\n name = name.trim().toLowerCase();\n if (name.trim() == \"\") {\n throw new Error(\"Role name cannot be empty\");\n }\n const roleDef = this.getRoleDef(name);\n if (roleDef != null) {\n throw new Error(\"Role already exists\");\n // roleDef.notesOnly = notesOnly;\n // return roleDef;\n }\n // create new and add\n const rd = new RoleDef();\n rd.name = name;\n rd.notesOnly = notesOnly;\n rd.index = this.roles.length;\n this.roles.push(rd);\n\n return rd;\n }\n\n get currRoleDef(): RoleDef | null {\n if (this._currRoleDef == null) {\n if (this.roles.length == 0) {\n return null;\n } else {\n this._currRoleDef = this.roles[this.roles.length - 1];\n }\n }\n return this._currRoleDef;\n }\n\n setCurrRole(name: string): void {\n name = name.trim().toLowerCase();\n if (name.trim() == \"\") {\n throw new Error(\"Role name cannot be empty\");\n }\n const roleDef = this.getRoleDef(name) || (this.onMissingRole ? this.onMissingRole(name) || null : null);\n if (roleDef == null) {\n throw new Error(\"Role not found: \" + name);\n }\n this._currRoleDef = roleDef;\n }\n\n // Gets the current line, creating it if needed\n private _currentLine: Line | null = null;\n get currentLine(): Line {\n if (this._currentLine == null) {\n return this.newLine();\n }\n return this._currentLine;\n }\n\n resetLine(): void {\n this._currentLine = null;\n }\n\n newLine(): Line {\n if (this._currentLine && this._currentLine.isEmpty) {\n // then remove it first instead of adding another\n // so we dont have a string of empty lines\n this.removeLine(this._currentLine);\n }\n this._currentLine = new Line();\n this.addLine(this._currentLine);\n return this._currentLine;\n }\n\n private _layoutParams: LayoutParams | null = null;\n resetLayoutParams(): void {\n this._layoutParams = null;\n this.resetLine();\n }\n\n get layoutParams(): LayoutParams {\n if (this._layoutParams == null) {\n // create it or find one that matches current params\n this._layoutParams = this.findUnnamedLayoutParams();\n if (this._layoutParams == null) {\n this._layoutParams = this.snapshotLayoutParams();\n this._unnamedLayoutParams.push(this._layoutParams);\n }\n }\n return this._layoutParams;\n }\n\n ensureNamedLayoutParams(name: string): LayoutParams {\n let lp = this._namedLayoutParams.get(name) || null;\n if (lp == null || this._layoutParams != lp) {\n // no change so go ahead\n if (lp == null) {\n // does not exist so create one by re-snapshotting it\n // and saving it\n lp = this.snapshotLayoutParams();\n this._namedLayoutParams.set(name, lp);\n } else {\n // copy named LPs attributes into our locals\n this.currentCycle = lp.cycle;\n this.currentAPB = lp.beatDuration;\n this.currentBreaks = lp.lineBreaks;\n }\n this._layoutParams = lp;\n this.resetLine(); // since layout params have changed\n }\n return this._layoutParams;\n }\n\n protected snapshotLayoutParams(): LayoutParams {\n return new LayoutParams({\n cycle: this.currentCycle,\n beatDuration: this.currentAPB,\n layout: this.currentBreaks,\n });\n }\n\n /**\n * Find a layout params that is currently _unnamed but matches one\n * by current set of layout attributes.\n */\n protected findUnnamedLayoutParams(): LayoutParams | null {\n return (\n this._unnamedLayoutParams.find((lp) => {\n return (\n lp.beatDuration == this.currentAPB &&\n this.currentCycle.equals(lp.cycle) &&\n lp.lineBreaksEqual(this.currentBreaks)\n );\n }) || null\n );\n }\n}\n"]}
1
+ {"version":3,"file":"notation.js","sourceRoot":"","sources":["../../src/notation.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,MAAM,EAAE,MAAM,UAAU,CAAC;AAClC,OAAO,EAAE,KAAK,EAAE,MAAM,SAAS,CAAC;AAChC,OAAO,EAAE,IAAI,EAAE,MAAM,QAAQ,CAAC;AAC9B,OAAO,EAAE,YAAY,EAAE,MAAM,WAAW,CAAC;AAEzC,MAAM,OAAO,OAAO;IA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C;IAES,oBAAoB;QAC5B,OAAO,IAAI,YAAY,CAAC;YACtB,KAAK,EAAE,IAAI,CAAC,YAAY;YACxB,YAAY,EAAE,IAAI,CAAC,UAAU;YAC7B,MAAM,EAAE,IAAI,CAAC,aAAa;SAC3B,CAAC,CAAC;IACL,CAAC;IAMS,uBAAuB;QAC/B,OAAO,CACL,IAAI,CAAC,oBAAoB,CAAC,IAAI,CAAC,CAAC,EAAE,EAAE,EAAE;YACpC,OAAO,CACL,EAAE,CAAC,YAAY,IAAI,IAAI,CAAC,UAAU;gBAClC,IAAI,CAAC,YAAY,CAAC,MAAM,CAAC,EAAE,CAAC,KAAK,CAAC;gBAClC,EAAE,CAAC,eAAe,CAAC,IAAI,CAAC,aAAa,CAAC,CACvC,CAAC;QACJ,CAAC,CAAC,IAAI,IAAI,CACX,CAAC;IACJ,CAAC;CACF","sourcesContent":["import * as TSU from \"@panyam/tsutils\";\nimport { Entity } from \"./entity\";\nimport { Cycle } from \"./cycle\";\nimport { Line } from \"./core\";\nimport { LayoutParams } from \"./layouts\";\n\nexport class RoleDef {\n name = \"\";\n notesOnly = false;\n index = 0;\n}\n\nexport type CmdParam = { key: TSU.Nullable<string>; value: any };\nexport abstract class Command extends Entity {\n // Commands that are auto generated are usually created by other commands\n autoGenerated = false;\n prevSibling: null | Command = null;\n nextSibling: null | Command = null;\n params: CmdParam[];\n index: number;\n\n constructor(params: CmdParam[] = []) {\n super();\n this.params = params;\n this.index = 0;\n this.validateParams();\n }\n\n /**\n * called to validate parameters.\n */\n validateParams(): void {\n //\n }\n\n get name(): string {\n return this.constructor.name;\n }\n\n debugValue(): any {\n return { name: this.name, index: this.index, params: this.params };\n }\n\n getParam(name: string): any {\n for (const param of this.params) {\n if (param.key == name) return param.value;\n }\n return null;\n }\n\n getParamAt(index: number): any {\n return index < this.params.length ? this.params[index].value : null;\n }\n abstract applyToNotation(notebook: Notation): void;\n}\n\nexport class RawBlock extends Entity {\n readonly TYPE: string = \"RawBlock\";\n constructor(public content: string, public contentType: string = \"md\") {\n super();\n }\n\n debugValue(): any {\n return { ...super.debugValue(), content: this.content, contentType: this.contentType };\n }\n}\n\nexport class MetaData {\n constructor(public readonly key: string, public readonly value: string, public readonly params?: any) {\n params = params || {};\n }\n}\n\nexport class Notation extends Entity {\n readonly TYPE = \"Notation\";\n private _unnamedLayoutParams: LayoutParams[] = [];\n private _namedLayoutParams = new Map<string, LayoutParams>();\n private _currRoleDef: TSU.Nullable<RoleDef> = null;\n roles: RoleDef[] = [];\n blocks: (Line | RawBlock)[] = [];\n currentAPB = 1;\n currentCycle: Cycle = Cycle.DEFAULT;\n currentBreaks: number[] = [];\n metadata = new Map<string, MetaData>();\n onMissingRole: (name: string) => RoleDef | null = (name) => this.newRoleDef(name, name == \"sw\");\n\n get unnamedLayoutParams(): ReadonlyArray<LayoutParams> {\n return this._unnamedLayoutParams;\n }\n\n get namedLayoutParams(): ReadonlyMap<string, LayoutParams> {\n return this._namedLayoutParams;\n }\n\n addLine(line: Line): void {\n this.blocks.push(line);\n }\n\n removeLine(line: Line): number {\n const index = this.blocks.findIndex((l) => l == line);\n if (index >= 0) {\n this.blocks.splice(index, 1);\n }\n return index;\n }\n\n addRawBlock(raw: RawBlock): void {\n this.blocks.push(raw);\n this.resetLine();\n }\n\n addMetaData(meta: MetaData, addBlock = true): void {\n if (addBlock && !this.metadata.has(meta.key)) {\n // Add a new raw block here\n // set this by key so even if metadata changes we can\n // get latest value of it\n const raw = new RawBlock(meta.key, \"metadata\");\n this.addRawBlock(raw);\n }\n this.metadata.set(meta.key, meta);\n }\n\n debugValue(): any {\n return {\n ...super.debugValue,\n roles: this.roles,\n blocks: this.blocks.map((b) => b.debugValue()),\n currentAPB: this.currentAPB,\n currentCycle: this.currentCycle?.uuid,\n currentBreaks: this.currentBreaks,\n };\n }\n\n getRoleDef(name: string): TSU.Nullable<RoleDef> {\n name = name.trim().toLowerCase();\n if (name == \"\") {\n return this.roles[this.roles.length - 1] || null;\n }\n for (let i = 0; i < this.roles.length; i++) {\n const rd = this.roles[i];\n if (name == rd.name) return rd;\n }\n return null;\n }\n\n newRoleDef(name: string, notesOnly = false): RoleDef {\n name = name.trim().toLowerCase();\n if (name.trim() == \"\") {\n throw new Error(\"Role name cannot be empty\");\n }\n const roleDef = this.getRoleDef(name);\n if (roleDef != null) {\n throw new Error(\"Role already exists\");\n // roleDef.notesOnly = notesOnly;\n // return roleDef;\n }\n // create new and add\n const rd = new RoleDef();\n rd.name = name;\n rd.notesOnly = notesOnly;\n rd.index = this.roles.length;\n this.roles.push(rd);\n\n return rd;\n }\n\n get currRoleDef(): RoleDef | null {\n if (this._currRoleDef == null) {\n if (this.roles.length == 0) {\n return null;\n } else {\n this._currRoleDef = this.roles[this.roles.length - 1];\n }\n }\n return this._currRoleDef;\n }\n\n setCurrRole(name: string): void {\n name = name.trim().toLowerCase();\n if (name.trim() == \"\") {\n throw new Error(\"Role name cannot be empty\");\n }\n const roleDef = this.getRoleDef(name) || (this.onMissingRole ? this.onMissingRole(name) || null : null);\n if (roleDef == null) {\n throw new Error(\"Role not found: \" + name);\n }\n this._currRoleDef = roleDef;\n }\n\n // Gets the current line, creating it if needed\n private _currentLine: Line | null = null;\n get currentLine(): Line {\n if (this._currentLine == null) {\n return this.newLine();\n }\n return this._currentLine;\n }\n\n resetLine(): void {\n this._currentLine = null;\n }\n\n newLine(): Line {\n if (this._currentLine && this._currentLine.isEmpty) {\n // then remove it first instead of adding another\n // so we dont have a string of empty lines\n this.removeLine(this._currentLine);\n }\n this._currentLine = new Line();\n this.addLine(this._currentLine);\n return this._currentLine;\n }\n\n private _layoutParams: LayoutParams | null = null;\n resetLayoutParams(): void {\n this._layoutParams = null;\n this.resetLine();\n }\n\n get layoutParams(): LayoutParams {\n if (this._layoutParams == null) {\n // create it or find one that matches current params\n this._layoutParams = this.findUnnamedLayoutParams();\n if (this._layoutParams == null) {\n this._layoutParams = this.snapshotLayoutParams();\n this._unnamedLayoutParams.push(this._layoutParams);\n }\n }\n return this._layoutParams;\n }\n\n ensureNamedLayoutParams(name: string): LayoutParams {\n let lp = this._namedLayoutParams.get(name) || null;\n if (lp == null || this._layoutParams != lp) {\n // no change so go ahead\n if (lp == null) {\n // does not exist so create one by re-snapshotting it\n // and saving it\n lp = this.snapshotLayoutParams();\n this._namedLayoutParams.set(name, lp);\n } else {\n // copy named LPs attributes into our locals\n this.currentCycle = lp.cycle;\n this.currentAPB = lp.beatDuration;\n this.currentBreaks = lp.lineBreaks;\n }\n this._layoutParams = lp;\n this.resetLine(); // since layout params have changed\n }\n return this._layoutParams;\n }\n\n protected snapshotLayoutParams(): LayoutParams {\n return new LayoutParams({\n cycle: this.currentCycle,\n beatDuration: this.currentAPB,\n layout: this.currentBreaks,\n });\n }\n\n /**\n * Find a layout params that is currently _unnamed but matches one\n * by current set of layout attributes.\n */\n protected findUnnamedLayoutParams(): LayoutParams | null {\n return (\n this._unnamedLayoutParams.find((lp) => {\n return (\n lp.beatDuration == this.currentAPB &&\n this.currentCycle.equals(lp.cycle) &&\n lp.lineBreaksEqual(this.currentBreaks)\n );\n }) || null\n );\n }\n}\n"]}
@@ -2,11 +2,11 @@ import * as TSU from "@panyam/tsutils";
2
2
  import * as G from "galore";
3
3
  import * as TLEX from "tlex";
4
4
  import { Literal, Note, Atom, Rest, Space, Group } from "./core";
5
- import { Command, CmdParam } from "./notation";
5
+ import { Notation, Command, CmdParam } from "./notation";
6
6
  export declare class Parser {
7
7
  errors: (TLEX.TokenizerError | G.ParseError)[];
8
+ metadata: any;
8
9
  readonly commands: Command[];
9
- private runCommandFound;
10
10
  protected ruleHandlers: {
11
11
  newFraction: (rule: G.Rule, parent: G.PTNode, ...children: G.PTNode[]) => TSU.Num.Fraction;
12
12
  newGroup: (rule: G.Rule, parent: G.PTNode, ...children: G.PTNode[]) => Group;
@@ -31,6 +31,7 @@ export declare class Parser {
31
31
  concatParamList: (rule: G.Rule, parent: G.PTNode, ...children: G.PTNode[]) => any;
32
32
  newCommand: (rule: G.Rule, parent: G.PTNode, ...children: G.PTNode[]) => Command;
33
33
  appendAtoms: (rule: G.Rule, parent: G.PTNode, ...children: G.PTNode[]) => null;
34
+ prependFrontMatter: (rule: G.Rule, parent: G.PTNode, ...children: G.PTNode[]) => any;
34
35
  appendCommand: (rule: G.Rule, parent: G.PTNode, ...children: G.PTNode[]) => null;
35
36
  appendRoleSelector: (rule: G.Rule, parent: G.PTNode, ...children: G.PTNode[]) => null;
36
37
  insertEmbedding: (rule: G.Rule, parent: G.PTNode, ...children: G.PTNode[]) => null;
@@ -39,5 +40,6 @@ export declare class Parser {
39
40
  createCommand(name: string, params: CmdParam[]): Command;
40
41
  addCommand(cmd: Command): void;
41
42
  parse(input: string): any;
43
+ parseAndBuild(input: string): [Notation, G.ParseError[]];
42
44
  parseEmbelishment(value: string): [any, boolean];
43
45
  }
package/lib/esm/parser.js CHANGED
@@ -1,12 +1,14 @@
1
1
  import * as TSU from "@panyam/tsutils";
2
2
  import * as G from "galore";
3
3
  import * as TLEX from "tlex";
4
+ import matter from "gray-matter";
4
5
  import { Literal, AtomType, Note, Rest, Space, Syllable, Group, Marker } from "./core";
6
+ import { Notation, MetaData as Meta } from "./notation";
5
7
  import { RawEmbedding, ApplyLayout, AddAtoms, SetCycle, SetBeatDuration, SetBreaks, ActivateRole, CreateRole, CreateLine, MetaData, } from "./commands";
6
8
  import * as carnatic from "./carnatic";
7
9
  const ONE = TSU.Num.Fraction.ONE;
8
10
  const TWO = ONE.timesNum(2);
9
- const [parser, itemGraph] = G.newParser(String.raw `
11
+ const [parser] = G.newParser(String.raw `
10
12
  %define IdentChar /[^%!@$#&\^|\[\]={}()<>+\-,;~: \t\f\r\n\v\\\.\'\"]/
11
13
 
12
14
  %token BSLASH "\\"
@@ -25,6 +27,7 @@ const [parser, itemGraph] = G.newParser(String.raw `
25
27
  %token SEMI_COLON ";"
26
28
  %token COLON ":"
27
29
 
30
+ %token FRONT_MATTER /^---$/m { toFrontMatter }
28
31
  %token SINGLE_LINE_RAW_STRING />(.*)$/m { toSingleLineRawString }
29
32
  %token MULTI_LINE_RAW_STRING /r(#{0,})"/ { toMultiLineRawString }
30
33
 
@@ -48,6 +51,10 @@ const [parser, itemGraph] = G.newParser(String.raw `
48
51
  %skip_flex "//.*$"
49
52
  %skip /\/\*.*?\*\//
50
53
 
54
+ Document -> Elements
55
+ | FRONT_MATTER Elements { prependFrontMatter }
56
+ ;
57
+
51
58
  Elements -> Elements Command Atoms { appendCommand }
52
59
  | Elements RoleSelector Atoms { appendRoleSelector }
53
60
  | Elements Embedding Atoms { insertEmbedding }
@@ -192,13 +199,23 @@ const [parser, itemGraph] = G.newParser(String.raw `
192
199
  token.value = tape.substring(startPos, endPos);
193
200
  return token;
194
201
  },
202
+ toFrontMatter: (token, tape, owner) => {
203
+ const endPat = "\n---";
204
+ const startPos = tape.index;
205
+ const endPos = TLEX.TapeHelper.advanceAfter(tape, endPat) - endPat.length;
206
+ if (endPos < 0) {
207
+ throw new Error("EOF expected while finding end of front matter");
208
+ }
209
+ token.value = tape.substring(startPos, endPos);
210
+ return token;
211
+ },
195
212
  },
196
213
  });
197
214
  export class Parser {
198
215
  constructor(config) {
199
216
  this.errors = [];
217
+ this.metadata = {};
200
218
  this.commands = [];
201
- this.runCommandFound = false;
202
219
  this.ruleHandlers = {
203
220
  newFraction: (rule, parent, ...children) => {
204
221
  if (children.length == 1) {
@@ -326,6 +343,13 @@ export class Parser {
326
343
  }
327
344
  return null;
328
345
  },
346
+ prependFrontMatter: (rule, parent, ...children) => {
347
+ const fm = children[0].value;
348
+ const { data } = matter("---\n" + fm + "\n---");
349
+ console.log("Parsed FM: ", data);
350
+ this.metadata = data;
351
+ return children[1].value;
352
+ },
329
353
  appendCommand: (rule, parent, ...children) => {
330
354
  const command = children[1].value;
331
355
  this.addCommand(command);
@@ -412,6 +436,17 @@ export class Parser {
412
436
  }
413
437
  return null;
414
438
  }
439
+ parseAndBuild(input) {
440
+ this.parse(input);
441
+ const notation = new Notation();
442
+ const errors = [];
443
+ errors.push(...this.errors);
444
+ for (const key in this.metadata)
445
+ notation.addMetaData(new Meta(key, this.metadata[key]));
446
+ for (const cmd of this.commands)
447
+ cmd.applyToNotation(notation);
448
+ return [notation, errors];
449
+ }
415
450
  parseEmbelishment(value) {
416
451
  return carnatic.parseEmbelishment(value);
417
452
  }
@@ -1 +1 @@
1
- {"version":3,"file":"parser.js","sourceRoot":"","sources":["../../src/parser.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,GAAG,MAAM,iBAAiB,CAAC;AACvC,OAAO,KAAK,CAAC,MAAM,QAAQ,CAAC;AAC5B,OAAO,KAAK,IAAI,MAAM,MAAM,CAAC;AAC7B,OAAO,EAAE,OAAO,EAAE,QAAQ,EAAE,IAAI,EAAQ,IAAI,EAAE,KAAK,EAAE,QAAQ,EAAE,KAAK,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAC;AAE7F,OAAO,EACL,YAAY,EACZ,WAAW,EACX,QAAQ,EACR,QAAQ,EACR,eAAe,EACf,SAAS,EACT,YAAY,EACZ,UAAU,EACV,UAAU,EACV,QAAQ,GACT,MAAM,YAAY,CAAC;AAGpB,OAAO,KAAK,QAAQ,MAAM,YAAY,CAAC;AAEvC,MAAM,GAAG,GAAG,GAAG,CAAC,GAAG,CAAC,QAAQ,CAAC,GAAG,CAAC;AACjC,MAAM,GAAG,GAAG,GAAG,CAAC,QAAQ,CAAC,CAAC,CAAC,CAAC;AAW5B,MAAM,CAAC,MAAM,EAAE,SAAS,CAAC,GAAG,CAAC,CAAC,SAAS,CACrC,MAAM,CAAC,GAAG,CAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;KAwGP,EACH;IACE,kBAAkB,EAAE,IAAI;IACxB,KAAK,EAAE,EAAE;IACT,IAAI,EAAE,MAAM;IACZ,aAAa,EAAE;QACb,cAAc,EAAE,CAAC,KAAiB,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;QACjB,IAAI;YACF,MAAM,KAAK,GAAG,MAAM,CAAC,KAAK,CAAC,KAAK,EAAE;gBAChC,gBAAgB,EAAE,IAAI;gBACtB,YAAY,EAAE,IAAI,CAAC,YAAY;gBAC/B,YAAY,EAAE,CAAC,GAAwB,EAAE,EAAE;oBACzC,IAAI,CAAC,MAAM,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;oBACtB,OAAO,IAAI,CAAC;gBACd,CAAC;aACF,CAAC,CAAC;YACH,OAAO,KAAK,CAAC;SACd;QAAC,OAAO,GAAG,EAAE;YACZ,IAAI,GAAG,YAAY,CAAC,CAAC,UAAU,EAAE;gBAC/B,IAAI,CAAC,MAAM,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;aACvB;iBAAM;gBACL,MAAM,GAAG,CAAC;aACX;SACF;QACD,OAAO,IAAI,CAAC;IACd,CAAC;IAED,iBAAiB,CAAC,KAAa;QAC7B,OAAO,QAAQ,CAAC,iBAAiB,CAAC,KAAK,CAAC,CAAC;IAC3C,CAAC;CACF","sourcesContent":["import * as TSU from \"@panyam/tsutils\";\nimport * as G from \"galore\";\nimport * as TLEX from \"tlex\";\nimport { Literal, AtomType, Note, Atom, Rest, Space, Syllable, Group, Marker } from \"./core\";\nimport { Command, CmdParam } from \"./notation\";\nimport {\n RawEmbedding,\n ApplyLayout,\n AddAtoms,\n SetCycle,\n SetBeatDuration,\n SetBreaks,\n ActivateRole,\n CreateRole,\n CreateLine,\n MetaData,\n} from \"./commands\";\n\n// TODO - Make this plugable from the client instead of hard coded\nimport * as carnatic from \"./carnatic\";\n\nconst ONE = TSU.Num.Fraction.ONE;\nconst TWO = ONE.timesNum(2);\n\n/**\n * V4 of our parser builds on V3 and has the following improvements:\n *\n * 1. Embedding Headings to demarcate sections so users dont have to use\n * explicit MD for headings.\n * 2. Unlike V3 here users break out *of* song instead instead break out \"into\"\n * song. So users spend more time writing notation and less worrying about\n * other things like headings etc.\n */\nconst [parser, itemGraph] = G.newParser(\n String.raw`\n %define IdentChar /[^%!@$#&\\^|\\[\\]={}()<>+\\-,;~: \\t\\f\\r\\n\\v\\\\\\.\\'\\\"]/\n\n %token BSLASH \"\\\\\"\n %token OPEN_SQ \"[\"\n %token CLOSE_SQ \"]\"\n %token EQUALS \"=\"\n %token OPEN_PAREN \"(\"\n %token CLOSE_PAREN \")\"\n %token OPEN_BRACE \"{\"\n %token CLOSE_BRACE \"}\"\n %token SLASH \"/\"\n %token STAR \"*\"\n %token CARET \"^\"\n // %skip \"-\"\n %token COMMA \",\"\n %token SEMI_COLON \";\"\n %token COLON \":\"\n\n %token SINGLE_LINE_RAW_STRING />(.*)$/m { toSingleLineRawString }\n %token MULTI_LINE_RAW_STRING /r(#{0,})\"/ { toMultiLineRawString }\n\n %token EMBELISHMENT /~[^\\s]*/ { toEmbelishment }\n %token NUMBER /-?\\d+/ { toNumber }\n %token BOOLEAN /true|false/ { toBoolean }\n %token POST_MARKER /<<\"(([^\"\\\\\\n]|\\\\.|\\\\\\n)*)\"/ { toMarker }\n %token POST_MARKER /<<'(([^'\\\\\\n]|\\\\.|\\\\\\n)*)'/ { toMarker }\n %token PRE_MARKER /\"(([^\"\\\\\\n]|\\\\.|\\\\\\n)*)\">>/ { toMarker }\n %token PRE_MARKER /'(([^'\\\\\\n]|\\\\.|\\\\\\n)*)'>>/ { toMarker }\n %token STRING /\"([^\"\\\\\\n]|\\\\.|\\\\\\n)*\"/ { toString }\n %token STRING /'([^'\\\\\\n]|\\\\.|\\\\\\n)*'/ { toString }\n %token DOTS_IDENT /(\\.+)({IdentChar}+)/ { toOctavedNote }\n %token IDENT_DOTS /({IdentChar}+)(\\.+)/ { toOctavedNote }\n %token IDENT_COLON /{IdentChar}+:/ { toRoleSelector }\n %token IDENT /{IdentChar}+/\n %token BSLASH_IDENT /\\\\{IDENT}/ { toCommandName }\n %token BSLASH_NUMBER /\\\\{NUMBER}/\n %token HYPHEN /-/\n %skip /[ \\t\\n\\f\\r]+/\n %skip_flex \"//.*$\"\n %skip /\\/\\*.*?\\*\\//\n\n Elements -> Elements Command Atoms { appendCommand } \n | Elements RoleSelector Atoms { appendRoleSelector } \n | Elements Embedding Atoms { insertEmbedding }\n | Atoms { appendAtoms }\n ;\n\n Embedding -> SINGLE_LINE_RAW_STRING | MULTI_LINE_RAW_STRING ;\n\n Command -> BSLASH_IDENT CommandParams ? { newCommand } ;\n CommandParams -> OPEN_PAREN ParamList ? CLOSE_PAREN { $2 } ;\n\n ParamList -> ParamList COMMA Param { concatParamList } ;\n ParamList -> Param { newParamList };\n Param -> ParamValue { newParam } ;\n Param -> ParamKey EQUALS ParamValue { newParam } ;\n ParamKey -> IDENT ;\n ParamValue -> ( STRING | Fraction | NUMBER | BOOLEAN ) ;\n\n RoleSelector -> IDENT_COLON ;\n\n Atoms -> Atoms Atom { concatAtoms } ;\n Atoms -> { newArray } ;\n\n Atom -> Atom POST_MARKER { applyPostMarker }\n | PreMarkedAtom\n ;\n PreMarkedAtom -> Leaf\n | PRE_MARKER PreMarkedAtom { applyPreMarker }\n ;\n\n Leaf -> Space | Lit | Group | Rest ;\n Leaf -> Duration Leaf { applyDuration } ;\n Rest -> HYPHEN { newRest };\n Space -> COMMA { newSpace } \n | SEMI_COLON { newDoubleSpace } \n | UNDER_SCORE { newSilentSpace } \n ;\n\n /* - An alternative representation to support both pre and\n * post embelishment operators. Here PRE_EMBs have a higher\n * associativity over POST_EMBs\n */\n Lit -> Lit POST_EMB { litWithPostEmb }\n | PreEmbLit\n ;\n\n PreEmbLit -> LitToken \n | LitToken CARET NUMBER { litWithCaret }\n | LitToken CARET STAR { litWithCaret }\n | PRE_EMB PreEmbLit { litWithPreEmb }\n ;\n \n LitToken -> DOTS_IDENT { litToAtom }\n | IDENT { litToAtom }\n | IDENT_DOTS { litToAtom }\n | STRING { litToAtom }\n ;\n\n Group -> OPEN_SQ Atoms CLOSE_SQ { newGroup };\n\n Duration -> Fraction | NUMBER;\n Fraction -> NUMBER SLASH NUMBER { newFraction } ;\n `,\n {\n allowLeftRecursion: true,\n debug: \"\",\n type: \"lalr\",\n tokenHandlers: {\n toEmbelishment: (token: TLEX.Token, tape: TLEX.Tape, owner: Parser) => {\n const [emb, pre] = owner.parseEmbelishment(token.value);\n if (emb == null) {\n console.log(\"Skipping Embelishment: \", token.value);\n owner.errors.push(\n new TLEX.TokenizerError(\n `Invalid embelishment: ${token.value}`,\n token.start,\n 1 + token.end - token.start,\n \"InvalidEmbelishment\",\n token.value,\n ),\n );\n return null;\n }\n token.value = emb;\n token.tag = pre ? \"PRE_EMB\" : \"POST_EMB\";\n return token;\n },\n toCommandName: (token: TLEX.Token, tape: TLEX.Tape, owner: any) => {\n token.value = token.value.substring(1);\n return token;\n },\n toBoolean: (token: TLEX.Token, tape: TLEX.Tape, owner: any) => {\n token.value = token.value == \"true\";\n return token;\n },\n toNumber: (token: TLEX.Token, tape: TLEX.Tape, owner: any) => {\n token.value = parseInt(token.value);\n return token;\n },\n toString: (token: TLEX.Token, tape: TLEX.Tape, owner: any) => {\n token.value = token.value.substring(1, token.value.length - 1);\n return token;\n },\n toMarker: (token: TLEX.Token, tape: TLEX.Tape, owner: any) => {\n if (token.tag != \"PRE_MARKER\" && token.tag != \"POST_MARKER\") {\n throw new Error(\"Invalid token for converting to note: \" + token.tag);\n }\n const isBefore = token.tag == \"PRE_MARKER\";\n const markerText = isBefore\n ? token.value.substring(1, token.value.length - 3)\n : token.value.substring(3, token.value.length - 1);\n // console.log(\"TokVal: \", token.value, token.positions);\n // console.log(\"Marker Text: \", markerText, isBefore);\n token.value = new Marker(markerText, isBefore);\n return token;\n },\n toOctavedNote: (token: TLEX.Token, tape: TLEX.Tape, owner: any) => {\n if (token.tag == \"DOTS_IDENT\") {\n const octave = token.positions[1][1] - token.positions[1][0];\n const note = token.value.substring(octave);\n token.value = new Note(note, ONE, -octave);\n } else if (token.tag == \"IDENT_DOTS\") {\n const octave = token.positions[2][1] - token.positions[2][0];\n const note = token.value.substring(0, token.value.length - octave);\n token.value = new Note(note, ONE, octave);\n } else {\n throw new Error(\"Invalid token for converting to note: \" + token.tag);\n }\n return token;\n },\n toRoleSelector: (token: TLEX.Token, tape: TLEX.Tape, owner: any) => {\n token.value = token.value.substring(0, token.value.length - 1);\n return token;\n },\n toLineAnnotation: (token: TLEX.Token, tape: TLEX.Tape, owner: any) => {\n // skip the initial \"!\"\n token.value = token.value.substring(1);\n return token;\n },\n toSingleLineRawString: (token: TLEX.Token, tape: TLEX.Tape, owner: any) => {\n // skip the initial \">\"\n token.value = token.value.substring(1);\n return token;\n },\n toMultiLineRawString: (token: TLEX.Token, tape: TLEX.Tape, owner: any) => {\n // consume everything until \"#<N times> as start\n const hashes = tape.substring(token.positions[1][0], token.positions[1][1]);\n const endPat = '\"' + hashes;\n const startPos = tape.index;\n const endPos = TLEX.TapeHelper.advanceAfter(tape, endPat) - endPat.length;\n if (endPos < 0) {\n throw new Error(\"EOF expected while finding end of Raw String Literal: '\" + endPat + \"'\");\n }\n token.value = tape.substring(startPos, endPos);\n return token;\n },\n },\n },\n);\n\n/**\n * A notation doc is a list of lines that are found in a single document.\n *\n * Since our document (md or html etc) can contain multiple snippets\n * all these snippets are related\n */\nexport class Parser {\n errors: (TLEX.TokenizerError | G.ParseError)[] = [];\n readonly commands: Command[] = [];\n // readonly notation: Notation = new Notation();\n private runCommandFound = false;\n // readonly parseTree = new PTNodeList(\"Snippet\", null);\n\n protected ruleHandlers = {\n newFraction: (rule: G.Rule, parent: G.PTNode, ...children: G.PTNode[]) => {\n if (children.length == 1) {\n return new TSU.Num.Fraction(children[0].value);\n } else {\n return new TSU.Num.Fraction(children[0].value, children[2].value);\n }\n },\n newGroup: (rule: G.Rule, parent: G.PTNode, ...children: G.PTNode[]) => {\n const out = new Group(...children[1].value).setDuration(TWO, true);\n return out;\n },\n litWithCaret: (rule: G.Rule, parent: G.PTNode, ...children: G.PTNode[]) => {\n const lit = Note.fromLit(children[0].value as Literal);\n const opnode = children[2];\n const shiftValue = opnode.sym.label == \"STAR\" ? true : opnode.value;\n lit.shift = shiftValue;\n return lit;\n },\n litWithPreEmb: (rule: G.Rule, parent: G.PTNode, ...children: G.PTNode[]) => {\n const emb = children[0];\n const lit = children[1].value as Literal;\n lit.embelishments.splice(0, 0, emb.value);\n return lit;\n },\n litWithPostEmb: (rule: G.Rule, parent: G.PTNode, ...children: G.PTNode[]) => {\n const lit = children[0].value as Literal;\n const emb = children[1];\n lit.embelishments.push(emb);\n return lit;\n },\n litToAtom: (rule: G.Rule, parent: G.PTNode, ...children: G.PTNode[]) => {\n const lit = children[0];\n if (lit.sym.label == \"DOTS_IDENT\" || lit.sym.label == \"IDENT_DOTS\") {\n return lit.value;\n } else if (lit.sym.label == \"IDENT\") {\n // Mark this as a Literal to be processed later\n return new Literal(lit.value);\n // return role.notesOnly ? new Note(lit.value) : new Syllable(lit.value);\n } else if (lit.sym.label == \"STRING\") {\n // const role = this.snippet.currRole;\n // if (role.notesOnly) throw new Error(\"Strings cannot appear in notes only mode\");\n return new Syllable(lit.value);\n } else {\n throw new Error(\"Invalid lit: \" + lit);\n }\n },\n newSpace: (rule: G.Rule, parent: G.PTNode, ...children: G.PTNode[]) => {\n return new Space();\n },\n newRest: (rule: G.Rule, parent: G.PTNode, ...children: G.PTNode[]) => {\n return new Rest();\n },\n newDoubleSpace: (rule: G.Rule, parent: G.PTNode, ...children: G.PTNode[]) => {\n return new Space(ONE.timesNum(2));\n },\n newSilentSpace: (rule: G.Rule, parent: G.PTNode, ...children: G.PTNode[]) => {\n return new Space(ONE, true);\n },\n applyPreMarker: (rule: G.Rule, parent: G.PTNode, ...children: G.PTNode[]) => {\n const marker = children[0].value as Marker;\n const leaf = children[1].value as Atom;\n // console.log(\"marker, leaf: \", marker, leaf);\n if (!leaf.markersBefore) {\n leaf.markersBefore = [];\n }\n leaf.markersBefore.splice(0, 0, marker);\n return leaf;\n },\n applyPostMarker: (rule: G.Rule, parent: G.PTNode, ...children: G.PTNode[]) => {\n const leaf = children[0].value as Atom;\n const marker = children[1].value as Marker;\n if (!leaf.markersAfter) {\n leaf.markersAfter = [];\n }\n leaf.markersAfter.push(marker);\n return leaf;\n },\n applyDuration: (rule: G.Rule, parent: G.PTNode, ...children: G.PTNode[]) => {\n let dur = children[0].value as TSU.Num.Fraction | number;\n const leaf = children[1].value as Atom;\n if (typeof dur === \"number\") {\n dur = ONE.timesNum(dur);\n }\n if (leaf.TYPE == AtomType.GROUP) {\n (leaf as Group).setDuration(dur, true);\n } else {\n leaf.duration = dur;\n }\n return leaf;\n },\n newArray: (rule: G.Rule, parent: G.PTNode, ...children: G.PTNode[]) => {\n // create an array of values from all the values of child nodes\n return children.map((c) => c.value);\n },\n concatAtoms: (rule: G.Rule, parent: G.PTNode, ...children: G.PTNode[]) => {\n const atoms = children[0].value;\n const atom = children[1].value;\n atoms.push(atom);\n return atoms;\n },\n newParam: (rule: G.Rule, parent: G.PTNode, ...children: G.PTNode[]) => {\n if (children.length == 1) {\n return { key: null, value: children[0].value };\n } else {\n return { key: children[0].value, value: children[2].value };\n }\n },\n newParamList: (rule: G.Rule, parent: G.PTNode, ...children: G.PTNode[]) => {\n return [children[0].value];\n },\n concatParamList: (rule: G.Rule, parent: G.PTNode, ...children: G.PTNode[]) => {\n const params = children[0].value;\n const newParam = children[2].value;\n params.push(newParam);\n return params;\n },\n newCommand: (rule: G.Rule, parent: G.PTNode, ...children: G.PTNode[]) => {\n return this.createCommand(children[0].value, children[1].value);\n },\n appendAtoms: (rule: G.Rule, parent: G.PTNode, ...children: G.PTNode[]) => {\n const atoms = children[0].value as Atom[];\n if (atoms.length > 0) {\n this.addCommand(new AddAtoms(...atoms));\n }\n return null;\n },\n appendCommand: (rule: G.Rule, parent: G.PTNode, ...children: G.PTNode[]) => {\n const command = children[1].value as Command;\n this.addCommand(command);\n\n const atoms = children[2].value as Atom[];\n if (atoms.length > 0) {\n this.addCommand(new AddAtoms(...atoms));\n }\n return null;\n },\n appendRoleSelector: (rule: G.Rule, parent: G.PTNode, ...children: G.PTNode[]) => {\n const roleName = children[1].value;\n const lName = roleName.toLowerCase().trim();\n this.addCommand(new ActivateRole([{ key: null, value: lName }]));\n\n const atoms = children[2].value as Atom[];\n if (atoms.length > 0) {\n this.addCommand(new AddAtoms(...atoms));\n }\n return null;\n },\n insertEmbedding: (rule: G.Rule, parent: G.PTNode, ...children: G.PTNode[]) => {\n // How to handle embeddings - these are just blocks\n // to escape out of song (most likely for some rendering of html/md etc)\n const rawVal = children[1].value;\n this.addCommand(new RawEmbedding([{ key: null, value: rawVal }]));\n const atoms = children[2].value as Atom[];\n if (atoms.length > 0) {\n this.addCommand(new AddAtoms(...atoms));\n }\n return null;\n },\n };\n\n constructor(config?: any) {\n config = config || {};\n }\n\n createCommand(name: string, params: CmdParam[]): Command {\n const lName = name.trim().toLowerCase();\n params = params || [];\n if (lName == \"line\") {\n return new CreateLine(params);\n } else if (lName == \"meta\") {\n return new MetaData(params);\n } else if (lName == \"role\") {\n return new CreateRole(params);\n } else if (lName == \"layout\") {\n return new ApplyLayout(params);\n } else if (lName == \"beatduration\") {\n return new SetBeatDuration(params);\n } else if (lName == \"breaks\") {\n return new SetBreaks(params);\n } else if (lName == \"cycle\") {\n return new SetCycle(params);\n } else {\n // Try to set this as the current role\n throw new Error(\"Invalid command: \" + lName);\n }\n }\n\n addCommand(cmd: Command): void {\n cmd.index = this.commands.length;\n this.commands.push(cmd);\n }\n\n parse(input: string): any {\n this.errors = [];\n try {\n const ptree = parser.parse(input, {\n tokenizerContext: this,\n ruleHandlers: this.ruleHandlers,\n onTokenError: (err: TLEX.TokenizerError) => {\n this.errors.push(err);\n return true;\n },\n });\n return ptree;\n } catch (err) {\n if (err instanceof G.ParseError) {\n this.errors.push(err);\n } else {\n throw err;\n }\n }\n return null;\n }\n\n parseEmbelishment(value: string): [any, boolean] {\n return carnatic.parseEmbelishment(value);\n }\n}\n"]}
1
+ {"version":3,"file":"parser.js","sourceRoot":"","sources":["../../src/parser.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,GAAG,MA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;IACd,CAAC;IAED,aAAa,CAAC,KAAa;QACzB,IAAI,CAAC,KAAK,CAAC,KAAK,CAAC,CAAC;QAClB,MAAM,QAAQ,GAAG,IAAI,QAAQ,EAAE,CAAC;QAChC,MAAM,MAAM,GAAmB,EAAE,CAAC;QAClC,MAAM,CAAC,IAAI,CAAC,GAAG,IAAI,CAAC,MAAM,CAAC,CAAC;QAG5B,KAAK,MAAM,GAAG,IAAI,IAAI,CAAC,QAAQ;YAAE,QAAQ,CAAC,WAAW,CAAC,IAAI,IAAI,CAAC,GAAG,EAAE,IAAI,CAAC,QAAQ,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC;QACzF,KAAK,MAAM,GAAG,IAAI,IAAI,CAAC,QAAQ;YAAE,GAAG,CAAC,eAAe,CAAC,QAAQ,CAAC,CAAC;QAC/D,OAAO,CAAC,QAAQ,EAAE,MAAM,CAAC,CAAC;IAC5B,CAAC;IAED,iBAAiB,CAAC,KAAa;QAC7B,OAAO,QAAQ,CAAC,iBAAiB,CAAC,KAAK,CAAC,CAAC;IAC3C,CAAC;CACF","sourcesContent":["import * as TSU from \"@panyam/tsutils\";\nimport * as G from \"galore\";\nimport * as TLEX from \"tlex\";\nimport matter from \"gray-matter\";\nimport { Literal, AtomType, Note, Atom, Rest, Space, Syllable, Group, Marker } from \"./core\";\nimport { Notation, MetaData as Meta, Command, CmdParam } from \"./notation\";\nimport {\n RawEmbedding,\n ApplyLayout,\n AddAtoms,\n SetCycle,\n SetBeatDuration,\n SetBreaks,\n ActivateRole,\n CreateRole,\n CreateLine,\n MetaData,\n} from \"./commands\";\n\n// TODO - Make this plugable from the client instead of hard coded\nimport * as carnatic from \"./carnatic\";\n\nconst ONE = TSU.Num.Fraction.ONE;\nconst TWO = ONE.timesNum(2);\n\n/**\n * V4 of our parser builds on V3 and has the following improvements:\n *\n * 1. Embedding Headings to demarcate sections so users dont have to use\n * explicit MD for headings.\n * 2. Unlike V3 here users break out *of* song instead instead break out \"into\"\n * song. So users spend more time writing notation and less worrying about\n * other things like headings etc.\n */\nconst [parser /*itemGraph*/] = G.newParser(\n String.raw`\n %define IdentChar /[^%!@$#&\\^|\\[\\]={}()<>+\\-,;~: \\t\\f\\r\\n\\v\\\\\\.\\'\\\"]/\n\n %token BSLASH \"\\\\\"\n %token OPEN_SQ \"[\"\n %token CLOSE_SQ \"]\"\n %token EQUALS \"=\"\n %token OPEN_PAREN \"(\"\n %token CLOSE_PAREN \")\"\n %token OPEN_BRACE \"{\"\n %token CLOSE_BRACE \"}\"\n %token SLASH \"/\"\n %token STAR \"*\"\n %token CARET \"^\"\n // %skip \"-\"\n %token COMMA \",\"\n %token SEMI_COLON \";\"\n %token COLON \":\"\n\n %token FRONT_MATTER /^---$/m { toFrontMatter }\n %token SINGLE_LINE_RAW_STRING />(.*)$/m { toSingleLineRawString }\n %token MULTI_LINE_RAW_STRING /r(#{0,})\"/ { toMultiLineRawString }\n\n %token EMBELISHMENT /~[^\\s]*/ { toEmbelishment }\n %token NUMBER /-?\\d+/ { toNumber }\n %token BOOLEAN /true|false/ { toBoolean }\n %token POST_MARKER /<<\"(([^\"\\\\\\n]|\\\\.|\\\\\\n)*)\"/ { toMarker }\n %token POST_MARKER /<<'(([^'\\\\\\n]|\\\\.|\\\\\\n)*)'/ { toMarker }\n %token PRE_MARKER /\"(([^\"\\\\\\n]|\\\\.|\\\\\\n)*)\">>/ { toMarker }\n %token PRE_MARKER /'(([^'\\\\\\n]|\\\\.|\\\\\\n)*)'>>/ { toMarker }\n %token STRING /\"([^\"\\\\\\n]|\\\\.|\\\\\\n)*\"/ { toString }\n %token STRING /'([^'\\\\\\n]|\\\\.|\\\\\\n)*'/ { toString }\n %token DOTS_IDENT /(\\.+)({IdentChar}+)/ { toOctavedNote }\n %token IDENT_DOTS /({IdentChar}+)(\\.+)/ { toOctavedNote }\n %token IDENT_COLON /{IdentChar}+:/ { toRoleSelector }\n %token IDENT /{IdentChar}+/\n %token BSLASH_IDENT /\\\\{IDENT}/ { toCommandName }\n %token BSLASH_NUMBER /\\\\{NUMBER}/\n %token HYPHEN /-/\n %skip /[ \\t\\n\\f\\r]+/\n %skip_flex \"//.*$\"\n %skip /\\/\\*.*?\\*\\//\n\n Document -> Elements\n | FRONT_MATTER Elements { prependFrontMatter }\n ;\n\n Elements -> Elements Command Atoms { appendCommand } \n | Elements RoleSelector Atoms { appendRoleSelector } \n | Elements Embedding Atoms { insertEmbedding }\n | Atoms { appendAtoms }\n ;\n\n Embedding -> SINGLE_LINE_RAW_STRING | MULTI_LINE_RAW_STRING ;\n\n Command -> BSLASH_IDENT CommandParams ? { newCommand } ;\n CommandParams -> OPEN_PAREN ParamList ? CLOSE_PAREN { $2 } ;\n\n ParamList -> ParamList COMMA Param { concatParamList } ;\n ParamList -> Param { newParamList };\n Param -> ParamValue { newParam } ;\n Param -> ParamKey EQUALS ParamValue { newParam } ;\n ParamKey -> IDENT ;\n ParamValue -> ( STRING | Fraction | NUMBER | BOOLEAN ) ;\n\n RoleSelector -> IDENT_COLON ;\n\n Atoms -> Atoms Atom { concatAtoms } ;\n Atoms -> { newArray } ;\n\n Atom -> Atom POST_MARKER { applyPostMarker }\n | PreMarkedAtom\n ;\n PreMarkedAtom -> Leaf\n | PRE_MARKER PreMarkedAtom { applyPreMarker }\n ;\n\n Leaf -> Space | Lit | Group | Rest ;\n Leaf -> Duration Leaf { applyDuration } ;\n Rest -> HYPHEN { newRest };\n Space -> COMMA { newSpace } \n | SEMI_COLON { newDoubleSpace } \n | UNDER_SCORE { newSilentSpace } \n ;\n\n /* - An alternative representation to support both pre and\n * post embelishment operators. Here PRE_EMBs have a higher\n * associativity over POST_EMBs\n */\n Lit -> Lit POST_EMB { litWithPostEmb }\n | PreEmbLit\n ;\n\n PreEmbLit -> LitToken \n | LitToken CARET NUMBER { litWithCaret }\n | LitToken CARET STAR { litWithCaret }\n | PRE_EMB PreEmbLit { litWithPreEmb }\n ;\n \n LitToken -> DOTS_IDENT { litToAtom }\n | IDENT { litToAtom }\n | IDENT_DOTS { litToAtom }\n | STRING { litToAtom }\n ;\n\n Group -> OPEN_SQ Atoms CLOSE_SQ { newGroup };\n\n Duration -> Fraction | NUMBER;\n Fraction -> NUMBER SLASH NUMBER { newFraction } ;\n `,\n {\n allowLeftRecursion: true,\n debug: \"\",\n type: \"lalr\",\n tokenHandlers: {\n toEmbelishment: (token: TLEX.Token, tape: TLEX.Tape, owner: Parser) => {\n const [emb, pre] = owner.parseEmbelishment(token.value);\n if (emb == null) {\n console.log(\"Skipping Embelishment: \", token.value);\n owner.errors.push(\n new TLEX.TokenizerError(\n `Invalid embelishment: ${token.value}`,\n token.start,\n 1 + token.end - token.start,\n \"InvalidEmbelishment\",\n token.value,\n ),\n );\n return null;\n }\n token.value = emb;\n token.tag = pre ? \"PRE_EMB\" : \"POST_EMB\";\n return token;\n },\n toCommandName: (token: TLEX.Token, tape: TLEX.Tape, owner: any) => {\n token.value = token.value.substring(1);\n return token;\n },\n toBoolean: (token: TLEX.Token, tape: TLEX.Tape, owner: any) => {\n token.value = token.value == \"true\";\n return token;\n },\n toNumber: (token: TLEX.Token, tape: TLEX.Tape, owner: any) => {\n token.value = parseInt(token.value);\n return token;\n },\n toString: (token: TLEX.Token, tape: TLEX.Tape, owner: any) => {\n token.value = token.value.substring(1, token.value.length - 1);\n return token;\n },\n toMarker: (token: TLEX.Token, tape: TLEX.Tape, owner: any) => {\n if (token.tag != \"PRE_MARKER\" && token.tag != \"POST_MARKER\") {\n throw new Error(\"Invalid token for converting to note: \" + token.tag);\n }\n const isBefore = token.tag == \"PRE_MARKER\";\n const markerText = isBefore\n ? token.value.substring(1, token.value.length - 3)\n : token.value.substring(3, token.value.length - 1);\n // console.log(\"TokVal: \", token.value, token.positions);\n // console.log(\"Marker Text: \", markerText, isBefore);\n token.value = new Marker(markerText, isBefore);\n return token;\n },\n toOctavedNote: (token: TLEX.Token, tape: TLEX.Tape, owner: any) => {\n if (token.tag == \"DOTS_IDENT\") {\n const octave = token.positions[1][1] - token.positions[1][0];\n const note = token.value.substring(octave);\n token.value = new Note(note, ONE, -octave);\n } else if (token.tag == \"IDENT_DOTS\") {\n const octave = token.positions[2][1] - token.positions[2][0];\n const note = token.value.substring(0, token.value.length - octave);\n token.value = new Note(note, ONE, octave);\n } else {\n throw new Error(\"Invalid token for converting to note: \" + token.tag);\n }\n return token;\n },\n toRoleSelector: (token: TLEX.Token, tape: TLEX.Tape, owner: any) => {\n token.value = token.value.substring(0, token.value.length - 1);\n return token;\n },\n toLineAnnotation: (token: TLEX.Token, tape: TLEX.Tape, owner: any) => {\n // skip the initial \"!\"\n token.value = token.value.substring(1);\n return token;\n },\n toSingleLineRawString: (token: TLEX.Token, tape: TLEX.Tape, owner: any) => {\n // skip the initial \">\"\n token.value = token.value.substring(1);\n return token;\n },\n toMultiLineRawString: (token: TLEX.Token, tape: TLEX.Tape, owner: any) => {\n // consume everything until \"#<N times> as start\n const hashes = tape.substring(token.positions[1][0], token.positions[1][1]);\n const endPat = '\"' + hashes;\n const startPos = tape.index;\n const endPos = TLEX.TapeHelper.advanceAfter(tape, endPat) - endPat.length;\n if (endPos < 0) {\n throw new Error(\"EOF expected while finding end of Raw String Literal: '\" + endPat + \"'\");\n }\n token.value = tape.substring(startPos, endPos);\n return token;\n },\n toFrontMatter: (token: TLEX.Token, tape: TLEX.Tape, owner: any) => {\n // skip the initial \">\"\n const endPat = \"\\n---\";\n const startPos = tape.index;\n const endPos = TLEX.TapeHelper.advanceAfter(tape, endPat) - endPat.length;\n if (endPos < 0) {\n throw new Error(\"EOF expected while finding end of front matter\");\n }\n token.value = tape.substring(startPos, endPos);\n // console.log(\"Found FM: \", token.value);\n return token;\n },\n },\n },\n);\n\n/**\n * A notation doc is a list of lines that are found in a single document.\n *\n * Since our document (md or html etc) can contain multiple snippets\n * all these snippets are related\n */\nexport class Parser {\n errors: (TLEX.TokenizerError | G.ParseError)[] = [];\n metadata: any = {};\n readonly commands: Command[] = [];\n // readonly notation: Notation = new Notation();\n // private runCommandFound = false;\n // readonly parseTree = new PTNodeList(\"Snippet\", null);\n\n protected ruleHandlers = {\n newFraction: (rule: G.Rule, parent: G.PTNode, ...children: G.PTNode[]) => {\n if (children.length == 1) {\n return new TSU.Num.Fraction(children[0].value);\n } else {\n return new TSU.Num.Fraction(children[0].value, children[2].value);\n }\n },\n newGroup: (rule: G.Rule, parent: G.PTNode, ...children: G.PTNode[]) => {\n const out = new Group(...children[1].value).setDuration(TWO, true);\n return out;\n },\n litWithCaret: (rule: G.Rule, parent: G.PTNode, ...children: G.PTNode[]) => {\n const lit = Note.fromLit(children[0].value as Literal);\n const opnode = children[2];\n const shiftValue = opnode.sym.label == \"STAR\" ? true : opnode.value;\n lit.shift = shiftValue;\n return lit;\n },\n litWithPreEmb: (rule: G.Rule, parent: G.PTNode, ...children: G.PTNode[]) => {\n const emb = children[0];\n const lit = children[1].value as Literal;\n lit.embelishments.splice(0, 0, emb.value);\n return lit;\n },\n litWithPostEmb: (rule: G.Rule, parent: G.PTNode, ...children: G.PTNode[]) => {\n const lit = children[0].value as Literal;\n const emb = children[1];\n lit.embelishments.push(emb);\n return lit;\n },\n litToAtom: (rule: G.Rule, parent: G.PTNode, ...children: G.PTNode[]) => {\n const lit = children[0];\n if (lit.sym.label == \"DOTS_IDENT\" || lit.sym.label == \"IDENT_DOTS\") {\n return lit.value;\n } else if (lit.sym.label == \"IDENT\") {\n // Mark this as a Literal to be processed later\n return new Literal(lit.value);\n // return role.notesOnly ? new Note(lit.value) : new Syllable(lit.value);\n } else if (lit.sym.label == \"STRING\") {\n // const role = this.snippet.currRole;\n // if (role.notesOnly) throw new Error(\"Strings cannot appear in notes only mode\");\n return new Syllable(lit.value);\n } else {\n throw new Error(\"Invalid lit: \" + lit);\n }\n },\n newSpace: (rule: G.Rule, parent: G.PTNode, ...children: G.PTNode[]) => {\n return new Space();\n },\n newRest: (rule: G.Rule, parent: G.PTNode, ...children: G.PTNode[]) => {\n return new Rest();\n },\n newDoubleSpace: (rule: G.Rule, parent: G.PTNode, ...children: G.PTNode[]) => {\n return new Space(ONE.timesNum(2));\n },\n newSilentSpace: (rule: G.Rule, parent: G.PTNode, ...children: G.PTNode[]) => {\n return new Space(ONE, true);\n },\n applyPreMarker: (rule: G.Rule, parent: G.PTNode, ...children: G.PTNode[]) => {\n const marker = children[0].value as Marker;\n const leaf = children[1].value as Atom;\n // console.log(\"marker, leaf: \", marker, leaf);\n if (!leaf.markersBefore) {\n leaf.markersBefore = [];\n }\n leaf.markersBefore.splice(0, 0, marker);\n return leaf;\n },\n applyPostMarker: (rule: G.Rule, parent: G.PTNode, ...children: G.PTNode[]) => {\n const leaf = children[0].value as Atom;\n const marker = children[1].value as Marker;\n if (!leaf.markersAfter) {\n leaf.markersAfter = [];\n }\n leaf.markersAfter.push(marker);\n return leaf;\n },\n applyDuration: (rule: G.Rule, parent: G.PTNode, ...children: G.PTNode[]) => {\n let dur = children[0].value as TSU.Num.Fraction | number;\n const leaf = children[1].value as Atom;\n if (typeof dur === \"number\") {\n dur = ONE.timesNum(dur);\n }\n if (leaf.TYPE == AtomType.GROUP) {\n (leaf as Group).setDuration(dur, true);\n } else {\n leaf.duration = dur;\n }\n return leaf;\n },\n newArray: (rule: G.Rule, parent: G.PTNode, ...children: G.PTNode[]) => {\n // create an array of values from all the values of child nodes\n return children.map((c) => c.value);\n },\n concatAtoms: (rule: G.Rule, parent: G.PTNode, ...children: G.PTNode[]) => {\n const atoms = children[0].value;\n const atom = children[1].value;\n atoms.push(atom);\n return atoms;\n },\n newParam: (rule: G.Rule, parent: G.PTNode, ...children: G.PTNode[]) => {\n if (children.length == 1) {\n return { key: null, value: children[0].value };\n } else {\n return { key: children[0].value, value: children[2].value };\n }\n },\n newParamList: (rule: G.Rule, parent: G.PTNode, ...children: G.PTNode[]) => {\n return [children[0].value];\n },\n concatParamList: (rule: G.Rule, parent: G.PTNode, ...children: G.PTNode[]) => {\n const params = children[0].value;\n const newParam = children[2].value;\n params.push(newParam);\n return params;\n },\n newCommand: (rule: G.Rule, parent: G.PTNode, ...children: G.PTNode[]) => {\n return this.createCommand(children[0].value, children[1].value);\n },\n appendAtoms: (rule: G.Rule, parent: G.PTNode, ...children: G.PTNode[]) => {\n const atoms = children[0].value as Atom[];\n if (atoms.length > 0) {\n this.addCommand(new AddAtoms(...atoms));\n }\n return null;\n },\n prependFrontMatter: (rule: G.Rule, parent: G.PTNode, ...children: G.PTNode[]) => {\n const fm = children[0].value;\n // console.log(\"Child 0: \", fm);\n // console.log(\"Child 1: \", children[1].value);\n const { data } = matter(\"---\\n\" + fm + \"\\n---\");\n console.log(\"Parsed FM: \", data);\n this.metadata = data;\n return children[1].value;\n },\n appendCommand: (rule: G.Rule, parent: G.PTNode, ...children: G.PTNode[]) => {\n const command = children[1].value as Command;\n this.addCommand(command);\n\n const atoms = children[2].value as Atom[];\n if (atoms.length > 0) {\n this.addCommand(new AddAtoms(...atoms));\n }\n return null;\n },\n appendRoleSelector: (rule: G.Rule, parent: G.PTNode, ...children: G.PTNode[]) => {\n const roleName = children[1].value;\n const lName = roleName.toLowerCase().trim();\n this.addCommand(new ActivateRole([{ key: null, value: lName }]));\n\n const atoms = children[2].value as Atom[];\n if (atoms.length > 0) {\n this.addCommand(new AddAtoms(...atoms));\n }\n return null;\n },\n insertEmbedding: (rule: G.Rule, parent: G.PTNode, ...children: G.PTNode[]) => {\n // How to handle embeddings - these are just blocks\n // to escape out of song (most likely for some rendering of html/md etc)\n const rawVal = children[1].value;\n this.addCommand(new RawEmbedding([{ key: null, value: rawVal }]));\n const atoms = children[2].value as Atom[];\n if (atoms.length > 0) {\n this.addCommand(new AddAtoms(...atoms));\n }\n return null;\n },\n };\n\n constructor(config?: any) {\n config = config || {};\n }\n\n createCommand(name: string, params: CmdParam[]): Command {\n const lName = name.trim().toLowerCase();\n params = params || [];\n if (lName == \"line\") {\n return new CreateLine(params);\n } else if (lName == \"meta\") {\n return new MetaData(params);\n } else if (lName == \"role\") {\n return new CreateRole(params);\n } else if (lName == \"layout\") {\n return new ApplyLayout(params);\n } else if (lName == \"beatduration\") {\n return new SetBeatDuration(params);\n } else if (lName == \"breaks\") {\n return new SetBreaks(params);\n } else if (lName == \"cycle\") {\n return new SetCycle(params);\n } else {\n // Try to set this as the current role\n throw new Error(\"Invalid command: \" + lName);\n }\n }\n\n addCommand(cmd: Command): void {\n cmd.index = this.commands.length;\n this.commands.push(cmd);\n }\n\n parse(input: string): any {\n this.errors = [];\n try {\n const ptree = parser.parse(input, {\n tokenizerContext: this,\n ruleHandlers: this.ruleHandlers,\n onTokenError: (err: TLEX.TokenizerError) => {\n this.errors.push(err);\n return true;\n },\n });\n return ptree;\n } catch (err) {\n if (err instanceof G.ParseError) {\n this.errors.push(err);\n } else {\n throw err;\n }\n }\n return null;\n }\n\n parseAndBuild(input: string): [Notation, G.ParseError[]] {\n this.parse(input);\n const notation = new Notation();\n const errors: G.ParseError[] = [];\n errors.push(...this.errors);\n\n // First add the metadata then we can set it\n for (const key in this.metadata) notation.addMetaData(new Meta(key, this.metadata[key]));\n for (const cmd of this.commands) cmd.applyToNotation(notation);\n return [notation, errors];\n }\n\n parseEmbelishment(value: string): [any, boolean] {\n return carnatic.parseEmbelishment(value);\n }\n}\n"]}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "notations",
3
- "version": "0.0.60",
3
+ "version": "0.0.61",
4
4
  "author": "Sriram Panyam",
5
5
  "description": "A package for modelling, parsing, laying out carnatic musical notation",
6
6
  "homepage": "https://github.com/panyam/notations#readme",
@@ -27,7 +27,8 @@
27
27
  "dependencies": {
28
28
  "@lume/kiwi": "^0.1.0",
29
29
  "@panyam/tsutils": "*",
30
- "galore": "*"
30
+ "galore": "*",
31
+ "gray-matter": "^4.0.3"
31
32
  },
32
33
  "devDependencies": {
33
34
  "@babel/core": "^7.20.5",