notations 1.0.4 → 1.0.7
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/README.md +1 -0
- package/dist/NotationView.css +15 -0
- package/dist/NotationView.css.map +1 -1
- package/dist/NotationView.min.css +1 -1
- package/dist/NotationView.min.css.map +1 -1
- package/dist/notations.umd.js +469 -108
- package/dist/notations.umd.min.js +2 -2
- package/dist/notations.umd.min.js.map +1 -1
- package/lib/cjs/beats.js +1 -1
- package/lib/cjs/beats.js.map +1 -1
- package/lib/cjs/block.d.ts +4 -0
- package/lib/cjs/block.js +24 -0
- package/lib/cjs/block.js.map +1 -1
- package/lib/cjs/carnatic/NotationView.d.ts +1 -0
- package/lib/cjs/carnatic/NotationView.js +10 -0
- package/lib/cjs/carnatic/NotationView.js.map +1 -1
- package/lib/cjs/carnatic/atomviews.d.ts +4 -1
- package/lib/cjs/carnatic/atomviews.js +18 -2
- package/lib/cjs/carnatic/atomviews.js.map +1 -1
- package/lib/cjs/carnatic/embelishments.d.ts +18 -1
- package/lib/cjs/carnatic/embelishments.js +87 -1
- package/lib/cjs/carnatic/embelishments.js.map +1 -1
- package/lib/cjs/core.d.ts +18 -3
- package/lib/cjs/core.js +161 -21
- package/lib/cjs/core.js.map +1 -1
- package/lib/cjs/entity.d.ts +4 -0
- package/lib/cjs/entity.js +12 -0
- package/lib/cjs/entity.js.map +1 -1
- package/lib/cjs/events.d.ts +56 -0
- package/lib/cjs/events.js +27 -0
- package/lib/cjs/events.js.map +1 -0
- package/lib/cjs/index.d.ts +1 -0
- package/lib/cjs/index.js +1 -0
- package/lib/cjs/index.js.map +1 -1
- package/lib/cjs/shapes.d.ts +13 -1
- package/lib/cjs/shapes.js +35 -7
- package/lib/cjs/shapes.js.map +1 -1
- package/lib/esm/beats.js +1 -1
- package/lib/esm/beats.js.map +1 -1
- package/lib/esm/block.d.ts +4 -0
- package/lib/esm/block.js +24 -0
- package/lib/esm/block.js.map +1 -1
- package/lib/esm/carnatic/NotationView.d.ts +1 -0
- package/lib/esm/carnatic/NotationView.js +10 -0
- package/lib/esm/carnatic/NotationView.js.map +1 -1
- package/lib/esm/carnatic/atomviews.d.ts +4 -1
- package/lib/esm/carnatic/atomviews.js +19 -3
- package/lib/esm/carnatic/atomviews.js.map +1 -1
- package/lib/esm/carnatic/embelishments.d.ts +18 -1
- package/lib/esm/carnatic/embelishments.js +85 -0
- package/lib/esm/carnatic/embelishments.js.map +1 -1
- package/lib/esm/core.d.ts +18 -3
- package/lib/esm/core.js +161 -21
- package/lib/esm/core.js.map +1 -1
- package/lib/esm/entity.d.ts +4 -0
- package/lib/esm/entity.js +12 -0
- package/lib/esm/entity.js.map +1 -1
- package/lib/esm/events.d.ts +56 -0
- package/lib/esm/events.js +24 -0
- package/lib/esm/events.js.map +1 -0
- package/lib/esm/index.d.ts +1 -0
- package/lib/esm/index.js +1 -0
- package/lib/esm/index.js.map +1 -1
- package/lib/esm/shapes.d.ts +13 -1
- package/lib/esm/shapes.js +34 -7
- package/lib/esm/shapes.js.map +1 -1
- package/package.json +3 -1
- package/styles/NotationView.scss +15 -0
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"notations.umd.min.js","mappings":"CAAA,SAA2CA,EAAMC,GAC1B,iBAAZC,SAA0C,iBAAXC,OACxCA,OAAOD,QAAUD,IACQ,mBAAXG,QAAyBA,OAAOC,IAC9CD,OAAO,GAAIH,GACe,iBAAZC,QACdA,QAAmB,UAAID,IAEvBD,EAAgB,UAAIC,GACrB,CATD,CASGK,KAAM,I,mBCRT,IAAIC,EAAsB,CCA1BA,EAAwB,CAACL,EAASM,KACjC,IAAI,IAAIC,KAAOD,EACXD,EAAoBG,EAAEF,EAAYC,KAASF,EAAoBG,EAAER,EAASO,IAC5EE,OAAOC,eAAeV,EAASO,EAAK,CAAEI,YAAY,EAAMC,IAAKN,EAAWC,MCJ3EF,EAAwB,CAACQ,EAAKC,IAAUL,OAAOM,UAAUC,eAAeC,KAA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,EAAKsG,UAAUyB,EAAMlL,UAAU,GAAG,GAAIkL,EAAMlL,UAAU,GAAG,IAElEmC,EAAWgB,EAAKpc,MAChB2zC,EAAS9oB,GAAgBjI,aAAaxG,EAAMs3B,GAAUA,EAAOvhD,OACnE,GAAIwhD,EAAS,EACX,MAAM,IAAIjmD,MAAM,0DAA4DgmD,EAAS,KAGvF,OADAvvB,EAAM7vB,MAAQ8nB,EAAKsG,UAAUtH,EAAUu4B,GAChCxvB,GAETyvB,cAAeA,CAACzvB,EAAmB/H,EAA0B22B,KAE3D,MACM33B,EAAWgB,EAAKpc,MAChB2zC,EAAS9oB,GAAgBjI,aAAaxG,EAF7B,SAE6Cs3B,EAC5D,GAAIC,EAAS,EACX,MAAM,IAAIjmD,MAAM,kDAIlB,OAFAy2B,EAAM7vB,MAAQ8nB,EAAKsG,UAAUtH,EAAUu4B,GAEhCxvB,O","sources":["webpack://Notations/webpack/universalModuleDefinition","webpack://Notations/webpack/bootstrap","webpack://Notations/webpack/runtime/define property getters","webpack://Notations/webpack/runtime/hasOwnProperty shorthand","webpack://Notations/../../src/entity.ts","webpack://Notations/../../src/types.ts","webpack://Notations/../../src/constants.ts","webpack://Notations/../../../src/comms/events.ts","webpack://Notations/../../src/list.ts","webpack://Notations/../../src/browser.ts","webpack://Notations/../../src/numberutils.ts","webpack://Notations/../../src/cycle.ts","webpack://Notations/../../src/core.ts","webpack://Notations/../../src/layouts.ts","webpack://Notations/../../src/grids.ts","webpack://Notations/../../src/beats.ts","webpack://Notations/../../src/graph.ts","webpack://Notations/../../src/sets.ts","webpack://Notations/../../src/grammar.ts","webpack://Notations/../../src/charclasses.ts","webpack://Notations/../../src/propertyescapes.ts","webpack://Notations/../../src/vm.ts","webpack://Notations/../../src/compiler.ts","webpack://Notations/../../src/errors.ts","webpack://Notations/../../src/tape.ts","webpack://Notations/../../src/token.ts","webpack://Notations/../../src/utils.ts","webpack://Notations/../../src/jsparser.ts","webpack://Notations/../../src/flexparser.ts","webpack://Notations/../../src/builder.ts","webpack://Notations/../../src/tokenizer.ts","webpack://Notations/../../src/samples.ts","webpack://Notations/../../src/dsl.ts","webpack://Notations/../../src/lr.ts","webpack://Notations/../../src/parser.ts","webpack://Notations/../../src/lritems.ts","webpack://Notations/../../src/ptables.ts","webpack://Notations/./node_modules/.pnpm/yaml@2.8.2/node_modules/yaml/browser/dist/nodes/identity.js","webpack://Notations/./node_modules/.pnpm/yaml@2.8.2/node_modules/yaml/browser/dist/visit.js","webpack://Notations/./node_modules/.pnpm/yaml@2.8.2/node_modules/yaml/browser/dist/doc/directives.js","webpack://Notations/./node_modules/.pnpm/yaml@2.8.2/node_modules/yaml/browser/dist/doc/anchors.js","webpack://Notations/./node_modules/.pnpm/yaml@2.8.2/node_modules/yaml/browser/dist/doc/applyReviver.js","webpack://Notations/./node_modules/.pnpm/yaml@2.8.2/node_modules/yaml/browser/dist/nodes/toJS.js","webpack://Notations/./node_modules/.pnpm/yaml@2.8.2/node_modules/yaml/browser/dist/nodes/Node.js","webpack://Notations/./node_modules/.pnpm/yaml@2.8.2/node_modules/yaml/browser/dist/nodes/Alias.js","webpack://Notations/./node_modules/.pnpm/yaml@2.8.2/node_modules/yaml/browser/dist/nodes/Scalar.js","webpack://Notations/./node_modules/.pnpm/yaml@2.8.2/node_modules/yaml/browser/dist/doc/createNode.js","webpack://Notations/./node_modules/.pnpm/yaml@2.8.2/node_modules/yaml/browser/dist/nodes/Collection.js","webpack://Notations/./node_modules/.pnpm/yaml@2.8.2/node_modules/yaml/browser/dist/stringify/stringifyComment.js","webpack://Notations/./node_modules/.pnpm/yaml@2.8.2/node_modules/yaml/browser/dist/stringify/foldFlowLines.js","webpack://Notations/./node_modules/.pnpm/yaml@2.8.2/node_modules/yaml/browser/dist/stringify/stringifyString.js","webpack://Notations/./node_modules/.pnpm/yaml@2.8.2/node_modules/yaml/browser/dist/stringify/stringify.js","webpack://Notations/./node_modules/.pnpm/yaml@2.8.2/node_modules/yaml/browser/dist/schema/yaml-1.1/merge.js","webpack://Notations/./node_modules/.pnpm/yaml@2.8.2/node_modules/yaml/browser/dist/nodes/addPairToJSMap.js","webpack://Notations/./node_modules/.pnpm/yaml@2.8.2/node_modules/yaml/browser/dist/log.js","webpack://Notations/./node_modules/.pnpm/yaml@2.8.2/node_modules/yaml/browser/dist/nodes/Pair.js","webpack://Notations/./node_modules/.pnpm/yaml@2.8.2/node_modules/yaml/browser/dist/stringify/stringifyPair.js","webpack://Notations/./node_modules/.pnpm/yaml@2.8.2/node_modules/yaml/browser/dist/stringify/stringifyCollection.js","webpack://Notations/./node_modules/.pnpm/yaml@2.8.2/node_modules/yaml/browser/dist/nodes/YAMLMap.js","webpack://Notations/./node_modules/.pnpm/yaml@2.8.2/node_modules/yaml/browser/dist/schema/common/map.js","webpack://Notations/./node_modules/.pnpm/yaml@2.8.2/node_modules/yaml/browser/dist/nodes/YAMLSeq.js","webpack://Notations/./node_modules/.pnpm/yaml@2.8.2/node_modules/yaml/browser/dist/schema/common/seq.js","webpack://Notations/./node_modules/.pnpm/yaml@2.8.2/node_modules/yaml/browser/dist/schema/common/string.js","webpack://Notations/./node_modules/.pnpm/yaml@2.8.2/node_modules/yaml/browser/dist/schema/common/null.js","webpack://Notations/./node_modules/.pnpm/yaml@2.8.2/node_modules/yaml/browser/dist/schema/core/bool.js","webpack://Notations/./node_modules/.pnpm/yaml@2.8.2/node_modules/yaml/browser/dist/stringify/stringifyNumber.js","webpack://Notations/./node_modules/.pnpm/yaml@2.8.2/node_modules/yaml/browser/dist/schema/core/float.js","webpack://Notations/./node_modules/.pnpm/yaml@2.8.2/node_modules/yaml/browser/dist/schema/core/int.js","webpack://Notations/./node_modules/.pnpm/yaml@2.8.2/node_modules/yaml/browser/dist/schema/core/schema.js","webpack://Notations/./node_modules/.pnpm/yaml@2.8.2/node_modules/yaml/browser/dist/schema/json/schema.js","webpack://Notations/./node_modules/.pnpm/yaml@2.8.2/node_modules/yaml/browser/dist/schema/yaml-1.1/binary.js","webpack://Notations/./node_modules/.pnpm/yaml@2.8.2/node_modules/yaml/browser/dist/schema/yaml-1.1/pairs.js","webpack://Notations/./node_modules/.pnpm/yaml@2.8.2/node_modules/yaml/browser/dist/schema/yaml-1.1/omap.js","webpack://Notations/./node_modules/.pnpm/yaml@2.8.2/node_modules/yaml/browser/dist/schema/yaml-1.1/bool.js","webpack://Notations/./node_modules/.pnpm/yaml@2.8.2/node_modules/yaml/browser/dist/schema/yaml-1.1/float.js","webpack://Notations/./node_modules/.pnpm/yaml@2.8.2/node_modules/yaml/browser/dist/schema/yaml-1.1/int.js","webpack://Notations/./node_modules/.pnpm/yaml@2.8.2/node_modules/yaml/browser/dist/schema/yaml-1.1/set.js","webpack://Notations/./node_modules/.pnpm/yaml@2.8.2/node_modules/yaml/browser/dist/schema/yaml-1.1/timestamp.js","webpack://Notations/./node_modules/.pnpm/yaml@2.8.2/node_modules/yaml/browser/dist/schema/yaml-1.1/schema.js","webpack://Notations/./node_modules/.pnpm/yaml@2.8.2/node_modules/yaml/browser/dist/schema/tags.js","webpack://Notations/./node_modules/.pnpm/yaml@2.8.2/node_modules/yaml/browser/dist/errors.js","webpack://Notations/./node_modules/.pnpm/yaml@2.8.2/node_modules/yaml/browser/dist/parse/cst-visit.js","webpack://Notations/../../../src/carnatic/gamakas.ts","webpack://Notations/./node_modules/.pnpm/yaml@2.8.2/node_modules/yaml/browser/dist/parse/lexer.js","webpack://Notations/../../src/shapes.ts","webpack://Notations/../../src/factory.ts","webpack://Notations/../../src/debug.ts"],"sourcesContent":["(function webpackUniversalModuleDefinition(root, factory) {\n\tif(typeof exports === 'object' && typeof module === 'object')\n\t\tmodule.exports = factory();\n\telse if(typeof define === 'function' && define.amd)\n\t\tdefine([], factory);\n\telse if(typeof exports === 'object')\n\t\texports[\"Notations\"] = factory();\n\telse\n\t\troot[\"Notations\"] = factory();\n})(this, () => {\nreturn ","// The require scope\nvar __webpack_require__ = {};\n\n","// define getter functions for harmony exports\n__webpack_require__.d = (exports, definition) => {\n\tfor(var key in definition) {\n\t\tif(__webpack_require__.o(definition, key) && !__webpack_require__.o(exports, key)) {\n\t\t\tObject.defineProperty(exports, key, { enumerable: true, get: definition[key] });\n\t\t}\n\t}\n};","__webpack_require__.o = (obj, prop) => (Object.prototype.hasOwnProperty.call(obj, prop))","import * as TSU from \"@panyam/tsutils\";\n\n/**\n * A common Entity base class with support for unique IDs, parent references,\n * copying, and debug info. This serves as the foundation for all entities\n * in the notation system.\n *\n * Note: Child management is intentionally NOT included here. Each container type\n * (BlockContainer, Line, Group, etc.) defines its own child management with\n * appropriate types.\n */\nexport class Entity {\n readonly TYPE: string = \"Entity\";\n\n private static counter = 0;\n /** Unique identifier for this entity */\n readonly uuid = Entity.counter++;\n /** Parent entity in the tree hierarchy */\n protected _parent: TSU.Nullable<Entity> = null;\n\n /**\n * Creates a new Entity.\n * @param config Optional configuration object\n */\n constructor(config: any = null) {\n config = config || {};\n if (config.metadata) throw new Error(\"See where metadata is being passed\");\n }\n\n /**\n * Gets the parent entity.\n */\n get parent(): TSU.Nullable<Entity> {\n return this._parent;\n }\n\n /**\n * Sets the parent entity.\n * @param parent The parent entity to set\n */\n setParent(parent: TSU.Nullable<Entity>): void {\n this._parent = parent;\n }\n\n /**\n * Returns a debug-friendly representation of this entity.\n * Usually overridden by children to add more debug info.\n * @returns An object containing debug information\n */\n debugValue(): any {\n return { type: this.TYPE };\n }\n\n /**\n * Returns a simple string representation of this Entity.\n * @returns A string representation\n */\n toString(): string {\n return `Entity(id = ${this.uuid})`;\n }\n\n /**\n * Checks if this Entity is equal to another Entity.\n * @param another The Entity to compare with\n * @param expect Optional parameter\n * @returns True if the Entities are equal, false otherwise\n */\n equals(another: this, expect = false): boolean {\n if (this.TYPE != another.TYPE) return false;\n return true;\n }\n\n /**\n * Creates a clone of this entity.\n * Cloning is a two-part process:\n * 1. Creation of a new instance via this.newInstance()\n * 2. Copying of data into the new instance via this.copyTo()\n *\n * @returns A new instance of the same type with the same properties\n */\n clone(): this {\n const out = this.newInstance();\n this.copyTo(out);\n return out;\n }\n\n /**\n * Copies information about this instance into another instance of the same type.\n * @param another The target instance to copy properties to\n */\n copyTo(another: this): void {\n // Subclasses override to copy their specific properties\n }\n\n /**\n * First part of the cloning process where the instance is created.\n * @returns A new instance of the same type\n */\n protected newInstance(): this {\n return new (this.constructor as any)();\n }\n}\n\n/**\n * Music is all about timing! TimedEntities are base of all entities that\n * have a duration. This is an abstract class that all timed entities inherit from.\n */\nexport abstract class TimedEntity extends Entity {\n readonly TYPE: string = \"TimedEntity\";\n\n /**\n * Gets the duration of this entity in terms of beats.\n * By default, entity durations are readonly.\n */\n abstract get duration(): TSU.Num.Fraction;\n\n /**\n * Checks if this TimedEntity is equal to another TimedEntity.\n * @param another The TimedEntity to compare with\n * @returns True if the TimedEntities are equal, false otherwise\n */\n equals(another: this): boolean {\n return super.equals(another) && this.duration.equals(another.duration);\n }\n}\n","export type Timestamp = number;\nexport type NumberRange = [number, number];\n\nexport type StringMap<T> = { [key: string]: T };\nexport type NumMap<T> = { [key: number]: T };\nexport type Nullable<T> = T | null;\n\nexport type Undefined<T> = T | undefined | void;\n\nexport function assert(condition: boolean, msg?: string): asserts condition {\n if (!condition) {\n throw new Error(msg);\n }\n}\n","export const INFINITY = 1e48;\nexport const MAX_INT = 2 ** 32;\nexport const MAX_LONG = 2 ** 64;\n","import { Nullable, Timestamp } from \"../types\";\n\n/**\n * Super class of all Events.\n */\nexport class TEvent {\n // Globally unique ID for all events.\n private static counter = 0;\n readonly uuid = TEvent.counter++;\n\n /**\n * The event this event was spawned from (if any).\n */\n protected _spawnedFrom: Nullable<this> = null;\n\n /**\n * Name of the event.\n */\n readonly name: string;\n\n /**\n * Source from which this event is originating.\n */\n readonly source: any;\n\n /**\n * Source state that is set by the source of the event only\n * *it* can use.\n */\n sourceState: any = null;\n\n /**\n * Event specific payload.\n */\n payload: any;\n\n /**\n * Whether the event was cancelled.\n */\n cancelled = false;\n\n /**\n * Timestamp of the event - optional.\n */\n timeStamp: Timestamp = -1;\n\n /**\n * All child events that were spawned from this Event.\n * The parent/spawnedFrom and child event references help us\n * form a call tree/trace of a events as it traverses\n * the system.\n */\n children: TEvent[] = [];\n\n constructor(name: string, source: any, payload?: any) {\n this.name = name;\n this.source = source;\n this.payload = payload;\n }\n\n get spawnedFrom(): Nullable<this> {\n return this._spawnedFrom;\n }\n\n protected setSpawnedFrom(msg: Nullable<this>): void {\n this._spawnedFrom = msg;\n if (msg == null) this._rootEvent = this;\n else this._rootEvent = msg.rootEvent;\n }\n\n spawn(name: string, source: any, payload?: any): TEvent {\n const child = new TEvent(name, source, payload);\n child.setSpawnedFrom(this);\n this.children.push(child);\n return child;\n }\n\n /**\n * The first/root message in the forward chain.\n */\n private _rootEvent: this;\n\n get rootEvent(): this {\n return this._rootEvent as this;\n }\n}\n\nexport class State {\n private static counter = 0;\n stateData: any = null;\n readonly id = State.counter++;\n\n get name(): string {\n return this.constructor.name;\n }\n\n enter(data: any): void {\n this.stateData = data;\n }\n\n handle(event: TEvent): void {\n // todo\n }\n}\n\nexport type EventCallback = ((event: TEvent) => void) | ((event: TEvent) => Promise<void>);\n\nexport class EventEmitter {\n protected _eventHub: EventHub | null;\n constructor() {\n this._eventHub = new EventHub();\n }\n get eventHub(): EventHub | null {\n return this._eventHub;\n }\n set eventHub(hub: EventHub | null) {\n const oldHub = this._eventHub;\n this._eventHub = hub;\n this.eventHubChanged(oldHub);\n }\n protected eventHubChanged(oldHub: EventHub | null): void {\n // Do nothing\n console.log(\"WARNING - EventHub Change Listener not implemented: \", this.constructor.name);\n }\n}\n\nexport class EventHub {\n private _handlers: { [key: string]: Array<EventCallback> } = {};\n\n on(names: Array<string> | string, callback: EventCallback): this {\n return this._addHandler(names, this._handlers, callback);\n }\n\n removeOn(names: Array<string> | string, callback: EventCallback): this {\n return this._removeHandler(names, this._handlers, callback);\n }\n\n _ensurestrings(names: Array<string> | string): string[] {\n if (typeof names === \"string\") {\n names = (names as string).split(\",\");\n }\n return names.map(function (v) {\n return v.trim();\n });\n }\n\n _addHandler<T>(names: Array<string> | string, handlerlist: { [key: string]: Array<T> }, handler: T): this {\n this._ensurestrings(names).forEach(function (name) {\n handlerlist[name] = handlerlist[name] || [];\n handlerlist[name].push(handler);\n });\n return this;\n }\n\n _removeHandler<T>(names: Array<string> | string, handlerlist: { [key: string]: Array<T> }, handler: T): this {\n this._ensurestrings(names).forEach(function (name) {\n const evHandlers = handlerlist[name] || [];\n for (let i = 0; i < evHandlers.length; i++) {\n if (evHandlers[i] == handler) {\n evHandlers.splice(i, 1);\n break;\n }\n }\n });\n return this;\n }\n\n emit(name: string, source: any, payload?: any): boolean {\n const evt = new TEvent(name, source, payload);\n if (this._inBatchMode) {\n this._events.push(evt);\n return true;\n } else {\n return this.dispatchEvent(evt);\n }\n }\n\n dispatchEvent(event: TEvent): boolean {\n const evtCallbacks = this._handlers[event.name] || [];\n for (const callback of evtCallbacks) {\n callback(event);\n if (event.cancelled) return false;\n }\n return true;\n }\n\n // Support for transactional/batch event handling, where\n // the user can allow a bunch of events to first collect\n // before triggering a batch dispatch\n public static BATCH_EVENTS = \"BatchEvents\";\n protected _events: TEvent[] = [];\n protected _inBatchMode = false;\n startBatchMode(): this {\n if (!this._inBatchMode) {\n this._inBatchMode = true;\n }\n return this;\n }\n\n cancelBatch(): void {\n this._inBatchMode = false;\n this._events = [];\n }\n\n commitBatch(): void {\n this._inBatchMode = false;\n this.emit(EventHub.BATCH_EVENTS, this, this._events);\n this._events = [];\n }\n}\n\n/**\n * StateMachines allow declarative and stateful chaining of events.\n */\nexport class StateMachine {\n private _states: { [key: string]: State } = {};\n private _rootState: Nullable<State> = null;\n private _currentState: Nullable<State> = null;\n constructor() {\n this._states = {};\n this._rootState = null;\n this._currentState = null;\n }\n\n /**\n * The starting/root state of the machine.\n *\n * @param {String} name Name of the default/root state.\n */\n set rootState(name: string) {\n this._rootState = this.getState(name);\n if (this._currentState == null) {\n this._currentState = this._rootState;\n }\n }\n\n /**\n * Exits the current state (if any) and enters a new state.\n *\n * @param {String} state Name of the new state to enter.\n * @param {Object} data State specific data for the state handler to use for the new state.\n */\n enter(state: string, data: any = null): void {\n if (state == \"\") {\n this._currentState = this._rootState;\n } else {\n this._currentState = this.getState(state);\n }\n if (this._currentState != null) {\n this._currentState.enter(data);\n }\n }\n\n /**\n * Get the state by name.\n *\n * @param {String} name Name of the state being queried.\n * @returns {State} State object associated with the name.\n */\n getState(name: string): State {\n if (!(name in this._states)) {\n throw Error(\"State '\" + name + \"' not yet registered.\");\n }\n return this._states[name];\n }\n\n /**\n * Register a new state in the state machine.\n *\n * @param {State} state State being registered. If another State with\n * the same name exists, then a {DuplicateError} is thrown.\n * @param {Bool} isRoot Whether the new state is a root state.\n */\n registerState(state: State, isRoot = false): void {\n const name = state.name;\n if (name in this._states) {\n throw Error(\"State '\" + name + \"' already registered.\");\n }\n this._states[name] = state;\n if (isRoot || false) {\n this.rootState = state.name;\n }\n }\n\n /**\n * Handles an event from the current state in the state machine possibly resulting in a state transition.\n *\n * @param {Object} name Type of event being sent.\n * @param {EventSource} source The source generating the event.\n * @param {Object} data The event specific data.\n */\n handle(event: TEvent): void {\n if (this._currentState == null) return;\n\n const nextState: any = this._currentState.handle(event);\n if (nextState != null) {\n if (nextState == \"\") {\n if (this._rootState != null) {\n this.enter(this._rootState.name);\n } else {\n throw new Error(\"Root state has not been set\");\n }\n } else {\n this.enter(nextState);\n }\n }\n }\n}\n","import { Nullable } from \"./types\";\n\nexport interface ListNode<V> {\n nextSibling: Nullable<V>;\n prevSibling: Nullable<V>;\n}\n\nclass MutableListNode<V> implements ListNode<MutableListNode<V>> {\n nextSibling: Nullable<MutableListNode<V>> = null;\n prevSibling: Nullable<MutableListNode<V>> = null;\n constructor(public value: V) {}\n}\n\n/**\n * A list implementation where the value itself contains next and prev pointers\n * so we do not need to create wrapper classes.\n */\nexport class ValueList<V extends ListNode<V>> {\n protected _firstChild: Nullable<V> = null;\n protected _lastChild: Nullable<V> = null;\n protected _size = 0;\n\n constructor(...values: V[]) {\n for (const v of values) this.pushBack(v);\n }\n\n toJSON(): V[] {\n return Array.from(this.values());\n }\n\n forEach(method: (val: V) => boolean | any): number {\n let tmp: V | null = this._firstChild;\n let count = 0;\n while (tmp != null) {\n if (method(tmp) == false) {\n break;\n }\n count++;\n tmp = tmp.nextSibling;\n }\n return count;\n }\n\n equals(another: ValueList<V>, eqlFunc: (val1: V, val2: V) => boolean): boolean {\n if (this.size != another.size) return false;\n let tmp = this.first;\n let tmp2 = another.first;\n for (; tmp != null && tmp2 != null; tmp = tmp.nextSibling, tmp2 = tmp2.nextSibling) {\n if (!eqlFunc(tmp, tmp2)) {\n return false;\n }\n }\n return tmp == null && tmp2 == null;\n }\n\n get isEmpty(): boolean {\n return this._size == 0;\n }\n\n get size(): number {\n return this._size;\n }\n\n get first(): Nullable<V> {\n return this._firstChild;\n }\n\n get last(): Nullable<V> {\n return this._lastChild;\n }\n\n /**\n * Generator of values in reverse order.\n */\n *reversedValues(): Generator<V> {\n let tmp = this._lastChild;\n while (tmp != null) {\n yield tmp;\n tmp = tmp.prevSibling;\n }\n }\n\n /**\n * Generator of values in forward order.\n */\n *values(): Generator<V> {\n let tmp = this._firstChild;\n while (tmp != null) {\n yield tmp;\n tmp = tmp.nextSibling;\n }\n }\n\n add(child: V, before: Nullable<V> = null): this {\n // Ensure that this node is not added anywhere else\n if (child.nextSibling != null || child.prevSibling != null) {\n throw new Error(\"New node already added to a list. Remove it first\");\n }\n child.nextSibling = child.prevSibling = null;\n this._size++;\n if (this._firstChild == null || this._lastChild == null) {\n this._firstChild = this._lastChild = child;\n } else if (before == null) {\n child.prevSibling = this._lastChild;\n child.nextSibling = null;\n this._lastChild.nextSibling = child;\n this._lastChild = child;\n } else if (before == this._firstChild) {\n child.nextSibling = before;\n child.prevSibling = null;\n this._firstChild.prevSibling = child;\n this._firstChild = child;\n } else {\n const prev = before.prevSibling;\n child.nextSibling = before;\n before.prevSibling = child;\n child.prevSibling = prev;\n if (prev != null) {\n prev.nextSibling = child;\n }\n }\n return this;\n }\n\n pushFront(value: V): this {\n return this.add(value, this._firstChild);\n }\n\n pushBack(value: V): this {\n return this.add(value);\n }\n\n /**\n * Removes a child node from this list.\n * It is upto the caller to ensure that this node indeed belongs\n * to this list otherwise deletion of a non belonging node could result\n * in undefined behaviour.\n */\n remove(child: V): this {\n const next = child.nextSibling;\n const prev = child.prevSibling;\n\n if (next == null) {\n this._lastChild = prev;\n if (prev == null) this._firstChild = null;\n } else {\n next.prevSibling = prev;\n }\n\n if (prev == null) {\n this._firstChild = next;\n if (next == null) this._lastChild = null;\n } else {\n prev.nextSibling = next;\n }\n\n this._size--;\n\n child.prevSibling = child.nextSibling = null;\n return this;\n }\n\n popBack(): V {\n if (this._lastChild == null) {\n throw new Error(\"No children\");\n }\n const out = this._lastChild;\n this.remove(out);\n return out;\n }\n\n popFront(): V {\n if (this._firstChild == null) {\n throw new Error(\"No children\");\n }\n const out = this._firstChild;\n this.remove(out);\n return out;\n }\n}\n\n/**\n * A list implementation where the values themselves need to be wrapper in a list node.\n * If values already have sibling node properties they can be direclty used\n * via ValueLists.\n */\nexport class List<V> {\n private container: ValueList<MutableListNode<V>>;\n\n constructor(...values: V[]) {\n this.container = new ValueList<MutableListNode<V>>();\n for (const v of values) this.push(v);\n }\n\n toJSON(): V[] {\n return Array.from(this.values());\n }\n\n forEach(method: (val: V) => boolean | any): number {\n return this.container.forEach((v) => method(v.value));\n }\n\n equals(another: List<V>, eqlFunc: (val1: V, val2: V) => boolean): boolean {\n return this.container.equals(another.container, (a, b) => eqlFunc(a.value, b.value));\n }\n\n find(target: V): Nullable<MutableListNode<V>> {\n for (const v of this.container.values()) {\n if (target == v.value) {\n return v;\n }\n }\n return null;\n }\n\n get isEmpty(): boolean {\n return this.container.isEmpty;\n }\n\n get size(): number {\n return this.container.size;\n }\n\n get first(): Nullable<MutableListNode<V>> {\n return this.container.first;\n }\n\n get last(): Nullable<MutableListNode<V>> {\n return this.container.last;\n }\n\n /**\n * Generator of values in reverse order.\n */\n *reversedValues(): Generator<V> {\n for (const v of this.container.reversedValues()) yield v.value;\n }\n\n /**\n * Generator of values in forward order.\n */\n *values(): Generator<V> {\n for (const v of this.container.values()) yield v.value;\n }\n\n popBack(): V {\n return this.container.popBack().value;\n }\n\n popFront(): V {\n return this.container.popFront().value;\n }\n\n pushFront(value: V): this {\n return this.add(value, this.container.first);\n }\n\n push(value: V): this {\n return this.add(value);\n }\n\n add(child: V, before: Nullable<MutableListNode<V>> = null): this {\n this.container.add(new MutableListNode(child), before);\n return this;\n }\n}\n","declare let navigator: any;\nexport class Browser {\n static IS_EXPLORER = () => navigator && navigator.userAgent.indexOf(\"MSIE\") > -1;\n static IS_FIREFOX = () => navigator && navigator.userAgent.indexOf(\"Firefox\") > -1;\n static IS_OPERA = () => navigator && navigator.userAgent.toLowerCase().indexOf(\"op\") > -1;\n\n protected static UAHasChrome = () => navigator && navigator.userAgent.indexOf(\"Chrome\") > -1;\n protected static UAHasSafari = () => navigator && navigator.userAgent.indexOf(\"Safari\") > -1;\n static IS_SAFARI = () => navigator && Browser.UAHasSafari() && (!Browser.UAHasChrome() || !Browser.UAHasSafari());\n static IS_CHROME = () => navigator && Browser.UAHasChrome() && (!Browser.UAHasChrome() || !Browser.IS_OPERA());\n}\n","import { Nullable } from \"./types\";\n\nexport function range(start: number, end: Nullable<number> = null, incr: Nullable<number> = 1): number[] {\n if (end == null) {\n const absStart = Math.abs(start);\n const arr = Array.from({ length: absStart });\n if (start >= 0) {\n return arr.map((x, i) => i);\n } else {\n return arr.map((x, i) => i - (absStart - 1));\n }\n }\n const out: number[] = [];\n if (incr == null) {\n incr = 1;\n }\n incr = Math.abs(incr);\n if (start !== end) {\n if (start < end) {\n for (let i = start; i <= end; i += incr) {\n out.push(i);\n }\n } else {\n for (let i = start; i >= end; i -= incr) {\n out.push(i);\n }\n }\n }\n return out;\n}\n\nexport function gcdof(x: number, y: number): number {\n x = Math.abs(x);\n y = Math.abs(y);\n while (y > 0) {\n const t = y;\n y = x % y;\n x = t;\n }\n return x;\n}\n\nexport class Fraction {\n readonly num: number;\n readonly den: number;\n\n static readonly ZERO = new Fraction();\n static readonly ONE = new Fraction(1, 1);\n static readonly INFINITY = new Fraction(1, 0);\n\n constructor(num = 0, den = 1, factorized = false) {\n if (isNaN(num) || isNaN(den)) {\n throw new Error(`Invalid numerator(${num}) or denminator(${den})`);\n }\n if (factorized) {\n const gcd = gcdof(num, den);\n num /= gcd;\n den /= gcd;\n }\n this.num = num;\n this.den = den;\n }\n\n static parse(val: string, factorized = false): Fraction {\n const parts = val\n .trim()\n .split(\"/\")\n .map((x) => x.trim());\n let num = 1;\n let den = 1;\n if (parts.length == 1) num = parseInt(parts[0]);\n else if (parts.length != 2) {\n throw new Error(\"Invalid fraction string: \" + val);\n } else {\n if (parts[0].length > 0) {\n num = parseInt(parts[0]);\n }\n if (parts[1].length > 0) {\n den = parseInt(parts[1]);\n }\n }\n if (isNaN(num) || isNaN(den)) {\n throw new Error(\"Invalid fraction string: \" + val);\n }\n return new Fraction(num, den, factorized);\n }\n\n get isWhole(): boolean {\n return this.num % this.den == 0;\n }\n\n get isZero(): boolean {\n return this.num == 0;\n }\n\n get isInfinity(): boolean {\n return this.den == 0;\n }\n\n get isOne(): boolean {\n return this.num == this.den;\n }\n\n get ceil(): number {\n if (this.num % this.den == 0) {\n return this.num / this.den;\n } else {\n return 1 + Math.floor(this.num / this.den);\n }\n }\n\n get floor(): number {\n if (this.num % this.den == 0) {\n return this.num / this.den;\n } else {\n return Math.floor(this.num / this.den);\n }\n }\n\n plus(another: Fraction, factorized = false): Fraction {\n return new Fraction(this.num * another.den + this.den * another.num, this.den * another.den, factorized);\n }\n\n plusNum(another: number, factorized = false): Fraction {\n return new Fraction(this.num + this.den * another, this.den, factorized);\n }\n\n minus(another: Fraction, factorized = false): Fraction {\n return new Fraction(this.num * another.den - this.den * another.num, this.den * another.den, factorized);\n }\n\n minusNum(another: number, factorized = false): Fraction {\n return new Fraction(this.num - this.den * another, this.den, factorized);\n }\n\n times(another: Fraction, factorized = false): Fraction {\n return new Fraction(this.num * another.num, this.den * another.den, factorized);\n }\n\n timesNum(another: number, factorized = false): Fraction {\n return new Fraction(this.num * another, this.den, factorized);\n }\n\n divby(another: Fraction, factorized = false): Fraction {\n return new Fraction(this.num * another.den, this.den * another.num, factorized);\n }\n\n divbyNum(another: number, factorized = false): Fraction {\n return new Fraction(this.num, this.den * another, factorized);\n }\n\n /**\n * Returns another / this.\n */\n numDivby(another: number, factorized = false): Fraction {\n return new Fraction(this.den * another, this.num, factorized);\n }\n\n /**\n * Returns this % another\n */\n mod(another: Fraction): Fraction {\n // a (mod b) = a − b ⌊a / b⌋\n const d = this.divby(another);\n const floorOfD = Math.floor(d.num / d.den);\n return this.minus(another.timesNum(floorOfD));\n }\n\n /*\n * Returns this % another\n */\n modNum(another: number): Fraction {\n // a (mod b) = a − b ⌊a / b⌋\n const d = this.divbyNum(another);\n const floorOfD = Math.floor(d.num / d.den);\n return this.minusNum(another * floorOfD);\n }\n\n get inverse(): Fraction {\n return new Fraction(this.den, this.num);\n }\n\n get factorized(): Fraction {\n const gcd = gcdof(this.num, this.den);\n return new Fraction(this.num / gcd, this.den / gcd);\n }\n\n equals(another: Fraction): boolean {\n return this.num * another.den == this.den * another.num;\n }\n\n equalsNum(another: number): boolean {\n return this.num == this.den * another;\n }\n\n cmp(another: Fraction): number {\n return this.num * another.den - this.den * another.num;\n }\n\n cmpNum(another: number): number {\n return this.num - this.den * another;\n }\n\n isLT(another: Fraction): boolean {\n return this.cmp(another) < 0;\n }\n\n isLTE(another: Fraction): boolean {\n return this.cmp(another) <= 0;\n }\n\n isLTNum(another: number): boolean {\n return this.cmpNum(another) < 0;\n }\n\n isLTENum(another: number): boolean {\n return this.cmpNum(another) <= 0;\n }\n\n isGT(another: Fraction): boolean {\n return this.cmp(another) > 0;\n }\n\n isGTE(another: Fraction): boolean {\n return this.cmp(another) >= 0;\n }\n\n isGTNum(another: number): boolean {\n return this.cmpNum(another) > 0;\n }\n\n isGTENum(another: number): boolean {\n return this.cmpNum(another) >= 0;\n }\n\n toString(): string {\n return this.num + \"/\" + this.den;\n }\n\n static max(f1: Fraction, f2: Fraction): Fraction {\n return f1.cmp(f2) > 0 ? f1 : f2;\n }\n\n static min(f1: Fraction, f2: Fraction): Fraction {\n return f1.cmp(f2) < 0 ? f1 : f2;\n }\n}\n\n// Shortcut helper\nexport const Frac = (a = 0, b = 1, factorized = false): Fraction => new Fraction(a, b, factorized);\n","import * as TSU from \"@panyam/tsutils\";\nimport { Entity, TimedEntity } from \"./entity\";\n\n/**\n * Alias to TSU.Num.Fraction in tsutils.\n */\ntype Fraction = TSU.Num.Fraction;\nexport type CyclePosition = [number, number, number];\nexport type CycleIterator = Generator<[CyclePosition, Fraction]>;\n\nconst ZERO = TSU.Num.Fraction.ZERO;\nconst ONE = TSU.Num.Fraction.ONE;\n\n/**\n * A cursor that traverses through a Cycle's beats in a controlled manner.\n * Allows forward and backward navigation through the cycle.\n */\nexport class CycleCursor {\n /**\n * Creates a new CycleCursor.\n * @param cycle The Cycle to traverse\n * @param barIndex The starting bar index, defaults to 0\n * @param beatIndex The starting beat index within the bar, defaults to 0\n * @param instance The starting instance index within the beat, defaults to 0\n */\n constructor(\n public readonly cycle: Cycle,\n public barIndex = 0,\n public beatIndex = 0,\n public instance = 0,\n ) {}\n\n /**\n * Advances the cursor to the next beat and returns the current position and beat length.\n * @returns A tuple containing the current position and beat length\n */\n get next(): [CyclePosition, Fraction] {\n const currBar = this.cycle.bars[this.barIndex];\n const result: [CyclePosition, Fraction] = [\n [this.barIndex, this.beatIndex, this.instance],\n currBar.beatLengths[this.beatIndex],\n ];\n this.instance++;\n if (!currBar.beatCounts[this.beatIndex] || this.instance >= currBar.beatCounts[this.beatIndex]) {\n this.instance = 0;\n this.beatIndex++;\n if (this.beatIndex >= currBar.beatLengths.length) {\n this.beatIndex = 0;\n this.barIndex++;\n if (this.barIndex >= this.cycle.bars.length) {\n this.barIndex = 0;\n }\n }\n }\n return result;\n }\n\n /**\n * Moves the cursor to the previous beat and returns the current position and beat length.\n * @returns A tuple containing the current position and beat length\n */\n get prev(): [CyclePosition, Fraction] {\n const currBar = this.cycle.bars[this.barIndex];\n const result: [CyclePosition, Fraction] = [\n [this.barIndex, this.beatIndex, this.instance],\n currBar.beatLengths[this.beatIndex],\n ];\n // TODO - result should be set *after* decrementing if we had already\n // done a \"next\" before this otherwise user may have to do a prev twice\n this.instance--;\n if (this.instance < 0) {\n this.beatIndex--;\n if (this.beatIndex < 0) {\n this.barIndex--;\n if (this.barIndex < 0) {\n this.barIndex = this.cycle.bars.length - 1;\n }\n this.beatIndex = this.cycle.bars[this.barIndex].beatCount - 1;\n }\n this.instance = (this.cycle.bars[this.barIndex].beatCounts[this.beatIndex] || 1) - 1;\n }\n return result;\n }\n}\n\n/**\n * Represents a bar in a musical cycle.\n * A bar consists of beats with specific lengths and counts.\n */\nexport class Bar extends TimedEntity {\n readonly TYPE: string = \"Bar\";\n\n /** Name of the bar (e.g., \"Laghu\", \"Dhrutam\") */\n name: string;\n\n /** Length/Duration of each beat in the bar */\n beatLengths: Fraction[] = [];\n\n /** How many times each beat should be repeated (the Kalai) */\n beatCounts: number[] = [];\n\n /**\n * Creates a new Bar.\n * @param config Configuration object containing name, beatLengths, and beatCounts\n */\n constructor(config: any = null) {\n super((config = config || {}));\n this.name = config.name || \"\";\n for (const bl of config.beatLengths || []) {\n if (typeof bl === \"number\") {\n this.beatLengths.push(TSU.Num.Frac(bl));\n } else {\n this.beatLengths.push(bl);\n }\n }\n for (const bc of config.beatCounts || []) {\n this.beatCounts.push(bc);\n }\n while (this.beatCounts.length < this.beatLengths.length) {\n this.beatCounts.push(1);\n }\n }\n\n /**\n * Returns a debug-friendly representation of this Bar.\n * @returns An object containing debug information\n */\n debugValue(): any {\n return { ...super.debugValue(), name: name, beatLengths: this.beatLengths };\n }\n\n /**\n * Checks if this Bar is equal to another Bar.\n * @param another The Bar to compare with\n * @returns True if the Bars are equal, false otherwise\n */\n equals(another: this): boolean {\n if (!super.equals(another)) return false;\n if (this.beatLengths.length != another.beatLengths.length) return false;\n if (this.beatCounts.length != another.beatCounts.length) return false;\n for (let i = 0; i < this.beatLengths.length; i++) {\n if (!this.beatLengths[i].equals(another.beatLengths[i])) return false;\n }\n for (let i = 0; i < this.beatCounts.length; i++) {\n if (this.beatCounts[i] != another.beatCounts[i]) return false;\n }\n return true;\n }\n\n /**\n * Copies the properties of this Bar to another Bar.\n * @param another The target Bar to copy properties to\n */\n copyTo(another: this): void {\n super.copyTo(another);\n another.name = this.name;\n another.beatLengths = [...this.beatLengths];\n another.beatCounts = [...this.beatCounts];\n }\n\n /**\n * Gets the instance count for a specific beat in the bar.\n * @param beatIndex The index of the beat\n * @returns The number of instances for the specified beat\n */\n instanceCount(beatIndex: number): number {\n if (beatIndex > this.beatCounts.length) {\n // by default each beat has 1 instance?\n return 1;\n } else {\n return this.beatCounts[beatIndex];\n }\n }\n\n /**\n * Gets the number of unique beats in this bar (irrespective of instances).\n */\n get beatCount(): number {\n return this.beatLengths.length;\n }\n\n /**\n * Gets the total number of beat instances in this bar.\n */\n get totalBeatCount(): number {\n let out = 0;\n for (let i = 0; i < this.beatLengths.length; i++) {\n out += this.beatCounts[i] || 1;\n }\n return out;\n }\n\n /**\n * Gets the total duration of time across all beats in this bar.\n */\n get duration(): Fraction {\n let total = ZERO;\n for (let i = 0; i < this.beatLengths.length; i++) {\n total = total.plus(this.beatLengths[i].timesNum(this.beatCounts[i] || 1));\n }\n return total;\n }\n}\n\n/**\n * Represents a complete rhythmic cycle pattern composed of bars.\n * In carnatic music, this typically represents a tala.\n */\nexport class Cycle extends TimedEntity {\n readonly TYPE: string = \"Cycle\";\n\n /** Name of the cycle (e.g., \"Adi Thalam\") */\n name: string;\n\n /** The bars that make up this cycle */\n bars: Bar[];\n\n /**\n * Default cycle representing Adi Thalam (4+2+2 structure).\n */\n static readonly DEFAULT = new Cycle({\n name: \"Adi Thalam\",\n bars: [\n new Bar({ name: \"Laghu\", beatLengths: [1, 1, 1, 1] }),\n new Bar({ name: \"Dhrutam\", beatLengths: [1, 1] }),\n new Bar({ name: \"Dhrutam\", beatLengths: [1, 1] }),\n ],\n });\n\n /**\n * Creates a new Cycle.\n * @param config Configuration object containing name and bars\n */\n constructor(config: null | { name?: string; bars?: Bar[] } = null) {\n super((config = config || {}));\n this.name = config.name || \"\";\n this.bars = config.bars || [];\n }\n\n /**\n * Returns a debug-friendly representation of this Cycle.\n * @returns An object containing debug information\n */\n debugValue(): any {\n return { ...super.debugValue(), name: name, bars: this.bars.map((p) => p.debugValue()) };\n }\n\n /**\n * Gets all child entities of this Cycle.\n * @returns An array of child entities (bars)\n */\n children(): Entity[] {\n return this.bars;\n }\n\n /**\n * Checks if this Cycle is equal to another Cycle.\n * @param another The Cycle to compare with\n * @returns True if the Cycles are equal, false otherwise\n */\n equals(another: this): boolean {\n if (!super.equals(another)) {\n return false;\n }\n if (this.bars.length != another.bars.length) return false;\n for (let i = 0; i < this.bars.length; i++) {\n if (!this.bars[i].equals(another.bars[i])) return false;\n }\n return true;\n }\n\n /**\n * Given a global beat index, returns the position within the cycle.\n *\n * @param globalIndex The global beat index\n * @returns A tuple containing [cycle number, position, start offset]\n * - cycle: The nth cycle in which the beat lies\n * - position: [barIndex, beatIndex, instance] within the cycle\n * - startOffset: Offset of the beat at this global index\n */\n getAtIndex(globalIndex: number): [number, CyclePosition, Fraction] {\n let cycle = 0;\n while (globalIndex < 0) {\n globalIndex += this.totalBeatCount;\n cycle--;\n }\n if (globalIndex >= this.totalBeatCount) {\n cycle = Math.floor(globalIndex / this.totalBeatCount);\n }\n globalIndex = globalIndex % this.totalBeatCount;\n let offset = ZERO;\n for (let barIndex = 0; barIndex < this.bars.length; barIndex++) {\n const bar = this.bars[barIndex];\n if (globalIndex >= bar.totalBeatCount) {\n globalIndex -= bar.totalBeatCount;\n offset = offset.plus(bar.duration);\n } else {\n // this is the bar!\n for (let beatIndex = 0; beatIndex < bar.beatCount; beatIndex++) {\n const beatLength = bar.beatLengths[beatIndex];\n const beatCount = bar.beatCounts[beatIndex] || 1;\n if (globalIndex >= beatCount) {\n globalIndex -= beatCount;\n offset = offset.plus(beatLength.timesNum(beatCount));\n } else {\n // this is it\n const instance = globalIndex;\n return [cycle, [barIndex, beatIndex, instance], offset.plus(beatLength.timesNum(instance))];\n }\n }\n }\n }\n throw new Error(\"Should not be here!\");\n }\n\n /**\n * Given a global offset, returns the position within the cycle.\n *\n * @param globalOffset The global time offset\n * @returns A tuple containing [cycle number, position, note offset, global index]\n * - cycle: The nth cycle in which the offset lies\n * - position: [barIndex, beatIndex, instance] within the cycle\n * - startOffset: The note offset within the beat\n * - globalIndex: The beat index within the entire cycle\n */\n getPosition(globalOffset: Fraction): [number, CyclePosition, Fraction, number] {\n const duration = this.duration;\n let cycleNum = 0;\n if (globalOffset.isLT(ZERO)) {\n while (globalOffset.isLT(ZERO)) {\n cycleNum--;\n globalOffset = globalOffset.plus(duration);\n }\n } else if (globalOffset.isGTE(duration)) {\n const realOffset = globalOffset.mod(duration);\n globalOffset = globalOffset.minus(realOffset).divby(duration);\n TSU.assert(globalOffset.isWhole);\n cycleNum = globalOffset.floor;\n globalOffset = realOffset;\n }\n\n // here globalOffset is positive and >= 0 and < this.duration\n let globalIndex = 0;\n for (let barIndex = 0; barIndex < this.bars.length; barIndex++) {\n const bar = this.bars[barIndex];\n const barDuration = bar.duration;\n if (globalOffset.isGTE(barDuration)) {\n globalOffset = globalOffset.minus(barDuration);\n } else {\n // this is the bar!\n for (let beatIndex = 0; beatIndex < bar.beatCount; beatIndex++) {\n const beatLength = bar.beatLengths[beatIndex];\n const beatCount = bar.beatCounts[beatIndex] || 1;\n for (let instance = 0; instance < beatCount; instance++, globalIndex++) {\n if (globalOffset.isGTE(beatLength)) {\n globalOffset = globalOffset.minus(beatLength);\n } else {\n // this is it\n return [cycleNum, [barIndex, beatIndex, instance], globalOffset, globalIndex];\n }\n }\n }\n }\n globalIndex += bar.totalBeatCount;\n }\n\n throw new Error(\"Should not be here!\");\n }\n\n /**\n * Creates an iterator that yields beats in sequence from a starting position.\n *\n * @param startBar The starting bar index, defaults to 0\n * @param startBeat The starting beat index, defaults to 0\n * @param startInstance The starting instance index, defaults to 0\n * @returns A generator that yields [position, beat length] pairs\n */\n *iterateBeats(startBar = 0, startBeat = 0, startInstance = 0): CycleIterator {\n let barIndex = startBar;\n let beatIndex = startBeat;\n let instanceIndex = startInstance;\n while (true) {\n const currBar = this.bars[barIndex];\n yield [[barIndex, beatIndex, instanceIndex], currBar.beatLengths[beatIndex]];\n instanceIndex++;\n if (!currBar.beatCounts[beatIndex] || instanceIndex >= currBar.beatCounts[beatIndex]) {\n instanceIndex = 0;\n beatIndex++;\n if (beatIndex >= currBar.beatLengths.length) {\n beatIndex = 0;\n barIndex++;\n if (barIndex >= this.bars.length) {\n barIndex = 0;\n }\n }\n }\n }\n }\n\n /**\n * Copies the properties of this Cycle to another Cycle.\n * @param another The target Cycle to copy properties to\n */\n copyTo(another: this): void {\n super.copyTo(another);\n another.name = this.name;\n another.bars = this.bars.map((x) => x.clone());\n }\n\n /**\n * Gets the number of unique beats in this cycle (irrespective of instances).\n */\n get beatCount(): number {\n let out = 0;\n for (const bar of this.bars) out += bar.beatCount;\n return out;\n }\n\n /**\n * Gets the total number of beat instances in this cycle.\n */\n get totalBeatCount(): number {\n let out = 0;\n for (const bar of this.bars) out += bar.totalBeatCount;\n return out;\n }\n\n /**\n * Gets the total duration of time across all bars in this cycle.\n */\n get duration(): Fraction {\n return this.bars.reduce((x, y) => x.plus(y.duration), ZERO);\n }\n}\n","import * as TSU from \"@panyam/tsutils\";\nimport { Entity, TimedEntity } from \"./entity\";\nimport { LayoutParams } from \"./layouts\";\n\n/**\n * Alias to TSU.Num.Fraction in tsutils.\n */\ntype Fraction = TSU.Num.Fraction;\nexport const ZERO = TSU.Num.Fraction.ZERO;\nexport const ONE = TSU.Num.Fraction.ONE;\n\n/**\n * AtomType enums are used to denote specific Atoms\n * Each type represents a specific musical or notational element.\n * @enum\n */\nexport enum AtomType {\n NOTE = \"Note\",\n LITERAL = \"Literal\",\n SYLLABLE = \"Syllable\",\n SPACE = \"Space\",\n GROUP = \"Group\",\n LABEL = \"Label\",\n REST = \"Rest\",\n MARKER = \"Marker\",\n}\n\n/**\n * Atoms are the base class for all timed entities that can appear in a Notation.\n * An Atom represents the fundamental building block of the notation system.\n */\nexport abstract class Atom extends TimedEntity {\n readonly TYPE: string = \"Atom\";\n\n protected _duration: Fraction;\n /** Markers to be displayed before this atom */\n markersBefore: Marker[];\n /** Markers to be displayed after this atom */\n markersAfter: Marker[];\n /** Next atom in the sequence */\n nextSibling: TSU.Nullable<Atom> = null;\n /** Previous atom in the sequence */\n prevSibling: TSU.Nullable<Atom> = null;\n /** The Group this Atom belongs to, if any */\n parentGroup: TSU.Nullable<Group> = null;\n\n /** Indicates if this Atom is a continuation from a previous atom */\n isContinuation = false;\n\n /**\n * Creates a new Atom with the specified duration.\n * @param duration The duration of the atom, defaults to ONE (1/1)\n */\n constructor(duration = ONE) {\n super();\n this._duration = duration || ONE;\n }\n\n /**\n * Splits this atom at the specified duration.\n * @param requiredDuration The duration at which to split the atom\n * @returns A new atom representing the portion beyond the split point, or null if no split is needed\n */\n abstract splitAt(requiredDuration: Fraction): TSU.Nullable<Atom>;\n\n /**\n * Returns a debug-friendly representation of this Atom.\n * @returns An object containing debug information\n */\n debugValue(): any {\n const out = super.debugValue();\n if (!this.duration.isOne) {\n out.duration = this.duration.factorized.toString();\n }\n if (this.isContinuation) {\n out.isContinuation = true;\n }\n if ((this.markersBefore || []).length > 0) {\n out.mbef = this.markersBefore.map((m) => m.debugValue());\n }\n if ((this.markersAfter || []).length > 0) {\n out.maft = this.markersAfter.map((m) => m.debugValue());\n }\n return out;\n }\n\n /**\n * Copies the properties of this atom to another atom.\n * @param another The target atom to copy properties to\n */\n copyTo(another: this): void {\n super.copyTo(another);\n another._duration = new TSU.Num.Fraction(this.duration.num, this.duration.den);\n }\n\n /**\n * Gets the duration of this atom.\n */\n get duration(): Fraction {\n return this._duration;\n }\n\n /**\n * Sets the duration of this atom.\n */\n set duration(d: Fraction) {\n this._duration = d;\n }\n}\n\n/**\n * Base class for atoms that cannot contain other atoms.\n * LeafAtom represents atomic elements that can't be further subdivided.\n */\nexport abstract class LeafAtom extends Atom {\n readonly TYPE: string = \"LeafAtom\";\n\n /** Indicates if this atom is followed by a rest */\n beforeRest = false;\n\n /**\n * Splits this atom at a certain duration.\n * If this atom's duration is longer than the given duration, it's truncated\n * to the given duration and a continuation space is returned.\n *\n * @param duration The duration at which to split the atom\n * @returns A new Space atom representing the spillover if needed, otherwise null\n */\n splitAt(duration: Fraction): TSU.Nullable<Atom> {\n if (this.duration.cmp(duration) > 0) {\n const spillOver = this.createSpilloverSpace(this.duration.minus(duration));\n spillOver.isContinuation = true;\n this.duration = duration;\n // TODO - Here we need to move the markersAfter to the spill-over as it doesnt belong to this any more\n return spillOver;\n }\n return null;\n }\n\n /**\n * Creates a Space atom to represent spillover duration when splitting.\n * @param duration The duration of the spillover\n * @returns A new Space atom\n */\n protected createSpilloverSpace(duration: Fraction): Space {\n return new Space(duration);\n }\n\n /**\n * Returns a debug-friendly representation of this LeafAtom.\n * @returns An object containing debug information\n */\n debugValue(): any {\n return this.beforeRest ? { ...super.debugValue(), beforeRest: true } : super.debugValue();\n }\n}\n\n/**\n * Represents a marker or annotation in the notation.\n * Markers can be placed before or after atoms to provide additional context.\n */\nexport class Marker extends Entity {\n readonly TYPE = \"Marker\";\n\n /**\n * Creates a new Marker with the specified text.\n * @param text The text content of the marker\n * @param isBefore Whether the marker should appear before (true) or after (false) its associated atom\n */\n constructor(\n public text: string,\n public isBefore = true,\n ) {\n super();\n }\n\n /**\n * Returns a debug-friendly representation of this Marker.\n * @returns An object containing debug information\n */\n debugValue(): any {\n return { ...super.debugValue(), text: this.text, before: this.isBefore };\n }\n\n /**\n * Returns a string representation of this Marker.\n * @returns A string representation\n */\n toString(): string {\n return `Marker(${this.text}-${this.isBefore})`;\n }\n}\n\n/**\n * Represents a rest (silence) in the notation.\n * Rests are zero-length atoms that indicate a pause.\n */\nexport class Rest extends LeafAtom {\n readonly TYPE = \"Rest\";\n\n /**\n * Creates a new Rest.\n * Rests are zero length by default.\n */\n constructor() {\n super(ZERO);\n }\n}\n\n/**\n * Represents a space or silence in the notation.\n * Spaces can be used to denote either silence or continuations of previous notes.\n */\nexport class Space extends LeafAtom {\n readonly TYPE = \"Space\";\n\n /**\n * Indicates whether this is a silent space or a continuation of the previous note.\n */\n isSilent = false;\n\n /**\n * Creates a new Space with the specified duration and silence property.\n * @param duration The duration of the space, defaults to ONE (1/1)\n * @param isSilent Whether the space represents silence (true) or a continuation (false)\n */\n constructor(duration = ONE, isSilent = false) {\n super(duration);\n this.isSilent = isSilent;\n }\n\n /**\n * Returns a debug-friendly representation of this Space.\n * @returns An object containing debug information\n */\n debugValue(): any {\n return { ...super.debugValue(), isSilent: this.isSilent };\n }\n\n /**\n * Returns a string representation of this Space.\n * @returns A string representation\n */\n toString(): string {\n return `Space(${this.duration}-${this.isSilent})`;\n }\n\n /**\n * Copies the properties of this Space to another Space.\n * @param another The target Space to copy properties to\n */\n copyTo(another: this): void {\n super.copyTo(another);\n another.isSilent = this.isSilent;\n }\n\n /**\n * Checks if this Space is equal to another Space.\n * @param another The Space to compare with\n * @returns True if the Spaces are equal, false otherwise\n */\n equals(another: this): boolean {\n return super.equals(another) && this.isSilent == another.isSilent;\n }\n\n /**\n * Creates a Space atom to represent spillover duration when splitting.\n * @param duration The duration of the spillover\n * @returns A new Space atom with the same silence property as this Space\n */\n protected createSpilloverSpace(duration: Fraction): Space {\n const out = super.createSpilloverSpace(duration);\n out.isSilent = this.isSilent;\n return out;\n }\n}\n\n/**\n * Represents a literal value in the notation.\n * Literals are the basic building blocks for notes and syllables.\n */\nexport class Literal extends LeafAtom {\n readonly TYPE: string = \"Literal\";\n\n /**\n * The embellishments applied to this Literal.\n */\n embelishments: any[] = [];\n\n /**\n * Creates a new Literal with the specified value and duration.\n * @param value The string value of the literal\n * @param duration The duration of the literal, defaults to ONE (1/1)\n */\n constructor(\n public value: string,\n duration = ONE,\n ) {\n super(duration);\n }\n\n /**\n * Returns a debug-friendly representation of this Literal.\n * @returns An object containing debug information\n */\n debugValue(): any {\n const out = { ...super.debugValue(), value: this.value };\n if (this.embelishments.length > 0) {\n out.embs = this.embelishments.map((e) => (\"debugValue\" in e ? e.debugValue() : e));\n }\n return out;\n }\n\n /**\n * Returns a string representation of this Literal.\n * @returns A string representation\n */\n toString(): string {\n return `Lit(${this.duration}-${this.value})`;\n }\n\n /**\n * Checks if this Literal is equal to another Literal.\n * @param another The Literal to compare with\n * @returns True if the Literals are equal, false otherwise\n */\n equals(another: this): boolean {\n return super.equals(another) && this.value == another.value;\n }\n\n /**\n * Copies the properties of this Literal to another Literal.\n * @param another The target Literal to copy properties to\n */\n copyTo(another: this): void {\n super.copyTo(another);\n another.value = this.value;\n }\n}\n\n/**\n * Represents a syllable in lyrics or text to be sung.\n * Extends Literal to provide specialized handling for sung text.\n */\nexport class Syllable extends Literal {\n readonly TYPE = \"Syllable\";\n\n /**\n * Creates a Syllable from a Literal.\n * @param lit The Literal to convert to a Syllable\n * @returns A new Syllable with the properties of the Literal\n */\n static fromLit(lit: Literal): Syllable {\n if (lit.TYPE == AtomType.SYLLABLE) return lit as Syllable;\n const out = new Syllable(lit.value, lit.duration);\n out.embelishments = lit.embelishments;\n out.beforeRest = lit.beforeRest;\n return out;\n }\n\n /**\n * Returns a string representation of this Syllable.\n * @returns A string representation\n */\n toString(): string {\n return `Syll(${this.duration}-${this.value})`;\n }\n}\n\n/**\n * Represents a musical note in the notation.\n * Extends Literal to add properties specific to musical notes.\n */\nexport class Note extends Literal {\n readonly TYPE = \"Note\";\n\n /**\n * Which octave the note is in. Can be positive or negative to indicate higher or lower octaves.\n */\n octave = 0;\n\n /**\n * How the note is shifted - i.e., shifted towards major or minor by # of semi-tones.\n */\n shift: number | boolean = 0;\n\n /**\n * Creates a new Note with the specified properties.\n * @param value The string value of the note\n * @param duration The duration of the note, defaults to ONE (1/1)\n * @param octave The octave of the note, defaults to 0\n * @param shift The shift of the note, defaults to 0\n */\n constructor(value: string, duration = ONE, octave = 0, shift = 0) {\n super(value, duration);\n this.octave = octave;\n this.shift = shift;\n }\n\n /**\n * Creates a Note from a Literal.\n * @param lit The Literal to convert to a Note\n * @returns A new Note with the properties of the Literal\n */\n static fromLit(lit: Literal): Note {\n if (lit.TYPE == AtomType.NOTE) return lit as Note;\n const out = new Note(lit.value, lit.duration);\n out.embelishments = lit.embelishments;\n out.beforeRest = lit.beforeRest;\n return out;\n }\n\n /**\n * Returns a debug-friendly representation of this Note.\n * @returns An object containing debug information\n */\n debugValue(): any {\n const out = { ...super.debugValue() };\n if (this.octave != 0) out.octave = this.octave;\n if (this.shift != 0) out.shift = this.shift;\n return out;\n }\n\n /**\n * Returns a string representation of this Note.\n * @returns A string representation\n */\n toString(): string {\n return `Note(${this.duration}-${this.value}-${this.octave})`;\n }\n\n /**\n * Checks if this Note is equal to another Note.\n * @param another The Note to compare with\n * @returns True if the Notes are equal, false otherwise\n */\n equals(another: this): boolean {\n return super.equals(another) && this.octave == another.octave && this.shift == another.shift;\n }\n\n /**\n * Copies the properties of this Note to another Note.\n * @param another The target Note to copy properties to\n */\n copyTo(another: this): void {\n super.copyTo(another);\n another.octave = this.octave;\n another.shift = this.shift;\n }\n}\n\n/**\n * Represents a group of atoms that are treated as a single unit.\n * Groups can contain any number of atoms, including other groups.\n */\nexport class Group extends Atom {\n readonly TYPE = \"Group\";\n\n /**\n * Indicates whether the duration is static or linear to the number of atoms in this group.\n * When true, the duration is used as a multiplier for the total child duration.\n * When false, the duration is absolute.\n */\n durationIsMultiplier = false;\n\n /**\n * The list of atoms in this group.\n */\n readonly atoms = new TSU.Lists.ValueList<Atom>();\n\n /**\n * Creates a new Group containing the specified atoms.\n * @param atoms The atoms to include in this group\n */\n constructor(...atoms: Atom[]) {\n super(atoms.length == 0 ? ZERO : ONE);\n this.addAtoms(false, ...atoms);\n }\n\n /**\n * Checks if this Group is equal to another Group.\n * @param another The Group to compare with\n * @param expect Optional parameter\n * @returns True if the Groups are equal, false otherwise\n */\n equals(another: this, expect = false): boolean {\n if (!super.equals(another)) return false;\n return this.atoms.equals(another.atoms, (a1, a2) => a1.equals(a2));\n }\n\n /**\n * Copies the properties of this Group to another Group.\n * @param another The target Group to copy properties to\n */\n copyTo(another: this): void {\n super.copyTo(another);\n another.durationIsMultiplier = this.durationIsMultiplier;\n this.atoms.forEach((atom) => another.atoms.add(atom.clone()));\n }\n\n /**\n * Gets the duration of this group.\n * If durationIsMultiplier is true, returns the total child duration divided by the multiplier.\n * Otherwise, returns the absolute duration.\n */\n get duration(): Fraction {\n if (this.durationIsMultiplier) {\n return this.totalChildDuration.divby(this._duration);\n } else {\n return this._duration;\n }\n }\n\n /**\n * Sets this group to use a multiplier for duration calculations.\n * @param asMultiplier Whether to use the duration as a multiplier\n * @returns This Group instance for method chaining\n */\n setDurationAsMultiplier(asMultiplier = true): this {\n this.durationIsMultiplier = asMultiplier;\n return this;\n }\n\n /**\n * Sets the duration of this group.\n * @param d The new duration\n * @param asMultiplier Whether to use the duration as a multiplier\n * @returns This Group instance for method chaining\n */\n setDuration(d: Fraction, asMultiplier = false): this {\n this._duration = d;\n this.durationIsMultiplier = asMultiplier;\n return this;\n }\n\n /**\n * Returns a debug-friendly representation of this Group.\n * @returns An object containing debug information\n */\n debugValue(): any {\n const out = { ...super.debugValue(), atoms: Array.from(this.atoms.values(), (a) => a.debugValue()) };\n if (this.durationIsMultiplier) out.durationIsMultiplier = true;\n return out;\n }\n\n /**\n * Splits this group into two parts.\n * The first part (this group) fits within the given duration and everything else\n * longer than the given duration is returned as a new Group.\n *\n * @param requiredDuration The duration at which to split the group\n * @returns A new Group containing the atoms beyond the split point, or null if no split is needed\n */\n splitAt(requiredDuration: Fraction): TSU.Nullable<Group> {\n if (this.duration.isLTE(requiredDuration) || requiredDuration.isLTE(ZERO)) {\n return null;\n }\n const targetGroup = new Group();\n if (this.durationIsMultiplier) {\n targetGroup.durationIsMultiplier = true;\n targetGroup._duration = this._duration;\n }\n\n let remainingDur = this.duration;\n const totalChildDuration = this.totalChildDuration;\n const durationFactor = this.durationIsMultiplier\n ? ONE.divby(this._duration)\n : this._duration.divby(totalChildDuration, true);\n while (remainingDur.isGT(requiredDuration) && this.atoms.last) {\n const lastChild = this.atoms.last;\n // Child's duration is absolute in its own \"system\"\n // Its duration within the parent (this) group's frame of reference depends\n // on whether the parent's duration is absolute or as a multiplier\n //\n // realChildDuration = case (group.durationIsMultiper) {\n // | true => child.duration / this._duration\n // | false => child.duration * this._duration / total child duration\n // }\n const childDuration = lastChild.duration.times(durationFactor);\n const newDuration = remainingDur.minus(childDuration);\n if (newDuration.isGTE(requiredDuration)) {\n // remove ourselves and add to target\n // in both cases duration will be adjusted if need be\n this.removeAtoms(true, lastChild);\n targetGroup.insertAtomsAt(targetGroup.atoms.first, true, lastChild);\n if (newDuration.equals(requiredDuration)) {\n // we have reached the end so return\n return targetGroup;\n }\n } else {\n // our scenario is now this:\n //\n // totalParentDuration = 10\n // required = 8\n // lastChildDuration (relative to parent) is 5\n //\n // durWithoutLast = 10 - 5\n // newRequired = requiredDur - durWithoutLast = 3\n //\n // However 3 is a duration in the parent's frame of reference\n // this has to be converted back to the child's FoR\n const newRequiredDur = requiredDuration.minus(newDuration, true).divby(durationFactor, true);\n // console.log( \"newRequiredDur: \", newRequiredDur, \"requiedDur: \", requiredDuration, \"remainingDur: \", remainingDur,);\n // then the last item needs to be split, and by how much?\n const spillOver = lastChild.splitAt(newRequiredDur);\n if (spillOver == null) {\n throw new Error(\"Spill over cannot be null here\");\n }\n if (!this.durationIsMultiplier) {\n // Our own duration has also now changed\n this._duration = requiredDuration;\n } else {\n if (this._duration.isZero) throw new Error(\"How can this be?\");\n }\n spillOver.isContinuation = true;\n // Add spill over to the target\n targetGroup.insertAtomsAt(targetGroup.atoms.first, true, spillOver);\n return targetGroup;\n }\n remainingDur = newDuration;\n }\n return targetGroup;\n }\n\n /**\n * Gets the total duration of all child atoms.\n * @returns The sum of durations of all atoms in this group\n */\n get totalChildDuration(): Fraction {\n let out = ZERO;\n this.atoms.forEach((atom) => (out = out.plus(atom.duration)));\n return out;\n }\n\n /**\n * Inserts atoms before a given cursor atom.\n * If the cursor atom is null, the atoms are appended at the end.\n *\n * @param beforeAtom The atom before which to insert the new atoms, or null to append\n * @param adjustDuration Whether to adjust this group's duration based on the new atoms\n * @param atoms The atoms to insert\n * @returns This Group instance for method chaining\n */\n insertAtomsAt(beforeAtom: TSU.Nullable<Atom>, adjustDuration = false, ...atoms: Atom[]): this {\n adjustDuration = adjustDuration && !this.durationIsMultiplier;\n const oldChildDuration = adjustDuration ? this.totalChildDuration : ONE;\n // First form a chain of the given atoms\n for (const atom of atoms) {\n if (atom.parentGroup != null) {\n if (atom.parentGroup != this) {\n throw new Error(\"Atom belongs to another parent. Remove it first\");\n }\n atom.parentGroup.removeAtoms(false, atom);\n }\n if (atom.TYPE == AtomType.REST) {\n const last = this.atoms.last;\n if (last && last.TYPE != AtomType.GROUP && last.TYPE != AtomType.LABEL) {\n (last as LeafAtom).beforeRest = true;\n }\n } else {\n atom.parentGroup = this;\n this.atoms.add(atom, beforeAtom);\n }\n }\n if (adjustDuration) {\n if (this._duration.isZero) {\n if (this.durationIsMultiplier) throw new Error(\"How can this be?\");\n this._duration = this.totalChildDuration;\n } else {\n const scaleFactor = this.totalChildDuration.divby(oldChildDuration);\n this._duration = this._duration.times(scaleFactor, true);\n }\n }\n return this;\n }\n\n /**\n * Adds atoms to the end of this group's atom list.\n *\n * @param adjustDuration Whether to adjust this group's duration based on the new atoms\n * @param atoms The atoms to add\n * @returns This Group instance for method chaining\n */\n addAtoms(adjustDuration = false, ...atoms: Atom[]): this {\n return this.insertAtomsAt(null, adjustDuration, ...atoms);\n }\n\n /**\n * Removes atoms from this group's child list.\n *\n * @param adjustDuration Whether to adjust this group's duration after removing atoms\n * @param atoms The atoms to remove\n * @returns This Group instance for method chaining\n */\n removeAtoms(adjustDuration = false, ...atoms: Atom[]): this {\n adjustDuration = adjustDuration && !this.durationIsMultiplier;\n const oldChildDuration = adjustDuration ? this.totalChildDuration : ONE;\n for (const atom of atoms) {\n if (atom.parentGroup == this) {\n this.atoms.remove(atom);\n atom.parentGroup = null;\n } else if (atom.parentGroup != null) {\n throw new Error(\"Atom cannot be removed as it does not belong to this group\");\n }\n }\n if (adjustDuration) {\n if (this._duration.isZero) {\n if (this.durationIsMultiplier) throw new Error(\"How can this be?\");\n this._duration = this.totalChildDuration;\n } else {\n const scaleFactor = this.totalChildDuration.divby(oldChildDuration);\n this._duration = this._duration.times(scaleFactor, true);\n }\n }\n return this;\n }\n}\n\n/**\n * Represents a line of notation containing multiple roles.\n * A line can have atoms starting before or after the cycle.\n */\nexport class Line extends Entity {\n readonly TYPE: string = \"Line\";\n\n /**\n * Offset tells how many notes before or after the cycle this line's atoms start at.\n */\n offset: Fraction = ZERO;\n\n /**\n * The roles contained in this line.\n */\n roles: Role[] = [];\n\n /**\n * Text to be displayed in the margin of the line.\n * This is a hacky solution to doing left side pre-margin text typically\n * found in notations - e.g., line X of a pallavi has this. This makes vertical\n * space less wasteful.\n *\n * A better solution is inter-beat annotation but it is very complex for now.\n */\n marginText = \"\";\n\n /**\n * The LayoutParams associated with this line.\n */\n layoutParams: LayoutParams;\n\n /**\n * Finds the index of a role with the given name.\n * @param name The name of the role to find\n * @returns The index of the role, or -1 if not found\n */\n indexOfRole(name: string): number {\n for (let i = 0; i < this.roles.length; i++) {\n if (this.roles[i].name == name) return i;\n }\n return -1;\n }\n\n /**\n * Checks if this line is empty (has no content in any role).\n */\n get isEmpty(): boolean {\n for (const r of this.roles) if (!r.isEmpty) return false;\n return true;\n }\n\n /**\n * Returns a debug-friendly representation of this Line.\n * @returns An object containing debug information\n */\n debugValue(): any {\n const out = {\n ...super.debugValue(),\n roles: this.roles.map((r) => r.debugValue()),\n };\n if (!this.offset.isZero) {\n out.offset = this.offset.toString();\n }\n return out;\n }\n\n /**\n * Copies the properties of this Line to another Line.\n * @param another The target Line to copy properties to\n */\n copyTo(another: this): void {\n super.copyTo(another);\n another.roles = this.roles.map((r) => r.clone());\n }\n\n /**\n * Adds atoms to a role in this line.\n * @param roleName The name of the role to add atoms to\n * @param defaultToNotes Whether to default to notes for this role\n * @param atoms The atoms to add\n * @returns This Line instance for method chaining\n */\n addAtoms(roleName: string, defaultToNotes: boolean, ...atoms: Atom[]): this {\n const role = this.ensureRole(roleName, defaultToNotes);\n role.addAtoms(...atoms);\n return this;\n }\n\n /**\n * Ensures a role with the given name exists in this line, creating it if needed.\n * @param roleName The name of the role to ensure\n * @param defaultToNotes Whether to default to notes for this role\n * @returns The role with the specified name\n */\n ensureRole(roleName: string, defaultToNotes: boolean): Role {\n // Ensure we have this many roles\n let ri = this.roles.findIndex((r) => r.name == roleName);\n if (ri < 0) {\n ri = this.roles.length;\n const role = new Role(this, roleName);\n role.defaultToNotes = defaultToNotes;\n this.roles.push(role);\n }\n return this.roles[ri];\n }\n\n /**\n * Gets the maximum duration across all roles in this line.\n */\n get duration(): Fraction {\n let max = ZERO;\n for (const role of this.roles) {\n max = TSU.Num.Fraction.max(role.duration, max);\n }\n return max;\n }\n}\n\n/**\n * Represents a specific role or voice in a line of notation.\n * Each role contains a sequence of atoms.\n */\nexport class Role extends Entity {\n readonly TYPE = \"Role\";\n\n /**\n * Whether this role represents notes by default.\n */\n defaultToNotes = true;\n\n /**\n * The atoms in this role.\n */\n atoms: Atom[] = [];\n\n /**\n * Creates a new Role with the specified line and name.\n * @param line The line this role belongs to\n * @param name The name of the role\n */\n constructor(\n public readonly line: Line,\n public readonly name: string,\n ) {\n super();\n }\n\n /**\n * Checks if this role is empty (has no atoms).\n */\n get isEmpty(): boolean {\n return this.atoms.length == 0;\n }\n\n /**\n * Returns a debug-friendly representation of this Role.\n * @returns An object containing debug information\n */\n debugValue(): any {\n return { name: this.name, atoms: this.atoms.map((a) => a.debugValue()) };\n }\n\n /**\n * Adds atoms to this role.\n * @param atoms The atoms to add\n */\n addAtoms(...atoms: Atom[]): void {\n let last: null | Atom = null;\n for (const atom of atoms) {\n if (atom.TYPE == AtomType.REST) {\n if (last && last.TYPE != AtomType.GROUP && last.TYPE != AtomType.LABEL) {\n (last as LeafAtom).beforeRest = true;\n }\n } else {\n this.atoms.push(atom);\n }\n last = atom;\n }\n }\n\n /**\n * Copies the properties of this Role to another Role.\n * @param another The target Role to copy properties to\n */\n copyTo(another: Role): void {\n another.addAtoms(...this.atoms);\n }\n\n /**\n * Gets the total duration of all atoms in this role.\n */\n get duration(): Fraction {\n return this.atoms.reduce((a, b) => a.plus(b.duration), ZERO);\n }\n}\n","import * as TSU from \"@panyam/tsutils\";\nimport { Cycle, CyclePosition, CycleCursor } from \"./cycle\";\n\ntype Fraction = TSU.Num.Fraction;\nconst ZERO = TSU.Num.Fraction.ZERO;\n\n/**\n * Manages layout parameters for arranging beats and notes in the notation.\n * LayoutParams determines how beats are organized into lines and rows based on\n * cycle patterns and line breaks.\n */\nexport class LayoutParams {\n private static counter = 0;\n /** Unique identifier for this layout parameters instance */\n readonly uuid = LayoutParams.counter++;\n\n /** Duration of a single beat (multiplier for beat lengths) */\n beatDuration: number;\n\n /** The cycle pattern to use for this layout */\n cycle: Cycle;\n\n /** The pattern of line breaks to apply */\n protected _lineBreaks: number[];\n\n /** Cache of row start offsets */\n private _rowStartOffsets: Fraction[];\n\n /** Cache of row end offsets */\n private _rowEndOffsets: Fraction[];\n\n /** Cache of row durations */\n private _rowDurations: Fraction[];\n\n /** Total duration of the layout pattern */\n private _totalLayoutDuration;\n\n /** Cached beat layout information */\n private _beatLayouts: [CyclePosition, Fraction][][];\n\n /** Total number of beats across all layout lines */\n private _totalBeats: number;\n\n /**\n * Creates a new LayoutParams instance.\n * @param config Configuration object containing beatDuration, cycle, and lineBreaks\n */\n constructor(config?: any) {\n config = config || {};\n this.beatDuration = config.beatDuration || 1;\n if (\"cycle\" in config) this.cycle = config.cycle;\n if (!this.cycle || this.cycle.duration.isZero) {\n this.cycle = Cycle.DEFAULT;\n }\n\n this._rowStartOffsets = [];\n this._rowEndOffsets = [];\n this._rowDurations = [];\n this._totalLayoutDuration = ZERO;\n this._totalBeats = 0;\n this._beatLayouts = [];\n this.lineBreaks = config.lineBreaks || config.layout || [];\n }\n\n /**\n * Checks if this LayoutParams is equal to another LayoutParams.\n * @param another The LayoutParams to compare with\n * @returns True if the LayoutParams are equal, false otherwise\n */\n equals(another: this): boolean {\n return (\n // super.equals(another) &&\n this.beatDuration == another.beatDuration &&\n this.cycle.equals(another.cycle) &&\n this.lineBreaksEqual(another._lineBreaks)\n );\n }\n\n /**\n * Checks if the line breaks pattern is equal to another pattern.\n * @param another The line breaks pattern to compare with\n * @returns True if the patterns are equal, false otherwise\n */\n lineBreaksEqual(another: number[]): boolean {\n return this._lineBreaks.length == another.length && this._lineBreaks.every((x, i) => x == another[i]);\n }\n\n /**\n * Returns a debug-friendly representation of this LayoutParams.\n * @returns An object containing debug information\n */\n debugValue(): any {\n return {\n // ...super.debugValue(),\n cycle: this.cycle?.debugValue(),\n beatDuration: this.beatDuration,\n lineBreaks: this._lineBreaks,\n };\n }\n\n /**\n * Returns the \"location\" of a beat within a layout.\n *\n * Lines are broken into beats of notes and those beats are aligned as per\n * the specs in the LayoutParams (breaks). For example if the breaks param\n * stipulates [5, 5, 4] then we have 5 beats in the first 2 lines and 4 in\n * the last line.\n *\n * @param beat The beat to locate\n * @returns A tuple containing [layoutLine, layoutColumn, rowOffset]\n * - layoutLine: The line in the layout break spec this beat falls in\n * - layoutColumn: The column within the layoutLine\n * - rowOffset: The offset of the beat from the start of the row/line\n */\n getBeatLocation(beat: {\n index: number;\n barIndex: number;\n beatIndex: number;\n instance: number;\n }): [number, number, Fraction] {\n //\n // If a line contains say 50 beats (B1 - B50), then it is laid out as:\n //\n // C0 C1 C2 C3 C4\n // ---------------------\n // L0 | B1 B2 B3 B4 B5\n // L1 | B6 B7 B8 B9 B10\n // L2 | B11 B12 B13 B14\n // L0 | B15 B16 B17 B18 B19\n // L1 | B20 B21 B22 B23 B24\n // L2 | B25 B26 B27 B28\n // L0 | B29 B30 B31 B32 B33\n // L1 | B34 B35 B36 B37 B38\n // L2 | B39 B40 B41 B42\n // L0 | B43 B44 B45 B46 B47\n // L1 | B48 B49 B50\n //\n // This methods returns the triple: [layoutLine, layoutColumn, rowOffset]\n // where\n //\n // layoutLine: The particular line in the layout break spec this index falls in.\n // *Note*: Since lines can start with negative offsets, we can\n // even return a layoutLine that is towards the end and then go\n // back to 0, eg 4, 0, 1, 2, 3, 4, 0, 1, 2, 3, 4 ...\n // (eg returns L0 or L1 ... Ln)\n // layoutColumn: The column within the layoutLine line where this beat falls.\n // (eg C0 - C4 above - or depending on how many columns exist\n // in the particular layout line).\n // rowOffset: The note offset of the beat from the start of the row/line\n // (not from the start of the cycle).\n //\n // Note the beatIndex can also be negative so we can return a beat\n // starting from before the cycle starting point.\n //\n // To calculate the \"real\" line globally simply do:\n //\n // realLine = lineBreaks.length // Math.floor(beatIndex / this.totalBeats) + layoutLine;\n //\n // Some examples here are (using B1-B50 above):\n const modIndex = beat.index % this.totalBeats;\n let total = 0;\n for (let i = 0; i < this._lineBreaks.length; i++) {\n if (modIndex < total + this._lineBreaks[i]) {\n // TODO: What is the right offset here?\n let offset = ZERO;\n if (modIndex > total) {\n const cursor = new CycleCursor(this.cycle, beat.barIndex, beat.beatIndex, beat.instance);\n let [, duration] = cursor.prev;\n for (let i = total; i < modIndex; i++) {\n [, duration] = cursor.prev;\n offset = offset.plus(duration.timesNum(this.beatDuration));\n }\n }\n return [i, modIndex - total, offset];\n }\n total += this._lineBreaks[i];\n }\n throw new Error(\"Invalid beat index: \" + beat.index);\n return [-1, -1, ZERO];\n }\n\n /**\n * Gets the line layout pattern - i.e., number of beats in each line - as a\n * repeating pattern.\n *\n * For example 4,2,4 indicates that the notes in our song should be\n * laid out 4 beats in line 1, 2 beats in line 2, 4 beats in line 3 and\n * 4 beats in line 4 and so on as long as there are more notes available\n * in this line.\n */\n get lineBreaks(): number[] {\n if (!this._lineBreaks || this._lineBreaks.length == 0) {\n // trigger a refresh\n this.lineBreaks = [this.cycle.beatCount];\n }\n return this._lineBreaks;\n }\n\n /**\n * Sets the line layout pattern.\n */\n set lineBreaks(val: number[]) {\n this._lineBreaks = val;\n this.refreshLayout();\n }\n\n /**\n * Returns the number of beats in each line based on the line layout\n * after taking beatDuration into account.\n */\n get beatLayouts(): ReadonlyArray<ReadonlyArray<[CyclePosition, Fraction]>> {\n if (!this._beatLayouts || this._beatLayouts.length < this.lineBreaks.length) {\n this.refreshLayout();\n }\n return this._beatLayouts;\n }\n\n /**\n * Gets the total number of beats across all lines in the layout pattern.\n */\n get totalBeats(): number {\n this.beatLayouts;\n return this._totalBeats;\n }\n\n /**\n * Gets the total duration of all beats across all lines in the layout pattern.\n */\n get totalLayoutDuration(): Fraction {\n this.beatLayouts;\n return this._totalLayoutDuration;\n }\n\n /**\n * Refreshes the layout calculations based on the current cycle and line breaks.\n * This rebuilds the beat layouts, row durations, and offset information.\n */\n protected refreshLayout(): void {\n const cycleIter = this.cycle.iterateBeats();\n const akb = this.beatDuration;\n this._beatLayouts = this.lineBreaks.map((numBeats, index) => {\n const beats: [CyclePosition, Fraction][] = [];\n // see what the beat lengths are here\n for (let i = 0; i < numBeats; i++) {\n const nextCP = cycleIter.next().value;\n nextCP[1] = nextCP[1].timesNum(akb);\n beats.push(nextCP);\n }\n return beats;\n });\n this._totalBeats = this.lineBreaks.reduce((a, b) => a + b, 0);\n this._rowDurations = this._beatLayouts.map((beats) => beats.reduce((x, y) => x.plus(y[1]), ZERO));\n this._rowDurations.forEach((rd, index) => {\n this._rowStartOffsets[index] = index == 0 ? ZERO : this._rowStartOffsets[index - 1].plus(rd);\n });\n this._rowEndOffsets = this._rowDurations.map((rd, index) => {\n return this._rowStartOffsets[index].plus(rd);\n });\n this._totalLayoutDuration = this._rowDurations.reduce((x, y) => x.plus(y), ZERO);\n }\n}\n","import * as TSU from \"@panyam/tsutils\";\n// import * as kiwi from \"@lume/kiwi\";\n\n/**\n * Event emitted when layout changes occur in a GridLayoutGroup.\n * Subscribers can use this to update their views incrementally.\n */\nexport interface LayoutChangeEvent {\n /** The range of rows affected by the change */\n affectedRowRange: { start: number; end: number } | null;\n /** The range of columns affected by the change */\n affectedColRange: { start: number; end: number } | null;\n /** Whether column widths changed (requires horizontal re-layout) */\n columnWidthsChanged: boolean;\n /** Whether row heights changed (requires vertical re-layout) */\n rowHeightsChanged: boolean;\n /** The grid models that were affected */\n affectedGridModels: GridModel[];\n}\n\n/**\n * Callback type for layout change subscribers.\n */\nexport type LayoutChangeCallback = (event: LayoutChangeEvent) => void;\n\n/**\n * A generic grid layout system for hosting child views (similar to GridBagLayout).\n * This provides a framework for hosting BeatViews in a structured grid arrangement,\n * with support for rows, columns, and alignment.\n *\n * Grid \"cells\" can be referred to by cell indexes. Additionally, grid rows and\n * columns can have names (like in spreadsheets) so that even when rows and columns\n * are inserted, though indexes may change, the \"addresses\" remain fixed and immovable.\n */\nexport class GridModel extends TSU.Events.EventEmitter {\n private static idCounter = 0;\n readonly uuid = GridModel.idCounter++;\n /** Timestamp of the last update to this grid */\n lastUpdatedAt = 0;\n // cells = new SparseArray<SparseArray<GridCell>>();\n /** The rows in this grid */\n rows: GridRow[] = [];\n /** Mapping of row indices to row alignment objects */\n rowAligns = new Map<number, RowAlign>();\n /** Mapping of column indices to column alignment objects */\n colAligns = new Map<number, ColAlign>();\n\n /**\n * Returns a debug-friendly representation of this GridModel.\n * @returns An object containing debug information\n */\n debugValue() {\n const out = {\n rows: this.rows.map((r) => r.debugValue()),\n lastUpdatedAt: this.lastUpdatedAt,\n } as any;\n return out;\n }\n\n /**\n * Gets the index of the first non-empty row.\n * @returns The index of the first row containing cells, or -1 if none\n */\n get firstRow(): number {\n for (const gr of this.rows) {\n if (gr.numCells > 0) return gr.rowIndex;\n }\n return -1;\n }\n\n /**\n * Gets the index of the leftmost column containing cells.\n * @returns The index of the first column containing cells, or -1 if none\n */\n get firstCol(): number {\n let minCol = -1;\n for (const gr of this.rows) {\n const fc = gr.firstCol;\n if (fc >= 0) {\n if (minCol < 0 || fc < minCol) {\n minCol = fc;\n }\n }\n }\n return minCol;\n }\n\n /**\n * Gets all non-empty cells in a specific row.\n * @param row The index of the row\n * @returns An array of cells in the row\n */\n cellsInRow(row: number): GridCell[] {\n const out = [] as GridCell[];\n const gr = this.rows[row];\n if (gr) {\n for (const cell of gr.cells) {\n if (cell?.value) out.push(cell);\n }\n }\n return out;\n }\n\n /**\n * Gets all non-empty cells in a specific column.\n * @param col The index of the column\n * @returns An array of cells in the column\n */\n cellsInCol(col: number): GridCell[] {\n const out = [] as GridCell[];\n for (const gr of this.rows) {\n const cell = gr.cellAt(col);\n if (cell?.value) out.push(cell);\n }\n return out;\n }\n\n /**\n * Adds a row alignment object to the grid.\n * @param align The row alignment to add\n */\n addRowAlign(align: RowAlign): void {\n this.rowAligns.set(align.uuid, align);\n }\n\n /**\n * Adds a column alignment object to the grid.\n * @param align The column alignment to add\n */\n addColAlign(align: ColAlign): void {\n this.colAligns.set(align.uuid, align);\n }\n\n /**\n * Adds rows to the grid.\n * @param insertBefore The index before which to insert the rows, or -1 to append\n * @param numRows The number of rows to add\n * @returns This grid instance for method chaining\n */\n addRows(insertBefore = -1, numRows = 1): this {\n if (insertBefore < 0) {\n insertBefore = this.rows.length;\n }\n let next = this.rows[insertBefore] || null;\n const prev = this.rows[insertBefore - 1] || null;\n for (let i = numRows - 1; i >= 0; i--) {\n const newRow = new GridRow(this, insertBefore + i);\n this.rows.splice(insertBefore, 0, newRow);\n if (next != null) {\n newRow.defaultRowAlign.addSuccessor(next.defaultRowAlign);\n }\n if (i == 0 && insertBefore > 0) {\n prev.defaultRowAlign.addSuccessor(newRow.defaultRowAlign);\n }\n next = newRow;\n }\n for (let i = insertBefore + numRows; i < this.rows.length; i++) {\n this.rows[i].rowIndex += numRows;\n }\n return this;\n }\n\n /**\n * Gets a row at the specified index, creating it if necessary.\n * @param row The index of the row to get\n * @returns The row at the specified index\n */\n getRow(row: number): GridRow {\n if (row >= this.rows.length) {\n this.addRows(-1, 1 + row - this.rows.length);\n }\n return this.rows[row];\n }\n\n /**\n * Sets a value in a cell at the specified row and column.\n * @param row The row index\n * @param col The column index\n * @param value The value to set\n * @param cellCreator Optional function to create a custom cell\n * @returns The previous value of the cell\n */\n setValue(row: number, col: number, value: any, cellCreator?: (row: GridRow, col: number) => GridCell): any {\n const grow = this.getRow(row);\n if (!cellCreator) {\n cellCreator = (row: GridRow, col: number) => {\n return new GridCell(row, col);\n };\n }\n if (value == null) {\n const out = grow.clearCellAt(col);\n if (out != null) {\n this.eventHub?.emit(GridCellEvent.CLEARED, this, {\n loc: out.location,\n });\n }\n return out;\n } else {\n const cell = grow.cellAt(col, cellCreator) as GridCell;\n const oldValue = cell.value;\n this.eventHub?.emit(GridCellEvent.UPDATED, this, {\n loc: cell.location,\n cell: cell,\n oldValue: cell.value,\n });\n cell.value = value;\n return oldValue;\n }\n }\n\n /**\n * Handles changes to the event hub.\n */\n protected eventHubChanged(): void {\n console.log(\"Event Hub Changed for GridModel\");\n }\n}\n\n/**\n * Interface for a view associated with a grid cell.\n * GridCellView defines the contract for views that can be placed in grid cells.\n */\nexport interface GridCellView {\n /** The grid cell this view is associated with */\n readonly cell: GridCell;\n /** X-coordinate of the view */\n x: number;\n /** Y-coordinate of the view */\n y: number;\n /** Width of the view */\n width: number;\n /** Height of the view */\n height: number;\n\n /**\n * Sets the bounds of the view.\n * @param x New x-coordinate, or null to keep current value\n * @param y New y-coordinate, or null to keep current value\n * @param w New width, or null to keep current value\n * @param h New height, or null to keep current value\n * @param applyLayout Whether to apply layout immediately\n * @returns The new bounds values\n */\n setBounds(\n x: number | null,\n y: number | null,\n w: number | null,\n h: number | null,\n applyLayout: boolean,\n ): [number | null, number | null, number | null, number | null];\n\n /** Whether this view needs layout */\n readonly needsLayout: boolean;\n\n /** The minimum size this view requires */\n readonly minSize: TSU.Geom.Size;\n\n /** The bounding box of this view */\n readonly bbox: TSU.Geom.Rect;\n}\n\n/**\n * Enum defining the events that can occur on grid cells.\n */\nexport enum GridCellEvent {\n ADDED = \"CellAdded\",\n CLEARED = \"CellCleared\",\n REMOVED = \"CellRemoved\",\n UPDATED = \"CellUpdated\",\n MOVED = \"CellMoved\",\n}\n\n/**\n * Represents a cell in the grid.\n * GridCell holds a value and manages alignment with rows and columns.\n */\nexport class GridCell {\n private static idCounter = 0;\n readonly uuid = GridCell.idCounter++;\n /** The view associated with this cell */\n cellView: GridCellView | null;\n private _rowAlign: RowAlign;\n private _colAlign: ColAlign;\n\n /**\n * Creates a new GridCell.\n * @param gridRow The row this cell belongs to\n * @param colIndex The column index of this cell\n * @param value Optional initial value for the cell\n */\n constructor(\n public gridRow: GridRow,\n public colIndex: number,\n public value: any = null,\n ) {\n this.rowAlign = gridRow.defaultRowAlign;\n }\n\n /**\n * Gets the row alignment for this cell.\n */\n get rowAlign(): RowAlign {\n return this._rowAlign;\n }\n\n /**\n * Sets the row alignment for this cell.\n */\n set rowAlign(val: RowAlign) {\n val.addCell(this);\n this._rowAlign = val;\n }\n\n /**\n * Gets the column alignment for this cell.\n */\n get colAlign(): ColAlign {\n return this._colAlign;\n }\n\n /**\n * Sets the column alignment for this cell.\n */\n set colAlign(val: ColAlign) {\n val.addCell(this);\n this._colAlign = val;\n }\n\n /**\n * Gets the location string for this cell (rowIndex:colIndex).\n */\n get location(): string {\n return this.gridRow.rowIndex + \":\" + this.colIndex;\n }\n\n /**\n * Gets the grid this cell belongs to.\n */\n get grid(): GridModel {\n return this.gridRow.grid;\n }\n\n /**\n * Gets the row index of this cell.\n */\n get rowIndex(): number {\n return this.gridRow.rowIndex;\n }\n\n /**\n * Returns a debug-friendly representation of this GridCell.\n * @returns An object containing debug information\n */\n debugValue() {\n const out = {\n r: this.gridRow.rowIndex,\n c: this.colIndex,\n value: this.value,\n y: this.rowAlign.coordOffset,\n h: this.rowAlign.maxLength,\n } as any;\n if (this.colAlign) {\n out.x = this.colAlign.coordOffset;\n out.w = this.colAlign.maxLength;\n }\n return out;\n }\n}\n\n/**\n * Represents a row of grid cells in a GridModel.\n */\nexport class GridRow {\n /** The cells in this row */\n cells: (null | GridCell)[] = [];\n /** The default vertical alignment for all cells in this row */\n defaultRowAlign: RowAlign;\n\n /**\n * Creates a new GridRow.\n * @param grid The grid this row belongs to\n * @param rowIndex The index of this row\n */\n constructor(\n public grid: GridModel,\n public rowIndex: number,\n ) {\n this.defaultRowAlign = new RowAlign();\n this.grid.addRowAlign(this.defaultRowAlign);\n }\n\n /**\n * Gets the index of the first non-empty column in this row.\n */\n get firstCol() {\n for (let i = 0; i < this.cells.length; i++) {\n if (this.cells[i]?.value) {\n return i;\n }\n }\n return -1;\n }\n\n /**\n * Gets the number of columns in this row.\n */\n get numCols() {\n return this.cells.length;\n }\n\n /**\n * Gets the number of cells that contain values.\n */\n get numCells() {\n let i = 0;\n for (const cell of this.cells) {\n if (cell != null && cell.value != null) i++;\n }\n return i;\n }\n\n /**\n * Gets the cell at the specified column index, optionally creating it if it doesn't exist.\n * @param col The column index\n * @param creator Optional function to create the cell if it doesn't exist\n * @returns The cell at the specified index, or null if it doesn't exist and no creator was provided\n */\n cellAt(col: number, creator?: (row: GridRow, col: number) => GridCell): GridCell | null {\n let out = this.cells[col] || null;\n if (!out && creator) {\n this.cells[col] = out = creator(this, col);\n out.gridRow = this;\n out.colIndex = col;\n if (out.rowAlign) {\n this.grid.addRowAlign(out.rowAlign);\n }\n if (out.colAlign) {\n this.grid.addColAlign(out.colAlign);\n }\n }\n return out;\n }\n\n /**\n * Clears the cell at the given column.\n * Note this is not the same as \"removing\" a cell.\n * Removing a cell would require all cells to the \"right\" to be shifted left.\n * @param col The column index\n * @returns The cell that was cleared, or null if none existed\n */\n clearCellAt(col: number): GridCell | null {\n const out = this.cells[col] || null;\n if (out) {\n this.cells[col] = null;\n }\n return out;\n }\n\n /**\n * Returns a debug-friendly representation of this GridRow.\n * @returns An object containing debug information\n */\n debugValue() {\n return {\n r: this.rowIndex,\n cells: this.cells.filter((c) => c).map((c) => c?.debugValue()),\n };\n }\n}\n\n/**\n * Base class for row and column alignment objects.\n * AlignedLine manages the alignment of cells along a line (row or column).\n */\nexport abstract class AlignedLine {\n private static idCounter = 0;\n readonly uuid = AlignedLine.idCounter++;\n /** Whether this line needs layout */\n needsLayout = false;\n /** The coordinate offset of this line */\n protected _coordOffset = 0;\n /** The maximum length of this line */\n protected _maxLength = 0;\n /** Padding before this line */\n paddingBefore = 5;\n /** Padding after this line */\n paddingAfter = 5;\n /** The cells that belong to this line */\n cells: GridCell[] = [];\n /** Function to get a view for a cell value */\n getCellView: (value: any) => GridCellView;\n\n /**\n * Sets the offset of this line.\n * @param val The new offset value\n */\n abstract setOffset(val: number): void;\n\n /**\n * Evaluates the maximum length required for this line.\n * @param changedCells Cells that have changed and need re-evaluation\n * @returns The maximum length\n */\n abstract evalMaxLength(changedCells: GridCell[]): number;\n\n /**\n * Gets the coordinate offset of this line.\n */\n get coordOffset(): number {\n return this._coordOffset;\n }\n\n /**\n * Gets the maximum length of this line, including padding.\n */\n get maxLength(): number {\n return this._maxLength + this.paddingBefore + this.paddingAfter;\n }\n\n /**\n * Sets the maximum length of this line.\n * @param length The new maximum length\n */\n setMaxLength(length: number) {\n this._maxLength = length;\n }\n\n /**\n * Sets the padding before and after this line.\n * @param before Padding before the line\n * @param after Padding after the line\n */\n setPadding(before: number, after: number): void {\n if (before >= 0) {\n this.paddingBefore = before;\n }\n if (after >= 0) {\n this.paddingAfter = after;\n }\n }\n\n /**\n * Adds a cell to this line.\n * @param cell The cell to add\n * @returns This line instance for method chaining\n */\n addCell(cell: GridCell): this {\n if (this.beforeAddingCell(cell)) {\n this.cells.push(cell);\n }\n return this;\n }\n\n /**\n * Called before adding a cell to perform validation or preparation.\n * @param cell The cell to be added\n * @returns Whether the cell should be added\n */\n protected abstract beforeAddingCell(cell: GridCell): boolean;\n\n /**\n * Removes a cell from this line.\n * @param cell The cell to remove\n * @returns This line instance for method chaining\n */\n removeCell(cell: GridCell): this {\n if (this.beforeRemovingCell(cell)) {\n for (let i = 0; i < this.cells.length; i++) {\n if (this.cells[i].uuid == cell.uuid) {\n this.cells.splice(i, 1);\n break;\n }\n }\n }\n return this;\n }\n\n /**\n * Called before removing a cell to perform validation.\n * @param cell The cell to be removed\n * @returns Whether the cell should be removed\n */\n protected abstract beforeRemovingCell(cell: GridCell): boolean;\n\n // The \"neighboring\" lines that depend on this line to be placed\n // before they are placed\n /** Lines that must be positioned before this line */\n prevLines = [] as this[];\n /** Lines that must be positioned after this line */\n nextLines = [] as this[];\n\n /**\n * Adds a successor line to this line.\n * @param next The line to add as a successor\n */\n addSuccessor(next: this): void {\n // Set nextCol as a successor of this col\n // TODO - Ensure no cycles\n for (const c of this.nextLines) {\n if (c == next) return;\n }\n this.nextLines.push(next);\n next.prevLines.push(this);\n }\n\n /* TODO: Disabling only to improve test coverage as this method is\n * not used.\n * When we have mutable grids where we can insert/remove neighbors\n * we can enable this again.\n */\n /*\n removeSuccessor(next: this): void {\n // Set nextCol as a successor of this col\n // TODO - Ensure no cycles\n for (let i = 0; i < this.nextLines.length; i++) {\n if (this.nextLines[i] == next) {\n this.nextLines.splice(i, 1);\n break;\n }\n }\n for (let i = 0; i < next.prevLines.length; i++) {\n if (next.prevLines[i] == this) {\n next.prevLines.splice(i, 1);\n break;\n }\n }\n }\n */\n}\n\n/**\n * Manages the alignment of cells in a column.\n */\nexport class ColAlign extends AlignedLine {\n paddingBefore = 10;\n /** Padding after this line */\n paddingAfter = 10;\n\n /**\n * Sets the offset of this column and updates all associated cells.\n * @param val The new offset value\n */\n setOffset(val: number): void {\n this._coordOffset = val;\n for (const cell of this.cells) {\n if (cell.value) {\n const cellView = this.getCellView(cell);\n if (this._maxLength <= 0) {\n // this hasnt been evaluated yet so do it!\n this.evalMaxLength();\n }\n cellView.setBounds(val, null, this.maxLength, null, true);\n }\n }\n }\n\n /**\n * Evaluates the maximum width required for this column.\n * @param changedCells Cells that have changed and need re-evaluation\n * @returns The maximum width\n */\n evalMaxLength(changedCells: GridCell[] = []): number {\n this._maxLength = 0;\n for (const cell of this.cells) {\n if (cell.value) {\n const cellView = this.getCellView(cell);\n this._maxLength = Math.max(cellView.minSize.width, this._maxLength);\n }\n }\n return this._maxLength;\n }\n\n /**\n * Called before adding a cell to perform validation or preparation.\n * @param cell The cell to be added\n * @returns Whether the cell should be added\n */\n protected beforeAddingCell(cell: GridCell): boolean {\n if (cell.colAlign && cell.colAlign != this) {\n cell.colAlign.removeCell(cell);\n }\n return cell.colAlign != this;\n }\n\n /**\n * Called before removing a cell to perform validation.\n * @param cell The cell to be removed\n * @returns Whether the cell should be removed\n */\n beforeRemovingCell(cell: GridCell): boolean {\n return cell.colAlign == this;\n }\n}\n\n/**\n * Manages the alignment of cells in a row.\n */\nexport class RowAlign extends AlignedLine {\n /**\n * Sets the Y coordinate of all cells in this row.\n * @param val The new Y coordinate\n */\n setOffset(val: number): void {\n this._coordOffset = val;\n for (const cell of this.cells) {\n if (cell.value) {\n const cellView = this.getCellView(cell);\n if (this._maxLength <= 0) {\n // this hasnt been evaluated yet so do it!\n this.evalMaxLength();\n }\n cellView.setBounds(null, val, null, this.maxLength, true);\n }\n }\n }\n\n /**\n * Evaluates the maximum height required for this row.\n * @param changedCells Cells that have changed and need re-evaluation\n * @returns The maximum height\n */\n evalMaxLength(changedCells: GridCell[] = []): number {\n this._maxLength = 0;\n for (const cell of this.cells) {\n if (cell.value) {\n const cellView = this.getCellView(cell);\n this._maxLength = Math.max(cellView.minSize.height, this._maxLength);\n }\n }\n return this._maxLength;\n }\n\n /**\n * Called before adding a cell to perform validation or preparation.\n * @param cell The cell to be added\n * @returns Whether the cell should be added\n */\n protected beforeAddingCell(cell: GridCell): boolean {\n if (cell.rowAlign && cell.rowAlign != this) {\n cell.rowAlign.removeCell(cell);\n }\n return cell.rowAlign != this;\n }\n\n /**\n * Called before removing a cell to perform validation.\n * @param cell The cell to be removed\n * @returns Whether the cell should be removed\n */\n beforeRemovingCell(cell: GridCell): boolean {\n return cell.rowAlign == this;\n }\n}\n\n/**\n * The layout manager for a collection of GridViews bound by common alignment objects.\n * Manages the layout of multiple grid models, ensuring proper alignment between them.\n */\nexport class GridLayoutGroup {\n // rowAligns = new Map<number, RowAlign>();\n // colAligns = new Map<number, ColAlign>();\n /** The grid models managed by this layout group */\n gridModels = [] as GridModel[];\n\n /** Subscribers to layout change events */\n private layoutChangeSubscribers = new Set<LayoutChangeCallback>();\n\n /** Previous column widths by ColAlign uuid - for detecting actual changes */\n private previousColumnWidths = new Map<number, number>();\n\n /** Previous row heights by RowAlign uuid - for detecting actual changes */\n private previousRowHeights = new Map<number, number>();\n\n /**\n * Subscribes to layout change events.\n * @param callback Function to call when layout changes\n * @returns Unsubscribe function\n */\n onLayoutChange(callback: LayoutChangeCallback): () => void {\n this.layoutChangeSubscribers.add(callback);\n return () => {\n this.layoutChangeSubscribers.delete(callback);\n };\n }\n\n /**\n * Notifies all subscribers of a layout change.\n * @param event The layout change event\n */\n protected notifyLayoutChange(event: LayoutChangeEvent): void {\n for (const callback of this.layoutChangeSubscribers) {\n try {\n callback(event);\n } catch (e) {\n console.error(\"Error in layout change callback:\", e);\n }\n }\n }\n\n /**\n * Gets the number of layout change subscribers.\n */\n get subscriberCount(): number {\n return this.layoutChangeSubscribers.size;\n }\n\n /**\n * Event handler for processing events from grid models.\n */\n private eventHandler = (event: TSU.Events.TEvent) => {\n this.applyModelEvents(event.payload);\n };\n\n /**\n * Adds a grid model to this layout group.\n * @param gridModel The grid model to add\n * @returns True if the model was added successfully\n */\n addGridModel(gridModel: GridModel): boolean {\n gridModel.eventHub?.on(TSU.Events.EventHub.BATCH_EVENTS, this.eventHandler);\n this.gridModels.push(gridModel);\n return true;\n }\n\n /**\n * Gets all row alignment objects that have no predecessors.\n * @returns An array of starting row alignments\n */\n startingRowAligns(): RowAlign[] {\n const out = [] as RowAlign[];\n const visited = {} as any;\n for (const gm of this.gridModels) {\n for (const cell of gm.cellsInRow(gm.firstRow)) {\n if (cell.rowAlign && !visited[cell.rowAlign.uuid]) {\n visited[cell.rowAlign.uuid] = true;\n out.push(cell.rowAlign);\n }\n }\n }\n return out;\n }\n\n /**\n * Gets all column alignment objects that have no predecessors.\n * @returns An array of starting column alignments\n */\n startingColAligns(): ColAlign[] {\n const out = [] as ColAlign[];\n const visited = {} as any;\n for (const gm of this.gridModels) {\n for (const cell of gm.cellsInCol(gm.firstCol)) {\n if (cell.colAlign && !visited[cell.colAlign.uuid]) {\n visited[cell.colAlign.uuid] = true;\n out.push(cell.colAlign);\n }\n }\n }\n return out;\n }\n\n /**\n * Removes a grid model from this layout group.\n * @param gridModel The grid model to remove\n */\n removeGridModel(gridModel: GridModel): void {\n gridModel.eventHub?.removeOn(TSU.Events.EventHub.BATCH_EVENTS, this.eventHandler);\n }\n\n /**\n * Function to get a view for a cell value.\n */\n getCellView: (cell: GridCell) => GridCellView;\n\n /**\n * Gets the starting row alignments.\n */\n get startingRows(): RowAlign[] {\n return this.startingRowAligns();\n }\n\n /**\n * Gets the starting column alignments.\n */\n get startingCols(): ColAlign[] {\n return this.startingColAligns();\n }\n\n /**\n * Forces a full refresh of the layout.\n * This recalculates all row and column sizes and positions.\n * @param notify Whether to notify subscribers of the change (default: true)\n */\n refreshLayout(notify = true): void {\n const changedRowAligns = {} as any;\n const changedColAligns = {} as any;\n\n for (const rowAlign of this.startingRowAligns()) {\n if (!(rowAlign.uuid in changedRowAligns)) {\n changedRowAligns[rowAlign.uuid] = {\n align: rowAlign,\n cells: [],\n };\n }\n }\n\n for (const colAlign of this.startingColAligns()) {\n if (!(colAlign.uuid in changedColAligns)) {\n changedColAligns[colAlign.uuid] = {\n align: colAlign,\n cells: [],\n };\n }\n }\n\n // Pass the previous dimension maps for O(1) inline change detection\n const rowHeightsChanged = this.doBfsLayout(this.startingRows, changedRowAligns, this.previousRowHeights);\n const columnWidthsChanged = this.doBfsLayout(this.startingCols, changedColAligns, this.previousColumnWidths);\n\n // Notify subscribers of full refresh\n if (notify && this.layoutChangeSubscribers.size > 0) {\n this.notifyLayoutChange({\n affectedRowRange: null, // null means all rows\n affectedColRange: null, // null means all columns\n columnWidthsChanged,\n rowHeightsChanged,\n affectedGridModels: this.gridModels,\n });\n }\n }\n\n /**\n * Applies model events to update the layout.\n * @param events The events to process\n */\n protected applyModelEvents(events: TSU.Events.TEvent[]): void {\n // As the grid model changes (cell content changed, cleared etc) we need\n // to refresh our layout based on this.\n // As a first step the new height and width of all changed cells is\n // evaluted to see which rows and/or columns are affected (and need to be\n // resized/repositioned).\n const [changedRowAligns, changedColAligns, affectedGridModels] = this.changesForEvents(events);\n const hadRowChanges = Object.keys(changedRowAligns).length > 0;\n const hadColChanges = Object.keys(changedColAligns).length > 0;\n\n // Pass the previous dimension maps for O(1) inline change detection\n const rowHeightsChanged = this.doBfsLayout(this.startingRows, changedRowAligns, this.previousRowHeights);\n const columnWidthsChanged = this.doBfsLayout(this.startingCols, changedColAligns, this.previousColumnWidths);\n\n // Notify subscribers of incremental changes\n if (this.layoutChangeSubscribers.size > 0 && (hadRowChanges || hadColChanges)) {\n // Calculate affected ranges from the changed alignments\n const affectedRowRange = this.calculateAffectedRowRange(changedRowAligns);\n const affectedColRange = this.calculateAffectedColRange(changedColAligns);\n\n this.notifyLayoutChange({\n affectedRowRange,\n affectedColRange,\n columnWidthsChanged,\n rowHeightsChanged,\n affectedGridModels: affectedGridModels,\n });\n }\n }\n\n /**\n * Calculates the range of affected rows from changed row alignments.\n * Returns null if no rows changed or range cannot be determined.\n */\n protected calculateAffectedRowRange(changedRowAligns: any): { start: number; end: number } | null {\n let minRow = Infinity;\n let maxRow = -Infinity;\n\n for (const alignId in changedRowAligns) {\n const { cells } = changedRowAligns[alignId];\n for (const cell of cells) {\n const rowIndex = cell.gridRow.rowIndex;\n minRow = Math.min(minRow, rowIndex);\n maxRow = Math.max(maxRow, rowIndex);\n }\n }\n\n if (minRow === Infinity) return null;\n return { start: minRow, end: maxRow };\n }\n\n /**\n * Calculates the range of affected columns from changed column alignments.\n * Returns null if no columns changed or range cannot be determined.\n */\n protected calculateAffectedColRange(changedColAligns: any): { start: number; end: number } | null {\n let minCol = Infinity;\n let maxCol = -Infinity;\n\n for (const alignId in changedColAligns) {\n const { cells } = changedColAligns[alignId];\n for (const cell of cells) {\n const colIndex = cell.colIndex;\n minCol = Math.min(minCol, colIndex);\n maxCol = Math.max(maxCol, colIndex);\n }\n }\n\n if (minCol === Infinity) return null;\n return { start: minCol, end: maxCol };\n }\n\n /**\n * Checks if an alignment's maxLength changed from previous value.\n * Updates the stored previous value. O(1) cost.\n * @param align The alignment to check\n * @param previousMap Map storing previous lengths\n * @returns true if length changed (or is new)\n */\n private checkAndUpdateLength<T extends AlignedLine>(align: T, previousMap: Map<number, number>): boolean {\n const previous = previousMap.get(align.uuid);\n const current = align.maxLength;\n previousMap.set(align.uuid, current);\n return previous === undefined || previous !== current;\n }\n\n /**\n * Determines which rows and columns need to be updated based on events.\n * @param events The events to process\n * @returns A tuple containing the changed row alignments, column alignments, and affected grid models\n */\n protected changesForEvents(events: TSU.Events.TEvent[]): [any, any, GridModel[]] {\n // Step 1 - topologically sort RowAligns of changed cells\n // Step 2 - topologically sort ColAligns of changed cells\n // Step 3 -\n const cellVisited = {} as any;\n const changedRowAligns = {} as any;\n const changedColAligns = {} as any;\n const affectedGridModelsSet = new Set<GridModel>();\n // Going in reverse means we only get the latest event affecting a cell\n // instead of going through every change.\n // Later on we can revisit this if the events are edge triggered instead\n // of level triggered\n for (let i = events.length - 1; i >= 0; i--) {\n const event = events[i];\n const loc = event.payload.loc;\n if (cellVisited[loc]) continue;\n cellVisited[loc] = true;\n const [row, col] = loc.split(\":\").map((x: string) => parseInt(x));\n const gridModel = event.source as GridModel;\n affectedGridModelsSet.add(gridModel);\n const cell = gridModel.getRow(row).cellAt(col);\n if (cell) {\n // TODO - For now we are marking both row and col as having\n // changed for a cell. We can optimize this to only row or\n // col based on whether height or width has changed.\n if (!(cell.rowAlign.uuid in changedRowAligns)) {\n changedRowAligns[cell.rowAlign.uuid] = {\n align: cell.rowAlign,\n cells: [],\n };\n }\n changedRowAligns[cell.rowAlign.uuid][\"cells\"].push(cell);\n\n if (!(cell.colAlign.uuid in changedColAligns)) {\n changedColAligns[cell.colAlign.uuid] = {\n align: cell.colAlign,\n cells: [],\n };\n }\n changedColAligns[cell.colAlign.uuid][\"cells\"].push(cell);\n }\n }\n return [changedRowAligns, changedColAligns, Array.from(affectedGridModelsSet)];\n }\n\n /**\n * Ensures that a cell view getter function is available for an alignment.\n * @param align The alignment to check\n * @returns The cell view getter function\n */\n protected ensureGetCellView(align: AlignedLine) {\n if (!align.getCellView) {\n if (!this.getCellView) {\n return null;\n }\n align.getCellView = this.getCellView;\n }\n return align.getCellView;\n }\n\n /**\n * Performs a breadth-first layout of aligned lines.\n * @param startingLines The lines to start from\n * @param changedAligns Map of alignment IDs to changed alignments\n * @param previousLengths Map to track previous lengths for change detection\n * @returns true if any dimension (width/height) actually changed\n */\n protected doBfsLayout<T extends AlignedLine>(\n startingLines: T[],\n changedAligns: any,\n previousLengths?: Map<number, number>,\n ): boolean {\n // 1. start from the starting lines and do a BF traversal\n // 2. If a line not visited (ie laid out):\n // if it is in the changedAlign list then reval its length (w/h)\n // set its offset and length if either width or offset has changed\n // offset can be thought of changed if the preceding line's offset has changed\n // first do above for rows\n if (!this.getCellView) return false;\n let anyDimensionChanged = false;\n\n for (const alignId in changedAligns) {\n const val = changedAligns[alignId];\n this.ensureGetCellView(val.align);\n val.align.evalMaxLength(val.cells);\n\n // Check if this alignment's length actually changed (O(1))\n if (previousLengths && this.checkAndUpdateLength(val.align, previousLengths)) {\n anyDimensionChanged = true;\n }\n }\n\n let lineQueue = [] as [null | T, T][];\n const visitedLines = {} as any;\n for (const line of startingLines) lineQueue.push([null, line]);\n const lineOffsetChanged = {} as any;\n while (lineQueue.length > 0) {\n const nextQueue = [] as [null | T, T][];\n for (let i = 0; i < lineQueue.length; i++) {\n const [prevLineAlign, lineAlign] = lineQueue[i];\n visitedLines[lineAlign.uuid] = true;\n let newOffset = lineAlign.coordOffset;\n let lineChanged = lineAlign.uuid in changedAligns;\n if (prevLineAlign) {\n if (lineOffsetChanged[prevLineAlign.uuid]) {\n newOffset = prevLineAlign.coordOffset + prevLineAlign.maxLength;\n lineChanged = true;\n }\n }\n if (lineChanged) {\n this.ensureGetCellView(lineAlign);\n lineAlign.setOffset(newOffset);\n lineOffsetChanged[lineAlign.uuid] = true;\n }\n\n // Add next neighbors now\n for (const next of lineAlign.nextLines) {\n if (!visitedLines[next.uuid]) {\n nextQueue.push([lineAlign, next]);\n }\n }\n }\n lineQueue = nextQueue;\n }\n\n return anyDimensionChanged;\n }\n}\n","import * as TSU from \"@panyam/tsutils\";\nimport { AtomType, Marker, Group, Line, Atom, Space, Role } from \"./\";\nimport { CycleIterator, CyclePosition } from \"./cycle\";\nimport { WindowIterator } from \"./iterators\";\nimport { LayoutParams } from \"./layouts\";\nimport { GridModel, GridRow, GridCell, ColAlign, GridLayoutGroup } from \"./grids\";\nimport { Block, BlockItem, isLine, isBlock } from \"./notation\";\n\ntype Fraction = TSU.Num.Fraction;\nconst ZERO = TSU.Num.Fraction.ZERO;\nconst ONE = TSU.Num.Fraction.ONE;\n\n/**\n * Represents a single beat in the notation.\n * A beat contains one or more atoms and has a specific position in a bar.\n */\nexport class Beat {\n private static idCounter = 0;\n readonly uuid = Beat.idCounter++;\n // Should this be as flat Atoms or should we keep it as atoms and breakdown later?\n\n /** The atom contained in this beat */\n atom: Atom;\n protected atomIsPlaceholder = false;\n\n /**\n * Creates a new Beat.\n * @param index The index of this beat in the sequence\n * @param role The role this beat belongs to\n * @param offset The time offset of this beat from the start\n * @param duration The duration of this beat\n * @param barIndex The index of the bar containing this beat\n * @param beatIndex The index of this beat within its bar\n * @param instance The instance number of this beat\n * @param prevBeat The previous beat in the sequence, if any\n * @param nextBeat The next beat in the sequence, if any\n */\n constructor(\n public readonly index: number,\n public readonly role: Role,\n public readonly offset: Fraction,\n public readonly duration: Fraction,\n public readonly barIndex: number,\n public readonly beatIndex: number,\n public readonly instance: number,\n public readonly prevBeat: null | Beat,\n public nextBeat: null | Beat,\n ) {}\n\n /**\n * Returns a debug-friendly representation of this Beat.\n * @returns An object containing debug information\n */\n debugValue(): any {\n return {\n index: this.index,\n role: this.role.name,\n offset: this.offset.toString(),\n duration: this.duration.toString(),\n barIndex: this.barIndex,\n beatIndex: this.beatIndex,\n instance: this.instance,\n atom: this.atom.debugValue(),\n };\n }\n\n /**\n * Gets the end offset of this beat (offset + duration).\n */\n get endOffset(): Fraction {\n return this.offset.plus(this.duration);\n }\n\n /**\n * Checks if this beat is filled completely (no remaining space).\n */\n get filled(): boolean {\n return this.remaining.isZero;\n }\n\n /**\n * Gets the remaining duration available in this beat.\n */\n get remaining(): Fraction {\n return this.atom ? this.duration.minus(this.atom.duration, true) : this.duration;\n }\n\n /**\n * Adds an atom to this beat.\n * @param atom The atom to add\n * @returns True if the atom was added successfully, false if there's not enough space\n */\n add(atom: Atom): boolean {\n if (this.remaining.cmp(atom.duration) < 0) {\n return false;\n }\n if (!this.atom) {\n this.atom = atom;\n } else {\n if (!this.atomIsPlaceholder) {\n this.atomIsPlaceholder = true;\n this.atom = new Group(this.atom).setDuration(ONE, true);\n }\n (this.atom as Group).addAtoms(true, atom);\n }\n return true;\n }\n\n /**\n * Gets all markers that should be displayed before this beat.\n * @returns An array of Marker objects\n */\n get preMarkers(): Marker[] {\n const out = [] as Marker[];\n let curr: Atom | null = this.atom;\n while (curr != null) {\n for (const marker of curr.markersBefore || []) {\n out.push(marker);\n }\n if (curr.TYPE == AtomType.GROUP) {\n curr = (curr as Group).atoms.first;\n } else {\n curr = null;\n }\n }\n return out;\n }\n\n /**\n * Gets all markers that should be displayed after this beat.\n * @returns An array of Marker objects\n */\n get postMarkers(): Marker[] {\n const out = [] as Marker[];\n let curr: Atom | null = this.atom;\n while (curr != null) {\n out.splice(0, 0, ...(curr.markersAfter || []));\n if (curr.TYPE == AtomType.GROUP) {\n curr = (curr as Group).atoms.last;\n } else {\n curr = null;\n }\n }\n return out;\n }\n}\n\n/**\n * Builds a sequence of beats from atoms according to layout parameters.\n * Used to convert a flat sequence of atoms into structured beats for display.\n */\nexport class BeatsBuilder {\n /** All atoms divided into beats */\n readonly beats: Beat[] = [];\n readonly startIndex: number;\n readonly beatOffset: Fraction;\n cycleIter: CycleIterator;\n windowIter: WindowIterator;\n\n /** Callback for when an atom is added to this role */\n onAtomAdded: (atom: Atom, beat: Beat) => void;\n\n /** Callback for when a new beat is added */\n onBeatAdded: (beat: Beat) => void;\n\n /** Callback for when a beat has been filled */\n onBeatFilled: (beat: Beat) => void;\n\n /**\n * Creates a new BeatsBuilder.\n * @param role The role containing the atoms\n * @param layoutParams Layout parameters for structuring beats\n * @param startOffset The starting offset for the first beat, defaults to ZERO\n * @param atoms Initial atoms to add to the beats\n */\n constructor(\n public readonly role: Role,\n public readonly layoutParams: LayoutParams,\n public readonly startOffset: Fraction = ZERO,\n ...atoms: Atom[]\n ) {\n const [, [bar, beat, instance], beatOffset, index] = layoutParams.cycle.getPosition(startOffset);\n this.cycleIter = layoutParams.cycle.iterateBeats(bar, beat, instance);\n this.windowIter = new WindowIterator();\n this.beatOffset = beatOffset;\n\n // evaluate the start beatindex - typically it would be 0 if things start\n // at beginning of a cycle. But if the start offset is < 0 then the\n // startIndex should also shift accordingly\n this.startIndex = index;\n this.addAtoms(...atoms);\n }\n\n /**\n * Adds atoms to be processed into beats.\n * @param atoms The atoms to add\n */\n addAtoms(...atoms: Atom[]): void {\n // First add all atoms to the atom Iterator so we can\n // fetch them as FlatAtoms. This is needed because atoms\n // passed here could be unflatted (via groups) or much larger\n // than what can fit in the given role/bar etc. So this\n // flattening and windowing is needed before we add them\n // to the views - and this is done by the durationIterators.\n this.windowIter.push(...atoms);\n while (this.windowIter.hasMore) {\n // get the last/current row and add a new one if it is full\n let currBeat = this.beats[this.beats.length - 1];\n\n // First add a row if last row is filled\n if (this.beats.length == 0 || currBeat.filled) {\n // what should be the beatlengths be here?\n currBeat = this.addBeat();\n }\n\n // For this beat get symbols in all roles\n const [remAtoms, filled] = this.windowIter.get(currBeat.remaining);\n TSU.assert(remAtoms.length > 0, \"Atleast one element should have been available here\");\n // render the atoms now\n for (const atom of remAtoms) {\n // console.log(\"Adding FA: \", flatAtom.debugValue(), flatAtom.atom);\n TSU.assert(currBeat.add(atom), \"Should return true as we are already using a duration iterator here\");\n if (this.onAtomAdded) this.onAtomAdded(atom, currBeat);\n }\n if (currBeat.filled) {\n if (this.onBeatFilled) this.onBeatFilled(currBeat);\n }\n }\n }\n\n /**\n * Adds a new beat to the sequence.\n * @returns The newly created beat\n */\n protected addBeat(): Beat {\n const numBeats = this.beats.length;\n const lastBeat = numBeats == 0 ? null : this.beats[numBeats - 1];\n const nextCP: [CyclePosition, Fraction] = this.cycleIter.next().value;\n const apb = this.layoutParams.beatDuration;\n const newBeat = new Beat(\n lastBeat == null ? this.startIndex : lastBeat.index + 1,\n this.role,\n lastBeat == null ? this.startOffset.minus(this.beatOffset).timesNum(apb, true) : lastBeat.endOffset,\n nextCP[1].timesNum(apb),\n nextCP[0][0],\n nextCP[0][1],\n nextCP[0][2],\n lastBeat,\n null,\n );\n if (lastBeat == null && this.beatOffset.isGT(ZERO)) {\n // Add spaces to fill up empty beats\n newBeat.add(new Space(this.beatOffset.timesNum(apb)));\n }\n if (lastBeat) lastBeat.nextBeat = newBeat;\n this.beats.push(newBeat);\n if (this.onBeatAdded) this.onBeatAdded(newBeat);\n return newBeat;\n }\n}\n\n/**\n * Represents a column of beats in a layout grid.\n * Used for aligning beats vertically in the notation.\n */\nexport class BeatColumn extends ColAlign {\n /** Spacing between atoms in this column */\n atomSpacing = 5;\n /** Unique key for this column */\n readonly key: string;\n\n /**\n * Creates a new BeatColumn.\n * @param offset The starting offset of this column\n * @param endOffset The ending offset of this column\n * @param markerType The type of marker for this column (negative: before, positive: after, zero: normal)\n */\n constructor(\n public readonly offset: Fraction,\n public readonly endOffset: Fraction,\n public readonly markerType: number,\n ) {\n super();\n offset = offset.factorized;\n endOffset = endOffset.factorized;\n this.key = BeatColumn.keyFor(offset, endOffset, markerType);\n }\n\n /**\n * Generates a key for identifying columns with the same offsets and marker type.\n * @param offset The starting offset\n * @param endOffset The ending offset\n * @param markerType The type of marker (negative: before, positive: after, zero: normal)\n * @returns A string key\n */\n static keyFor(offset: Fraction, endOffset: Fraction, markerType = 0): string {\n offset = offset.factorized;\n endOffset = endOffset.factorized;\n if (markerType < 0) {\n // return the column for the marker \"before\" this col\n // int his case only the \"start offset\" is needed and length doesnt matter\n return \":\" + offset.toString();\n } else if (markerType > 0) {\n // return the column for the marker \"after\" this col\n // in this case only thd end offset matters\n return endOffset.toString() + \":\";\n } else {\n return offset.toString() + \":\" + endOffset.toString();\n }\n }\n}\n\n/**\n * Manages the organization of beats into columns based on their offsets.\n * Used to create a directed acyclic graph (DAG) of beat columns for layout purposes.\n *\n * Grouping of beats by their column based on the layout params.\n * The confusion is we have beats broken up and saved in columns\n * but we are loosing how a line is supposed to access it in its own way\n * we have beatsByRole for getting all beats for a role (in a line)\n * sequentially we have beatColumns for getting all beats in a particular\n * column across all lines and roles globally.\n *\n * What we want here is for a given line get all roles, their beats\n * in zipped way. eg for a Line with 3 roles and say 10 beats each\n * (with the breaks of 4, 1) we need:\n *\n * R1 B1 R1 B2 R1 B3 R1 B4\n * R2 B1 R2 B2 R2 B3 R2 B4\n * R3 B1 R3 B2 R3 B3 R3 B4\n *\n * R1 B5\n * R2 B5\n * R3 B5\n *\n * R1 B6 R1 B7 R1 B8 R1 B9\n * R2 B6 R2 B7 R2 B8 R2 B9\n * R3 B6 R3 B7 R3 B8 R3 B9\n *\n * R1 B10\n * R2 B10\n * R3 B10\n *\n *\n * Here we have 5 distinct beat columns:\n *\n * 1: R1B1, R2B1, R3B1, R1B6, R2B6, R3B6,\n * 2: R1B2, R2B2, R3B2, R1B7, R2B7, R3B7,\n * 3: R1B3, R2B3, R3B3, R1B8, R2B8, R3B8,\n * 4: R1B4, R2B4, R3B4, R1B9, R2B9, R3B9,\n * 5: R1B5, R2B5, R3B5, R1B10, R2B10, R3B10,\n *\n */\nexport class BeatColDAG {\n /** Map of column keys to BeatColumn objects */\n beatColumns = new Map<string, BeatColumn>();\n\n /**\n * Creates a new BeatColDAG.\n * @param layoutGroup The layout group to associate with this DAG\n */\n constructor(public readonly layoutGroup: GridLayoutGroup) {\n //\n }\n\n /**\n * Gets the beat column for a given duration at the specified offset.\n * Creates a new column if none exists.\n * @param offset The starting offset\n * @param endOffset The ending offset\n * @param markerType The type of marker\n * @returns The BeatColumn for the specified parameters\n */\n getBeatColumn(offset: Fraction, endOffset: Fraction, markerType = 0): BeatColumn {\n const [bcol, newcreated] = this.ensureBeatColumn(offset, endOffset, markerType);\n if (newcreated) {\n if (markerType == 0) {\n const [prevcol] = this.ensureBeatColumn(offset, endOffset, -1);\n const [nextcol] = this.ensureBeatColumn(offset, endOffset, 1);\n prevcol.addSuccessor(bcol);\n bcol.addSuccessor(nextcol);\n for (const other of this.beatColumns.values()) {\n // only join the \"marker\" columns\n if (other.markerType == -1 && endOffset.equals(other.offset)) {\n // our next col is a preecessor of other\n nextcol.addSuccessor(other);\n } else if (other.markerType == 1 && other.endOffset.equals(offset)) {\n // our prev col is a predecessor of other\n other.addSuccessor(prevcol);\n }\n }\n }\n }\n return bcol;\n }\n\n /**\n * Ensures a beat column exists for the given parameters.\n * @param offset The starting offset\n * @param endOffset The ending offset\n * @param markerType The type of marker\n * @returns A tuple containing the column and whether it was newly created\n */\n protected ensureBeatColumn(offset: Fraction, endOffset: Fraction, markerType = 0): [BeatColumn, boolean] {\n const key = BeatColumn.keyFor(offset, endOffset, markerType);\n let bcol = this.beatColumns.get(key) || null;\n const newcreated = bcol == null;\n if (!bcol) {\n bcol = new BeatColumn(offset, endOffset, markerType);\n this.beatColumns.set(key, bcol);\n }\n return [bcol, newcreated];\n }\n}\n\n/** Type alias for line IDs */\ntype LineId = number;\n/** Type alias for layout parameter IDs */\ntype LPID = number;\n\n/**\n * Manages the beat layouts for all lines in a notation.\n * Handles the creation of grid models, positioning of beats, and alignment of beats across lines.\n */\nexport class GlobalBeatLayout {\n /** Map of line IDs to grid models */\n gridModelsForLine = new Map<LineId, GridModel>();\n /** Map of line IDs to arrays of beats for each role */\n roleBeatsForLine = new Map<LineId, Beat[][]>();\n /** Map of layout parameter IDs to beat column DAGs */\n beatColDAGsByLP = new Map<LPID, BeatColDAG>();\n /** The global layout group for all grid models */\n readonly gridLayoutGroup: GridLayoutGroup;\n\n /**\n * Creates a new GlobalBeatLayout.\n * @param sharedGridLayoutGroup Optional shared GridLayoutGroup for column alignment across multiple views.\n * If not provided, a new GridLayoutGroup is created internally.\n */\n constructor(sharedGridLayoutGroup?: GridLayoutGroup) {\n this.gridLayoutGroup = sharedGridLayoutGroup ?? new GridLayoutGroup();\n }\n\n /**\n * Gets the GridModel associated with a particular line, creating one if it doesn't exist.\n * @param lineid The ID of the line\n * @returns The GridModel for the line\n */\n getGridModelForLine(lineid: LineId): GridModel {\n let out = this.gridModelsForLine.get(lineid) || null;\n if (!out) {\n out = new GridModel();\n this.gridLayoutGroup.addGridModel(out);\n this.gridModelsForLine.set(lineid, out);\n }\n return out;\n }\n\n /**\n * Gets the BeatColDAG for a specific layout parameter ID, creating one if it doesn't exist.\n * @param lpid The layout parameter ID\n * @returns The BeatColDAG for the layout parameters\n */\n protected beatColDAGForLP(lpid: LPID): BeatColDAG {\n let out = this.beatColDAGsByLP.get(lpid) || null;\n if (!out) {\n out = new BeatColDAG(this.gridLayoutGroup);\n this.beatColDAGsByLP.set(lpid, out);\n }\n return out;\n }\n\n /**\n * Adds a line to the beat layout.\n * This ensures that a line is broken down into beats and added into a dedicated GridModel.\n *\n * A line must also be given the layout params by which the beat breakdown will happen.\n * This LayoutParams object does not have to be unique per line (this non-constraint allows\n * beats to be aligned across lines).\n *\n * @param line The line to add\n */\n addLine(line: Line): void {\n const gridModel = this.getGridModelForLine(line.uuid) as GridModel;\n gridModel.eventHub?.startBatchMode();\n this.lineToRoleBeats(line, gridModel);\n gridModel.eventHub?.commitBatch();\n }\n\n /**\n * Recursively processes a block and its children to build beat layouts.\n * Uses block.children() to get expanded children (e.g., RepeatBlock expands to N copies).\n *\n * @param block The block to process\n */\n processBlock(block: Block): void {\n for (const child of block.children()) {\n this.processBlockItem(child);\n }\n }\n\n /**\n * Processes a single block item (Block, Line, or RawBlock).\n *\n * @param item The item to process\n */\n protected processBlockItem(item: BlockItem): void {\n if (isLine(item)) {\n const line = item as Line;\n if (!line.isEmpty && line.layoutParams != null) {\n this.addLine(line);\n }\n } else if (isBlock(item)) {\n this.processBlock(item as Block);\n }\n // RawBlocks are ignored (no beat layout for raw content)\n }\n\n /**\n * Converts a line into a series of beats for each role.\n * @param line The line to convert\n * @param gridModel The grid model to use\n * @returns Arrays of beats for each role\n */\n protected lineToRoleBeats(line: Line, gridModel: GridModel): Beat[][] {\n const lp = line.layoutParams;\n const roleBeats = [] as Beat[][];\n this.roleBeatsForLine.set(line.uuid, roleBeats);\n const lineOffset = line.offset.divbyNum(lp.beatDuration);\n for (const role of line.roles) {\n const bb = new BeatsBuilder(role, lp, lineOffset, ...role.atoms);\n roleBeats.push(bb.beats);\n\n // Add these to the beat layout too\n for (const beat of bb.beats) {\n // beat.ensureUniformSpaces(layoutParams.beatDuration);\n this.addBeat(beat, gridModel);\n }\n }\n return roleBeats;\n }\n\n /**\n * Adds a beat to the layout.\n * @param beat The beat to add\n * @param gridModel The grid model to add the beat to\n * @returns The grid cell containing the beat\n */\n protected addBeat(beat: Beat, gridModel: GridModel): GridCell {\n // Get the beat column at this index (and line) and add to it.\n const line = beat.role.line;\n const lp = line.layoutParams;\n const beatColDAG = this.beatColDAGForLP(lp.uuid);\n const [layoutLine, layoutColumn, rowOffset] = lp.getBeatLocation(beat);\n const colEnd = rowOffset.plus(beat.duration, true);\n const bcol = beatColDAG.getBeatColumn(rowOffset, colEnd, 0);\n\n // Since a beat's column has a \"pre\" and \"post\" col to, each\n // beat has 3 columns for it\n const roleIndex = beat.role.line.indexOfRole(beat.role.name);\n const nthLine = Math.floor(beat.index / lp.totalBeats);\n const realLine = lp.lineBreaks.length * nthLine + layoutLine;\n const realRow = line.roles.length * realLine + roleIndex;\n // pre marker goes on realCol - 1, post marker goes on realCol + 1\n const realCol = 1 + layoutColumn * 3;\n const preMarkers = beat.preMarkers;\n if (preMarkers.length > 0) {\n const val = {\n beat: beat,\n markers: preMarkers,\n };\n const precol = beatColDAG.getBeatColumn(rowOffset, colEnd, -1);\n gridModel.setValue(realRow, realCol - 1, val, (gridRow: GridRow, col: number) => {\n const cell = new GridCell(gridRow, col);\n cell.colAlign = precol;\n return cell;\n });\n }\n const postMarkers = beat.postMarkers;\n if (postMarkers.length > 0) {\n const val = {\n beat: beat,\n markers: postMarkers,\n };\n const postcol = beatColDAG.getBeatColumn(rowOffset, colEnd, 1);\n gridModel.setValue(realRow, realCol + 1, val, (gridRow: GridRow, col: number) => {\n const cell = new GridCell(gridRow, col);\n cell.colAlign = postcol;\n return cell;\n });\n }\n return gridModel.setValue(realRow, realCol, beat, (gridRow: GridRow, col: number) => {\n const cell = new GridCell(gridRow, col);\n cell.colAlign = bcol;\n return cell;\n });\n }\n}\n","import * as TSU from \"@panyam/tsutils\";\n\ntype EdgeData = any;\ntype EdgeFunctor<T> = (node: T) => ReadonlyArray<[T, EdgeData]>;\ntype IDFunc<T> = (t: T) => number | string;\n\nexport function allMinimalCycles<T>(\n nodes: ReadonlyArray<T>,\n idFunc: IDFunc<T>,\n edges: EdgeFunctor<T>,\n): ReadonlyArray<[T, EdgeData]> {\n // Tells which cycle a node is assigned to if any\n const cycles: [T, EdgeData][] = [];\n const inACycle = {} as any;\n nodes.forEach((node) => {\n // start from node and do a BFS to see what cycle a node appears in\n if (!(idFunc(node) in inACycle)) {\n const startNode = node;\n const visited = {} as any;\n let queue: [T, [EdgeData, T][]][] = [[node, []]];\n while (queue.length > 0) {\n const newQueue: [T, [EdgeData, T][]][] = [];\n for (let i = 0; i < queue.length; i++) {\n const [node, c] = queue[i];\n TSU.assert(node != null);\n const e = edges(node);\n let cycle = [...c];\n for (const [nextNode, edgeData] of e) {\n if (nextNode == startNode) {\n // we have a cycle\n cycle.push([edgeData, nextNode]);\n cycle.forEach(([e, n], i) => (inACycle[n] = true));\n cycles.push([startNode, cycle]);\n cycle = cycle.slice(0, cycle.length - 1);\n } else if (!(idFunc(nextNode) in visited)) {\n visited[idFunc(nextNode)] = true;\n newQueue.push([nextNode, [...cycle, [edgeData, nextNode]]]);\n }\n }\n }\n queue = newQueue;\n }\n }\n });\n return cycles;\n}\n\nexport function digraph(): void {\n //\n}\n","import * as TSU from \"@panyam/tsutils\";\nimport { Grammar, Sym, Str, Rule } from \"./grammar\";\n\ntype NumMap<T> = TSU.NumMap<T>;\ntype StringMap<T> = TSU.StringMap<T>;\ntype Nullable<T> = TSU.Nullable<T>;\n\nconst defaultKeyFunc = (x: any) => x.key;\n\nexport class Trie<T> {\n protected keyFunc: (t: T) => string;\n readonly root: TrieNode<T> = new TrieNode();\n\n constructor(keyFunc: (t: T) => string) {\n this.keyFunc = keyFunc;\n }\n\n add(values: T[], fromIndex = 0): TrieNode<T> {\n // we are at the bottom\n let curr = this.root;\n for (let i = fromIndex; i < values.length; i++) {\n const key = this.keyFunc(values[i]);\n if (curr.children.has(key)) {\n curr = curr.children.get(key)!;\n } else {\n const newNode = new TrieNode<T>();\n newNode.value = values[i];\n newNode.parent = curr;\n curr.children.set(key, newNode);\n curr = newNode;\n }\n }\n curr.isLeaf = true;\n return curr;\n }\n\n get debugValue(): any {\n return this.root.debugValue;\n }\n}\n\nexport class TrieNode<T> {\n isLeaf = false;\n value: Nullable<T> = null;\n parent: Nullable<TrieNode<T>> = null;\n children = new Map<string, TrieNode<T>>();\n\n get debugValue(): any {\n const out = { value: this.value, children: {} as any } as any;\n if (this.isLeaf) out[\"isLeaf\"] = true;\n for (const [key, value] of this.children.entries()) {\n out.children[key] = value.debugValue;\n }\n return out;\n }\n}\n\nexport class IDSet<T extends { id: number }> {\n protected _entries: T[] = [];\n protected _entriesByKey: StringMap<T> = {};\n protected keyFunc: (t: T) => string;\n\n constructor(keyFunc: (t: T) => string = defaultKeyFunc) {\n this.keyFunc = keyFunc;\n }\n\n clear(): void {\n this._entries = [];\n this._entriesByKey = {};\n }\n\n /**\n * Removes all entries that match a predict.\n */\n remove(predicate: (t: T) => boolean): boolean {\n const e2: T[] = [];\n this._entriesByKey = {};\n let modified = false;\n for (let l = 0; l < this._entries.length; l++) {\n const e = this._entries[l];\n if (!predicate(e)) {\n // keep it if predicate failes\n e.id = e2.length;\n e2.push(e);\n this._entriesByKey[this.keyFunc(e)] = e;\n } else {\n modified = true;\n }\n }\n this._entries = e2;\n return modified;\n }\n\n get entries(): ReadonlyArray<T> {\n return this._entries;\n }\n\n get(id: number): T {\n TSU.assert(id >= 0 && id < this._entries.length);\n return this._entries[id];\n }\n\n getByKey(key: string): Nullable<T> {\n return this._entriesByKey[key] || null;\n }\n\n ensure(entry: T, throwIfExists = false): T {\n // see if this itemset exists\n if (this.has(entry)) {\n if (throwIfExists) throw new Error(`Entry ${this.keyFunc(entry)} already exists`);\n return this._entriesByKey[this.keyFunc(entry)];\n } else {\n this._entriesByKey[this.keyFunc(entry)] = entry;\n entry.id = this._entries.length;\n this._entries.push(entry);\n return entry;\n }\n }\n\n has(entry: T): boolean {\n return this.keyFunc(entry) in this._entriesByKey;\n }\n\n get size(): number {\n return this._entries.length;\n }\n}\n\nexport class SymbolSet {\n readonly grammar: Grammar;\n readonly enforceSymbolType: Nullable<boolean>;\n entries = new Set<number>();\n hasNull = false;\n\n constructor(grammar: Grammar, enforceSymbolType: Nullable<boolean> = true) {\n this.grammar = grammar;\n this.enforceSymbolType = enforceSymbolType;\n }\n\n get debugString(): string {\n return \"<\" + this.labels().sort().join(\", \") + \">\";\n }\n\n labels(skipAux = false): string[] {\n const out: string[] = [];\n for (const i of this.entries) {\n const exp = this.grammar.getSymById(i);\n TSU.assert(exp != null);\n if (!skipAux || !exp.isAuxiliary) out.push(exp.label);\n }\n if (this.hasNull) out.push(\"\");\n return out;\n }\n\n addFrom(another: SymbolSet, includeNull = true): number {\n return another.addTo(this, includeNull);\n }\n\n addTo(another: SymbolSet, includeNull = true): number {\n const before = another.entries.size;\n for (const termid of this.entries) {\n another.entries.add(termid);\n }\n if (includeNull) {\n another.hasNull = this.hasNull || another.hasNull;\n }\n return another.entries.size - before;\n }\n\n has(term: Sym): boolean {\n return this.entries.has(term.id);\n }\n\n add(term: Sym): this {\n TSU.assert(\n this.enforceSymbolType == null || this.enforceSymbolType == term.isTerminal,\n `Terminal types being enforced: ${this.enforceSymbolType}`,\n );\n this.entries.add(term.id);\n return this;\n }\n\n delete(term: Sym): boolean {\n return this.entries.delete(term.id);\n }\n\n get size(): number {\n return this.entries.size + (this.hasNull ? 1 : 0);\n }\n}\n\n/**\n * Tells which non terminals are nullables.\n */\nexport class NullableSet {\n readonly grammar: Grammar;\n entries: Set<number>;\n private visited: any;\n\n constructor(grammar: Grammar) {\n this.grammar = grammar;\n this.refresh();\n }\n\n get nonterms(): Sym[] {\n const out: Sym[] = [];\n this.entries.forEach((id) => {\n const e = this.grammar.getSymById(id);\n TSU.assert(e != null && !e.isTerminal);\n out.push(e);\n });\n return out;\n }\n\n refresh(): void {\n // Nuke entries cache. Will force isNullable to recompute.\n this.entries = new Set();\n this.visited = {};\n\n let beforeCount = 0;\n do {\n beforeCount = this.entries.size;\n this.grammar.allNonTerminals.forEach((nt) => this.visit(nt));\n } while (beforeCount != this.entries.size);\n }\n\n protected visit(nt: Sym): void {\n for (const rule of this.grammar.rulesForNT(nt)) {\n if (this.isStrNullable(rule.rhs)) {\n this.add(nt);\n break;\n }\n }\n }\n\n isNullable(nt: Sym): boolean {\n return !nt.isTerminal && this.entries.has(nt.id);\n }\n\n isStrNullable(str: Str, fromIndex = 0, toIndex: Nullable<number> = null): boolean {\n if (toIndex == null) {\n toIndex = str.length - 1;\n }\n for (let i = fromIndex; i <= toIndex; i++) {\n if (!this.isNullable(str.syms[i])) {\n return false;\n }\n }\n return true;\n }\n\n add(nt: Sym): void {\n TSU.assert(!nt.isTerminal);\n this.entries.add(nt.id);\n }\n}\n\nclass SymSymbolSets {\n readonly grammar: Grammar;\n entries: NumMap<SymbolSet> = {};\n private _count = 0;\n\n constructor(grammar: Grammar) {\n this.grammar = grammar;\n }\n\n refresh(): void {\n this.entries = {};\n this._count = 0;\n }\n\n forEachTerm(nt: Sym, visitor: (x: Nullable<Sym>) => boolean | void): void {\n const entries = this.entriesFor(nt);\n entries.entries.forEach((x) => {\n const term = this.grammar.getSymById(x);\n TSU.assert(term != null && term.isTerminal);\n visitor(term);\n });\n if (entries.hasNull) visitor(null);\n }\n\n get debugValue(): any {\n const out = {} as any;\n for (const x in this.entries) out[this.grammar.getSymById(x as any)!.label] = this.entries[x].debugString;\n return out;\n }\n\n get count(): number {\n let c = 0;\n for (const x in this.entries) c += this.entries[x].size;\n return c;\n // TSU.assert(c == this._count, \"Count mismatch\")\n // return this._count;\n }\n\n entriesFor(sym: Sym): SymbolSet {\n if (sym.id in this.entries) {\n return this.entries[sym.id];\n } else {\n const out = new SymbolSet(this.grammar);\n this.entries[sym.id] = out;\n return out;\n }\n }\n\n /**\n * Add the null symbol into this set of terminals for a given expression.\n */\n addNull(nt: Sym): boolean {\n const entries = this.entriesFor(nt);\n if (entries.hasNull) return false;\n entries.hasNull = true;\n return true;\n }\n\n /**\n * Add a Null, term or another expression to the set of terminals\n * for a given expression. If source is an expression then all\n * of the source expression's terminal symbosl are added to exp's\n * term set.\n */\n add(nt: Sym, source: Sym, includeNull = true): boolean {\n if (nt.isTerminal) {\n TSU.assert(false, \"Should not be here\");\n }\n const entries = this.entriesFor(nt);\n if (source.isTerminal) {\n if (entries.has(source)) return false;\n // console.log(`Adding Term(${term.label}) to Set of ${exp.id}`);\n entries.add(source);\n this._count++;\n } else {\n const srcEntries = this.entriesFor(source);\n const destEntries = this.entriesFor(nt);\n const count = srcEntries.addTo(destEntries, includeNull);\n this._count += count;\n }\n return true;\n }\n}\n\n/**\n * For each symbol maps its label to a list of terminals that\n * start that non terminal.\n */\nexport class FirstSets extends SymSymbolSets {\n readonly nullables: NullableSet;\n\n constructor(grammar: Grammar, nullables?: NullableSet) {\n super(grammar);\n if (!nullables) {\n nullables = new NullableSet(grammar);\n }\n this.nullables = nullables;\n this.refresh();\n }\n\n /**\n * For a given string return the first(str) starting at a given index.\n * Including eps if it exists.\n */\n forEachTermIn(str: Str, fromIndex = 0, visitor: (term: Nullable<Sym>) => void): void {\n // This needs to be memoized by exp.id + index\n const syms = str.syms;\n const visited = {} as any;\n let allNullable = true;\n for (let j = fromIndex; allNullable && j < syms.length; j++) {\n const symj = syms[j];\n if (symj.isTerminal) {\n visitor(symj);\n allNullable = false;\n } else {\n const nt = symj as Sym;\n this.forEachTerm(nt, (term) => {\n if (term != null && !(term.id in visited)) {\n visited[term.id] = true;\n visitor(term);\n }\n });\n if (!this.nullables.isNullable(symj as Sym)) {\n allNullable = false;\n }\n }\n }\n if (allNullable) visitor(null);\n }\n\n /**\n * Reevaluates the first sets of a grammar.\n * This method assumes that the grammar's nullables are fresh.\n */\n refresh(): void {\n super.refresh();\n // this.grammar.terminals.forEach((t) => this.add(t, t));\n\n let beforeCount = 0;\n do {\n beforeCount = this.count;\n this.grammar.forEachRule(null, (rule) => {\n this.processRule(rule);\n });\n } while (beforeCount != this.count);\n }\n\n processRule(rule: Rule): void {\n const nullables = this.nullables;\n let allNullable = true;\n for (const s of rule.rhs.syms) {\n // First(s) - null will be in First(nonterm)\n // Null will onlybe added if all symbols are nullable\n this.add(rule.nt, s, false);\n if (s.isTerminal || !nullables.isNullable(s as Sym)) {\n // since s is not nullable the next rule's first set\n // cannot affect nonterm's firs set\n allNullable = false;\n break;\n }\n }\n if (allNullable) this.addNull(rule.nt);\n }\n}\n\n/**\n * For each symbol maps its label to a list of terminals that\n * start that non terminal.\n */\nexport class FollowSets extends SymSymbolSets {\n readonly firstSets: FirstSets;\n\n constructor(grammar: Grammar, firstSets?: FirstSets) {\n super(grammar);\n this.firstSets = firstSets || new FirstSets(grammar);\n this.refresh();\n }\n\n get nullables(): NullableSet {\n return this.firstSets.nullables;\n }\n\n /**\n * Reevaluates the follow sets of each expression in our grammar.\n * This method assumes that the grammar's nullables and firstSets are\n * up-to-date.\n */\n refresh(): void {\n super.refresh();\n const g = this.grammar;\n TSU.assert(g.startSymbol != null, \"Select start symbol of the grammar\");\n this.add(g.startSymbol, g.Eof);\n\n let beforeCount = 0;\n do {\n beforeCount = this.count;\n this.grammar.forEachRule(null, (rule) => this.processRule(rule));\n } while (beforeCount != this.count);\n }\n\n /**\n * Add Follows[source] into Follows[dest] recursively.\n */\n processRule(rule: Rule): void {\n const syms = rule.rhs.syms;\n const firstSets = this.firstSets;\n const nullables = this.firstSets.nullables;\n\n // Rule 1:\n // If A -> aBb1b2b3..bn:\n // Follow(B) = Follow(B) U { First(b1b2b3...bn) - eps }\n for (let i = 0; i < syms.length; i++) {\n const sym = syms[i];\n if (sym.isTerminal) continue;\n firstSets.forEachTermIn(rule.rhs, i + 1, (term) => {\n if (term != null) this.add(sym, term);\n });\n }\n\n // Rule 2:\n // If A -> aBb1b2b3..bn:\n // if Nullable(b1b2b3...bn):\n // Follow(B) = Follow(B) U Follow(N)\n for (let i = syms.length - 1; i >= 0; i--) {\n if (syms[i].isTerminal) continue;\n\n // This needs to be memoized??\n let allNullable = true;\n for (let j = i + 1; j < syms.length; j++) {\n const symj = syms[j];\n if (symj.isTerminal || !nullables.isNullable(symj as Sym)) {\n allNullable = false;\n break;\n }\n }\n if (allNullable) {\n this.add(syms[i], rule.nt);\n }\n }\n }\n}\n","import * as TSU from \"@panyam/tsutils\";\nimport { allMinimalCycles } from \"./graph\";\nimport { IDSet, SymbolSet, FirstSets, FollowSets, NullableSet } from \"./sets\";\n\ntype StringMap<T> = TSU.StringMap<T>;\ntype Nullable<T> = TSU.Nullable<T>;\n\n/**\n * Symbols represent both terminals and non-terminals in our system.\n * Chosing a convention of using a single class to represent both instead\n * of a base class with Term and NonTerm children has the following effects:\n * 1. We can change the type of a literal when doing things like reading\n * a grammar DSL when we dont konw if a symbol is a term or non-term\n * until *all* the declarations have been read and parsed.\n * 2. The down side of this we would need more explicit isTerm checks\n * but we would have done that anyway by calling getTerm and getNT\n * verions of the getSym method.\n */\nexport class Sym {\n isAuxiliary = false;\n auxType: string | null = null;\n precedence = 1;\n assocLeft = true;\n\n private static idCounter = -1;\n\n /**\n * An ID assigned to indicate order of \"creation\" of this symbol in the grammar.\n */\n creationId = -1;\n\n /**\n * ID unique across all expression within the grammar.\n */\n id: number;\n\n /**\n * Creates a new symbol in the grammar.\n *\n * @param grammar Grammar this symbol belongs to.\n * @param label Label for the symbol.\n * @param isTerminal Whether the symbol is a terminal or not.\n * @param id ID unique across all expression within the\n * grammar.\n */\n constructor(\n public readonly grammar: Grammar,\n public readonly label: string,\n public isTerminal: boolean,\n id: Nullable<number> = null,\n ) {\n this.isTerminal = isTerminal;\n this.label = label;\n if (id == null) {\n this.id = Sym.idCounter--;\n } else {\n this.id = id;\n }\n }\n\n compareTo(another: this): number {\n return this.label.localeCompare(another.label);\n }\n\n equals(another: this): boolean {\n return this.label == another.label;\n }\n\n toString(): string {\n return this.label;\n }\n}\n\nexport class Str {\n syms: Sym[];\n\n constructor(...syms: Sym[]) {\n this.syms = syms || [];\n }\n\n append(...lits: Sym[]): this {\n for (const l of lits) this.syms.push(l);\n return this;\n }\n\n extend(...strs: Str[]): this {\n for (const s of strs) this.append(...s.syms);\n return this;\n }\n\n copy(): Str {\n return new Str(...this.syms);\n }\n\n add(lit: Sym): void {\n this.syms.push(lit);\n }\n\n isTerminal(index: number): boolean {\n return this.syms[index].isTerminal;\n }\n\n get length(): number {\n return this.syms.length;\n }\n\n toString(): string {\n return this.syms.map((s) => s.toString()).join(\" \");\n }\n\n slice(startIndex: number, endIndex: number): Str {\n return new Str(...this.syms.slice(startIndex, endIndex));\n }\n\n splice(index: number, numToDelete: number, ...itemsToAdd: Sym[]): Str {\n this.syms.splice(index, numToDelete, ...itemsToAdd);\n return this;\n }\n\n compareTo(another: this): number {\n for (let i = 0; i < this.syms.length && i < another.syms.length; i++) {\n const diff = this.syms[i].compareTo(another.syms[i]);\n if (diff != 0) return diff;\n }\n return this.syms.length - another.syms.length;\n }\n\n equals(another: this): boolean {\n return this.compareTo(another) == 0;\n }\n\n /**\n * Returns true if another string is a substring within\n * this string at the given offset.\n */\n containsAt(offset: number, another: Str): boolean {\n let i = 0;\n for (; i < another.length && offset + i < this.syms.length; i++) {\n if (!this.syms[offset + i].equals(another.syms[i])) return false;\n // if (this.cardinalities[i] != another.cardinalities[i]) return false;\n }\n return i == another.length;\n }\n\n get debugString(): string {\n return this.syms.map((lit) => lit.label).join(\" \");\n }\n}\n\nexport class RuleAction {\n constructor(public value: string | number) {}\n\n get isFunction(): boolean {\n return typeof this.value === \"string\";\n }\n\n get isChildPosition(): boolean {\n return typeof this.value === \"number\";\n }\n}\n\nexport class Rule {\n id: number;\n constructor(\n public nt: Sym,\n public rhs: Str,\n public action: RuleAction | null = null,\n ) {\n if (nt.isTerminal) {\n throw new Error(\"Cannot add rules to a terminal\");\n }\n }\n\n get debugString(): string {\n return `${this.nt.label} -> ${this.rhs.debugString}`;\n }\n\n equals(another: this): boolean {\n return this.compareTo(another) == 0;\n }\n\n compareTo(another: this): number {\n TSU.assert(!isNaN(this.id));\n const diff = this.nt.compareTo(another.nt);\n if (diff == 0) {\n this.rhs.compareTo(another.rhs);\n }\n return diff;\n }\n}\n\nexport class Grammar {\n public startSymbol: Nullable<Sym> = null;\n modified = true;\n protected symbolSet = new IDSet<Sym>((s) => s.label);\n protected allRules: Rule[] = [];\n protected _rulesForNT: Nullable<StringMap<Rule[]>> = null;\n protected _followSets: Nullable<FollowSets> = null;\n\n /**\n * Prefix used for auxiliary symbols.\n */\n auxNTPrefix: string;\n\n readonly Null: Sym;\n readonly Eof: Sym;\n private _AugStartRule: Rule;\n private _hasNull = false;\n\n /**\n * A way of creating Grammars with a \"single expresssion\".\n */\n static make(callback: (g: Grammar) => void): Grammar {\n const g = new Grammar();\n callback(g);\n return g;\n }\n\n constructor(config?: any) {\n config = config || {};\n this.auxNTPrefix = config.auxNTPrefix || \"$\";\n this.Null = this.newTerm(\"\");\n this.Eof = this.newTerm(\"$end\");\n }\n\n rulesForNT(nt: Sym): Rule[] {\n TSU.assert(!nt.isTerminal);\n if (this._rulesForNT == null) {\n this._rulesForNT = {};\n for (const rule of this.allRules) {\n if (!(rule.nt.label in this._rulesForNT)) {\n this._rulesForNT[rule.nt.label] = [];\n }\n this._rulesForNT[rule.nt.label].push(rule);\n }\n }\n if (!(nt.label in this._rulesForNT)) {\n this._rulesForNT[nt.label] = [];\n }\n return this._rulesForNT[nt.label];\n }\n\n get nullables(): NullableSet {\n return this.firstSets.nullables;\n }\n\n get firstSets(): FirstSets {\n return this.followSets.firstSets;\n }\n\n get followSets(): FollowSets {\n if (this.modified || this._followSets == null) {\n this.refresh();\n }\n TSU.assert(this._followSets != null);\n return this._followSets;\n }\n\n get augStartRule(): Rule {\n return this._AugStartRule;\n }\n\n augmentStartSymbol(label = \"$accept\"): this {\n TSU.assert(this._AugStartRule == null, \"Ensure this grammar has not yet been augmented.\");\n TSU.assert(this.startSymbol != null, \"Start symbol not yet set\");\n const augSym = this.newNT(label);\n this._AugStartRule = new Rule(augSym, new Str(this.startSymbol));\n this.addRule(this._AugStartRule, 0);\n return this;\n }\n\n refresh(): this {\n this.symbolSet.entries.forEach((s, i) => (s.id = i));\n this._rulesForNT = null;\n this.allRules.forEach((rule, i) => {\n rule.id = i;\n });\n this._followSets = new FollowSets(this);\n this.modified = false;\n return this;\n }\n\n addTerminals(...terminals: string[]): void {\n for (const t of terminals) {\n this.newTerm(t);\n }\n }\n\n get terminals(): ReadonlyArray<Sym> {\n return this.symbolSet.entries.filter((x) => x.isTerminal);\n }\n\n get allNonTerminals(): ReadonlyArray<Sym> {\n return this.symbolSet.entries.filter((x) => !x.isTerminal);\n }\n\n get nonTerminals(): ReadonlyArray<Sym> {\n return this.symbolSet.entries.filter((x) => !x.isTerminal && !x.isAuxiliary);\n }\n\n get auxNonTerminals(): ReadonlyArray<Sym> {\n return this.symbolSet.entries.filter((x) => x.isAuxiliary);\n }\n\n get allSymbols(): ReadonlyArray<Sym> {\n return this.symbolSet.entries;\n }\n\n /**\n * A way to quickly iterate through all non-terminals.\n */\n forEachNT(visitor: (nt: Sym) => void | boolean | undefined | null): void {\n for (const sym of this.symbolSet.entries) {\n if (sym.isTerminal) continue;\n if (visitor(sym) == false) return;\n }\n }\n\n /**\n * A iterator across all the rules for either all non terminals in this grammar\n * for a single non terminal (if the nt value is non null).\n *\n * @param visitor\n */\n forEachRule(nt: Nullable<Sym>, visitor: (rule: Rule, index: number) => void | boolean | undefined | null): boolean {\n const rules = nt == null ? this.allRules : this.rulesForNT(nt) || [];\n for (let i = 0; i < rules.length; i++) {\n if (visitor(rules[i], i) == false) return false;\n }\n return true;\n }\n\n getRule(nt: string | Sym, index: number): Rule {\n if (typeof nt === \"string\") nt = this.getSym(nt)!;\n TSU.assert(nt != null);\n return this.rulesForNT(nt)[index];\n }\n\n /**\n * Return the the index of a rule if it already exists to prevent duplicates.\n */\n findRule(nt: Sym, production: Str): number {\n return this.rulesForNT(nt).findIndex((r) => r.nt == nt && r.rhs.equals(production));\n }\n\n /**\n * Adds a new rule to a particular non terminal of the grammar\n * Each rule represents a production of the form:\n *\n * name -> A B C D;\n *\n * Null production can be represented with an empty exps list.\n */\n add(nt: string | Sym, production: Str, action: RuleAction | null = null): Rule {\n let nonterm: Nullable<Sym> = null;\n if (typeof nt === \"string\") {\n nonterm = this.getSym(nt);\n if (nonterm == null) {\n // create it\n nonterm = this.newNT(nt);\n }\n } else {\n nonterm = this.ensureSym(nt);\n }\n return this.addRule(new Rule(nonterm, production, action));\n }\n\n /**\n * Add a rule directly.\n */\n addRule(rule: Rule, index = -1): Rule {\n if (this.findRule(rule.nt, rule.rhs) >= 0) {\n throw new Error(\"Duplicate rule: \" + rule.debugString);\n }\n rule.id = this.allRules.length;\n if (rule.rhs.length == 0) this._hasNull = true;\n if (index < 0) {\n this.allRules.push(rule);\n } else {\n this.allRules.splice(index, 0, rule);\n }\n this._rulesForNT = null;\n // this.rulesForNT(rule.nt).push(rule);\n this.modified = true;\n return rule;\n }\n\n /**\n * Removes all rules from the grammar which match the given predicate.\n */\n removeRules(pred: (r: Rule) => boolean): boolean {\n this.allRules = this.allRules.filter((r) => !pred(r));\n this._rulesForNT = null;\n this.modified = true;\n return true;\n }\n\n /**\n * Removes all symbols from the grammar and all of its productions which match\n * a particular predicate.\n */\n removeSymbols(pred: (s: Sym) => boolean): boolean {\n let modified = false;\n const newRules: Rule[] = [];\n this.allRules.forEach((r) => {\n if (pred(r.nt)) return;\n // if it was already a null production then leave it\n if (r.rhs.length == 0) {\n newRules.push(r);\n } else {\n const newRhs = new Str(...r.rhs.syms.filter((s) => !pred(s)));\n modified = modified || r.rhs.length != newRhs.length;\n if (newRhs.length > 0) {\n newRules.push(new Rule(r.nt, newRhs));\n }\n }\n });\n this.allRules = newRules;\n modified = this.symbolSet.remove(pred) || modified;\n this.modified = this.modified || modified;\n return modified;\n }\n\n /**\n * Gets or creates a terminal with the given label.\n * The grammar acts as a factory for terminal symbols\n * so that we can reuse symbols instead of having\n * users create new symbols each time.\n *\n * This also ensures that users are not able mix terminal\n * and non terminal labels.\n */\n getSymById(id: number): Nullable<Sym> {\n // if (id == Grammar.AUG_SYM_ID) return this._AugStartRule?.nt || null;\n // else if (id == this.Eof.id) return this.Eof;\n // else if (id == this.Null.id) return this.Null;\n return this.symbolSet.get(id);\n }\n\n getSym(label: string): Nullable<Sym> {\n // if (this._AugStartRule && label == this._AugStartRule.nt.label) return this._AugStartRule.nt;\n return this.symbolSet.getByKey(label);\n }\n\n ensureSym(sym: Sym, throwIfExists = false): Sym {\n const sym2 = this.symbolSet.ensure(sym, throwIfExists);\n if (sym == sym2) {\n if (sym2.creationId < 0) {\n sym2.creationId = this.symbolSet.size;\n }\n } else {\n TSU.assert(!throwIfExists, \"Should have already thrown error\");\n }\n return sym2;\n }\n\n /**\n * Ensures that a terminal by a given name exists (creating if\n * necessary). If a terminal already exists by this label then\n * an error is thrown.\n *\n * The grammar acts as a factory for terminal and non terminal symbols\n * so that we can reuse symbols instead of having users create new\n * symbols each time. This also ensures that users are not able mix\n * terminal and non terminal labels.\n */\n T(label: string, throwIfExists = false): Sym {\n let t = this.getSym(label);\n if (t != null) {\n if (throwIfExists) throw new Error(`Terminal ${label} is already exists`);\n if (!t.isTerminal) throw new Error(`Symbol (${label}) already exists as a non-terminal`);\n } else {\n t = new Sym(this, label, true);\n t = this.ensureSym(t, true);\n }\n return t;\n }\n\n /**\n * Ensures that a non term by a given name exists (creating if\n * necessary). If a terminal already exists by this label then\n * an error is thrown.\n *\n * The grammar acts as a factory for terminal and non terminal symbols\n * so that we can reuse symbols instead of having users create new\n * symbols each time. This also ensures that users are not able mix\n * terminal and non terminal labels.\n */\n NT(label: string, isAuxiliary = false, throwIfExists = false): Sym {\n let nt = this.getSym(label);\n if (nt != null) {\n if (throwIfExists) throw new Error(`Non-terminal ${label} is already exists`);\n if (nt.isTerminal) throw new Error(`Symbol (${label}) already exists as a terminal`);\n } else {\n nt = new Sym(this, label, false);\n nt.isAuxiliary = isAuxiliary;\n nt = this.ensureSym(nt, true);\n if (!isAuxiliary && this.startSymbol == null) {\n this.startSymbol = nt;\n }\n }\n return nt;\n }\n\n /**\n * Creates a terminal with the given label if one does not\n * already exist.\n */\n newTerm(label: string): Sym {\n return this.T(label, true);\n }\n\n /**\n * Creates a non terminal with the given label if it does not\n * already exist.\n */\n newNT(label: string, isAuxiliary = false): Sym {\n return this.NT(label, isAuxiliary, true);\n }\n\n /**\n * Checks if a given label is a terminal.\n */\n isTerminal(label: string): boolean {\n const t = this.getSym(label);\n return t != null && t.isTerminal;\n }\n\n /**\n * Checks if a given label is a non-terminal.\n */\n isNT(label: string): boolean {\n const t = this.getSym(label);\n return t != null && !t.isTerminal && !t.isAuxiliary;\n }\n\n /**\n * Checks if a given label is an auxiliary non-terminal.\n */\n isAuxNT(label: string): boolean {\n const t = this.getSym(label);\n return t != null && !t.isTerminal && t.isAuxiliary;\n }\n\n seq(...exps: (Str | string)[]): Str {\n if (exps.length == 1) {\n return this.normalizeRule(exps[0]);\n } else {\n const out = new Str();\n for (const e of exps) {\n const s = this.normalizeRule(e);\n // insert string here inline\n // A ( B C D ) => A B C D\n for (let i = 0; i < s.length; i++) {\n // out.add(s.syms[i], s.cardinalities[i]);\n out.add(s.syms[i]);\n }\n }\n return out;\n }\n }\n\n /**\n * Provides a union rule:\n *\n * (A | B | C | D)\n *\n * Each of A, B, C or D themselves could be strings or literals.\n */\n anyof(...rules: (Str | string)[]): Str {\n if (rules.length == 1) {\n return this.normalizeRule(rules[0]);\n } else {\n // see if there is already NT with the exact set of rules\n // reuse if it exists. That would make this method\n // Idempotent (which it needs to be).\n return new Str(this.ensureAuxNT(...rules.map((r) => this.normalizeRule(r))));\n }\n }\n\n opt(exp: Str | string): Str {\n // convert to aux rule\n const out = this.anyof(exp, new Str());\n const nt = out.syms[0];\n TSU.assert(out.syms.length == 1 && nt.isAuxiliary, \"NT must be an auxiliary symbol\");\n nt.auxType = \"opt\";\n return out;\n }\n\n atleast0(exp: Str | string, leftRec = true): Str {\n const s = this.normalizeRule(exp);\n // We want to find another auxiliary NT that has the following rules:\n // X -> exp X | ; # if leftRec = true\n //\n // X -> X exp | ; # otherwise:\n let auxNT = this.findAuxNT((auxNT) => {\n const rules = this.rulesForNT(auxNT);\n if (rules.length != 2) return false;\n\n let which = 0;\n if (rules[0].rhs.length == 0) {\n which = 1;\n } else if (rules[1].rhs.length == 0) {\n which = 0;\n } else {\n return false;\n }\n\n const rule = rules[which].rhs;\n if (rule.length != 1 + exp.length) return false;\n if (rule.syms[0].equals(auxNT)) {\n return rule.containsAt(1, s);\n } else if (rule.syms[rule.length - 1].equals(auxNT)) {\n return rule.containsAt(0, s);\n }\n return false;\n });\n if (auxNT == null) {\n auxNT = this.newAuxNT();\n auxNT.auxType = leftRec ? \"atleast0:left\" : \"atleast0\";\n this.add(auxNT, new Str());\n if (leftRec) {\n this.add(auxNT, new Str(auxNT).extend(s));\n } else {\n this.add(auxNT, s.copy().append(auxNT));\n }\n }\n return new Str(auxNT);\n }\n\n atleast1(exp: Str | string, leftRec = true): Str {\n const s = this.normalizeRule(exp);\n // We want to find another auxiliary NT that has the following rules:\n // X -> exp X | exp ; # if leftRec = true\n //\n // X -> X exp | exp ; # otherwise:\n let auxNT = this.findAuxNT((auxNT) => {\n const rules = this.rulesForNT(auxNT);\n if (rules.length != 2) return false;\n\n let which = 0;\n if (rules[0].rhs.equals(s)) {\n which = 1;\n } else if (rules[1].rhs.equals(s)) {\n which = 0;\n } else {\n return false;\n }\n\n const rule = rules[which].rhs;\n if (rule.length != 1 + exp.length) return false;\n if (rule.syms[0].equals(auxNT)) {\n return rule.containsAt(1, s);\n } else if (rule.syms[rule.length - 1].equals(auxNT)) {\n return rule.containsAt(0, s);\n }\n return false;\n });\n if (auxNT == null) {\n auxNT = this.newAuxNT();\n auxNT.auxType = leftRec ? \"atleast1:left\" : \"atleast1\";\n this.add(auxNT, s);\n if (leftRec) {\n this.add(auxNT, new Str(auxNT).extend(s));\n } else {\n this.add(auxNT, s.copy().append(auxNT));\n }\n }\n return new Str(auxNT);\n }\n\n normalizeRule(exp: Str | string): Str {\n if (typeof exp === \"string\") {\n const lit = this.getSym(exp);\n if (lit == null) throw new Error(`Invalid symbol: '${exp}'`);\n return new Str(lit);\n } else {\n // We have an expression that needs to be fronted by an\n // auxiliarry non-terminal\n return exp;\n }\n }\n\n // Override this to have a different\n protected auxNTCount = 0;\n protected newAuxNTName(): string {\n return this.auxNTPrefix + this.auxNTCount++;\n }\n\n newAuxNT(name = \"\"): Sym {\n if (name == \"\") name = this.newAuxNTName();\n return this.newNT(name, true);\n }\n\n ensureAuxNT(...rules: Str[]): Sym {\n let nt = this.findAuxNTByRules(...rules);\n if (nt == null) {\n nt = this.newAuxNT();\n nt.auxType = \"anyof\";\n for (const rule of rules) this.add(nt, rule);\n }\n return nt;\n }\n\n /**\n * Find an auxiliary rule that has the same rules as the ones here.\n * This can be used to ensure duplicate rules are not created for\n * union expressions.\n */\n findAuxNT(filter: (nt: Sym) => boolean): Nullable<Sym> {\n for (const auxNT of this.symbolSet.entries) {\n if (!auxNT.isAuxiliary) continue;\n if (filter(auxNT)) return auxNT;\n }\n return null;\n }\n\n findAuxNTByRules(...rules: Str[]): Nullable<Sym> {\n return this.findAuxNT((auxNT) => {\n const ntRules = this.rulesForNT(auxNT);\n if (ntRules.length != rules.length) return false;\n for (let i = 0; i < ntRules.length; i++) {\n if (!ntRules[i].rhs.equals(rules[i])) return false;\n }\n return true;\n });\n }\n\n print(options: any = null): string[] {\n options = options || {};\n const ruleSep = options.ruleSep || \"->\";\n const includeSemiColon = options.includeSemiColon || false;\n const lambdaSymbol = options.lambdaSymbol || \"\";\n const out: string[] = [];\n this.forEachRule(null, (rule: Rule, index: number) => {\n let r = `${rule.nt.label} ${ruleSep} `;\n if (rule.rhs.length > 0) r += rule.rhs.debugString;\n else r += lambdaSymbol;\n if (includeSemiColon) r += \" ;\";\n out.push(r);\n });\n return out;\n }\n\n /**\n * Returns a flat list of all productions in a single list.\n */\n get debugValue(): string[] {\n const out: string[] = [];\n this.forEachRule(null, (rule: Rule, index: number) => {\n out.push(`${rule.nt.label} -> ${rule.rhs.debugString}`);\n });\n return out;\n }\n\n /**\n * Returns all non terminals that can derive terminals.\n */\n get terminalDerivingSymbols(): SymbolSet {\n const out = new SymbolSet(this, null);\n let nadded = -1;\n let allDerive = true;\n while (nadded != 0) {\n nadded = 0;\n for (const rule of this.allRules) {\n allDerive = true;\n for (const sym of rule.rhs.syms) {\n if (!out.has(sym)) {\n if (sym.isTerminal) {\n out.add(sym);\n nadded++;\n } else {\n allDerive = false;\n }\n }\n }\n if (allDerive && !out.has(rule.nt)) {\n out.add(rule.nt);\n nadded++;\n }\n }\n }\n return out;\n }\n\n /*\n * Returns all non terminal that are reachable from a given symbol.\n * If the FROM symbol is omitted then the start symbol is used.\n */\n reachableSymbols(fromSymbol: Nullable<Sym> = null): SymbolSet {\n if (fromSymbol == null) {\n fromSymbol = this._AugStartRule ? this._AugStartRule.nt : this.startSymbol;\n }\n TSU.assert(fromSymbol != null, \"Start symbol does not exist\");\n const reachable = new SymbolSet(this, false).add(fromSymbol);\n let queue: Sym[] = [fromSymbol];\n while (queue.length > 0) {\n const newQueue: Sym[] = [];\n for (const curr of queue) {\n for (const rule of this.rulesForNT(curr)) {\n for (const sym of rule.rhs.syms) {\n if (!sym.isTerminal && !reachable.has(sym)) {\n newQueue.push(sym);\n reachable.add(sym);\n }\n }\n }\n }\n queue = newQueue;\n }\n return reachable;\n }\n\n /**\n * Returns all cycles in this grammar.\n */\n get cycles(): ReadonlyArray<[Sym, any]> {\n /*\n * Returns the edge of the given nonterm\n * For a nt such that:\n * S -> alpha1 X1 beta1 |\n * alpha2 X2 beta2 |\n * ...\n * alphaN XN betaN |\n *\n * S's neighbouring nodes would be Xk if all of alphak is optional\n * AND all of betak is optional\n */\n const edgeFunctor = (node: Sym): [Sym, any][] => {\n const out: [Sym, any][] = [];\n this.forEachRule(node, (rule, ruleIndex) => {\n rule.rhs.syms.forEach((s, j) => {\n if (s.isTerminal) return;\n if (this.nullables.isStrNullable(rule.rhs, 0, j - 1) && this.nullables.isStrNullable(rule.rhs, j + 1)) {\n out.push([s, [node, ruleIndex]]);\n }\n });\n });\n return out;\n };\n return allMinimalCycles(this.allNonTerminals, (val: Sym) => val.label, edgeFunctor);\n }\n\n /**\n * Returns a set of \"Starting\" non terminals which have atleast\n * one production containing left recursion.\n */\n get leftRecursion(): any {\n const edgeFunctor = (node: Sym): [Sym, any][] => {\n const out: [Sym, any][] = [];\n this.forEachRule(node, (rule, ruleIndex) => {\n rule.rhs.syms.forEach((s, j) => {\n if (s.isTerminal) return;\n out.push([s, ruleIndex]);\n // If this is symbol is not nullable then we can stop here\n return this.nullables.isNullable(s);\n });\n });\n return out;\n };\n return allMinimalCycles(this.allNonTerminals, (val: Sym) => val.id, edgeFunctor);\n }\n}\n","export enum CharClassType {\n WORD_CHAR,\n DIGITS,\n SPACES,\n}\n\nconst ZERO = \"0\".charCodeAt(0);\nconst NINE = \"9\".charCodeAt(0);\nconst lA = \"a\".charCodeAt(0);\nconst lZ = \"z\".charCodeAt(0);\nconst uA = \"A\".charCodeAt(0);\nconst uZ = \"Z\".charCodeAt(0);\nconst USCORE = \"_\".charCodeAt(0);\n\n/**\n * An abstract class to be implemented for enabling different types of char classes.\n * Char classes are a form of \"short codes\" to identify characters. eg SPACES, DIGITS etc.\n * Char classes are only shortcuts. One can get away without using them and instead explicitly\n * construct the underlying state machine or regex (eg DIGIT could be replaced with [0-9]).\n */\nexport abstract class CharClassHelper {\n matches(charCode: number, neg: boolean): boolean {\n const res = this.match(charCode);\n return neg ? !res : res;\n }\n protected abstract match(charCode: number): boolean;\n abstract reString(neg: boolean): string;\n}\n\nconst spaceChars = \" \\f\\n\\r\\t\\v\\u00a0\\u1680\\u2028\\u2029\\u202f\\u205f\\u3000\\ufeff\";\n\n/**\n * Spaces - \\s => [ \\b\\c\\u00a0\\t\\r\\n\\u2028\\u2029<BOM><USP>]\n * BOM = \\uFEFF\n * USP = Other unicode space separator\n */\nexport class Spaces extends CharClassHelper {\n match(charCode: number): boolean {\n // if (charCode == 0x180e) return true;\n if (charCode >= 0x2000 && charCode <= 0x200a) return true;\n for (let i = 0; i < spaceChars.length; i++) {\n if (spaceChars.charCodeAt(i) == charCode) return true;\n }\n return false;\n }\n\n reString(neg: boolean): string {\n return neg ? \"\\\\S\" : \"\\\\s\";\n }\n}\n\n/**\n * Char class for denoting a digit - [0-9].\n */\nexport class Digit extends CharClassHelper {\n match(charCode: number): boolean {\n return charCode >= ZERO && charCode <= NINE;\n }\n\n reString(neg: boolean): string {\n return neg ? \"\\\\D\" : \"\\\\d\";\n }\n}\n\n/**\n * Char class for denoting \"\\\\w\" - ie any WordChar\n */\nexport class WordChar extends CharClassHelper {\n match(charCode: number): boolean {\n return (\n charCode == USCORE ||\n (charCode >= ZERO && charCode <= NINE) ||\n (charCode >= lA && charCode <= lZ) ||\n (charCode >= uA && charCode <= uZ)\n );\n return true;\n }\n\n reString(neg: boolean): string {\n return neg ? \"\\\\W\" : \"\\\\w\";\n }\n}\n\nexport const CharClassHelpers: ReadonlyArray<CharClassHelper> = [new WordChar(), new Digit(), new Spaces()];\n","export enum PropertyName {\n // Binary Property Names\n gc,\n General_Category = gc,\n sc,\n Script = sc,\n scx,\n Script_Extension = scx,\n\n // Non binary property names\n Any,\n ASCII,\n AHex,\n ASCII_Hex_Digit = AHex,\n Alpha,\n Alphabetic = Alpha,\n Bidi_M,\n Bidi_Mirrored = Bidi_M,\n Bidi_C,\n Bidi_Control = Bidi_C,\n CI,\n Case_Ignorable = CI,\n Cased,\n CWCF,\n Changes_When_Casefolded = CWCF,\n CWCM,\n Changes_When_Casemapped = CWCM,\n CWL,\n Changes_When_Lowercased = CWL,\n CWKCF,\n Changes_When_NFKC_Casefolded = CWKCF,\n CWT,\n Changes_When_Titlecased = CWT,\n CWU,\n Changes_When_Uppercased = CWU,\n Dash,\n DI,\n Default_Ignorable_Code_Point = DI,\n Dep,\n Deprecated = Dep,\n Dia,\n Diacritic = Dia,\n Emoji,\n Emoji_Component,\n Emoji_Modifier,\n Emoji_Modifier_Base,\n Emoji_Presentation,\n Ext,\n Extender = Ext,\n Gr_Base,\n Grapheme_Base = Gr_Base,\n Gr_Ext,\n Grapheme_Extend = Gr_Ext,\n Hex,\n Hex_Digit = Hex,\n IDSB,\n IDS_Binary_Operator = IDSB,\n IDST,\n IDS_Trinary_Operator = IDST,\n IDC,\n ID_Continue = IDC,\n IDS,\n ID_Start = IDS,\n Ideo,\n Ideographic = Ideo,\n Join_C,\n Join_Control = Join_C,\n LOE,\n Logical_Order_Exception = LOE,\n Lower,\n Lowercase = Lower,\n Math,\n NChar,\n Noncharacter_Code_Point = NChar,\n Pat_Syn,\n Pattern_Syntax = Pat_Syn,\n Pat_WS,\n Pattern_White_Space = Pat_WS,\n QMark,\n Quotation_Mark = QMark,\n Radical,\n RI,\n Regional_Indicator = RI,\n STerm,\n Sentence_Terminal = STerm,\n SD,\n Soft_Dotted = SD,\n Term,\n Terminal_Punctuation = Term,\n UIdeo,\n Unified_Ideograph = UIdeo,\n Upper,\n Uppercase = Upper,\n VS,\n Variation_Selector = VS,\n space,\n White_Space = space,\n XIDC,\n XID_Continue = XIDC,\n XIDS,\n XID_Start = XIDS,\n}\n\nexport enum PropertyValue {\n // General Category proeprty values\n LC,\n Cased_Letter = LC,\n Pe,\n Close_Punctuation = Pe,\n Pc,\n Connector_Punctuation = Pc,\n Cc,\n cntrl = Cc,\n Control = Cc,\n Sc,\n Currency_Symbol = Sc,\n Pd,\n Dash_Punctuation = Pd,\n Nd,\n digit = Nd,\n Decimal_Number = digit,\n Me,\n Enclosing_Mark = Me,\n Pf,\n Final_Punctuation = Pf,\n Cf,\n Format = Cf,\n Pi,\n Initial_Punctuation = Pi,\n L,\n Letter = L,\n Nl,\n Letter_Number = Nl,\n Zl,\n Line_Separator = Zl,\n Ll,\n Lowercase_Letter = Ll,\n M,\n Combining_Mark = M,\n Mark,\n Sm,\n Math_Symbol = Sm,\n Lm,\n Modifier_Letter = Lm,\n Sk,\n Modifier_Symbol = Sk,\n Mn,\n Nonspacing_Mark = Mn,\n N,\n Number = N,\n Ps,\n Open_Punctuation = Ps,\n C,\n Other = C,\n Lo,\n Other_Letter = Lo,\n No,\n Other_Number = No,\n Po,\n Other_Punctuation = Po,\n So,\n Other_Symbol = So,\n Zp,\n Paragraph_Separator = Zp,\n Co,\n Private_Use = Co,\n P,\n punct = P,\n Punctuation = P,\n Z,\n Separator = Z,\n Zs,\n Space_Separator = Zs,\n Mc,\n Spacing_Mark = Mc,\n Cs,\n Surrogate = Cs,\n S,\n Symbol = S,\n Lt,\n Titlecase_Letter = Lt,\n Cn,\n Unassigned = Cn,\n Lu,\n Uppercase_Letter = Lu,\n // Script and Script Extension proeprty values\n}\n\nexport function propertyNameFor(value: string): PropertyName {\n value = value.trim();\n if (!(value in PropertyName)) {\n throw new SyntaxError(\"Invalid property name: \" + value);\n }\n return (PropertyName as any)[value];\n}\n\nexport function propertyValueFor(value: string): PropertyValue {\n value = value.trim();\n if (!(value in PropertyValue)) {\n throw new SyntaxError(\"Invalid property value: \" + value);\n }\n return (PropertyValue as any)[value];\n}\n\nexport function propertyNameString(value: number): string {\n if (!(value in PropertyName)) {\n throw new Error(\"Invalid property name: \" + value);\n }\n return PropertyName[value];\n}\n\nexport function propertyValueString(value: number): string {\n if (!(value in PropertyValue)) {\n throw new Error(\"Invalid property value: \" + value);\n }\n return PropertyValue[value];\n}\n","import * as TSU from \"@panyam/tsutils\";\nimport { TapeInterface as Tape } from \"./tape\";\nimport { Char } from \"./core\";\n\nfunction isNewLineChar(ch: string): boolean {\n return ch == \"\\r\" || ch == \"\\n\" || ch == \"\\u2028\" || ch == \"\\u2029\";\n}\n\nexport class Match {\n groups: [number, number][] = [];\n positions: number[] = [];\n constructor(public priority = 10, public matchIndex = -1, public start = -1, public end = -1) {}\n}\n\nexport enum OpCode {\n // Any character\n Any,\n // Any character not including a new line\n AnyNonNL,\n // Char and CI Chars\n Char,\n CIChar,\n // NegChar,\n // NegCIChar,\n\n // Non char opcodes\n Match,\n Noop,\n Save,\n Split,\n Jump,\n Begin, // Forward lookahead matches\n RBegin, // Reverse lookahead matches\n End,\n\n // Look ahead and Look back matchers\n // ^ and $ that are not activated on newlines\n StartingChar,\n EndingChar,\n // ^ and $ that are activated on newlines as well\n MLStartingChar,\n MLEndingChar,\n StartOfWord,\n EndOfWord,\n GroupStart,\n GroupEnd,\n\n // Stops the thread if state does not match\n EnsureState,\n}\n\nexport class Prog {\n instrs: Instr[] = [];\n stateMapping: Map<string, number>;\n\n constructor(public readonly startCondition = \"INITIAL\", public readonly scIsInclusive = true) {\n this.stateMapping = new Map<string, number>();\n this.registerState(\"INITIAL\");\n this.registerState(startCondition);\n }\n\n get length(): number {\n return this.instrs.length;\n }\n\n /**\n * Adds a state to our program and returns the state's index.\n */\n registerState(state: string): number {\n if (!this.stateMapping.has(state)) {\n this.stateMapping.set(state, this.stateMapping.size);\n }\n return this.stateMapping.get(state) || -1;\n }\n\n add(opcode: any, char: null | Char = null, ...args: number[]): Instr {\n const out = new Instr(opcode, char).add(...args);\n out.offset = this.instrs.length;\n this.instrs.push(out);\n return out;\n }\n\n static with(initializer: (prog: Prog) => void): Prog {\n const out = new Prog();\n initializer(out);\n return out;\n }\n\n debugValue(instrDebugValue: (instr: Instr) => string = InstrDebugValue): any {\n if (instrDebugValue) {\n return this.instrs.map((instr, index) => {\n if (instr.comment.trim().length > 0) return `L${index}: ${instrDebugValue(instr)} # ${instr.comment}`;\n else return `L${index}: ${instrDebugValue(instr)}`;\n });\n } else {\n return this.instrs.map((instr, index) => `L${index}: ${instr.debugValue}`);\n }\n }\n}\n\nexport class Instr {\n offset = 0;\n comment = \"\";\n args: number[] = [];\n // used for char match instructions - if opcode == Char or CIChar\n constructor(public readonly opcode: any, public char: null | Char = null) {\n this.char = char;\n }\n\n add(...args: number[]): this {\n this.args.push(...args);\n return this;\n }\n\n get debugValue(): any {\n let c = this.comment.trim();\n if (c.length > 0) c = \" # \" + c;\n return `${this.opcode} ${this.args.join(\" \")} ${this.char || \"\"} ${c}`;\n }\n}\n\n/**\n * A thread that is performing an execution of the regex VM.\n */\nexport class Thread {\n parentId = -1;\n id = 0;\n priority = 0;\n /**\n * Saved positions into the input stream for the purpose of\n * partial and custom matches.\n */\n groups: [number, number][] = [];\n positions: number[] = [];\n registers: TSU.NumMap<number> = {};\n\n /**\n * Create a thread at the given offset\n */\n constructor(public readonly offset: number = 0, public readonly gen: number = 0) {}\n\n regIncr(regId: number): void {\n if (!(regId in this.registers)) {\n throw new Error(`Register at offset ${regId} is invalid`);\n }\n this.registers[regId]++;\n }\n\n regAcquire(regId: number): void {\n if (regId in this.registers) {\n throw new Error(`Register at offset ${regId} already acquired. Release it first`);\n }\n this.registers[regId] = 0;\n }\n\n regRelease(regId: number): void {\n if (!(regId in this.registers)) {\n throw new Error(`Register at offset ${regId} is invalid`);\n }\n delete this.registers[regId];\n }\n\n regValue(regId: number): number {\n if (!(regId in this.registers)) {\n throw new Error(`Register at offset ${regId} is invalid`);\n }\n return this.registers[regId];\n }\n}\n\nexport interface VMTracer {\n threadDequeued(thread: Thread, tapeIndex: number): void;\n threadStepped(thread: Thread, tapeIndex: number, gen: number): void;\n threadQueued(thread: Thread, tapeIndex: number): void;\n}\n\nexport class VM {\n // TODO - To prevent excessive heap activity and GC\n // create a pool of threads and just have a cap on\n // match sizes\n // To eve simplify each Thread could just be something like:\n // number[] where\n // number[0] == offset\n // number[1-2*MaxSubs] = Substitutions\n // number[2*MaxSubs - 2*MaxSubs + M] = Registers\n // where M = Max number of NewReg instructions\n protected threadCounter = 0;\n protected currThreads: Thread[] = [];\n protected nextThreads: Thread[] = [];\n protected startPos = 0; // Where the match is beginning from - this will be set to tape.index when match is called\n // Initial state is always 0\n protected currState = 0;\n\n /**\n * Get the current lexer state (for incremental lexing support).\n * State is used to track context-sensitive lexing (e.g., inside string, comment).\n */\n getState(): number {\n return this.currState;\n }\n\n /**\n * Set the lexer state (for incremental lexing support).\n * Allows restarting lexing from a saved state.\n */\n setState(state: number): void {\n this.currState = state;\n }\n\n protected gen = 0;\n // Records which \"generation\" of the match a particular\n // offset is in. If a thread is added at a particular\n // offset the generation number is used to see if the\n // thread is a duplicate (and avoided if so). This\n // ensures that are linearly bounded on the number of\n // number threads as we match.\n protected genForOffset: TSU.NumMap<number> = {};\n\n tracer: VMTracer;\n constructor(\n public readonly prog: Prog,\n public readonly start = 0,\n public readonly end = -1,\n public readonly forward = true,\n configs: any = {},\n ) {\n if (end < 0) {\n end = prog.length - 1;\n }\n this.end = end;\n }\n\n savePosition(thread: Thread, pos: number, tapeIndex: number): void {\n while (thread.positions.length <= pos) thread.positions.push(-1);\n thread.positions[pos] = tapeIndex;\n }\n\n jumpBy(thread: Thread, delta = 1): Thread {\n return this.jumpTo(thread, thread.offset + delta);\n }\n\n jumpTo(thread: Thread, newOffset: number): Thread {\n // TODO - Why create new thread here - investigate if we can\n // return the same thread with the offset updated?\n // if we really want a \"history\" we could jsut keep prev offsets\n // in a list so we can keep a trace\n const out = new Thread(newOffset, this.gen);\n out.id = thread.id;\n out.parentId = thread.parentId;\n out.priority = thread.priority;\n out.positions = thread.positions;\n out.groups = thread.groups;\n out.registers = thread.registers;\n return out;\n }\n\n forkTo(thread: Thread, newOffset: number): Thread {\n const out = new Thread(newOffset, this.gen);\n out.id = ++this.threadCounter;\n out.parentId = thread.id;\n out.priority = thread.priority;\n out.positions = [...thread.positions];\n out.groups = [...thread.groups];\n out.registers = { ...thread.registers };\n return out;\n }\n\n startGroup(thread: Thread, groupIndex: number, tapeIndex: number): Thread {\n const newThread = this.forkTo(thread, thread.offset + 1);\n newThread.groups.push([groupIndex, tapeIndex]);\n return newThread;\n }\n\n endGroup(thread: Thread, groupIndex: number, tapeIndex: number): Thread {\n const newThread = this.forkTo(thread, thread.offset + 1);\n newThread.groups.push([-groupIndex, tapeIndex]);\n return newThread;\n }\n\n addThread(thread: Thread, list: Thread[], tape: Tape, delta = 0): void {\n if (\n thread.offset < this.start ||\n thread.offset > this.end ||\n this.genForOffset[thread.offset - this.start] == this.gen\n ) {\n // duplicate\n return;\n }\n this.genForOffset[thread.offset - this.start] = this.gen;\n const instr = this.prog.instrs[thread.offset];\n let nextCh: string;\n let lastCh: string;\n let newThread: Thread;\n // if (this.tracer) this.tracer.threadStepped(thread, tape.index, this.gen);\n const opcode = instr.opcode;\n switch (opcode) {\n case OpCode.Jump:\n newThread = this.jumpTo(thread, instr.args[0]);\n this.addThread(newThread, list, tape, delta);\n break;\n case OpCode.Split:\n for (let j = 0; j < instr.args.length; j++) {\n const newOff = instr.args[j];\n // TODO - only fork on position/group write instead of always forking on a split\n const newThread = j == 0 ? this.jumpTo(thread, newOff) : this.forkTo(thread, newOff);\n this.addThread(newThread, list, tape, delta);\n }\n break;\n case OpCode.Save:\n newThread = this.jumpTo(thread, thread.offset + 1);\n this.savePosition(newThread, instr.args[0], tape.index + delta);\n if (this.tracer) this.tracer.threadQueued(thread, tape.index + delta);\n this.addThread(newThread, list, tape, delta);\n break;\n case OpCode.GroupStart:\n newThread = this.startGroup(thread, instr.args[0], tape.index + delta);\n if (this.tracer) this.tracer.threadQueued(thread, tape.index + delta);\n this.addThread(newThread, list, tape, delta);\n break;\n case OpCode.GroupEnd:\n newThread = this.endGroup(thread, instr.args[0], tape.index + delta);\n if (this.tracer) this.tracer.threadQueued(thread, tape.index + delta);\n this.addThread(newThread, list, tape, delta);\n break;\n case OpCode.StartingChar:\n case OpCode.MLStartingChar:\n // only proceed further if prev was a newline or start\n lastCh = this.prevCh(tape);\n if (tape.index == 0 || (opcode == OpCode.MLStartingChar && isNewLineChar(lastCh))) {\n // have a match so can go forwrd but dont advance tape on\n // the same generation\n this.addThread(this.jumpBy(thread, 1), list, tape, delta);\n }\n break;\n case OpCode.EndingChar:\n case OpCode.MLEndingChar:\n // On end of input we dont advance tape but thread moves on\n // if at end of line boundary\n // check if next is end of input\n nextCh = this.nextCh(tape);\n if (nextCh == \"\" || (opcode == OpCode.MLEndingChar && isNewLineChar(nextCh))) {\n this.addThread(this.jumpBy(thread, 1), list, tape, delta);\n }\n break;\n case OpCode.StartOfWord:\n // only proceed further if prev was a newline or start\n /*\n lastCh = this.prevCh(tape);\n if (tape.index == 0 || (this.multiline && (isNewLineChar(lastCh) || isSpaceChar(lastCh)))) {\n // have a match so can go forwrd but dont advance tape on\n // the same generation\n this.addThread(this.jumpBy(thread, 1), list, tape, delta);\n }\n */\n break;\n case OpCode.EndOfWord:\n // On end of input we dont advance tape but thread moves on\n // if at end of line boundary\n // check if next is end of input\n /*\n nextCh = this.nextCh(tape);\n if (nextCh == \"\" || (this.multiline && (isNewLineChar(nextCh) || isSpaceChar(nextCh)))) {\n this.addThread(this.jumpBy(thread, 1), list, tape, delta);\n }\n */\n break;\n case OpCode.RBegin:\n {\n const [groupIndex, negate, end] = instr.args;\n const pos = (1 + groupIndex) * 2;\n const groupStart = thread.positions[pos];\n const [matchSuccess, matchEnd] = this.recurseMatch(\n tape,\n groupStart - 1,\n instr.offset + 1,\n end,\n false,\n negate == 1,\n );\n if (matchSuccess) {\n // TODO - Consider using a DFA for this case so we can mitigate\n // pathological cases with an exponential blowup on a success\n this.addThread(this.jumpTo(thread, end + 1), list, tape, delta);\n }\n }\n break;\n case OpCode.Begin:\n // This results in a new VM being created for this sub program and\n // kicking off a backtracking execution - Making these as explicit\n // constructs for the user to use means the user can make this choice\n // on their own voilition\n const [consume, negate, end] = instr.args;\n if (consume == 1) {\n // since this results in the consumption of a character (similar to \"Char\")\n // defer this to the list\n if (this.tracer) this.tracer.threadQueued(thread, tape.index);\n list.push(thread);\n } else {\n const [matchSuccess, matchEnd] = this.recurseMatch(\n tape,\n tape.index + 1,\n instr.offset + 1,\n end,\n true,\n negate == 1,\n );\n if (matchSuccess) {\n // TODO - Consider using a DFA for this case so we can mitigate\n // pathological cases with an exponential blowup on a success\n this.addThread(this.jumpTo(thread, end + 1), list, tape, delta);\n }\n }\n break;\n case OpCode.EnsureState:\n const states = instr.args;\n for (const state of states) {\n if (this.currState == state) {\n this.addThread(this.jumpBy(thread, 1), list, tape, delta);\n break;\n }\n }\n break;\n default:\n if (this.tracer) this.tracer.threadQueued(thread, tape.index);\n list.push(thread);\n break;\n }\n }\n\n matchCurrPos(tape: Tape, char: Char, ignoreCase = false): boolean {\n if (ignoreCase) {\n return char.match(tape.currChCodeLower) || char.match(tape.currChCodeUpper);\n } else {\n return char.match(tape.currChCode);\n }\n }\n\n protected hasMore(tape: Tape): boolean {\n return this.forward ? tape.hasMore : tape.index >= 0;\n }\n\n protected nextCh(tape: Tape): string {\n const next = tape.index + (this.forward ? 1 : -1);\n return tape.charAt(next);\n // if (next < 0 || next >= tape.input.length) return \"\";\n // return tape.input[next];\n }\n\n protected prevCh(tape: Tape): string {\n return tape.charAt(tape.index - (this.forward ? 1 : -1));\n // return tape.input[tape.index - (this.forward ? 1 : -1)];\n }\n\n /**\n * Runs the given instructions and returns a triple:\n * [matchId, matchStart, matchEnd]\n */\n match(tape: Tape): Match | null {\n // this.gen = 0; this.genForOffset = {};\n if (this.end < this.start) return null;\n this.startMatching(tape);\n let bestMatch: TSU.Nullable<Match> = null;\n while (this.currThreads.length > 0) {\n bestMatch = this.stepChar(tape, bestMatch);\n }\n // ensure tape is rewound to end of last match\n if (bestMatch != null) tape.index = bestMatch.end;\n return bestMatch;\n }\n\n recurseMatch(\n tape: Tape,\n tapeIndex: number,\n startOffset: number,\n endOffset: number,\n forward = true,\n negate = false,\n ): [boolean, number] {\n const savedPos = tape.index;\n if (!tape.canAdvance(forward ? 1 : -1)) return [negate, -1];\n tape.index = tapeIndex;\n // tape.advance(forward ? 1 : -1);\n const vm = new VM(this.prog, startOffset, endOffset, forward);\n const match = vm.match(tape);\n const newPos = tape.index;\n tape.index = savedPos; // always restore it first and let caller use it\n return [(match != null && !negate) || (match == null && negate), newPos];\n }\n\n startMatching(tape: Tape): void {\n this.currThreads = [];\n this.nextThreads = [];\n this.gen++;\n this.addThread(new Thread(this.start, this.gen), this.currThreads, tape);\n // let largestMatchEnd = -1;\n // let lastMatchIndex = -1;\n this.startPos = tape.index;\n }\n\n stepChar(tape: Tape, currMatch: TSU.Nullable<Match> = null): TSU.Nullable<Match> {\n // At this point all our threads are point to the next \"transition\" or \"match\" action.\n this.gen++;\n // console.log(`Ch (@${tape.index}): ${tape.currChCode}, Gen (${this.gen})`);\n for (let i = 0; i < this.currThreads.length; i++) {\n const thread = this.currThreads[i];\n // console.log(` Thread (${i}): ${thread.offset}(${thread.gen})`);\n const nextMatch = this.stepThread(tape, thread);\n if (nextMatch != null) {\n if (\n currMatch == null ||\n nextMatch.priority > currMatch.priority ||\n (nextMatch.priority == currMatch.priority && nextMatch.end > currMatch.end)\n ) {\n currMatch = nextMatch;\n break;\n } else if (currMatch != nextMatch) {\n // Since we kill of lower priority matches becuase of matchedInGen\n // we should not be here\n // TSU.assert(false, \"Should not be here\");\n }\n }\n }\n if (this.hasMore(tape)) {\n tape.advance(this.forward ? 1 : -1);\n }\n this.currThreads = this.nextThreads;\n this.nextThreads = [];\n return currMatch;\n }\n\n stepThread(tape: Tape, thread: Thread): TSU.Nullable<Match> {\n if (this.tracer) this.tracer.threadStepped(thread, tape.index, this.gen);\n let currMatch: TSU.Nullable<Match> = null;\n const instrs = this.prog.instrs;\n const instr = instrs[thread.offset];\n const opcode = instr.opcode;\n const args = instr.args;\n const delta = this.forward ? 1 : -1;\n // Do char match based actions\n let advanceTape = false;\n let ch: number;\n switch (opcode) {\n case OpCode.RBegin:\n throw new Error(\"Invalid state. Reverse matches must be handled in addThread\");\n break;\n case OpCode.Begin:\n const [consume, negate, end] = instr.args;\n TSU.assert(consume == 1, \"Plain lookahead cannot be here\");\n const [matchSuccess, matchEnd] = this.recurseMatch(tape, tape.index, instr.offset + 1, end, true, negate == 1);\n if (matchSuccess) {\n // TODO - Consider using a DFA for this case so we can mitigate\n // pathological cases with an exponential blowup\n // on a success we have a few options\n this.addThread(this.jumpTo(thread, end + 1), this.nextThreads, tape);\n }\n break;\n case OpCode.End:\n // Return back to calling VM - very similar to a match\n const out = new Match(-1, -1, this.startPos, tape.index);\n out.groups = thread.groups;\n out.positions = thread.positions;\n return out;\n break;\n case OpCode.Match:\n // we have a match on this thread so return it\n // Update the match if we are a higher prioirty or longer match\n // than what was already found (if any)\n if (tape.index > this.startPos) {\n const currPriority = instr.args[0];\n const matchIndex = instr.args[1];\n currMatch = new Match();\n currMatch.start = this.startPos;\n currMatch.end = tape.index;\n currMatch.priority = currPriority;\n currMatch.matchIndex = matchIndex;\n currMatch.groups = thread.groups;\n currMatch.positions = thread.positions;\n }\n break;\n case OpCode.Char:\n case OpCode.CIChar:\n if (this.hasMore(tape)) {\n advanceTape = this.matchCurrPos(tape, instr.char!, opcode == OpCode.CIChar);\n }\n break;\n /*\n case OpCode.NegChar:\n case OpCode.NegCIChar:\n if (this.hasMore(tape)) {\n advanceTape = !this.matchCurrPos(tape, args, opcode == OpCode.NegCIChar);\n }\n break;\n */\n case OpCode.AnyNonNL:\n case OpCode.Any:\n if (this.hasMore(tape)) {\n advanceTape = opcode == OpCode.Any || !isNewLineChar(tape.currCh);\n }\n break;\n }\n if (advanceTape /* && this.hasMore(tape) */) {\n this.addThread(this.jumpBy(thread, 1), this.nextThreads, tape, delta);\n }\n return currMatch;\n }\n}\n\nexport function InstrDebugValue(instr: Instr): string {\n switch (instr.opcode) {\n case OpCode.Match:\n return `Match ${instr.args[0]} ${instr.args[1]}`;\n // case OpCode.NegChar:\n // case OpCode.NegCIChar:\n case OpCode.Char:\n case OpCode.CIChar: {\n let out = `${OpCode[instr.opcode].toString()} `;\n // out += `${CharType[instr.args[0]]}`;\n // for (let i = 1; i < instr.args.length; i++) out += \" \" + instr.args[i];\n out += `${instr.char!.debugValue()}`;\n return out;\n }\n case OpCode.Any:\n return \".\";\n case OpCode.AnyNonNL:\n return \"NL.\";\n case OpCode.StartingChar:\n return \"^\";\n case OpCode.MLStartingChar:\n return \"NL^\";\n case OpCode.EndingChar:\n return \"$NL\";\n case OpCode.MLEndingChar:\n return \"$NL_MultiLine\";\n case OpCode.Save:\n return `Save ${instr.args[0]}`;\n case OpCode.GroupStart:\n return `GroupStart ${instr.args[0]}`;\n case OpCode.GroupEnd:\n return `GroupEnd ${instr.args[0]}`;\n case OpCode.Split:\n return `Split ${instr.args.join(\", \")}`;\n case OpCode.Jump:\n return `Jump ${instr.args[0]}`;\n case OpCode.Begin:\n return `Begin ${instr.args.join(\" \")}`;\n case OpCode.RBegin:\n return `RBegin ${instr.args.join(\" \")}`;\n case OpCode.End:\n return `End ${instr.args.join(\" \")}`;\n case OpCode.EnsureState:\n return `EnsureState ${instr.args.join(\" \")}`;\n default:\n throw new Error(\"Invalid Opcode: \" + instr.opcode);\n }\n}\n","import * as TSU from \"@panyam/tsutils\";\n\nimport {\n Rule,\n RegexType,\n Quant,\n Regex,\n Cat,\n Char,\n CharType,\n Var,\n BackNumRef,\n BackNamedRef,\n LookAhead,\n LookBack,\n Union,\n} from \"./core\";\nimport { OpCode, Prog, Instr } from \"./vm\";\n\nexport type RegexResolver = (name: string) => Regex;\nexport type CompilerListener = (expr: Regex, prog: Prog, start: number, length: number) => void;\n\n/**\n * The regex Compiler compiles a parsed regular expression tree into bytecode that is\n * executed by the VM.\n */\nexport class Compiler {\n emitGroups = false;\n emitPosition = true;\n constructor(\n public regexResolver: TSU.Nullable<RegexResolver>,\n public listener: TSU.Nullable<CompilerListener> = null,\n ) {}\n\n compile(rules: Rule[]): Prog {\n // Split across each of our expressions\n const out = new Prog();\n // only add the split instruction if we have more than one rule\n const split: Instr = rules.length <= 1 ? new Instr(OpCode.Split) : out.add(OpCode.Split, null);\n rules.forEach((rule, i) => {\n split.add(out.instrs.length);\n const ignoreCase = rule.expr.ignoreCase == null ? false : rule.expr.ignoreCase;\n const dotAll = rule.expr.dotAll == null ? true : rule.expr.dotAll;\n const multiline = rule.expr.multiline == null ? true : rule.expr.multiline;\n if (rule.needsSpecificStates && rule.activeStates != null) {\n const ensureInstr = out.add(OpCode.EnsureState, null);\n rule.activeStates.forEach((state) => {\n const ind = out.registerState(state);\n ensureInstr.add(ind);\n });\n }\n this.compileExpr(rule.expr, out, ignoreCase, dotAll, multiline);\n out.add(OpCode.Match, null).add(rule.priority, rule.matchIndex >= 0 ? rule.matchIndex : i);\n });\n return out;\n }\n\n /**\n * Compile a given expression into a set of instructions.\n */\n protected compileExpr(expr: Regex, prog: Prog, ignoreCase: boolean, dotAll: boolean, multiline: boolean): number {\n const start = prog.length;\n const currOffset = prog.length;\n if (expr.groupIndex >= 0) {\n if (this.emitPosition) prog.add(OpCode.Save).add((1 + expr.groupIndex) * 2);\n if (this.emitGroups) prog.add(OpCode.GroupStart).add(1 + expr.groupIndex);\n }\n if (expr.tag == RegexType.CHAR) {\n this.compileChar(expr as Char, prog, ignoreCase, dotAll, multiline);\n } else if (expr.tag == RegexType.START_OF_INPUT) {\n const ml = expr.multiline == null ? multiline : expr.multiline;\n prog.add(ml ? OpCode.MLStartingChar : OpCode.StartingChar);\n } else if (expr.tag == RegexType.END_OF_INPUT) {\n const ml = expr.multiline == null ? multiline : expr.multiline;\n prog.add(ml ? OpCode.MLEndingChar : OpCode.EndingChar);\n } else if (expr.tag == RegexType.START_OF_WORD) {\n prog.add(OpCode.StartOfWord);\n } else if (expr.tag == RegexType.END_OF_WORD) {\n prog.add(OpCode.EndOfWord);\n } else if (expr.tag == RegexType.CAT) {\n this.compileCat(expr as Cat, prog, ignoreCase, dotAll, multiline);\n } else if (expr.tag == RegexType.UNION) {\n this.compileUnion(expr as Union, prog, ignoreCase, dotAll, multiline);\n } else if (expr.tag == RegexType.QUANT) {\n this.compileQuant(expr as Quant, prog, ignoreCase, dotAll, multiline);\n } else if (expr.tag == RegexType.VAR) {\n this.compileVar(expr as Var, prog, ignoreCase, dotAll, multiline);\n } else if (expr.tag == RegexType.BACK_NAMED_REF) {\n this.compileBackNamedRef(expr as BackNamedRef, prog, ignoreCase, dotAll, multiline);\n } else if (expr.tag == RegexType.BACK_NUM_REF) {\n this.compileBackNumRef(expr as BackNumRef, prog, ignoreCase, dotAll, multiline);\n // } else if (expr.tag == RegexType.NEG) { this.compileNeg(expr as Neg, prog);\n } else if (expr.tag == RegexType.LOOK_AHEAD) {\n this.compileLookAhead(expr as LookAhead, prog, ignoreCase, dotAll, multiline);\n } else if (expr.tag == RegexType.LOOK_BACK) {\n this.compileLookBack(expr as LookBack, prog, ignoreCase, dotAll, multiline);\n } else {\n throw new Error(\"Regex Type not yet supported: \" + expr.tag);\n }\n if (expr.groupIndex >= 0) {\n if (this.emitGroups) prog.add(OpCode.GroupEnd).add(1 + expr.groupIndex);\n if (this.emitPosition) prog.add(OpCode.Save).add((1 + expr.groupIndex) * 2 + 1);\n }\n if (this.listener && prog.length > currOffset) {\n this.listener(expr, prog, currOffset, prog.length - currOffset);\n }\n return prog.length - start;\n }\n\n protected compileChar(char: Char, prog: Prog, ignoreCase: boolean, dotAll: boolean, multiline: boolean): void {\n if (char.op == CharType.AnyChar) {\n // TODO - Should neg be ignored?\n prog.add(dotAll ? OpCode.Any : OpCode.AnyNonNL);\n } else {\n const instr = prog.add(ignoreCase ? OpCode.CIChar : OpCode.Char);\n instr.char = char;\n /*\n // We have Neg or not, CI or not\n const instr = prog.add(\n ignoreCase ? (char.neg ? OpCode.NegCIChar : OpCode.CIChar) : char.neg ? OpCode.NegChar : OpCode.Char,\n );\n instr.add(char.op);\n\n // And now the arguments\n for (const arg of char.args) instr.add(arg);\n */\n }\n }\n\n protected compileCat(cat: Cat, prog: Prog, ignoreCase: boolean, dotAll: boolean, multiline: boolean): void {\n for (const child of cat.children) {\n this.compileExpr(child, prog, ignoreCase, dotAll, multiline);\n }\n }\n\n protected compileBackNumRef(\n ne: BackNumRef,\n prog: Prog,\n ignoreCase: boolean,\n dotAll: boolean,\n multiline: boolean,\n ): void {\n // TODO - This may need a resolution at \"runtime\" so the instruction\n // should reflect as such?\n // See compiler.spec.ts - \"Test Back Named Groups\"\n throw new Error(\"BackNumRef Not Implemented\");\n }\n\n protected compileBackNamedRef(\n ne: BackNamedRef,\n prog: Prog,\n ignoreCase: boolean,\n dotAll: boolean,\n multiline: boolean,\n ): void {\n // TODO - This may need a resolution at \"runtime\" so the instruction\n // should reflect as such?\n // See compiler.spec.ts - \"Test Back Named Groups\"\n throw new Error(\"BackNameRef Not Implemented\");\n }\n\n protected compileVar(v: Var, prog: Prog, ignoreCase: boolean, dotAll: boolean, multiline: boolean): void {\n const name = v.name.trim();\n const expr = this.regexResolver ? this.regexResolver(name) : null;\n if (expr == null) {\n throw new Error(`Cannot find expression: ${name}`);\n }\n this.compileExpr(expr, prog, ignoreCase, dotAll, multiline);\n }\n\n protected compileUnion(union: Union, prog: Prog, ignoreCase: boolean, dotAll: boolean, multiline: boolean): void {\n const split = prog.add(OpCode.Split);\n const jumps: Instr[] = [];\n\n for (let i = 0; i < union.options.length; i++) {\n split.add(prog.length);\n this.compileExpr(union.options[i], prog, ignoreCase, dotAll, multiline);\n if (i < union.options.length - 1) {\n jumps.push(prog.add(OpCode.Jump));\n }\n }\n for (const jmp of jumps) {\n jmp.add(prog.length);\n }\n }\n\n /**\n * Compiles a repetition (with quantifiers) into its instructions. This explicitly expands\n * a rule of the form x\\{a,b\\} to xx... (a) times followed by x? (b - a) times\n */\n protected compileQuant(quant: Quant, prog: Prog, ignoreCase: boolean, dotAll: boolean, multiline: boolean): void {\n // optimize the special cases of *, ? and +\n if (quant.minCount == 0 && quant.maxCount == TSU.Constants.MAX_INT) {\n // *\n this.compileAtleast0(quant.expr, prog, quant.greedy, ignoreCase, dotAll, multiline);\n } else if (quant.minCount == 1 && quant.maxCount == TSU.Constants.MAX_INT) {\n // +\n this.compileAtleast1(quant.expr, prog, quant.greedy, ignoreCase, dotAll, multiline);\n } else if (quant.minCount == 0 && quant.maxCount == 1) {\n // ?\n this.compileOptional(quant.expr, prog, quant.greedy, ignoreCase, dotAll, multiline);\n } else {\n // general case - Currently going with Option 1\n //\n // - convert x{a,b} to xxxxxx (a) times followed by x? b - a times\n for (let i = 0; i < quant.minCount; i++) {\n this.compileExpr(quant.expr, prog, ignoreCase, dotAll, multiline);\n }\n // generate x? b - a times\n if (quant.isUnlimited) {\n // then generate a a* here\n this.compileAtleast0(quant.expr, prog, quant.greedy, ignoreCase, dotAll, multiline);\n } else {\n for (let i = quant.minCount; i < quant.maxCount; i++) {\n this.compileOptional(quant.expr, prog, quant.greedy, ignoreCase, dotAll, multiline);\n }\n }\n }\n }\n\n protected compileAtleast1(\n expr: Regex,\n prog: Prog,\n greedy = true,\n ignoreCase: boolean,\n dotAll: boolean,\n multiline: boolean,\n ): void {\n const l1 = prog.length;\n this.compileExpr(expr, prog, ignoreCase, dotAll, multiline);\n const split = prog.add(OpCode.Split);\n const l3 = prog.length;\n if (greedy) {\n split.add(l1, l3);\n } else {\n split.add(l3, l1);\n }\n }\n\n protected compileAtleast0(\n expr: Regex,\n prog: Prog,\n greedy: boolean,\n ignoreCase: boolean,\n dotAll: boolean,\n multiline: boolean,\n ): void {\n const split = prog.add(OpCode.Split);\n const l1 = split.offset;\n const l2 = prog.length;\n this.compileExpr(expr, prog, ignoreCase, dotAll, multiline);\n prog.add(OpCode.Jump).add(l1);\n const l3 = prog.length;\n if (greedy) {\n split.add(l2, l3);\n } else {\n split.add(l3, l2);\n }\n }\n\n protected compileOptional(\n expr: Regex,\n prog: Prog,\n greedy: boolean,\n ignoreCase: boolean,\n dotAll: boolean,\n multiline: boolean,\n ): void {\n const split = prog.add(OpCode.Split);\n const l1 = prog.length;\n this.compileExpr(expr, prog, ignoreCase, dotAll, multiline);\n const l2 = prog.length;\n if (greedy) {\n split.add(l1, l2);\n } else {\n split.add(l2, l1);\n }\n }\n\n /**\n * Compiles lookahead assertions\n */\n protected compileLookAhead(\n la: LookAhead,\n prog: Prog,\n ignoreCase: boolean,\n dotAll: boolean,\n multiline: boolean,\n ): void {\n // how should this work?\n // Ensure that assertion matches first before continuing with the expression\n this.compileExpr(la.expr, prog, ignoreCase, dotAll, multiline);\n const begin = prog.add(OpCode.Begin).add(0, la.negate ? 1 : 0); // negate if needed\n this.compileExpr(la.cond, prog, ignoreCase, dotAll, multiline);\n const end = prog.add(OpCode.End).add(begin.offset);\n begin.add(end.offset);\n }\n\n /**\n * Compiles lookback assertions\n */\n protected compileLookBack(lb: LookBack, prog: Prog, ignoreCase: boolean, dotAll: boolean, multiline: boolean): void {\n // Ensure that assertion matches first before continuing with the expression\n this.compileExpr(lb.expr, prog, ignoreCase, dotAll, multiline);\n TSU.assert(lb.expr.groupIndex >= 0, \"LookBack Assertion requires expression to have a group Index\");\n const begin = prog.add(OpCode.RBegin).add(lb.expr.groupIndex, lb.negate ? 1 : 0); // negate if needed\n this.compileExpr(lb.cond.reverse(), prog, ignoreCase, dotAll, multiline);\n const end = prog.add(OpCode.End).add(begin.offset);\n begin.add(end.offset);\n }\n}\n","import * as TSU from \"@panyam/tsutils\";\nimport { Token } from \"./token\";\n\nexport class TokenizerError extends Error {\n readonly name: string = \"TokenizerError\";\n\n constructor(\n message: string,\n public offset: number,\n public length: number,\n public type: string,\n public value: any = null,\n ) {\n super(message);\n Object.setPrototypeOf(this, new.target.prototype);\n }\n}\n\nexport class UnexpectedTokenError extends Error {\n readonly name: string = \"UnexpectedTokenError\";\n expectedTokens: Token[];\n\n constructor(public foundToken: TSU.Nullable<Token>, ...expectedTokens: Token[]) {\n super(\n `Found Token: ${foundToken?.tag || \"EOF\"} (${foundToken?.value || \"\"}), Expected: ${expectedTokens.join(\", \")}`,\n );\n this.expectedTokens = expectedTokens;\n }\n}\n","export abstract class TapeInterface {\n index = 0;\n abstract charAt(index: number): string;\n abstract hasIndex(index: number): boolean;\n abstract substring(startIndex: number, endIndex: number): string;\n\n constructor(public forward = true) {}\n\n advance(delta = 1): boolean {\n const next = this.forward ? this.index + delta : this.index - delta;\n // if (!this.hasIndex(next)) return false;\n this.index = next;\n return true;\n }\n\n canAdvance(delta = 1): boolean {\n const next = this.forward ? this.index + delta : this.index - delta;\n return this.hasIndex(next);\n }\n\n get hasMore(): boolean {\n const next = this.forward ? this.index : this.index - 1;\n return this.hasIndex(next);\n // return this.forward ? this.index < this.input.length : this.index > 0;\n }\n\n get currCh(): string {\n return this.charAt(this.index);\n }\n\n get prevCh(): string {\n return this.charAt(this.index - (this.forward ? 1 : -1));\n }\n\n get nextCh(): string {\n const next = this.index + (this.forward ? 1 : -1);\n return this.charAt(next);\n }\n\n get currChCode(): number {\n if (!this.hasMore) return -1;\n return this.currCh.charCodeAt(0);\n // return this.input.charCodeAt(this.index);\n }\n\n get currChCodeLower(): number {\n if (!this.hasMore) return -1;\n return this.currCh.toLowerCase().charCodeAt(0);\n }\n\n get currChCodeUpper(): number {\n if (!this.hasMore) return -1;\n return this.currCh.toUpperCase().charCodeAt(0);\n }\n\n charCodeAt(index: number): number {\n if (!this.hasIndex(index)) return -1;\n return this.charAt(index).charCodeAt(0);\n }\n\n charCodeAtLower(index: number): number {\n if (!this.hasIndex(index)) return -1;\n return this.charAt(index).toLowerCase().charCodeAt(0);\n }\n\n charCodeAtUpper(index: number): number {\n if (!this.hasIndex(index)) return -1;\n return this.charAt(index).toUpperCase().charCodeAt(0);\n }\n}\n\n/**\n * A Tape of characters we would read with some extra helpers like rewinding\n * forwarding and prefix checking that is fed into the different tokenizers\n * used by the scannerless parsers.\n */\nexport class Tape extends TapeInterface {\n protected _rawInput: string;\n readonly input: string[];\n\n constructor(input: string, public forward = true) {\n super(forward);\n this._rawInput = input;\n this.input = [...input];\n }\n\n push(content: string): void {\n this._rawInput += content;\n this.input.push(...content);\n }\n\n substring(startIndex: number, endIndex: number): string {\n return this._rawInput.substring(startIndex, endIndex);\n // return this.input.slice(startIndex, endIndex).join(\"\");\n }\n\n hasIndex(index: number): boolean {\n return index >= 0 && index < this.input.length;\n }\n\n charAt(index: number): string {\n if (index < 0 || index >= this.input.length) return \"\";\n return this.input[index];\n }\n}\n\nexport class TapeHelper {\n /**\n * Advances the tape to the end of the first occurence of\n * the given pattern.\n */\n static advanceAfter(tape: TapeInterface, pattern: string, ensureNoPrefixSlash = true): number {\n let pos = TapeHelper.advanceTo(tape, pattern, ensureNoPrefixSlash);\n if (pos >= 0) {\n pos += pattern.length;\n tape.index = pos;\n }\n return pos;\n }\n\n /**\n * Advances the tape till the start of a given pattern.\n * This is not the most optimal implementation and just does a brute\n * force search at each index. Instead using the Regex interface\n * directly will be faster.\n */\n static advanceTo(tape: TapeInterface, pattern: string, ensureNoPrefixSlash = true): number {\n const lastIndex = tape.index;\n while (tape.hasMore) {\n const currStart = tape.index;\n if (TapeHelper.matches(tape, pattern)) {\n const endIndex = tape.index;\n tape.index = currStart;\n let numSlashes = 0;\n if (ensureNoPrefixSlash) {\n for (let i = endIndex - 1; i >= 0; i--) {\n if (tape.charAt(i) == \"\\\\\") numSlashes++;\n else break;\n }\n }\n if (numSlashes % 2 == 0) {\n return tape.index;\n }\n }\n tape.advance(1);\n }\n tape.index = lastIndex;\n throw new Error(`Unexpected end of input before (${pattern})`);\n return -1;\n }\n\n /**\n * Tells if the given prefix is matche at the current position of the tokenizer.\n */\n static matches(tape: TapeInterface, prefix: string, advance = true): boolean {\n const lastIndex = tape.index;\n let i = 0;\n let success = true;\n for (; i < prefix.length; i++) {\n if (prefix[i] != tape.currCh) {\n success = false;\n break;\n }\n tape.advance(1);\n }\n // Reset pointers if we are only peeking or match failed\n if (!advance || !success) {\n tape.index = lastIndex;\n }\n return success;\n }\n}\n","import * as TSU from \"@panyam/tsutils\";\nimport { TapeInterface as Tape } from \"./tape\";\nimport { TokenizerError, UnexpectedTokenError } from \"./errors\";\n\nexport type TokenType = number | string;\n\nexport class Token {\n private static idCounter = 0;\n // ID for uniquely identifying tokens if needed for shallow equality\n id = Token.idCounter++;\n value: any = null;\n groups: TSU.NumMap<number[]> = {};\n positions: TSU.NumMap<[number, number]> = {};\n\n // Incremental lexing support fields\n /**\n * Lexer state when this token was constructed.\n * 0 = INITIAL state. Higher numbers represent other states (e.g., inside string, comment).\n * Used for incremental lexing to restart from a token boundary.\n */\n state = 0;\n\n /**\n * Number of characters read beyond this token's lexeme to determine it.\n * Most tokens need 1 char lookahead to know they're complete (e.g., identifier ends on non-alnum).\n * Used for incremental lexing dependency tracking.\n */\n lookahead = 1;\n\n /**\n * Number of preceding tokens whose lookahead reaches this token.\n * Default 1 means the previous token's lookahead extends into this token.\n * Used for incremental lexing to find affected region on edit.\n */\n lookback = 1;\n\n constructor(public tag: TokenType, public readonly matchIndex: number, public start: number, public end: number) {}\n\n isOneOf(...expected: any[]): boolean {\n for (const tok of expected) {\n if (this.tag == tok) {\n return true;\n }\n }\n return false;\n }\n}\n\nexport type NextTokenFunc = (tape: Tape, owner: any) => Token | null;\n\n/**\n * A wrapper on a tokenizer for providing features like k-lookahead, token\n * insertion, rewinding, expectation enforcement etc.\n */\nexport class TokenBuffer {\n buffer: Token[] = [];\n\n constructor(public readonly nextToken: NextTokenFunc, public tokenizerContext: any) {}\n\n next(tape: Tape): Token | null {\n const out = this.peek(tape);\n if (out != null) {\n this.consume();\n }\n return out;\n }\n\n /**\n * Peek at the nth token in the token stream.\n */\n peek(tape: Tape, nth = 0): Token | null {\n while (this.buffer.length <= nth) {\n const tok = this.nextToken(tape, this.tokenizerContext);\n if (tok == null) return null;\n this.buffer.push(tok);\n }\n return this.buffer[nth];\n }\n\n match(\n tape: Tape,\n matchFunc: (token: Token) => boolean,\n ensure = false,\n consume = true,\n nextAction?: (token: Token) => boolean | undefined,\n ): Token | null {\n const token = this.peek(tape);\n if (token != null) {\n if (matchFunc(token)) {\n if (nextAction && nextAction != null) {\n nextAction(token);\n }\n if (consume) {\n this.consume();\n }\n } else if (ensure) {\n // Should we throw an error?\n throw new UnexpectedTokenError(token);\n } else {\n return null;\n }\n } else if (ensure) {\n throw new TokenizerError(\"Unexpected end of input\", -1, 0, \"UnexpectedEndOfInput\");\n }\n return token;\n }\n\n consume(): void {\n this.buffer.splice(0, 1);\n }\n\n consumeIf(tape: Tape, ...expected: TokenType[]): Token | null {\n return this.match(tape, (t) => t.isOneOf(...expected));\n }\n\n expectToken(tape: Tape, ...expected: TokenType[]): Token {\n return this.match(tape, (t) => t.isOneOf(...expected), true, true) as Token;\n }\n\n ensureToken(tape: Tape, ...expected: TokenType[]): Token {\n return this.match(tape, (t) => t.isOneOf(...expected), true, false) as Token;\n }\n\n nextMatches(tape: Tape, ...expected: TokenType[]): Token | null {\n const token = this.peek(tape);\n if (token == null) return null;\n for (const tok of expected) {\n if (token.tag == tok) return token;\n }\n return null;\n }\n}\n","export class GroupCounter {\n value = -1;\n next(): number {\n return ++this.value;\n }\n get current(): number {\n return this.value;\n }\n}\n\nexport function isSpace(ch: string): boolean {\n return ch == \" \" || ch == \"\\t\" || ch == \"\\n\" || ch == \"\\r\";\n}\n\n// function isSpaceChar(ch: string): boolean { return ch == \" \" || ch == \"\\t\"; }\n","import * as TSU from \"@panyam/tsutils\";\nimport {\n Quant,\n RegexType,\n StartOfInput,\n EndOfInput,\n Regex,\n Cat,\n Char,\n LeafChar,\n CharGroup,\n CharType,\n Var,\n BackNamedRef,\n BackNumRef,\n LookAhead,\n LookBack,\n Union,\n} from \"./core\";\nimport { CharClassType } from \"./charclasses\";\nimport { GroupCounter } from \"./utils\";\n\n/**\n * A RegexParser for parsing regex strings in JS RegExp format.\n * This class will seldom have to be used directly. Instead use one of the methods in {@link Builder}\n */\nexport class RegexParser {\n protected unicode: boolean;\n protected counter: GroupCounter;\n /**\n * @param pattern The pattern string being parsed.\n * @param config Configs for the regex to include whether parsing is unicode or plain ASCII.\n */\n constructor(public readonly pattern: string, config?: { unicode?: boolean }) {\n this.counter = new GroupCounter();\n this.unicode = config?.unicode || false;\n }\n\n protected reduceLeft(stack: Regex[]): Regex {\n const r = stack.length == 1 ? stack[0] : new Cat(...stack);\n // remove all elements on stack\n stack.splice(0);\n return r;\n }\n\n protected throwError(msg: string): void {\n throw new SyntaxError(`Error in JS RE '${this.pattern}': ${msg}`);\n }\n\n /**\n * Creates a regex tree given a string\n */\n parse(curr = 0, end = -1): Regex {\n const pattern = this.pattern;\n const stack: Regex[] = [];\n if (end < 0) end = pattern.length - 1;\n while (curr <= end) {\n const currCh = pattern[curr];\n // see if we have groups so they get highest preference\n if (currCh == \".\") {\n stack.push(LeafChar.Any());\n curr++;\n } else if (currCh == \"\\\\\" && pattern[curr + 1] >= \"1\" && pattern[curr + 1] <= \"9\") {\n // Numeric references\n curr++;\n let num = \"\";\n while (curr <= end && pattern[curr] >= \"0\" && pattern[curr] <= \"9\") {\n num = num + pattern[curr++];\n }\n const refNum = parseInt(num);\n if (refNum > this.counter.current + 1) {\n this.throwError(\"Invalid reference: \" + refNum);\n }\n stack.push(new BackNumRef(refNum));\n } else if (currCh == \"\\\\\" && pattern[curr + 1] == \"k\" && pattern[curr + 2] == \"<\") {\n // Named references\n curr += 3;\n let gtPos = curr;\n while (gtPos <= end && pattern[gtPos] != \">\") gtPos++;\n if (gtPos > end) this.throwError(\"Expected '>' found EOI\");\n const name = pattern.substring(curr, gtPos);\n if (name.trim() == \"\") {\n this.throwError(\"Expected name\");\n }\n stack.push(new BackNamedRef(name));\n curr = gtPos + 1;\n } else if (currCh == \"[\") {\n // character ranges\n let clPos = curr + 1;\n while (clPos <= end && pattern[clPos] != \"]\") {\n if (pattern[clPos] == \"\\\\\") clPos++;\n clPos++;\n }\n if (clPos > end) this.throwError(\"Expected ']' found EOI\");\n stack.push(this.parseCharGroup(curr + 1, clPos - 1));\n curr = clPos + 1;\n } else if (currCh == \"^\") {\n stack.push(new StartOfInput());\n curr++;\n } else if (currCh == \"$\") {\n stack.push(new EndOfInput());\n curr++;\n } else if (currCh == \"|\") {\n if (curr + 1 <= end) {\n // reduce everything \"until now\" and THEN apply\n const prev = this.reduceLeft(stack);\n // this.parse everything to the right\n const rest = this.parse(curr + 1, end);\n return new Union(prev, rest);\n }\n curr = end + 1;\n } else if (currCh == \"(\") {\n curr = this.parseGroup(stack, curr, end);\n } else if (currCh == \")\" || currCh == \"]\" || currCh == \"}\") {\n this.throwError(`Unmatched ${currCh}. Try using \\\\${currCh}`);\n } else if (pattern[curr] == \"*\" || pattern[curr] == \"?\" || pattern[curr] == \"+\" || pattern[curr] == \"{\") {\n curr = this.parseQuant(stack, curr, end);\n } else {\n // plain old alphabets\n const [result, nchars] = this.parseChar(curr, end);\n stack.push(result);\n curr += nchars;\n }\n }\n if (stack.length <= 0) {\n // this.throwError(`Invalid Regex (${curr} - ${end}): ${pattern}`);\n }\n if (stack.length == 1) return stack[0];\n return new Cat(...stack);\n }\n\n protected parseGroup(stack: Regex[], curr: number, end: number): number {\n // we have a grouping or an assertion\n let clPos = curr + 1;\n let depth = 0;\n const pattern = this.pattern;\n while (clPos <= end && (pattern[clPos] != \")\" || depth > 0)) {\n if (pattern[clPos] == \"(\") depth++;\n else if (pattern[clPos] == \")\") depth--;\n if (pattern[clPos] == \"\\\\\") clPos++;\n clPos++;\n }\n if (clPos > end) this.throwError(\"Expected ')' found EOI\");\n\n curr++;\n if (pattern[curr] == \"?\") {\n // assertions\n curr++; // skip the \"?\"\n if (pattern[curr] == \":\") {\n // A non capturing\n stack.push(this.parse(curr + 1, clPos - 1));\n } else if (pattern[curr] == \"<\" && pattern[curr + 1] != \"!\" && pattern[curr + 1] != \"=\") {\n // Named capture group\n const groupIndex = this.counter.next();\n let groupName = \"\";\n // get name of this group\n let gtPos = curr + 1;\n while (gtPos <= end && pattern[gtPos] != \">\") {\n groupName += pattern[gtPos];\n gtPos++;\n }\n const subExpr = this.parse(gtPos + 1, clPos - 1);\n subExpr.groupIndex = groupIndex;\n if (groupName.length > 0) subExpr.groupName = groupName;\n } else {\n // We have lookback/ahead assertions\n let after = true;\n if (pattern[curr] == \"<\") {\n curr++;\n after = false;\n }\n const neg = pattern[curr++] == \"!\";\n const cond = this.parse(curr, clPos - 1);\n if (after) {\n // reduce everything \"until now\" and THEN apply\n if (stack.length == 0) {\n // this.throwError(\"LookAhead condition cannot be before empty rule\");\n }\n // const endIndex = stack.length - 1;\n // stack[endIndex] = new LookAhead(stack[endIndex], cond, neg);\n const expr = new LookAhead(this.reduceLeft(stack), cond, neg);\n stack.push(expr);\n } else {\n // Lookbacks are interesting, we have something like:\n // (?<!...)abcde\n // clPos points to \")\" We need abcde also parsed\n // and then lookback applied to it\n const rest = this.parse(clPos + 1, end);\n if (rest.groupIndex < 0) {\n rest.groupIndex = this.counter.next();\n rest.groupIsSilent = true;\n }\n stack.push(new LookBack(rest, cond, neg));\n return end + 1;\n }\n }\n } else {\n // plain old grouping of the form (xyz)\n const groupIndex = this.counter.next();\n let neg = false;\n if (pattern[curr] == \"^\") {\n neg = true;\n curr++;\n }\n let subExpr = this.parse(curr, clPos - 1);\n // if (neg) subExpr = new Neg(subExpr);\n // Do the next before the previous call if we want group\n // index to match outer brackets first\n if (subExpr.groupIndex >= 0) {\n // Already set so create cat\n subExpr = new Cat(subExpr);\n }\n subExpr.groupIndex = groupIndex;\n stack.push(subExpr);\n }\n return clPos + 1;\n }\n\n protected parseCharGroup(curr: number, end: number): Char {\n const out: Char[] = [];\n // first see which characters are in this (until the end)\n let i = curr;\n let neg = false;\n const pattern = this.pattern;\n if (pattern[i] == \"^\") {\n neg = true;\n i++;\n }\n for (; i <= end; ) {\n const [currch, nchars] = this.parseChar(i, end);\n i += nchars;\n if (i < pattern.length && pattern[i] == \"-\") {\n i++;\n // TODO - Should this be for all such \"operator\" charactors?\n if (pattern[i] == \"]\" || pattern[i] == \"[\") {\n // Special case for something like:\n // [....x-] or [.....x-[:alpha:]]\n out.push(currch);\n out.push(LeafChar.Single(\"-\"));\n } else if (i <= end) {\n const [endch, nchars] = this.parseChar(i, end);\n if (currch.op != CharType.SingleChar || endch.op != CharType.SingleChar) {\n this.throwError(\"Char range cannot start or end in a char class\");\n }\n if (endch.args[0] < currch.args[0]) {\n this.throwError(\"End cannot be less than start\");\n }\n out.push(CharGroup.Range(currch, endch));\n i += nchars;\n } else {\n this.throwError(\"Unterminated char class\");\n }\n } else {\n out.push(currch);\n }\n }\n return CharGroup.Union(neg, out);\n }\n\n protected parseChar(index = 0, end = 0): [LeafChar, number] {\n if (this.pattern[index] == \"\\\\\") {\n return this.parseEscapeChar(index, end);\n } else {\n return this.parseSingleChar(index, end);\n }\n }\n\n protected parseSingleChar(index = 0, end = 0): [LeafChar, number] {\n // single char\n const ch = this.pattern.charCodeAt(index);\n return [LeafChar.Single(ch), 1];\n }\n\n protected parsePropertyEscape(index = 0, end = 0): [LeafChar, number] {\n const pattern = this.pattern;\n if (pattern[index] + 1 != \"{\") {\n this.throwError(\"Invalid property escape\");\n }\n index += 2;\n let clEnd = index;\n let eqPos = -1;\n while (clEnd <= end && pattern[clEnd] != \"}\") {\n if (pattern[clEnd] == \"=\") eqPos = clEnd;\n clEnd++;\n }\n if (clEnd > end) {\n this.throwError(\"Invalid property escape\");\n }\n // see if this is a lone property escape\n const propStr = pattern.substring(index, clEnd);\n let propName = \"General_Category\";\n let propValue = propStr;\n if (eqPos >= 0) {\n const parts = propStr.split(\"=\");\n if (parts.length != 2) this.throwError(\"Invalid property escape\");\n propName = parts[0].trim();\n propValue = parts[1].trim();\n }\n return [LeafChar.PropertyEscape(propName, propValue), 2 + clEnd + 1 - index];\n }\n\n protected parseEscapeChar(index = 0, end = 0): [LeafChar, number] {\n const pattern = this.pattern;\n TSU.assert(pattern[index] == \"\\\\\", \"Expected '\\\\'\");\n // escape char\n index++;\n if (index > end) {\n this.throwError(\"Encounted unexpected end of input after \\\\\");\n }\n const ch = pattern[index];\n if ((this.unicode && ch == \"p\") || ch == \"P\") {\n // property escapes\n return this.parsePropertyEscape(index, end);\n }\n switch (ch) {\n // char classes\n case \"w\":\n return [LeafChar.Class(CharClassType.WORD_CHAR), 2];\n case \"W\":\n return [LeafChar.Class(CharClassType.WORD_CHAR, true), 2];\n case \"d\":\n return [LeafChar.Class(CharClassType.DIGITS), 2];\n case \"D\":\n return [LeafChar.Class(CharClassType.DIGITS, true), 2];\n case \"s\":\n return [LeafChar.Class(CharClassType.SPACES), 2];\n case \"S\":\n return [LeafChar.Class(CharClassType.SPACES, true), 2];\n case \"0\":\n if (pattern[index + 1] >= \"0\" && pattern[index + 1] <= \"9\" && this.unicode) {\n this.throwError(\"Invalid decimal escape\");\n }\n return [LeafChar.Single(\"\\0\"), 2];\n case \"r\":\n return [LeafChar.Single(\"\\r\"), 2];\n case \"n\":\n return [LeafChar.Single(\"\\n\"), 2];\n case \"f\":\n return [LeafChar.Single(\"\\f\"), 2];\n case \"b\":\n return [LeafChar.Single(\"\\b\"), 2];\n case \"v\":\n return [LeafChar.Single(\"\\v\"), 2];\n case \"t\":\n return [LeafChar.Single(\"\\t\"), 2];\n case \"c\":\n // ControlEscape:\n // https://262.ecma-international.org/5.1/#sec-15.10.2.10\n if (this.unicode || index >= end) {\n this.throwError(`Invalid char sequence at ${index}, ${end}`);\n }\n const next = pattern.charCodeAt(index + 1) % 32;\n return [LeafChar.Single(next), 3];\n case \"x\":\n // 2 digit hex digits\n index++;\n if (index >= end) {\n this.throwError(`Invalid hex sequence at ${index}, ${end}`);\n }\n const hexSeq = pattern.substring(index, index + 2);\n const hexVal = parseInt(hexSeq, 16);\n TSU.assert(!isNaN(hexVal), `Invalid hex sequence: '${hexSeq}'`);\n return [LeafChar.Single(hexVal), 4];\n case \"u\": // this could \\uABCD or \\u{ABCDEF}\n index++;\n // 4 digit hex digits for unicode\n if (index > end - 3) {\n this.throwError(`Invalid unicode sequence at ${index}`);\n }\n const ucodeSeq = pattern.substring(index, index + 4);\n const ucodeVal = parseInt(ucodeSeq, 16);\n if (isNaN(ucodeVal)) {\n this.throwError(`Invalid unicode sequence: '${ucodeSeq}'`);\n }\n return [LeafChar.Single(ucodeVal), 6];\n case \"^\": // List of special operators that need to be escaped\n case \"$\":\n case \".\":\n case \"*\":\n case \"+\":\n case \"?\":\n case \"\\\\\":\n case \"'\":\n case '\"':\n case \"(\":\n case \")\":\n case \"[\":\n case \"]\":\n case \"{\":\n case \"}\":\n case \"|\":\n case \"/\":\n return [LeafChar.Single(ch), 2];\n default:\n if (this.unicode) this.throwError(\"Invalid escape character: \" + ch);\n return [LeafChar.Single(ch), 2];\n }\n }\n\n protected parseQuant(stack: Regex[], curr: number, end: number): number {\n const pattern = this.pattern;\n const lastCh = pattern[curr - 1];\n let minCount = 1,\n maxCount = 1;\n if (pattern[curr] == \"*\") {\n minCount = 0;\n maxCount = TSU.Constants.MAX_INT;\n } else if (pattern[curr] == \"+\") {\n minCount = Math.min(minCount, 1);\n maxCount = TSU.Constants.MAX_INT;\n } else if (pattern[curr] == \"?\") {\n minCount = 0;\n maxCount = Math.max(maxCount, 1);\n } else if (pattern[curr] == \"{\") {\n // find the next \"}\"\n const clPos = pattern.indexOf(\"}\", curr + 1);\n if (clPos <= curr || clPos > end) {\n this.throwError(\"Unexpected end of input while looking for '}'\");\n }\n const sub = pattern.substring(curr + 1, clPos).trim();\n const parts = sub.split(\",\").map((x) => parseInt(x.trim()));\n curr = clPos;\n if (parts.length == 1) {\n if (isNaN(parts[0])) {\n if (sub.trim().length > 0) {\n stack.push(new Var(sub.trim()));\n return curr + 1;\n } else {\n this.throwError(`Invalid quantifier: /${sub}/`);\n }\n }\n minCount = maxCount = parts[0];\n } else if (parts.length == 2) {\n minCount = isNaN(parts[0]) ? 0 : parts[0];\n maxCount = isNaN(parts[1]) ? TSU.Constants.MAX_INT : parts[1];\n if (minCount > maxCount) {\n this.throwError(`Invalid Quant /${sub}/: Min must be <= Max`);\n }\n } else if (parts.length > 2) {\n this.throwError(`Invalid quantifier spec: \"{${sub}}\"`);\n }\n } else {\n throw new Error(\"Here?\");\n }\n // Quantifiers\n if (stack.length <= 0) {\n this.throwError(\"Quantifier cannot appear before an expression\");\n }\n // no optimizations - convert the last one into a Quantifier\n // and we will start to fill in the quantities and greediness\n const last = stack[stack.length - 1];\n if (last.tag == RegexType.QUANT && (lastCh == \"*\" || lastCh == \"?\" || lastCh == \"+\" || lastCh == \"}\")) {\n this.throwError(\"Nothing to repeat\");\n }\n if (this.unicode && (last.tag == RegexType.LOOK_AHEAD || last.tag == RegexType.LOOK_BACK)) {\n this.throwError(\"Cannot have quantifier on assertion in unicode mode\");\n }\n const quant = (stack[stack.length - 1] = new Quant(last));\n quant.minCount = minCount;\n quant.maxCount = maxCount;\n // check if there is an extra lazy quantifier\n curr++;\n if (curr <= end && pattern[curr] == \"?\" && quant.greedy) {\n curr++;\n quant.greedy = false;\n }\n return curr;\n }\n}\n","import * as TSU from \"@panyam/tsutils\";\nimport { TapeInterface as Tape } from \"./tape\";\nimport {\n LookAhead,\n Quant,\n RegexType,\n StartOfInput,\n EndOfInput,\n Regex,\n Cat,\n CharType,\n Char,\n LeafChar,\n CharGroup,\n Var,\n Union,\n} from \"./core\";\nimport { CharClassType } from \"./charclasses\";\nimport { GroupCounter, isSpace } from \"./utils\";\n\nfunction advanceIf(tape: Tape, ch: string): boolean {\n const pos = tape.index;\n for (let i = 0; i < ch.length; i++) {\n if (tape.currCh != ch.charAt(i)) {\n tape.index = pos;\n return false;\n }\n tape.advance(1);\n }\n return true;\n}\n\n/**\n * A RegexParser for parsing regex strings in Flex RE format.\n * This class will seldom have to be used directly. Instead use one of the methods in {@link Builder}\n */\nexport class RegexParser {\n protected counter: GroupCounter = new GroupCounter();\n\n parse(pattern: Tape, ignoreSpaces = false, obCount = 0): Regex {\n const stack: Regex[] = [];\n\n while (pattern.hasMore) {\n const currCh = pattern.currCh;\n // see if we have groups so they get highest preference\n if (advanceIf(pattern, \".\")) {\n stack.push(LeafChar.Any());\n } else if (advanceIf(pattern, \"^\")) {\n const x = new StartOfInput();\n x.multiline = true;\n stack.push(x);\n } else if (advanceIf(pattern, \"$\")) {\n const x = new EndOfInput();\n x.multiline = true;\n stack.push(x);\n } else if (advanceIf(pattern, \"|\")) {\n // reduce everything \"until now\" and THEN apply\n const prev = this.reduceLeft(stack);\n // this.parse everything to the right\n const rest = this.parse(pattern, ignoreSpaces, obCount);\n return new Union(prev, rest);\n } else if (currCh == \"[\") {\n stack.push(this.parseCharGroup(pattern));\n } else if (currCh == \"*\" || currCh == \"?\" || currCh == \"+\" || currCh == \"{\") {\n this.parseQuant(pattern, stack);\n } else if (ignoreSpaces && isSpace(currCh)) {\n // do nothing\n pattern.advance(1);\n } else if (ignoreSpaces && advanceIf(pattern, \"/*\")) {\n // Read everything until a */\n while (pattern.currCh != \"*\" || pattern.nextCh != \"/\") {\n if (!pattern.hasMore) {\n this.throwError(pattern, \"Unterminated comment\");\n }\n pattern.advance(1);\n }\n pattern.advance(2);\n // now do nothing\n } else if (advanceIf(pattern, \"{-}\")) {\n // char class intersection\n throw new Error(\"Intersection Not yet supported\");\n } else if (advanceIf(pattern, \"{+}\")) {\n // char class union\n throw new Error(\"Union Not yet supported\");\n } else if (advanceIf(pattern, \"(\")) {\n if (advanceIf(pattern, \"?\")) {\n if (advanceIf(pattern, \"#\")) {\n while (pattern.hasMore && pattern.currCh != \")\") pattern.advance(1);\n TSU.assert(advanceIf(pattern, \")\"), \"Expected ')'\");\n } else {\n // pattern of the form (?r-s:pattern)\n let ignoreCase = false;\n let dotAll = false;\n let ignoreSpaces2 = ignoreSpaces as boolean;\n let neg = false;\n while (pattern.hasMore && pattern.currCh != \":\") {\n if (pattern.currCh == \"i\") {\n ignoreCase = neg ? false : true;\n } else if (pattern.currCh == \"s\") {\n dotAll = neg ? false : true;\n } else if (pattern.currCh == \"x\") {\n ignoreSpaces2 = neg ? false : true;\n } else if (pattern.currCh == \"-\") {\n neg = true;\n }\n pattern.advance(1);\n }\n TSU.assert(advanceIf(pattern, \":\"), \"Expected ':'\");\n const groupIndex = this.counter.next();\n let subExpr = this.parse(pattern, ignoreSpaces2, obCount + 1);\n if (subExpr.groupIndex >= 0) {\n // Already set so create cat\n subExpr = new Cat(subExpr);\n }\n subExpr.dotAll = dotAll;\n subExpr.ignoreCase = ignoreCase;\n subExpr.groupIndex = groupIndex;\n stack.push(subExpr);\n TSU.assert(advanceIf(pattern, \")\"), \"Expected ')'\");\n }\n } else {\n // parse the subgroup and give it a group number\n const groupIndex = this.counter.next();\n let subExpr = this.parse(pattern, ignoreSpaces, obCount + 1);\n if (subExpr.groupIndex >= 0) {\n // Already set so create cat\n subExpr = new Cat(subExpr);\n }\n subExpr.groupIndex = groupIndex;\n stack.push(subExpr);\n TSU.assert(advanceIf(pattern, \")\"), \"Expected ')'\");\n }\n } else if (currCh == \")\") {\n if (obCount == 0) {\n this.throwError(pattern, `Unmatched ${currCh}. Try using \\\\${currCh}`);\n }\n // stop here so we can recurse up\n break;\n } else if (currCh == \"]\" || currCh == \"}\") {\n this.throwError(pattern, `Unmatched ${currCh}. Try using \\\\${currCh}`);\n } else if (advanceIf(pattern, \"/\")) {\n // LookAheads\n const prev = this.reduceLeft(stack);\n // this.parse everything to the right\n const rest = this.parse(pattern, ignoreSpaces, obCount);\n return new LookAhead(prev, rest, false);\n } else if (advanceIf(pattern, '\"')) {\n // raw string\n while (pattern.currCh != '\"') {\n if (!pattern.hasMore) {\n this.throwError(pattern, \"Unterminated string\");\n }\n stack.push(this.parseChar(pattern));\n }\n pattern.advance(1);\n } else {\n // plain old alphabets\n stack.push(this.parseChar(pattern));\n }\n }\n if (stack.length == 1) return stack[0];\n return new Cat(...stack);\n }\n\n protected parseQuant(pattern: Tape, stack: Regex[]): void {\n let minCount = 1,\n maxCount = 1;\n if (advanceIf(pattern, \"*\")) {\n minCount = 0;\n maxCount = TSU.Constants.MAX_INT;\n } else if (advanceIf(pattern, \"+\")) {\n minCount = Math.min(minCount, 1);\n maxCount = TSU.Constants.MAX_INT;\n } else if (advanceIf(pattern, \"?\")) {\n minCount = 0;\n maxCount = Math.max(maxCount, 1);\n } else if (advanceIf(pattern, \"{\")) {\n let foundComma = false;\n let p1 = \"\";\n let p2 = \"\";\n while (pattern.hasMore && pattern.currCh != \"}\") {\n if (pattern.currCh == \",\") foundComma = true;\n else {\n if (!foundComma) p1 += pattern.currCh;\n else p2 += pattern.currCh;\n }\n pattern.advance(1);\n }\n if (!pattern.hasMore) {\n this.throwError(pattern, \"Invalid property escape\");\n }\n // see if this is a lone property escape\n p1 = p1.trim();\n p2 = p2.trim();\n // advance over the \"}\"\n pattern.advance(1);\n\n const part1 = parseInt(p1);\n const part2 = parseInt(p2);\n if (foundComma) {\n minCount = isNaN(part1) ? 0 : part1;\n maxCount = isNaN(part2) ? TSU.Constants.MAX_INT : part2;\n if (minCount > maxCount) {\n this.throwError(pattern, `Invalid Quant /${p1},${p2}/: Min must be <= Max`);\n }\n } else {\n if (isNaN(part1)) {\n if (p1.length > 0) {\n stack.push(new Var(p1));\n // nothing more\n return;\n } else {\n this.throwError(pattern, `Invalid quantifier: /${p1}/`);\n }\n minCount = maxCount = 1;\n } else {\n minCount = maxCount = part1;\n }\n }\n } else {\n this.throwError(pattern, \"Expected '{', '*', '?' or '+', Found: \" + pattern.currCh);\n }\n // Quantifiers\n if (stack.length <= 0) {\n this.throwError(pattern, \"Quantifier cannot appear before an expression\");\n }\n // no optimizations - convert the last one into a Quantifier\n // and we will start to fill in the quantities and greediness\n const last = stack[stack.length - 1];\n let quant: Quant;\n if (last.tag == RegexType.QUANT && last.groupIndex < 0) {\n // Fold repeated quants unless they are not in a group\n quant = last as Quant;\n quant.minCount = Math.min(minCount, quant.minCount);\n quant.maxCount = Math.max(maxCount, quant.maxCount);\n } else {\n quant = stack[stack.length - 1] = new Quant(last);\n quant.minCount = minCount;\n quant.maxCount = maxCount;\n }\n // check if there is an extra lazy quantifier\n if (quant.greedy && advanceIf(pattern, \"?\")) {\n quant.greedy = false;\n }\n }\n\n protected parseCharGroup(pattern: Tape): Char {\n const out: Char[] = [];\n TSU.assert(advanceIf(pattern, \"[\"), \"Expected '['\");\n // first see which characters are in this (until the end)\n const neg = advanceIf(pattern, \"^\");\n while (pattern.currCh != \"]\") {\n const currch = this.parseChar(pattern);\n if (advanceIf(pattern, \"-\")) {\n if (pattern.hasMore) {\n // TODO - Should this be for all such \"operator\" charactors?\n if (pattern.currCh == \"]\" || pattern.currCh == \"[\") {\n // Special case for something like:\n // [....x-] or [.....x-[:alpha:]]\n out.push(currch);\n out.push(LeafChar.Single(\"-\"));\n } else {\n const endch = this.parseChar(pattern);\n if (currch.op != CharType.SingleChar || endch.op != CharType.SingleChar) {\n this.throwError(pattern, \"Char range cannot start or end in a char class\");\n }\n if (endch.args[0] < currch.args[0]) {\n this.throwError(pattern, \"End cannot be less than start\");\n }\n // currch.end = endch.start;\n out.push(CharGroup.Range(currch, endch));\n }\n } else {\n this.throwError(pattern, \"Unterminated char class\");\n }\n } else {\n out.push(currch);\n }\n }\n TSU.assert(advanceIf(pattern, \"]\"), \"']' expected\");\n return CharGroup.Union(neg, out);\n }\n\n protected parseChar(pattern: Tape): LeafChar {\n if (pattern.currCh == \"\\\\\") {\n return this.parseEscapeChar(pattern);\n } else {\n return this.parseSingleChar(pattern);\n }\n }\n\n protected parseSingleChar(pattern: Tape): LeafChar {\n // single char\n const ch = pattern.currCh;\n pattern.advance(1);\n return LeafChar.Single(ch);\n }\n\n protected parsePropertyEscape(pattern: Tape): LeafChar {\n TSU.assert(advanceIf(pattern, \"\\\\{\"), \"Invalid property escape\");\n pattern.advance(2);\n let foundEq = false;\n let propName = \"\";\n let propValue = \"\";\n while (pattern.hasMore && pattern.currCh != \"}\") {\n if (pattern.currCh == \"=\") foundEq = true;\n else {\n if (!foundEq) propName += pattern.currCh;\n else propValue += pattern.currCh;\n }\n pattern.advance(1);\n }\n if (!pattern.hasMore) {\n this.throwError(pattern, \"Invalid property escape\");\n }\n // see if this is a lone property escape\n propName = propName.trim();\n propValue = propValue.trim();\n if (!foundEq) {\n propValue = propName;\n propName = \"General_Category\";\n }\n // advance over the \"}\"\n pattern.advance(1);\n return LeafChar.PropertyEscape(propName, propValue);\n }\n\n protected parseEscapeChar(pattern: Tape): LeafChar {\n TSU.assert(advanceIf(pattern, \"\\\\\"), \"Expected '\\\\'\");\n // escape char\n if (!pattern.hasMore) {\n this.throwError(pattern, \"Encounted unexpected end of input after \\\\\");\n }\n if (advanceIf(pattern, \"w\")) {\n return LeafChar.Class(CharClassType.WORD_CHAR);\n } else if (advanceIf(pattern, \"W\")) {\n return LeafChar.Class(CharClassType.WORD_CHAR, true);\n } else if (advanceIf(pattern, \"d\")) {\n return LeafChar.Class(CharClassType.DIGITS);\n } else if (advanceIf(pattern, \"D\")) {\n return LeafChar.Class(CharClassType.DIGITS, true);\n } else if (advanceIf(pattern, \"s\")) {\n return LeafChar.Class(CharClassType.SPACES);\n } else if (advanceIf(pattern, \"S\")) {\n return LeafChar.Class(CharClassType.SPACES, true);\n } else if (advanceIf(pattern, \"0\")) {\n return LeafChar.Single(\"\\0\");\n } else if (advanceIf(pattern, \"r\")) {\n return LeafChar.Single(\"\\r\");\n } else if (advanceIf(pattern, \"n\")) {\n return LeafChar.Single(\"\\n\");\n } else if (advanceIf(pattern, \"f\")) {\n return LeafChar.Single(\"\\f\");\n } else if (advanceIf(pattern, \"b\")) {\n return LeafChar.Single(\"\\b\");\n } else if (advanceIf(pattern, \"v\")) {\n return LeafChar.Single(\"\\v\");\n } else if (advanceIf(pattern, \"t\")) {\n return LeafChar.Single(\"\\t\");\n } else if (advanceIf(pattern, \"\\\\\")) {\n return LeafChar.Single(\"\\\\\");\n } else if (advanceIf(pattern, \"'\")) {\n return LeafChar.Single(\"'\");\n } else if (advanceIf(pattern, '\"')) {\n return LeafChar.Single('\"');\n } else if (advanceIf(pattern, \"x\")) {\n // 2 digit hex digits\n if (!pattern.hasMore) {\n this.throwError(pattern, `Invalid hex sequence at ${pattern.index}`);\n }\n const hexSeq = pattern.currCh + pattern.nextCh;\n const hexVal = parseInt(hexSeq, 16);\n TSU.assert(!isNaN(hexVal), `Invalid hex sequence: '${hexSeq}'`);\n pattern.advance(2);\n return LeafChar.Single(hexVal);\n } else if (advanceIf(pattern, \"u\")) {\n // 4 digit hex digits for unicode\n if (!pattern.canAdvance(3)) {\n // index >= pattern.input.length - 3) {\n this.throwError(pattern, `Invalid unicode sequence at ${pattern.index}`);\n }\n const ucodeSeq = pattern.substring(pattern.index, pattern.index + 4);\n const ucodeVal = parseInt(ucodeSeq, 16);\n if (isNaN(ucodeVal)) {\n this.throwError(pattern, `Invalid unicode sequence: '${ucodeSeq}'`);\n }\n pattern.advance(4);\n return LeafChar.Single(ucodeVal);\n }\n // default\n const ch = pattern.currCh;\n pattern.advance(1);\n return LeafChar.Single(ch);\n }\n\n protected reduceLeft(stack: Regex[]): Regex {\n const r = stack.length == 1 ? stack[0] : new Cat(...stack);\n // remove all elements on stack\n stack.splice(0);\n return r;\n }\n\n protected throwError(pattern: Tape, msg: string): void {\n throw new Error(msg);\n // this.throwError(pattern, `Error in Flex RE '${pattern.input}': ${msg}`);\n }\n}\n","import { Rule, Regex, REPatternType } from \"./core\";\nimport { RegexParser as JSREParser } from \"./jsparser\";\nimport { RegexParser as FlexREParser } from \"./flexparser\";\nimport { Tape } from \"./tape\";\n\n/**\n * Uber method to build a Regex given either a regex string or a JS regex.\n *\n * @param pattern Either a regex pattern, a JS RegExp object, or an already parsed Regex object.\n * @param config TBD\n *\n * @return A {@link Rule} object that contains the pattern as well as its normalized regex tree.\n */\nexport function build(pattern: string | RegExp | Regex, config?: any): Rule {\n if (typeof pattern === \"string\") {\n const rule = new Rule(exprFromJSRE(pattern, config), config);\n rule.pattern = pattern;\n return rule;\n } else if (pattern.constructor.name == \"RegExp\") {\n const rule = new Rule(exprFromJSRE(pattern as RegExp, config), config);\n rule.pattern = (pattern as RegExp).source;\n return rule;\n } else {\n // Already compiled expression\n return new Rule(pattern as Regex, config);\n }\n}\n\n/*\nexport function fromRE(pattern: string, config?: any): Rule {\n const expr = new JSREParser(pattern, config).parse();\n const rule = new Rule(expr, config);\n rule.pattern = pattern;\n return rule;\n}\n\nexport function fromJSRE(re: RegExp, config?: any): Rule {\n const expr = exprFromJSRE(re);\n const rule = new Rule(expr, config);\n rule.pattern = re.source;\n return rule;\n}\n\nexport function fromFlexRE(re: string, config?: any): Rule {\n const expr = exprFromFlexRE(re);\n const rule = new Rule(expr, config);\n rule.pattern = re;\n return rule;\n}\n*/\n\n/**\n * \"Flattens\" either a single REPatternType or a list of REPatternTypes into a flat list of all\n * REPatternTypes at the leaf levels.\n */\nexport function flatten(re: REPatternType | REPatternType[], index = 0, rules?: Rule[]): Rule[] {\n rules = rules || [];\n if (typeof re === \"string\") {\n rules.push(build(re, { tag: index }));\n } else if (re.constructor == RegExp) {\n rules.push(build(re, { tag: index }));\n } else if (re.constructor == Rule) {\n rules.push(re as Rule);\n } else if (re.constructor == Regex) {\n rules.push(new Rule(re as Regex));\n } else {\n const res = re as (RegExp | Rule | string)[];\n for (let i = 0; i < res.length; i++) {\n flatten(res[i], i, rules);\n }\n }\n return rules;\n}\n\n/**\n * Takes a string assumed to be in Flex RE format and parses the Regex expression out of it.\n */\nexport function exprFromFlexRE(pattern: string): Regex {\n const parser = new FlexREParser();\n try {\n const expr = parser.parse(new Tape(pattern));\n // if not specified default to false\n if (expr.dotAll == null) expr.dotAll = false;\n if (expr.multiline == null) expr.multiline = false;\n return expr;\n } catch (error) {\n console.log(\"Error in FLEX RE: \", pattern);\n throw error;\n }\n}\n\n/**\n * Takes a string assumed to be in JS RE format and parses the Regex expression out of it.\n */\nexport function exprFromJSRE(re: string | RegExp, config?: any): Regex {\n config = config || {};\n const isRegExp = typeof re !== \"string\";\n const pattern = typeof re === \"string\" ? re : re.source;\n if (isRegExp) config.unicode = (re as RegExp).unicode;\n const expr = new JSREParser(pattern, config).parse();\n if (typeof re !== \"string\") {\n expr.dotAll = re.dotAll;\n expr.ignoreCase = re.ignoreCase;\n expr.multiline = re.multiline;\n }\n return expr;\n}\n\n/**\n * A way to build a JS RE from a string literal, eg: jsRE`a*b+`\n */\nexport function jsRE(strings: TemplateStringsArray, ...keys: any[]): Regex {\n // what we have is the raw value of this template and this can be parsed by our parser\n const merged = String.raw(strings, ...keys);\n return exprFromJSRE(merged);\n}\n\n/**\n * A way to build a Flex RE from a string literal, eg: flexRE`a*b+`\n */\nexport function flexRE(strings: TemplateStringsArray, ...keys: any[]): Regex {\n const merged = String.raw(strings, ...keys);\n return exprFromFlexRE(merged);\n}\n","import * as TSU from \"@panyam/tsutils\";\nimport { Regex, Union, Rule, RuleConfig } from \"./core\";\nimport { Prog, Match, VM } from \"./vm\";\nimport { Compiler } from \"./compiler\";\nimport { TapeInterface as Tape, Tape as DefaultTape } from \"./tape\";\nimport { TokenizerError } from \"./errors\";\nimport * as Builder from \"./builder\";\nimport { Token, TokenType } from \"./token\";\n\nexport type RuleMatchHandler = (rule: Rule, tape: Tape, token: Token, owner: any) => any;\nexport type TokenizerErrorHandler = (error: Error, tape: Tape, startIndex: number) => Error | null;\n\nexport function toToken(tag: TokenType, m: Match, tape: Tape | null): Token {\n const out = new Token(tag, m.matchIndex, m.start, m.end);\n for (let i = 0; i < m.positions.length; i += 2) {\n if (m.positions[i] >= 0) {\n out.positions[Math.floor(i / 2)] = [m.positions[i], m.positions[i + 1]];\n }\n }\n for (const [groupIndex, tapeIndex] of m.groups) {\n const gi = Math.abs(groupIndex);\n if (!(gi in out.groups)) {\n out.groups[gi] = [];\n }\n out.groups[gi].push(tapeIndex);\n }\n if (tape != null) out.value = tape.substring(m.start, m.end);\n return out;\n}\n\nexport class BaseTokenizer {\n protected _prog: Prog | null = null;\n protected _vm: VM | null = null;\n\n /**\n * Error handler called when an invalid character or lexeme is encountered.\n * If this method returns back an error then the tokenization stops otherwise\n * (if a null is returned) then tokenization continues.\n *\n * @param error The error currently caught and being handled.\n * @param tape The tape currently being tokenized.\n * @param startIndex The start index when the tokenization began resulting in the error.\n */\n onError: TokenizerErrorHandler | null = null;\n\n // Stores named rules\n // Rules are a \"regex\", whether literal or not\n allRules: Rule[] = [];\n onMatchHandlers: (RuleMatchHandler | null)[] = [];\n matchHandlersByValue: any = {};\n variables = new Map<string, Regex>();\n compiler: Compiler = new Compiler((name) => {\n let out = this.variables.get(name) || null;\n if (out == null) out = this.findRuleByValue(name)?.expr || null;\n if (out == null) throw new Error(`Invalid regex reference: ${name}`);\n return out;\n });\n\n getVar(name: string): Regex | null {\n return this.variables.get(name) || null;\n }\n\n addVar(name: string, regex: Regex): this {\n let currValue = this.variables.get(name) || null;\n if (currValue == null) {\n currValue = regex;\n } else {\n currValue = new Union(currValue, regex);\n }\n this.variables.set(name, regex);\n return this;\n }\n\n findRuleByValue(value: any): Rule | null {\n return this.allRules.find((r) => r.tag == value) || null;\n }\n\n /**\n * Helper method over the addRule method that converts the pattern to its normalized expression form\n * and adds a rule to the tokenizer.\n *\n * @param pattern A raw string or a JS RegExp, or parsed Regex expression\n * (either from JS or Flex RE syntax).\n * @param config Rule configs to control priority and other aspects of rules to be used during\n * the match stage.\n * @param onMatch A callback method called when the rule is matched.\n */\n add(\n pattern: string | RegExp | Regex,\n config?: RuleConfig | RuleMatchHandler | null,\n onMatch: RuleMatchHandler | null = null,\n ): this {\n if (typeof config === \"function\") {\n onMatch = config;\n config = null;\n }\n return this.addRule(Builder.build(pattern, config), onMatch);\n }\n\n /**\n * Helper method over the addRule method that converts the pattern to its normalized expression form\n * and adds a rule to the tokenizer.\n *\n * @param rule A normalized Rule object that contains both the pattern as well as rule configs\n * to be used during the match and afterwards (if successfully matched).\n * @param onMatch A callback method called when the rule is matched.\n */\n addRule(rule: Rule, onMatch: null | RuleMatchHandler = null): this {\n rule.matchIndex = this.allRules.length;\n this.allRules.push(rule);\n this.onMatchHandlers.push(onMatch);\n this._prog = null;\n this._vm = null;\n return this;\n }\n\n /**\n * Add a token match callback by value.\n */\n on(tag: any, onMatch: RuleMatchHandler): this {\n this.matchHandlersByValue[tag] = onMatch;\n return this;\n }\n\n get prog(): Prog {\n if (this._prog == null) {\n const sortedRules = this.sortRules();\n this._prog = this.compiler.compile(sortedRules);\n }\n return this._prog;\n }\n\n get vm(): VM {\n if (this._vm == null) {\n this._vm = new VM(this.prog);\n }\n return this._vm;\n }\n\n protected sortRules(): Rule[] {\n // Sort rules so high priority ones appear first\n const sortedRules: Rule[] = this.allRules.map((rule) => rule);\n sortedRules.sort((r1, r2) => {\n if (r1.priority != r2.priority) return r2.priority - r1.priority;\n return r1.matchIndex - r2.matchIndex;\n });\n return sortedRules;\n }\n}\n\n/**\n * A batch tokenizer.\n */\nexport class Tokenizer extends BaseTokenizer {\n idCounter = 0;\n\n /**\n * Get the current lexer state (for incremental lexing support).\n * State is used to track context-sensitive lexing modes.\n */\n getState(): number {\n return this.vm.getState();\n }\n\n /**\n * Set the lexer state (for incremental lexing support).\n * Allows restarting lexing from a saved state.\n */\n setState(state: number): void {\n this.vm.setState(state);\n }\n\n /**\n * Reset the tokenizer state. Useful for incremental lexing\n * when restarting from a different position.\n */\n reset(): void {\n this.idCounter = 0;\n // Reset VM state to initial\n if (this._vm) {\n this._vm.setState(0);\n }\n }\n\n next(tape: Tape, owner: any): Token | null {\n if (!tape.hasMore) {\n return null;\n }\n const startIndex = tape.index;\n const startChar = tape.currCh;\n const m = this.vm.match(tape);\n if (m == null) {\n // no match so we have an error\n let err: Error | null = null;\n if (tape.index == startIndex + 1) {\n err = new TokenizerError(`Unexpected Character: ${startChar}`, startIndex, 1, \"UnexpectedCharacter\", startChar);\n } else {\n err = new TokenizerError(\n `Unexpected Symbol: ${tape.substring(startIndex, tape.index)}`,\n startIndex,\n tape.index - startIndex,\n \"UnexpectedLexeme\",\n );\n }\n if (this.onError) {\n err = this.onError(err, tape, startIndex);\n }\n if (err != null) {\n throw err;\n } else {\n // err has been ocnsumed so we can restart tokenizer at the current position\n return this.next(tape, owner);\n }\n }\n const rule = this.allRules[m.matchIndex];\n let token = toToken(rule.tag, m, tape);\n token.id = this.idCounter++;\n let onMatch = this.onMatchHandlers[m.matchIndex];\n if (!onMatch) {\n onMatch = this.matchHandlersByValue[rule.tag];\n }\n if (onMatch) {\n token = onMatch(rule, tape, token, owner);\n if (token == null) {\n // null is returned by onMatch to skip tokens\n return this.next(tape, owner);\n }\n } else if (rule.skip) {\n return this.next(tape, owner);\n }\n return token;\n }\n\n tokenize(tape: string | Tape, owner: any = null): Token[] {\n const tokens = [] as Token[];\n if (typeof tape === \"string\") {\n tape = new DefaultTape(tape);\n }\n let next = this.next(tape, owner);\n while (next) {\n tokens.push(next);\n try {\n next = this.next(tape, owner);\n } catch (err: any) {\n tokens.push({\n tag: \"ERROR\",\n start: err.offset,\n end: err.offset + err.length,\n value: err.message,\n } as Token);\n break;\n }\n }\n return tokens;\n }\n}\n","import { flexRE } from \"./builder\";\n\nexport const SINGLE_QUOTE_STRING = flexRE`[\"]([^\"\\\\\\n]|\\\\.|\\\\\\n)*[\"]`;\nexport const DOUBLE_QUOTE_STRING = flexRE`[']([^'\\\\\\n]|\\\\.|\\\\\\n)*[']`;\nexport const SIMPLE_JS_STRING = '\"(.*?(?<!\\\\\\\\))\"';\nexport const JS_REGEX_WITHOUT_LB = String.raw`/([^\\\\/]|\\\\.)*/([imus]*)`;\nexport const JS_REGEX = String.raw`/(.+?(?<!\\\\))/([imus]*)`;\n","import * as TSU from \"@panyam/tsutils\";\nimport * as TLEX from \"tlex\";\nimport { Sym, Grammar, Str, Rule, RuleAction } from \"./grammar\";\n\ntype Tape = TLEX.TapeInterface;\n\nconst str2regex = (s: string | number): string => {\n if (typeof s === \"number\") return \"\" + s;\n return s.replace(/[\\-\\[\\]\\/\\{\\}\\(\\)\\*\\+\\?\\.\\\\\\^\\$\\|]/g, \"\\\\$&\");\n};\n\nexport enum TokenType {\n STRING = \"STRING\",\n REGEX = \"REGEX\",\n NUMBER = \"NUMBER\",\n SPACES = \"SPACES\",\n IDENT = \"IDENT\",\n PCT_IDENT = \"PCT_IDENT\",\n STAR = \"STAR\",\n PLUS = \"PLUS\",\n QMARK = \"QMARK\",\n PIPE = \"PIPE\",\n DOLLAR_NUM = \"DOLLAR_NUM\",\n DOLLAR_IDENT = \"DOLLAR_IDENT\",\n OPEN_PAREN = \"OPEN_PAREN\",\n CLOSE_PAREN = \"CLOSE_PAREN\",\n OPEN_BRACE = \"OPEN_BRACE\",\n CLOSE_BRACE = \"CLOSE_BRACE\",\n OPEN_SQ = \"OPEN_SQ\",\n CLOSE_SQ = \"CLOSE_SQ\",\n COMMENT = \"COMMENT\",\n ARROW = \"ARROW\",\n COLCOLHYPHEN = \"COLCOLHYPHEN\",\n COLON = \"COLON\",\n SEMI_COLON = \"SEMI_COLON\",\n}\n\nexport type NewSymbolCallback = TSU.Nullable<(label: string, assumedTerminal: boolean) => Sym | void>;\nexport type TokenHandler = (token: TLEX.Token, tape: TLEX.TapeInterface, owner: any) => TLEX.Token | null;\n\nexport interface LoaderConfig {\n grammar?: Grammar;\n leftRecursive?: boolean;\n newSymbolCallback?: NewSymbolCallback;\n tokenHandlers: TSU.StringMap<TokenHandler>;\n debug?: string;\n}\n\n/**\n * Entry point in loading a grammar from a DSL spec.\n */\nexport function load(input: string, params?: LoaderConfig): [Grammar, null | TLEX.NextTokenFunc] {\n params = params || ({} as LoaderConfig);\n const g = new Grammar(params.grammar || {});\n const eparser = new Loader(input, { ...params, grammar: g });\n // g.augmentStartSymbol();\n const tokenFunc = eparser.generatedTokenizer.next.bind(eparser.generatedTokenizer);\n const debug = params.debug || \"\";\n if (debug.split(\"|\").findIndex((p: string) => p == \"all\" || p == \"lexer\") >= 0) {\n console.log(\"Prog: \\n\", `${eparser.generatedTokenizer.vm.prog.debugValue().join(\"\\n\")}`);\n }\n return [g, tokenFunc];\n}\n\n/**\n * The SemanticHandler is the bridge between the DSL, the Grammar, the Parser\n * and the caller of the parser.\n * In the DSL semantic actions can be added to tokenizer and grammar specs.\n * However the problem how to invoke them during runtime.\n *\n * For example in the grammar:\n *\n * E -> E + E { add($1, $3) }\n *\n * declares that when this rule is reduced the \"add\" function (in user land) is\n * invoked with the results of the right hand side values.\n *\n * This parsing however is done by the DSL loader and at this time the \"add\" method\n * is not declared anywhere. In fact the the declaration is only used by the parser\n * driver (after the parse tables have been constructed and parsing is started on\n * a real input). The parser here needs to supply the definition for \"add\" method.\n * Note only this only the parser can call what is needed to kick off the \"add\" method\n * to be invoked.\n *\n * So the parser will need something like:\n *\n * while (input) {\n * ....\n * reduceRule(Nt, E1, E2, E3 ..., \"action\")\n * }\n *\n * the \"action\" will be part of the SemanticHandler\n *\n * reduceRule(Nt...., \"action\") {\n * Nt.value = semanticHandler.getAction(\"action\").apply(E1, E2...., En);\n * }\n *\n * Similarly the caller of the \"parse\" method could populate the actions, eg:\n *\n * semanticHandler.register(\"action\", (a, b, c) => {\n * return ....;\n * });\n *\n * The DSL loader in turn returns a semanticHandler instance just the way it\n * creates a tokenizer.\n *\n * There are a couple of options here.\n *\n * 1. Keep actions simple and store action IDs and let the caller do all the work, eg:\n *\n * E -> E + E { add $1 $3 }\n *\n * 2. Provide a stronger expression syntax:\n *\n * Or we could add a slightly more functional syntax so that a proper interpreter like setup is possible, eg:\n *\n * E -> E + E { add(halve($1), double($3)) }\n *\n * Here instead of calling an action \"add\" we could actually store expression trees and call an interpreter\n * with attribute value bindings.\n *\n * For now we will go with (1) as it is simpler and we can always build up (2) if doing (1) alone is too verbose.\n *\n * With (1), syntax for semantic actions is:\n *\n * SemAction -> \"{\" ActionSpec \"}\" ;\n *\n * ActionSpec -> DOLLAR_NUM\n * | IDENT ( IDENT | DOLLAR_NUM | NUM | STRING | BOOLEAN | NULL ) *\n * ;\n *\n * 3. There is an evern simpler third option. Instead of the parser trying to martial parameters etc it could just\n * let the handler do the work of martialling/extracting parameters from children. This is effective and easy\n *\n * In this mode all child nodes are passed as is to the handler and it is upto the handler to return the semantic\n * value of the production.\n */\n\nexport function Tokenizer(): TLEX.Tokenizer {\n const lexer = new TLEX.Tokenizer();\n lexer.add(/->/, { tag: TokenType.ARROW });\n lexer.add(/\\[/, { tag: TokenType.OPEN_SQ });\n lexer.add(/\\]/, { tag: TokenType.CLOSE_SQ });\n lexer.add(/\\(/, { tag: TokenType.OPEN_PAREN });\n lexer.add(/\\)/, { tag: TokenType.CLOSE_PAREN });\n lexer.add(/\\{/, { tag: TokenType.OPEN_BRACE });\n lexer.add(/\\}/, { tag: TokenType.CLOSE_BRACE });\n lexer.add(/\\*/, { tag: TokenType.STAR });\n lexer.add(/\\+/, { tag: TokenType.PLUS });\n lexer.add(/\\?/, { tag: TokenType.QMARK });\n lexer.add(/;/, { tag: TokenType.SEMI_COLON });\n lexer.add(/:/, { tag: TokenType.COLON });\n lexer.add(/\\|/, { tag: TokenType.PIPE });\n lexer.add(/\\s+/m, { tag: TokenType.SPACES }, () => null);\n lexer.add(/\\/\\*.*?\\*\\//s, { tag: TokenType.COMMENT }, () => null);\n lexer.add(/\\/\\/.*$/m, { tag: TokenType.COMMENT }, () => null);\n lexer.add(TLEX.Samples.DOUBLE_QUOTE_STRING, { tag: TokenType.STRING }, (rule, tape, token) => {\n token.value = tape.substring(token.start + 1, token.end - 1);\n return token;\n });\n lexer.add(TLEX.Samples.SINGLE_QUOTE_STRING, { tag: TokenType.STRING }, (rule, tape, token) => {\n token.value = tape.substring(token.start + 1, token.end - 1);\n return token;\n });\n lexer.add(TLEX.Samples.JS_REGEX, { tag: TokenType.REGEX }, (rule, tape, token) => {\n const pattern = tape.substring(token.positions[1][0], token.positions[1][1]);\n const flags = tape.substring(token.positions[3][0], token.positions[3][1]);\n token.value = [pattern, flags];\n return token;\n });\n lexer.add(/\\d+/, { tag: TokenType.NUMBER }, (rule, tape, token) => {\n token.value = parseInt(tape.substring(token.start, token.end));\n return token;\n });\n lexer.add(/%([\\w][\\w\\d_]*)/, { tag: TokenType.PCT_IDENT }, (rule, tape, token) => {\n token.value = tape.substring(token.start + 1, token.end);\n return token;\n });\n lexer.add(/\\$\\d+/, { tag: TokenType.DOLLAR_NUM }, (rule, tape, token) => {\n token.value = parseInt(tape.substring(token.start + 1, token.end));\n return token;\n });\n lexer.add(/\\$([\\w][\\w\\d_]*)/, { tag: TokenType.DOLLAR_IDENT }, (rule, tape, token) => {\n token.value = tape.substring(token.start + 1, token.end);\n return token;\n });\n lexer.add(/[\\w][\\w\\d_]*/, { tag: TokenType.IDENT });\n return lexer;\n}\n\nexport enum NodeType {\n GRAMMAR = \"GRAMMAR\",\n DECL = \"DECL\",\n RULE = \"RULE\",\n PROD_NULL = \"PROD_NULL\",\n PROD_STR = \"PROD_STR\",\n PROD_UNION = \"PROD_UNION\",\n PROD_NAME = \"PROD_NAME\",\n PROD_STRING = \"PROD_STRING\",\n PROD_NUM = \"PROD_NUM\",\n PROD_IDENT = \"PROD_IDENT\",\n PROD_STAR = \"PROD_STAR\",\n PROD_PLUS = \"PROD_PLUS\",\n PROD_OPTIONAL = \"PROD_OPTIONAL\",\n IDENT = \"IDENT\",\n ERROR = \"ERROR\",\n COMMENT = \"COMMENT\",\n}\n\n/**\n * EBNF Grammar:\n *\n * grammar -> rules;\n *\n * decl -> rule ;\n *\n * rules -> rule | rule rules ;\n *\n * rule -> IDENT \"->\" top_productions \";\" ;\n *\n * top_productions -> ( actionSpec ) ?\n * | prod ( actionSpec ) ? top_productions\n * ;\n *\n * productions ->\n * | prod \"|\" productions\n * ;\n *\n * prod -> ( prod_group | optional_prod | IDENT ( \":\" name ) ? | STRING ) ( \"*\" | \"+\" | \"?\" ) ?\n * ;\n *\n * prod_group -> \"(\" productions \")\" ;\n *\n * optional_prod -> \"[\" productions \"]\" ;\n *\n * actionSpec := \"{\" IDENT \"(\" IDENT ( \",\" IDENT ) * \")\" \"}\"\n */\nexport class Loader {\n readonly grammar: Grammar;\n private tokenizer: TLEX.TokenBuffer;\n private leftRecursive = false;\n readonly generatedTokenizer: TLEX.Tokenizer = new TLEX.Tokenizer();\n tokenHandlers: TSU.StringMap<TokenHandler>;\n\n /*\n * The newSymbol callback provided to the contructor is a way for the client to\n * be given a chance to create a symbol given a new label that is encountered.\n * The client can either return a null to let this parser define the Symbol\n * or return a Symbol which will be associated with the given label going\n * forward.\n *\n * The newSymbol callback will ONLY be called once for each new label\n * encountered by the parser. If the client returns a duplicte symbol\n * then parsing fails.\n */\n private newSymbolCallback: NewSymbolCallback;\n private symbolsByLabel: TSU.StringMap<Sym>;\n\n /**\n * Allowed regex syntaxes - js or flex\n */\n private regexSyntax = \"js\";\n\n constructor(input: string, config?: LoaderConfig) {\n config = config || ({} as LoaderConfig);\n this.symbolsByLabel = {};\n this.grammar = config.grammar || new Grammar();\n this.leftRecursive = \"leftRecursive\" in config ? config.leftRecursive || false : true;\n this.newSymbolCallback = config.newSymbolCallback || null;\n this.tokenHandlers = config.tokenHandlers || {};\n this.parse(input);\n }\n\n /**\n * As the parser creates encounters a new literal or an identifier (hinting at\n * either a terminal or a non terminal), it needs to know which symbol to associate\n * with this lit/ident going forward.\n *\n * All symbols created for the grammar, since they are either created\n * by this parser or by the client (invokved by this parser), are\n * stored locally to be returned in this method.\n */\n symbolForLabel(label: string): TSU.Nullable<Sym> {\n return this.symbolsByLabel[label] || null;\n }\n\n /**\n * Registers a symbol for a given label.\n */\n registerSymbol(label: string, sym: Sym): void {\n TSU.assert(!(label in this.symbolsByLabel), `${label} is already registered`);\n this.symbolsByLabel[label] = sym;\n }\n\n /**\n * Ensures that a symbol exists for a given label (as found in the parser spec)\n * to be used through out the grammar.\n */\n ensureSymbol(label: string, assumedTerminal: boolean): Sym {\n let currSym = this.symbolForLabel(label);\n\n if (currSym != null) return currSym;\n else if (this.newSymbolCallback) {\n // then give the user a chance to create a symbol for this\n currSym = this.newSymbolCallback(label, assumedTerminal) || null;\n }\n if (currSym == null) {\n if (assumedTerminal) {\n currSym = this.grammar.newTerm(label);\n } else {\n currSym = this.grammar.newNT(label);\n }\n }\n // then register it so it is used going forward\n this.registerSymbol(label, currSym);\n return currSym;\n }\n\n parse(input: string): void {\n const et = Tokenizer();\n const ntFunc = (tape: Tape, owner: any) => {\n const out = et.next(tape, this);\n return out;\n };\n this.tokenizer = new TLEX.TokenBuffer(ntFunc, this);\n this.parseGrammar(new TLEX.Tape(input));\n }\n\n parseRegex(tape: TLEX.TapeInterface, tag?: string, priority = 0, syntax = \"\"): TLEX.Rule {\n if (syntax == \"\") syntax = this.regexSyntax;\n if (syntax == \"js\") {\n const tokPattern = this.tokenizer.expectToken(tape, TokenType.STRING, TokenType.NUMBER, TokenType.REGEX);\n let rule: TLEX.Rule;\n if (!tag || tag.length == 0) {\n tag = \"/\" + tokPattern.value[0] + \"/\" + tokPattern.value[1];\n }\n if (tokPattern.tag == TokenType.STRING || tokPattern.tag == TokenType.NUMBER) {\n const pattern = str2regex(tokPattern.value);\n rule = TLEX.Builder.build(pattern, { tag: tag, priority: priority + 20 });\n } else if (tokPattern.tag == TokenType.REGEX) {\n let re = tokPattern.value[0];\n if (tokPattern.value[1].length > 0) {\n // Flags given so create\n re = new RegExp(tokPattern.value[0], tokPattern.value[1]);\n }\n rule = TLEX.Builder.build(re, { tag: tag, priority: priority + 10 });\n } else {\n throw new TLEX.UnexpectedTokenError(tokPattern);\n }\n return rule;\n } else {\n // Flex style RE - no delimiters - just read until end of line and strip spaces\n let patternStr = \"\";\n while (tape.hasMore && tape.currCh != \"\\n\") {\n patternStr += tape.currCh;\n tape.advance();\n }\n patternStr = patternStr.trim();\n if (!tag || tag.length == 0) {\n tag = \"/\" + patternStr + \"/\";\n }\n return new TLEX.Rule(TLEX.Builder.exprFromFlexRE(patternStr), { tag: tag, priority: priority });\n }\n }\n\n parseGrammar(tape: TLEX.Tape): void {\n let peeked = this.tokenizer.peek(tape);\n while (peeked != null) {\n if (peeked.tag == TokenType.IDENT) {\n // declaration\n this.parseDecl(tape);\n } else if (peeked.tag == TokenType.PCT_IDENT) {\n this.tokenizer.next(tape);\n this.parseDirective(tape, peeked.value);\n } else {\n throw new SyntaxError(`Declaration must start with IDENT or PCT_IDENT. Found: '${peeked.value}' instead.`);\n }\n peeked = this.tokenizer.peek(tape);\n }\n }\n\n parseDirective(tape: TLEX.TapeInterface, directive: string): void {\n if (directive == \"start\") {\n // override start directive\n const next = this.tokenizer.expectToken(tape, TokenType.IDENT);\n this.grammar.startSymbol = this.ensureSymbol(next.value as string, false);\n } else if (directive == \"resyntax\") {\n // override start directive\n const next = this.tokenizer.expectToken(tape, TokenType.IDENT);\n if (next.value != \"js\" && next.value != \"flex\") {\n throw new SyntaxError(\"Invalid regex syntax: \" + next.value);\n }\n this.regexSyntax = next.value;\n } else if (directive.startsWith(\"skip\")) {\n const rule = this.parseRegex(tape, \"\", 30, directive.endsWith(\"flex\") ? \"flex\" : \"\");\n const tokenHandler = this.parseTokenHandler(tape);\n if (tokenHandler) {\n this.generatedTokenizer.addRule(rule, (rule, tape, token) => {\n tokenHandler(rule, tape, token, this);\n return null;\n });\n } else {\n this.generatedTokenizer.addRule(rule, () => null);\n }\n } else if (directive.startsWith(\"token\") || directive.startsWith(\"define\")) {\n const isDef = directive.startsWith(\"define\");\n const tokName = this.tokenizer.expectToken(tape, TokenType.IDENT, TokenType.STRING);\n let label = tokName.value as string;\n if (tokName.tag == TokenType.STRING || tokName.tag == TokenType.NUMBER) {\n label = `\"${tokName.value}\"`;\n }\n const rule = this.parseRegex(tape, label, 0, directive.endsWith(\"flex\") ? \"flex\" : \"\");\n if (isDef) {\n // Define a \"reusable\" regex that is not a token on its own\n this.generatedTokenizer.addVar(label, rule.expr);\n } else {\n const tokenHandler = this.parseTokenHandler(tape);\n // see if we have a handler function here\n this.generatedTokenizer.addRule(rule, tokenHandler);\n // register it\n this.ensureSymbol(label, true);\n }\n } else {\n throw new Error(\"Invalid directive: \" + directive);\n }\n }\n\n parseTokenHandler(tape: Tape): TLEX.RuleMatchHandler | null {\n if (!this.tokenizer.consumeIf(tape, TokenType.OPEN_BRACE)) {\n return null;\n }\n\n const funcName = this.tokenizer.expectToken(tape, TokenType.IDENT);\n\n // how do we use the funcName to\n const out = (rule: TLEX.Rule, tape: Tape, token: any, owner: any) => {\n const handler = this.tokenHandlers[funcName.value];\n if (!handler) throw new Error(\"Handler method not found: \" + funcName.value);\n token = handler(token, tape, owner);\n return token;\n };\n\n this.tokenizer.expectToken(tape, TokenType.CLOSE_BRACE);\n return out;\n }\n\n parseDecl(tape: Tape): void {\n const ident = this.tokenizer.expectToken(tape, TokenType.IDENT);\n if (this.tokenizer.consumeIf(tape, TokenType.ARROW, TokenType.COLON)) {\n const nt = this.ensureSymbol(ident.value as string, false);\n if (nt.isTerminal) {\n // it is a terminal so mark it as a non-term now that we\n // know there is a declaration for it.\n nt.isTerminal = false;\n } else if (nt.isAuxiliary) {\n throw new Error(\"NT is already auxiliary and cannot be reused.\");\n }\n for (const [rhs, action] of this.parseProductions(tape, this.grammar, nt)) {\n const rule = this.grammar.add(nt, rhs, action);\n }\n this.tokenizer.expectToken(tape, TokenType.SEMI_COLON);\n }\n }\n\n parseProductions(tape: Tape, grammar: Grammar, nt: TSU.Nullable<Sym>): [Str, RuleAction | null][] {\n const out: [Str, RuleAction | null][] = [];\n while (this.tokenizer.peek(tape) != null) {\n const rule = this.parseProd(tape, grammar);\n out.push(rule);\n if (this.tokenizer.consumeIf(tape, TokenType.PIPE)) {\n continue;\n } else if (this.tokenizer.nextMatches(tape, TokenType.CLOSE_SQ, TokenType.CLOSE_PAREN, TokenType.SEMI_COLON)) {\n break;\n }\n }\n return out;\n }\n\n parseProd(tape: Tape, grammar: Grammar): [Str, null | RuleAction] {\n const out = new Str();\n while (true) {\n // if we are starting with a FOLLOW symbol then return as it marks\n // the end of this production\n if (\n this.tokenizer.nextMatches(\n tape,\n TokenType.CLOSE_PAREN,\n TokenType.CLOSE_SQ,\n TokenType.SEMI_COLON,\n TokenType.PIPE,\n TokenType.OPEN_BRACE,\n )\n ) {\n break;\n // return [out, null];\n }\n\n let curr: TSU.Nullable<Str> = null;\n if (this.tokenizer.consumeIf(tape, TokenType.OPEN_PAREN)) {\n const rules = this.parseProductions(tape, grammar, null);\n if (rules.length == 0) {\n // nothing\n } else if (rules.length == 1) {\n // TODO: Consider actions in non top level rules\n curr = rules[0][0];\n } else {\n // create a new NT over this\n // TODO: Consider actions in non top level rules\n curr = grammar.anyof(...rules.map((r) => r[0]));\n }\n this.tokenizer.expectToken(tape, TokenType.CLOSE_PAREN);\n } else if (this.tokenizer.consumeIf(tape, TokenType.OPEN_SQ)) {\n const rules = this.parseProductions(tape, grammar, null);\n if (rules.length == 0) {\n // nothing\n } else if (rules.length == 1) {\n // TODO: Consider actions in non top level rules\n curr = grammar.opt(rules[0][0]);\n } else {\n // create a new NT over this\n // TODO: Consider actions in non top level rules\n curr = grammar.opt(grammar.anyof(...rules.map((r) => r[0])));\n }\n this.tokenizer.expectToken(tape, TokenType.CLOSE_SQ);\n } else if (\n this.tokenizer.nextMatches(tape, TokenType.IDENT, TokenType.STRING, TokenType.NUMBER, TokenType.REGEX)\n ) {\n const token = this.tokenizer.next(tape) as TLEX.Token;\n let label = token.value as string;\n if (token.tag == TokenType.STRING || token.tag == TokenType.NUMBER) {\n label = `\"${token.value}\"`;\n const pattern = str2regex(token.value);\n const rule = TLEX.Builder.build(pattern, { tag: label, priority: 20 });\n this.generatedTokenizer.addRule(rule);\n } else if (token.tag == TokenType.REGEX) {\n label = \"/\" + token.value[0] + \"/\" + token.value[1];\n let re = token.value[0];\n if (token.value[1].length > 0) {\n // Flags given so create\n re = new RegExp(token.value[0], token.value[1]);\n }\n const rule = TLEX.Builder.build(re, { tag: label, priority: 10 });\n this.generatedTokenizer.addRule(rule);\n } else {\n // Normal\n }\n // See if this symbol is already registered\n const currSym = this.ensureSymbol(label, true);\n curr = new Str(currSym);\n } else {\n throw new TLEX.UnexpectedTokenError(this.tokenizer.peek(tape));\n }\n\n if (curr == null) {\n throw new Error(\"Could not determine node\");\n }\n\n if (this.tokenizer.consumeIf(tape, TokenType.STAR)) {\n curr = grammar.atleast0(curr, this.leftRecursive);\n } else if (this.tokenizer.consumeIf(tape, TokenType.PLUS)) {\n curr = grammar.atleast1(curr, this.leftRecursive);\n } else if (this.tokenizer.consumeIf(tape, TokenType.QMARK)) {\n curr = grammar.opt(curr);\n }\n out.extend(curr);\n }\n let action: RuleAction | null = null;\n if (this.tokenizer.consumeIf(tape, TokenType.OPEN_BRACE)) {\n const next = this.tokenizer.expectToken(tape, TokenType.DOLLAR_NUM, TokenType.IDENT);\n action = new RuleAction(next.value);\n this.tokenizer.expectToken(tape, TokenType.CLOSE_BRACE);\n }\n return [out, action];\n }\n}\n","import * as TSU from \"@panyam/tsutils\";\nimport * as TLEX from \"tlex\";\nimport { Sym, Grammar, Rule } from \"./grammar\";\nimport {\n PTNode,\n SimpleParser as ParserBase,\n BeforeAddingChildCallback,\n RuleReductionCallback,\n NextTokenCallback,\n} from \"./parser\";\nimport { ParseError } from \"./errors\";\n\ntype Nullable<T> = TSU.Nullable<T>;\ntype NumMap<T> = TSU.NumMap<T>;\ntype StringMap<T> = TSU.StringMap<T>;\n\nexport enum LRActionType {\n ACCEPT,\n SHIFT,\n REDUCE,\n GOTO, // can *ONLY* be valid for non-terms\n}\n\nexport class LRAction {\n // Type of action\n tag: LRActionType;\n\n // Next state to go to after performing the action (if valid).\n gotoState: Nullable<number> = null;\n\n // The rule to be used for a reduce action\n rule: Nullable<Rule> = null;\n\n toString(): string {\n if (this.tag == LRActionType.ACCEPT) return \"Acc\";\n else if (this.tag == LRActionType.SHIFT) {\n return \"S\" + this.gotoState!;\n } else if (this.tag == LRActionType.REDUCE) {\n return \"R \" + this.rule!.id;\n } else {\n return \"\" + this.gotoState!;\n }\n }\n\n equals(another: LRAction): boolean {\n return this.tag == another.tag && this.gotoState == another.gotoState && this.rule == another.rule;\n }\n\n static Shift(goto: number): LRAction {\n const out = new LRAction();\n out.tag = LRActionType.SHIFT;\n out.gotoState = goto;\n return out;\n }\n\n static Reduce(rule: Rule): LRAction {\n const out = new LRAction();\n out.tag = LRActionType.REDUCE;\n out.rule = rule;\n return out;\n }\n\n static Goto(gotoState: number): LRAction {\n const out = new LRAction();\n out.tag = LRActionType.GOTO;\n out.gotoState = gotoState;\n return out;\n }\n\n static Accept(): LRAction {\n const out = new LRAction();\n out.tag = LRActionType.ACCEPT;\n return out;\n }\n}\n\n/**\n * A parsing table for LR parsers.\n */\nexport class ParseTable {\n // Records which actions have conflicts\n conflictActions: NumMap<StringMap<boolean>> = {};\n\n /**\n * Maps symbol (by id) to the action;\n */\n actions: NumMap<NumMap<LRAction[]>> = {};\n\n constructor(public readonly grammar: Grammar) {}\n\n get hasConflicts(): boolean {\n return Object.keys(this.conflictActions).length > 0;\n }\n\n /**\n * Gets the action for a given sym from a given state.\n */\n getActions(stateId: number, next: Sym, ensure = false): LRAction[] {\n let l1: NumMap<LRAction[]>;\n if (stateId in this.actions) {\n l1 = this.actions[stateId];\n } else if (ensure) {\n l1 = this.actions[stateId] = {};\n } else {\n return [];\n }\n\n if (next.id in l1) {\n return l1[next.id];\n } else if (ensure) {\n return (l1[next.id] = []);\n }\n return [];\n }\n\n addAction(stateId: number, next: Sym, action: LRAction): this {\n const actions = this.getActions(stateId, next, true);\n if (actions.findIndex((ac) => ac.equals(action)) < 0) {\n actions.push(action);\n }\n if (actions.length > 1) {\n this.conflictActions[stateId] = this.conflictActions[stateId] || {};\n this.conflictActions[stateId][next.label] = true;\n }\n return this;\n }\n\n get debugValue(): any {\n const out: any = {};\n for (const fromId in this.actions) {\n out[fromId] = {};\n for (const symId in this.actions[fromId]) {\n const sym = this.grammar.getSymById(symId as any)!;\n const actions = this.actions[fromId][sym.id] || [];\n if (actions.length > 0) {\n out[fromId][sym.label] = actions.map((a) => a.toString());\n }\n }\n }\n return out;\n }\n}\n\nexport class ParseStack {\n // A way of marking the kind of item that is on the stack\n // true => isStateId\n // false => isSymbolId\n readonly stateStack: number[] = [];\n readonly nodeStack: PTNode[] = [];\n\n push(state: number, node: PTNode): void {\n this.stateStack.push(state);\n this.nodeStack.push(node);\n }\n\n /**\n * Gets the nth item from the top of the stack.\n */\n top(nth = 0): [number, PTNode] {\n return [this.stateStack[this.stateStack.length - 1 - nth], this.nodeStack[this.nodeStack.length - 1 - nth]];\n }\n\n pop(): [number, PTNode] {\n const out = this.top();\n this.stateStack.pop();\n this.nodeStack.pop();\n return out;\n }\n\n /**\n * Pop N items from the stack.\n */\n popN(n = 1): void {\n const L = this.stateStack.length;\n this.stateStack.splice(L - n, n);\n this.nodeStack.splice(L - n, n);\n }\n\n get isEmpty(): boolean {\n return this.stateStack.length == 0 || this.nodeStack.length == 0;\n }\n}\n\nexport type ActionResolverCallback = (\n actions: LRAction[],\n stack: ParseStack,\n tokenbuffer: TLEX.TokenBuffer,\n) => LRAction;\n\nexport type RuleActionHandler = (rule: Rule, parent: PTNode, ...children: PTNode[]) => any;\n\nexport type TokenErrorCallback = (err: TLEX.TokenizerError, input: TLEX.Tape) => boolean;\n\nexport interface ParserContext {\n buildParseTree?: boolean;\n copySingleChild?: boolean;\n ruleHandlers: TSU.StringMap<RuleActionHandler>;\n beforeAddingChildNode?: BeforeAddingChildCallback;\n onReduction?: RuleReductionCallback;\n onNextToken?: NextTokenCallback;\n actionResolver?: ActionResolverCallback;\n onTokenError?: TokenErrorCallback;\n // The owner used for tokenizer to get an insight into the context\n // (to allow context sensitive scanning - aka \"scanner hacks\").\n tokenizerContext: any;\n}\n\nexport class Parser extends ParserBase {\n constructor(\n public readonly parseTable: ParseTable,\n config: any = {},\n ) {\n super();\n }\n\n get grammar(): Grammar {\n return this.parseTable.grammar;\n }\n\n /**\n * Parses the input and returns the resulting root Parse Tree node.\n */\n protected parseInput(input: TLEX.Tape, context?: ParserContext): Nullable<PTNode> {\n context = context || ({} as ParserContext);\n // Set default values for missing values\n this.tokenbuffer.tokenizerContext = context.tokenizerContext;\n if (context.buildParseTree != false) context.buildParseTree = true;\n if (context.copySingleChild != false) context.copySingleChild = true;\n let idCounter = 0;\n const stack = new ParseStack();\n stack.push(0, new PTNode(idCounter++, this.grammar.augStartRule.nt, null));\n const tokenbuffer = this.tokenbuffer;\n const g = this.grammar;\n let output: Nullable<PTNode> = null;\n\n /**\n * Pick an action among several actions based on several factors (eg\n * curr parse stack, tokenbuffer etc).\n */\n function resolveActions(actions: LRAction[]): LRAction {\n if (context?.actionResolver) {\n return context.actionResolver(actions, stack, tokenbuffer);\n } else {\n if (actions.length > 1) {\n throw new Error(\"Multiple actions found.\");\n }\n return actions[0];\n }\n }\n\n function nextToken(): TLEX.Token | null {\n try {\n return tokenbuffer.peek(input);\n } catch (err /* InvalidCharacterException */) {\n if (!context?.onTokenError || !context?.onTokenError(err as TLEX.TokenizerError, input)) {\n // no handler or handler could do nothing so throw it up again\n throw err;\n }\n\n // Handler managed to do \"something\" so retry again\n // TODO - Check offsets were modified?\n return nextToken();\n }\n }\n\n while (true) {\n // while (tokenbuffer.peek(input) != null || !stack.isEmpty) {\n let token = nextToken();\n if (token == null) {\n if (stack.isEmpty) {\n // no more to do\n break;\n }\n } else if (context.onNextToken) {\n token = context.onNextToken(token);\n }\n const nextSym = token == null ? g.Eof : this.getSym(token);\n const nextValue = token == null ? null : token.value;\n let [topState, topNode] = stack.top();\n const actions = this.parseTable.getActions(topState, nextSym);\n if (actions == null || actions.length == 0) {\n // TODO - use a error handler here\n throw new ParseError(`Unexpected Token: '${nextSym.label}'`, \"UnexpectedToken\", {\n state: topState,\n token: token,\n nextSym: nextSym,\n });\n }\n\n const action = resolveActions(actions);\n if (action.tag == LRActionType.ACCEPT) {\n break;\n } else if (action.tag == LRActionType.SHIFT) {\n tokenbuffer.next(input);\n const newNode = new PTNode(idCounter++, nextSym, nextValue);\n stack.push(action.gotoState!, newNode);\n } else {\n // reduce\n TSU.assert(action.rule != null, \"Nonterm and ruleindex must be provided for a reduction action\");\n const ruleLen = action.rule.rhs.length;\n\n // here see if a rule handler exists - if it does use it\n let newNode = new PTNode(idCounter++, action.rule.nt, null);\n // Begin the reduction here. We are breaking the reduction into\n // two parts:\n //\n // 1. Adding child nodes into the parent (reduced) node. Here\n // the beforeAddingChildNode callback is used to modify children\n // being added.\n // 2. After all children have been added to give the caller a chance\n // to handle/post-process the reduction - eg to build the semantic value.\n //\n // Our onReduction is a catch all to perform semantic actions. Instead\n // we could do rule specific ones by using the rule.action (if it exists)\n // and only invoke the onReduction if a rule specific action does not exist.\n //\n // Are these \"double steps\" needed? Can we just build parse tree, filter out\n // child nodes and eval semantic value with a single action?\n //\n // Can semanticHandler do this?\n //\n // eg with\n //\n // E -> E + E { add }\n //\n // we could have our stack looking like;\n //\n // .... s1 E s2 E\n //\n // to be reduced and add could be called with:\n //\n // add(E1, E2) - as the child nodes themselves.\n //\n // the add handler could now do a few things:\n //\n // 1. Ensure all nodes are added to E as is (resulting in 3 nodes - \"E\", \"+\", \"E\")\n // 2. Not add any nodes\n // 3. Computing the value of E and E and the sum of those and put it in the parent E.\n // 4. or all of the above.\n //\n // Doing filtering seems like a very premature usecase. In the case of incremental\n // parsing we may need all nodes to exist and filtering out can get in the way of that.\n //\n // But let us leave it for now and make any semantic handling happen *after* parse tree\n // child node filter/transformation\n if (context.buildParseTree) {\n for (let i = ruleLen - 1; i >= 0; i--) {\n const childNode: TSU.Nullable<PTNode> = stack.top(i)[1];\n if (context.beforeAddingChildNode) {\n for (const node of context.beforeAddingChildNode(newNode, childNode)) {\n newNode.add(node);\n }\n } else if (childNode != null) {\n newNode.add(childNode);\n }\n }\n }\n // Now apply the semantic handler if it exists\n if (action.rule.action) {\n // call it\n if (action.rule.action.isFunction) {\n // find the function associated with\n const handlerName = action.rule.action.value;\n const handler = context.ruleHandlers![handlerName];\n if (!handler) throw new Error(\"Action handler not found: \" + handlerName);\n // TODO - Replace the handler signature to take an\n // interface that returns the nth child node (directly from\n // the parse stack) instead of all children - this way we\n // can even avoid building a parse tree if need be and\n // decouple semantic actions from parse tree building\n newNode.value = handler(action.rule, newNode, ...newNode.children);\n } else {\n // setting value as a child's value, eg $1, $2 etc\n newNode.value = newNode.children[(action.rule.action.value as number) - 1].value;\n }\n } else if (context.onReduction) {\n // fallback to default reduction handler\n newNode = context.onReduction(newNode, action.rule);\n } else if (newNode.children.length == 1 && context.copySingleChild) {\n // If we have only 1 child set the semantic value to be child's value\n // ie values \"bubble up\"\n newNode.value = newNode.children[0].value;\n }\n\n // Perform the action reduction by popping ruleLen number of items off the stack\n // and replace the top with our newNode\n stack.popN(ruleLen);\n [topState, topNode] = stack.top();\n const newAction = resolveActions(this.parseTable.getActions(topState, action.rule.nt));\n TSU.assert(newAction != null && newAction.gotoState != null, \"Top item does not have an action.\");\n stack.push(newAction.gotoState, newNode);\n output = newNode;\n }\n }\n // It is possible that here no reductions have been done!\n return output;\n }\n}\n","import * as TSU from \"@panyam/tsutils\";\nimport * as TLEX from \"tlex\";\nimport { Sym, Grammar, Rule } from \"./grammar\";\n\ntype Nullable<T> = TSU.Nullable<T>;\n\n/**\n * As the parse tree is built, nodes are created and added to parents bottom up.\n * This method is called before a child node is added to its parent. The\n * node's left-most siblings have already been added this point.\n *\n * This method is an opportunity to filter or transfor the node or even adding\n * other nodes to the parent's child list. Note that at this point the parent\n * has *NOT* been added to its parent.\n *\n * In order to filter out the node, return null. Otherwise return a\n * PTNode instance for the actual node to be added to the parent.\n */\nexport type BeforeAddingChildCallback = (parent: PTNode, child: PTNode) => PTNode[];\n\n/**\n * This method is called when after a rule has been reduced. At this time\n * all the children have already been reduced (and called with this method).\n * Now is the opportunity for the parent node reduction to perform custom\n * actions. Note that this method cannot modify the stack. It can only be\n * used to perform things like AST building or logging etc.\n */\nexport type RuleReductionCallback = (node: PTNode, rule: Rule) => PTNode;\n\n/**\n * This method is called as soon as the next token is received from the tokenizer.\n * This allows one to filter out tokens or even transform them based on any other\n * context being maintained.\n */\nexport type NextTokenCallback = (token: TLEX.Token) => TSU.Nullable<TLEX.Token>;\n\nexport class PFNode {\n children: this[] = [];\n constructor(\n public readonly id: number,\n public readonly sym: Sym,\n public value: any,\n ...children: PFNode[]\n ) {\n this.children = (children as this[]) || [];\n }\n\n get childCount(): number {\n return this.children.length;\n }\n\n childAt(index: number): this {\n if (index < 0) return this.children[this.children.length + index] as this;\n return this.children[index] as this;\n }\n\n get isTerminal(): boolean {\n return this.sym.isTerminal;\n }\n\n add(node: this, index = -1): this {\n if (this.isTerminal) {\n throw new Error(`Cannot add children (${node.sym.label}) to a terminal node: ${this.sym.label}`);\n }\n if (index < 0) {\n this.children.push(node);\n } else {\n this.children.splice(index, 0, node);\n }\n return this;\n }\n\n splice(index: number, numToDelete: number, ...nodes: this[]): this {\n this.children.splice(index, numToDelete, ...nodes);\n return this;\n }\n\n get reprString(): string {\n /*\n let out = `Node(${this.sym.label}, {this.value}`;\n if (this.children.length > 0) out += \", \" + this.children.map((c) => c.reprString).join(\", \");\n out += \")\";\n return out;\n */\n return this.debugValue(false).join(\"\\n\");\n }\n\n debugValue(raw = true): any {\n if (raw) {\n const out: any = [this.sym.label];\n if (this.value) out.push(this.value);\n if (this.children.length > 0) out.push(this.children.map((c) => c.debugValue(raw)));\n return out;\n } else {\n const out: any[] = [];\n const value = this.value;\n out.push(this.value == null ? this.sym.label : this.sym.label + \" - \" + this.value);\n this.children.forEach((node) => (node.debugValue(raw) as string[]).forEach((l) => out.push(\" \" + l)));\n return out;\n }\n }\n}\n\nexport class PTNode extends PFNode {\n parent: Nullable<PTNode> = null;\n\n add(node: this, index = -1): this {\n super.add(node, index);\n node.parent = this;\n return this;\n }\n\n splice(index: number, numToDelete: number, ...nodes: this[]): this {\n for (const node of nodes) node.parent = this;\n return super.splice(index, numToDelete, ...nodes);\n }\n}\n\nexport abstract class ParserBase {\n tokenbuffer: TLEX.TokenBuffer;\n\n setTokenizer(tokenizer: TLEX.NextTokenFunc): this {\n this.tokenbuffer = new TLEX.TokenBuffer(tokenizer, null);\n return this;\n }\n\n abstract get grammar(): Grammar;\n\n /**\n * Converts the token to a Terminal based on the tag value.\n */\n getSym(token: TLEX.Token): Sym {\n const out = this.grammar.getSym(token.tag as string);\n if (out == null) {\n throw new Error(\"Invalid token tag: \" + token.tag + \", Value: \" + token.value);\n }\n return out;\n }\n}\n\nexport abstract class SimpleParser extends ParserBase {\n parse(input: string | TLEX.Tape, delegate: any = null): Nullable<PTNode> {\n if (typeof input === \"string\") {\n input = new TLEX.Tape(input);\n }\n return this.parseInput(input, delegate);\n }\n\n /**\n * Parses the input and returns the resulting root Parse Tree node.\n */\n protected abstract parseInput(input: TLEX.Tape, delegate: any): Nullable<PTNode>;\n}\n\nexport abstract class ParallelParser extends ParserBase {\n parse(input: string | TLEX.Tape, delegate: any = null): PFNode[] {\n if (typeof input === \"string\") {\n input = new TLEX.Tape(input);\n }\n return this.parseInput(input, delegate);\n }\n\n /**\n * Parses the input and returns the resulting root Parse Tree node.\n */\n protected abstract parseInput(input: TLEX.Tape, delegate: any): PFNode[];\n}\n","import * as TSU from \"@panyam/tsutils\";\nimport { Sym, Grammar, Rule } from \"./grammar\";\nimport { IDSet } from \"./sets\";\n\ntype Nullable<T> = TSU.Nullable<T>;\ntype NumMap<T> = TSU.NumMap<T>;\n\nexport class LRItem {\n id = 0;\n readonly rule: Rule;\n readonly position: number;\n constructor(rule: Rule, position = 0) {\n this.rule = rule;\n this.position = position;\n }\n\n advance(): LRItem {\n TSU.assert(this.position < this.rule.rhs.length);\n return new LRItem(this.rule, this.position + 1);\n }\n\n copy(): LRItem {\n return new LRItem(this.rule, this.position);\n }\n\n /**\n * TODO - Instead of using strings as keys, can we use a unique ID?\n * If we assume a max limit on number of non terminals in our grammar\n * and a max limit on the number of rules per non terminal and a\n * max limit on the size of each rule then we can uniquely identify\n * a rule and position for a non-terminal by a single (64 bit) number\n *\n * We can use the following bitpacking to nominate this:\n *\n * <padding 16 bits><nt id 16 bits><ruleIndex 16 bits><position 16 bits>\n */\n get key(): string {\n TSU.assert(!isNaN(this.rule.id), \"Rule's ID is not yet set.\");\n return this.rule.id + \":\" + this.position;\n }\n\n compareTo(another: this): number {\n let diff = this.rule.id - another.rule.id;\n if (diff == 0) diff = this.position - another.position;\n return diff;\n }\n\n equals(another: this): boolean {\n return this.compareTo(another) == 0;\n }\n\n get debugString(): string {\n const rule = this.rule;\n const pos = this.position;\n const pre = rule.rhs.syms.slice(0, pos).join(\" \");\n const post = rule.rhs.syms.slice(pos).join(\" \");\n return `${rule.id} - ${rule.nt} -> ${pre} • ${post}`;\n }\n}\n\nexport class LRItemSet {\n id = 0;\n readonly itemGraph: LRItemGraph;\n protected _key: Nullable<string> = null;\n readonly values: number[];\n protected _lookaheads: NumMap<Sym[]> = {};\n protected _hasLookAheads = false;\n\n constructor(ig: LRItemGraph, ...entries: number[]) {\n this.itemGraph = ig;\n this.values = entries;\n }\n\n copy(): LRItemSet {\n const out = new LRItemSet(this.itemGraph, ...this.values);\n out._lookaheads = { ...this._lookaheads };\n out._hasLookAheads = this._hasLookAheads;\n return out;\n }\n\n /**\n * Adds a new look ahead symbol for a given item.\n */\n addLookAhead(item: LRItem, sym: Sym): boolean {\n if (!(item.id in this._lookaheads)) {\n this._lookaheads[item.id] = [];\n }\n for (const s of this._lookaheads[item.id]) if (s == sym) return false;\n this._hasLookAheads = true;\n this._key = null;\n this._lookaheads[item.id].push(sym);\n this._lookaheads[item.id].sort((s1, s2) => s1.id - s2.id);\n return true;\n }\n\n /**\n * Clears all lookaheads from this itemset.\n */\n clearLookAheads(): void {\n this._lookaheads = {};\n }\n\n /**\n * Gets the lookahead symbols for a given item.\n */\n getLookAheads(item: LRItem): ReadonlyArray<Sym> {\n return this._lookaheads[item.id] || [];\n }\n\n // A way to cache the key of this item set.\n // Keys help make the comparison of two sets easy.\n get key(): string {\n if (this._key == null) {\n this._key = this.revalKey();\n }\n return this._key;\n }\n\n protected revalKey(): string {\n if (this.hasLookAheads) {\n this.values.sort();\n return this.values\n .map((itemId) => {\n const la = this._lookaheads[itemId] || [];\n return itemId + \"[\" + la.map((s) => s.id).join(\",\") + \"]\";\n })\n .join(\"/\");\n } else {\n this.values.sort();\n return this.values.join(\"/\");\n }\n }\n\n has(itemId: number): boolean {\n return this.values.indexOf(itemId) >= 0;\n }\n\n equals(another: LRItemSet): boolean {\n return this.key == another.key;\n }\n\n add(itemId: number): this {\n if (!this.has(itemId)) {\n this.values.push(itemId);\n this._key = null;\n }\n return this;\n }\n\n get size(): number {\n return this.values.length;\n }\n\n get debugString(): string {\n return this.debugValue.join(\"\\n\");\n }\n\n get hasLookAheads(): boolean {\n return this._hasLookAheads;\n }\n\n get debugValue(): any {\n if (this.hasLookAheads) {\n const items = this.values.map((v: number) => this.itemGraph.items.get(v));\n // sort them by rule\n items.sort((i1, i2) => i1.compareTo(i2));\n // then append the look aheads\n return items.map((item) => {\n const las = this.getLookAheads(item)\n .map((s) => s.label)\n .sort((s1, s2) => s1.localeCompare(s2))\n .join(\", \");\n return las.length > 0 ? `${item.debugString} / ( ${las} )` : item.debugString;\n });\n } else {\n const items = this.values.map((v: number) => this.itemGraph.items.get(v));\n // sort them by rule\n items.sort((i1, i2) => i1.compareTo(i2));\n return items.map((i) => i.debugString);\n }\n }\n}\n\nexport abstract class LRItemGraph {\n // List of all unique LRItems that can be used in this item graph.\n // Note that since the same Item can reside in multiple sets only\n // one is created via the newItem method and it is referred\n // everwhere it is needed.\n\n /**\n * Using IDed sets of Items and ItemSets.\n * This ensures that only one copy of an item exists\n * \"by value\".\n */\n items: IDSet<LRItem>;\n itemSets: IDSet<LRItemSet>;\n\n // Goto sets for a set and a given transition out of it\n gotoSets: NumMap<NumMap<LRItemSet>> = {};\n\n abstract closure(itemSet: LRItemSet): LRItemSet;\n abstract startSet(): LRItemSet;\n\n constructor(public readonly grammar: Grammar) {\n this.items = new IDSet();\n this.itemSets = new IDSet();\n }\n\n protected startItem(): LRItem {\n const startSymbol = this.grammar.startSymbol;\n TSU.assert(startSymbol != null, \"Start symbol must be set\");\n TSU.assert((this.grammar.augStartRule || null) != null, \"Grammar is not augmented\");\n return this.items.ensure(new LRItem(this.grammar.augStartRule));\n }\n\n reset(): void {\n this.grammar.refresh();\n this.gotoSets = {};\n this.items.clear();\n this.itemSets.clear();\n this.startSet();\n }\n\n refresh(): this {\n this.reset();\n this.grammar.refresh();\n this.evalGotoSets();\n return this;\n }\n\n /**\n * Computes all the goto sets used to create the graph of items.\n */\n protected evalGotoSets(): void {\n const out = this.itemSets;\n for (let i = 0; i < out.size; i++) {\n const currSet = out.get(i);\n // This will also include the null symbol since Grammar\n // adds Null and Eof symbols automatically\n for (const sym of this.grammar.allSymbols) {\n if (sym != this.grammar.Null) {\n const gotoSet = this.goto(currSet, sym);\n if (gotoSet.size > 0) {\n this.setGoto(currSet, sym, gotoSet);\n }\n }\n }\n }\n }\n\n /**\n * Computes the GOTO set of this ItemSet for a particular symbol transitioning\n * out of this item set.\n */\n goto(itemSet: LRItemSet, sym: Sym): LRItemSet {\n const out = this.newItemSet();\n for (const itemId of itemSet.values) {\n const item = this.items.get(itemId);\n // see if item.position points to \"sym\" in its rule\n const rule = item.rule;\n if (item.position < rule.rhs.length) {\n if (rule.rhs.syms[item.position] == sym) {\n // advance the item and add it\n this.advanceItemAndAdd(item, itemSet, out);\n }\n }\n }\n // compute the closure of the new set\n return this.closure(out);\n }\n\n protected advanceItemAndAdd(itemToAdvance: LRItem, fromItemSet: LRItemSet, toItemSet: LRItemSet): void {\n const newItem = this.items.ensure(itemToAdvance.advance());\n toItemSet.add(newItem.id);\n // copy over the look aheads\n for (const laSym of fromItemSet.getLookAheads(itemToAdvance)) {\n toItemSet.addLookAhead(newItem, laSym);\n }\n }\n\n protected newItemSet(...items: LRItem[]): LRItemSet {\n return new LRItemSet(this, ...items.map((item) => item.id));\n }\n\n get size(): number {\n return this.itemSets.size;\n }\n\n protected ensureGotoSet(fromSet: LRItemSet): NumMap<LRItemSet> {\n if (!(fromSet.id in this.gotoSets)) {\n this.gotoSets[fromSet.id] = {};\n }\n return this.gotoSets[fromSet.id];\n }\n\n setGoto(fromSet: LRItemSet, sym: Sym, toSet: LRItemSet): void {\n const entries = this.ensureGotoSet(fromSet);\n entries[sym.id] = toSet;\n }\n\n getGoto(fromSet: LRItemSet, sym: Sym): Nullable<LRItemSet> {\n return (this.gotoSets[fromSet.id] || {})[sym.id] || null;\n }\n\n forEachGoto(itemSet: LRItemSet, visitor: (sym: Sym, nextSet: LRItemSet) => boolean | void): void {\n const gotoSet = this.gotoSets[itemSet.id] || {};\n for (const symid in gotoSet) {\n const sym = this.grammar.getSymById(symid as any) as Sym;\n const next = gotoSet[symid];\n if (visitor(sym, next) == false) break;\n }\n }\n\n gotoSetFor(itemSet: LRItemSet): NumMap<LRItemSet> {\n return this.gotoSets[itemSet.id] || {};\n }\n\n get debugValue(): any {\n const out = {} as any;\n this.itemSets.entries.forEach((iset) => {\n out[iset.id] = { items: [], goto: {} };\n out[iset.id][\"items\"] = iset.debugValue;\n const g = this.gotoSets[iset.id];\n for (const symid in g) {\n const sym = this.grammar.getSymById(symid as any)!;\n out[iset.id][\"goto\"] = out[iset.id][\"goto\"] || {};\n out[iset.id][\"goto\"][sym.label] = g[symid].id;\n }\n });\n return out;\n }\n}\n\nexport class LR0ItemGraph extends LRItemGraph {\n /**\n * Creates the set for the grammar. This is done by creating an\n * augmented rule of the form S' -> S (where S is the start symbol of\n * the grammar) and creating the closure of this starting rule, ie:\n *\n * StartSet = closure({S' -> . S})\n */\n startSet(): LRItemSet {\n const startItem = this.startItem();\n const newset = this.newItemSet(startItem);\n return this.closure(newset);\n }\n\n /**\n * Computes the closure of a given item set and returns a new\n * item set.\n */\n closure(itemSet: LRItemSet): LRItemSet {\n const out = new LRItemSet(this, ...itemSet.values);\n for (let i = 0; i < out.values.length; i++) {\n const itemId = out.values[i];\n const item = this.items.get(itemId)!;\n const rule = item.rule;\n // Evaluate the closure\n // Cannot do anything past the end\n if (item.position < rule.rhs.length) {\n const sym = rule.rhs.syms[item.position];\n if (!sym.isTerminal) {\n for (const rule of this.grammar.rulesForNT(sym)) {\n const newItem = this.items.ensure(new LRItem(rule, 0));\n out.add(newItem.id);\n }\n }\n }\n }\n return out.size == 0 ? out : this.itemSets.ensure(out);\n }\n}\n\nexport class LR1ItemGraph extends LRItemGraph {\n /**\n * Overridden to include the EOF marker as the lookahead for the start state\n *\n * StartSet = closure({S' -> . S, $})\n */\n startSet(): LRItemSet {\n const startItem = this.startItem();\n const newset = this.newItemSet(startItem);\n newset.addLookAhead(startItem, this.grammar.Eof);\n return this.closure(newset);\n }\n\n /**\n * Computes the closure of this item set and returns a new\n * item set.\n */\n closure(itemSet: LRItemSet): LRItemSet {\n const out = itemSet.copy();\n for (let i = 0; i < out.values.length; i++) {\n const itemId = out.values[i];\n const item = this.items.get(itemId) as LRItem;\n // Evaluate the closure\n // Cannot do anything past the end\n if (item.position >= item.rule.rhs.length) continue;\n const rhs = item.rule.rhs;\n const B = rhs.syms[item.position];\n if (B.isTerminal) continue;\n\n for (const lookahead of out.getLookAheads(item)) {\n const suffix = rhs.copy().append(lookahead);\n this.grammar.firstSets.forEachTermIn(suffix, item.position + 1, (term) => {\n if (term != null) {\n // For each rule [ B -> beta, term ] add it to\n // our list of items if it doesnt already exist\n const bRules = this.grammar.rulesForNT(B);\n for (const br of bRules) {\n const newItem = this.items.ensure(new LRItem(br, 0));\n out.add(newItem.id);\n out.addLookAhead(newItem, term);\n }\n }\n });\n }\n }\n return out.size == 0 ? out : this.itemSets.ensure(out);\n }\n}\n","import * as TSU from \"@panyam/tsutils\";\nimport { Grammar, Str, Sym, Rule } from \"./grammar\";\nimport { LRAction, ParseTable } from \"./lr\";\nimport { LRItem, LRItemSet, LRItemGraph, LR0ItemGraph, LR1ItemGraph } from \"./lritems\";\nimport { Goto } from \"./tests/utils\";\n\nexport function makeParseTable(g: Grammar, type = \"lr1\"): [ParseTable, LRItemGraph] {\n switch (type) {\n case \"lr1\":\n return makeLRParseTable(g);\n case \"lalr\":\n return makeLALRParseTable(g);\n }\n return makeSLRParseTable(g);\n}\n\n/**\n * A SLR parse table maker.\n */\nexport function makeSLRParseTable(grammar: Grammar): [ParseTable, LRItemGraph] {\n const ig = makeSLRAutomaton(grammar);\n return [makeParseTableFromLA(ig, grammar), ig];\n}\n\nexport function makeSLRAutomaton(grammar: Grammar): LRItemGraph {\n const ig = new LR0ItemGraph(grammar).refresh();\n for (const itemSet of ig.itemSets.entries) {\n evalLASetsForSLRItem(grammar, ig, itemSet);\n }\n return ig;\n}\n\n/**\n * For a given LR(0) Item in the LR0 automaton evaluates the lookahead set\n * for an SLR1 parse table.\n *\n * The SLR lookahead is:\n *\n * SLRLA(q, A -> w) = Follow(A)\n *\n * @param grammar\n * @param ig\n * @param itemSet\n */\nexport function evalLASetsForSLRItem(grammar: Grammar, ig: LRItemGraph, itemSet: LRItemSet): void {\n // Look for transitions from this set\n for (const itemId of itemSet.values) {\n const item = ig.items.get(itemId);\n const rule = item.rule;\n if (item.position >= rule.rhs.length) {\n // if sym is in follows(nt) then add the rule\n // Reduce nt -> rule for all sym in follows(nt)\n grammar.followSets.forEachTerm(rule.nt, (term) => {\n if (term != null) {\n TSU.assert(term.isTerminal);\n itemSet.addLookAhead(item, term);\n }\n });\n }\n }\n}\n\n/**\n * A canonical LR1 parse table maker.\n */\nexport function makeLRParseTable(grammar: Grammar): [ParseTable, LRItemGraph] {\n const ig = new LR1ItemGraph(grammar).refresh();\n const parseTable = makeParseTableFromLA(ig, grammar);\n return [parseTable, ig];\n}\n\n/**\n * A LALR(1) parse table maker using Bermudez and Logothetis' (1989)\n * \"Simple computation of LALR(1) lookahead sets\" method.\n */\nexport function makeLALRParseTable(grammar: Grammar): [ParseTable, LRItemGraph] {\n // const [parseTable, ig] = makeSLRParseTable(grammar);\n const [parseTable, ig] = makeSLRParseTable(grammar);\n\n if (!parseTable.hasConflicts) {\n return [parseTable, ig];\n }\n\n // This is a really simple method compared to DeRemer and Penello's method\n // (based on relations).\n //\n // 1. First transform the grammar G into G' that is based on around the LR0\n // item graph\n const g2 = grammarFromLR0ItemGraph(ig, grammar);\n\n // Reverse of goto sets in the LR automaton to track predecessor states.\n const prevSets: TSU.NumMap<TSU.NumMap<Set<number>>> = {};\n\n for (const startState in ig.gotoSets) {\n for (const symId in ig.gotoSets[startState]) {\n const nextSet = ig.gotoSets[startState][symId];\n if (!(nextSet.id in prevSets)) {\n prevSets[nextSet.id] = {};\n }\n if (!(symId in prevSets[nextSet.id])) {\n prevSets[nextSet.id][symId] = new Set();\n }\n prevSets[nextSet.id][symId].add(startState as any as number);\n }\n }\n\n // For conflict states upgrade lookahead sets based on union of follow\n // sets of G2 for the corresponding sets\n // LALRLA(q, A -> w) =\n for (const startState in parseTable.conflictActions) {\n // So here we have a startState where a symbol was extraneously added\n // into the look ahead set. So here recompute the lookahead set\n // for this state\n const itemSet = ig.itemSets.get(startState as any as number);\n evalLASetsForLALRItem(grammar, g2, ig, itemSet, prevSets);\n }\n\n // Now that all look aheads have been recomputed - recreate\n // the parse table\n return [makeParseTableFromLA(ig, grammar), ig];\n}\n\n/**\n * Shared parse table creator for SLR/LR/LALR grammars that have lookahead\n * in the LR0 automaton.\n */\nexport function makeParseTableFromLA(ig: LRItemGraph, grammar: Grammar): ParseTable {\n const parseTable = new ParseTable(grammar);\n for (const itemSet of ig.itemSets.entries) {\n // Look for transitions from this set\n for (const itemId of itemSet.values) {\n const item = ig.items.get(itemId);\n const rule = item.rule;\n if (item.position < rule.rhs.length) {\n // possibilities of shift\n const sym = rule.rhs.syms[item.position];\n if (sym.isTerminal) {\n const nextSet = ig.getGoto(itemSet, sym);\n if (nextSet) {\n parseTable.addAction(itemSet.id, sym, LRAction.Shift(nextSet.id));\n }\n }\n } else if (!rule.nt.equals(grammar.augStartRule.nt)) {\n // We have nt -> rule DOT / t\n // AND nt != S'\n // Reduce nt -> rule for t\n const lookaheads = itemSet.getLookAheads(item);\n for (const lookahead of lookaheads) {\n parseTable.addAction(itemSet.id, lookahead, LRAction.Reduce(rule));\n }\n }\n }\n\n // Now create GOTO entries for (State,X) where X is a non-term\n ig.forEachGoto(itemSet, (sym, next) => {\n if (sym != null && !sym.isTerminal) {\n parseTable.addAction(itemSet.id, sym, LRAction.Goto(next.id));\n }\n });\n\n // If this state contains the augmented item, S' -> S . / $\n // then add accept\n const lr1Item = ig.items.ensure(new LRItem(grammar.augStartRule, 1));\n itemSet.addLookAhead(lr1Item, grammar.Eof);\n if (itemSet.has(lr1Item.id)) {\n parseTable.addAction(itemSet.id, grammar.Eof, LRAction.Accept());\n }\n }\n return parseTable;\n}\n\n/**\n * For a given LR(0) Item in the LR0 automaton evaluates the lookahead set\n * for an LALR1 parse table.\n *\n * The LALR lookahead is:\n *\n * LALRLA(q, A -> w) = {t | [r:t] in Follow[p: A], Go[p: w] = q }\n *\n * Here [r: t] refers to a state in the augmented grammar transformed from the original\n * grammar where the nonterminals and terminals are based on the transitions in the\n * LR(0) automaton. This augmented grammar is also passed in as a parameter.\n *\n * @param grammar - Original grammar\n * @param augGrammar - Augmented grammar\n * @param ig - LR0 Automaton\n * @param itemSet - The item set in the automaton (ie a particular state)\n * for which lookahead sets are to be computed.\n * @param prevSets - A mapping where prevSets[stateI][symId] is a list of\n * states X1,X2...Xn where where the transition\n * X1[symId] = stateI, X2[symId] = stateI ...\n * Xn[symId] = stateI\n */\nexport function evalLASetsForLALRItem(\n grammar: Grammar,\n augGrammar: Grammar,\n ig: LRItemGraph,\n itemSet: LRItemSet,\n prevSets: TSU.NumMap<TSU.NumMap<Set<number>>>,\n): void {\n // find p going backwards from q spelling w\n function findP(rule: Rule, i: number, currState: number, states: Set<number>): void {\n if (i < 0) {\n // we have reached the end - currState is P\n // Ensure there is a transition from currState on rule.nt\n const transitions: TSU.NumMap<LRItemSet> = ig.gotoSets[currState];\n TSU.assert((transitions[rule.nt.id] || null) != null, \"Transition on rule.nt missing from start state\");\n states.add(currState);\n } else {\n const sym = rule.rhs.syms[i];\n const prevStates = prevSets[currState][sym.id] || null;\n TSU.assert(prevStates != null, \"Prev set should not be null\");\n prevStates.forEach((nextState) => findP(rule, i - 1, nextState, states));\n }\n }\n\n itemSet.clearLookAheads();\n // Look for transitions from this set\n for (const itemId of itemSet.values) {\n const item = ig.items.get(itemId);\n const rule = item.rule;\n if (item.position >= rule.rhs.length) {\n // Here we have rule of the form A -> w in state q\n //\n // For this state we compute LALR lookaheads as:\n //\n // LALRLA(q, A -> w) = {t | [r:t] in Follow[p: A], Go[p: w] = q }\n const pSet = new Set<number>();\n findP(rule, rule.rhs.length - 1, itemSet.id, pSet);\n pSet.forEach((p) => {\n // Now find the NT [p: A] in the augmented grammar\n const pALabel = `[${p}:${rule.nt.label}]`;\n const pA = augGrammar.getSym(pALabel);\n TSU.assert(pA != null, \"Augmented grammar symbol [p:A] not found\");\n augGrammar.followSets.forEachTerm(pA, (term) => {\n if (term != null && term != augGrammar.Eof) {\n TSU.assert(term.isTerminal);\n // This term is in the form [r: T] in the augmented grammar.\n // Get the T from this and add to the look ahead set\n const label = term.label.substring(term.label.indexOf(\":\") + 1, term.label.length - 1).trim();\n const T = grammar.getSym(label);\n TSU.assert(T != null, `T (${label}) in [r:T] cannot be null`);\n itemSet.addLookAhead(item, T);\n }\n });\n });\n }\n }\n}\n\n/**\n * For a grammar G and its LR0 ItemGraph, IG, returns a transformed grammar G'\n * that is based along the transitions of IG.\n *\n * For this new Grammar G' we have:\n *\n * NonTerminals N' = { [p: A] | if Go[p: A] is defined },\n * Terminals T' = { [p: t] | if Go[p: t] is defined },\n * Start Symbol S' = [ Start : S ]\n * Productions P' = { [p1 : A ] -> [p1 : X1][p2 : X2]...[pn : Xn], if\n * [p1 : A] is in N' AND\n * [pi : Xi] is in N' U T' AND\n * A -> X1 X2 .. An is in P (of original grammar G)\n */\nexport function grammarFromLR0ItemGraph(ig: LR0ItemGraph, g: Grammar): Grammar {\n const g2 = new Grammar();\n\n function ensureG2Sym(pi: number, sym: Sym): Sym {\n const newSymLabel = `[${pi}:${sym.label}]`;\n const newSym = g2.ensureSym(new Sym(g2, newSymLabel, sym.isTerminal), false);\n if (pi == 0 && g.startSymbol == sym && g.startSymbol != newSym && !sym.isTerminal) {\n g2.startSymbol = newSym;\n }\n return newSym;\n }\n\n // Create N', T' and S'\n for (const startState in ig.gotoSets) {\n // transitions is a Map of symId -> ItemSet\n const transitions: TSU.NumMap<LRItemSet> = ig.gotoSets[startState];\n for (const symId in transitions) {\n const sym = g.getSymById(symId as any as number)!;\n ensureG2Sym(startState as any as number, sym);\n }\n }\n\n function buildRuleFrom(startSet: number, A: Sym, rule: Rule): Str {\n // Str to be built up for the production in the transformed grammar\n // - [P1:X1][P2:X2]...[Pn:Xn]\n let pi = startSet;\n const newSyms = rule.rhs.syms.map((xi, index) => {\n const nextSym = ensureG2Sym(pi, xi);\n const transitions: TSU.NumMap<LRItemSet> = ig.gotoSets[pi];\n const nextSet = transitions[xi.id] || null;\n TSU.assert(nextSet != null, \"Next set transition *must* be valid\");\n pi = nextSet.id;\n return nextSym;\n });\n return new Str(...newSyms);\n }\n\n for (const startState in ig.gotoSets) {\n // from P1 - for every transition that is a non terminal A\n // find an equivalent chain of transition starting from P1 where we have\n // [P1:X1][P2:X2]...[Pn:Xn]\n // for All A -> X1X2...Xn in G\n const transitions: TSU.NumMap<LRItemSet> = ig.gotoSets[startState];\n for (const symId in transitions) {\n const startSym = g.getSymById(symId as any as number)!;\n const p1 = startState as any as number;\n if (!startSym.isTerminal) {\n const newA = ensureG2Sym(p1, startSym);\n g.forEachRule(startSym, (rule, index) => {\n const newRHS = buildRuleFrom(p1, startSym, rule);\n const newRule = new Rule(newA, newRHS);\n g2.addRule(newRule);\n });\n }\n }\n }\n // Do another pass to evaluate P'\n return g2;\n}\n","const ALIAS = Symbol.for('yaml.alias');\nconst DOC = Symbol.for('yaml.document');\nconst MAP = Symbol.for('yaml.map');\nconst PAIR = Symbol.for('yaml.pair');\nconst SCALAR = Symbol.for('yaml.scalar');\nconst SEQ = Symbol.for('yaml.seq');\nconst NODE_TYPE = Symbol.for('yaml.node.type');\nconst isAlias = (node) => !!node && typeof node === 'object' && node[NODE_TYPE] === ALIAS;\nconst isDocument = (node) => !!node && typeof node === 'object' && node[NODE_TYPE] === DOC;\nconst isMap = (node) => !!node && typeof node === 'object' && node[NODE_TYPE] === MAP;\nconst isPair = (node) => !!node && typeof node === 'object' && node[NODE_TYPE] === PAIR;\nconst isScalar = (node) => !!node && typeof node === 'object' && node[NODE_TYPE] === SCALAR;\nconst isSeq = (node) => !!node && typeof node === 'object' && node[NODE_TYPE] === SEQ;\nfunction isCollection(node) {\n if (node && typeof node === 'object')\n switch (node[NODE_TYPE]) {\n case MAP:\n case SEQ:\n return true;\n }\n return false;\n}\nfunction isNode(node) {\n if (node && typeof node === 'object')\n switch (node[NODE_TYPE]) {\n case ALIAS:\n case MAP:\n case SCALAR:\n case SEQ:\n return true;\n }\n return false;\n}\nconst hasAnchor = (node) => (isScalar(node) || isCollection(node)) && !!node.anchor;\n\nexport { ALIAS, DOC, MAP, NODE_TYPE, PAIR, SCALAR, SEQ, hasAnchor, isAlias, isCollection, isDocument, isMap, isNode, isPair, isScalar, isSeq };\n","import { isDocument, isNode, isPair, isCollection, isMap, isSeq, isScalar, isAlias } from './nodes/identity.js';\n\nconst BREAK = Symbol('break visit');\nconst SKIP = Symbol('skip children');\nconst REMOVE = Symbol('remove node');\n/**\n * Apply a visitor to an AST node or document.\n *\n * Walks through the tree (depth-first) starting from `node`, calling a\n * `visitor` function with three arguments:\n * - `key`: For sequence values and map `Pair`, the node's index in the\n * collection. Within a `Pair`, `'key'` or `'value'`, correspondingly.\n * `null` for the root node.\n * - `node`: The current node.\n * - `path`: The ancestry of the current node.\n *\n * The return value of the visitor may be used to control the traversal:\n * - `undefined` (default): Do nothing and continue\n * - `visit.SKIP`: Do not visit the children of this node, continue with next\n * sibling\n * - `visit.BREAK`: Terminate traversal completely\n * - `visit.REMOVE`: Remove the current node, then continue with the next one\n * - `Node`: Replace the current node, then continue by visiting it\n * - `number`: While iterating the items of a sequence or map, set the index\n * of the next step. This is useful especially if the index of the current\n * node has changed.\n *\n * If `visitor` is a single function, it will be called with all values\n * encountered in the tree, including e.g. `null` values. Alternatively,\n * separate visitor functions may be defined for each `Map`, `Pair`, `Seq`,\n * `Alias` and `Scalar` node. To define the same visitor function for more than\n * one node type, use the `Collection` (map and seq), `Value` (map, seq & scalar)\n * and `Node` (alias, map, seq & scalar) targets. Of all these, only the most\n * specific defined one will be used for each node.\n */\nfunction visit(node, visitor) {\n const visitor_ = initVisitor(visitor);\n if (isDocument(node)) {\n const cd = visit_(null, node.contents, visitor_, Object.freeze([node]));\n if (cd === REMOVE)\n node.contents = null;\n }\n else\n visit_(null, node, visitor_, Object.freeze([]));\n}\n// Without the `as symbol` casts, TS declares these in the `visit`\n// namespace using `var`, but then complains about that because\n// `unique symbol` must be `const`.\n/** Terminate visit traversal completely */\nvisit.BREAK = BREAK;\n/** Do not visit the children of the current node */\nvisit.SKIP = SKIP;\n/** Remove the current node */\nvisit.REMOVE = REMOVE;\nfunction visit_(key, node, visitor, path) {\n const ctrl = callVisitor(key, node, visitor, path);\n if (isNode(ctrl) || isPair(ctrl)) {\n replaceNode(key, path, ctrl);\n return visit_(key, ctrl, visitor, path);\n }\n if (typeof ctrl !== 'symbol') {\n if (isCollection(node)) {\n path = Object.freeze(path.concat(node));\n for (let i = 0; i < node.items.length; ++i) {\n const ci = visit_(i, node.items[i], visitor, path);\n if (typeof ci === 'number')\n i = ci - 1;\n else if (ci === BREAK)\n return BREAK;\n else if (ci === REMOVE) {\n node.items.splice(i, 1);\n i -= 1;\n }\n }\n }\n else if (isPair(node)) {\n path = Object.freeze(path.concat(node));\n const ck = visit_('key', node.key, visitor, path);\n if (ck === BREAK)\n return BREAK;\n else if (ck === REMOVE)\n node.key = null;\n const cv = visit_('value', node.value, visitor, path);\n if (cv === BREAK)\n return BREAK;\n else if (cv === REMOVE)\n node.value = null;\n }\n }\n return ctrl;\n}\n/**\n * Apply an async visitor to an AST node or document.\n *\n * Walks through the tree (depth-first) starting from `node`, calling a\n * `visitor` function with three arguments:\n * - `key`: For sequence values and map `Pair`, the node's index in the\n * collection. Within a `Pair`, `'key'` or `'value'`, correspondingly.\n * `null` for the root node.\n * - `node`: The current node.\n * - `path`: The ancestry of the current node.\n *\n * The return value of the visitor may be used to control the traversal:\n * - `Promise`: Must resolve to one of the following values\n * - `undefined` (default): Do nothing and continue\n * - `visit.SKIP`: Do not visit the children of this node, continue with next\n * sibling\n * - `visit.BREAK`: Terminate traversal completely\n * - `visit.REMOVE`: Remove the current node, then continue with the next one\n * - `Node`: Replace the current node, then continue by visiting it\n * - `number`: While iterating the items of a sequence or map, set the index\n * of the next step. This is useful especially if the index of the current\n * node has changed.\n *\n * If `visitor` is a single function, it will be called with all values\n * encountered in the tree, including e.g. `null` values. Alternatively,\n * separate visitor functions may be defined for each `Map`, `Pair`, `Seq`,\n * `Alias` and `Scalar` node. To define the same visitor function for more than\n * one node type, use the `Collection` (map and seq), `Value` (map, seq & scalar)\n * and `Node` (alias, map, seq & scalar) targets. Of all these, only the most\n * specific defined one will be used for each node.\n */\nasync function visitAsync(node, visitor) {\n const visitor_ = initVisitor(visitor);\n if (isDocument(node)) {\n const cd = await visitAsync_(null, node.contents, visitor_, Object.freeze([node]));\n if (cd === REMOVE)\n node.contents = null;\n }\n else\n await visitAsync_(null, node, visitor_, Object.freeze([]));\n}\n// Without the `as symbol` casts, TS declares these in the `visit`\n// namespace using `var`, but then complains about that because\n// `unique symbol` must be `const`.\n/** Terminate visit traversal completely */\nvisitAsync.BREAK = BREAK;\n/** Do not visit the children of the current node */\nvisitAsync.SKIP = SKIP;\n/** Remove the current node */\nvisitAsync.REMOVE = REMOVE;\nasync function visitAsync_(key, node, visitor, path) {\n const ctrl = await callVisitor(key, node, visitor, path);\n if (isNode(ctrl) || isPair(ctrl)) {\n replaceNode(key, path, ctrl);\n return visitAsync_(key, ctrl, visitor, path);\n }\n if (typeof ctrl !== 'symbol') {\n if (isCollection(node)) {\n path = Object.freeze(path.concat(node));\n for (let i = 0; i < node.items.length; ++i) {\n const ci = await visitAsync_(i, node.items[i], visitor, path);\n if (typeof ci === 'number')\n i = ci - 1;\n else if (ci === BREAK)\n return BREAK;\n else if (ci === REMOVE) {\n node.items.splice(i, 1);\n i -= 1;\n }\n }\n }\n else if (isPair(node)) {\n path = Object.freeze(path.concat(node));\n const ck = await visitAsync_('key', node.key, visitor, path);\n if (ck === BREAK)\n return BREAK;\n else if (ck === REMOVE)\n node.key = null;\n const cv = await visitAsync_('value', node.value, visitor, path);\n if (cv === BREAK)\n return BREAK;\n else if (cv === REMOVE)\n node.value = null;\n }\n }\n return ctrl;\n}\nfunction initVisitor(visitor) {\n if (typeof visitor === 'object' &&\n (visitor.Collection || visitor.Node || visitor.Value)) {\n return Object.assign({\n Alias: visitor.Node,\n Map: visitor.Node,\n Scalar: visitor.Node,\n Seq: visitor.Node\n }, visitor.Value && {\n Map: visitor.Value,\n Scalar: visitor.Value,\n Seq: visitor.Value\n }, visitor.Collection && {\n Map: visitor.Collection,\n Seq: visitor.Collection\n }, visitor);\n }\n return visitor;\n}\nfunction callVisitor(key, node, visitor, path) {\n if (typeof visitor === 'function')\n return visitor(key, node, path);\n if (isMap(node))\n return visitor.Map?.(key, node, path);\n if (isSeq(node))\n return visitor.Seq?.(key, node, path);\n if (isPair(node))\n return visitor.Pair?.(key, node, path);\n if (isScalar(node))\n return visitor.Scalar?.(key, node, path);\n if (isAlias(node))\n return visitor.Alias?.(key, node, path);\n return undefined;\n}\nfunction replaceNode(key, path, node) {\n const parent = path[path.length - 1];\n if (isCollection(parent)) {\n parent.items[key] = node;\n }\n else if (isPair(parent)) {\n if (key === 'key')\n parent.key = node;\n else\n parent.value = node;\n }\n else if (isDocument(parent)) {\n parent.contents = node;\n }\n else {\n const pt = isAlias(parent) ? 'alias' : 'scalar';\n throw new Error(`Cannot replace node with ${pt} parent`);\n }\n}\n\nexport { visit, visitAsync };\n","import { isNode } from '../nodes/identity.js';\nimport { visit } from '../visit.js';\n\nconst escapeChars = {\n '!': '%21',\n ',': '%2C',\n '[': '%5B',\n ']': '%5D',\n '{': '%7B',\n '}': '%7D'\n};\nconst escapeTagName = (tn) => tn.replace(/[!,[\\]{}]/g, ch => escapeChars[ch]);\nclass Directives {\n constructor(yaml, tags) {\n /**\n * The directives-end/doc-start marker `---`. If `null`, a marker may still be\n * included in the document's stringified representation.\n */\n this.docStart = null;\n /** The doc-end marker `...`. */\n this.docEnd = false;\n this.yaml = Object.assign({}, Directives.defaultYaml, yaml);\n this.tags = Object.assign({}, Directives.defaultTags, tags);\n }\n clone() {\n const copy = new Directives(this.yaml, this.tags);\n copy.docStart = this.docStart;\n return copy;\n }\n /**\n * During parsing, get a Directives instance for the current document and\n * update the stream state according to the current version's spec.\n */\n atDocument() {\n const res = new Directives(this.yaml, this.tags);\n switch (this.yaml.version) {\n case '1.1':\n this.atNextDocument = true;\n break;\n case '1.2':\n this.atNextDocument = false;\n this.yaml = {\n explicit: Directives.defaultYaml.explicit,\n version: '1.2'\n };\n this.tags = Object.assign({}, Directives.defaultTags);\n break;\n }\n return res;\n }\n /**\n * @param onError - May be called even if the action was successful\n * @returns `true` on success\n */\n add(line, onError) {\n if (this.atNextDocument) {\n this.yaml = { explicit: Directives.defaultYaml.explicit, version: '1.1' };\n this.tags = Object.assign({}, Directives.defaultTags);\n this.atNextDocument = false;\n }\n const parts = line.trim().split(/[ \\t]+/);\n const name = parts.shift();\n switch (name) {\n case '%TAG': {\n if (parts.length !== 2) {\n onError(0, '%TAG directive should contain exactly two parts');\n if (parts.length < 2)\n return false;\n }\n const [handle, prefix] = parts;\n this.tags[handle] = prefix;\n return true;\n }\n case '%YAML': {\n this.yaml.explicit = true;\n if (parts.length !== 1) {\n onError(0, '%YAML directive should contain exactly one part');\n return false;\n }\n const [version] = parts;\n if (version === '1.1' || version === '1.2') {\n this.yaml.version = version;\n return true;\n }\n else {\n const isValid = /^\\d+\\.\\d+$/.test(version);\n onError(6, `Unsupported YAML version ${version}`, isValid);\n return false;\n }\n }\n default:\n onError(0, `Unknown directive ${name}`, true);\n return false;\n }\n }\n /**\n * Resolves a tag, matching handles to those defined in %TAG directives.\n *\n * @returns Resolved tag, which may also be the non-specific tag `'!'` or a\n * `'!local'` tag, or `null` if unresolvable.\n */\n tagName(source, onError) {\n if (source === '!')\n return '!'; // non-specific tag\n if (source[0] !== '!') {\n onError(`Not a valid tag: ${source}`);\n return null;\n }\n if (source[1] === '<') {\n const verbatim = source.slice(2, -1);\n if (verbatim === '!' || verbatim === '!!') {\n onError(`Verbatim tags aren't resolved, so ${source} is invalid.`);\n return null;\n }\n if (source[source.length - 1] !== '>')\n onError('Verbatim tags must end with a >');\n return verbatim;\n }\n const [, handle, suffix] = source.match(/^(.*!)([^!]*)$/s);\n if (!suffix)\n onError(`The ${source} tag has no suffix`);\n const prefix = this.tags[handle];\n if (prefix) {\n try {\n return prefix + decodeURIComponent(suffix);\n }\n catch (error) {\n onError(String(error));\n return null;\n }\n }\n if (handle === '!')\n return source; // local tag\n onError(`Could not resolve tag: ${source}`);\n return null;\n }\n /**\n * Given a fully resolved tag, returns its printable string form,\n * taking into account current tag prefixes and defaults.\n */\n tagString(tag) {\n for (const [handle, prefix] of Object.entries(this.tags)) {\n if (tag.startsWith(prefix))\n return handle + escapeTagName(tag.substring(prefix.length));\n }\n return tag[0] === '!' ? tag : `!<${tag}>`;\n }\n toString(doc) {\n const lines = this.yaml.explicit\n ? [`%YAML ${this.yaml.version || '1.2'}`]\n : [];\n const tagEntries = Object.entries(this.tags);\n let tagNames;\n if (doc && tagEntries.length > 0 && isNode(doc.contents)) {\n const tags = {};\n visit(doc.contents, (_key, node) => {\n if (isNode(node) && node.tag)\n tags[node.tag] = true;\n });\n tagNames = Object.keys(tags);\n }\n else\n tagNames = [];\n for (const [handle, prefix] of tagEntries) {\n if (handle === '!!' && prefix === 'tag:yaml.org,2002:')\n continue;\n if (!doc || tagNames.some(tn => tn.startsWith(prefix)))\n lines.push(`%TAG ${handle} ${prefix}`);\n }\n return lines.join('\\n');\n }\n}\nDirectives.defaultYaml = { explicit: false, version: '1.2' };\nDirectives.defaultTags = { '!!': 'tag:yaml.org,2002:' };\n\nexport { Directives };\n","import { isScalar, isCollection } from '../nodes/identity.js';\nimport { visit } from '../visit.js';\n\n/**\n * Verify that the input string is a valid anchor.\n *\n * Will throw on errors.\n */\nfunction anchorIsValid(anchor) {\n if (/[\\x00-\\x19\\s,[\\]{}]/.test(anchor)) {\n const sa = JSON.stringify(anchor);\n const msg = `Anchor must not contain whitespace or control characters: ${sa}`;\n throw new Error(msg);\n }\n return true;\n}\nfunction anchorNames(root) {\n const anchors = new Set();\n visit(root, {\n Value(_key, node) {\n if (node.anchor)\n anchors.add(node.anchor);\n }\n });\n return anchors;\n}\n/** Find a new anchor name with the given `prefix` and a one-indexed suffix. */\nfunction findNewAnchor(prefix, exclude) {\n for (let i = 1; true; ++i) {\n const name = `${prefix}${i}`;\n if (!exclude.has(name))\n return name;\n }\n}\nfunction createNodeAnchors(doc, prefix) {\n const aliasObjects = [];\n const sourceObjects = new Map();\n let prevAnchors = null;\n return {\n onAnchor: (source) => {\n aliasObjects.push(source);\n prevAnchors ?? (prevAnchors = anchorNames(doc));\n const anchor = findNewAnchor(prefix, prevAnchors);\n prevAnchors.add(anchor);\n return anchor;\n },\n /**\n * With circular references, the source node is only resolved after all\n * of its child nodes are. This is why anchors are set only after all of\n * the nodes have been created.\n */\n setAnchors: () => {\n for (const source of aliasObjects) {\n const ref = sourceObjects.get(source);\n if (typeof ref === 'object' &&\n ref.anchor &&\n (isScalar(ref.node) || isCollection(ref.node))) {\n ref.node.anchor = ref.anchor;\n }\n else {\n const error = new Error('Failed to resolve repeated object (this should not happen)');\n error.source = source;\n throw error;\n }\n }\n },\n sourceObjects\n };\n}\n\nexport { anchorIsValid, anchorNames, createNodeAnchors, findNewAnchor };\n","/**\n * Applies the JSON.parse reviver algorithm as defined in the ECMA-262 spec,\n * in section 24.5.1.1 \"Runtime Semantics: InternalizeJSONProperty\" of the\n * 2021 edition: https://tc39.es/ecma262/#sec-json.parse\n *\n * Includes extensions for handling Map and Set objects.\n */\nfunction applyReviver(reviver, obj, key, val) {\n if (val && typeof val === 'object') {\n if (Array.isArray(val)) {\n for (let i = 0, len = val.length; i < len; ++i) {\n const v0 = val[i];\n const v1 = applyReviver(reviver, val, String(i), v0);\n // eslint-disable-next-line @typescript-eslint/no-array-delete\n if (v1 === undefined)\n delete val[i];\n else if (v1 !== v0)\n val[i] = v1;\n }\n }\n else if (val instanceof Map) {\n for (const k of Array.from(val.keys())) {\n const v0 = val.get(k);\n const v1 = applyReviver(reviver, val, k, v0);\n if (v1 === undefined)\n val.delete(k);\n else if (v1 !== v0)\n val.set(k, v1);\n }\n }\n else if (val instanceof Set) {\n for (const v0 of Array.from(val)) {\n const v1 = applyReviver(reviver, val, v0, v0);\n if (v1 === undefined)\n val.delete(v0);\n else if (v1 !== v0) {\n val.delete(v0);\n val.add(v1);\n }\n }\n }\n else {\n for (const [k, v0] of Object.entries(val)) {\n const v1 = applyReviver(reviver, val, k, v0);\n if (v1 === undefined)\n delete val[k];\n else if (v1 !== v0)\n val[k] = v1;\n }\n }\n }\n return reviver.call(obj, key, val);\n}\n\nexport { applyReviver };\n","import { hasAnchor } from './identity.js';\n\n/**\n * Recursively convert any node or its contents to native JavaScript\n *\n * @param value - The input value\n * @param arg - If `value` defines a `toJSON()` method, use this\n * as its first argument\n * @param ctx - Conversion context, originally set in Document#toJS(). If\n * `{ keep: true }` is not set, output should be suitable for JSON\n * stringification.\n */\nfunction toJS(value, arg, ctx) {\n // eslint-disable-next-line @typescript-eslint/no-unsafe-return\n if (Array.isArray(value))\n return value.map((v, i) => toJS(v, String(i), ctx));\n if (value && typeof value.toJSON === 'function') {\n // eslint-disable-next-line @typescript-eslint/no-unsafe-call\n if (!ctx || !hasAnchor(value))\n return value.toJSON(arg, ctx);\n const data = { aliasCount: 0, count: 1, res: undefined };\n ctx.anchors.set(value, data);\n ctx.onCreate = res => {\n data.res = res;\n delete ctx.onCreate;\n };\n const res = value.toJSON(arg, ctx);\n if (ctx.onCreate)\n ctx.onCreate(res);\n return res;\n }\n if (typeof value === 'bigint' && !ctx?.keep)\n return Number(value);\n return value;\n}\n\nexport { toJS };\n","import { applyReviver } from '../doc/applyReviver.js';\nimport { NODE_TYPE, isDocument } from './identity.js';\nimport { toJS } from './toJS.js';\n\nclass NodeBase {\n constructor(type) {\n Object.defineProperty(this, NODE_TYPE, { value: type });\n }\n /** Create a copy of this node. */\n clone() {\n const copy = Object.create(Object.getPrototypeOf(this), Object.getOwnPropertyDescriptors(this));\n if (this.range)\n copy.range = this.range.slice();\n return copy;\n }\n /** A plain JavaScript representation of this node. */\n toJS(doc, { mapAsMap, maxAliasCount, onAnchor, reviver } = {}) {\n if (!isDocument(doc))\n throw new TypeError('A document argument is required');\n const ctx = {\n anchors: new Map(),\n doc,\n keep: true,\n mapAsMap: mapAsMap === true,\n mapKeyWarned: false,\n maxAliasCount: typeof maxAliasCount === 'number' ? maxAliasCount : 100\n };\n const res = toJS(this, '', ctx);\n if (typeof onAnchor === 'function')\n for (const { count, res } of ctx.anchors.values())\n onAnchor(res, count);\n return typeof reviver === 'function'\n ? applyReviver(reviver, { '': res }, '', res)\n : res;\n }\n}\n\nexport { NodeBase };\n","import { anchorIsValid } from '../doc/anchors.js';\nimport { visit } from '../visit.js';\nimport { ALIAS, isAlias, isCollection, isPair, hasAnchor } from './identity.js';\nimport { NodeBase } from './Node.js';\nimport { toJS } from './toJS.js';\n\nclass Alias extends NodeBase {\n constructor(source) {\n super(ALIAS);\n this.source = source;\n Object.defineProperty(this, 'tag', {\n set() {\n throw new Error('Alias nodes cannot have tags');\n }\n });\n }\n /**\n * Resolve the value of this alias within `doc`, finding the last\n * instance of the `source` anchor before this node.\n */\n resolve(doc, ctx) {\n let nodes;\n if (ctx?.aliasResolveCache) {\n nodes = ctx.aliasResolveCache;\n }\n else {\n nodes = [];\n visit(doc, {\n Node: (_key, node) => {\n if (isAlias(node) || hasAnchor(node))\n nodes.push(node);\n }\n });\n if (ctx)\n ctx.aliasResolveCache = nodes;\n }\n let found = undefined;\n for (const node of nodes) {\n if (node === this)\n break;\n if (node.anchor === this.source)\n found = node;\n }\n return found;\n }\n toJSON(_arg, ctx) {\n if (!ctx)\n return { source: this.source };\n const { anchors, doc, maxAliasCount } = ctx;\n const source = this.resolve(doc, ctx);\n if (!source) {\n const msg = `Unresolved alias (the anchor must be set before the alias): ${this.source}`;\n throw new ReferenceError(msg);\n }\n let data = anchors.get(source);\n if (!data) {\n // Resolve anchors for Node.prototype.toJS()\n toJS(source, null, ctx);\n data = anchors.get(source);\n }\n /* istanbul ignore if */\n if (data?.res === undefined) {\n const msg = 'This should not happen: Alias anchor was not resolved?';\n throw new ReferenceError(msg);\n }\n if (maxAliasCount >= 0) {\n data.count += 1;\n if (data.aliasCount === 0)\n data.aliasCount = getAliasCount(doc, source, anchors);\n if (data.count * data.aliasCount > maxAliasCount) {\n const msg = 'Excessive alias count indicates a resource exhaustion attack';\n throw new ReferenceError(msg);\n }\n }\n return data.res;\n }\n toString(ctx, _onComment, _onChompKeep) {\n const src = `*${this.source}`;\n if (ctx) {\n anchorIsValid(this.source);\n if (ctx.options.verifyAliasOrder && !ctx.anchors.has(this.source)) {\n const msg = `Unresolved alias (the anchor must be set before the alias): ${this.source}`;\n throw new Error(msg);\n }\n if (ctx.implicitKey)\n return `${src} `;\n }\n return src;\n }\n}\nfunction getAliasCount(doc, node, anchors) {\n if (isAlias(node)) {\n const source = node.resolve(doc);\n const anchor = anchors && source && anchors.get(source);\n return anchor ? anchor.count * anchor.aliasCount : 0;\n }\n else if (isCollection(node)) {\n let count = 0;\n for (const item of node.items) {\n const c = getAliasCount(doc, item, anchors);\n if (c > count)\n count = c;\n }\n return count;\n }\n else if (isPair(node)) {\n const kc = getAliasCount(doc, node.key, anchors);\n const vc = getAliasCount(doc, node.value, anchors);\n return Math.max(kc, vc);\n }\n return 1;\n}\n\nexport { Alias };\n","import { SCALAR } from './identity.js';\nimport { NodeBase } from './Node.js';\nimport { toJS } from './toJS.js';\n\nconst isScalarValue = (value) => !value || (typeof value !== 'function' && typeof value !== 'object');\nclass Scalar extends NodeBase {\n constructor(value) {\n super(SCALAR);\n this.value = value;\n }\n toJSON(arg, ctx) {\n return ctx?.keep ? this.value : toJS(this.value, arg, ctx);\n }\n toString() {\n return String(this.value);\n }\n}\nScalar.BLOCK_FOLDED = 'BLOCK_FOLDED';\nScalar.BLOCK_LITERAL = 'BLOCK_LITERAL';\nScalar.PLAIN = 'PLAIN';\nScalar.QUOTE_DOUBLE = 'QUOTE_DOUBLE';\nScalar.QUOTE_SINGLE = 'QUOTE_SINGLE';\n\nexport { Scalar, isScalarValue };\n","import { Alias } from '../nodes/Alias.js';\nimport { isNode, isPair, MAP, SEQ, isDocument } from '../nodes/identity.js';\nimport { Scalar } from '../nodes/Scalar.js';\n\nconst defaultTagPrefix = 'tag:yaml.org,2002:';\nfunction findTagObject(value, tagName, tags) {\n if (tagName) {\n const match = tags.filter(t => t.tag === tagName);\n const tagObj = match.find(t => !t.format) ?? match[0];\n if (!tagObj)\n throw new Error(`Tag ${tagName} not found`);\n return tagObj;\n }\n return tags.find(t => t.identify?.(value) && !t.format);\n}\nfunction createNode(value, tagName, ctx) {\n if (isDocument(value))\n value = value.contents;\n if (isNode(value))\n return value;\n if (isPair(value)) {\n const map = ctx.schema[MAP].createNode?.(ctx.schema, null, ctx);\n map.items.push(value);\n return map;\n }\n if (value instanceof String ||\n value instanceof Number ||\n value instanceof Boolean ||\n (typeof BigInt !== 'undefined' && value instanceof BigInt) // not supported everywhere\n ) {\n // https://tc39.es/ecma262/#sec-serializejsonproperty\n value = value.valueOf();\n }\n const { aliasDuplicateObjects, onAnchor, onTagObj, schema, sourceObjects } = ctx;\n // Detect duplicate references to the same object & use Alias nodes for all\n // after first. The `ref` wrapper allows for circular references to resolve.\n let ref = undefined;\n if (aliasDuplicateObjects && value && typeof value === 'object') {\n ref = sourceObjects.get(value);\n if (ref) {\n ref.anchor ?? (ref.anchor = onAnchor(value));\n return new Alias(ref.anchor);\n }\n else {\n ref = { anchor: null, node: null };\n sourceObjects.set(value, ref);\n }\n }\n if (tagName?.startsWith('!!'))\n tagName = defaultTagPrefix + tagName.slice(2);\n let tagObj = findTagObject(value, tagName, schema.tags);\n if (!tagObj) {\n if (value && typeof value.toJSON === 'function') {\n // eslint-disable-next-line @typescript-eslint/no-unsafe-call\n value = value.toJSON();\n }\n if (!value || typeof value !== 'object') {\n const node = new Scalar(value);\n if (ref)\n ref.node = node;\n return node;\n }\n tagObj =\n value instanceof Map\n ? schema[MAP]\n : Symbol.iterator in Object(value)\n ? schema[SEQ]\n : schema[MAP];\n }\n if (onTagObj) {\n onTagObj(tagObj);\n delete ctx.onTagObj;\n }\n const node = tagObj?.createNode\n ? tagObj.createNode(ctx.schema, value, ctx)\n : typeof tagObj?.nodeClass?.from === 'function'\n ? tagObj.nodeClass.from(ctx.schema, value, ctx)\n : new Scalar(value);\n if (tagName)\n node.tag = tagName;\n else if (!tagObj.default)\n node.tag = tagObj.tag;\n if (ref)\n ref.node = node;\n return node;\n}\n\nexport { createNode };\n","import { createNode } from '../doc/createNode.js';\nimport { isNode, isPair, isCollection, isScalar } from './identity.js';\nimport { NodeBase } from './Node.js';\n\nfunction collectionFromPath(schema, path, value) {\n let v = value;\n for (let i = path.length - 1; i >= 0; --i) {\n const k = path[i];\n if (typeof k === 'number' && Number.isInteger(k) && k >= 0) {\n const a = [];\n a[k] = v;\n v = a;\n }\n else {\n v = new Map([[k, v]]);\n }\n }\n return createNode(v, undefined, {\n aliasDuplicateObjects: false,\n keepUndefined: false,\n onAnchor: () => {\n throw new Error('This should not happen, please report a bug.');\n },\n schema,\n sourceObjects: new Map()\n });\n}\n// Type guard is intentionally a little wrong so as to be more useful,\n// as it does not cover untypable empty non-string iterables (e.g. []).\nconst isEmptyPath = (path) => path == null ||\n (typeof path === 'object' && !!path[Symbol.iterator]().next().done);\nclass Collection extends NodeBase {\n constructor(type, schema) {\n super(type);\n Object.defineProperty(this, 'schema', {\n value: schema,\n configurable: true,\n enumerable: false,\n writable: true\n });\n }\n /**\n * Create a copy of this collection.\n *\n * @param schema - If defined, overwrites the original's schema\n */\n clone(schema) {\n const copy = Object.create(Object.getPrototypeOf(this), Object.getOwnPropertyDescriptors(this));\n if (schema)\n copy.schema = schema;\n copy.items = copy.items.map(it => isNode(it) || isPair(it) ? it.clone(schema) : it);\n if (this.range)\n copy.range = this.range.slice();\n return copy;\n }\n /**\n * Adds a value to the collection. For `!!map` and `!!omap` the value must\n * be a Pair instance or a `{ key, value }` object, which may not have a key\n * that already exists in the map.\n */\n addIn(path, value) {\n if (isEmptyPath(path))\n this.add(value);\n else {\n const [key, ...rest] = path;\n const node = this.get(key, true);\n if (isCollection(node))\n node.addIn(rest, value);\n else if (node === undefined && this.schema)\n this.set(key, collectionFromPath(this.schema, rest, value));\n else\n throw new Error(`Expected YAML collection at ${key}. Remaining path: ${rest}`);\n }\n }\n /**\n * Removes a value from the collection.\n * @returns `true` if the item was found and removed.\n */\n deleteIn(path) {\n const [key, ...rest] = path;\n if (rest.length === 0)\n return this.delete(key);\n const node = this.get(key, true);\n if (isCollection(node))\n return node.deleteIn(rest);\n else\n throw new Error(`Expected YAML collection at ${key}. Remaining path: ${rest}`);\n }\n /**\n * Returns item at `key`, or `undefined` if not found. By default unwraps\n * scalar values from their surrounding node; to disable set `keepScalar` to\n * `true` (collections are always returned intact).\n */\n getIn(path, keepScalar) {\n const [key, ...rest] = path;\n const node = this.get(key, true);\n if (rest.length === 0)\n return !keepScalar && isScalar(node) ? node.value : node;\n else\n return isCollection(node) ? node.getIn(rest, keepScalar) : undefined;\n }\n hasAllNullValues(allowScalar) {\n return this.items.every(node => {\n if (!isPair(node))\n return false;\n const n = node.value;\n return (n == null ||\n (allowScalar &&\n isScalar(n) &&\n n.value == null &&\n !n.commentBefore &&\n !n.comment &&\n !n.tag));\n });\n }\n /**\n * Checks if the collection includes a value with the key `key`.\n */\n hasIn(path) {\n const [key, ...rest] = path;\n if (rest.length === 0)\n return this.has(key);\n const node = this.get(key, true);\n return isCollection(node) ? node.hasIn(rest) : false;\n }\n /**\n * Sets a value in this collection. For `!!set`, `value` needs to be a\n * boolean to add/remove the item from the set.\n */\n setIn(path, value) {\n const [key, ...rest] = path;\n if (rest.length === 0) {\n this.set(key, value);\n }\n else {\n const node = this.get(key, true);\n if (isCollection(node))\n node.setIn(rest, value);\n else if (node === undefined && this.schema)\n this.set(key, collectionFromPath(this.schema, rest, value));\n else\n throw new Error(`Expected YAML collection at ${key}. Remaining path: ${rest}`);\n }\n }\n}\n\nexport { Collection, collectionFromPath, isEmptyPath };\n","/**\n * Stringifies a comment.\n *\n * Empty comment lines are left empty,\n * lines consisting of a single space are replaced by `#`,\n * and all other lines are prefixed with a `#`.\n */\nconst stringifyComment = (str) => str.replace(/^(?!$)(?: $)?/gm, '#');\nfunction indentComment(comment, indent) {\n if (/^\\n+$/.test(comment))\n return comment.substring(1);\n return indent ? comment.replace(/^(?! *$)/gm, indent) : comment;\n}\nconst lineComment = (str, indent, comment) => str.endsWith('\\n')\n ? indentComment(comment, indent)\n : comment.includes('\\n')\n ? '\\n' + indentComment(comment, indent)\n : (str.endsWith(' ') ? '' : ' ') + comment;\n\nexport { indentComment, lineComment, stringifyComment };\n","const FOLD_FLOW = 'flow';\nconst FOLD_BLOCK = 'block';\nconst FOLD_QUOTED = 'quoted';\n/**\n * Tries to keep input at up to `lineWidth` characters, splitting only on spaces\n * not followed by newlines or spaces unless `mode` is `'quoted'`. Lines are\n * terminated with `\\n` and started with `indent`.\n */\nfunction foldFlowLines(text, indent, mode = 'flow', { indentAtStart, lineWidth = 80, minContentWidth = 20, onFold, onOverflow } = {}) {\n if (!lineWidth || lineWidth < 0)\n return text;\n if (lineWidth < minContentWidth)\n minContentWidth = 0;\n const endStep = Math.max(1 + minContentWidth, 1 + lineWidth - indent.length);\n if (text.length <= endStep)\n return text;\n const folds = [];\n const escapedFolds = {};\n let end = lineWidth - indent.length;\n if (typeof indentAtStart === 'number') {\n if (indentAtStart > lineWidth - Math.max(2, minContentWidth))\n folds.push(0);\n else\n end = lineWidth - indentAtStart;\n }\n let split = undefined;\n let prev = undefined;\n let overflow = false;\n let i = -1;\n let escStart = -1;\n let escEnd = -1;\n if (mode === FOLD_BLOCK) {\n i = consumeMoreIndentedLines(text, i, indent.length);\n if (i !== -1)\n end = i + endStep;\n }\n for (let ch; (ch = text[(i += 1)]);) {\n if (mode === FOLD_QUOTED && ch === '\\\\') {\n escStart = i;\n switch (text[i + 1]) {\n case 'x':\n i += 3;\n break;\n case 'u':\n i += 5;\n break;\n case 'U':\n i += 9;\n break;\n default:\n i += 1;\n }\n escEnd = i;\n }\n if (ch === '\\n') {\n if (mode === FOLD_BLOCK)\n i = consumeMoreIndentedLines(text, i, indent.length);\n end = i + indent.length + endStep;\n split = undefined;\n }\n else {\n if (ch === ' ' &&\n prev &&\n prev !== ' ' &&\n prev !== '\\n' &&\n prev !== '\\t') {\n // space surrounded by non-space can be replaced with newline + indent\n const next = text[i + 1];\n if (next && next !== ' ' && next !== '\\n' && next !== '\\t')\n split = i;\n }\n if (i >= end) {\n if (split) {\n folds.push(split);\n end = split + endStep;\n split = undefined;\n }\n else if (mode === FOLD_QUOTED) {\n // white-space collected at end may stretch past lineWidth\n while (prev === ' ' || prev === '\\t') {\n prev = ch;\n ch = text[(i += 1)];\n overflow = true;\n }\n // Account for newline escape, but don't break preceding escape\n const j = i > escEnd + 1 ? i - 2 : escStart - 1;\n // Bail out if lineWidth & minContentWidth are shorter than an escape string\n if (escapedFolds[j])\n return text;\n folds.push(j);\n escapedFolds[j] = true;\n end = j + endStep;\n split = undefined;\n }\n else {\n overflow = true;\n }\n }\n }\n prev = ch;\n }\n if (overflow && onOverflow)\n onOverflow();\n if (folds.length === 0)\n return text;\n if (onFold)\n onFold();\n let res = text.slice(0, folds[0]);\n for (let i = 0; i < folds.length; ++i) {\n const fold = folds[i];\n const end = folds[i + 1] || text.length;\n if (fold === 0)\n res = `\\n${indent}${text.slice(0, end)}`;\n else {\n if (mode === FOLD_QUOTED && escapedFolds[fold])\n res += `${text[fold]}\\\\`;\n res += `\\n${indent}${text.slice(fold + 1, end)}`;\n }\n }\n return res;\n}\n/**\n * Presumes `i + 1` is at the start of a line\n * @returns index of last newline in more-indented block\n */\nfunction consumeMoreIndentedLines(text, i, indent) {\n let end = i;\n let start = i + 1;\n let ch = text[start];\n while (ch === ' ' || ch === '\\t') {\n if (i < start + indent) {\n ch = text[++i];\n }\n else {\n do {\n ch = text[++i];\n } while (ch && ch !== '\\n');\n end = i;\n start = i + 1;\n ch = text[start];\n }\n }\n return end;\n}\n\nexport { FOLD_BLOCK, FOLD_FLOW, FOLD_QUOTED, foldFlowLines };\n","import { Scalar } from '../nodes/Scalar.js';\nimport { foldFlowLines, FOLD_FLOW, FOLD_QUOTED, FOLD_BLOCK } from './foldFlowLines.js';\n\nconst getFoldOptions = (ctx, isBlock) => ({\n indentAtStart: isBlock ? ctx.indent.length : ctx.indentAtStart,\n lineWidth: ctx.options.lineWidth,\n minContentWidth: ctx.options.minContentWidth\n});\n// Also checks for lines starting with %, as parsing the output as YAML 1.1 will\n// presume that's starting a new document.\nconst containsDocumentMarker = (str) => /^(%|---|\\.\\.\\.)/m.test(str);\nfunction lineLengthOverLimit(str, lineWidth, indentLength) {\n if (!lineWidth || lineWidth < 0)\n return false;\n const limit = lineWidth - indentLength;\n const strLen = str.length;\n if (strLen <= limit)\n return false;\n for (let i = 0, start = 0; i < strLen; ++i) {\n if (str[i] === '\\n') {\n if (i - start > limit)\n return true;\n start = i + 1;\n if (strLen - start <= limit)\n return false;\n }\n }\n return true;\n}\nfunction doubleQuotedString(value, ctx) {\n const json = JSON.stringify(value);\n if (ctx.options.doubleQuotedAsJSON)\n return json;\n const { implicitKey } = ctx;\n const minMultiLineLength = ctx.options.doubleQuotedMinMultiLineLength;\n const indent = ctx.indent || (containsDocumentMarker(value) ? ' ' : '');\n let str = '';\n let start = 0;\n for (let i = 0, ch = json[i]; ch; ch = json[++i]) {\n if (ch === ' ' && json[i + 1] === '\\\\' && json[i + 2] === 'n') {\n // space before newline needs to be escaped to not be folded\n str += json.slice(start, i) + '\\\\ ';\n i += 1;\n start = i;\n ch = '\\\\';\n }\n if (ch === '\\\\')\n switch (json[i + 1]) {\n case 'u':\n {\n str += json.slice(start, i);\n const code = json.substr(i + 2, 4);\n switch (code) {\n case '0000':\n str += '\\\\0';\n break;\n case '0007':\n str += '\\\\a';\n break;\n case '000b':\n str += '\\\\v';\n break;\n case '001b':\n str += '\\\\e';\n break;\n case '0085':\n str += '\\\\N';\n break;\n case '00a0':\n str += '\\\\_';\n break;\n case '2028':\n str += '\\\\L';\n break;\n case '2029':\n str += '\\\\P';\n break;\n default:\n if (code.substr(0, 2) === '00')\n str += '\\\\x' + code.substr(2);\n else\n str += json.substr(i, 6);\n }\n i += 5;\n start = i + 1;\n }\n break;\n case 'n':\n if (implicitKey ||\n json[i + 2] === '\"' ||\n json.length < minMultiLineLength) {\n i += 1;\n }\n else {\n // folding will eat first newline\n str += json.slice(start, i) + '\\n\\n';\n while (json[i + 2] === '\\\\' &&\n json[i + 3] === 'n' &&\n json[i + 4] !== '\"') {\n str += '\\n';\n i += 2;\n }\n str += indent;\n // space after newline needs to be escaped to not be folded\n if (json[i + 2] === ' ')\n str += '\\\\';\n i += 1;\n start = i + 1;\n }\n break;\n default:\n i += 1;\n }\n }\n str = start ? str + json.slice(start) : json;\n return implicitKey\n ? str\n : foldFlowLines(str, indent, FOLD_QUOTED, getFoldOptions(ctx, false));\n}\nfunction singleQuotedString(value, ctx) {\n if (ctx.options.singleQuote === false ||\n (ctx.implicitKey && value.includes('\\n')) ||\n /[ \\t]\\n|\\n[ \\t]/.test(value) // single quoted string can't have leading or trailing whitespace around newline\n )\n return doubleQuotedString(value, ctx);\n const indent = ctx.indent || (containsDocumentMarker(value) ? ' ' : '');\n const res = \"'\" + value.replace(/'/g, \"''\").replace(/\\n+/g, `$&\\n${indent}`) + \"'\";\n return ctx.implicitKey\n ? res\n : foldFlowLines(res, indent, FOLD_FLOW, getFoldOptions(ctx, false));\n}\nfunction quotedString(value, ctx) {\n const { singleQuote } = ctx.options;\n let qs;\n if (singleQuote === false)\n qs = doubleQuotedString;\n else {\n const hasDouble = value.includes('\"');\n const hasSingle = value.includes(\"'\");\n if (hasDouble && !hasSingle)\n qs = singleQuotedString;\n else if (hasSingle && !hasDouble)\n qs = doubleQuotedString;\n else\n qs = singleQuote ? singleQuotedString : doubleQuotedString;\n }\n return qs(value, ctx);\n}\n// The negative lookbehind avoids a polynomial search,\n// but isn't supported yet on Safari: https://caniuse.com/js-regexp-lookbehind\nlet blockEndNewlines;\ntry {\n blockEndNewlines = new RegExp('(^|(?<!\\n))\\n+(?!\\n|$)', 'g');\n}\ncatch {\n blockEndNewlines = /\\n+(?!\\n|$)/g;\n}\nfunction blockString({ comment, type, value }, ctx, onComment, onChompKeep) {\n const { blockQuote, commentString, lineWidth } = ctx.options;\n // 1. Block can't end in whitespace unless the last line is non-empty.\n // 2. Strings consisting of only whitespace are best rendered explicitly.\n if (!blockQuote || /\\n[\\t ]+$/.test(value)) {\n return quotedString(value, ctx);\n }\n const indent = ctx.indent ||\n (ctx.forceBlockIndent || containsDocumentMarker(value) ? ' ' : '');\n const literal = blockQuote === 'literal'\n ? true\n : blockQuote === 'folded' || type === Scalar.BLOCK_FOLDED\n ? false\n : type === Scalar.BLOCK_LITERAL\n ? true\n : !lineLengthOverLimit(value, lineWidth, indent.length);\n if (!value)\n return literal ? '|\\n' : '>\\n';\n // determine chomping from whitespace at value end\n let chomp;\n let endStart;\n for (endStart = value.length; endStart > 0; --endStart) {\n const ch = value[endStart - 1];\n if (ch !== '\\n' && ch !== '\\t' && ch !== ' ')\n break;\n }\n let end = value.substring(endStart);\n const endNlPos = end.indexOf('\\n');\n if (endNlPos === -1) {\n chomp = '-'; // strip\n }\n else if (value === end || endNlPos !== end.length - 1) {\n chomp = '+'; // keep\n if (onChompKeep)\n onChompKeep();\n }\n else {\n chomp = ''; // clip\n }\n if (end) {\n value = value.slice(0, -end.length);\n if (end[end.length - 1] === '\\n')\n end = end.slice(0, -1);\n end = end.replace(blockEndNewlines, `$&${indent}`);\n }\n // determine indent indicator from whitespace at value start\n let startWithSpace = false;\n let startEnd;\n let startNlPos = -1;\n for (startEnd = 0; startEnd < value.length; ++startEnd) {\n const ch = value[startEnd];\n if (ch === ' ')\n startWithSpace = true;\n else if (ch === '\\n')\n startNlPos = startEnd;\n else\n break;\n }\n let start = value.substring(0, startNlPos < startEnd ? startNlPos + 1 : startEnd);\n if (start) {\n value = value.substring(start.length);\n start = start.replace(/\\n+/g, `$&${indent}`);\n }\n const indentSize = indent ? '2' : '1'; // root is at -1\n // Leading | or > is added later\n let header = (startWithSpace ? indentSize : '') + chomp;\n if (comment) {\n header += ' ' + commentString(comment.replace(/ ?[\\r\\n]+/g, ' '));\n if (onComment)\n onComment();\n }\n if (!literal) {\n const foldedValue = value\n .replace(/\\n+/g, '\\n$&')\n .replace(/(?:^|\\n)([\\t ].*)(?:([\\n\\t ]*)\\n(?![\\n\\t ]))?/g, '$1$2') // more-indented lines aren't folded\n // ^ more-ind. ^ empty ^ capture next empty lines only at end of indent\n .replace(/\\n+/g, `$&${indent}`);\n let literalFallback = false;\n const foldOptions = getFoldOptions(ctx, true);\n if (blockQuote !== 'folded' && type !== Scalar.BLOCK_FOLDED) {\n foldOptions.onOverflow = () => {\n literalFallback = true;\n };\n }\n const body = foldFlowLines(`${start}${foldedValue}${end}`, indent, FOLD_BLOCK, foldOptions);\n if (!literalFallback)\n return `>${header}\\n${indent}${body}`;\n }\n value = value.replace(/\\n+/g, `$&${indent}`);\n return `|${header}\\n${indent}${start}${value}${end}`;\n}\nfunction plainString(item, ctx, onComment, onChompKeep) {\n const { type, value } = item;\n const { actualString, implicitKey, indent, indentStep, inFlow } = ctx;\n if ((implicitKey && value.includes('\\n')) ||\n (inFlow && /[[\\]{},]/.test(value))) {\n return quotedString(value, ctx);\n }\n if (/^[\\n\\t ,[\\]{}#&*!|>'\"%@`]|^[?-]$|^[?-][ \\t]|[\\n:][ \\t]|[ \\t]\\n|[\\n\\t ]#|[\\n\\t :]$/.test(value)) {\n // not allowed:\n // - '-' or '?'\n // - start with an indicator character (except [?:-]) or /[?-] /\n // - '\\n ', ': ' or ' \\n' anywhere\n // - '#' not preceded by a non-space char\n // - end with ' ' or ':'\n return implicitKey || inFlow || !value.includes('\\n')\n ? quotedString(value, ctx)\n : blockString(item, ctx, onComment, onChompKeep);\n }\n if (!implicitKey &&\n !inFlow &&\n type !== Scalar.PLAIN &&\n value.includes('\\n')) {\n // Where allowed & type not set explicitly, prefer block style for multiline strings\n return blockString(item, ctx, onComment, onChompKeep);\n }\n if (containsDocumentMarker(value)) {\n if (indent === '') {\n ctx.forceBlockIndent = true;\n return blockString(item, ctx, onComment, onChompKeep);\n }\n else if (implicitKey && indent === indentStep) {\n return quotedString(value, ctx);\n }\n }\n const str = value.replace(/\\n+/g, `$&\\n${indent}`);\n // Verify that output will be parsed as a string, as e.g. plain numbers and\n // booleans get parsed with those types in v1.2 (e.g. '42', 'true' & '0.9e-3'),\n // and others in v1.1.\n if (actualString) {\n const test = (tag) => tag.default && tag.tag !== 'tag:yaml.org,2002:str' && tag.test?.test(str);\n const { compat, tags } = ctx.doc.schema;\n if (tags.some(test) || compat?.some(test))\n return quotedString(value, ctx);\n }\n return implicitKey\n ? str\n : foldFlowLines(str, indent, FOLD_FLOW, getFoldOptions(ctx, false));\n}\nfunction stringifyString(item, ctx, onComment, onChompKeep) {\n const { implicitKey, inFlow } = ctx;\n const ss = typeof item.value === 'string'\n ? item\n : Object.assign({}, item, { value: String(item.value) });\n let { type } = item;\n if (type !== Scalar.QUOTE_DOUBLE) {\n // force double quotes on control characters & unpaired surrogates\n if (/[\\x00-\\x08\\x0b-\\x1f\\x7f-\\x9f\\u{D800}-\\u{DFFF}]/u.test(ss.value))\n type = Scalar.QUOTE_DOUBLE;\n }\n const _stringify = (_type) => {\n switch (_type) {\n case Scalar.BLOCK_FOLDED:\n case Scalar.BLOCK_LITERAL:\n return implicitKey || inFlow\n ? quotedString(ss.value, ctx) // blocks are not valid inside flow containers\n : blockString(ss, ctx, onComment, onChompKeep);\n case Scalar.QUOTE_DOUBLE:\n return doubleQuotedString(ss.value, ctx);\n case Scalar.QUOTE_SINGLE:\n return singleQuotedString(ss.value, ctx);\n case Scalar.PLAIN:\n return plainString(ss, ctx, onComment, onChompKeep);\n default:\n return null;\n }\n };\n let res = _stringify(type);\n if (res === null) {\n const { defaultKeyType, defaultStringType } = ctx.options;\n const t = (implicitKey && defaultKeyType) || defaultStringType;\n res = _stringify(t);\n if (res === null)\n throw new Error(`Unsupported default string type ${t}`);\n }\n return res;\n}\n\nexport { stringifyString };\n","import { anchorIsValid } from '../doc/anchors.js';\nimport { isPair, isAlias, isNode, isScalar, isCollection } from '../nodes/identity.js';\nimport { stringifyComment } from './stringifyComment.js';\nimport { stringifyString } from './stringifyString.js';\n\nfunction createStringifyContext(doc, options) {\n const opt = Object.assign({\n blockQuote: true,\n commentString: stringifyComment,\n defaultKeyType: null,\n defaultStringType: 'PLAIN',\n directives: null,\n doubleQuotedAsJSON: false,\n doubleQuotedMinMultiLineLength: 40,\n falseStr: 'false',\n flowCollectionPadding: true,\n indentSeq: true,\n lineWidth: 80,\n minContentWidth: 20,\n nullStr: 'null',\n simpleKeys: false,\n singleQuote: null,\n trueStr: 'true',\n verifyAliasOrder: true\n }, doc.schema.toStringOptions, options);\n let inFlow;\n switch (opt.collectionStyle) {\n case 'block':\n inFlow = false;\n break;\n case 'flow':\n inFlow = true;\n break;\n default:\n inFlow = null;\n }\n return {\n anchors: new Set(),\n doc,\n flowCollectionPadding: opt.flowCollectionPadding ? ' ' : '',\n indent: '',\n indentStep: typeof opt.indent === 'number' ? ' '.repeat(opt.indent) : ' ',\n inFlow,\n options: opt\n };\n}\nfunction getTagObject(tags, item) {\n if (item.tag) {\n const match = tags.filter(t => t.tag === item.tag);\n if (match.length > 0)\n return match.find(t => t.format === item.format) ?? match[0];\n }\n let tagObj = undefined;\n let obj;\n if (isScalar(item)) {\n obj = item.value;\n let match = tags.filter(t => t.identify?.(obj));\n if (match.length > 1) {\n const testMatch = match.filter(t => t.test);\n if (testMatch.length > 0)\n match = testMatch;\n }\n tagObj =\n match.find(t => t.format === item.format) ?? match.find(t => !t.format);\n }\n else {\n obj = item;\n tagObj = tags.find(t => t.nodeClass && obj instanceof t.nodeClass);\n }\n if (!tagObj) {\n const name = obj?.constructor?.name ?? (obj === null ? 'null' : typeof obj);\n throw new Error(`Tag not resolved for ${name} value`);\n }\n return tagObj;\n}\n// needs to be called before value stringifier to allow for circular anchor refs\nfunction stringifyProps(node, tagObj, { anchors, doc }) {\n if (!doc.directives)\n return '';\n const props = [];\n const anchor = (isScalar(node) || isCollection(node)) && node.anchor;\n if (anchor && anchorIsValid(anchor)) {\n anchors.add(anchor);\n props.push(`&${anchor}`);\n }\n const tag = node.tag ?? (tagObj.default ? null : tagObj.tag);\n if (tag)\n props.push(doc.directives.tagString(tag));\n return props.join(' ');\n}\nfunction stringify(item, ctx, onComment, onChompKeep) {\n if (isPair(item))\n return item.toString(ctx, onComment, onChompKeep);\n if (isAlias(item)) {\n if (ctx.doc.directives)\n return item.toString(ctx);\n if (ctx.resolvedAliases?.has(item)) {\n throw new TypeError(`Cannot stringify circular structure without alias nodes`);\n }\n else {\n if (ctx.resolvedAliases)\n ctx.resolvedAliases.add(item);\n else\n ctx.resolvedAliases = new Set([item]);\n item = item.resolve(ctx.doc);\n }\n }\n let tagObj = undefined;\n const node = isNode(item)\n ? item\n : ctx.doc.createNode(item, { onTagObj: o => (tagObj = o) });\n tagObj ?? (tagObj = getTagObject(ctx.doc.schema.tags, node));\n const props = stringifyProps(node, tagObj, ctx);\n if (props.length > 0)\n ctx.indentAtStart = (ctx.indentAtStart ?? 0) + props.length + 1;\n const str = typeof tagObj.stringify === 'function'\n ? tagObj.stringify(node, ctx, onComment, onChompKeep)\n : isScalar(node)\n ? stringifyString(node, ctx, onComment, onChompKeep)\n : node.toString(ctx, onComment, onChompKeep);\n if (!props)\n return str;\n return isScalar(node) || str[0] === '{' || str[0] === '['\n ? `${props} ${str}`\n : `${props}\\n${ctx.indent}${str}`;\n}\n\nexport { createStringifyContext, stringify };\n","import { isScalar, isAlias, isSeq, isMap } from '../../nodes/identity.js';\nimport { Scalar } from '../../nodes/Scalar.js';\n\n// If the value associated with a merge key is a single mapping node, each of\n// its key/value pairs is inserted into the current mapping, unless the key\n// already exists in it. If the value associated with the merge key is a\n// sequence, then this sequence is expected to contain mapping nodes and each\n// of these nodes is merged in turn according to its order in the sequence.\n// Keys in mapping nodes earlier in the sequence override keys specified in\n// later mapping nodes. -- http://yaml.org/type/merge.html\nconst MERGE_KEY = '<<';\nconst merge = {\n identify: value => value === MERGE_KEY ||\n (typeof value === 'symbol' && value.description === MERGE_KEY),\n default: 'key',\n tag: 'tag:yaml.org,2002:merge',\n test: /^<<$/,\n resolve: () => Object.assign(new Scalar(Symbol(MERGE_KEY)), {\n addToJSMap: addMergeToJSMap\n }),\n stringify: () => MERGE_KEY\n};\nconst isMergeKey = (ctx, key) => (merge.identify(key) ||\n (isScalar(key) &&\n (!key.type || key.type === Scalar.PLAIN) &&\n merge.identify(key.value))) &&\n ctx?.doc.schema.tags.some(tag => tag.tag === merge.tag && tag.default);\nfunction addMergeToJSMap(ctx, map, value) {\n value = ctx && isAlias(value) ? value.resolve(ctx.doc) : value;\n if (isSeq(value))\n for (const it of value.items)\n mergeValue(ctx, map, it);\n else if (Array.isArray(value))\n for (const it of value)\n mergeValue(ctx, map, it);\n else\n mergeValue(ctx, map, value);\n}\nfunction mergeValue(ctx, map, value) {\n const source = ctx && isAlias(value) ? value.resolve(ctx.doc) : value;\n if (!isMap(source))\n throw new Error('Merge sources must be maps or map aliases');\n const srcMap = source.toJSON(null, ctx, Map);\n for (const [key, value] of srcMap) {\n if (map instanceof Map) {\n if (!map.has(key))\n map.set(key, value);\n }\n else if (map instanceof Set) {\n map.add(key);\n }\n else if (!Object.prototype.hasOwnProperty.call(map, key)) {\n Object.defineProperty(map, key, {\n value,\n writable: true,\n enumerable: true,\n configurable: true\n });\n }\n }\n return map;\n}\n\nexport { addMergeToJSMap, isMergeKey, merge };\n","import { warn } from '../log.js';\nimport { isMergeKey, addMergeToJSMap } from '../schema/yaml-1.1/merge.js';\nimport { createStringifyContext } from '../stringify/stringify.js';\nimport { isNode } from './identity.js';\nimport { toJS } from './toJS.js';\n\nfunction addPairToJSMap(ctx, map, { key, value }) {\n if (isNode(key) && key.addToJSMap)\n key.addToJSMap(ctx, map, value);\n // TODO: Should drop this special case for bare << handling\n else if (isMergeKey(ctx, key))\n addMergeToJSMap(ctx, map, value);\n else {\n const jsKey = toJS(key, '', ctx);\n if (map instanceof Map) {\n map.set(jsKey, toJS(value, jsKey, ctx));\n }\n else if (map instanceof Set) {\n map.add(jsKey);\n }\n else {\n const stringKey = stringifyKey(key, jsKey, ctx);\n const jsValue = toJS(value, stringKey, ctx);\n if (stringKey in map)\n Object.defineProperty(map, stringKey, {\n value: jsValue,\n writable: true,\n enumerable: true,\n configurable: true\n });\n else\n map[stringKey] = jsValue;\n }\n }\n return map;\n}\nfunction stringifyKey(key, jsKey, ctx) {\n if (jsKey === null)\n return '';\n // eslint-disable-next-line @typescript-eslint/no-base-to-string\n if (typeof jsKey !== 'object')\n return String(jsKey);\n if (isNode(key) && ctx?.doc) {\n const strCtx = createStringifyContext(ctx.doc, {});\n strCtx.anchors = new Set();\n for (const node of ctx.anchors.keys())\n strCtx.anchors.add(node.anchor);\n strCtx.inFlow = true;\n strCtx.inStringifyKey = true;\n const strKey = key.toString(strCtx);\n if (!ctx.mapKeyWarned) {\n let jsonStr = JSON.stringify(strKey);\n if (jsonStr.length > 40)\n jsonStr = jsonStr.substring(0, 36) + '...\"';\n warn(ctx.doc.options.logLevel, `Keys with collection values will be stringified due to JS Object restrictions: ${jsonStr}. Set mapAsMap: true to use object keys.`);\n ctx.mapKeyWarned = true;\n }\n return strKey;\n }\n return JSON.stringify(jsKey);\n}\n\nexport { addPairToJSMap };\n","function debug(logLevel, ...messages) {\n if (logLevel === 'debug')\n console.log(...messages);\n}\nfunction warn(logLevel, warning) {\n if (logLevel === 'debug' || logLevel === 'warn') {\n console.warn(warning);\n }\n}\n\nexport { debug, warn };\n","import { createNode } from '../doc/createNode.js';\nimport { stringifyPair } from '../stringify/stringifyPair.js';\nimport { addPairToJSMap } from './addPairToJSMap.js';\nimport { NODE_TYPE, PAIR, isNode } from './identity.js';\n\nfunction createPair(key, value, ctx) {\n const k = createNode(key, undefined, ctx);\n const v = createNode(value, undefined, ctx);\n return new Pair(k, v);\n}\nclass Pair {\n constructor(key, value = null) {\n Object.defineProperty(this, NODE_TYPE, { value: PAIR });\n this.key = key;\n this.value = value;\n }\n clone(schema) {\n let { key, value } = this;\n if (isNode(key))\n key = key.clone(schema);\n if (isNode(value))\n value = value.clone(schema);\n return new Pair(key, value);\n }\n toJSON(_, ctx) {\n const pair = ctx?.mapAsMap ? new Map() : {};\n return addPairToJSMap(ctx, pair, this);\n }\n toString(ctx, onComment, onChompKeep) {\n return ctx?.doc\n ? stringifyPair(this, ctx, onComment, onChompKeep)\n : JSON.stringify(this);\n }\n}\n\nexport { Pair, createPair };\n","import { isCollection, isNode, isScalar, isSeq } from '../nodes/identity.js';\nimport { Scalar } from '../nodes/Scalar.js';\nimport { stringify } from './stringify.js';\nimport { lineComment, indentComment } from './stringifyComment.js';\n\nfunction stringifyPair({ key, value }, ctx, onComment, onChompKeep) {\n const { allNullValues, doc, indent, indentStep, options: { commentString, indentSeq, simpleKeys } } = ctx;\n let keyComment = (isNode(key) && key.comment) || null;\n if (simpleKeys) {\n if (keyComment) {\n throw new Error('With simple keys, key nodes cannot have comments');\n }\n if (isCollection(key) || (!isNode(key) && typeof key === 'object')) {\n const msg = 'With simple keys, collection cannot be used as a key value';\n throw new Error(msg);\n }\n }\n let explicitKey = !simpleKeys &&\n (!key ||\n (keyComment && value == null && !ctx.inFlow) ||\n isCollection(key) ||\n (isScalar(key)\n ? key.type === Scalar.BLOCK_FOLDED || key.type === Scalar.BLOCK_LITERAL\n : typeof key === 'object'));\n ctx = Object.assign({}, ctx, {\n allNullValues: false,\n implicitKey: !explicitKey && (simpleKeys || !allNullValues),\n indent: indent + indentStep\n });\n let keyCommentDone = false;\n let chompKeep = false;\n let str = stringify(key, ctx, () => (keyCommentDone = true), () => (chompKeep = true));\n if (!explicitKey && !ctx.inFlow && str.length > 1024) {\n if (simpleKeys)\n throw new Error('With simple keys, single line scalar must not span more than 1024 characters');\n explicitKey = true;\n }\n if (ctx.inFlow) {\n if (allNullValues || value == null) {\n if (keyCommentDone && onComment)\n onComment();\n return str === '' ? '?' : explicitKey ? `? ${str}` : str;\n }\n }\n else if ((allNullValues && !simpleKeys) || (value == null && explicitKey)) {\n str = `? ${str}`;\n if (keyComment && !keyCommentDone) {\n str += lineComment(str, ctx.indent, commentString(keyComment));\n }\n else if (chompKeep && onChompKeep)\n onChompKeep();\n return str;\n }\n if (keyCommentDone)\n keyComment = null;\n if (explicitKey) {\n if (keyComment)\n str += lineComment(str, ctx.indent, commentString(keyComment));\n str = `? ${str}\\n${indent}:`;\n }\n else {\n str = `${str}:`;\n if (keyComment)\n str += lineComment(str, ctx.indent, commentString(keyComment));\n }\n let vsb, vcb, valueComment;\n if (isNode(value)) {\n vsb = !!value.spaceBefore;\n vcb = value.commentBefore;\n valueComment = value.comment;\n }\n else {\n vsb = false;\n vcb = null;\n valueComment = null;\n if (value && typeof value === 'object')\n value = doc.createNode(value);\n }\n ctx.implicitKey = false;\n if (!explicitKey && !keyComment && isScalar(value))\n ctx.indentAtStart = str.length + 1;\n chompKeep = false;\n if (!indentSeq &&\n indentStep.length >= 2 &&\n !ctx.inFlow &&\n !explicitKey &&\n isSeq(value) &&\n !value.flow &&\n !value.tag &&\n !value.anchor) {\n // If indentSeq === false, consider '- ' as part of indentation where possible\n ctx.indent = ctx.indent.substring(2);\n }\n let valueCommentDone = false;\n const valueStr = stringify(value, ctx, () => (valueCommentDone = true), () => (chompKeep = true));\n let ws = ' ';\n if (keyComment || vsb || vcb) {\n ws = vsb ? '\\n' : '';\n if (vcb) {\n const cs = commentString(vcb);\n ws += `\\n${indentComment(cs, ctx.indent)}`;\n }\n if (valueStr === '' && !ctx.inFlow) {\n if (ws === '\\n' && valueComment)\n ws = '\\n\\n';\n }\n else {\n ws += `\\n${ctx.indent}`;\n }\n }\n else if (!explicitKey && isCollection(value)) {\n const vs0 = valueStr[0];\n const nl0 = valueStr.indexOf('\\n');\n const hasNewline = nl0 !== -1;\n const flow = ctx.inFlow ?? value.flow ?? value.items.length === 0;\n if (hasNewline || !flow) {\n let hasPropsLine = false;\n if (hasNewline && (vs0 === '&' || vs0 === '!')) {\n let sp0 = valueStr.indexOf(' ');\n if (vs0 === '&' &&\n sp0 !== -1 &&\n sp0 < nl0 &&\n valueStr[sp0 + 1] === '!') {\n sp0 = valueStr.indexOf(' ', sp0 + 1);\n }\n if (sp0 === -1 || nl0 < sp0)\n hasPropsLine = true;\n }\n if (!hasPropsLine)\n ws = `\\n${ctx.indent}`;\n }\n }\n else if (valueStr === '' || valueStr[0] === '\\n') {\n ws = '';\n }\n str += ws + valueStr;\n if (ctx.inFlow) {\n if (valueCommentDone && onComment)\n onComment();\n }\n else if (valueComment && !valueCommentDone) {\n str += lineComment(str, ctx.indent, commentString(valueComment));\n }\n else if (chompKeep && onChompKeep) {\n onChompKeep();\n }\n return str;\n}\n\nexport { stringifyPair };\n","import { isNode, isPair } from '../nodes/identity.js';\nimport { stringify } from './stringify.js';\nimport { lineComment, indentComment } from './stringifyComment.js';\n\nfunction stringifyCollection(collection, ctx, options) {\n const flow = ctx.inFlow ?? collection.flow;\n const stringify = flow ? stringifyFlowCollection : stringifyBlockCollection;\n return stringify(collection, ctx, options);\n}\nfunction stringifyBlockCollection({ comment, items }, ctx, { blockItemPrefix, flowChars, itemIndent, onChompKeep, onComment }) {\n const { indent, options: { commentString } } = ctx;\n const itemCtx = Object.assign({}, ctx, { indent: itemIndent, type: null });\n let chompKeep = false; // flag for the preceding node's status\n const lines = [];\n for (let i = 0; i < items.length; ++i) {\n const item = items[i];\n let comment = null;\n if (isNode(item)) {\n if (!chompKeep && item.spaceBefore)\n lines.push('');\n addCommentBefore(ctx, lines, item.commentBefore, chompKeep);\n if (item.comment)\n comment = item.comment;\n }\n else if (isPair(item)) {\n const ik = isNode(item.key) ? item.key : null;\n if (ik) {\n if (!chompKeep && ik.spaceBefore)\n lines.push('');\n addCommentBefore(ctx, lines, ik.commentBefore, chompKeep);\n }\n }\n chompKeep = false;\n let str = stringify(item, itemCtx, () => (comment = null), () => (chompKeep = true));\n if (comment)\n str += lineComment(str, itemIndent, commentString(comment));\n if (chompKeep && comment)\n chompKeep = false;\n lines.push(blockItemPrefix + str);\n }\n let str;\n if (lines.length === 0) {\n str = flowChars.start + flowChars.end;\n }\n else {\n str = lines[0];\n for (let i = 1; i < lines.length; ++i) {\n const line = lines[i];\n str += line ? `\\n${indent}${line}` : '\\n';\n }\n }\n if (comment) {\n str += '\\n' + indentComment(commentString(comment), indent);\n if (onComment)\n onComment();\n }\n else if (chompKeep && onChompKeep)\n onChompKeep();\n return str;\n}\nfunction stringifyFlowCollection({ items }, ctx, { flowChars, itemIndent }) {\n const { indent, indentStep, flowCollectionPadding: fcPadding, options: { commentString } } = ctx;\n itemIndent += indentStep;\n const itemCtx = Object.assign({}, ctx, {\n indent: itemIndent,\n inFlow: true,\n type: null\n });\n let reqNewline = false;\n let linesAtValue = 0;\n const lines = [];\n for (let i = 0; i < items.length; ++i) {\n const item = items[i];\n let comment = null;\n if (isNode(item)) {\n if (item.spaceBefore)\n lines.push('');\n addCommentBefore(ctx, lines, item.commentBefore, false);\n if (item.comment)\n comment = item.comment;\n }\n else if (isPair(item)) {\n const ik = isNode(item.key) ? item.key : null;\n if (ik) {\n if (ik.spaceBefore)\n lines.push('');\n addCommentBefore(ctx, lines, ik.commentBefore, false);\n if (ik.comment)\n reqNewline = true;\n }\n const iv = isNode(item.value) ? item.value : null;\n if (iv) {\n if (iv.comment)\n comment = iv.comment;\n if (iv.commentBefore)\n reqNewline = true;\n }\n else if (item.value == null && ik?.comment) {\n comment = ik.comment;\n }\n }\n if (comment)\n reqNewline = true;\n let str = stringify(item, itemCtx, () => (comment = null));\n if (i < items.length - 1)\n str += ',';\n if (comment)\n str += lineComment(str, itemIndent, commentString(comment));\n if (!reqNewline && (lines.length > linesAtValue || str.includes('\\n')))\n reqNewline = true;\n lines.push(str);\n linesAtValue = lines.length;\n }\n const { start, end } = flowChars;\n if (lines.length === 0) {\n return start + end;\n }\n else {\n if (!reqNewline) {\n const len = lines.reduce((sum, line) => sum + line.length + 2, 2);\n reqNewline = ctx.options.lineWidth > 0 && len > ctx.options.lineWidth;\n }\n if (reqNewline) {\n let str = start;\n for (const line of lines)\n str += line ? `\\n${indentStep}${indent}${line}` : '\\n';\n return `${str}\\n${indent}${end}`;\n }\n else {\n return `${start}${fcPadding}${lines.join(' ')}${fcPadding}${end}`;\n }\n }\n}\nfunction addCommentBefore({ indent, options: { commentString } }, lines, comment, chompKeep) {\n if (comment && chompKeep)\n comment = comment.replace(/^\\n+/, '');\n if (comment) {\n const ic = indentComment(commentString(comment), indent);\n lines.push(ic.trimStart()); // Avoid double indent on first line\n }\n}\n\nexport { stringifyCollection };\n","import { stringifyCollection } from '../stringify/stringifyCollection.js';\nimport { addPairToJSMap } from './addPairToJSMap.js';\nimport { Collection } from './Collection.js';\nimport { MAP, isPair, isScalar } from './identity.js';\nimport { Pair, createPair } from './Pair.js';\nimport { isScalarValue } from './Scalar.js';\n\nfunction findPair(items, key) {\n const k = isScalar(key) ? key.value : key;\n for (const it of items) {\n if (isPair(it)) {\n if (it.key === key || it.key === k)\n return it;\n if (isScalar(it.key) && it.key.value === k)\n return it;\n }\n }\n return undefined;\n}\nclass YAMLMap extends Collection {\n static get tagName() {\n return 'tag:yaml.org,2002:map';\n }\n constructor(schema) {\n super(MAP, schema);\n this.items = [];\n }\n /**\n * A generic collection parsing method that can be extended\n * to other node classes that inherit from YAMLMap\n */\n static from(schema, obj, ctx) {\n const { keepUndefined, replacer } = ctx;\n const map = new this(schema);\n const add = (key, value) => {\n if (typeof replacer === 'function')\n value = replacer.call(obj, key, value);\n else if (Array.isArray(replacer) && !replacer.includes(key))\n return;\n if (value !== undefined || keepUndefined)\n map.items.push(createPair(key, value, ctx));\n };\n if (obj instanceof Map) {\n for (const [key, value] of obj)\n add(key, value);\n }\n else if (obj && typeof obj === 'object') {\n for (const key of Object.keys(obj))\n add(key, obj[key]);\n }\n if (typeof schema.sortMapEntries === 'function') {\n map.items.sort(schema.sortMapEntries);\n }\n return map;\n }\n /**\n * Adds a value to the collection.\n *\n * @param overwrite - If not set `true`, using a key that is already in the\n * collection will throw. Otherwise, overwrites the previous value.\n */\n add(pair, overwrite) {\n let _pair;\n if (isPair(pair))\n _pair = pair;\n else if (!pair || typeof pair !== 'object' || !('key' in pair)) {\n // In TypeScript, this never happens.\n _pair = new Pair(pair, pair?.value);\n }\n else\n _pair = new Pair(pair.key, pair.value);\n const prev = findPair(this.items, _pair.key);\n const sortEntries = this.schema?.sortMapEntries;\n if (prev) {\n if (!overwrite)\n throw new Error(`Key ${_pair.key} already set`);\n // For scalars, keep the old node & its comments and anchors\n if (isScalar(prev.value) && isScalarValue(_pair.value))\n prev.value.value = _pair.value;\n else\n prev.value = _pair.value;\n }\n else if (sortEntries) {\n const i = this.items.findIndex(item => sortEntries(_pair, item) < 0);\n if (i === -1)\n this.items.push(_pair);\n else\n this.items.splice(i, 0, _pair);\n }\n else {\n this.items.push(_pair);\n }\n }\n delete(key) {\n const it = findPair(this.items, key);\n if (!it)\n return false;\n const del = this.items.splice(this.items.indexOf(it), 1);\n return del.length > 0;\n }\n get(key, keepScalar) {\n const it = findPair(this.items, key);\n const node = it?.value;\n return (!keepScalar && isScalar(node) ? node.value : node) ?? undefined;\n }\n has(key) {\n return !!findPair(this.items, key);\n }\n set(key, value) {\n this.add(new Pair(key, value), true);\n }\n /**\n * @param ctx - Conversion context, originally set in Document#toJS()\n * @param {Class} Type - If set, forces the returned collection type\n * @returns Instance of Type, Map, or Object\n */\n toJSON(_, ctx, Type) {\n const map = Type ? new Type() : ctx?.mapAsMap ? new Map() : {};\n if (ctx?.onCreate)\n ctx.onCreate(map);\n for (const item of this.items)\n addPairToJSMap(ctx, map, item);\n return map;\n }\n toString(ctx, onComment, onChompKeep) {\n if (!ctx)\n return JSON.stringify(this);\n for (const item of this.items) {\n if (!isPair(item))\n throw new Error(`Map items must all be pairs; found ${JSON.stringify(item)} instead`);\n }\n if (!ctx.allNullValues && this.hasAllNullValues(false))\n ctx = Object.assign({}, ctx, { allNullValues: true });\n return stringifyCollection(this, ctx, {\n blockItemPrefix: '',\n flowChars: { start: '{', end: '}' },\n itemIndent: ctx.indent || '',\n onChompKeep,\n onComment\n });\n }\n}\n\nexport { YAMLMap, findPair };\n","import { isMap } from '../../nodes/identity.js';\nimport { YAMLMap } from '../../nodes/YAMLMap.js';\n\nconst map = {\n collection: 'map',\n default: true,\n nodeClass: YAMLMap,\n tag: 'tag:yaml.org,2002:map',\n resolve(map, onError) {\n if (!isMap(map))\n onError('Expected a mapping for this tag');\n return map;\n },\n createNode: (schema, obj, ctx) => YAMLMap.from(schema, obj, ctx)\n};\n\nexport { map };\n","import { createNode } from '../doc/createNode.js';\nimport { stringifyCollection } from '../stringify/stringifyCollection.js';\nimport { Collection } from './Collection.js';\nimport { SEQ, isScalar } from './identity.js';\nimport { isScalarValue } from './Scalar.js';\nimport { toJS } from './toJS.js';\n\nclass YAMLSeq extends Collection {\n static get tagName() {\n return 'tag:yaml.org,2002:seq';\n }\n constructor(schema) {\n super(SEQ, schema);\n this.items = [];\n }\n add(value) {\n this.items.push(value);\n }\n /**\n * Removes a value from the collection.\n *\n * `key` must contain a representation of an integer for this to succeed.\n * It may be wrapped in a `Scalar`.\n *\n * @returns `true` if the item was found and removed.\n */\n delete(key) {\n const idx = asItemIndex(key);\n if (typeof idx !== 'number')\n return false;\n const del = this.items.splice(idx, 1);\n return del.length > 0;\n }\n get(key, keepScalar) {\n const idx = asItemIndex(key);\n if (typeof idx !== 'number')\n return undefined;\n const it = this.items[idx];\n return !keepScalar && isScalar(it) ? it.value : it;\n }\n /**\n * Checks if the collection includes a value with the key `key`.\n *\n * `key` must contain a representation of an integer for this to succeed.\n * It may be wrapped in a `Scalar`.\n */\n has(key) {\n const idx = asItemIndex(key);\n return typeof idx === 'number' && idx < this.items.length;\n }\n /**\n * Sets a value in this collection. For `!!set`, `value` needs to be a\n * boolean to add/remove the item from the set.\n *\n * If `key` does not contain a representation of an integer, this will throw.\n * It may be wrapped in a `Scalar`.\n */\n set(key, value) {\n const idx = asItemIndex(key);\n if (typeof idx !== 'number')\n throw new Error(`Expected a valid index, not ${key}.`);\n const prev = this.items[idx];\n if (isScalar(prev) && isScalarValue(value))\n prev.value = value;\n else\n this.items[idx] = value;\n }\n toJSON(_, ctx) {\n const seq = [];\n if (ctx?.onCreate)\n ctx.onCreate(seq);\n let i = 0;\n for (const item of this.items)\n seq.push(toJS(item, String(i++), ctx));\n return seq;\n }\n toString(ctx, onComment, onChompKeep) {\n if (!ctx)\n return JSON.stringify(this);\n return stringifyCollection(this, ctx, {\n blockItemPrefix: '- ',\n flowChars: { start: '[', end: ']' },\n itemIndent: (ctx.indent || '') + ' ',\n onChompKeep,\n onComment\n });\n }\n static from(schema, obj, ctx) {\n const { replacer } = ctx;\n const seq = new this(schema);\n if (obj && Symbol.iterator in Object(obj)) {\n let i = 0;\n for (let it of obj) {\n if (typeof replacer === 'function') {\n const key = obj instanceof Set ? it : String(i++);\n it = replacer.call(obj, key, it);\n }\n seq.items.push(createNode(it, undefined, ctx));\n }\n }\n return seq;\n }\n}\nfunction asItemIndex(key) {\n let idx = isScalar(key) ? key.value : key;\n if (idx && typeof idx === 'string')\n idx = Number(idx);\n return typeof idx === 'number' && Number.isInteger(idx) && idx >= 0\n ? idx\n : null;\n}\n\nexport { YAMLSeq };\n","import { isSeq } from '../../nodes/identity.js';\nimport { YAMLSeq } from '../../nodes/YAMLSeq.js';\n\nconst seq = {\n collection: 'seq',\n default: true,\n nodeClass: YAMLSeq,\n tag: 'tag:yaml.org,2002:seq',\n resolve(seq, onError) {\n if (!isSeq(seq))\n onError('Expected a sequence for this tag');\n return seq;\n },\n createNode: (schema, obj, ctx) => YAMLSeq.from(schema, obj, ctx)\n};\n\nexport { seq };\n","import { stringifyString } from '../../stringify/stringifyString.js';\n\nconst string = {\n identify: value => typeof value === 'string',\n default: true,\n tag: 'tag:yaml.org,2002:str',\n resolve: str => str,\n stringify(item, ctx, onComment, onChompKeep) {\n ctx = Object.assign({ actualString: true }, ctx);\n return stringifyString(item, ctx, onComment, onChompKeep);\n }\n};\n\nexport { string };\n","import { Scalar } from '../../nodes/Scalar.js';\n\nconst nullTag = {\n identify: value => value == null,\n createNode: () => new Scalar(null),\n default: true,\n tag: 'tag:yaml.org,2002:null',\n test: /^(?:~|[Nn]ull|NULL)?$/,\n resolve: () => new Scalar(null),\n stringify: ({ source }, ctx) => typeof source === 'string' && nullTag.test.test(source)\n ? source\n : ctx.options.nullStr\n};\n\nexport { nullTag };\n","import { Scalar } from '../../nodes/Scalar.js';\n\nconst boolTag = {\n identify: value => typeof value === 'boolean',\n default: true,\n tag: 'tag:yaml.org,2002:bool',\n test: /^(?:[Tt]rue|TRUE|[Ff]alse|FALSE)$/,\n resolve: str => new Scalar(str[0] === 't' || str[0] === 'T'),\n stringify({ source, value }, ctx) {\n if (source && boolTag.test.test(source)) {\n const sv = source[0] === 't' || source[0] === 'T';\n if (value === sv)\n return source;\n }\n return value ? ctx.options.trueStr : ctx.options.falseStr;\n }\n};\n\nexport { boolTag };\n","function stringifyNumber({ format, minFractionDigits, tag, value }) {\n if (typeof value === 'bigint')\n return String(value);\n const num = typeof value === 'number' ? value : Number(value);\n if (!isFinite(num))\n return isNaN(num) ? '.nan' : num < 0 ? '-.inf' : '.inf';\n let n = Object.is(value, -0) ? '-0' : JSON.stringify(value);\n if (!format &&\n minFractionDigits &&\n (!tag || tag === 'tag:yaml.org,2002:float') &&\n /^\\d/.test(n)) {\n let i = n.indexOf('.');\n if (i < 0) {\n i = n.length;\n n += '.';\n }\n let d = minFractionDigits - (n.length - i - 1);\n while (d-- > 0)\n n += '0';\n }\n return n;\n}\n\nexport { stringifyNumber };\n","import { Scalar } from '../../nodes/Scalar.js';\nimport { stringifyNumber } from '../../stringify/stringifyNumber.js';\n\nconst floatNaN = {\n identify: value => typeof value === 'number',\n default: true,\n tag: 'tag:yaml.org,2002:float',\n test: /^(?:[-+]?\\.(?:inf|Inf|INF)|\\.nan|\\.NaN|\\.NAN)$/,\n resolve: str => str.slice(-3).toLowerCase() === 'nan'\n ? NaN\n : str[0] === '-'\n ? Number.NEGATIVE_INFINITY\n : Number.POSITIVE_INFINITY,\n stringify: stringifyNumber\n};\nconst floatExp = {\n identify: value => typeof value === 'number',\n default: true,\n tag: 'tag:yaml.org,2002:float',\n format: 'EXP',\n test: /^[-+]?(?:\\.[0-9]+|[0-9]+(?:\\.[0-9]*)?)[eE][-+]?[0-9]+$/,\n resolve: str => parseFloat(str),\n stringify(node) {\n const num = Number(node.value);\n return isFinite(num) ? num.toExponential() : stringifyNumber(node);\n }\n};\nconst float = {\n identify: value => typeof value === 'number',\n default: true,\n tag: 'tag:yaml.org,2002:float',\n test: /^[-+]?(?:\\.[0-9]+|[0-9]+\\.[0-9]*)$/,\n resolve(str) {\n const node = new Scalar(parseFloat(str));\n const dot = str.indexOf('.');\n if (dot !== -1 && str[str.length - 1] === '0')\n node.minFractionDigits = str.length - dot - 1;\n return node;\n },\n stringify: stringifyNumber\n};\n\nexport { float, floatExp, floatNaN };\n","import { stringifyNumber } from '../../stringify/stringifyNumber.js';\n\nconst intIdentify = (value) => typeof value === 'bigint' || Number.isInteger(value);\nconst intResolve = (str, offset, radix, { intAsBigInt }) => (intAsBigInt ? BigInt(str) : parseInt(str.substring(offset), radix));\nfunction intStringify(node, radix, prefix) {\n const { value } = node;\n if (intIdentify(value) && value >= 0)\n return prefix + value.toString(radix);\n return stringifyNumber(node);\n}\nconst intOct = {\n identify: value => intIdentify(value) && value >= 0,\n default: true,\n tag: 'tag:yaml.org,2002:int',\n format: 'OCT',\n test: /^0o[0-7]+$/,\n resolve: (str, _onError, opt) => intResolve(str, 2, 8, opt),\n stringify: node => intStringify(node, 8, '0o')\n};\nconst int = {\n identify: intIdentify,\n default: true,\n tag: 'tag:yaml.org,2002:int',\n test: /^[-+]?[0-9]+$/,\n resolve: (str, _onError, opt) => intResolve(str, 0, 10, opt),\n stringify: stringifyNumber\n};\nconst intHex = {\n identify: value => intIdentify(value) && value >= 0,\n default: true,\n tag: 'tag:yaml.org,2002:int',\n format: 'HEX',\n test: /^0x[0-9a-fA-F]+$/,\n resolve: (str, _onError, opt) => intResolve(str, 2, 16, opt),\n stringify: node => intStringify(node, 16, '0x')\n};\n\nexport { int, intHex, intOct };\n","import { map } from '../common/map.js';\nimport { nullTag } from '../common/null.js';\nimport { seq } from '../common/seq.js';\nimport { string } from '../common/string.js';\nimport { boolTag } from './bool.js';\nimport { floatNaN, floatExp, float } from './float.js';\nimport { intOct, int, intHex } from './int.js';\n\nconst schema = [\n map,\n seq,\n string,\n nullTag,\n boolTag,\n intOct,\n int,\n intHex,\n floatNaN,\n floatExp,\n float\n];\n\nexport { schema };\n","import { Scalar } from '../../nodes/Scalar.js';\nimport { map } from '../common/map.js';\nimport { seq } from '../common/seq.js';\n\nfunction intIdentify(value) {\n return typeof value === 'bigint' || Number.isInteger(value);\n}\nconst stringifyJSON = ({ value }) => JSON.stringify(value);\nconst jsonScalars = [\n {\n identify: value => typeof value === 'string',\n default: true,\n tag: 'tag:yaml.org,2002:str',\n resolve: str => str,\n stringify: stringifyJSON\n },\n {\n identify: value => value == null,\n createNode: () => new Scalar(null),\n default: true,\n tag: 'tag:yaml.org,2002:null',\n test: /^null$/,\n resolve: () => null,\n stringify: stringifyJSON\n },\n {\n identify: value => typeof value === 'boolean',\n default: true,\n tag: 'tag:yaml.org,2002:bool',\n test: /^true$|^false$/,\n resolve: str => str === 'true',\n stringify: stringifyJSON\n },\n {\n identify: intIdentify,\n default: true,\n tag: 'tag:yaml.org,2002:int',\n test: /^-?(?:0|[1-9][0-9]*)$/,\n resolve: (str, _onError, { intAsBigInt }) => intAsBigInt ? BigInt(str) : parseInt(str, 10),\n stringify: ({ value }) => intIdentify(value) ? value.toString() : JSON.stringify(value)\n },\n {\n identify: value => typeof value === 'number',\n default: true,\n tag: 'tag:yaml.org,2002:float',\n test: /^-?(?:0|[1-9][0-9]*)(?:\\.[0-9]*)?(?:[eE][-+]?[0-9]+)?$/,\n resolve: str => parseFloat(str),\n stringify: stringifyJSON\n }\n];\nconst jsonError = {\n default: true,\n tag: '',\n test: /^/,\n resolve(str, onError) {\n onError(`Unresolved plain scalar ${JSON.stringify(str)}`);\n return str;\n }\n};\nconst schema = [map, seq].concat(jsonScalars, jsonError);\n\nexport { schema };\n","import { Scalar } from '../../nodes/Scalar.js';\nimport { stringifyString } from '../../stringify/stringifyString.js';\n\nconst binary = {\n identify: value => value instanceof Uint8Array, // Buffer inherits from Uint8Array\n default: false,\n tag: 'tag:yaml.org,2002:binary',\n /**\n * Returns a Buffer in node and an Uint8Array in browsers\n *\n * To use the resulting buffer as an image, you'll want to do something like:\n *\n * const blob = new Blob([buffer], { type: 'image/jpeg' })\n * document.querySelector('#photo').src = URL.createObjectURL(blob)\n */\n resolve(src, onError) {\n if (typeof atob === 'function') {\n // On IE 11, atob() can't handle newlines\n const str = atob(src.replace(/[\\n\\r]/g, ''));\n const buffer = new Uint8Array(str.length);\n for (let i = 0; i < str.length; ++i)\n buffer[i] = str.charCodeAt(i);\n return buffer;\n }\n else {\n onError('This environment does not support reading binary tags; either Buffer or atob is required');\n return src;\n }\n },\n stringify({ comment, type, value }, ctx, onComment, onChompKeep) {\n if (!value)\n return '';\n const buf = value; // checked earlier by binary.identify()\n let str;\n if (typeof btoa === 'function') {\n let s = '';\n for (let i = 0; i < buf.length; ++i)\n s += String.fromCharCode(buf[i]);\n str = btoa(s);\n }\n else {\n throw new Error('This environment does not support writing binary tags; either Buffer or btoa is required');\n }\n type ?? (type = Scalar.BLOCK_LITERAL);\n if (type !== Scalar.QUOTE_DOUBLE) {\n const lineWidth = Math.max(ctx.options.lineWidth - ctx.indent.length, ctx.options.minContentWidth);\n const n = Math.ceil(str.length / lineWidth);\n const lines = new Array(n);\n for (let i = 0, o = 0; i < n; ++i, o += lineWidth) {\n lines[i] = str.substr(o, lineWidth);\n }\n str = lines.join(type === Scalar.BLOCK_LITERAL ? '\\n' : ' ');\n }\n return stringifyString({ comment, type, value: str }, ctx, onComment, onChompKeep);\n }\n};\n\nexport { binary };\n","import { isSeq, isPair, isMap } from '../../nodes/identity.js';\nimport { createPair, Pair } from '../../nodes/Pair.js';\nimport { Scalar } from '../../nodes/Scalar.js';\nimport { YAMLSeq } from '../../nodes/YAMLSeq.js';\n\nfunction resolvePairs(seq, onError) {\n if (isSeq(seq)) {\n for (let i = 0; i < seq.items.length; ++i) {\n let item = seq.items[i];\n if (isPair(item))\n continue;\n else if (isMap(item)) {\n if (item.items.length > 1)\n onError('Each pair must have its own sequence indicator');\n const pair = item.items[0] || new Pair(new Scalar(null));\n if (item.commentBefore)\n pair.key.commentBefore = pair.key.commentBefore\n ? `${item.commentBefore}\\n${pair.key.commentBefore}`\n : item.commentBefore;\n if (item.comment) {\n const cn = pair.value ?? pair.key;\n cn.comment = cn.comment\n ? `${item.comment}\\n${cn.comment}`\n : item.comment;\n }\n item = pair;\n }\n seq.items[i] = isPair(item) ? item : new Pair(item);\n }\n }\n else\n onError('Expected a sequence for this tag');\n return seq;\n}\nfunction createPairs(schema, iterable, ctx) {\n const { replacer } = ctx;\n const pairs = new YAMLSeq(schema);\n pairs.tag = 'tag:yaml.org,2002:pairs';\n let i = 0;\n if (iterable && Symbol.iterator in Object(iterable))\n for (let it of iterable) {\n if (typeof replacer === 'function')\n it = replacer.call(iterable, String(i++), it);\n let key, value;\n if (Array.isArray(it)) {\n if (it.length === 2) {\n key = it[0];\n value = it[1];\n }\n else\n throw new TypeError(`Expected [key, value] tuple: ${it}`);\n }\n else if (it && it instanceof Object) {\n const keys = Object.keys(it);\n if (keys.length === 1) {\n key = keys[0];\n value = it[key];\n }\n else {\n throw new TypeError(`Expected tuple with one key, not ${keys.length} keys`);\n }\n }\n else {\n key = it;\n }\n pairs.items.push(createPair(key, value, ctx));\n }\n return pairs;\n}\nconst pairs = {\n collection: 'seq',\n default: false,\n tag: 'tag:yaml.org,2002:pairs',\n resolve: resolvePairs,\n createNode: createPairs\n};\n\nexport { createPairs, pairs, resolvePairs };\n","import { isScalar, isPair } from '../../nodes/identity.js';\nimport { toJS } from '../../nodes/toJS.js';\nimport { YAMLMap } from '../../nodes/YAMLMap.js';\nimport { YAMLSeq } from '../../nodes/YAMLSeq.js';\nimport { resolvePairs, createPairs } from './pairs.js';\n\nclass YAMLOMap extends YAMLSeq {\n constructor() {\n super();\n this.add = YAMLMap.prototype.add.bind(this);\n this.delete = YAMLMap.prototype.delete.bind(this);\n this.get = YAMLMap.prototype.get.bind(this);\n this.has = YAMLMap.prototype.has.bind(this);\n this.set = YAMLMap.prototype.set.bind(this);\n this.tag = YAMLOMap.tag;\n }\n /**\n * If `ctx` is given, the return type is actually `Map<unknown, unknown>`,\n * but TypeScript won't allow widening the signature of a child method.\n */\n toJSON(_, ctx) {\n if (!ctx)\n return super.toJSON(_);\n const map = new Map();\n if (ctx?.onCreate)\n ctx.onCreate(map);\n for (const pair of this.items) {\n let key, value;\n if (isPair(pair)) {\n key = toJS(pair.key, '', ctx);\n value = toJS(pair.value, key, ctx);\n }\n else {\n key = toJS(pair, '', ctx);\n }\n if (map.has(key))\n throw new Error('Ordered maps must not include duplicate keys');\n map.set(key, value);\n }\n return map;\n }\n static from(schema, iterable, ctx) {\n const pairs = createPairs(schema, iterable, ctx);\n const omap = new this();\n omap.items = pairs.items;\n return omap;\n }\n}\nYAMLOMap.tag = 'tag:yaml.org,2002:omap';\nconst omap = {\n collection: 'seq',\n identify: value => value instanceof Map,\n nodeClass: YAMLOMap,\n default: false,\n tag: 'tag:yaml.org,2002:omap',\n resolve(seq, onError) {\n const pairs = resolvePairs(seq, onError);\n const seenKeys = [];\n for (const { key } of pairs.items) {\n if (isScalar(key)) {\n if (seenKeys.includes(key.value)) {\n onError(`Ordered maps must not include duplicate keys: ${key.value}`);\n }\n else {\n seenKeys.push(key.value);\n }\n }\n }\n return Object.assign(new YAMLOMap(), pairs);\n },\n createNode: (schema, iterable, ctx) => YAMLOMap.from(schema, iterable, ctx)\n};\n\nexport { YAMLOMap, omap };\n","import { Scalar } from '../../nodes/Scalar.js';\n\nfunction boolStringify({ value, source }, ctx) {\n const boolObj = value ? trueTag : falseTag;\n if (source && boolObj.test.test(source))\n return source;\n return value ? ctx.options.trueStr : ctx.options.falseStr;\n}\nconst trueTag = {\n identify: value => value === true,\n default: true,\n tag: 'tag:yaml.org,2002:bool',\n test: /^(?:Y|y|[Yy]es|YES|[Tt]rue|TRUE|[Oo]n|ON)$/,\n resolve: () => new Scalar(true),\n stringify: boolStringify\n};\nconst falseTag = {\n identify: value => value === false,\n default: true,\n tag: 'tag:yaml.org,2002:bool',\n test: /^(?:N|n|[Nn]o|NO|[Ff]alse|FALSE|[Oo]ff|OFF)$/,\n resolve: () => new Scalar(false),\n stringify: boolStringify\n};\n\nexport { falseTag, trueTag };\n","import { Scalar } from '../../nodes/Scalar.js';\nimport { stringifyNumber } from '../../stringify/stringifyNumber.js';\n\nconst floatNaN = {\n identify: value => typeof value === 'number',\n default: true,\n tag: 'tag:yaml.org,2002:float',\n test: /^(?:[-+]?\\.(?:inf|Inf|INF)|\\.nan|\\.NaN|\\.NAN)$/,\n resolve: (str) => str.slice(-3).toLowerCase() === 'nan'\n ? NaN\n : str[0] === '-'\n ? Number.NEGATIVE_INFINITY\n : Number.POSITIVE_INFINITY,\n stringify: stringifyNumber\n};\nconst floatExp = {\n identify: value => typeof value === 'number',\n default: true,\n tag: 'tag:yaml.org,2002:float',\n format: 'EXP',\n test: /^[-+]?(?:[0-9][0-9_]*)?(?:\\.[0-9_]*)?[eE][-+]?[0-9]+$/,\n resolve: (str) => parseFloat(str.replace(/_/g, '')),\n stringify(node) {\n const num = Number(node.value);\n return isFinite(num) ? num.toExponential() : stringifyNumber(node);\n }\n};\nconst float = {\n identify: value => typeof value === 'number',\n default: true,\n tag: 'tag:yaml.org,2002:float',\n test: /^[-+]?(?:[0-9][0-9_]*)?\\.[0-9_]*$/,\n resolve(str) {\n const node = new Scalar(parseFloat(str.replace(/_/g, '')));\n const dot = str.indexOf('.');\n if (dot !== -1) {\n const f = str.substring(dot + 1).replace(/_/g, '');\n if (f[f.length - 1] === '0')\n node.minFractionDigits = f.length;\n }\n return node;\n },\n stringify: stringifyNumber\n};\n\nexport { float, floatExp, floatNaN };\n","import { stringifyNumber } from '../../stringify/stringifyNumber.js';\n\nconst intIdentify = (value) => typeof value === 'bigint' || Number.isInteger(value);\nfunction intResolve(str, offset, radix, { intAsBigInt }) {\n const sign = str[0];\n if (sign === '-' || sign === '+')\n offset += 1;\n str = str.substring(offset).replace(/_/g, '');\n if (intAsBigInt) {\n switch (radix) {\n case 2:\n str = `0b${str}`;\n break;\n case 8:\n str = `0o${str}`;\n break;\n case 16:\n str = `0x${str}`;\n break;\n }\n const n = BigInt(str);\n return sign === '-' ? BigInt(-1) * n : n;\n }\n const n = parseInt(str, radix);\n return sign === '-' ? -1 * n : n;\n}\nfunction intStringify(node, radix, prefix) {\n const { value } = node;\n if (intIdentify(value)) {\n const str = value.toString(radix);\n return value < 0 ? '-' + prefix + str.substr(1) : prefix + str;\n }\n return stringifyNumber(node);\n}\nconst intBin = {\n identify: intIdentify,\n default: true,\n tag: 'tag:yaml.org,2002:int',\n format: 'BIN',\n test: /^[-+]?0b[0-1_]+$/,\n resolve: (str, _onError, opt) => intResolve(str, 2, 2, opt),\n stringify: node => intStringify(node, 2, '0b')\n};\nconst intOct = {\n identify: intIdentify,\n default: true,\n tag: 'tag:yaml.org,2002:int',\n format: 'OCT',\n test: /^[-+]?0[0-7_]+$/,\n resolve: (str, _onError, opt) => intResolve(str, 1, 8, opt),\n stringify: node => intStringify(node, 8, '0')\n};\nconst int = {\n identify: intIdentify,\n default: true,\n tag: 'tag:yaml.org,2002:int',\n test: /^[-+]?[0-9][0-9_]*$/,\n resolve: (str, _onError, opt) => intResolve(str, 0, 10, opt),\n stringify: stringifyNumber\n};\nconst intHex = {\n identify: intIdentify,\n default: true,\n tag: 'tag:yaml.org,2002:int',\n format: 'HEX',\n test: /^[-+]?0x[0-9a-fA-F_]+$/,\n resolve: (str, _onError, opt) => intResolve(str, 2, 16, opt),\n stringify: node => intStringify(node, 16, '0x')\n};\n\nexport { int, intBin, intHex, intOct };\n","import { isMap, isPair, isScalar } from '../../nodes/identity.js';\nimport { Pair, createPair } from '../../nodes/Pair.js';\nimport { YAMLMap, findPair } from '../../nodes/YAMLMap.js';\n\nclass YAMLSet extends YAMLMap {\n constructor(schema) {\n super(schema);\n this.tag = YAMLSet.tag;\n }\n add(key) {\n let pair;\n if (isPair(key))\n pair = key;\n else if (key &&\n typeof key === 'object' &&\n 'key' in key &&\n 'value' in key &&\n key.value === null)\n pair = new Pair(key.key, null);\n else\n pair = new Pair(key, null);\n const prev = findPair(this.items, pair.key);\n if (!prev)\n this.items.push(pair);\n }\n /**\n * If `keepPair` is `true`, returns the Pair matching `key`.\n * Otherwise, returns the value of that Pair's key.\n */\n get(key, keepPair) {\n const pair = findPair(this.items, key);\n return !keepPair && isPair(pair)\n ? isScalar(pair.key)\n ? pair.key.value\n : pair.key\n : pair;\n }\n set(key, value) {\n if (typeof value !== 'boolean')\n throw new Error(`Expected boolean value for set(key, value) in a YAML set, not ${typeof value}`);\n const prev = findPair(this.items, key);\n if (prev && !value) {\n this.items.splice(this.items.indexOf(prev), 1);\n }\n else if (!prev && value) {\n this.items.push(new Pair(key));\n }\n }\n toJSON(_, ctx) {\n return super.toJSON(_, ctx, Set);\n }\n toString(ctx, onComment, onChompKeep) {\n if (!ctx)\n return JSON.stringify(this);\n if (this.hasAllNullValues(true))\n return super.toString(Object.assign({}, ctx, { allNullValues: true }), onComment, onChompKeep);\n else\n throw new Error('Set items must all have null values');\n }\n static from(schema, iterable, ctx) {\n const { replacer } = ctx;\n const set = new this(schema);\n if (iterable && Symbol.iterator in Object(iterable))\n for (let value of iterable) {\n if (typeof replacer === 'function')\n value = replacer.call(iterable, value, value);\n set.items.push(createPair(value, null, ctx));\n }\n return set;\n }\n}\nYAMLSet.tag = 'tag:yaml.org,2002:set';\nconst set = {\n collection: 'map',\n identify: value => value instanceof Set,\n nodeClass: YAMLSet,\n default: false,\n tag: 'tag:yaml.org,2002:set',\n createNode: (schema, iterable, ctx) => YAMLSet.from(schema, iterable, ctx),\n resolve(map, onError) {\n if (isMap(map)) {\n if (map.hasAllNullValues(true))\n return Object.assign(new YAMLSet(), map);\n else\n onError('Set items must all have null values');\n }\n else\n onError('Expected a mapping for this tag');\n return map;\n }\n};\n\nexport { YAMLSet, set };\n","import { stringifyNumber } from '../../stringify/stringifyNumber.js';\n\n/** Internal types handle bigint as number, because TS can't figure it out. */\nfunction parseSexagesimal(str, asBigInt) {\n const sign = str[0];\n const parts = sign === '-' || sign === '+' ? str.substring(1) : str;\n const num = (n) => asBigInt ? BigInt(n) : Number(n);\n const res = parts\n .replace(/_/g, '')\n .split(':')\n .reduce((res, p) => res * num(60) + num(p), num(0));\n return (sign === '-' ? num(-1) * res : res);\n}\n/**\n * hhhh:mm:ss.sss\n *\n * Internal types handle bigint as number, because TS can't figure it out.\n */\nfunction stringifySexagesimal(node) {\n let { value } = node;\n let num = (n) => n;\n if (typeof value === 'bigint')\n num = n => BigInt(n);\n else if (isNaN(value) || !isFinite(value))\n return stringifyNumber(node);\n let sign = '';\n if (value < 0) {\n sign = '-';\n value *= num(-1);\n }\n const _60 = num(60);\n const parts = [value % _60]; // seconds, including ms\n if (value < 60) {\n parts.unshift(0); // at least one : is required\n }\n else {\n value = (value - parts[0]) / _60;\n parts.unshift(value % _60); // minutes\n if (value >= 60) {\n value = (value - parts[0]) / _60;\n parts.unshift(value); // hours\n }\n }\n return (sign +\n parts\n .map(n => String(n).padStart(2, '0'))\n .join(':')\n .replace(/000000\\d*$/, '') // % 60 may introduce error\n );\n}\nconst intTime = {\n identify: value => typeof value === 'bigint' || Number.isInteger(value),\n default: true,\n tag: 'tag:yaml.org,2002:int',\n format: 'TIME',\n test: /^[-+]?[0-9][0-9_]*(?::[0-5]?[0-9])+$/,\n resolve: (str, _onError, { intAsBigInt }) => parseSexagesimal(str, intAsBigInt),\n stringify: stringifySexagesimal\n};\nconst floatTime = {\n identify: value => typeof value === 'number',\n default: true,\n tag: 'tag:yaml.org,2002:float',\n format: 'TIME',\n test: /^[-+]?[0-9][0-9_]*(?::[0-5]?[0-9])+\\.[0-9_]*$/,\n resolve: str => parseSexagesimal(str, false),\n stringify: stringifySexagesimal\n};\nconst timestamp = {\n identify: value => value instanceof Date,\n default: true,\n tag: 'tag:yaml.org,2002:timestamp',\n // If the time zone is omitted, the timestamp is assumed to be specified in UTC. The time part\n // may be omitted altogether, resulting in a date format. In such a case, the time part is\n // assumed to be 00:00:00Z (start of day, UTC).\n test: RegExp('^([0-9]{4})-([0-9]{1,2})-([0-9]{1,2})' + // YYYY-Mm-Dd\n '(?:' + // time is optional\n '(?:t|T|[ \\\\t]+)' + // t | T | whitespace\n '([0-9]{1,2}):([0-9]{1,2}):([0-9]{1,2}(\\\\.[0-9]+)?)' + // Hh:Mm:Ss(.ss)?\n '(?:[ \\\\t]*(Z|[-+][012]?[0-9](?::[0-9]{2})?))?' + // Z | +5 | -03:30\n ')?$'),\n resolve(str) {\n const match = str.match(timestamp.test);\n if (!match)\n throw new Error('!!timestamp expects a date, starting with yyyy-mm-dd');\n const [, year, month, day, hour, minute, second] = match.map(Number);\n const millisec = match[7] ? Number((match[7] + '00').substr(1, 3)) : 0;\n let date = Date.UTC(year, month - 1, day, hour || 0, minute || 0, second || 0, millisec);\n const tz = match[8];\n if (tz && tz !== 'Z') {\n let d = parseSexagesimal(tz, false);\n if (Math.abs(d) < 30)\n d *= 60;\n date -= 60000 * d;\n }\n return new Date(date);\n },\n stringify: ({ value }) => value?.toISOString().replace(/(T00:00:00)?\\.000Z$/, '') ?? ''\n};\n\nexport { floatTime, intTime, timestamp };\n","import { map } from '../common/map.js';\nimport { nullTag } from '../common/null.js';\nimport { seq } from '../common/seq.js';\nimport { string } from '../common/string.js';\nimport { binary } from './binary.js';\nimport { trueTag, falseTag } from './bool.js';\nimport { floatNaN, floatExp, float } from './float.js';\nimport { intBin, intOct, int, intHex } from './int.js';\nimport { merge } from './merge.js';\nimport { omap } from './omap.js';\nimport { pairs } from './pairs.js';\nimport { set } from './set.js';\nimport { intTime, floatTime, timestamp } from './timestamp.js';\n\nconst schema = [\n map,\n seq,\n string,\n nullTag,\n trueTag,\n falseTag,\n intBin,\n intOct,\n int,\n intHex,\n floatNaN,\n floatExp,\n float,\n binary,\n merge,\n omap,\n pairs,\n set,\n intTime,\n floatTime,\n timestamp\n];\n\nexport { schema };\n","import { map } from './common/map.js';\nimport { nullTag } from './common/null.js';\nimport { seq } from './common/seq.js';\nimport { string } from './common/string.js';\nimport { boolTag } from './core/bool.js';\nimport { floatNaN, floatExp, float } from './core/float.js';\nimport { intOct, intHex, int } from './core/int.js';\nimport { schema } from './core/schema.js';\nimport { schema as schema$1 } from './json/schema.js';\nimport { binary } from './yaml-1.1/binary.js';\nimport { merge } from './yaml-1.1/merge.js';\nimport { omap } from './yaml-1.1/omap.js';\nimport { pairs } from './yaml-1.1/pairs.js';\nimport { schema as schema$2 } from './yaml-1.1/schema.js';\nimport { set } from './yaml-1.1/set.js';\nimport { timestamp, intTime, floatTime } from './yaml-1.1/timestamp.js';\n\nconst schemas = new Map([\n ['core', schema],\n ['failsafe', [map, seq, string]],\n ['json', schema$1],\n ['yaml11', schema$2],\n ['yaml-1.1', schema$2]\n]);\nconst tagsByName = {\n binary,\n bool: boolTag,\n float,\n floatExp,\n floatNaN,\n floatTime,\n int,\n intHex,\n intOct,\n intTime,\n map,\n merge,\n null: nullTag,\n omap,\n pairs,\n seq,\n set,\n timestamp\n};\nconst coreKnownTags = {\n 'tag:yaml.org,2002:binary': binary,\n 'tag:yaml.org,2002:merge': merge,\n 'tag:yaml.org,2002:omap': omap,\n 'tag:yaml.org,2002:pairs': pairs,\n 'tag:yaml.org,2002:set': set,\n 'tag:yaml.org,2002:timestamp': timestamp\n};\nfunction getTags(customTags, schemaName, addMergeTag) {\n const schemaTags = schemas.get(schemaName);\n if (schemaTags && !customTags) {\n return addMergeTag && !schemaTags.includes(merge)\n ? schemaTags.concat(merge)\n : schemaTags.slice();\n }\n let tags = schemaTags;\n if (!tags) {\n if (Array.isArray(customTags))\n tags = [];\n else {\n const keys = Array.from(schemas.keys())\n .filter(key => key !== 'yaml11')\n .map(key => JSON.stringify(key))\n .join(', ');\n throw new Error(`Unknown schema \"${schemaName}\"; use one of ${keys} or define customTags array`);\n }\n }\n if (Array.isArray(customTags)) {\n for (const tag of customTags)\n tags = tags.concat(tag);\n }\n else if (typeof customTags === 'function') {\n tags = customTags(tags.slice());\n }\n if (addMergeTag)\n tags = tags.concat(merge);\n return tags.reduce((tags, tag) => {\n const tagObj = typeof tag === 'string' ? tagsByName[tag] : tag;\n if (!tagObj) {\n const tagName = JSON.stringify(tag);\n const keys = Object.keys(tagsByName)\n .map(key => JSON.stringify(key))\n .join(', ');\n throw new Error(`Unknown custom tag ${tagName}; use one of ${keys}`);\n }\n if (!tags.includes(tagObj))\n tags.push(tagObj);\n return tags;\n }, []);\n}\n\nexport { coreKnownTags, getTags };\n","class YAMLError extends Error {\n constructor(name, pos, code, message) {\n super();\n this.name = name;\n this.code = code;\n this.message = message;\n this.pos = pos;\n }\n}\nclass YAMLParseError extends YAMLError {\n constructor(pos, code, message) {\n super('YAMLParseError', pos, code, message);\n }\n}\nclass YAMLWarning extends YAMLError {\n constructor(pos, code, message) {\n super('YAMLWarning', pos, code, message);\n }\n}\nconst prettifyError = (src, lc) => (error) => {\n if (error.pos[0] === -1)\n return;\n error.linePos = error.pos.map(pos => lc.linePos(pos));\n const { line, col } = error.linePos[0];\n error.message += ` at line ${line}, column ${col}`;\n let ci = col - 1;\n let lineStr = src\n .substring(lc.lineStarts[line - 1], lc.lineStarts[line])\n .replace(/[\\n\\r]+$/, '');\n // Trim to max 80 chars, keeping col position near the middle\n if (ci >= 60 && lineStr.length > 80) {\n const trimStart = Math.min(ci - 39, lineStr.length - 79);\n lineStr = '…' + lineStr.substring(trimStart);\n ci -= trimStart - 1;\n }\n if (lineStr.length > 80)\n lineStr = lineStr.substring(0, 79) + '…';\n // Include previous line in context if pointing at line start\n if (line > 1 && /^ *$/.test(lineStr.substring(0, ci))) {\n // Regexp won't match if start is trimmed\n let prev = src.substring(lc.lineStarts[line - 2], lc.lineStarts[line - 1]);\n if (prev.length > 80)\n prev = prev.substring(0, 79) + '…\\n';\n lineStr = prev + lineStr;\n }\n if (/[^ ]/.test(lineStr)) {\n let count = 1;\n const end = error.linePos[1];\n if (end?.line === line && end.col > col) {\n count = Math.max(1, Math.min(end.col - col, 80 - ci));\n }\n const pointer = ' '.repeat(ci) + '^'.repeat(count);\n error.message += `:\\n\\n${lineStr}\\n${pointer}\\n`;\n }\n};\n\nexport { YAMLError, YAMLParseError, YAMLWarning, prettifyError };\n","const BREAK = Symbol('break visit');\nconst SKIP = Symbol('skip children');\nconst REMOVE = Symbol('remove item');\n/**\n * Apply a visitor to a CST document or item.\n *\n * Walks through the tree (depth-first) starting from the root, calling a\n * `visitor` function with two arguments when entering each item:\n * - `item`: The current item, which included the following members:\n * - `start: SourceToken[]` – Source tokens before the key or value,\n * possibly including its anchor or tag.\n * - `key?: Token | null` – Set for pair values. May then be `null`, if\n * the key before the `:` separator is empty.\n * - `sep?: SourceToken[]` – Source tokens between the key and the value,\n * which should include the `:` map value indicator if `value` is set.\n * - `value?: Token` – The value of a sequence item, or of a map pair.\n * - `path`: The steps from the root to the current node, as an array of\n * `['key' | 'value', number]` tuples.\n *\n * The return value of the visitor may be used to control the traversal:\n * - `undefined` (default): Do nothing and continue\n * - `visit.SKIP`: Do not visit the children of this token, continue with\n * next sibling\n * - `visit.BREAK`: Terminate traversal completely\n * - `visit.REMOVE`: Remove the current item, then continue with the next one\n * - `number`: Set the index of the next step. This is useful especially if\n * the index of the current token has changed.\n * - `function`: Define the next visitor for this item. After the original\n * visitor is called on item entry, next visitors are called after handling\n * a non-empty `key` and when exiting the item.\n */\nfunction visit(cst, visitor) {\n if ('type' in cst && cst.type === 'document')\n cst = { start: cst.start, value: cst.value };\n _visit(Object.freeze([]), cst, visitor);\n}\n// Without the `as symbol` casts, TS declares these in the `visit`\n// namespace using `var`, but then complains about that because\n// `unique symbol` must be `const`.\n/** Terminate visit traversal completely */\nvisit.BREAK = BREAK;\n/** Do not visit the children of the current item */\nvisit.SKIP = SKIP;\n/** Remove the current item */\nvisit.REMOVE = REMOVE;\n/** Find the item at `path` from `cst` as the root */\nvisit.itemAtPath = (cst, path) => {\n let item = cst;\n for (const [field, index] of path) {\n const tok = item?.[field];\n if (tok && 'items' in tok) {\n item = tok.items[index];\n }\n else\n return undefined;\n }\n return item;\n};\n/**\n * Get the immediate parent collection of the item at `path` from `cst` as the root.\n *\n * Throws an error if the collection is not found, which should never happen if the item itself exists.\n */\nvisit.parentCollection = (cst, path) => {\n const parent = visit.itemAtPath(cst, path.slice(0, -1));\n const field = path[path.length - 1][0];\n const coll = parent?.[field];\n if (coll && 'items' in coll)\n return coll;\n throw new Error('Parent collection not found');\n};\nfunction _visit(path, item, visitor) {\n let ctrl = visitor(item, path);\n if (typeof ctrl === 'symbol')\n return ctrl;\n for (const field of ['key', 'value']) {\n const token = item[field];\n if (token && 'items' in token) {\n for (let i = 0; i < token.items.length; ++i) {\n const ci = _visit(Object.freeze(path.concat([[field, i]])), token.items[i], visitor);\n if (typeof ci === 'number')\n i = ci - 1;\n else if (ci === BREAK)\n return BREAK;\n else if (ci === REMOVE) {\n token.items.splice(i, 1);\n i -= 1;\n }\n }\n if (typeof ctrl === 'function' && field === 'key')\n ctrl = ctrl(item, path);\n }\n }\n return typeof ctrl === 'function' ? ctrl(item, path) : ctrl;\n}\n\nexport { visit };\n","import { Note } from \"../core\";\n\nexport enum GamakaType {\n // Kampitam (~)\n // The oscilation between 2 notes - eg p , S..n S..n S..n\n Kampitham = \"Kampitham\",\n\n // Nokku (w)\n Nokku = \"Nokku\",\n\n // Spuritham (∴ / u+2234) - Stress on the second note of a jantai\n Spuritham = \"Spuritham\",\n\n // Prathyagatham (∵ / u+2235) - Similar to reverse of Spuritham (in descending order)\n Prathyagatham = \"Prathyagatham\",\n\n // Raavi (^)\n Aahaatam_Raavi = \"Raavi\",\n\n // Kandippu (✓)\n // eg - Shankarabharanam's S. ,,, n , P ,,, - where the n is subtle\n Aahaatam_Kandippu = \"Kandippu\",\n\n // Vali (⌒ - U+2312)\n Vaali = \"Vaali\",\n\n // Odukkal (x):\n // A veena gamakam where the note itself is stretched more to get the next\n // note effect (instead of plucking the next note itself).\n // Not possible where plucking of strings is not possible.\n // On voice etc it just will sound like an Eetra Jaaru.\n Odukkal = \"Odukkal\",\n\n // (/) Ascension from one note to another - eg S / P\n Jaaru_Eetra = \"EetraJaaru\",\n\n // (\\) Descending from one note to another - eg P \\ S\n Jaaru_Irakka = \"IrakkaJaaru\",\n\n // Orikkai (γ)\n // eg S~~ RN N~~S.D D~~~NP\n Orikkai = \"Orikkai\",\n}\n\nexport class Gamaka {\n constructor(public readonly type: GamakaType) {}\n debugValue(): any {\n return { type: this.type };\n }\n}\n\nexport class JaaruGamaka extends Gamaka {\n constructor(\n public readonly ascending = true,\n public readonly startingNote: null | Note = null,\n ) {\n super(ascending ? GamakaType.Jaaru_Eetra : GamakaType.Jaaru_Irakka);\n }\n\n debugValue(): any {\n const out = { ...super.debugValue(), ascending: this.ascending };\n if (this.startingNote) out[\"startingNote\"] = this.startingNote.debugValue();\n return out;\n }\n}\n\nexport function parseEmbelishment(value: string): [any, boolean] {\n value = value.substring(1);\n if (value == \"\") {\n return [new Gamaka(GamakaType.Kampitham), true];\n } else if (value == \"^\") {\n return [new Gamaka(GamakaType.Aahaatam_Raavi), true];\n } else if (value == \"~\") {\n return [new Gamaka(GamakaType.Vaali), true];\n } else if (value == \"w\" || value == \"W\") {\n return [new Gamaka(GamakaType.Nokku), true];\n } else if (value == \"∴\" || value == \":-\") {\n return [new Gamaka(GamakaType.Spuritham), true];\n } else if (value == \"∵\" || value == \"-:\") {\n return [new Gamaka(GamakaType.Prathyagatham), true];\n } else if (value == \"✓\" || value == \"./\" || value == \".\\\\\") {\n return [new Gamaka(GamakaType.Aahaatam_Kandippu), true];\n } else if (value.endsWith(\"/\")) {\n value = value.substring(0, value.length - 1).trim();\n return [new JaaruGamaka(true, value.length > 0 ? new Note(value) : null), true];\n } else if (value.endsWith(\"\\\\\")) {\n value = value.substring(0, value.length - 1);\n return [new JaaruGamaka(false, value.length > 0 ? new Note(value) : null), true];\n } else if (value == \"x\") {\n return [new Gamaka(GamakaType.Odukkal), true];\n } else if (value == \"γ\" || value == \"Y\") {\n return [new Gamaka(GamakaType.Orikkai), true];\n }\n // throw new Error(\"Invalid carnatic embelishment: \" + value);\n return [null, false];\n}\n","import { BOM, DOCUMENT, FLOW_END, SCALAR } from './cst.js';\n\n/*\nSTART -> stream\n\nstream\n directive -> line-end -> stream\n indent + line-end -> stream\n [else] -> line-start\n\nline-end\n comment -> line-end\n newline -> .\n input-end -> END\n\nline-start\n doc-start -> doc\n doc-end -> stream\n [else] -> indent -> block-start\n\nblock-start\n seq-item-start -> block-start\n explicit-key-start -> block-start\n map-value-start -> block-start\n [else] -> doc\n\ndoc\n line-end -> line-start\n spaces -> doc\n anchor -> doc\n tag -> doc\n flow-start -> flow -> doc\n flow-end -> error -> doc\n seq-item-start -> error -> doc\n explicit-key-start -> error -> doc\n map-value-start -> doc\n alias -> doc\n quote-start -> quoted-scalar -> doc\n block-scalar-header -> line-end -> block-scalar(min) -> line-start\n [else] -> plain-scalar(false, min) -> doc\n\nflow\n line-end -> flow\n spaces -> flow\n anchor -> flow\n tag -> flow\n flow-start -> flow -> flow\n flow-end -> .\n seq-item-start -> error -> flow\n explicit-key-start -> flow\n map-value-start -> flow\n alias -> flow\n quote-start -> quoted-scalar -> flow\n comma -> flow\n [else] -> plain-scalar(true, 0) -> flow\n\nquoted-scalar\n quote-end -> .\n [else] -> quoted-scalar\n\nblock-scalar(min)\n newline + peek(indent < min) -> .\n [else] -> block-scalar(min)\n\nplain-scalar(is-flow, min)\n scalar-end(is-flow) -> .\n peek(newline + (indent < min)) -> .\n [else] -> plain-scalar(min)\n*/\nfunction isEmpty(ch) {\n switch (ch) {\n case undefined:\n case ' ':\n case '\\n':\n case '\\r':\n case '\\t':\n return true;\n default:\n return false;\n }\n}\nconst hexDigits = new Set('0123456789ABCDEFabcdef');\nconst tagChars = new Set(\"0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz-#;/?:@&=+$_.!~*'()\");\nconst flowIndicatorChars = new Set(',[]{}');\nconst invalidAnchorChars = new Set(' ,[]{}\\n\\r\\t');\nconst isNotAnchorChar = (ch) => !ch || invalidAnchorChars.has(ch);\n/**\n * Splits an input string into lexical tokens, i.e. smaller strings that are\n * easily identifiable by `tokens.tokenType()`.\n *\n * Lexing starts always in a \"stream\" context. Incomplete input may be buffered\n * until a complete token can be emitted.\n *\n * In addition to slices of the original input, the following control characters\n * may also be emitted:\n *\n * - `\\x02` (Start of Text): A document starts with the next token\n * - `\\x18` (Cancel): Unexpected end of flow-mode (indicates an error)\n * - `\\x1f` (Unit Separator): Next token is a scalar value\n * - `\\u{FEFF}` (Byte order mark): Emitted separately outside documents\n */\nclass Lexer {\n constructor() {\n /**\n * Flag indicating whether the end of the current buffer marks the end of\n * all input\n */\n this.atEnd = false;\n /**\n * Explicit indent set in block scalar header, as an offset from the current\n * minimum indent, so e.g. set to 1 from a header `|2+`. Set to -1 if not\n * explicitly set.\n */\n this.blockScalarIndent = -1;\n /**\n * Block scalars that include a + (keep) chomping indicator in their header\n * include trailing empty lines, which are otherwise excluded from the\n * scalar's contents.\n */\n this.blockScalarKeep = false;\n /** Current input */\n this.buffer = '';\n /**\n * Flag noting whether the map value indicator : can immediately follow this\n * node within a flow context.\n */\n this.flowKey = false;\n /** Count of surrounding flow collection levels. */\n this.flowLevel = 0;\n /**\n * Minimum level of indentation required for next lines to be parsed as a\n * part of the current scalar value.\n */\n this.indentNext = 0;\n /** Indentation level of the current line. */\n this.indentValue = 0;\n /** Position of the next \\n character. */\n this.lineEndPos = null;\n /** Stores the state of the lexer if reaching the end of incpomplete input */\n this.next = null;\n /** A pointer to `buffer`; the current position of the lexer. */\n this.pos = 0;\n }\n /**\n * Generate YAML tokens from the `source` string. If `incomplete`,\n * a part of the last line may be left as a buffer for the next call.\n *\n * @returns A generator of lexical tokens\n */\n *lex(source, incomplete = false) {\n if (source) {\n if (typeof source !== 'string')\n throw TypeError('source is not a string');\n this.buffer = this.buffer ? this.buffer + source : source;\n this.lineEndPos = null;\n }\n this.atEnd = !incomplete;\n let next = this.next ?? 'stream';\n while (next && (incomplete || this.hasChars(1)))\n next = yield* this.parseNext(next);\n }\n atLineEnd() {\n let i = this.pos;\n let ch = this.buffer[i];\n while (ch === ' ' || ch === '\\t')\n ch = this.buffer[++i];\n if (!ch || ch === '#' || ch === '\\n')\n return true;\n if (ch === '\\r')\n return this.buffer[i + 1] === '\\n';\n return false;\n }\n charAt(n) {\n return this.buffer[this.pos + n];\n }\n continueScalar(offset) {\n let ch = this.buffer[offset];\n if (this.indentNext > 0) {\n let indent = 0;\n while (ch === ' ')\n ch = this.buffer[++indent + offset];\n if (ch === '\\r') {\n const next = this.buffer[indent + offset + 1];\n if (next === '\\n' || (!next && !this.atEnd))\n return offset + indent + 1;\n }\n return ch === '\\n' || indent >= this.indentNext || (!ch && !this.atEnd)\n ? offset + indent\n : -1;\n }\n if (ch === '-' || ch === '.') {\n const dt = this.buffer.substr(offset, 3);\n if ((dt === '---' || dt === '...') && isEmpty(this.buffer[offset + 3]))\n return -1;\n }\n return offset;\n }\n getLine() {\n let end = this.lineEndPos;\n if (typeof end !== 'number' || (end !== -1 && end < this.pos)) {\n end = this.buffer.indexOf('\\n', this.pos);\n this.lineEndPos = end;\n }\n if (end === -1)\n return this.atEnd ? this.buffer.substring(this.pos) : null;\n if (this.buffer[end - 1] === '\\r')\n end -= 1;\n return this.buffer.substring(this.pos, end);\n }\n hasChars(n) {\n return this.pos + n <= this.buffer.length;\n }\n setNext(state) {\n this.buffer = this.buffer.substring(this.pos);\n this.pos = 0;\n this.lineEndPos = null;\n this.next = state;\n return null;\n }\n peek(n) {\n return this.buffer.substr(this.pos, n);\n }\n *parseNext(next) {\n switch (next) {\n case 'stream':\n return yield* this.parseStream();\n case 'line-start':\n return yield* this.parseLineStart();\n case 'block-start':\n return yield* this.parseBlockStart();\n case 'doc':\n return yield* this.parseDocument();\n case 'flow':\n return yield* this.parseFlowCollection();\n case 'quoted-scalar':\n return yield* this.parseQuotedScalar();\n case 'block-scalar':\n return yield* this.parseBlockScalar();\n case 'plain-scalar':\n return yield* this.parsePlainScalar();\n }\n }\n *parseStream() {\n let line = this.getLine();\n if (line === null)\n return this.setNext('stream');\n if (line[0] === BOM) {\n yield* this.pushCount(1);\n line = line.substring(1);\n }\n if (line[0] === '%') {\n let dirEnd = line.length;\n let cs = line.indexOf('#');\n while (cs !== -1) {\n const ch = line[cs - 1];\n if (ch === ' ' || ch === '\\t') {\n dirEnd = cs - 1;\n break;\n }\n else {\n cs = line.indexOf('#', cs + 1);\n }\n }\n while (true) {\n const ch = line[dirEnd - 1];\n if (ch === ' ' || ch === '\\t')\n dirEnd -= 1;\n else\n break;\n }\n const n = (yield* this.pushCount(dirEnd)) + (yield* this.pushSpaces(true));\n yield* this.pushCount(line.length - n); // possible comment\n this.pushNewline();\n return 'stream';\n }\n if (this.atLineEnd()) {\n const sp = yield* this.pushSpaces(true);\n yield* this.pushCount(line.length - sp);\n yield* this.pushNewline();\n return 'stream';\n }\n yield DOCUMENT;\n return yield* this.parseLineStart();\n }\n *parseLineStart() {\n const ch = this.charAt(0);\n if (!ch && !this.atEnd)\n return this.setNext('line-start');\n if (ch === '-' || ch === '.') {\n if (!this.atEnd && !this.hasChars(4))\n return this.setNext('line-start');\n const s = this.peek(3);\n if ((s === '---' || s === '...') && isEmpty(this.charAt(3))) {\n yield* this.pushCount(3);\n this.indentValue = 0;\n this.indentNext = 0;\n return s === '---' ? 'doc' : 'stream';\n }\n }\n this.indentValue = yield* this.pushSpaces(false);\n if (this.indentNext > this.indentValue && !isEmpty(this.charAt(1)))\n this.indentNext = this.indentValue;\n return yield* this.parseBlockStart();\n }\n *parseBlockStart() {\n const [ch0, ch1] = this.peek(2);\n if (!ch1 && !this.atEnd)\n return this.setNext('block-start');\n if ((ch0 === '-' || ch0 === '?' || ch0 === ':') && isEmpty(ch1)) {\n const n = (yield* this.pushCount(1)) + (yield* this.pushSpaces(true));\n this.indentNext = this.indentValue + 1;\n this.indentValue += n;\n return yield* this.parseBlockStart();\n }\n return 'doc';\n }\n *parseDocument() {\n yield* this.pushSpaces(true);\n const line = this.getLine();\n if (line === null)\n return this.setNext('doc');\n let n = yield* this.pushIndicators();\n switch (line[n]) {\n case '#':\n yield* this.pushCount(line.length - n);\n // fallthrough\n case undefined:\n yield* this.pushNewline();\n return yield* this.parseLineStart();\n case '{':\n case '[':\n yield* this.pushCount(1);\n this.flowKey = false;\n this.flowLevel = 1;\n return 'flow';\n case '}':\n case ']':\n // this is an error\n yield* this.pushCount(1);\n return 'doc';\n case '*':\n yield* this.pushUntil(isNotAnchorChar);\n return 'doc';\n case '\"':\n case \"'\":\n return yield* this.parseQuotedScalar();\n case '|':\n case '>':\n n += yield* this.parseBlockScalarHeader();\n n += yield* this.pushSpaces(true);\n yield* this.pushCount(line.length - n);\n yield* this.pushNewline();\n return yield* this.parseBlockScalar();\n default:\n return yield* this.parsePlainScalar();\n }\n }\n *parseFlowCollection() {\n let nl, sp;\n let indent = -1;\n do {\n nl = yield* this.pushNewline();\n if (nl > 0) {\n sp = yield* this.pushSpaces(false);\n this.indentValue = indent = sp;\n }\n else {\n sp = 0;\n }\n sp += yield* this.pushSpaces(true);\n } while (nl + sp > 0);\n const line = this.getLine();\n if (line === null)\n return this.setNext('flow');\n if ((indent !== -1 && indent < this.indentNext && line[0] !== '#') ||\n (indent === 0 &&\n (line.startsWith('---') || line.startsWith('...')) &&\n isEmpty(line[3]))) {\n // Allowing for the terminal ] or } at the same (rather than greater)\n // indent level as the initial [ or { is technically invalid, but\n // failing here would be surprising to users.\n const atFlowEndMarker = indent === this.indentNext - 1 &&\n this.flowLevel === 1 &&\n (line[0] === ']' || line[0] === '}');\n if (!atFlowEndMarker) {\n // this is an error\n this.flowLevel = 0;\n yield FLOW_END;\n return yield* this.parseLineStart();\n }\n }\n let n = 0;\n while (line[n] === ',') {\n n += yield* this.pushCount(1);\n n += yield* this.pushSpaces(true);\n this.flowKey = false;\n }\n n += yield* this.pushIndicators();\n switch (line[n]) {\n case undefined:\n return 'flow';\n case '#':\n yield* this.pushCount(line.length - n);\n return 'flow';\n case '{':\n case '[':\n yield* this.pushCount(1);\n this.flowKey = false;\n this.flowLevel += 1;\n return 'flow';\n case '}':\n case ']':\n yield* this.pushCount(1);\n this.flowKey = true;\n this.flowLevel -= 1;\n return this.flowLevel ? 'flow' : 'doc';\n case '*':\n yield* this.pushUntil(isNotAnchorChar);\n return 'flow';\n case '\"':\n case \"'\":\n this.flowKey = true;\n return yield* this.parseQuotedScalar();\n case ':': {\n const next = this.charAt(1);\n if (this.flowKey || isEmpty(next) || next === ',') {\n this.flowKey = false;\n yield* this.pushCount(1);\n yield* this.pushSpaces(true);\n return 'flow';\n }\n }\n // fallthrough\n default:\n this.flowKey = false;\n return yield* this.parsePlainScalar();\n }\n }\n *parseQuotedScalar() {\n const quote = this.charAt(0);\n let end = this.buffer.indexOf(quote, this.pos + 1);\n if (quote === \"'\") {\n while (end !== -1 && this.buffer[end + 1] === \"'\")\n end = this.buffer.indexOf(\"'\", end + 2);\n }\n else {\n // double-quote\n while (end !== -1) {\n let n = 0;\n while (this.buffer[end - 1 - n] === '\\\\')\n n += 1;\n if (n % 2 === 0)\n break;\n end = this.buffer.indexOf('\"', end + 1);\n }\n }\n // Only looking for newlines within the quotes\n const qb = this.buffer.substring(0, end);\n let nl = qb.indexOf('\\n', this.pos);\n if (nl !== -1) {\n while (nl !== -1) {\n const cs = this.continueScalar(nl + 1);\n if (cs === -1)\n break;\n nl = qb.indexOf('\\n', cs);\n }\n if (nl !== -1) {\n // this is an error caused by an unexpected unindent\n end = nl - (qb[nl - 1] === '\\r' ? 2 : 1);\n }\n }\n if (end === -1) {\n if (!this.atEnd)\n return this.setNext('quoted-scalar');\n end = this.buffer.length;\n }\n yield* this.pushToIndex(end + 1, false);\n return this.flowLevel ? 'flow' : 'doc';\n }\n *parseBlockScalarHeader() {\n this.blockScalarIndent = -1;\n this.blockScalarKeep = false;\n let i = this.pos;\n while (true) {\n const ch = this.buffer[++i];\n if (ch === '+')\n this.blockScalarKeep = true;\n else if (ch > '0' && ch <= '9')\n this.blockScalarIndent = Number(ch) - 1;\n else if (ch !== '-')\n break;\n }\n return yield* this.pushUntil(ch => isEmpty(ch) || ch === '#');\n }\n *parseBlockScalar() {\n let nl = this.pos - 1; // may be -1 if this.pos === 0\n let indent = 0;\n let ch;\n loop: for (let i = this.pos; (ch = this.buffer[i]); ++i) {\n switch (ch) {\n case ' ':\n indent += 1;\n break;\n case '\\n':\n nl = i;\n indent = 0;\n break;\n case '\\r': {\n const next = this.buffer[i + 1];\n if (!next && !this.atEnd)\n return this.setNext('block-scalar');\n if (next === '\\n')\n break;\n } // fallthrough\n default:\n break loop;\n }\n }\n if (!ch && !this.atEnd)\n return this.setNext('block-scalar');\n if (indent >= this.indentNext) {\n if (this.blockScalarIndent === -1)\n this.indentNext = indent;\n else {\n this.indentNext =\n this.blockScalarIndent + (this.indentNext === 0 ? 1 : this.indentNext);\n }\n do {\n const cs = this.continueScalar(nl + 1);\n if (cs === -1)\n break;\n nl = this.buffer.indexOf('\\n', cs);\n } while (nl !== -1);\n if (nl === -1) {\n if (!this.atEnd)\n return this.setNext('block-scalar');\n nl = this.buffer.length;\n }\n }\n // Trailing insufficiently indented tabs are invalid.\n // To catch that during parsing, we include them in the block scalar value.\n let i = nl + 1;\n ch = this.buffer[i];\n while (ch === ' ')\n ch = this.buffer[++i];\n if (ch === '\\t') {\n while (ch === '\\t' || ch === ' ' || ch === '\\r' || ch === '\\n')\n ch = this.buffer[++i];\n nl = i - 1;\n }\n else if (!this.blockScalarKeep) {\n do {\n let i = nl - 1;\n let ch = this.buffer[i];\n if (ch === '\\r')\n ch = this.buffer[--i];\n const lastChar = i; // Drop the line if last char not more indented\n while (ch === ' ')\n ch = this.buffer[--i];\n if (ch === '\\n' && i >= this.pos && i + 1 + indent > lastChar)\n nl = i;\n else\n break;\n } while (true);\n }\n yield SCALAR;\n yield* this.pushToIndex(nl + 1, true);\n return yield* this.parseLineStart();\n }\n *parsePlainScalar() {\n const inFlow = this.flowLevel > 0;\n let end = this.pos - 1;\n let i = this.pos - 1;\n let ch;\n while ((ch = this.buffer[++i])) {\n if (ch === ':') {\n const next = this.buffer[i + 1];\n if (isEmpty(next) || (inFlow && flowIndicatorChars.has(next)))\n break;\n end = i;\n }\n else if (isEmpty(ch)) {\n let next = this.buffer[i + 1];\n if (ch === '\\r') {\n if (next === '\\n') {\n i += 1;\n ch = '\\n';\n next = this.buffer[i + 1];\n }\n else\n end = i;\n }\n if (next === '#' || (inFlow && flowIndicatorChars.has(next)))\n break;\n if (ch === '\\n') {\n const cs = this.continueScalar(i + 1);\n if (cs === -1)\n break;\n i = Math.max(i, cs - 2); // to advance, but still account for ' #'\n }\n }\n else {\n if (inFlow && flowIndicatorChars.has(ch))\n break;\n end = i;\n }\n }\n if (!ch && !this.atEnd)\n return this.setNext('plain-scalar');\n yield SCALAR;\n yield* this.pushToIndex(end + 1, true);\n return inFlow ? 'flow' : 'doc';\n }\n *pushCount(n) {\n if (n > 0) {\n yield this.buffer.substr(this.pos, n);\n this.pos += n;\n return n;\n }\n return 0;\n }\n *pushToIndex(i, allowEmpty) {\n const s = this.buffer.slice(this.pos, i);\n if (s) {\n yield s;\n this.pos += s.length;\n return s.length;\n }\n else if (allowEmpty)\n yield '';\n return 0;\n }\n *pushIndicators() {\n switch (this.charAt(0)) {\n case '!':\n return ((yield* this.pushTag()) +\n (yield* this.pushSpaces(true)) +\n (yield* this.pushIndicators()));\n case '&':\n return ((yield* this.pushUntil(isNotAnchorChar)) +\n (yield* this.pushSpaces(true)) +\n (yield* this.pushIndicators()));\n case '-': // this is an error\n case '?': // this is an error outside flow collections\n case ':': {\n const inFlow = this.flowLevel > 0;\n const ch1 = this.charAt(1);\n if (isEmpty(ch1) || (inFlow && flowIndicatorChars.has(ch1))) {\n if (!inFlow)\n this.indentNext = this.indentValue + 1;\n else if (this.flowKey)\n this.flowKey = false;\n return ((yield* this.pushCount(1)) +\n (yield* this.pushSpaces(true)) +\n (yield* this.pushIndicators()));\n }\n }\n }\n return 0;\n }\n *pushTag() {\n if (this.charAt(1) === '<') {\n let i = this.pos + 2;\n let ch = this.buffer[i];\n while (!isEmpty(ch) && ch !== '>')\n ch = this.buffer[++i];\n return yield* this.pushToIndex(ch === '>' ? i + 1 : i, false);\n }\n else {\n let i = this.pos + 1;\n let ch = this.buffer[i];\n while (ch) {\n if (tagChars.has(ch))\n ch = this.buffer[++i];\n else if (ch === '%' &&\n hexDigits.has(this.buffer[i + 1]) &&\n hexDigits.has(this.buffer[i + 2])) {\n ch = this.buffer[(i += 3)];\n }\n else\n break;\n }\n return yield* this.pushToIndex(i, false);\n }\n }\n *pushNewline() {\n const ch = this.buffer[this.pos];\n if (ch === '\\n')\n return yield* this.pushCount(1);\n else if (ch === '\\r' && this.charAt(1) === '\\n')\n return yield* this.pushCount(2);\n else\n return 0;\n }\n *pushSpaces(allowTabs) {\n let i = this.pos - 1;\n let ch;\n do {\n ch = this.buffer[++i];\n } while (ch === ' ' || (allowTabs && ch === '\\t'));\n const n = i - this.pos;\n if (n > 0) {\n yield this.buffer.substr(this.pos, n);\n this.pos = i;\n }\n return n;\n }\n *pushUntil(test) {\n let i = this.pos;\n let ch = this.buffer[i];\n while (!test(ch))\n ch = this.buffer[++i];\n return yield* this.pushToIndex(i, false);\n }\n}\n\nexport { Lexer };\n","import * as TSU from \"@panyam/tsutils\";\nimport { ZERO, Atom, LeafAtom, Group } from \"./core\";\n\n/**\n * Base class for all renderable objects.\n *\n * Shape caches properties like bounding boxes to improve performance,\n * since bounding box calculations can be expensive. This also allows\n * testing layouts and positioning without worrying about implementation details.\n */\nexport abstract class Shape {\n private static idCounter = 0;\n readonly shapeId: number = Shape.idCounter++;\n\n /**\n * Note that x and y coordinates are not always the x and y coordinates\n * of the bounding box.\n * E.g., a circle's x and y coordinates are its center point and not the\n * top left corner.\n * These \"main\" coordinates are referred to as control coordinates.\n */\n protected _x: number | null = null;\n protected _y: number | null = null;\n protected _width: number | null = null;\n protected _height: number | null = null;\n protected _bbox: TSU.Geom.Rect;\n protected _minSize: TSU.Geom.Size;\n protected parentShape: Shape | null = null;\n /** Child shapes contained within this shape */\n children: Shape[] = [];\n\n /**\n * Gets the bounding box of this shape.\n * Calculates it if it hasn't been calculated yet.\n */\n get bbox(): TSU.Geom.Rect {\n if (!this._bbox) {\n this._bbox = this.refreshBBox();\n }\n return this._bbox;\n }\n\n /**\n * Gets the minimum size of this shape.\n * This is usually the size of the bounding box.\n */\n get minSize(): TSU.Geom.Size {\n if (!this._minSize) {\n this._minSize = this.refreshMinSize();\n }\n return this._minSize;\n }\n\n /**\n * Refreshes the bounding box of this shape.\n * Called when the shape knows the bbox it is tracking cannot be trusted\n * and has to be refreshed by calling native methods.\n * @returns The refreshed bounding box\n */\n protected abstract refreshBBox(): TSU.Geom.Rect;\n\n /**\n * Refreshes the minimum size of this shape.\n * @returns The refreshed minimum size\n */\n protected abstract refreshMinSize(): TSU.Geom.Size;\n\n /**\n * Updates the bounds of this shape.\n * @param x New x coordinate, or null to keep current value\n * @param y New y coordinate, or null to keep current value\n * @param w New width, or null to keep current value\n * @param h New height, or null to keep current value\n * @returns The updated bounds values\n */\n protected abstract updateBounds(\n x: null | number,\n y: null | number,\n w: null | number,\n h: null | number,\n ): [number | null, number | null, number | null, number | null];\n\n /**\n * Invalidates the cached bounds of this shape.\n * Forces recalculation of bounding box and minimum size.\n */\n invalidateBounds(): void {\n this._minSize = null as unknown as TSU.Geom.Size;\n this._bbox = null as unknown as TSU.Geom.Rect;\n }\n\n /**\n * Sets the bounds of this shape.\n *\n * Note that null and NaN are valid values and mean the following:\n * - null: Don't change the value\n * - NaN: Set the value to null (use the bounding box's value)\n *\n * @param x New x coordinate, or null to keep current value\n * @param y New y coordinate, or null to keep current value\n * @param w New width, or null to keep current value\n * @param h New height, or null to keep current value\n * @param applyLayout Whether to apply layout immediately\n * @returns The updated bounds values\n */\n setBounds(\n x: number | null,\n y: number | null,\n w: number | null,\n h: number | null,\n applyLayout = false,\n ): [number | null, number | null, number | null, number | null] {\n if (x != null) {\n if (isNaN(x)) {\n this._x = null;\n } else {\n this._x = x;\n }\n }\n if (y != null) {\n if (isNaN(y)) {\n this._y = null;\n } else {\n this._y = y;\n }\n }\n if (w != null) {\n if (isNaN(w)) {\n this._width = null;\n } else {\n this._width = w;\n }\n }\n if (h != null) {\n if (isNaN(h)) {\n this._height = null;\n } else {\n this._height = h;\n }\n }\n const [nx, ny, nw, nh] = this.updateBounds(x, y, w, h);\n if (nx != null) {\n if (isNaN(nx)) {\n this._x = null;\n } else {\n this._x = nx;\n }\n }\n if (ny != null) {\n if (isNaN(ny)) {\n this._y = null;\n } else {\n this._y = ny;\n }\n }\n if (nw != null) {\n if (isNaN(nw)) {\n this._width = null;\n } else {\n this._width = nw;\n }\n }\n if (nh != null) {\n if (isNaN(nh)) {\n this._height = null;\n } else {\n this._height = nh;\n }\n }\n if (applyLayout) this.refreshLayout();\n // this.resetBBox();\n return [nx, ny, nw, nh];\n }\n\n /**\n * Checks if this shape has an explicit x coordinate.\n */\n get hasX(): boolean {\n return this._x != null && !isNaN(this._x);\n }\n\n /**\n * Checks if this shape has an explicit y coordinate.\n */\n get hasY(): boolean {\n return this._y != null && !isNaN(this._y);\n }\n\n /**\n * Checks if this shape has an explicit width.\n */\n get hasWidth(): boolean {\n return this._width != null && !isNaN(this._width);\n }\n\n /**\n * Checks if this shape has an explicit height.\n */\n get hasHeight(): boolean {\n return this._height != null && !isNaN(this._height);\n }\n\n /**\n * Gets the x coordinate within the parent's coordinate system.\n */\n get x(): number {\n return this._x || 0;\n }\n\n /**\n * Sets the x coordinate within the parent's coordinate system.\n */\n set x(x: number | null) {\n // Here a manual x is being set - how does this interfere with the bounding box?\n // We should _x to the new value to indicate a manual value was set.\n // and reset bbox so that based on this x a new bbox may need to be calculated\n this.setBounds(x == null ? NaN : x, null, null, null);\n }\n\n /**\n * Gets the y coordinate within the parent's coordinate system.\n */\n get y(): number {\n if (this._y != null) return this._y;\n return 0; // this.bbox.y;\n }\n\n /**\n * Sets the y coordinate within the parent's coordinate system.\n */\n set y(y: number | null) {\n this.setBounds(null, y == null ? NaN : y, null, null);\n }\n\n /**\n * Gets the width of this shape.\n */\n get width(): number {\n if (this._width != null) return this._width;\n return 0; // this.bbox.width;\n }\n\n /**\n * Sets the width of this shape.\n */\n set width(w: number | null) {\n this.setBounds(null, null, w == null ? NaN : w, null);\n }\n\n /**\n * Gets the height of this shape.\n */\n get height(): number {\n if (this._height != null) return this._height;\n return 0; // this.bbox.height;\n }\n\n /**\n * Sets the height of this shape.\n */\n set height(h: number | null) {\n this.setBounds(null, null, null, h == null ? NaN : h);\n }\n\n /**\n * Refreshes the layout of this shape.\n * Called when bounds or other properties have changed to give the shape an\n * opportunity to layout its children. For shapes with no children this is a no-op.\n */\n refreshLayout(): void {\n // throw new Error(\"Implement this\");\n }\n}\n\n/**\n * Represents an embellishment applied to a musical element.\n */\nexport abstract class Embelishment extends Shape {}\n\n/**\n * A shape that wraps an SVG element.\n * ElementShape provides the base class for all shapes that are rendered as SVG elements.\n */\nexport class ElementShape<T extends SVGGraphicsElement = SVGGraphicsElement> extends Shape {\n /**\n * Creates a new ElementShape.\n * @param element The SVG element this shape wraps\n */\n constructor(public readonly element: T) {\n super();\n }\n\n /**\n * Refreshes the bounding box of this element.\n * @returns The refreshed bounding box\n */\n protected refreshBBox(): TSU.Geom.Rect {\n return TSU.DOM.svgBBox(this.element);\n }\n\n /**\n * Refreshes the minimum size of this element.\n * @returns The refreshed minimum size\n */\n protected refreshMinSize(): TSU.Geom.Size {\n return TSU.DOM.svgBBox(this.element);\n }\n\n /**\n * Updates the bounds of this element.\n * @param x New x coordinate, or null to keep current value\n * @param y New y coordinate, or null to keep current value\n * @param w New width, or null to keep current value\n * @param h New height, or null to keep current value\n * @returns The updated bounds values\n */\n protected updateBounds(\n x: null | number,\n y: null | number,\n w: null | number,\n h: null | number,\n ): [number | null, number | null, number | null, number | null] {\n return [x, y, w, h];\n }\n\n /**\n * Refreshes the layout of this element.\n * Updates the element's attributes based on the shape's properties.\n */\n refreshLayout(): void {\n if (this.hasX) this.element.setAttribute(\"x\", \"\" + this._x);\n if (this.hasY) this.element.setAttribute(\"y\", \"\" + this._y);\n }\n}\n\n/**\n * Base class for views that represent atoms in the notation.\n * AtomView provides the visual representation of an atom.\n */\nexport abstract class AtomView extends Shape {\n /** Nesting depth of this atom in the structure */\n depth = 0;\n /** Index of the role containing this atom */\n roleIndex = 0;\n\n // LayoutMetrics for the AtomView so all atomviews laid out on the\n // same baseline will show up aligned vertically\n /** Baseline position for vertical alignment */\n baseline: number;\n /** Ascent (space above baseline) */\n ascent: number;\n /** Descent (space below baseline) */\n descent: number;\n /** Height of capital letters */\n capHeight: number;\n /** Space between lines */\n leading: number;\n\n /**\n * Checks if this atom view represents a leaf atom.\n */\n abstract isLeaf(): boolean;\n\n abstract get totalDuration(): TSU.Num.Fraction;\n\n /**\n * Returns the horizontal offset from the atom's origin to where the note glyph starts.\n * This accounts for left embellishments that appear before the note.\n * Used by GroupView to align note glyphs at their correct time positions.\n *\n * Default is 0 (glyph starts at origin). Subclasses with left embellishments\n * should override to return the width of left-side decorations.\n */\n get glyphOffset(): number {\n return 0;\n }\n\n /**\n * Creates the SVG elements needed for this atom view.\n * @param parent The parent SVG element to attach to\n */\n abstract createElements(parent: SVGGraphicsElement): void;\n}\n\n/**\n * A view for leaf atoms (those that cannot contain other atoms).\n */\nexport abstract class LeafAtomView extends AtomView {\n /**\n * Creates a new LeafAtomView.\n * @param leafAtom The leaf atom this view represents\n */\n constructor(public leafAtom: LeafAtom) {\n super();\n }\n\n /**\n * Leaf atom views always return true for isLeaf().\n */\n isLeaf(): boolean {\n return true;\n }\n\n /**\n * Gets a unique identifier for this view based on the atom's UUID.\n */\n get viewId(): number {\n return this.leafAtom.uuid;\n }\n\n /**\n * Returns the total duration of the atom rendered by this view.\n */\n get totalDuration(): TSU.Num.Fraction {\n return this.leafAtom.duration;\n }\n}\n\n/**\n * A view for group atoms that contain multiple child atoms.\n */\nexport abstract class GroupView extends AtomView {\n /** Space between atoms in this group */\n protected atomSpacing: number;\n /** The SVG group element for this view */\n protected groupElement: SVGGElement;\n /** Views for the atoms in this group */\n protected atomViews: AtomView[] = [];\n private _embelishments: Embelishment[];\n /** Whether this group represents notes by default */\n defaultToNotes = true;\n /** Whether this view needs layout */\n needsLayout = true;\n /** Scale factor for this group */\n scaleFactor = 1.0;\n /**\n * When true, shows continuation markers (\",\") for atoms with duration > 1\n * instead of just leaving empty space.\n */\n showContinuationMarkers = true;\n /** SVG elements for continuation markers */\n protected continuationMarkerElements: SVGTextElement[] = [];\n\n /**\n * Creates a new GroupView.\n * @param group The group atom this view represents\n * @param config Optional configuration object\n */\n constructor(\n public group: Group,\n config?: any,\n ) {\n super();\n this.atomSpacing = 5;\n this.setStyles(config || {});\n }\n\n /**\n * Returns the total duration of the group rendered by this view.\n */\n get totalDuration(): TSU.Num.Fraction {\n return this.group.totalChildDuration;\n }\n\n /**\n * Creates the SVG elements needed for this group view.\n * @param parent The parent SVG element to attach to\n */\n createElements(parent: SVGGraphicsElement): void {\n this.groupElement = TSU.DOM.createSVGNode(\"g\", {\n parent: parent,\n attrs: {\n class: \"groupViewRoot\",\n id: \"groupViewRoot\" + this.group.uuid,\n },\n });\n\n // now create child atom views for each atom in this Group\n for (const atom of this.group.atoms.values()) {\n const atomView = this.createAtomView(atom);\n this.atomViews.push(atomView);\n }\n this.invalidateBounds();\n }\n\n /**\n * Group views always return false for isLeaf().\n */\n isLeaf(): boolean {\n return false;\n }\n\n /**\n * Refreshes the bounding box of this group.\n * @returns The refreshed bounding box\n */\n protected refreshBBox(): TSU.Geom.Rect {\n return TSU.DOM.svgBBox(this.groupElement);\n }\n\n /**\n * Refreshes the minimum size of this group using duration-based width calculation.\n *\n * ## Duration-Based Width Algorithm\n *\n * This algorithm ensures atoms with extended durations receive proportionally\n * more horizontal space. For example, with `\\beatDuration(4)` and input `S 2 R G M`:\n * - S has duration 1, R has duration 2, G has duration 1\n * - R should visually occupy twice the horizontal space of S or G\n *\n * ### Algorithm Steps:\n *\n * 1. **Calculate width per duration unit**: For each atom, compute the visual width\n * needed per unit of duration: `(visualWidth + spacing) / duration`\n *\n * 2. **Find maximum**: Take the maximum width-per-duration across all atoms.\n * This ensures every atom has enough space for its visual content.\n *\n * 3. **Scale by total duration**: Multiply the max width-per-duration by the\n * group's total duration to get the final group width.\n *\n * ### Example:\n * ```\n * Atoms: S(dur=1, width=10px), R(dur=2, width=10px), G(dur=1, width=10px)\n * Spacing: 5px\n *\n * Width per duration:\n * S: (10 + 5) / 1 = 15 px/unit\n * R: (10 + 5) / 2 = 7.5 px/unit\n * G: (10 + 5) / 1 = 15 px/unit\n *\n * Max width per duration: 15 px/unit\n * Total duration: 1 + 2 + 1 = 4 units\n * Group width: 15 * 4 = 60px\n *\n * Positioning:\n * S at x=0 (time 0/4 * 60 = 0)\n * R at x=15 (time 1/4 * 60 = 15)\n * G at x=45 (time 3/4 * 60 = 45)\n * ```\n *\n * @returns The refreshed minimum size\n */\n protected refreshMinSize(): TSU.Geom.Size {\n let maxHeight = 0;\n\n // Step 1: Calculate width per duration unit for each atom\n let minWidthPerDuration = 0;\n this.atomViews.forEach((av) => {\n const ms = av.minSize;\n const dur = av.totalDuration;\n if (!dur.isZero) {\n const durValue = dur.num / dur.den;\n const widthPerDur = (ms.width + this.atomSpacing) / durValue;\n // Step 2: Track maximum width per duration\n minWidthPerDuration = Math.max(minWidthPerDuration, widthPerDur);\n }\n maxHeight = Math.max(maxHeight, ms.height);\n });\n\n // Step 3: Scale by total duration\n const totalDuration = this.group.totalChildDuration;\n const totalDurValue = totalDuration.num / totalDuration.den;\n const totalWidth = minWidthPerDuration * totalDurValue;\n\n return new TSU.Geom.Size(totalWidth * this.scaleFactor, maxHeight * this.scaleFactor);\n }\n\n /**\n * Creates an atom view for a specific atom.\n * @param atom The atom to create a view for\n * @returns The created atom view\n */\n abstract createAtomView(atom: Atom): AtomView;\n\n /**\n * Updates the bounds of this group.\n * @param x New x coordinate, or null to keep current value\n * @param y New y coordinate, or null to keep current value\n * @param w New width, or null to keep current value\n * @param h New height, or null to keep current value\n * @returns The updated bounds values\n */\n protected updateBounds(\n x: null | number,\n y: null | number,\n w: null | number,\n h: null | number,\n ): [number | null, number | null, number | null, number | null] {\n return [x, y, w, h];\n }\n\n /**\n * Refreshes the layout of this group using duration-based positioning.\n *\n * ## Duration-Based Positioning Algorithm\n *\n * Atoms are positioned at x-coordinates proportional to their time offset\n * within the group's total duration. This ensures that atoms with extended\n * durations visually occupy the correct amount of horizontal space.\n *\n * ### Width Source Priority:\n *\n * 1. **Column width** (preferred): If width was set via `setBounds()` from the\n * grid layout system (ColAlign), use that width. This enables global alignment\n * across all beats in the same column.\n *\n * 2. **Minimum size**: Fall back to `minSize.width` calculated by `refreshMinSize()`.\n *\n * ### Positioning Formula:\n * ```\n * xPosition = (timeOffset / totalDuration) * groupWidth\n * ```\n *\n * ### Continuation Markers:\n *\n * When `showContinuationMarkers` is true (default), atoms with duration > 1\n * will have \",\" markers rendered at each additional time slot. For example,\n * an atom with duration 2 will show \"R ,\" instead of \"R \".\n *\n * This helps users visually understand that the note continues through\n * multiple time slots without relying on empty space alone.\n *\n * ### Example:\n * ```\n * Input: S 2 R G (with beatDuration=4)\n * Group width: 60px, Total duration: 4 units\n *\n * Positioning:\n * S at x=0 (time 0, offset 0/4 * 60 = 0)\n * R at x=15 (time 1, offset 1/4 * 60 = 15)\n * \",\" at x=30 (continuation marker for R at time 2)\n * G at x=45 (time 3, offset 3/4 * 60 = 45)\n * ```\n */\n refreshLayout(): void {\n let transform = \"translate(\" + this.x + \",\" + this.y + \")\";\n if (this.scaleFactor < 1) {\n transform += \" scale(\" + this.scaleFactor + \")\";\n }\n this.groupElement.setAttribute(\"transform\", transform);\n\n const currY = 0;\n const totalDur = this.group.totalChildDuration;\n\n // Width source priority: column width (for global alignment) > minSize\n const unscaledMinWidth = this.minSize.width / this.scaleFactor;\n const groupWidth = this.hasWidth ? this.width / this.scaleFactor : unscaledMinWidth;\n\n // Clear existing continuation markers before re-rendering\n this.clearContinuationMarkers();\n\n // Position each atom based on its time offset\n let currTime = ZERO;\n this.atomViews.forEach((av, index) => {\n // Calculate where the NOTE GLYPH should appear based on time offset\n const glyphX = totalDur.isZero ? 0 : currTime.timesNum(groupWidth).divby(totalDur).floor;\n // Subtract glyphOffset so left embellishments don't push the glyph past its time position\n // The atom origin is placed earlier, so the glyph ends up at the correct time position\n const xPos = Math.max(0, glyphX - av.glyphOffset);\n av.setBounds(xPos, currY, null, null, true);\n\n // Render continuation markers for atoms with duration > 1\n if (this.showContinuationMarkers && !totalDur.isZero) {\n const atomDur = av.totalDuration;\n const durValue = atomDur.num / atomDur.den;\n if (durValue > 1) {\n // Render one marker at each additional time slot within the atom's duration\n const numMarkers = Math.floor(durValue) - 1;\n for (let i = 1; i <= numMarkers; i++) {\n // Marker time = currTime + (atomDuration * i / floor(duration))\n const markerTime = currTime.plus(atomDur.timesNum(i).divbyNum(Math.floor(durValue)));\n const markerX = markerTime.timesNum(groupWidth).divby(totalDur).floor;\n this.renderContinuationMarker(markerX, currY);\n }\n }\n }\n\n currTime = currTime.plus(av.totalDuration);\n });\n\n this.invalidateBounds();\n for (const e of this.embelishments) e.refreshLayout();\n this.invalidateBounds();\n }\n\n /**\n * Clears all continuation marker elements.\n */\n protected clearContinuationMarkers(): void {\n for (const el of this.continuationMarkerElements) {\n el.remove();\n }\n this.continuationMarkerElements = [];\n }\n\n /**\n * Renders a continuation marker (\",\") at the specified position.\n * @param x X position for the marker\n * @param y Y position for the marker\n */\n protected renderContinuationMarker(x: number, y: number): void {\n const marker = TSU.DOM.createSVGNode(\"text\", {\n parent: this.groupElement,\n attrs: {\n class: \"continuationMarker\",\n x: x.toString(),\n y: y.toString(),\n },\n text: \",\",\n }) as SVGTextElement;\n this.continuationMarkerElements.push(marker);\n }\n\n /**\n * Gets the embellishments for this group.\n */\n get embelishments(): Embelishment[] {\n if (!this._embelishments) {\n this._embelishments = this.createEmbelishments();\n }\n return this._embelishments;\n }\n\n /**\n * Creates the embellishments for this group.\n * @returns An array of embellishments\n */\n protected createEmbelishments(): Embelishment[] {\n return [];\n }\n\n /**\n * Sets the styles for this group.\n * @param config Style configuration object\n */\n setStyles(config: any): void {\n if (\"atomSpacing\" in config) this.atomSpacing = config.atomSpacing;\n if (\"showContinuationMarkers\" in config) this.showContinuationMarkers = config.showContinuationMarkers;\n this.needsLayout = true;\n }\n}\n","import * as TSU from \"@panyam/tsutils\";\nimport * as TLEX from \"tlex\";\nimport { load as loadGrammar, TokenHandler } from \"./dsl\";\nimport { makeParseTable } from \"./ptables\";\nimport { Parser, ParseTable } from \"./lr\";\nimport { LRItemGraph } from \"./lritems\";\nimport { logParserDebug } from \"./debug\";\n\n/**\n * Configuration options for creating a parser.\n */\nexport interface ParserOptions {\n /**\n * Parser algorithm to use.\n * - \"slr\": Simple LR - smallest tables, may have false conflicts\n * - \"lalr\": Look-Ahead LR - default, good balance of power and size\n * - \"lr1\": Canonical LR(1) - most powerful, largest tables\n * @default \"lalr\"\n */\n type?: \"slr\" | \"lalr\" | \"lr1\";\n\n /**\n * Custom tokenizer function. If not provided, one is auto-generated\n * from %token and inline token definitions in the grammar.\n */\n tokenizer?: TLEX.NextTokenFunc;\n\n /**\n * Enable debug output.\n * - \"lexer\": Log tokenizer program\n * - \"parser\": Log parse table and state transitions\n * - \"all\": Log both lexer and parser\n */\n debug?: \"all\" | \"lexer\" | \"parser\" | string;\n\n /**\n * Use left recursion for EBNF expansions (*, +).\n * @default true\n */\n leftRecursive?: boolean;\n\n /**\n * Prefix for auxiliary non-terminals created by EBNF expansions.\n * @default \"$\"\n */\n auxNTPrefix?: string;\n\n /**\n * Custom token handlers for post-processing tokens.\n */\n tokenHandlers?: TSU.StringMap<TokenHandler>;\n}\n\n/**\n * Creates a parser from a grammar DSL string.\n *\n * This is the main entry point for creating parsers in Galore.\n *\n * @param input - Grammar definition in DSL format\n * @param params - Configuration options\n * @returns A tuple of [parser, tokenFunc, itemGraph]\n * - parser: The LR parser instance\n * - tokenFunc: The generated tokenizer (or null if custom provided)\n * - itemGraph: The LR item graph (useful for debugging)\n *\n * @example\n * ```typescript\n * import { newParser } from \"galore\";\n *\n * const [parser, tokenFunc, itemGraph] = newParser(`\n * %token NUMBER /[0-9]+/\n * %skip /[ \\\\t\\\\n]+/\n *\n * Expr -> Expr \"+\" Term | Term ;\n * Term -> NUMBER ;\n * `, { type: \"lalr\" });\n *\n * const result = parser.parse(\"1 + 2\");\n * ```\n */\nexport function newLRParser(\n input: string,\n params: ParserOptions | null = null,\n): [Parser, null | TLEX.NextTokenFunc, LRItemGraph] {\n const options = params || ({} as ParserOptions);\n const [ptable, tokenFunc, itemGraph] = newParseTable(input, options);\n const parser = new Parser(ptable);\n if (options.tokenizer || tokenFunc) {\n parser.setTokenizer(options.tokenizer || tokenFunc!);\n }\n const debug = options.debug || \"\";\n if (debug.split(\"|\").findIndex((p: string) => p == \"all\" || p == \"parser\") >= 0) {\n logParserDebug(parser, itemGraph);\n }\n return [parser, tokenFunc, itemGraph];\n}\n\n/**\n * Creates a parse table from a grammar DSL string without creating a parser.\n *\n * Useful when you need access to the parse table for analysis or visualization.\n *\n * @param input - Grammar definition in DSL format\n * @param params - Configuration options\n * @returns A tuple of [parseTable, tokenFunc, itemGraph]\n *\n * @example\n * ```typescript\n * import { newParseTable, Printers } from \"galore\";\n *\n * const [ptable, tokenFunc, itemGraph] = newParseTable(grammar, { type: \"lalr\" });\n *\n * // Check for conflicts\n * if (ptable.hasConflicts) {\n * console.log(\"Conflicts:\", ptable.conflictActions);\n * }\n *\n * // Visualize the parse table\n * const html = Printers.parseTableToHtml(ptable, { itemGraph });\n * ```\n */\nexport function newParseTable(\n input: string,\n params: ParserOptions | null = null,\n): [ParseTable, null | TLEX.NextTokenFunc, LRItemGraph] {\n const options = params || ({} as ParserOptions);\n const [g, tokenFunc] = loadGrammar(input, options as any);\n g.augmentStartSymbol();\n const [ptable, itemGraph] = makeParseTable(g, options.type);\n return [ptable, tokenFunc, itemGraph];\n}\n","import { Parser, LRAction, ParseTable } from \"./lr\";\nimport { LRItemGraph } from \"./lritems\";\n\nexport function logParserDebug(parser: Parser, itemGraph?: LRItemGraph): void {\n const g = parser.grammar;\n const ptable = parser.parseTable;\n console.log(\n \"===============================\\nGrammar (as default): \\n\",\n g.debugValue.map((x, i) => `${i + 1} - ${x}`),\n \"===============================\\nGrammar (as Bison): \\n\",\n g.debugValue.map((x, i) => `${x.replace(\"->\", \":\")} ; \\n`).join(\"\"),\n \"===============================\\nParseTable: \\n\",\n JSON.stringify(mergedDebugValue(ptable, itemGraph), null, 4),\n \"===============================\\nConflicts: \\n\",\n ptable.conflictActions,\n );\n}\n\nexport function mergedDebugValue(ptable: ParseTable, itemGraph?: LRItemGraph): any {\n const merged = {} as any;\n const ptabDV = ptable.debugValue;\n const igDV = itemGraph?.debugValue;\n for (const stateId in ptabDV) {\n const actions = ptabDV[stateId];\n if (itemGraph) {\n const items = igDV[stateId];\n merged[stateId] = { items: items[\"items\"], actions: actions, goto: items[\"goto\"] };\n } else {\n merged[stateId] = actions;\n }\n }\n return merged;\n}\n"],"names":["root","factory","exports","module","define","amd","this","__webpack_require__","definition","key","o","Object","defineProperty","enumerable","get","obj","prop","prototype","hasOwnProperty","call","Entity","constructor","config","TYPE","uuid","counter","_parent","metadata","Error","parent","setParent","debugValue","type","toString","equals","another","expect","clone","out","newInstance","copyTo","TimedEntity","super","duration","assert","condition","msg","MAX_INT","Math","pow","TEvent","name","source","payload","_spawnedFrom","sourceState","cancelled","timeStamp","children","spawnedFrom","setSpawnedFrom","_rootEvent","rootEvent","spawn","child","push","State","stateData","id","enter","data","handle","event","EventEmitter","_eventHub","EventHub","eventHub","hub","oldHub","eventHubChanged","console","log","_handlers","_events","_inBatchMode","on","names","callback","_addHandler","removeOn","_removeHandler","_ensurestrings","split","map","v","trim","handlerlist","handler","forEach","evHandlers","i","length","splice","emit","evt","dispatchEvent","evtCallbacks","startBatchMode","cancelBatch","commitBatch","BATCH_EVENTS","ValueList","values","_firstChild","_lastChild","_size","pushBack","toJSON","Array","from","method","tmp","count","nextSibling","eqlFunc","size","first","tmp2","isEmpty","last","reversedValues","prevSibling","add","before","prev","pushFront","value","remove","next","popBack","popFront","Browser","gcdof","x","y","abs","t","IS_EXPLORER","navigator","userAgent","indexOf","IS_FIREFOX","IS_OPERA","toLowerCase","UAHasChrome","UAHasSafari","IS_SAFARI","IS_CHROME","Fraction","num","den","factorized","isNaN","gcd","parse","val","parts","parseInt","isWhole","isZero","isInfinity","isOne","ceil","floor","plus","plusNum","minus","minusNum","times","timesNum","divby","divbyNum","numDivby","mod","d","floorOfD","modNum","inverse","equalsNum","cmp","cmpNum","isLT","isLTE","isLTNum","isLTENum","isGT","isGTE","isGTNum","isGTENum","max","f1","f2","min","ZERO","ONE","INFINITY","Frac","a","b","TSU","CycleCursor","cycle","barIndex","beatIndex","instance","currBar","bars","result","beatLengths","beatCounts","beatCount","Bar","bl","bc","assign","instanceCount","totalBeatCount","total","Cycle","p","getAtIndex","globalIndex","offset","bar","beatLength","getPosition","globalOffset","cycleNum","realOffset","barDuration","iterateBeats","startBar","startBeat","startInstance","instanceIndex","reduce","DEFAULT","AtomType","Atom","parentGroup","isContinuation","_duration","markersBefore","mbef","m","markersAfter","maft","LeafAtom","beforeRest","splitAt","spillOver","createSpilloverSpace","Space","Marker","text","isBefore","isSilent","Literal","embelishments","embs","e","Note","octave","shift","fromLit","lit","NOTE","Group","atoms","durationIsMultiplier","addAtoms","a1","a2","atom","totalChildDuration","setDurationAsMultiplier","asMultiplier","setDuration","requiredDuration","targetGroup","remainingDur","durationFactor","lastChild","childDuration","newDuration","newRequiredDur","insertAtomsAt","removeAtoms","beforeAtom","adjustDuration","oldChildDuration","REST","GROUP","LABEL","scaleFactor","LayoutParams","beatDuration","_rowStartOffsets","_rowEndOffsets","_rowDurations","_totalLayoutDuration","_totalBeats","_beatLayouts","lineBreaks","layout","lineBreaksEqual","_lineBreaks","every","_a","getBeatLocation","beat","modIndex","index","totalBeats","cursor","refreshLayout","beatLayouts","totalLayoutDuration","cycleIter","akb","numBeats","beats","nextCP","rd","GridModel","idCounter","lastUpdatedAt","rows","rowAligns","Map","colAligns","r","firstRow","gr","numCells","rowIndex","firstCol","minCol","fc","cellsInRow","row","cell","cells","cellsInCol","col","cellAt","addRowAlign","align","set","addColAlign","addRows","insertBefore","numRows","newRow","GridRow","defaultRowAlign","addSuccessor","getRow","setValue","cellCreator","grow","GridCell","clearCellAt","GridCellEvent","CLEARED","loc","location","oldValue","_b","UPDATED","gridRow","colIndex","rowAlign","_rowAlign","addCell","colAlign","_colAlign","grid","c","coordOffset","h","maxLength","w","RowAlign","numCols","creator","filter","AlignedLine","needsLayout","_coordOffset","_maxLength","paddingBefore","paddingAfter","prevLines","nextLines","setMaxLength","setPadding","after","beforeAddingCell","removeCell","beforeRemovingCell","setOffset","cellView","getCellView","evalMaxLength","setBounds","changedCells","minSize","height","Beat","role","prevBeat","nextBeat","atomIsPlaceholder","endOffset","filled","remaining","preMarkers","curr","marker","postMarkers","allMinimalCycles","nodes","idFunc","edges","cycles","inACycle","node","startNode","visited","queue","newQueue","nextNode","edgeData","n","slice","defaultKeyFunc","IDSet","keyFunc","_entries","_entriesByKey","clear","predicate","e2","modified","l","entries","getByKey","ensure","entry","throwIfExists","has","SymbolSet","grammar","enforceSymbolType","Set","hasNull","debugString","labels","sort","join","skipAux","exp","getSymById","isAuxiliary","label","addFrom","includeNull","addTo","termid","term","isTerminal","delete","NullableSet","refresh","nonterms","beforeCount","allNonTerminals","nt","visit","rule","rulesForNT","isStrNullable","rhs","isNullable","str","fromIndex","toIndex","syms","SymSymbolSets","_count","forEachTerm","visitor","entriesFor","sym","addNull","srcEntries","destEntries","FirstSets","nullables","forEachTermIn","allNullable","j","symj","forEachRule","processRule","s","FollowSets","firstSets","g","startSymbol","Eof","Sym","auxType","precedence","assocLeft","creationId","compareTo","localeCompare","Str","append","lits","extend","strs","copy","startIndex","endIndex","numToDelete","itemsToAdd","diff","containsAt","RuleAction","isFunction","isChildPosition","Rule","action","Grammar","make","symbolSet","allRules","_rulesForNT","_followSets","_hasNull","auxNTCount","auxNTPrefix","Null","newTerm","followSets","augStartRule","_AugStartRule","augmentStartSymbol","augSym","newNT","addRule","addTerminals","terminals","nonTerminals","auxNonTerminals","allSymbols","forEachNT","rules","getRule","getSym","findRule","production","findIndex","nonterm","ensureSym","removeRules","pred","removeSymbols","newRules","newRhs","sym2","T","NT","isNT","isAuxNT","seq","exps","normalizeRule","anyof","ensureAuxNT","opt","atleast0","leftRec","auxNT","findAuxNT","which","newAuxNT","atleast1","newAuxNTName","findAuxNTByRules","ntRules","print","options","ruleSep","includeSemiColon","lambdaSymbol","terminalDerivingSymbols","nadded","allDerive","reachableSymbols","fromSymbol","reachable","ruleIndex","leftRecursion","CharClassType","charCodeAt","NINE","lA","lZ","uA","uZ","USCORE","CharClassHelper","matches","charCode","neg","res","match","CharClassHelpers","reString","spaceChars","PropertyName","PropertyValue","RegexType","CharType","OpCode","Regex","groupIndex","groupName","groupIsSilent","ignoreCase","dotAll","multiline","setOptions","isVariable","evalREString","modifiers","StartOfInput","tag","START_OF_INPUT","reverse","EndOfInput","END_OF_INPUT","Assertion","expr","cond","negate","LookAhead","LOOK_AHEAD","LookBack","LOOK_BACK","Quant","minCount","maxCount","greedy","QUANT","isUnlimited","quant","Cat","CAT","Union","UNION","option","Char","op","CHAR","ch","matchChar","LeafChar","args","Any","AnyChar","Class","charClass","CharClass","Single","SingleChar","PropertyEscape","propNameOrId","propValueOrId","SyntaxError","PropertyEscapes","String","fromCharCode","replace","CharGroup","chars","CharRange","Intersection","Range","start","end","Var","reversed","VAR","BackNamedRef","BACK_NAMED_REF","BackRef","BackNumRef","BACK_NUM_REF","skip","priority","matchIndex","activeStates","stateCanActivate","state","needsSpecificStates","isNewLineChar","Match","groups","positions","Prog","startCondition","scIsInclusive","instrs","stateMapping","registerState","opcode","char","Instr","with","initializer","instrDebugValue","InstrDebugValue","instr","comment","Thread","gen","parentId","registers","regIncr","regId","regAcquire","regRelease","regValue","VM","getState","currState","setState","prog","forward","configs","threadCounter","currThreads","nextThreads","startPos","genForOffset","savePosition","thread","pos","tapeIndex","jumpBy","delta","jumpTo","newOffset","forkTo","startGroup","newThread","endGroup","addThread","list","tape","nextCh","lastCh","Jump","Split","newOff","Save","tracer","threadQueued","GroupStart","GroupEnd","StartingChar","MLStartingChar","prevCh","EndingChar","MLEndingChar","StartOfWord","EndOfWord","RBegin","groupStart","matchSuccess","matchEnd","recurseMatch","Begin","consume","EnsureState","states","matchCurrPos","currChCodeLower","currChCodeUpper","currChCode","hasMore","charAt","startMatching","bestMatch","stepChar","startOffset","savedPos","canAdvance","newPos","currMatch","nextMatch","stepThread","advance","threadStepped","advanceTape","End","currPriority","CIChar","AnyNonNL","currCh","Compiler","regexResolver","listener","emitGroups","emitPosition","compile","ensureInstr","ind","compileExpr","currOffset","compileChar","ml","START_OF_WORD","END_OF_WORD","compileCat","compileUnion","compileQuant","compileVar","compileBackNamedRef","compileBackNumRef","compileLookAhead","compileLookBack","cat","ne","union","jumps","jmp","compileAtleast0","compileAtleast1","compileOptional","l1","l3","l2","la","begin","lb","TokenizerError","message","setPrototypeOf","UnexpectedTokenError","foundToken","expectedTokens","TapeInterface","hasIndex","toUpperCase","charCodeAtLower","charCodeAtUpper","Tape","input","_rawInput","content","substring","TapeHelper","advanceAfter","pattern","ensureNoPrefixSlash","advanceTo","lastIndex","currStart","numSlashes","prefix","success","Token","lookahead","lookback","isOneOf","expected","tok","TokenBuffer","nextToken","tokenizerContext","buffer","peek","nth","matchFunc","nextAction","token","consumeIf","expectToken","ensureToken","nextMatches","GroupCounter","current","isSpace","RegexParser","unicode","reduceLeft","stack","throwError","refNum","gtPos","clPos","parseCharGroup","rest","parseGroup","parseQuant","nchars","parseChar","depth","subExpr","currch","endch","parseEscapeChar","parseSingleChar","parsePropertyEscape","clEnd","eqPos","propStr","propName","propValue","WORD_CHAR","DIGITS","SPACES","hexSeq","hexVal","ucodeSeq","ucodeVal","sub","advanceIf","ignoreSpaces","obCount","ignoreSpaces2","foundComma","p1","p2","part1","part2","foundEq","build","exprFromJSRE","exprFromFlexRE","parser","FlexREParser","error","re","isRegExp","JSREParser","flexRE","strings","keys","raw","BaseTokenizer","_prog","_vm","onError","onMatchHandlers","matchHandlersByValue","variables","compiler","findRuleByValue","getVar","addVar","regex","currValue","find","onMatch","Builder","sortedRules","sortRules","vm","r1","r2","Tokenizer","reset","owner","startChar","err","gi","toToken","tokenize","tokens","DefaultTape","SINGLE_QUOTE_STRING","DOUBLE_QUOTE_STRING","JS_REGEX","str2regex","TokenType","NodeType","LRActionType","Loader","leftRecursive","generatedTokenizer","TLEX","regexSyntax","symbolsByLabel","newSymbolCallback","tokenHandlers","symbolForLabel","registerSymbol","ensureSymbol","assumedTerminal","currSym","et","lexer","ARROW","OPEN_SQ","CLOSE_SQ","OPEN_PAREN","CLOSE_PAREN","OPEN_BRACE","CLOSE_BRACE","STAR","PLUS","QMARK","SEMI_COLON","COLON","PIPE","COMMENT","STRING","REGEX","flags","NUMBER","PCT_IDENT","DOLLAR_NUM","DOLLAR_IDENT","IDENT","tokenizer","ntFunc","parseGrammar","parseRegex","syntax","tokPattern","RegExp","patternStr","peeked","parseDecl","parseDirective","directive","startsWith","endsWith","tokenHandler","parseTokenHandler","isDef","tokName","funcName","ident","parseProductions","parseProd","PFNode","childCount","childAt","reprString","PTNode","ParserBase","setTokenizer","tokenbuffer","SimpleParser","delegate","parseInput","ParseError","LRAction","gotoState","ACCEPT","SHIFT","REDUCE","Shift","goto","Reduce","Goto","GOTO","Accept","ParseTable","conflictActions","actions","hasConflicts","getActions","stateId","addAction","ac","fromId","symId","ParseStack","stateStack","nodeStack","top","pop","popN","L","Parser","parseTable","context","buildParseTree","copySingleChild","output","resolveActions","actionResolver","onTokenError","onNextToken","nextSym","nextValue","topState","topNode","newNode","ruleLen","childNode","beforeAddingChildNode","handlerName","ruleHandlers","onReduction","newAction","LRItem","position","pre","post","LRItemSet","ig","_key","_lookaheads","_hasLookAheads","itemGraph","addLookAhead","item","s1","s2","clearLookAheads","getLookAheads","revalKey","hasLookAheads","itemId","items","i1","i2","las","LRItemGraph","gotoSets","itemSets","startItem","startSet","evalGotoSets","currSet","gotoSet","setGoto","itemSet","newItemSet","advanceItemAndAdd","closure","itemToAdvance","fromItemSet","toItemSet","newItem","laSym","ensureGotoSet","fromSet","toSet","getGoto","forEachGoto","symid","gotoSetFor","iset","LR0ItemGraph","newset","LR1ItemGraph","B","suffix","bRules","br","makeSLRParseTable","evalLASetsForSLRItem","makeSLRAutomaton","makeParseTableFromLA","nextSet","lookaheads","lr1Item","evalLASetsForLALRItem","augGrammar","prevSets","findP","prevStates","nextState","pSet","pALabel","pA","ALIAS","Symbol","for","DOC","MAP","PAIR","SCALAR","SEQ","NODE_TYPE","isAlias","isDocument","isMap","isPair","isScalar","isSeq","isCollection","isNode","hasAnchor","anchor","BREAK","SKIP","REMOVE","visitor_","initVisitor","visit_","contents","freeze","path","ctrl","callVisitor","replaceNode","concat","ci","ck","cv","async","visitAsync","visitAsync_","Collection","Node","Value","Alias","Scalar","Seq","Pair","pt","escapeChars","escapeTagName","tn","Directives","yaml","tags","docStart","docEnd","defaultYaml","defaultTags","atDocument","version","atNextDocument","explicit","line","test","tagName","verbatim","decodeURIComponent","tagString","doc","lines","tagEntries","tagNames","some","anchorIsValid","sa","JSON","stringify","applyReviver","reviver","isArray","len","v0","v1","undefined","k","toJS","arg","ctx","aliasCount","anchors","onCreate","keep","Number","NodeBase","create","getPrototypeOf","getOwnPropertyDescriptors","range","mapAsMap","maxAliasCount","onAnchor","TypeError","mapKeyWarned","resolve","found","aliasResolveCache","_arg","ReferenceError","getAliasCount","_onComment","_onChompKeep","src","verifyAliasOrder","implicitKey","kc","vc","isScalarValue","createNode","schema","Boolean","BigInt","valueOf","aliasDuplicateObjects","onTagObj","sourceObjects","ref","tagObj","format","identify","findTagObject","iterator","nodeClass","default","collectionFromPath","isInteger","keepUndefined","BLOCK_FOLDED","BLOCK_LITERAL","PLAIN","QUOTE_DOUBLE","QUOTE_SINGLE","configurable","writable","it","addIn","done","isEmptyPath","deleteIn","getIn","keepScalar","hasAllNullValues","allowScalar","commentBefore","hasIn","setIn","stringifyComment","indentComment","indent","lineComment","includes","FOLD_FLOW","FOLD_BLOCK","FOLD_QUOTED","foldFlowLines","mode","indentAtStart","lineWidth","minContentWidth","onFold","onOverflow","endStep","folds","escapedFolds","overflow","escStart","escEnd","consumeMoreIndentedLines","fold","getFoldOptions","isBlock","containsDocumentMarker","doubleQuotedString","json","doubleQuotedAsJSON","minMultiLineLength","doubleQuotedMinMultiLineLength","code","substr","singleQuotedString","singleQuote","quotedString","qs","hasDouble","hasSingle","blockEndNewlines","blockString","onComment","onChompKeep","blockQuote","commentString","forceBlockIndent","literal","indentLength","limit","strLen","lineLengthOverLimit","chomp","endStart","endNlPos","startEnd","startWithSpace","startNlPos","header","foldedValue","literalFallback","foldOptions","body","stringifyString","inFlow","ss","_stringify","_type","actualString","indentStep","compat","plainString","defaultKeyType","defaultStringType","directives","resolvedAliases","testMatch","getTagObject","props","stringifyProps","MERGE_KEY","merge","description","addToJSMap","addMergeToJSMap","mergeValue","srcMap","addPairToJSMap","isMergeKey","jsKey","stringKey","strCtx","falseStr","flowCollectionPadding","indentSeq","nullStr","simpleKeys","trueStr","toStringOptions","collectionStyle","repeat","createStringifyContext","inStringifyKey","strKey","jsonStr","warning","logLevel","warn","stringifyKey","jsValue","createPair","_","allNullValues","keyComment","explicitKey","vsb","vcb","valueComment","keyCommentDone","chompKeep","spaceBefore","flow","valueCommentDone","valueStr","ws","vs0","nl0","hasNewline","hasPropsLine","sp0","stringifyPair","stringifyCollection","collection","stringifyFlowCollection","stringifyBlockCollection","blockItemPrefix","flowChars","itemIndent","itemCtx","addCommentBefore","ik","fcPadding","reqNewline","linesAtValue","iv","sum","ic","trimStart","findPair","YAMLMap","replacer","sortMapEntries","pair","overwrite","_pair","sortEntries","Type","YAMLSeq","idx","asItemIndex","string","nullTag","boolTag","stringifyNumber","minFractionDigits","isFinite","is","floatNaN","NaN","NEGATIVE_INFINITY","POSITIVE_INFINITY","floatExp","parseFloat","toExponential","intIdentify","intResolve","radix","intAsBigInt","intStringify","_onError","dot","stringifyJSON","binary","Uint8Array","atob","buf","btoa","resolvePairs","cn","createPairs","iterable","pairs","YAMLOMap","bind","omap","seenKeys","boolStringify","trueTag","falseTag","float","f","sign","intBin","intOct","int","intHex","YAMLSet","keepPair","parseSexagesimal","asBigInt","stringifySexagesimal","_60","unshift","padStart","intTime","floatTime","timestamp","Date","year","month","day","hour","minute","second","millisec","date","UTC","tz","toISOString","schema$1","schema$2","cst","_visit","field","GamakaType","itemAtPath","parentCollection","coll","Shape","shapeId","_x","_y","_width","_height","parentShape","bbox","_bbox","refreshBBox","_minSize","refreshMinSize","invalidateBounds","applyLayout","nx","ny","nw","nh","updateBounds","hasX","hasY","hasWidth","hasHeight","width","params","ptable","tokenFunc","eparser","debug","loadGrammar","makeLRParseTable","g2","ensureG2Sym","pi","newSymLabel","newSym","startState","transitions","buildRuleFrom","A","newSyms","xi","startSym","newA","newRHS","newRule","grammarFromLR0ItemGraph","makeLALRParseTable","makeParseTable","newParseTable","merged","ptabDV","igDV","mergedDebugValue","logParserDebug","G","toEmbelishment","emb","parseEmbelishment","errors","toCommandName","_tape","_owner","toBoolean","toNumber","toMarker","markerText","toOctavedNote","note","toRoleSelector","toLineAnnotation","toSingleLineRawString","toMultiLineRawString","endPat","endPos","toFrontMatter"],"ignoreList":[],"sourceRoot":""}
|
|
1
|
+
{"version":3,"file":"notations.umd.min.js","mappings":"CAAA,SAA2CA,EAAMC,GAC1B,iBAAZC,SAA0C,iBAAXC,OACxCA,OAAOD,QAAUD,IACQ,mBAAXG,QAAyBA,OAAOC,IAC9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gC,GAChC73B,GAET83B,cAAeA,CAAC93B,EAAmB9H,EAA0Bg/B,KAE3D,MACMhgC,EAAWgB,EAAKnf,MAChB8+C,EAASnxB,GAAgBjI,aAAavG,EAF7B,SAE6C0/B,EAC5D,GAAIC,EAAS,EACX,MAAM,IAAI3xD,MAAM,kDAIlB,OAFA85B,EAAM/yB,MAAQirB,EAAKqG,UAAUrH,EAAU2gC,GAEhC73B,O","sources":["webpack://Notations/webpack/universalModuleDefinition","webpack://Notations/webpack/bootstrap","webpack://Notations/../../src/events.ts","webpack://Notations/webpack/runtime/define property getters","webpack://Notations/webpack/runtime/hasOwnProperty shorthand","webpack://Notations/../../src/entity.ts","webpack://Notations/../../src/types.ts","webpack://Notations/../../src/constants.ts","webpack://Notations/../../../src/comms/events.ts","webpack://Notations/../../src/list.ts","webpack://Notations/../../src/geom.ts","webpack://Notations/../../src/browser.ts","webpack://Notations/../../src/dom.ts","webpack://Notations/../../src/numberutils.ts","webpack://Notations/../../src/cycle.ts","webpack://Notations/../../src/core.ts","webpack://Notations/../../src/layouts.ts","webpack://Notations/../../src/grids.ts","webpack://Notations/../../src/beats.ts","webpack://Notations/../../src/graph.ts","webpack://Notations/../../src/sets.ts","webpack://Notations/../../src/grammar.ts","webpack://Notations/../../src/charclasses.ts","webpack://Notations/../../src/propertyescapes.ts","webpack://Notations/../../src/vm.ts","webpack://Notations/../../src/compiler.ts","webpack://Notations/../../src/errors.ts","webpack://Notations/../../src/tape.ts","webpack://Notations/../../src/token.ts","webpack://Notations/../../src/utils.ts","webpack://Notations/../../src/jsparser.ts","webpack://Notations/../../src/flexparser.ts","webpack://Notations/../../src/builder.ts","webpack://Notations/../../src/tokenizer.ts","webpack://Notations/../../src/samples.ts","webpack://Notations/../../src/dsl.ts","webpack://Notations/../../src/lr.ts","webpack://Notations/../../src/parser.ts","webpack://Notations/../../src/lritems.ts","webpack://Notations/../../src/ptables.ts","webpack://Notations/./node_modules/.pnpm/yaml@2.8.2/node_modules/yaml/browser/dist/nodes/identity.js","webpack://Notations/./node_modules/.pnpm/yaml@2.8.2/node_modules/yaml/browser/dist/visit.js","webpack://Notations/./node_modules/.pnpm/yaml@2.8.2/node_modules/yaml/browser/dist/doc/directives.js","webpack://Notations/./node_modules/.pnpm/yaml@2.8.2/node_modules/yaml/browser/dist/doc/anchors.js","webpack://Notations/./node_modules/.pnpm/yaml@2.8.2/node_modules/yaml/browser/dist/doc/applyReviver.js","webpack://Notations/./node_modules/.pnpm/yaml@2.8.2/node_modules/yaml/browser/dist/nodes/toJS.js","webpack://Notations/./node_modules/.pnpm/yaml@2.8.2/node_modules/yaml/browser/dist/nodes/Node.js","webpack://Notations/./node_modules/.pnpm/yaml@2.8.2/node_modules/yaml/browser/dist/nodes/Alias.js","webpack://Notations/./node_modules/.pnpm/yaml@2.8.2/node_modules/yaml/browser/dist/nodes/Scalar.js","webpack://Notations/./node_modules/.pnpm/yaml@2.8.2/node_modules/yaml/browser/dist/doc/createNode.js","webpack://Notations/./node_modules/.pnpm/yaml@2.8.2/node_modules/yaml/browser/dist/nodes/Collection.js","webpack://Notations/./node_modules/.pnpm/yaml@2.8.2/node_modules/yaml/browser/dist/stringify/stringifyComment.js","webpack://Notations/./node_modules/.pnpm/yaml@2.8.2/node_modules/yaml/browser/dist/stringify/foldFlowLines.js","webpack://Notations/./node_modules/.pnpm/yaml@2.8.2/node_modules/yaml/browser/dist/stringify/stringifyString.js","webpack://Notations/./node_modules/.pnpm/yaml@2.8.2/node_modules/yaml/browser/dist/stringify/stringify.js","webpack://Notations/./node_modules/.pnpm/yaml@2.8.2/node_modules/yaml/browser/dist/schema/yaml-1.1/merge.js","webpack://Notations/./node_modules/.pnpm/yaml@2.8.2/node_modules/yaml/browser/dist/nodes/addPairToJSMap.js","webpack://Notations/./node_modules/.pnpm/yaml@2.8.2/node_modules/yaml/browser/dist/log.js","webpack://Notations/./node_modules/.pnpm/yaml@2.8.2/node_modules/yaml/browser/dist/nodes/Pair.js","webpack://Notations/./node_modules/.pnpm/yaml@2.8.2/node_modules/yaml/browser/dist/stringify/stringifyPair.js","webpack://Notations/./node_modules/.pnpm/yaml@2.8.2/node_modules/yaml/browser/dist/stringify/stringifyCollection.js","webpack://Notations/./node_modules/.pnpm/yaml@2.8.2/node_modules/yaml/browser/dist/nodes/YAMLMap.js","webpack://Notations/./node_modules/.pnpm/yaml@2.8.2/node_modules/yaml/browser/dist/schema/common/map.js","webpack://Notations/./node_modules/.pnpm/yaml@2.8.2/node_modules/yaml/browser/dist/nodes/YAMLSeq.js","webpack://Notations/./node_modules/.pnpm/yaml@2.8.2/node_modules/yaml/browser/dist/schema/common/seq.js","webpack://Notations/./node_modules/.pnpm/yaml@2.8.2/node_modules/yaml/browser/dist/schema/common/string.js","webpack://Notations/./node_modules/.pnpm/yaml@2.8.2/node_modules/yaml/browser/dist/schema/common/null.js","webpack://Notations/./node_modules/.pnpm/yaml@2.8.2/node_modules/yaml/browser/dist/schema/core/bool.js","webpack://Notations/./node_modules/.pnpm/yaml@2.8.2/node_modules/yaml/browser/dist/stringify/stringifyNumber.js","webpack://Notations/./node_modules/.pnpm/yaml@2.8.2/node_modules/yaml/browser/dist/schema/core/float.js","webpack://Notations/./node_modules/.pnpm/yaml@2.8.2/node_modules/yaml/browser/dist/schema/core/int.js","webpack://Notations/./node_modules/.pnpm/yaml@2.8.2/node_modules/yaml/browser/dist/schema/core/schema.js","webpack://Notations/./node_modules/.pnpm/yaml@2.8.2/node_modules/yaml/browser/dist/schema/json/schema.js","webpack://Notations/./node_modules/.pnpm/yaml@2.8.2/node_modules/yaml/browser/dist/schema/yaml-1.1/binary.js","webpack://Notations/./node_modules/.pnpm/yaml@2.8.2/node_modules/yaml/browser/dist/schema/yaml-1.1/pairs.js","webpack://Notations/./node_modules/.pnpm/yaml@2.8.2/node_modules/yaml/browser/dist/schema/yaml-1.1/omap.js","webpack://Notations/./node_modules/.pnpm/yaml@2.8.2/node_modules/yaml/browser/dist/schema/yaml-1.1/bool.js","webpack://Notations/./node_modules/.pnpm/yaml@2.8.2/node_modules/yaml/browser/dist/schema/yaml-1.1/float.js","webpack://Notations/./node_modules/.pnpm/yaml@2.8.2/node_modules/yaml/browser/dist/schema/yaml-1.1/int.js","webpack://Notations/./node_modules/.pnpm/yaml@2.8.2/node_modules/yaml/browser/dist/schema/yaml-1.1/set.js","webpack://Notations/./node_modules/.pnpm/yaml@2.8.2/node_modules/yaml/browser/dist/schema/yaml-1.1/timestamp.js","webpack://Notations/./node_modules/.pnpm/yaml@2.8.2/node_modules/yaml/browser/dist/schema/yaml-1.1/schema.js","webpack://Notations/./node_modules/.pnpm/yaml@2.8.2/node_modules/yaml/browser/dist/schema/tags.js","webpack://Notations/./node_modules/.pnpm/yaml@2.8.2/node_modules/yaml/browser/dist/errors.js","webpack://Notations/./node_modules/.pnpm/yaml@2.8.2/node_modules/yaml/browser/dist/parse/cst-visit.js","webpack://Notations/../../../src/carnatic/gamakas.ts","webpack://Notations/./node_modules/.pnpm/yaml@2.8.2/node_modules/yaml/browser/dist/parse/lexer.js","webpack://Notations/../../src/shapes.ts","webpack://Notations/../../../src/carnatic/embelishments.ts","webpack://Notations/../../../src/carnatic/atomviews.ts","webpack://Notations/../../src/factory.ts","webpack://Notations/../../src/debug.ts"],"sourcesContent":["(function webpackUniversalModuleDefinition(root, factory) {\n\tif(typeof exports === 'object' && typeof module === 'object')\n\t\tmodule.exports = factory();\n\telse if(typeof define === 'function' && define.amd)\n\t\tdefine([], factory);\n\telse if(typeof exports === 'object')\n\t\texports[\"Notations\"] = factory();\n\telse\n\t\troot[\"Notations\"] = factory();\n})(this, () => {\nreturn ","// The require scope\nvar __webpack_require__ = {};\n\n","/**\n * Model change events for incremental updates.\n *\n * This module defines the event types, interfaces, and observer patterns for\n * change notifications on model entities (Group, Role, Line, Block). These\n * events enable incremental updates to the rendering pipeline without full\n * re-renders.\n *\n * Uses the Observer pattern instead of pub/sub EventHub for:\n * - Type safety: Observers have strongly-typed method signatures\n * - Traceability: Easy to see who is observing what\n * - Explicit contracts: Clear interface between observable and observers\n *\n * Note: This module uses generic types to avoid circular dependencies with\n * core.ts and block.ts. The actual types are enforced at the call sites.\n */\n\n// ============================================\n// Event Types and Payloads\n// ============================================\n\n/**\n * Event types for Atom-related changes.\n */\nexport enum AtomChangeType {\n /** Atoms were added to the end */\n ADD = \"add\",\n /** Atoms were inserted at a specific position */\n INSERT = \"insert\",\n /** Atoms were removed */\n REMOVE = \"remove\",\n /** An atom's properties changed (duration, value, etc.) */\n UPDATE = \"update\",\n}\n\n/**\n * Event payload for atom changes in a Group or Role.\n * Generic T is typically Atom from core.ts.\n */\nexport interface AtomChangeEvent<T = any> {\n /** The type of change */\n type: AtomChangeType;\n /** The atoms that were added, inserted, or removed */\n atoms: T[];\n /** For INSERT: the index where atoms were inserted */\n index?: number;\n /** For UPDATE: the specific property that changed */\n property?: string;\n /** For UPDATE: the old value of the property */\n oldValue?: any;\n /** For UPDATE: the new value of the property */\n newValue?: any;\n}\n\n/**\n * Event types for Role-related changes on a Line.\n */\nexport enum RoleChangeType {\n /** A role was added to the line */\n ADD = \"add\",\n /** A role was removed from the line */\n REMOVE = \"remove\",\n}\n\n/**\n * Event payload for role changes on a Line.\n */\nexport interface RoleChangeEvent {\n /** The type of change */\n type: RoleChangeType;\n /** The role that was added or removed */\n roleName: string;\n}\n\n/**\n * Event types for BlockItem changes on a Block.\n */\nexport enum BlockItemChangeType {\n /** An item was added to the block */\n ADD = \"add\",\n /** An item was removed from the block */\n REMOVE = \"remove\",\n}\n\n/**\n * Event payload for block item changes.\n * Generic T is typically BlockItem (Block | Line | RawBlock) from block.ts.\n */\nexport interface BlockItemChangeEvent<T = any> {\n /** The type of change */\n type: BlockItemChangeType;\n /** The item that was added or removed */\n item: T;\n /** For ADD: the index where the item was added */\n index?: number;\n}\n\n// ============================================\n// Observer Interfaces\n// ============================================\n\n/**\n * Observer interface for Group atom changes.\n * Implement this interface to receive notifications when atoms are\n * added, inserted, or removed from a Group.\n *\n * @template TAtom The atom type (defaults to any to avoid circular deps)\n * @template TGroup The group type (defaults to any to avoid circular deps)\n */\nexport interface GroupObserver<TAtom = any, TGroup = any> {\n /**\n * Called when atoms are added to the end of the group.\n * @param group The group that changed\n * @param atoms The atoms that were added\n * @param index The index where atoms were added\n */\n onAtomsAdded?(group: TGroup, atoms: TAtom[], index: number): void;\n\n /**\n * Called when atoms are inserted at a specific position.\n * @param group The group that changed\n * @param atoms The atoms that were inserted\n * @param index The index where atoms were inserted\n */\n onAtomsInserted?(group: TGroup, atoms: TAtom[], index: number): void;\n\n /**\n * Called when atoms are removed from the group.\n * @param group The group that changed\n * @param atoms The atoms that were removed\n */\n onAtomsRemoved?(group: TGroup, atoms: TAtom[]): void;\n}\n\n/**\n * Observer interface for Role atom changes.\n * Implement this interface to receive notifications when atoms are\n * added, inserted, or removed from a Role.\n *\n * @template TAtom The atom type (defaults to any to avoid circular deps)\n * @template TRole The role type (defaults to any to avoid circular deps)\n */\nexport interface RoleObserver<TAtom = any, TRole = any> {\n /**\n * Called when atoms are added to the end of the role.\n * @param role The role that changed\n * @param atoms The atoms that were added\n * @param index The index where atoms were added\n */\n onAtomsAdded?(role: TRole, atoms: TAtom[], index: number): void;\n\n /**\n * Called when atoms are inserted at a specific position.\n * @param role The role that changed\n * @param atoms The atoms that were inserted\n * @param index The index where atoms were inserted\n */\n onAtomsInserted?(role: TRole, atoms: TAtom[], index: number): void;\n\n /**\n * Called when atoms are removed from the role.\n * @param role The role that changed\n * @param atoms The atoms that were removed\n */\n onAtomsRemoved?(role: TRole, atoms: TAtom[]): void;\n}\n\n/**\n * Observer interface for Line role changes.\n * Implement this interface to receive notifications when roles are\n * added or removed from a Line.\n *\n * @template TRole The role type (defaults to any to avoid circular deps)\n * @template TLine The line type (defaults to any to avoid circular deps)\n */\nexport interface LineObserver<TRole = any, TLine = any> {\n /**\n * Called when a role is added to the line.\n * @param line The line that changed\n * @param roleName The name of the added role\n * @param role The role that was added\n */\n onRoleAdded?(line: TLine, roleName: string, role: TRole): void;\n\n /**\n * Called when a role is removed from the line.\n * @param line The line that changed\n * @param roleName The name of the removed role\n */\n onRoleRemoved?(line: TLine, roleName: string): void;\n}\n\n/**\n * Observer interface for Block item changes.\n * Implement this interface to receive notifications when items are\n * added or removed from a Block.\n *\n * @template TItem The block item type (defaults to any to avoid circular deps)\n * @template TBlock The block type (defaults to any to avoid circular deps)\n */\nexport interface BlockObserver<TItem = any, TBlock = any> {\n /**\n * Called when an item is added to the block.\n * @param block The block that changed\n * @param item The item that was added\n * @param index The index where the item was added\n */\n onItemAdded?(block: TBlock, item: TItem, index: number): void;\n\n /**\n * Called when an item is removed from the block.\n * @param block The block that changed\n * @param item The item that was removed\n * @param index The index where the item was located\n */\n onItemRemoved?(block: TBlock, item: TItem, index: number): void;\n}\n\n// ============================================\n// Legacy Event Names (kept for compatibility)\n// ============================================\n\n/**\n * Model event names as constants.\n * @deprecated Use observer interfaces instead\n */\nexport const ModelEvents = {\n /** Emitted when atoms change in a Group or Role */\n ATOMS_CHANGED: \"atomsChanged\",\n /** Emitted when roles change on a Line */\n ROLES_CHANGED: \"rolesChanged\",\n /** Emitted when block items change on a Block */\n ITEMS_CHANGED: \"itemsChanged\",\n /** Emitted when an atom's duration changes */\n DURATION_CHANGED: \"durationChanged\",\n} as const;\n\n/**\n * Type for model event names.\n * @deprecated Use observer interfaces instead\n */\nexport type ModelEventName = (typeof ModelEvents)[keyof typeof ModelEvents];\n","// define getter functions for harmony exports\n__webpack_require__.d = (exports, definition) => {\n\tfor(var key in definition) {\n\t\tif(__webpack_require__.o(definition, key) && !__webpack_require__.o(exports, key)) {\n\t\t\tObject.defineProperty(exports, key, { enumerable: true, get: definition[key] });\n\t\t}\n\t}\n};","__webpack_require__.o = (obj, prop) => (Object.prototype.hasOwnProperty.call(obj, prop))","import * as TSU from \"@panyam/tsutils\";\n\n/**\n * A common Entity base class with support for unique IDs, parent references,\n * copying, and debug info. This serves as the foundation for all entities\n * in the notation system.\n *\n * Note: Child management is intentionally NOT included here. Each container type\n * (BlockContainer, Line, Group, etc.) defines its own child management with\n * appropriate types.\n *\n * Observer Pattern:\n * Each observable entity subclass (Group, Role, Line, Block) manages its own\n * typed observer list. This provides type safety and clear contracts between\n * observables and observers.\n */\nexport class Entity {\n readonly TYPE: string = \"Entity\";\n\n private static counter = 0;\n /** Unique identifier for this entity */\n readonly uuid = Entity.counter++;\n /** Parent entity in the tree hierarchy */\n protected _parent: TSU.Nullable<Entity> = null;\n\n /**\n * Whether events/observer notifications are enabled for this entity.\n * Subclasses check this flag before notifying observers.\n */\n protected _eventsEnabled = false;\n\n /**\n * Creates a new Entity.\n * @param config Optional configuration object\n */\n constructor(config: any = null) {\n config = config || {};\n if (config.metadata) throw new Error(\"See where metadata is being passed\");\n }\n\n /**\n * Enables observer notifications for this entity.\n * Call this to activate change notifications on entities that support them.\n * @returns This entity for method chaining\n */\n enableEvents(): this {\n this._eventsEnabled = true;\n return this;\n }\n\n /**\n * Disables observer notifications for this entity.\n * @returns This entity for method chaining\n */\n disableEvents(): this {\n this._eventsEnabled = false;\n return this;\n }\n\n /**\n * Checks if events/observer notifications are enabled.\n */\n get eventsEnabled(): boolean {\n return this._eventsEnabled;\n }\n\n /**\n * Gets the parent entity.\n */\n get parent(): TSU.Nullable<Entity> {\n return this._parent;\n }\n\n /**\n * Sets the parent entity.\n * @param parent The parent entity to set\n */\n setParent(parent: TSU.Nullable<Entity>): void {\n this._parent = parent;\n }\n\n /**\n * Returns a debug-friendly representation of this entity.\n * Usually overridden by children to add more debug info.\n * @returns An object containing debug information\n */\n debugValue(): any {\n return { type: this.TYPE };\n }\n\n /**\n * Returns a simple string representation of this Entity.\n * @returns A string representation\n */\n toString(): string {\n return `Entity(id = ${this.uuid})`;\n }\n\n /**\n * Checks if this Entity is equal to another Entity.\n * @param another The Entity to compare with\n * @param expect Optional parameter\n * @returns True if the Entities are equal, false otherwise\n */\n equals(another: this, expect = false): boolean {\n if (this.TYPE != another.TYPE) return false;\n return true;\n }\n\n /**\n * Creates a clone of this entity.\n * Cloning is a two-part process:\n * 1. Creation of a new instance via this.newInstance()\n * 2. Copying of data into the new instance via this.copyTo()\n *\n * @returns A new instance of the same type with the same properties\n */\n clone(): this {\n const out = this.newInstance();\n this.copyTo(out);\n return out;\n }\n\n /**\n * Copies information about this instance into another instance of the same type.\n * @param another The target instance to copy properties to\n */\n copyTo(another: this): void {\n // Subclasses override to copy their specific properties\n }\n\n /**\n * First part of the cloning process where the instance is created.\n * @returns A new instance of the same type\n */\n protected newInstance(): this {\n return new (this.constructor as any)();\n }\n}\n\n/**\n * Music is all about timing! TimedEntities are base of all entities that\n * have a duration. This is an abstract class that all timed entities inherit from.\n */\nexport abstract class TimedEntity extends Entity {\n readonly TYPE: string = \"TimedEntity\";\n\n /**\n * Gets the duration of this entity in terms of beats.\n * By default, entity durations are readonly.\n */\n abstract get duration(): TSU.Num.Fraction;\n\n /**\n * Checks if this TimedEntity is equal to another TimedEntity.\n * @param another The TimedEntity to compare with\n * @returns True if the TimedEntities are equal, false otherwise\n */\n equals(another: this): boolean {\n return super.equals(another) && this.duration.equals(another.duration);\n }\n}\n","export type Timestamp = number;\nexport type NumberRange = [number, number];\n\nexport type StringMap<T> = { [key: string]: T };\nexport type NumMap<T> = { [key: number]: T };\nexport type Nullable<T> = T | null;\n\nexport type Undefined<T> = T | undefined | void;\n\nexport function assert(condition: boolean, msg?: string): asserts condition {\n if (!condition) {\n throw new Error(msg);\n }\n}\n","export const INFINITY = 1e48;\nexport const MAX_INT = 2 ** 32;\nexport const MAX_LONG = 2 ** 64;\n","import { Nullable, Timestamp } from \"../types\";\n\n/**\n * Super class of all Events.\n */\nexport class TEvent {\n // Globally unique ID for all events.\n private static counter = 0;\n readonly uuid = TEvent.counter++;\n\n /**\n * The event this event was spawned from (if any).\n */\n protected _spawnedFrom: Nullable<this> = null;\n\n /**\n * Name of the event.\n */\n readonly name: string;\n\n /**\n * Source from which this event is originating.\n */\n readonly source: any;\n\n /**\n * Source state that is set by the source of the event only\n * *it* can use.\n */\n sourceState: any = null;\n\n /**\n * Event specific payload.\n */\n payload: any;\n\n /**\n * Whether the event was cancelled.\n */\n cancelled = false;\n\n /**\n * Timestamp of the event - optional.\n */\n timeStamp: Timestamp = -1;\n\n /**\n * All child events that were spawned from this Event.\n * The parent/spawnedFrom and child event references help us\n * form a call tree/trace of a events as it traverses\n * the system.\n */\n children: TEvent[] = [];\n\n constructor(name: string, source: any, payload?: any) {\n this.name = name;\n this.source = source;\n this.payload = payload;\n }\n\n get spawnedFrom(): Nullable<this> {\n return this._spawnedFrom;\n }\n\n protected setSpawnedFrom(msg: Nullable<this>): void {\n this._spawnedFrom = msg;\n if (msg == null) this._rootEvent = this;\n else this._rootEvent = msg.rootEvent;\n }\n\n spawn(name: string, source: any, payload?: any): TEvent {\n const child = new TEvent(name, source, payload);\n child.setSpawnedFrom(this);\n this.children.push(child);\n return child;\n }\n\n /**\n * The first/root message in the forward chain.\n */\n private _rootEvent: this;\n\n get rootEvent(): this {\n return this._rootEvent as this;\n }\n}\n\nexport class State {\n private static counter = 0;\n stateData: any = null;\n readonly id = State.counter++;\n\n get name(): string {\n return this.constructor.name;\n }\n\n enter(data: any): void {\n this.stateData = data;\n }\n\n handle(event: TEvent): void {\n // todo\n }\n}\n\nexport type EventCallback = ((event: TEvent) => void) | ((event: TEvent) => Promise<void>);\n\nexport class EventEmitter {\n protected _eventHub: EventHub | null;\n constructor() {\n this._eventHub = new EventHub();\n }\n get eventHub(): EventHub | null {\n return this._eventHub;\n }\n set eventHub(hub: EventHub | null) {\n const oldHub = this._eventHub;\n this._eventHub = hub;\n this.eventHubChanged(oldHub);\n }\n protected eventHubChanged(oldHub: EventHub | null): void {\n // Do nothing\n console.log(\"WARNING - EventHub Change Listener not implemented: \", this.constructor.name);\n }\n}\n\nexport class EventHub {\n private _handlers: { [key: string]: Array<EventCallback> } = {};\n\n on(names: Array<string> | string, callback: EventCallback): this {\n return this._addHandler(names, this._handlers, callback);\n }\n\n removeOn(names: Array<string> | string, callback: EventCallback): this {\n return this._removeHandler(names, this._handlers, callback);\n }\n\n _ensurestrings(names: Array<string> | string): string[] {\n if (typeof names === \"string\") {\n names = (names as string).split(\",\");\n }\n return names.map(function (v) {\n return v.trim();\n });\n }\n\n _addHandler<T>(names: Array<string> | string, handlerlist: { [key: string]: Array<T> }, handler: T): this {\n this._ensurestrings(names).forEach(function (name) {\n handlerlist[name] = handlerlist[name] || [];\n handlerlist[name].push(handler);\n });\n return this;\n }\n\n _removeHandler<T>(names: Array<string> | string, handlerlist: { [key: string]: Array<T> }, handler: T): this {\n this._ensurestrings(names).forEach(function (name) {\n const evHandlers = handlerlist[name] || [];\n for (let i = 0; i < evHandlers.length; i++) {\n if (evHandlers[i] == handler) {\n evHandlers.splice(i, 1);\n break;\n }\n }\n });\n return this;\n }\n\n emit(name: string, source: any, payload?: any): boolean {\n const evt = new TEvent(name, source, payload);\n if (this._inBatchMode) {\n this._events.push(evt);\n return true;\n } else {\n return this.dispatchEvent(evt);\n }\n }\n\n dispatchEvent(event: TEvent): boolean {\n const evtCallbacks = this._handlers[event.name] || [];\n for (const callback of evtCallbacks) {\n callback(event);\n if (event.cancelled) return false;\n }\n return true;\n }\n\n // Support for transactional/batch event handling, where\n // the user can allow a bunch of events to first collect\n // before triggering a batch dispatch\n public static BATCH_EVENTS = \"BatchEvents\";\n protected _events: TEvent[] = [];\n protected _inBatchMode = false;\n startBatchMode(): this {\n if (!this._inBatchMode) {\n this._inBatchMode = true;\n }\n return this;\n }\n\n cancelBatch(): void {\n this._inBatchMode = false;\n this._events = [];\n }\n\n commitBatch(): void {\n this._inBatchMode = false;\n this.emit(EventHub.BATCH_EVENTS, this, this._events);\n this._events = [];\n }\n}\n\n/**\n * StateMachines allow declarative and stateful chaining of events.\n */\nexport class StateMachine {\n private _states: { [key: string]: State } = {};\n private _rootState: Nullable<State> = null;\n private _currentState: Nullable<State> = null;\n constructor() {\n this._states = {};\n this._rootState = null;\n this._currentState = null;\n }\n\n /**\n * The starting/root state of the machine.\n *\n * @param {String} name Name of the default/root state.\n */\n set rootState(name: string) {\n this._rootState = this.getState(name);\n if (this._currentState == null) {\n this._currentState = this._rootState;\n }\n }\n\n /**\n * Exits the current state (if any) and enters a new state.\n *\n * @param {String} state Name of the new state to enter.\n * @param {Object} data State specific data for the state handler to use for the new state.\n */\n enter(state: string, data: any = null): void {\n if (state == \"\") {\n this._currentState = this._rootState;\n } else {\n this._currentState = this.getState(state);\n }\n if (this._currentState != null) {\n this._currentState.enter(data);\n }\n }\n\n /**\n * Get the state by name.\n *\n * @param {String} name Name of the state being queried.\n * @returns {State} State object associated with the name.\n */\n getState(name: string): State {\n if (!(name in this._states)) {\n throw Error(\"State '\" + name + \"' not yet registered.\");\n }\n return this._states[name];\n }\n\n /**\n * Register a new state in the state machine.\n *\n * @param {State} state State being registered. If another State with\n * the same name exists, then a {DuplicateError} is thrown.\n * @param {Bool} isRoot Whether the new state is a root state.\n */\n registerState(state: State, isRoot = false): void {\n const name = state.name;\n if (name in this._states) {\n throw Error(\"State '\" + name + \"' already registered.\");\n }\n this._states[name] = state;\n if (isRoot || false) {\n this.rootState = state.name;\n }\n }\n\n /**\n * Handles an event from the current state in the state machine possibly resulting in a state transition.\n *\n * @param {Object} name Type of event being sent.\n * @param {EventSource} source The source generating the event.\n * @param {Object} data The event specific data.\n */\n handle(event: TEvent): void {\n if (this._currentState == null) return;\n\n const nextState: any = this._currentState.handle(event);\n if (nextState != null) {\n if (nextState == \"\") {\n if (this._rootState != null) {\n this.enter(this._rootState.name);\n } else {\n throw new Error(\"Root state has not been set\");\n }\n } else {\n this.enter(nextState);\n }\n }\n }\n}\n","import { Nullable } from \"./types\";\n\nexport interface ListNode<V> {\n nextSibling: Nullable<V>;\n prevSibling: Nullable<V>;\n}\n\nclass MutableListNode<V> implements ListNode<MutableListNode<V>> {\n nextSibling: Nullable<MutableListNode<V>> = null;\n prevSibling: Nullable<MutableListNode<V>> = null;\n constructor(public value: V) {}\n}\n\n/**\n * A list implementation where the value itself contains next and prev pointers\n * so we do not need to create wrapper classes.\n */\nexport class ValueList<V extends ListNode<V>> {\n protected _firstChild: Nullable<V> = null;\n protected _lastChild: Nullable<V> = null;\n protected _size = 0;\n\n constructor(...values: V[]) {\n for (const v of values) this.pushBack(v);\n }\n\n toJSON(): V[] {\n return Array.from(this.values());\n }\n\n forEach(method: (val: V) => boolean | any): number {\n let tmp: V | null = this._firstChild;\n let count = 0;\n while (tmp != null) {\n if (method(tmp) == false) {\n break;\n }\n count++;\n tmp = tmp.nextSibling;\n }\n return count;\n }\n\n equals(another: ValueList<V>, eqlFunc: (val1: V, val2: V) => boolean): boolean {\n if (this.size != another.size) return false;\n let tmp = this.first;\n let tmp2 = another.first;\n for (; tmp != null && tmp2 != null; tmp = tmp.nextSibling, tmp2 = tmp2.nextSibling) {\n if (!eqlFunc(tmp, tmp2)) {\n return false;\n }\n }\n return tmp == null && tmp2 == null;\n }\n\n get isEmpty(): boolean {\n return this._size == 0;\n }\n\n get size(): number {\n return this._size;\n }\n\n get first(): Nullable<V> {\n return this._firstChild;\n }\n\n get last(): Nullable<V> {\n return this._lastChild;\n }\n\n /**\n * Generator of values in reverse order.\n */\n *reversedValues(): Generator<V> {\n let tmp = this._lastChild;\n while (tmp != null) {\n yield tmp;\n tmp = tmp.prevSibling;\n }\n }\n\n /**\n * Generator of values in forward order.\n */\n *values(): Generator<V> {\n let tmp = this._firstChild;\n while (tmp != null) {\n yield tmp;\n tmp = tmp.nextSibling;\n }\n }\n\n add(child: V, before: Nullable<V> = null): this {\n // Ensure that this node is not added anywhere else\n if (child.nextSibling != null || child.prevSibling != null) {\n throw new Error(\"New node already added to a list. Remove it first\");\n }\n child.nextSibling = child.prevSibling = null;\n this._size++;\n if (this._firstChild == null || this._lastChild == null) {\n this._firstChild = this._lastChild = child;\n } else if (before == null) {\n child.prevSibling = this._lastChild;\n child.nextSibling = null;\n this._lastChild.nextSibling = child;\n this._lastChild = child;\n } else if (before == this._firstChild) {\n child.nextSibling = before;\n child.prevSibling = null;\n this._firstChild.prevSibling = child;\n this._firstChild = child;\n } else {\n const prev = before.prevSibling;\n child.nextSibling = before;\n before.prevSibling = child;\n child.prevSibling = prev;\n if (prev != null) {\n prev.nextSibling = child;\n }\n }\n return this;\n }\n\n pushFront(value: V): this {\n return this.add(value, this._firstChild);\n }\n\n pushBack(value: V): this {\n return this.add(value);\n }\n\n /**\n * Removes a child node from this list.\n * It is upto the caller to ensure that this node indeed belongs\n * to this list otherwise deletion of a non belonging node could result\n * in undefined behaviour.\n */\n remove(child: V): this {\n const next = child.nextSibling;\n const prev = child.prevSibling;\n\n if (next == null) {\n this._lastChild = prev;\n if (prev == null) this._firstChild = null;\n } else {\n next.prevSibling = prev;\n }\n\n if (prev == null) {\n this._firstChild = next;\n if (next == null) this._lastChild = null;\n } else {\n prev.nextSibling = next;\n }\n\n this._size--;\n\n child.prevSibling = child.nextSibling = null;\n return this;\n }\n\n popBack(): V {\n if (this._lastChild == null) {\n throw new Error(\"No children\");\n }\n const out = this._lastChild;\n this.remove(out);\n return out;\n }\n\n popFront(): V {\n if (this._firstChild == null) {\n throw new Error(\"No children\");\n }\n const out = this._firstChild;\n this.remove(out);\n return out;\n }\n}\n\n/**\n * A list implementation where the values themselves need to be wrapper in a list node.\n * If values already have sibling node properties they can be direclty used\n * via ValueLists.\n */\nexport class List<V> {\n private container: ValueList<MutableListNode<V>>;\n\n constructor(...values: V[]) {\n this.container = new ValueList<MutableListNode<V>>();\n for (const v of values) this.push(v);\n }\n\n toJSON(): V[] {\n return Array.from(this.values());\n }\n\n forEach(method: (val: V) => boolean | any): number {\n return this.container.forEach((v) => method(v.value));\n }\n\n equals(another: List<V>, eqlFunc: (val1: V, val2: V) => boolean): boolean {\n return this.container.equals(another.container, (a, b) => eqlFunc(a.value, b.value));\n }\n\n find(target: V): Nullable<MutableListNode<V>> {\n for (const v of this.container.values()) {\n if (target == v.value) {\n return v;\n }\n }\n return null;\n }\n\n get isEmpty(): boolean {\n return this.container.isEmpty;\n }\n\n get size(): number {\n return this.container.size;\n }\n\n get first(): Nullable<MutableListNode<V>> {\n return this.container.first;\n }\n\n get last(): Nullable<MutableListNode<V>> {\n return this.container.last;\n }\n\n /**\n * Generator of values in reverse order.\n */\n *reversedValues(): Generator<V> {\n for (const v of this.container.reversedValues()) yield v.value;\n }\n\n /**\n * Generator of values in forward order.\n */\n *values(): Generator<V> {\n for (const v of this.container.values()) yield v.value;\n }\n\n popBack(): V {\n return this.container.popBack().value;\n }\n\n popFront(): V {\n return this.container.popFront().value;\n }\n\n pushFront(value: V): this {\n return this.add(value, this.container.first);\n }\n\n push(value: V): this {\n return this.add(value);\n }\n\n add(child: V, before: Nullable<MutableListNode<V>> = null): this {\n this.container.add(new MutableListNode(child), before);\n return this;\n }\n}\n","export interface Coords {\n x: number;\n y: number;\n}\n\nexport class Point implements Coords {\n constructor(public x = 0, public y = 0) {}\n}\n\nexport class Size {\n width = 0;\n height = 0;\n constructor(w = 0, h = 0) {\n this.width = w;\n this.height = h;\n }\n}\n\nexport class Insets {\n constructor(public left = 0, public top = 0, public right = 0, public bottom = 0) {}\n}\n\nexport interface BBox {\n x: number;\n y: number;\n width: number;\n height: number;\n}\n\nexport class Rect implements BBox {\n constructor(public x = 0, public y = 0, public width = 0, public height = 0) {}\n\n static from(box: BBox): Rect {\n return new Rect(box.x, box.y, box.width, box.height);\n }\n\n copy(): Rect {\n return Rect.from(this);\n }\n\n /**\n * Returns union with another box.\n */\n union(another: BBox | null): this {\n if (another) {\n const minX = Math.min(this.x, another.x);\n const minY = Math.min(this.y, another.y);\n const maxX = Math.max(this.x + this.width, another.x + another.width);\n const maxY = Math.max(this.y + this.height, another.y + another.height);\n this.x = minX;\n this.y = minY;\n this.width = maxX - minX;\n this.height = maxY - minY;\n }\n return this;\n }\n\n /**\n * Returns union of multiple boxes.\n */\n unionAll(...boxes: (BBox | null)[]): this {\n for (const b of boxes) this.union(b);\n return this;\n }\n}\n","declare let navigator: any;\nexport class Browser {\n static IS_EXPLORER = () => navigator && navigator.userAgent.indexOf(\"MSIE\") > -1;\n static IS_FIREFOX = () => navigator && navigator.userAgent.indexOf(\"Firefox\") > -1;\n static IS_OPERA = () => navigator && navigator.userAgent.toLowerCase().indexOf(\"op\") > -1;\n\n protected static UAHasChrome = () => navigator && navigator.userAgent.indexOf(\"Chrome\") > -1;\n protected static UAHasSafari = () => navigator && navigator.userAgent.indexOf(\"Safari\") > -1;\n static IS_SAFARI = () => navigator && Browser.UAHasSafari() && (!Browser.UAHasChrome() || !Browser.UAHasSafari());\n static IS_CHROME = () => navigator && Browser.UAHasChrome() && (!Browser.UAHasChrome() || !Browser.IS_OPERA());\n}\n","import { Undefined } from \"./types\";\nimport * as Geom from \"./geom\";\nimport { Browser } from \"./browser\";\n\ndeclare const $: any;\nconst fontMetrics: { [key: string]: any } = {};\n\n/**\n * Calculates the bounding box for an svg element in a consistent way across\n * browsers.\n */\nexport function svgBBox(element: SVGGraphicsElement): Geom.Rect {\n const bbox = Geom.Rect.from(element.getBBox());\n // Due to safari bug which returns really crazy span widths!\n if (Browser.IS_SAFARI()) {\n const clientRect = element.getClientRects()[0];\n if (clientRect) {\n const parentClientRect = element.parentElement?.getBoundingClientRect();\n bbox.x = bbox.x + clientRect.x - (parentClientRect?.x || 0);\n // bbox.y = clientRect.y; // - (parentClientRect?.y || 0);\n bbox.width = clientRect.width;\n bbox.height = clientRect.height;\n }\n }\n return bbox;\n}\n\nexport function getFontMetrics(fontFamily: string, fontSize: number): any {\n if (!(fontFamily in fontMetrics)) {\n fontMetrics[fontFamily] = {};\n }\n const familyMetrics = fontMetrics[fontFamily];\n if (!(fontSize in familyMetrics)) {\n const a = $(\"<div style='position:absolute;top:0;left:0'>M</div>\");\n a.css(\"font-family\", fontFamily);\n a.css(\"font-size\", fontSize);\n $($(document)[0].body).append(a);\n familyMetrics[fontSize] = {\n height: a[0].offsetHeight,\n size: fontSize,\n };\n a.remove();\n }\n return familyMetrics[fontSize];\n}\n\nexport function forEachChild(elem: Element, visitor: (child: Element, index: number) => Undefined<boolean>) {\n const children = elem.children;\n const L = children.length;\n for (let i = 0; i < L; i++) {\n const child = children[i];\n if (visitor(child, i) == false) return false;\n }\n}\n\nexport function forEachNode(elem: Element, visitor: (child: ChildNode, index: number) => Undefined<boolean>) {\n const children = elem.childNodes;\n const L = children.length;\n for (let i = 0; i < L; i++) {\n const child = children[i];\n if (visitor(child, i) == false) return;\n }\n}\n\nexport function forEachAttribute(elem: Element, visitor: (name: string, value: any) => Undefined<boolean>) {\n const nodeNameMap = elem.attributes;\n for (let i = 0; i < nodeNameMap.length; i++) {\n const attrib = nodeNameMap[i];\n if (visitor(attrib.name, attrib.value) == false) return;\n }\n}\n\n/**\n * Processing of different kinds of attributes.\n */\nexport function parseCSSStyles(value: string) {\n const out: any = {};\n if (value && value != null) {\n const values = value.split(\";\");\n values.forEach(function (elem) {\n if (elem.trim().length > 0) {\n const kvpair = elem.split(\":\");\n if (kvpair.length >= 2) {\n const key = kvpair[0].trim();\n const value = kvpair[1].trim();\n if (key.length > 0) {\n out[key] = value;\n }\n }\n }\n });\n }\n return out;\n}\n\nexport function getAttr(elem: Element, attrib: string, ...validators: any) {\n let value = elem.getAttribute(attrib);\n for (let i = 0; i < validators.length; i++) {\n value = validators[i](value);\n }\n return value;\n}\n\nexport function ensureAttr(elem: Element, attrib: string) {\n const value = elem.getAttribute(attrib) || null;\n if (value == null) {\n throw new Error(`Element MUST have Attribute: ${attrib}`);\n }\n return value;\n}\n\nexport function setAttr(elem: Element, name: string, value: any) {\n return elem.setAttribute(name, value);\n}\n\nexport function getAttrOrStyle(elem: Element, attribName: string, cssStyles: any, styleName: string) {\n return elem.getAttribute(attribName) || cssStyles[styleName];\n}\n\nexport function createSVGNode<T extends SVGGraphicsElement>(nodename: string, config?: any): any {\n config = config || {};\n config.ns = \"http://www.w3.org/2000/svg\";\n return createNode(nodename, config) as T;\n}\n\nexport function createNode(nodename: string, config?: any): Element {\n let out;\n config = config || {};\n const ns = config.ns;\n const doc = config.doc || document;\n const attrs = config.attrs || {};\n const text = config.text || \"\";\n const parent = config.parent || null;\n if (ns) out = doc.createElementNS(ns, nodename);\n else out = doc.createElement(nodename);\n if (parent != null) {\n parent.appendChild(out);\n }\n for (const attr in attrs || {}) {\n const value = attrs[attr];\n out.setAttribute(attr, value);\n }\n if (text) {\n out.textContent = text;\n }\n return out;\n}\n\n/**\n * Remove a node from its parent.\n */\nexport function removeNode(node: Node): void {\n node.parentNode?.removeChild(node);\n}\n\nexport function insertAfter(node: Node, ...newNodes: Node[]): boolean {\n const parentNode = node.parentNode;\n if (parentNode == null) return false;\n const nextNode = node.nextSibling;\n if (nextNode == null) {\n for (let i = 0; i < newNodes.length; i++) {\n parentNode.appendChild(newNodes[i]);\n }\n } else {\n for (let i = 0; i < newNodes.length; i++) {\n parentNode.insertBefore(newNodes[i], nextNode);\n }\n }\n return true;\n}\n\nexport function getCSS(elem: Element, attr: string): any {\n return (elem as any).style[attr];\n}\n\nexport function setCSS(elem: Element, attr: string, value: any): void {\n (elem as any).style[attr] = value;\n}\n\nexport function ensureElement(elemOrId: Element | string, root: any = null): Element {\n if (typeof elemOrId === \"string\") {\n if (root == null) root = document;\n return root.querySelector(elemOrId);\n } else {\n return elemOrId;\n }\n}\n\n/*\nexport function setEnabled(elem: Element, enable = true): Element {\n elem.prop(\"disabled\", !enable);\n return elem;\n}\n\nexport function setVisible(elem: Element, show = true): Element {\n if (show) {\n elem.show();\n } else {\n elem.hide();\n }\n return elem;\n}\n\nexport function getcssint(elem: JQuery<HTMLElement>, attrib: string): number{\n return parseInt(elem.css(attrib).replace(/px/, \"\"));\n}\n\nexport function centerElem(elem: JQuery<HTMLElement>, axis: string) {\n const parent = elem.parent();\n const horizPadding =\n getcssint(elem, \"padding-left\") +\n getcssint(elem, \"padding-right\") +\n getcssint(elem, \"margin-left\") +\n getcssint(elem, \"margin-right\") +\n getcssint(parent, \"border-left\") +\n getcssint(parent, \"border-right\");\n const vertPadding =\n getcssint(elem, \"padding-top\") +\n getcssint(elem, \"padding-bottom\") +\n getcssint(elem, \"margin-top\") +\n getcssint(elem, \"margin-bottom\") +\n getcssint(parent, \"border-top\") +\n getcssint(parent, \"border-bottom\");\n const finalHeight: number = (parent.height() as number) - vertPadding;\n const finalWidth: number = (parent.width() as number) - horizPadding;\n if (axis == \"x\") {\n elem.css(\"left\", (finalWidth - (elem.width() as number)) / 2);\n } else if (axis == \"y\") {\n elem.css(\"top\", (finalHeight - (elem.height() as number)) / 2);\n } else {\n elem.css(\"left\", (finalWidth - (elem.width() as number)) / 2);\n elem.css(\"top\", (finalHeight - (elem.height() as number)) / 2);\n }\n}\n\nexport function fillChildComponent(elem: JQuery<HTMLElement>) {\n const parent = elem.parent();\n const horizPadding =\n getcssint(elem, \"padding-left\") +\n getcssint(elem, \"padding-right\") +\n getcssint(elem, \"margin-left\") +\n getcssint(elem, \"margin-right\") +\n getcssint(parent, \"border-left\") +\n getcssint(parent, \"border-right\");\n const vertPadding =\n getcssint(elem, \"padding-top\") +\n getcssint(elem, \"padding-bottom\") +\n getcssint(elem, \"margin-top\") +\n getcssint(elem, \"margin-bottom\") +\n getcssint(parent, \"border-top\") +\n getcssint(parent, \"border-bottom\");\n const finalHeight = (parent.height() as number) - vertPadding;\n const finalWidth = (parent.width() as number) - horizPadding;\n elem.height(finalHeight);\n elem.width(finalWidth);\n}\n*/\n","import { Nullable } from \"./types\";\n\nexport function range(start: number, end: Nullable<number> = null, incr: Nullable<number> = 1): number[] {\n if (end == null) {\n const absStart = Math.abs(start);\n const arr = Array.from({ length: absStart });\n if (start >= 0) {\n return arr.map((x, i) => i);\n } else {\n return arr.map((x, i) => i - (absStart - 1));\n }\n }\n const out: number[] = [];\n if (incr == null) {\n incr = 1;\n }\n incr = Math.abs(incr);\n if (start !== end) {\n if (start < end) {\n for (let i = start; i <= end; i += incr) {\n out.push(i);\n }\n } else {\n for (let i = start; i >= end; i -= incr) {\n out.push(i);\n }\n }\n }\n return out;\n}\n\nexport function gcdof(x: number, y: number): number {\n x = Math.abs(x);\n y = Math.abs(y);\n while (y > 0) {\n const t = y;\n y = x % y;\n x = t;\n }\n return x;\n}\n\nexport class Fraction {\n readonly num: number;\n readonly den: number;\n\n static readonly ZERO = new Fraction();\n static readonly ONE = new Fraction(1, 1);\n static readonly INFINITY = new Fraction(1, 0);\n\n constructor(num = 0, den = 1, factorized = false) {\n if (isNaN(num) || isNaN(den)) {\n throw new Error(`Invalid numerator(${num}) or denminator(${den})`);\n }\n if (factorized) {\n const gcd = gcdof(num, den);\n num /= gcd;\n den /= gcd;\n }\n this.num = num;\n this.den = den;\n }\n\n static parse(val: string, factorized = false): Fraction {\n const parts = val\n .trim()\n .split(\"/\")\n .map((x) => x.trim());\n let num = 1;\n let den = 1;\n if (parts.length == 1) num = parseInt(parts[0]);\n else if (parts.length != 2) {\n throw new Error(\"Invalid fraction string: \" + val);\n } else {\n if (parts[0].length > 0) {\n num = parseInt(parts[0]);\n }\n if (parts[1].length > 0) {\n den = parseInt(parts[1]);\n }\n }\n if (isNaN(num) || isNaN(den)) {\n throw new Error(\"Invalid fraction string: \" + val);\n }\n return new Fraction(num, den, factorized);\n }\n\n get isWhole(): boolean {\n return this.num % this.den == 0;\n }\n\n get isZero(): boolean {\n return this.num == 0;\n }\n\n get isInfinity(): boolean {\n return this.den == 0;\n }\n\n get isOne(): boolean {\n return this.num == this.den;\n }\n\n get ceil(): number {\n if (this.num % this.den == 0) {\n return this.num / this.den;\n } else {\n return 1 + Math.floor(this.num / this.den);\n }\n }\n\n get floor(): number {\n if (this.num % this.den == 0) {\n return this.num / this.den;\n } else {\n return Math.floor(this.num / this.den);\n }\n }\n\n plus(another: Fraction, factorized = false): Fraction {\n return new Fraction(this.num * another.den + this.den * another.num, this.den * another.den, factorized);\n }\n\n plusNum(another: number, factorized = false): Fraction {\n return new Fraction(this.num + this.den * another, this.den, factorized);\n }\n\n minus(another: Fraction, factorized = false): Fraction {\n return new Fraction(this.num * another.den - this.den * another.num, this.den * another.den, factorized);\n }\n\n minusNum(another: number, factorized = false): Fraction {\n return new Fraction(this.num - this.den * another, this.den, factorized);\n }\n\n times(another: Fraction, factorized = false): Fraction {\n return new Fraction(this.num * another.num, this.den * another.den, factorized);\n }\n\n timesNum(another: number, factorized = false): Fraction {\n return new Fraction(this.num * another, this.den, factorized);\n }\n\n divby(another: Fraction, factorized = false): Fraction {\n return new Fraction(this.num * another.den, this.den * another.num, factorized);\n }\n\n divbyNum(another: number, factorized = false): Fraction {\n return new Fraction(this.num, this.den * another, factorized);\n }\n\n /**\n * Returns another / this.\n */\n numDivby(another: number, factorized = false): Fraction {\n return new Fraction(this.den * another, this.num, factorized);\n }\n\n /**\n * Returns this % another\n */\n mod(another: Fraction): Fraction {\n // a (mod b) = a − b ⌊a / b⌋\n const d = this.divby(another);\n const floorOfD = Math.floor(d.num / d.den);\n return this.minus(another.timesNum(floorOfD));\n }\n\n /*\n * Returns this % another\n */\n modNum(another: number): Fraction {\n // a (mod b) = a − b ⌊a / b⌋\n const d = this.divbyNum(another);\n const floorOfD = Math.floor(d.num / d.den);\n return this.minusNum(another * floorOfD);\n }\n\n get inverse(): Fraction {\n return new Fraction(this.den, this.num);\n }\n\n get factorized(): Fraction {\n const gcd = gcdof(this.num, this.den);\n return new Fraction(this.num / gcd, this.den / gcd);\n }\n\n equals(another: Fraction): boolean {\n return this.num * another.den == this.den * another.num;\n }\n\n equalsNum(another: number): boolean {\n return this.num == this.den * another;\n }\n\n cmp(another: Fraction): number {\n return this.num * another.den - this.den * another.num;\n }\n\n cmpNum(another: number): number {\n return this.num - this.den * another;\n }\n\n isLT(another: Fraction): boolean {\n return this.cmp(another) < 0;\n }\n\n isLTE(another: Fraction): boolean {\n return this.cmp(another) <= 0;\n }\n\n isLTNum(another: number): boolean {\n return this.cmpNum(another) < 0;\n }\n\n isLTENum(another: number): boolean {\n return this.cmpNum(another) <= 0;\n }\n\n isGT(another: Fraction): boolean {\n return this.cmp(another) > 0;\n }\n\n isGTE(another: Fraction): boolean {\n return this.cmp(another) >= 0;\n }\n\n isGTNum(another: number): boolean {\n return this.cmpNum(another) > 0;\n }\n\n isGTENum(another: number): boolean {\n return this.cmpNum(another) >= 0;\n }\n\n toString(): string {\n return this.num + \"/\" + this.den;\n }\n\n static max(f1: Fraction, f2: Fraction): Fraction {\n return f1.cmp(f2) > 0 ? f1 : f2;\n }\n\n static min(f1: Fraction, f2: Fraction): Fraction {\n return f1.cmp(f2) < 0 ? f1 : f2;\n }\n}\n\n// Shortcut helper\nexport const Frac = (a = 0, b = 1, factorized = false): Fraction => new Fraction(a, b, factorized);\n","import * as TSU from \"@panyam/tsutils\";\nimport { Entity, TimedEntity } from \"./entity\";\n\n/**\n * Alias to TSU.Num.Fraction in tsutils.\n */\ntype Fraction = TSU.Num.Fraction;\nexport type CyclePosition = [number, number, number];\nexport type CycleIterator = Generator<[CyclePosition, Fraction]>;\n\nconst ZERO = TSU.Num.Fraction.ZERO;\nconst ONE = TSU.Num.Fraction.ONE;\n\n/**\n * A cursor that traverses through a Cycle's beats in a controlled manner.\n * Allows forward and backward navigation through the cycle.\n */\nexport class CycleCursor {\n /**\n * Creates a new CycleCursor.\n * @param cycle The Cycle to traverse\n * @param barIndex The starting bar index, defaults to 0\n * @param beatIndex The starting beat index within the bar, defaults to 0\n * @param instance The starting instance index within the beat, defaults to 0\n */\n constructor(\n public readonly cycle: Cycle,\n public barIndex = 0,\n public beatIndex = 0,\n public instance = 0,\n ) {}\n\n /**\n * Advances the cursor to the next beat and returns the current position and beat length.\n * @returns A tuple containing the current position and beat length\n */\n get next(): [CyclePosition, Fraction] {\n const currBar = this.cycle.bars[this.barIndex];\n const result: [CyclePosition, Fraction] = [\n [this.barIndex, this.beatIndex, this.instance],\n currBar.beatLengths[this.beatIndex],\n ];\n this.instance++;\n if (!currBar.beatCounts[this.beatIndex] || this.instance >= currBar.beatCounts[this.beatIndex]) {\n this.instance = 0;\n this.beatIndex++;\n if (this.beatIndex >= currBar.beatLengths.length) {\n this.beatIndex = 0;\n this.barIndex++;\n if (this.barIndex >= this.cycle.bars.length) {\n this.barIndex = 0;\n }\n }\n }\n return result;\n }\n\n /**\n * Moves the cursor to the previous beat and returns the current position and beat length.\n * @returns A tuple containing the current position and beat length\n */\n get prev(): [CyclePosition, Fraction] {\n const currBar = this.cycle.bars[this.barIndex];\n const result: [CyclePosition, Fraction] = [\n [this.barIndex, this.beatIndex, this.instance],\n currBar.beatLengths[this.beatIndex],\n ];\n // TODO - result should be set *after* decrementing if we had already\n // done a \"next\" before this otherwise user may have to do a prev twice\n this.instance--;\n if (this.instance < 0) {\n this.beatIndex--;\n if (this.beatIndex < 0) {\n this.barIndex--;\n if (this.barIndex < 0) {\n this.barIndex = this.cycle.bars.length - 1;\n }\n this.beatIndex = this.cycle.bars[this.barIndex].beatCount - 1;\n }\n this.instance = (this.cycle.bars[this.barIndex].beatCounts[this.beatIndex] || 1) - 1;\n }\n return result;\n }\n}\n\n/**\n * Represents a bar in a musical cycle.\n * A bar consists of beats with specific lengths and counts.\n */\nexport class Bar extends TimedEntity {\n readonly TYPE: string = \"Bar\";\n\n /** Name of the bar (e.g., \"Laghu\", \"Dhrutam\") */\n name: string;\n\n /** Length/Duration of each beat in the bar */\n beatLengths: Fraction[] = [];\n\n /** How many times each beat should be repeated (the Kalai) */\n beatCounts: number[] = [];\n\n /**\n * Creates a new Bar.\n * @param config Configuration object containing name, beatLengths, and beatCounts\n */\n constructor(config: any = null) {\n super((config = config || {}));\n this.name = config.name || \"\";\n for (const bl of config.beatLengths || []) {\n if (typeof bl === \"number\") {\n this.beatLengths.push(TSU.Num.Frac(bl));\n } else {\n this.beatLengths.push(bl);\n }\n }\n for (const bc of config.beatCounts || []) {\n this.beatCounts.push(bc);\n }\n while (this.beatCounts.length < this.beatLengths.length) {\n this.beatCounts.push(1);\n }\n }\n\n /**\n * Returns a debug-friendly representation of this Bar.\n * @returns An object containing debug information\n */\n debugValue(): any {\n return { ...super.debugValue(), name: name, beatLengths: this.beatLengths };\n }\n\n /**\n * Checks if this Bar is equal to another Bar.\n * @param another The Bar to compare with\n * @returns True if the Bars are equal, false otherwise\n */\n equals(another: this): boolean {\n if (!super.equals(another)) return false;\n if (this.beatLengths.length != another.beatLengths.length) return false;\n if (this.beatCounts.length != another.beatCounts.length) return false;\n for (let i = 0; i < this.beatLengths.length; i++) {\n if (!this.beatLengths[i].equals(another.beatLengths[i])) return false;\n }\n for (let i = 0; i < this.beatCounts.length; i++) {\n if (this.beatCounts[i] != another.beatCounts[i]) return false;\n }\n return true;\n }\n\n /**\n * Copies the properties of this Bar to another Bar.\n * @param another The target Bar to copy properties to\n */\n copyTo(another: this): void {\n super.copyTo(another);\n another.name = this.name;\n another.beatLengths = [...this.beatLengths];\n another.beatCounts = [...this.beatCounts];\n }\n\n /**\n * Gets the instance count for a specific beat in the bar.\n * @param beatIndex The index of the beat\n * @returns The number of instances for the specified beat\n */\n instanceCount(beatIndex: number): number {\n if (beatIndex > this.beatCounts.length) {\n // by default each beat has 1 instance?\n return 1;\n } else {\n return this.beatCounts[beatIndex];\n }\n }\n\n /**\n * Gets the number of unique beats in this bar (irrespective of instances).\n */\n get beatCount(): number {\n return this.beatLengths.length;\n }\n\n /**\n * Gets the total number of beat instances in this bar.\n */\n get totalBeatCount(): number {\n let out = 0;\n for (let i = 0; i < this.beatLengths.length; i++) {\n out += this.beatCounts[i] || 1;\n }\n return out;\n }\n\n /**\n * Gets the total duration of time across all beats in this bar.\n */\n get duration(): Fraction {\n let total = ZERO;\n for (let i = 0; i < this.beatLengths.length; i++) {\n total = total.plus(this.beatLengths[i].timesNum(this.beatCounts[i] || 1));\n }\n return total;\n }\n}\n\n/**\n * Represents a complete rhythmic cycle pattern composed of bars.\n * In carnatic music, this typically represents a tala.\n */\nexport class Cycle extends TimedEntity {\n readonly TYPE: string = \"Cycle\";\n\n /** Name of the cycle (e.g., \"Adi Thalam\") */\n name: string;\n\n /** The bars that make up this cycle */\n bars: Bar[];\n\n /**\n * Default cycle representing Adi Thalam (4+2+2 structure).\n */\n static readonly DEFAULT = new Cycle({\n name: \"Adi Thalam\",\n bars: [\n new Bar({ name: \"Laghu\", beatLengths: [1, 1, 1, 1] }),\n new Bar({ name: \"Dhrutam\", beatLengths: [1, 1] }),\n new Bar({ name: \"Dhrutam\", beatLengths: [1, 1] }),\n ],\n });\n\n /**\n * Creates a new Cycle.\n * @param config Configuration object containing name and bars\n */\n constructor(config: null | { name?: string; bars?: Bar[] } = null) {\n super((config = config || {}));\n this.name = config.name || \"\";\n this.bars = config.bars || [];\n }\n\n /**\n * Returns a debug-friendly representation of this Cycle.\n * @returns An object containing debug information\n */\n debugValue(): any {\n return { ...super.debugValue(), name: name, bars: this.bars.map((p) => p.debugValue()) };\n }\n\n /**\n * Gets all child entities of this Cycle.\n * @returns An array of child entities (bars)\n */\n children(): Entity[] {\n return this.bars;\n }\n\n /**\n * Checks if this Cycle is equal to another Cycle.\n * @param another The Cycle to compare with\n * @returns True if the Cycles are equal, false otherwise\n */\n equals(another: this): boolean {\n if (!super.equals(another)) {\n return false;\n }\n if (this.bars.length != another.bars.length) return false;\n for (let i = 0; i < this.bars.length; i++) {\n if (!this.bars[i].equals(another.bars[i])) return false;\n }\n return true;\n }\n\n /**\n * Given a global beat index, returns the position within the cycle.\n *\n * @param globalIndex The global beat index\n * @returns A tuple containing [cycle number, position, start offset]\n * - cycle: The nth cycle in which the beat lies\n * - position: [barIndex, beatIndex, instance] within the cycle\n * - startOffset: Offset of the beat at this global index\n */\n getAtIndex(globalIndex: number): [number, CyclePosition, Fraction] {\n let cycle = 0;\n while (globalIndex < 0) {\n globalIndex += this.totalBeatCount;\n cycle--;\n }\n if (globalIndex >= this.totalBeatCount) {\n cycle = Math.floor(globalIndex / this.totalBeatCount);\n }\n globalIndex = globalIndex % this.totalBeatCount;\n let offset = ZERO;\n for (let barIndex = 0; barIndex < this.bars.length; barIndex++) {\n const bar = this.bars[barIndex];\n if (globalIndex >= bar.totalBeatCount) {\n globalIndex -= bar.totalBeatCount;\n offset = offset.plus(bar.duration);\n } else {\n // this is the bar!\n for (let beatIndex = 0; beatIndex < bar.beatCount; beatIndex++) {\n const beatLength = bar.beatLengths[beatIndex];\n const beatCount = bar.beatCounts[beatIndex] || 1;\n if (globalIndex >= beatCount) {\n globalIndex -= beatCount;\n offset = offset.plus(beatLength.timesNum(beatCount));\n } else {\n // this is it\n const instance = globalIndex;\n return [cycle, [barIndex, beatIndex, instance], offset.plus(beatLength.timesNum(instance))];\n }\n }\n }\n }\n throw new Error(\"Should not be here!\");\n }\n\n /**\n * Given a global offset, returns the position within the cycle.\n *\n * @param globalOffset The global time offset\n * @returns A tuple containing [cycle number, position, note offset, global index]\n * - cycle: The nth cycle in which the offset lies\n * - position: [barIndex, beatIndex, instance] within the cycle\n * - startOffset: The note offset within the beat\n * - globalIndex: The beat index within the entire cycle\n */\n getPosition(globalOffset: Fraction): [number, CyclePosition, Fraction, number] {\n const duration = this.duration;\n let cycleNum = 0;\n if (globalOffset.isLT(ZERO)) {\n while (globalOffset.isLT(ZERO)) {\n cycleNum--;\n globalOffset = globalOffset.plus(duration);\n }\n } else if (globalOffset.isGTE(duration)) {\n const realOffset = globalOffset.mod(duration);\n globalOffset = globalOffset.minus(realOffset).divby(duration);\n TSU.assert(globalOffset.isWhole);\n cycleNum = globalOffset.floor;\n globalOffset = realOffset;\n }\n\n // here globalOffset is positive and >= 0 and < this.duration\n let globalIndex = 0;\n for (let barIndex = 0; barIndex < this.bars.length; barIndex++) {\n const bar = this.bars[barIndex];\n const barDuration = bar.duration;\n if (globalOffset.isGTE(barDuration)) {\n globalOffset = globalOffset.minus(barDuration);\n } else {\n // this is the bar!\n for (let beatIndex = 0; beatIndex < bar.beatCount; beatIndex++) {\n const beatLength = bar.beatLengths[beatIndex];\n const beatCount = bar.beatCounts[beatIndex] || 1;\n for (let instance = 0; instance < beatCount; instance++, globalIndex++) {\n if (globalOffset.isGTE(beatLength)) {\n globalOffset = globalOffset.minus(beatLength);\n } else {\n // this is it\n return [cycleNum, [barIndex, beatIndex, instance], globalOffset, globalIndex];\n }\n }\n }\n }\n globalIndex += bar.totalBeatCount;\n }\n\n throw new Error(\"Should not be here!\");\n }\n\n /**\n * Creates an iterator that yields beats in sequence from a starting position.\n *\n * @param startBar The starting bar index, defaults to 0\n * @param startBeat The starting beat index, defaults to 0\n * @param startInstance The starting instance index, defaults to 0\n * @returns A generator that yields [position, beat length] pairs\n */\n *iterateBeats(startBar = 0, startBeat = 0, startInstance = 0): CycleIterator {\n let barIndex = startBar;\n let beatIndex = startBeat;\n let instanceIndex = startInstance;\n while (true) {\n const currBar = this.bars[barIndex];\n yield [[barIndex, beatIndex, instanceIndex], currBar.beatLengths[beatIndex]];\n instanceIndex++;\n if (!currBar.beatCounts[beatIndex] || instanceIndex >= currBar.beatCounts[beatIndex]) {\n instanceIndex = 0;\n beatIndex++;\n if (beatIndex >= currBar.beatLengths.length) {\n beatIndex = 0;\n barIndex++;\n if (barIndex >= this.bars.length) {\n barIndex = 0;\n }\n }\n }\n }\n }\n\n /**\n * Copies the properties of this Cycle to another Cycle.\n * @param another The target Cycle to copy properties to\n */\n copyTo(another: this): void {\n super.copyTo(another);\n another.name = this.name;\n another.bars = this.bars.map((x) => x.clone());\n }\n\n /**\n * Gets the number of unique beats in this cycle (irrespective of instances).\n */\n get beatCount(): number {\n let out = 0;\n for (const bar of this.bars) out += bar.beatCount;\n return out;\n }\n\n /**\n * Gets the total number of beat instances in this cycle.\n */\n get totalBeatCount(): number {\n let out = 0;\n for (const bar of this.bars) out += bar.totalBeatCount;\n return out;\n }\n\n /**\n * Gets the total duration of time across all bars in this cycle.\n */\n get duration(): Fraction {\n return this.bars.reduce((x, y) => x.plus(y.duration), ZERO);\n }\n}\n","import * as TSU from \"@panyam/tsutils\";\nimport { Entity, TimedEntity } from \"./entity\";\nimport { LayoutParams } from \"./layouts\";\nimport { AtomChangeType, GroupObserver, RoleObserver, LineObserver } from \"./events\";\n\n/**\n * Alias to TSU.Num.Fraction in tsutils.\n */\ntype Fraction = TSU.Num.Fraction;\nexport const ZERO = TSU.Num.Fraction.ZERO;\nexport const ONE = TSU.Num.Fraction.ONE;\n\n/**\n * AtomType enums are used to denote specific Atoms\n * Each type represents a specific musical or notational element.\n * @enum\n */\nexport enum AtomType {\n NOTE = \"Note\",\n LITERAL = \"Literal\",\n SYLLABLE = \"Syllable\",\n SPACE = \"Space\",\n GROUP = \"Group\",\n LABEL = \"Label\",\n REST = \"Rest\",\n MARKER = \"Marker\",\n}\n\n/**\n * Atoms are the base class for all timed entities that can appear in a Notation.\n * An Atom represents the fundamental building block of the notation system.\n */\nexport abstract class Atom extends TimedEntity {\n readonly TYPE: string = \"Atom\";\n\n protected _duration: Fraction;\n /** Markers to be displayed before this atom */\n markersBefore: Marker[];\n /** Markers to be displayed after this atom */\n markersAfter: Marker[];\n /** Next atom in the sequence */\n nextSibling: TSU.Nullable<Atom> = null;\n /** Previous atom in the sequence */\n prevSibling: TSU.Nullable<Atom> = null;\n /** The Group this Atom belongs to, if any */\n parentGroup: TSU.Nullable<Group> = null;\n\n /** Indicates if this Atom is a continuation from a previous atom */\n isContinuation = false;\n\n /**\n * Creates a new Atom with the specified duration.\n * @param duration The duration of the atom, defaults to ONE (1/1)\n */\n constructor(duration = ONE) {\n super();\n this._duration = duration || ONE;\n }\n\n /**\n * Splits this atom at the specified duration.\n * @param requiredDuration The duration at which to split the atom\n * @returns A new atom representing the portion beyond the split point, or null if no split is needed\n */\n abstract splitAt(requiredDuration: Fraction): TSU.Nullable<Atom>;\n\n /**\n * Returns a debug-friendly representation of this Atom.\n * @returns An object containing debug information\n */\n debugValue(): any {\n const out = super.debugValue();\n if (!this.duration.isOne) {\n out.duration = this.duration.factorized.toString();\n }\n if (this.isContinuation) {\n out.isContinuation = true;\n }\n if ((this.markersBefore || []).length > 0) {\n out.mbef = this.markersBefore.map((m) => m.debugValue());\n }\n if ((this.markersAfter || []).length > 0) {\n out.maft = this.markersAfter.map((m) => m.debugValue());\n }\n return out;\n }\n\n /**\n * Copies the properties of this atom to another atom.\n * @param another The target atom to copy properties to\n */\n copyTo(another: this): void {\n super.copyTo(another);\n another._duration = new TSU.Num.Fraction(this.duration.num, this.duration.den);\n }\n\n /**\n * Gets the duration of this atom.\n */\n get duration(): Fraction {\n return this._duration;\n }\n\n /**\n * Sets the duration of this atom.\n */\n set duration(d: Fraction) {\n this._duration = d;\n }\n}\n\n/**\n * Base class for atoms that cannot contain other atoms.\n * LeafAtom represents atomic elements that can't be further subdivided.\n */\nexport abstract class LeafAtom extends Atom {\n readonly TYPE: string = \"LeafAtom\";\n\n /** Indicates if this atom is followed by a rest */\n beforeRest = false;\n\n /**\n * Splits this atom at a certain duration.\n * If this atom's duration is longer than the given duration, it's truncated\n * to the given duration and a continuation space is returned.\n *\n * @param duration The duration at which to split the atom\n * @returns A new Space atom representing the spillover if needed, otherwise null\n */\n splitAt(duration: Fraction): TSU.Nullable<Atom> {\n if (this.duration.cmp(duration) > 0) {\n const spillOver = this.createSpilloverSpace(this.duration.minus(duration));\n spillOver.isContinuation = true;\n this.duration = duration;\n // TODO - Here we need to move the markersAfter to the spill-over as it doesnt belong to this any more\n return spillOver;\n }\n return null;\n }\n\n /**\n * Creates a Space atom to represent spillover duration when splitting.\n * @param duration The duration of the spillover\n * @returns A new Space atom\n */\n protected createSpilloverSpace(duration: Fraction): Space {\n return new Space(duration);\n }\n\n /**\n * Returns a debug-friendly representation of this LeafAtom.\n * @returns An object containing debug information\n */\n debugValue(): any {\n return this.beforeRest ? { ...super.debugValue(), beforeRest: true } : super.debugValue();\n }\n}\n\n/**\n * Represents a marker or annotation in the notation.\n * Markers can be placed before or after atoms to provide additional context.\n */\nexport class Marker extends Entity {\n readonly TYPE = \"Marker\";\n\n /**\n * Creates a new Marker with the specified text.\n * @param text The text content of the marker\n * @param isBefore Whether the marker should appear before (true) or after (false) its associated atom\n */\n constructor(\n public text: string,\n public isBefore = true,\n ) {\n super();\n }\n\n /**\n * Returns a debug-friendly representation of this Marker.\n * @returns An object containing debug information\n */\n debugValue(): any {\n return { ...super.debugValue(), text: this.text, before: this.isBefore };\n }\n\n /**\n * Returns a string representation of this Marker.\n * @returns A string representation\n */\n toString(): string {\n return `Marker(${this.text}-${this.isBefore})`;\n }\n}\n\n/**\n * Represents a rest (silence) in the notation.\n * Rests are zero-length atoms that indicate a pause.\n */\nexport class Rest extends LeafAtom {\n readonly TYPE = \"Rest\";\n\n /**\n * Creates a new Rest.\n * Rests are zero length by default.\n */\n constructor() {\n super(ZERO);\n }\n}\n\n/**\n * Represents a space or silence in the notation.\n * Spaces can be used to denote either silence or continuations of previous notes.\n */\nexport class Space extends LeafAtom {\n readonly TYPE = \"Space\";\n\n /**\n * Indicates whether this is a silent space or a continuation of the previous note.\n */\n isSilent = false;\n\n /**\n * Creates a new Space with the specified duration and silence property.\n * @param duration The duration of the space, defaults to ONE (1/1)\n * @param isSilent Whether the space represents silence (true) or a continuation (false)\n */\n constructor(duration = ONE, isSilent = false) {\n super(duration);\n this.isSilent = isSilent;\n }\n\n /**\n * Returns a debug-friendly representation of this Space.\n * @returns An object containing debug information\n */\n debugValue(): any {\n return { ...super.debugValue(), isSilent: this.isSilent };\n }\n\n /**\n * Returns a string representation of this Space.\n * @returns A string representation\n */\n toString(): string {\n return `Space(${this.duration}-${this.isSilent})`;\n }\n\n /**\n * Copies the properties of this Space to another Space.\n * @param another The target Space to copy properties to\n */\n copyTo(another: this): void {\n super.copyTo(another);\n another.isSilent = this.isSilent;\n }\n\n /**\n * Checks if this Space is equal to another Space.\n * @param another The Space to compare with\n * @returns True if the Spaces are equal, false otherwise\n */\n equals(another: this): boolean {\n return super.equals(another) && this.isSilent == another.isSilent;\n }\n\n /**\n * Creates a Space atom to represent spillover duration when splitting.\n * @param duration The duration of the spillover\n * @returns A new Space atom with the same silence property as this Space\n */\n protected createSpilloverSpace(duration: Fraction): Space {\n const out = super.createSpilloverSpace(duration);\n out.isSilent = this.isSilent;\n return out;\n }\n}\n\n/**\n * Represents a literal value in the notation.\n * Literals are the basic building blocks for notes and syllables.\n */\nexport class Literal extends LeafAtom {\n readonly TYPE: string = \"Literal\";\n\n /**\n * The embellishments applied to this Literal.\n */\n embelishments: any[] = [];\n\n /**\n * Creates a new Literal with the specified value and duration.\n * @param value The string value of the literal\n * @param duration The duration of the literal, defaults to ONE (1/1)\n */\n constructor(\n public value: string,\n duration = ONE,\n ) {\n super(duration);\n }\n\n /**\n * Returns a debug-friendly representation of this Literal.\n * @returns An object containing debug information\n */\n debugValue(): any {\n const out = { ...super.debugValue(), value: this.value };\n if (this.embelishments.length > 0) {\n out.embs = this.embelishments.map((e) => (\"debugValue\" in e ? e.debugValue() : e));\n }\n return out;\n }\n\n /**\n * Returns a string representation of this Literal.\n * @returns A string representation\n */\n toString(): string {\n return `Lit(${this.duration}-${this.value})`;\n }\n\n /**\n * Checks if this Literal is equal to another Literal.\n * @param another The Literal to compare with\n * @returns True if the Literals are equal, false otherwise\n */\n equals(another: this): boolean {\n return super.equals(another) && this.value == another.value;\n }\n\n /**\n * Copies the properties of this Literal to another Literal.\n * @param another The target Literal to copy properties to\n */\n copyTo(another: this): void {\n super.copyTo(another);\n another.value = this.value;\n }\n}\n\n/**\n * Represents a syllable in lyrics or text to be sung.\n * Extends Literal to provide specialized handling for sung text.\n */\nexport class Syllable extends Literal {\n readonly TYPE = \"Syllable\";\n\n /**\n * Creates a Syllable from a Literal.\n * @param lit The Literal to convert to a Syllable\n * @returns A new Syllable with the properties of the Literal\n */\n static fromLit(lit: Literal): Syllable {\n if (lit.TYPE == AtomType.SYLLABLE) return lit as Syllable;\n const out = new Syllable(lit.value, lit.duration);\n out.embelishments = lit.embelishments;\n out.beforeRest = lit.beforeRest;\n return out;\n }\n\n /**\n * Returns a string representation of this Syllable.\n * @returns A string representation\n */\n toString(): string {\n return `Syll(${this.duration}-${this.value})`;\n }\n}\n\n/**\n * Represents a musical note in the notation.\n * Extends Literal to add properties specific to musical notes.\n */\nexport class Note extends Literal {\n readonly TYPE = \"Note\";\n\n /**\n * Which octave the note is in. Can be positive or negative to indicate higher or lower octaves.\n */\n octave = 0;\n\n /**\n * How the note is shifted - i.e., shifted towards major or minor by # of semi-tones.\n */\n shift: number | boolean = 0;\n\n /**\n * Creates a new Note with the specified properties.\n * @param value The string value of the note\n * @param duration The duration of the note, defaults to ONE (1/1)\n * @param octave The octave of the note, defaults to 0\n * @param shift The shift of the note, defaults to 0\n */\n constructor(value: string, duration = ONE, octave = 0, shift = 0) {\n super(value, duration);\n this.octave = octave;\n this.shift = shift;\n }\n\n /**\n * Creates a Note from a Literal.\n * @param lit The Literal to convert to a Note\n * @returns A new Note with the properties of the Literal\n */\n static fromLit(lit: Literal): Note {\n if (lit.TYPE == AtomType.NOTE) return lit as Note;\n const out = new Note(lit.value, lit.duration);\n out.embelishments = lit.embelishments;\n out.beforeRest = lit.beforeRest;\n return out;\n }\n\n /**\n * Returns a debug-friendly representation of this Note.\n * @returns An object containing debug information\n */\n debugValue(): any {\n const out = { ...super.debugValue() };\n if (this.octave != 0) out.octave = this.octave;\n if (this.shift != 0) out.shift = this.shift;\n return out;\n }\n\n /**\n * Returns a string representation of this Note.\n * @returns A string representation\n */\n toString(): string {\n return `Note(${this.duration}-${this.value}-${this.octave})`;\n }\n\n /**\n * Checks if this Note is equal to another Note.\n * @param another The Note to compare with\n * @returns True if the Notes are equal, false otherwise\n */\n equals(another: this): boolean {\n return super.equals(another) && this.octave == another.octave && this.shift == another.shift;\n }\n\n /**\n * Copies the properties of this Note to another Note.\n * @param another The target Note to copy properties to\n */\n copyTo(another: this): void {\n super.copyTo(another);\n another.octave = this.octave;\n another.shift = this.shift;\n }\n}\n\n/**\n * Represents a group of atoms that are treated as a single unit.\n * Groups can contain any number of atoms, including other groups.\n */\nexport class Group extends Atom {\n readonly TYPE = \"Group\";\n\n /**\n * Indicates whether the duration is static or linear to the number of atoms in this group.\n * When true, the duration is used as a multiplier for the total child duration.\n * When false, the duration is absolute.\n */\n durationIsSpeedMultiplier = false;\n\n /**\n * The list of atoms in this group.\n */\n readonly atoms = new TSU.Lists.ValueList<Atom>();\n\n /**\n * Observers that receive notifications when atoms change.\n */\n private _observers: GroupObserver<Atom, Group>[] = [];\n\n /**\n * Creates a new Group containing the specified atoms.\n * @param atoms The atoms to include in this group\n */\n constructor(...atoms: Atom[]) {\n super(atoms.length == 0 ? ZERO : ONE);\n this.addAtoms(false, ...atoms);\n }\n\n /**\n * Adds an observer to receive atom change notifications.\n * @param observer The observer to add\n * @returns A function to remove the observer\n */\n addObserver(observer: GroupObserver<Atom, Group>): () => void {\n this._observers.push(observer);\n return () => this.removeObserver(observer);\n }\n\n /**\n * Removes an observer.\n * @param observer The observer to remove\n */\n removeObserver(observer: GroupObserver<Atom, Group>): void {\n const index = this._observers.indexOf(observer);\n if (index >= 0) {\n this._observers.splice(index, 1);\n }\n }\n\n /**\n * Notifies observers of atom changes.\n */\n private notifyObservers(type: AtomChangeType, atoms: Atom[], index: number): void {\n if (!this._eventsEnabled) return;\n for (const observer of this._observers) {\n switch (type) {\n case AtomChangeType.ADD:\n observer.onAtomsAdded?.(this, atoms, index);\n break;\n case AtomChangeType.INSERT:\n observer.onAtomsInserted?.(this, atoms, index);\n break;\n case AtomChangeType.REMOVE:\n observer.onAtomsRemoved?.(this, atoms);\n break;\n }\n }\n }\n\n /**\n * Checks if this Group is equal to another Group.\n * @param another The Group to compare with\n * @param expect Optional parameter\n * @returns True if the Groups are equal, false otherwise\n */\n equals(another: this, expect = false): boolean {\n if (!super.equals(another)) return false;\n return this.atoms.equals(another.atoms, (a1, a2) => a1.equals(a2));\n }\n\n /**\n * Copies the properties of this Group to another Group.\n * @param another The target Group to copy properties to\n */\n copyTo(another: this): void {\n super.copyTo(another);\n another.durationIsSpeedMultiplier = this.durationIsSpeedMultiplier;\n for (const atom of this.atoms.values()) {\n another.atoms.add(atom.clone());\n }\n }\n\n /**\n * Gets the duration of this group.\n * If durationIsSpeedMultiplier is true, returns the total child duration divided by the multiplier.\n * Otherwise, returns the absolute duration.\n */\n get duration(): Fraction {\n if (this.durationIsSpeedMultiplier) {\n return this.totalChildDuration.divby(this._duration);\n } else {\n return this._duration;\n }\n }\n\n /**\n * Sets this group to use a multiplier for duration calculations.\n * @param asSpeedMultiplier Whether to use the duration as a speed multiplier. Eg If our duration was 2 and this was\n * set then since the speed is doubled - then the actual duration is halved.\n * @returns This Group instance for method chaining\n */\n setDurationAsMultiplier(asSpeedMultiplier = true): this {\n this.durationIsSpeedMultiplier = asSpeedMultiplier;\n return this;\n }\n\n /**\n * Sets the duration of this group.\n * @param d The new duration\n * @param asSpeedMultiplier Whether to use the duration as a speed multiplier. Eg If our duration was 2 and this was\n * set then since the speed is doubled - then the actual duration is halved.\n * @returns This Group instance for method chaining\n */\n setDuration(d: Fraction, asSpeedMultiplier = false): this {\n this._duration = d;\n this.durationIsSpeedMultiplier = asSpeedMultiplier;\n return this;\n }\n\n /**\n * Returns a debug-friendly representation of this Group.\n * @returns An object containing debug information\n */\n debugValue(): any {\n const out = { ...super.debugValue(), atoms: Array.from(this.atoms.values(), (a) => a.debugValue()) };\n if (this.durationIsSpeedMultiplier) out.durationIsSpeedMultiplier = true;\n return out;\n }\n\n /**\n * Splits this group into two parts.\n * The first part (this group) fits within the given duration and everything else\n * longer than the given duration is returned as a new Group.\n *\n * @param requiredDuration The duration at which to split the group\n * @returns A new Group containing the atoms beyond the split point, or null if no split is needed\n */\n splitAt(requiredDuration: Fraction): TSU.Nullable<Group> {\n if (this.duration.isLTE(requiredDuration) || requiredDuration.isLTE(ZERO)) {\n return null;\n }\n const targetGroup = new Group();\n if (this.durationIsSpeedMultiplier) {\n targetGroup.durationIsSpeedMultiplier = true;\n targetGroup._duration = this._duration;\n }\n\n let remainingDur = this.duration;\n const totalChildDuration = this.totalChildDuration;\n const durationFactor = this.durationIsSpeedMultiplier\n ? ONE.divby(this._duration)\n : this._duration.divby(totalChildDuration, true);\n while (remainingDur.isGT(requiredDuration) && this.atoms.last) {\n const lastChild = this.atoms.last;\n // Child's duration is absolute in its own \"system\"\n // Its duration within the parent (this) group's frame of reference depends\n // on whether the parent's duration is absolute or as a multiplier\n //\n // realChildDuration = case (group.durationIsMultiper) {\n // | true => child.duration / this._duration\n // | false => child.duration * this._duration / total child duration\n // }\n const childDuration = lastChild.duration.times(durationFactor);\n const newDuration = remainingDur.minus(childDuration);\n if (newDuration.isGTE(requiredDuration)) {\n // remove ourselves and add to target\n // in both cases duration will be adjusted if need be\n this.removeAtoms(true, lastChild);\n targetGroup.insertAtomsAt(targetGroup.atoms.first, true, lastChild);\n if (newDuration.equals(requiredDuration)) {\n // we have reached the end so return\n return targetGroup;\n }\n } else {\n // our scenario is now this:\n //\n // totalParentDuration = 10\n // required = 8\n // lastChildDuration (relative to parent) is 5\n //\n // durWithoutLast = 10 - 5\n // newRequired = requiredDur - durWithoutLast = 3\n //\n // However 3 is a duration in the parent's frame of reference\n // this has to be converted back to the child's FoR\n const newRequiredDur = requiredDuration.minus(newDuration, true).divby(durationFactor, true);\n // console.log( \"newRequiredDur: \", newRequiredDur, \"requiedDur: \", requiredDuration, \"remainingDur: \", remainingDur,);\n // then the last item needs to be split, and by how much?\n const spillOver = lastChild.splitAt(newRequiredDur);\n if (spillOver == null) {\n throw new Error(\"Spill over cannot be null here\");\n }\n if (!this.durationIsSpeedMultiplier) {\n // Our own duration has also now changed\n this._duration = requiredDuration;\n } else {\n if (this._duration.isZero) throw new Error(\"How can this be?\");\n }\n spillOver.isContinuation = true;\n // Add spill over to the target\n targetGroup.insertAtomsAt(targetGroup.atoms.first, true, spillOver);\n return targetGroup;\n }\n remainingDur = newDuration;\n }\n return targetGroup;\n }\n\n /**\n * Gets the total duration of all child atoms.\n * @returns The sum of durations of all atoms in this group\n */\n get totalChildDuration(): Fraction {\n let out = ZERO;\n for (const atom of this.atoms.values()) {\n out = out.plus(atom.duration);\n }\n return out;\n }\n\n /**\n * Inserts atoms before a given cursor atom.\n * If the cursor atom is null, the atoms are appended at the end.\n *\n * @param beforeAtom The atom before which to insert the new atoms, or null to append\n * @param adjustDuration Whether to adjust this group's duration based on the new atoms\n * @param atoms The atoms to insert\n * @returns This Group instance for method chaining\n */\n insertAtomsAt(beforeAtom: TSU.Nullable<Atom>, adjustDuration = false, ...atoms: Atom[]): this {\n adjustDuration = adjustDuration && !this.durationIsSpeedMultiplier;\n const oldChildDuration = adjustDuration ? this.totalChildDuration : ONE;\n\n // Calculate insertion index for event notification\n let insertIndex: number;\n if (beforeAtom) {\n // Find index of beforeAtom using for loop\n insertIndex = 0;\n for (const a of this.atoms.values()) {\n if (a === beforeAtom) break;\n insertIndex++;\n }\n } else {\n // Appending to end - use size property\n insertIndex = this.atoms.size;\n }\n\n // Track which atoms were actually added (excluding REST atoms)\n const addedAtoms: Atom[] = [];\n\n // First form a chain of the given atoms\n for (const atom of atoms) {\n if (atom.parentGroup != null) {\n if (atom.parentGroup != this) {\n throw new Error(\"Atom belongs to another parent. Remove it first\");\n }\n atom.parentGroup.removeAtoms(false, atom);\n }\n if (atom.TYPE == AtomType.REST) {\n const last = this.atoms.last;\n if (last && last.TYPE != AtomType.GROUP && last.TYPE != AtomType.LABEL) {\n (last as LeafAtom).beforeRest = true;\n }\n } else {\n atom.parentGroup = this;\n this.atoms.add(atom, beforeAtom);\n addedAtoms.push(atom);\n }\n }\n if (adjustDuration) {\n if (this._duration.isZero) {\n if (this.durationIsSpeedMultiplier) throw new Error(\"How can this be?\");\n this._duration = this.totalChildDuration;\n } else {\n const scaleFactor = this.totalChildDuration.divby(oldChildDuration);\n this._duration = this._duration.times(scaleFactor, true);\n }\n }\n\n // Notify observers if atoms were added\n if (addedAtoms.length > 0) {\n const type = beforeAtom ? AtomChangeType.INSERT : AtomChangeType.ADD;\n this.notifyObservers(type, addedAtoms, insertIndex);\n }\n\n return this;\n }\n\n /**\n * Adds atoms to the end of this group's atom list.\n *\n * @param adjustDuration Whether to adjust this group's duration based on the new atoms\n * @param atoms The atoms to add\n * @returns This Group instance for method chaining\n */\n addAtoms(adjustDuration = false, ...atoms: Atom[]): this {\n return this.insertAtomsAt(null, adjustDuration, ...atoms);\n }\n\n /**\n * Removes atoms from this group's child list.\n *\n * @param adjustDuration Whether to adjust this group's duration after removing atoms\n * @param atoms The atoms to remove\n * @returns This Group instance for method chaining\n */\n removeAtoms(adjustDuration = false, ...atoms: Atom[]): this {\n adjustDuration = adjustDuration && !this.durationIsSpeedMultiplier;\n const oldChildDuration = adjustDuration ? this.totalChildDuration : ONE;\n\n // Track which atoms were actually removed\n const removedAtoms: Atom[] = [];\n\n for (const atom of atoms) {\n if (atom.parentGroup == this) {\n this.atoms.remove(atom);\n atom.parentGroup = null;\n removedAtoms.push(atom);\n } else if (atom.parentGroup != null) {\n throw new Error(\"Atom cannot be removed as it does not belong to this group\");\n }\n }\n if (adjustDuration) {\n if (this._duration.isZero) {\n if (this.durationIsSpeedMultiplier) throw new Error(\"How can this be?\");\n this._duration = this.totalChildDuration;\n } else {\n const scaleFactor = this.totalChildDuration.divby(oldChildDuration);\n this._duration = this._duration.times(scaleFactor, true);\n }\n }\n\n // Notify observers if atoms were removed\n if (removedAtoms.length > 0) {\n this.notifyObservers(AtomChangeType.REMOVE, removedAtoms, -1);\n }\n\n return this;\n }\n}\n\n/**\n * Represents a line of notation containing multiple roles.\n * A line can have atoms starting before or after the cycle.\n */\nexport class Line extends Entity {\n readonly TYPE: string = \"Line\";\n\n /**\n * Offset tells how many notes before or after the cycle this line's atoms start at.\n */\n offset: Fraction = ZERO;\n\n /**\n * The roles contained in this line.\n */\n roles: Role[] = [];\n\n /**\n * Text to be displayed in the margin of the line.\n * This is a hacky solution to doing left side pre-margin text typically\n * found in notations - e.g., line X of a pallavi has this. This makes vertical\n * space less wasteful.\n *\n * A better solution is inter-beat annotation but it is very complex for now.\n */\n marginText = \"\";\n\n /**\n * The LayoutParams associated with this line.\n */\n layoutParams: LayoutParams;\n\n /**\n * Observers that receive notifications when roles change.\n */\n private _observers: LineObserver<Role, Line>[] = [];\n\n /**\n * Adds an observer to receive role change notifications.\n * @param observer The observer to add\n * @returns A function to remove the observer\n */\n addObserver(observer: LineObserver<Role, Line>): () => void {\n this._observers.push(observer);\n return () => this.removeObserver(observer);\n }\n\n /**\n * Removes an observer.\n * @param observer The observer to remove\n */\n removeObserver(observer: LineObserver<Role, Line>): void {\n const index = this._observers.indexOf(observer);\n if (index >= 0) {\n this._observers.splice(index, 1);\n }\n }\n\n /**\n * Finds the index of a role with the given name.\n * @param name The name of the role to find\n * @returns The index of the role, or -1 if not found\n */\n indexOfRole(name: string): number {\n for (let i = 0; i < this.roles.length; i++) {\n if (this.roles[i].name == name) return i;\n }\n return -1;\n }\n\n /**\n * Checks if this line is empty (has no content in any role).\n */\n get isEmpty(): boolean {\n for (const r of this.roles) if (!r.isEmpty) return false;\n return true;\n }\n\n /**\n * Returns a debug-friendly representation of this Line.\n * @returns An object containing debug information\n */\n debugValue(): any {\n const out = {\n ...super.debugValue(),\n roles: this.roles.map((r) => r.debugValue()),\n };\n if (!this.offset.isZero) {\n out.offset = this.offset.toString();\n }\n return out;\n }\n\n /**\n * Copies the properties of this Line to another Line.\n * @param another The target Line to copy properties to\n */\n copyTo(another: this): void {\n super.copyTo(another);\n another.roles = this.roles.map((r) => r.clone());\n }\n\n /**\n * Adds atoms to a role in this line.\n * @param roleName The name of the role to add atoms to\n * @param defaultToNotes Whether to default to notes for this role\n * @param atoms The atoms to add\n * @returns This Line instance for method chaining\n */\n addAtoms(roleName: string, defaultToNotes: boolean, ...atoms: Atom[]): this {\n const role = this.ensureRole(roleName, defaultToNotes);\n role.addAtoms(...atoms);\n return this;\n }\n\n /**\n * Ensures a role with the given name exists in this line, creating it if needed.\n * @param roleName The name of the role to ensure\n * @param defaultToNotes Whether to default to notes for this role\n * @returns The role with the specified name\n */\n ensureRole(roleName: string, defaultToNotes: boolean): Role {\n // Ensure we have this many roles\n let ri = this.roles.findIndex((r) => r.name == roleName);\n if (ri < 0) {\n ri = this.roles.length;\n const role = new Role(this, roleName);\n role.defaultToNotes = defaultToNotes;\n this.roles.push(role);\n\n // Notify observers of new role\n if (this._eventsEnabled) {\n for (const observer of this._observers) {\n observer.onRoleAdded?.(this, roleName, role);\n }\n }\n }\n return this.roles[ri];\n }\n\n /**\n * Removes a role from this line.\n * @param roleName The name of the role to remove\n * @returns True if the role was removed, false if not found\n */\n removeRole(roleName: string): boolean {\n const ri = this.roles.findIndex((r) => r.name == roleName);\n if (ri >= 0) {\n this.roles.splice(ri, 1);\n\n // Notify observers of removed role\n if (this._eventsEnabled) {\n for (const observer of this._observers) {\n observer.onRoleRemoved?.(this, roleName);\n }\n }\n return true;\n }\n return false;\n }\n\n /**\n * Gets the maximum duration across all roles in this line.\n */\n get duration(): Fraction {\n let max = ZERO;\n for (const role of this.roles) {\n max = TSU.Num.Fraction.max(role.duration, max);\n }\n return max;\n }\n}\n\n/**\n * Represents a specific role or voice in a line of notation.\n * Each role contains a sequence of atoms.\n */\nexport class Role extends Entity {\n readonly TYPE = \"Role\";\n\n /**\n * Whether this role represents notes by default.\n */\n defaultToNotes = true;\n\n /**\n * The atoms in this role.\n */\n atoms: Atom[] = [];\n\n /**\n * Observers that receive notifications when atoms change.\n */\n private _observers: RoleObserver<Atom, Role>[] = [];\n\n /**\n * Creates a new Role with the specified line and name.\n * @param line The line this role belongs to\n * @param name The name of the role\n */\n constructor(\n public readonly line: Line,\n public readonly name: string,\n ) {\n super();\n }\n\n /**\n * Adds an observer to receive atom change notifications.\n * @param observer The observer to add\n * @returns A function to remove the observer\n */\n addObserver(observer: RoleObserver<Atom, Role>): () => void {\n this._observers.push(observer);\n return () => this.removeObserver(observer);\n }\n\n /**\n * Removes an observer.\n * @param observer The observer to remove\n */\n removeObserver(observer: RoleObserver<Atom, Role>): void {\n const index = this._observers.indexOf(observer);\n if (index >= 0) {\n this._observers.splice(index, 1);\n }\n }\n\n /**\n * Notifies observers of atom changes.\n */\n private notifyObservers(type: AtomChangeType, atoms: Atom[], index: number): void {\n if (!this._eventsEnabled) return;\n for (const observer of this._observers) {\n switch (type) {\n case AtomChangeType.ADD:\n observer.onAtomsAdded?.(this, atoms, index);\n break;\n case AtomChangeType.INSERT:\n observer.onAtomsInserted?.(this, atoms, index);\n break;\n case AtomChangeType.REMOVE:\n observer.onAtomsRemoved?.(this, atoms);\n break;\n }\n }\n }\n\n /**\n * Checks if this role is empty (has no atoms).\n */\n get isEmpty(): boolean {\n return this.atoms.length == 0;\n }\n\n /**\n * Returns a debug-friendly representation of this Role.\n * @returns An object containing debug information\n */\n debugValue(): any {\n return { name: this.name, atoms: this.atoms.map((a) => a.debugValue()) };\n }\n\n /**\n * Adds atoms to the end of this role.\n * @param atoms The atoms to add\n */\n addAtoms(...atoms: Atom[]): void {\n this.insertAtomsAt(this.atoms.length, ...atoms);\n }\n\n /**\n * Inserts atoms at a specific index in this role.\n * @param index The index at which to insert\n * @param atoms The atoms to insert\n */\n insertAtomsAt(index: number, ...atoms: Atom[]): void {\n // Track which atoms were actually added (excluding REST atoms)\n const addedAtoms: Atom[] = [];\n let last: null | Atom = index > 0 ? this.atoms[index - 1] : null;\n\n for (const atom of atoms) {\n if (atom.TYPE == AtomType.REST) {\n if (last && last.TYPE != AtomType.GROUP && last.TYPE != AtomType.LABEL) {\n (last as LeafAtom).beforeRest = true;\n }\n } else {\n this.atoms.splice(index + addedAtoms.length, 0, atom);\n addedAtoms.push(atom);\n }\n last = atom;\n }\n\n // Notify observers if atoms were added\n if (addedAtoms.length > 0) {\n const isAppend = index >= this.atoms.length - addedAtoms.length;\n const type = isAppend ? AtomChangeType.ADD : AtomChangeType.INSERT;\n this.notifyObservers(type, addedAtoms, index);\n }\n }\n\n /**\n * Removes atoms from this role.\n * @param atoms The atoms to remove\n */\n removeAtoms(...atoms: Atom[]): void {\n const removedAtoms: Atom[] = [];\n\n for (const atom of atoms) {\n const idx = this.atoms.indexOf(atom);\n if (idx >= 0) {\n this.atoms.splice(idx, 1);\n removedAtoms.push(atom);\n }\n }\n\n // Notify observers if atoms were removed\n if (removedAtoms.length > 0) {\n this.notifyObservers(AtomChangeType.REMOVE, removedAtoms, -1);\n }\n }\n\n /**\n * Copies the properties of this Role to another Role.\n * @param another The target Role to copy properties to\n */\n copyTo(another: Role): void {\n another.addAtoms(...this.atoms);\n }\n\n /**\n * Gets the total duration of all atoms in this role.\n */\n get duration(): Fraction {\n return this.atoms.reduce((a, b) => a.plus(b.duration), ZERO);\n }\n}\n","import * as TSU from \"@panyam/tsutils\";\nimport { Cycle, CyclePosition, CycleCursor } from \"./cycle\";\n\ntype Fraction = TSU.Num.Fraction;\nconst ZERO = TSU.Num.Fraction.ZERO;\n\n/**\n * Manages layout parameters for arranging beats and notes in the notation.\n * LayoutParams determines how beats are organized into lines and rows based on\n * cycle patterns and line breaks.\n */\nexport class LayoutParams {\n private static counter = 0;\n /** Unique identifier for this layout parameters instance */\n readonly uuid = LayoutParams.counter++;\n\n /** Duration of a single beat (multiplier for beat lengths) */\n beatDuration: number;\n\n /** The cycle pattern to use for this layout */\n cycle: Cycle;\n\n /** The pattern of line breaks to apply */\n protected _lineBreaks: number[];\n\n /** Cache of row start offsets */\n private _rowStartOffsets: Fraction[];\n\n /** Cache of row end offsets */\n private _rowEndOffsets: Fraction[];\n\n /** Cache of row durations */\n private _rowDurations: Fraction[];\n\n /** Total duration of the layout pattern */\n private _totalLayoutDuration;\n\n /** Cached beat layout information */\n private _beatLayouts: [CyclePosition, Fraction][][];\n\n /** Total number of beats across all layout lines */\n private _totalBeats: number;\n\n /**\n * Creates a new LayoutParams instance.\n * @param config Configuration object containing beatDuration, cycle, and lineBreaks\n */\n constructor(config?: any) {\n config = config || {};\n this.beatDuration = config.beatDuration || 1;\n if (\"cycle\" in config) this.cycle = config.cycle;\n if (!this.cycle || this.cycle.duration.isZero) {\n this.cycle = Cycle.DEFAULT;\n }\n\n this._rowStartOffsets = [];\n this._rowEndOffsets = [];\n this._rowDurations = [];\n this._totalLayoutDuration = ZERO;\n this._totalBeats = 0;\n this._beatLayouts = [];\n this.lineBreaks = config.lineBreaks || config.layout || [];\n }\n\n /**\n * Checks if this LayoutParams is equal to another LayoutParams.\n * @param another The LayoutParams to compare with\n * @returns True if the LayoutParams are equal, false otherwise\n */\n equals(another: this): boolean {\n return (\n // super.equals(another) &&\n this.beatDuration == another.beatDuration &&\n this.cycle.equals(another.cycle) &&\n this.lineBreaksEqual(another._lineBreaks)\n );\n }\n\n /**\n * Checks if the line breaks pattern is equal to another pattern.\n * @param another The line breaks pattern to compare with\n * @returns True if the patterns are equal, false otherwise\n */\n lineBreaksEqual(another: number[]): boolean {\n return this._lineBreaks.length == another.length && this._lineBreaks.every((x, i) => x == another[i]);\n }\n\n /**\n * Returns a debug-friendly representation of this LayoutParams.\n * @returns An object containing debug information\n */\n debugValue(): any {\n return {\n // ...super.debugValue(),\n cycle: this.cycle?.debugValue(),\n beatDuration: this.beatDuration,\n lineBreaks: this._lineBreaks,\n };\n }\n\n /**\n * Returns the \"location\" of a beat within a layout.\n *\n * Lines are broken into beats of notes and those beats are aligned as per\n * the specs in the LayoutParams (breaks). For example if the breaks param\n * stipulates [5, 5, 4] then we have 5 beats in the first 2 lines and 4 in\n * the last line.\n *\n * @param beat The beat to locate\n * @returns A tuple containing [layoutLine, layoutColumn, rowOffset]\n * - layoutLine: The line in the layout break spec this beat falls in\n * - layoutColumn: The column within the layoutLine\n * - rowOffset: The offset of the beat from the start of the row/line\n */\n getBeatLocation(beat: {\n index: number;\n barIndex: number;\n beatIndex: number;\n instance: number;\n }): [number, number, Fraction] {\n //\n // If a line contains say 50 beats (B1 - B50), then it is laid out as:\n //\n // C0 C1 C2 C3 C4\n // ---------------------\n // L0 | B1 B2 B3 B4 B5\n // L1 | B6 B7 B8 B9 B10\n // L2 | B11 B12 B13 B14\n // L0 | B15 B16 B17 B18 B19\n // L1 | B20 B21 B22 B23 B24\n // L2 | B25 B26 B27 B28\n // L0 | B29 B30 B31 B32 B33\n // L1 | B34 B35 B36 B37 B38\n // L2 | B39 B40 B41 B42\n // L0 | B43 B44 B45 B46 B47\n // L1 | B48 B49 B50\n //\n // This methods returns the triple: [layoutLine, layoutColumn, rowOffset]\n // where\n //\n // layoutLine: The particular line in the layout break spec this index falls in.\n // *Note*: Since lines can start with negative offsets, we can\n // even return a layoutLine that is towards the end and then go\n // back to 0, eg 4, 0, 1, 2, 3, 4, 0, 1, 2, 3, 4 ...\n // (eg returns L0 or L1 ... Ln)\n // layoutColumn: The column within the layoutLine line where this beat falls.\n // (eg C0 - C4 above - or depending on how many columns exist\n // in the particular layout line).\n // rowOffset: The note offset of the beat from the start of the row/line\n // (not from the start of the cycle).\n //\n // Note the beatIndex can also be negative so we can return a beat\n // starting from before the cycle starting point.\n //\n // To calculate the \"real\" line globally simply do:\n //\n // realLine = lineBreaks.length // Math.floor(beatIndex / this.totalBeats) + layoutLine;\n //\n // Some examples here are (using B1-B50 above):\n const modIndex = beat.index % this.totalBeats;\n let total = 0;\n for (let i = 0; i < this._lineBreaks.length; i++) {\n if (modIndex < total + this._lineBreaks[i]) {\n // TODO: What is the right offset here?\n let offset = ZERO;\n if (modIndex > total) {\n const cursor = new CycleCursor(this.cycle, beat.barIndex, beat.beatIndex, beat.instance);\n let [, duration] = cursor.prev;\n for (let i = total; i < modIndex; i++) {\n [, duration] = cursor.prev;\n offset = offset.plus(duration.timesNum(this.beatDuration));\n }\n }\n return [i, modIndex - total, offset];\n }\n total += this._lineBreaks[i];\n }\n throw new Error(\"Invalid beat index: \" + beat.index);\n return [-1, -1, ZERO];\n }\n\n /**\n * Gets the line layout pattern - i.e., number of beats in each line - as a\n * repeating pattern.\n *\n * For example 4,2,4 indicates that the notes in our song should be\n * laid out 4 beats in line 1, 2 beats in line 2, 4 beats in line 3 and\n * 4 beats in line 4 and so on as long as there are more notes available\n * in this line.\n */\n get lineBreaks(): number[] {\n if (!this._lineBreaks || this._lineBreaks.length == 0) {\n // trigger a refresh\n this.lineBreaks = [this.cycle.beatCount];\n }\n return this._lineBreaks;\n }\n\n /**\n * Sets the line layout pattern.\n */\n set lineBreaks(val: number[]) {\n this._lineBreaks = val;\n this.refreshLayout();\n }\n\n /**\n * Returns the number of beats in each line based on the line layout\n * after taking beatDuration into account.\n */\n get beatLayouts(): ReadonlyArray<ReadonlyArray<[CyclePosition, Fraction]>> {\n if (!this._beatLayouts || this._beatLayouts.length < this.lineBreaks.length) {\n this.refreshLayout();\n }\n return this._beatLayouts;\n }\n\n /**\n * Gets the total number of beats across all lines in the layout pattern.\n */\n get totalBeats(): number {\n this.beatLayouts;\n return this._totalBeats;\n }\n\n /**\n * Gets the total duration of all beats across all lines in the layout pattern.\n */\n get totalLayoutDuration(): Fraction {\n this.beatLayouts;\n return this._totalLayoutDuration;\n }\n\n /**\n * Refreshes the layout calculations based on the current cycle and line breaks.\n * This rebuilds the beat layouts, row durations, and offset information.\n */\n protected refreshLayout(): void {\n const cycleIter = this.cycle.iterateBeats();\n const akb = this.beatDuration;\n this._beatLayouts = this.lineBreaks.map((numBeats, index) => {\n const beats: [CyclePosition, Fraction][] = [];\n // see what the beat lengths are here\n for (let i = 0; i < numBeats; i++) {\n const nextCP = cycleIter.next().value;\n nextCP[1] = nextCP[1].timesNum(akb);\n beats.push(nextCP);\n }\n return beats;\n });\n this._totalBeats = this.lineBreaks.reduce((a, b) => a + b, 0);\n this._rowDurations = this._beatLayouts.map((beats) => beats.reduce((x, y) => x.plus(y[1]), ZERO));\n this._rowDurations.forEach((rd, index) => {\n this._rowStartOffsets[index] = index == 0 ? ZERO : this._rowStartOffsets[index - 1].plus(rd);\n });\n this._rowEndOffsets = this._rowDurations.map((rd, index) => {\n return this._rowStartOffsets[index].plus(rd);\n });\n this._totalLayoutDuration = this._rowDurations.reduce((x, y) => x.plus(y), ZERO);\n }\n}\n","import * as TSU from \"@panyam/tsutils\";\n// import * as kiwi from \"@lume/kiwi\";\n\n/**\n * Event emitted when layout changes occur in a GridLayoutGroup.\n * Subscribers can use this to update their views incrementally.\n */\nexport interface LayoutChangeEvent {\n /** The range of rows affected by the change */\n affectedRowRange: { start: number; end: number } | null;\n /** The range of columns affected by the change */\n affectedColRange: { start: number; end: number } | null;\n /** Whether column widths changed (requires horizontal re-layout) */\n columnWidthsChanged: boolean;\n /** Whether row heights changed (requires vertical re-layout) */\n rowHeightsChanged: boolean;\n /** The grid models that were affected */\n affectedGridModels: GridModel[];\n}\n\n/**\n * Callback type for layout change subscribers.\n */\nexport type LayoutChangeCallback = (event: LayoutChangeEvent) => void;\n\n/**\n * A generic grid layout system for hosting child views (similar to GridBagLayout).\n * This provides a framework for hosting BeatViews in a structured grid arrangement,\n * with support for rows, columns, and alignment.\n *\n * Grid \"cells\" can be referred to by cell indexes. Additionally, grid rows and\n * columns can have names (like in spreadsheets) so that even when rows and columns\n * are inserted, though indexes may change, the \"addresses\" remain fixed and immovable.\n */\nexport class GridModel extends TSU.Events.EventEmitter {\n private static idCounter = 0;\n readonly uuid = GridModel.idCounter++;\n /** Timestamp of the last update to this grid */\n lastUpdatedAt = 0;\n // cells = new SparseArray<SparseArray<GridCell>>();\n /** The rows in this grid */\n rows: GridRow[] = [];\n /** Mapping of row indices to row alignment objects */\n rowAligns = new Map<number, RowAlign>();\n /** Mapping of column indices to column alignment objects */\n colAligns = new Map<number, ColAlign>();\n\n /**\n * Returns a debug-friendly representation of this GridModel.\n * @returns An object containing debug information\n */\n debugValue() {\n const out = {\n rows: this.rows.map((r) => r.debugValue()),\n lastUpdatedAt: this.lastUpdatedAt,\n } as any;\n return out;\n }\n\n /**\n * Gets the index of the first non-empty row.\n * @returns The index of the first row containing cells, or -1 if none\n */\n get firstRow(): number {\n for (const gr of this.rows) {\n if (gr.numCells > 0) return gr.rowIndex;\n }\n return -1;\n }\n\n /**\n * Gets the index of the leftmost column containing cells.\n * @returns The index of the first column containing cells, or -1 if none\n */\n get firstCol(): number {\n let minCol = -1;\n for (const gr of this.rows) {\n const fc = gr.firstCol;\n if (fc >= 0) {\n if (minCol < 0 || fc < minCol) {\n minCol = fc;\n }\n }\n }\n return minCol;\n }\n\n /**\n * Gets all non-empty cells in a specific row.\n * @param row The index of the row\n * @returns An array of cells in the row\n */\n cellsInRow(row: number): GridCell[] {\n const out = [] as GridCell[];\n const gr = this.rows[row];\n if (gr) {\n for (const cell of gr.cells) {\n if (cell?.value) out.push(cell);\n }\n }\n return out;\n }\n\n /**\n * Gets all non-empty cells in a specific column.\n * @param col The index of the column\n * @returns An array of cells in the column\n */\n cellsInCol(col: number): GridCell[] {\n const out = [] as GridCell[];\n for (const gr of this.rows) {\n const cell = gr.cellAt(col);\n if (cell?.value) out.push(cell);\n }\n return out;\n }\n\n /**\n * Adds a row alignment object to the grid.\n * @param align The row alignment to add\n */\n addRowAlign(align: RowAlign): void {\n this.rowAligns.set(align.uuid, align);\n }\n\n /**\n * Adds a column alignment object to the grid.\n * @param align The column alignment to add\n */\n addColAlign(align: ColAlign): void {\n this.colAligns.set(align.uuid, align);\n }\n\n /**\n * Adds rows to the grid.\n * @param insertBefore The index before which to insert the rows, or -1 to append\n * @param numRows The number of rows to add\n * @returns This grid instance for method chaining\n */\n addRows(insertBefore = -1, numRows = 1): this {\n if (insertBefore < 0) {\n insertBefore = this.rows.length;\n }\n let next = this.rows[insertBefore] || null;\n const prev = this.rows[insertBefore - 1] || null;\n for (let i = numRows - 1; i >= 0; i--) {\n const newRow = new GridRow(this, insertBefore + i);\n this.rows.splice(insertBefore, 0, newRow);\n if (next != null) {\n newRow.defaultRowAlign.addSuccessor(next.defaultRowAlign);\n }\n if (i == 0 && insertBefore > 0) {\n prev.defaultRowAlign.addSuccessor(newRow.defaultRowAlign);\n }\n next = newRow;\n }\n for (let i = insertBefore + numRows; i < this.rows.length; i++) {\n this.rows[i].rowIndex += numRows;\n }\n return this;\n }\n\n /**\n * Gets a row at the specified index, creating it if necessary.\n * @param row The index of the row to get\n * @returns The row at the specified index\n */\n getRow(row: number): GridRow {\n if (row >= this.rows.length) {\n this.addRows(-1, 1 + row - this.rows.length);\n }\n return this.rows[row];\n }\n\n /**\n * Sets a value in a cell at the specified row and column.\n * @param row The row index\n * @param col The column index\n * @param value The value to set\n * @param cellCreator Optional function to create a custom cell\n * @returns The previous value of the cell\n */\n setValue(row: number, col: number, value: any, cellCreator?: (row: GridRow, col: number) => GridCell): any {\n const grow = this.getRow(row);\n if (!cellCreator) {\n cellCreator = (row: GridRow, col: number) => {\n return new GridCell(row, col);\n };\n }\n if (value == null) {\n const out = grow.clearCellAt(col);\n if (out != null) {\n this.eventHub?.emit(GridCellEvent.CLEARED, this, {\n loc: out.location,\n });\n }\n return out;\n } else {\n const cell = grow.cellAt(col, cellCreator) as GridCell;\n const oldValue = cell.value;\n this.eventHub?.emit(GridCellEvent.UPDATED, this, {\n loc: cell.location,\n cell: cell,\n oldValue: cell.value,\n });\n cell.value = value;\n return oldValue;\n }\n }\n\n /**\n * Handles changes to the event hub.\n */\n protected eventHubChanged(): void {\n console.log(\"Event Hub Changed for GridModel\");\n }\n}\n\n/**\n * Interface for a view associated with a grid cell.\n * GridCellView defines the contract for views that can be placed in grid cells.\n */\nexport interface GridCellView {\n /** The grid cell this view is associated with */\n readonly cell: GridCell;\n /** X-coordinate of the view */\n x: number;\n /** Y-coordinate of the view */\n y: number;\n /** Width of the view */\n width: number;\n /** Height of the view */\n height: number;\n\n /**\n * Sets the bounds of the view.\n * @param x New x-coordinate, or null to keep current value\n * @param y New y-coordinate, or null to keep current value\n * @param w New width, or null to keep current value\n * @param h New height, or null to keep current value\n * @param applyLayout Whether to apply layout immediately\n * @returns The new bounds values\n */\n setBounds(\n x: number | null,\n y: number | null,\n w: number | null,\n h: number | null,\n applyLayout: boolean,\n ): [number | null, number | null, number | null, number | null];\n\n /** Whether this view needs layout */\n readonly needsLayout: boolean;\n\n /** The minimum size this view requires */\n readonly minSize: TSU.Geom.Size;\n\n /** The bounding box of this view */\n readonly bbox: TSU.Geom.Rect;\n}\n\n/**\n * Enum defining the events that can occur on grid cells.\n */\nexport enum GridCellEvent {\n ADDED = \"CellAdded\",\n CLEARED = \"CellCleared\",\n REMOVED = \"CellRemoved\",\n UPDATED = \"CellUpdated\",\n MOVED = \"CellMoved\",\n}\n\n/**\n * Represents a cell in the grid.\n * GridCell holds a value and manages alignment with rows and columns.\n */\nexport class GridCell {\n private static idCounter = 0;\n readonly uuid = GridCell.idCounter++;\n /** The view associated with this cell */\n cellView: GridCellView | null;\n private _rowAlign: RowAlign;\n private _colAlign: ColAlign;\n\n /**\n * Creates a new GridCell.\n * @param gridRow The row this cell belongs to\n * @param colIndex The column index of this cell\n * @param value Optional initial value for the cell\n */\n constructor(\n public gridRow: GridRow,\n public colIndex: number,\n public value: any = null,\n ) {\n this.rowAlign = gridRow.defaultRowAlign;\n }\n\n /**\n * Gets the row alignment for this cell.\n */\n get rowAlign(): RowAlign {\n return this._rowAlign;\n }\n\n /**\n * Sets the row alignment for this cell.\n */\n set rowAlign(val: RowAlign) {\n val.addCell(this);\n this._rowAlign = val;\n }\n\n /**\n * Gets the column alignment for this cell.\n */\n get colAlign(): ColAlign {\n return this._colAlign;\n }\n\n /**\n * Sets the column alignment for this cell.\n */\n set colAlign(val: ColAlign) {\n val.addCell(this);\n this._colAlign = val;\n }\n\n /**\n * Gets the location string for this cell (rowIndex:colIndex).\n */\n get location(): string {\n return this.gridRow.rowIndex + \":\" + this.colIndex;\n }\n\n /**\n * Gets the grid this cell belongs to.\n */\n get grid(): GridModel {\n return this.gridRow.grid;\n }\n\n /**\n * Gets the row index of this cell.\n */\n get rowIndex(): number {\n return this.gridRow.rowIndex;\n }\n\n /**\n * Returns a debug-friendly representation of this GridCell.\n * @returns An object containing debug information\n */\n debugValue() {\n const out = {\n r: this.gridRow.rowIndex,\n c: this.colIndex,\n value: this.value,\n y: this.rowAlign.coordOffset,\n h: this.rowAlign.maxLength,\n } as any;\n if (this.colAlign) {\n out.x = this.colAlign.coordOffset;\n out.w = this.colAlign.maxLength;\n }\n return out;\n }\n}\n\n/**\n * Represents a row of grid cells in a GridModel.\n */\nexport class GridRow {\n /** The cells in this row */\n cells: (null | GridCell)[] = [];\n /** The default vertical alignment for all cells in this row */\n defaultRowAlign: RowAlign;\n\n /**\n * Creates a new GridRow.\n * @param grid The grid this row belongs to\n * @param rowIndex The index of this row\n */\n constructor(\n public grid: GridModel,\n public rowIndex: number,\n ) {\n this.defaultRowAlign = new RowAlign();\n this.grid.addRowAlign(this.defaultRowAlign);\n }\n\n /**\n * Gets the index of the first non-empty column in this row.\n */\n get firstCol() {\n for (let i = 0; i < this.cells.length; i++) {\n if (this.cells[i]?.value) {\n return i;\n }\n }\n return -1;\n }\n\n /**\n * Gets the number of columns in this row.\n */\n get numCols() {\n return this.cells.length;\n }\n\n /**\n * Gets the number of cells that contain values.\n */\n get numCells() {\n let i = 0;\n for (const cell of this.cells) {\n if (cell != null && cell.value != null) i++;\n }\n return i;\n }\n\n /**\n * Gets the cell at the specified column index, optionally creating it if it doesn't exist.\n * @param col The column index\n * @param creator Optional function to create the cell if it doesn't exist\n * @returns The cell at the specified index, or null if it doesn't exist and no creator was provided\n */\n cellAt(col: number, creator?: (row: GridRow, col: number) => GridCell): GridCell | null {\n let out = this.cells[col] || null;\n if (!out && creator) {\n this.cells[col] = out = creator(this, col);\n out.gridRow = this;\n out.colIndex = col;\n if (out.rowAlign) {\n this.grid.addRowAlign(out.rowAlign);\n }\n if (out.colAlign) {\n this.grid.addColAlign(out.colAlign);\n }\n }\n return out;\n }\n\n /**\n * Clears the cell at the given column.\n * Note this is not the same as \"removing\" a cell.\n * Removing a cell would require all cells to the \"right\" to be shifted left.\n * @param col The column index\n * @returns The cell that was cleared, or null if none existed\n */\n clearCellAt(col: number): GridCell | null {\n const out = this.cells[col] || null;\n if (out) {\n this.cells[col] = null;\n }\n return out;\n }\n\n /**\n * Returns a debug-friendly representation of this GridRow.\n * @returns An object containing debug information\n */\n debugValue() {\n return {\n r: this.rowIndex,\n cells: this.cells.filter((c) => c).map((c) => c?.debugValue()),\n };\n }\n}\n\n/**\n * Base class for row and column alignment objects.\n * AlignedLine manages the alignment of cells along a line (row or column).\n */\nexport abstract class AlignedLine {\n private static idCounter = 0;\n readonly uuid = AlignedLine.idCounter++;\n /** Whether this line needs layout */\n needsLayout = false;\n /** The coordinate offset of this line */\n protected _coordOffset = 0;\n /** The maximum length of this line */\n protected _maxLength = 0;\n /** Padding before this line */\n paddingBefore = 5;\n /** Padding after this line */\n paddingAfter = 5;\n /** The cells that belong to this line */\n cells: GridCell[] = [];\n /** Function to get a view for a cell value */\n getCellView: (value: any) => GridCellView;\n\n /**\n * Sets the offset of this line.\n * @param val The new offset value\n */\n abstract setOffset(val: number): void;\n\n /**\n * Evaluates the maximum length required for this line.\n * @param changedCells Cells that have changed and need re-evaluation\n * @returns The maximum length\n */\n abstract evalMaxLength(changedCells: GridCell[]): number;\n\n /**\n * Gets the coordinate offset of this line.\n */\n get coordOffset(): number {\n return this._coordOffset;\n }\n\n /**\n * Gets the maximum length of this line, including padding.\n */\n get maxLength(): number {\n return this._maxLength + this.paddingBefore + this.paddingAfter;\n }\n\n /**\n * Sets the maximum length of this line.\n * @param length The new maximum length\n */\n setMaxLength(length: number) {\n this._maxLength = length;\n }\n\n /**\n * Sets the padding before and after this line.\n * @param before Padding before the line\n * @param after Padding after the line\n */\n setPadding(before: number, after: number): void {\n if (before >= 0) {\n this.paddingBefore = before;\n }\n if (after >= 0) {\n this.paddingAfter = after;\n }\n }\n\n /**\n * Adds a cell to this line.\n * @param cell The cell to add\n * @returns This line instance for method chaining\n */\n addCell(cell: GridCell): this {\n if (this.beforeAddingCell(cell)) {\n this.cells.push(cell);\n }\n return this;\n }\n\n /**\n * Called before adding a cell to perform validation or preparation.\n * @param cell The cell to be added\n * @returns Whether the cell should be added\n */\n protected abstract beforeAddingCell(cell: GridCell): boolean;\n\n /**\n * Removes a cell from this line.\n * @param cell The cell to remove\n * @returns This line instance for method chaining\n */\n removeCell(cell: GridCell): this {\n if (this.beforeRemovingCell(cell)) {\n for (let i = 0; i < this.cells.length; i++) {\n if (this.cells[i].uuid == cell.uuid) {\n this.cells.splice(i, 1);\n break;\n }\n }\n }\n return this;\n }\n\n /**\n * Called before removing a cell to perform validation.\n * @param cell The cell to be removed\n * @returns Whether the cell should be removed\n */\n protected abstract beforeRemovingCell(cell: GridCell): boolean;\n\n // The \"neighboring\" lines that depend on this line to be placed\n // before they are placed\n /** Lines that must be positioned before this line */\n prevLines = [] as this[];\n /** Lines that must be positioned after this line */\n nextLines = [] as this[];\n\n /**\n * Adds a successor line to this line.\n * @param next The line to add as a successor\n */\n addSuccessor(next: this): void {\n // Set nextCol as a successor of this col\n // TODO - Ensure no cycles\n for (const c of this.nextLines) {\n if (c == next) return;\n }\n this.nextLines.push(next);\n next.prevLines.push(this);\n }\n\n /* TODO: Disabling only to improve test coverage as this method is\n * not used.\n * When we have mutable grids where we can insert/remove neighbors\n * we can enable this again.\n */\n /*\n removeSuccessor(next: this): void {\n // Set nextCol as a successor of this col\n // TODO - Ensure no cycles\n for (let i = 0; i < this.nextLines.length; i++) {\n if (this.nextLines[i] == next) {\n this.nextLines.splice(i, 1);\n break;\n }\n }\n for (let i = 0; i < next.prevLines.length; i++) {\n if (next.prevLines[i] == this) {\n next.prevLines.splice(i, 1);\n break;\n }\n }\n }\n */\n}\n\n/**\n * Manages the alignment of cells in a column.\n */\nexport class ColAlign extends AlignedLine {\n paddingBefore = 10;\n /** Padding after this line */\n paddingAfter = 10;\n\n /**\n * Sets the offset of this column and updates all associated cells.\n * @param val The new offset value\n */\n setOffset(val: number): void {\n this._coordOffset = val;\n for (const cell of this.cells) {\n if (cell.value) {\n const cellView = this.getCellView(cell);\n if (this._maxLength <= 0) {\n // this hasnt been evaluated yet so do it!\n this.evalMaxLength();\n }\n cellView.setBounds(val, null, this.maxLength, null, true);\n }\n }\n }\n\n /**\n * Evaluates the maximum width required for this column.\n * @param changedCells Cells that have changed and need re-evaluation\n * @returns The maximum width\n */\n evalMaxLength(changedCells: GridCell[] = []): number {\n this._maxLength = 0;\n for (const cell of this.cells) {\n if (cell.value) {\n const cellView = this.getCellView(cell);\n this._maxLength = Math.max(cellView.minSize.width, this._maxLength);\n }\n }\n return this._maxLength;\n }\n\n /**\n * Called before adding a cell to perform validation or preparation.\n * @param cell The cell to be added\n * @returns Whether the cell should be added\n */\n protected beforeAddingCell(cell: GridCell): boolean {\n if (cell.colAlign && cell.colAlign != this) {\n cell.colAlign.removeCell(cell);\n }\n return cell.colAlign != this;\n }\n\n /**\n * Called before removing a cell to perform validation.\n * @param cell The cell to be removed\n * @returns Whether the cell should be removed\n */\n beforeRemovingCell(cell: GridCell): boolean {\n return cell.colAlign == this;\n }\n}\n\n/**\n * Manages the alignment of cells in a row.\n */\nexport class RowAlign extends AlignedLine {\n /**\n * Sets the Y coordinate of all cells in this row.\n * @param val The new Y coordinate\n */\n setOffset(val: number): void {\n this._coordOffset = val;\n for (const cell of this.cells) {\n if (cell.value) {\n const cellView = this.getCellView(cell);\n if (this._maxLength <= 0) {\n // this hasnt been evaluated yet so do it!\n this.evalMaxLength();\n }\n cellView.setBounds(null, val, null, this.maxLength, true);\n }\n }\n }\n\n /**\n * Evaluates the maximum height required for this row.\n * @param changedCells Cells that have changed and need re-evaluation\n * @returns The maximum height\n */\n evalMaxLength(changedCells: GridCell[] = []): number {\n this._maxLength = 0;\n for (const cell of this.cells) {\n if (cell.value) {\n const cellView = this.getCellView(cell);\n this._maxLength = Math.max(cellView.minSize.height, this._maxLength);\n }\n }\n return this._maxLength;\n }\n\n /**\n * Called before adding a cell to perform validation or preparation.\n * @param cell The cell to be added\n * @returns Whether the cell should be added\n */\n protected beforeAddingCell(cell: GridCell): boolean {\n if (cell.rowAlign && cell.rowAlign != this) {\n cell.rowAlign.removeCell(cell);\n }\n return cell.rowAlign != this;\n }\n\n /**\n * Called before removing a cell to perform validation.\n * @param cell The cell to be removed\n * @returns Whether the cell should be removed\n */\n beforeRemovingCell(cell: GridCell): boolean {\n return cell.rowAlign == this;\n }\n}\n\n/**\n * The layout manager for a collection of GridViews bound by common alignment objects.\n * Manages the layout of multiple grid models, ensuring proper alignment between them.\n */\nexport class GridLayoutGroup {\n // rowAligns = new Map<number, RowAlign>();\n // colAligns = new Map<number, ColAlign>();\n /** The grid models managed by this layout group */\n gridModels = [] as GridModel[];\n\n /** Subscribers to layout change events */\n private layoutChangeSubscribers = new Set<LayoutChangeCallback>();\n\n /** Previous column widths by ColAlign uuid - for detecting actual changes */\n private previousColumnWidths = new Map<number, number>();\n\n /** Previous row heights by RowAlign uuid - for detecting actual changes */\n private previousRowHeights = new Map<number, number>();\n\n /**\n * Subscribes to layout change events.\n * @param callback Function to call when layout changes\n * @returns Unsubscribe function\n */\n onLayoutChange(callback: LayoutChangeCallback): () => void {\n this.layoutChangeSubscribers.add(callback);\n return () => {\n this.layoutChangeSubscribers.delete(callback);\n };\n }\n\n /**\n * Notifies all subscribers of a layout change.\n * @param event The layout change event\n */\n protected notifyLayoutChange(event: LayoutChangeEvent): void {\n for (const callback of this.layoutChangeSubscribers) {\n try {\n callback(event);\n } catch (e) {\n console.error(\"Error in layout change callback:\", e);\n }\n }\n }\n\n /**\n * Gets the number of layout change subscribers.\n */\n get subscriberCount(): number {\n return this.layoutChangeSubscribers.size;\n }\n\n /**\n * Event handler for processing events from grid models.\n */\n private eventHandler = (event: TSU.Events.TEvent) => {\n this.applyModelEvents(event.payload);\n };\n\n /**\n * Adds a grid model to this layout group.\n * @param gridModel The grid model to add\n * @returns True if the model was added successfully\n */\n addGridModel(gridModel: GridModel): boolean {\n gridModel.eventHub?.on(TSU.Events.EventHub.BATCH_EVENTS, this.eventHandler);\n this.gridModels.push(gridModel);\n return true;\n }\n\n /**\n * Gets all row alignment objects that have no predecessors.\n * @returns An array of starting row alignments\n */\n startingRowAligns(): RowAlign[] {\n const out = [] as RowAlign[];\n const visited = {} as any;\n for (const gm of this.gridModels) {\n for (const cell of gm.cellsInRow(gm.firstRow)) {\n if (cell.rowAlign && !visited[cell.rowAlign.uuid]) {\n visited[cell.rowAlign.uuid] = true;\n out.push(cell.rowAlign);\n }\n }\n }\n return out;\n }\n\n /**\n * Gets all column alignment objects that have no predecessors.\n * @returns An array of starting column alignments\n */\n startingColAligns(): ColAlign[] {\n const out = [] as ColAlign[];\n const visited = {} as any;\n for (const gm of this.gridModels) {\n for (const cell of gm.cellsInCol(gm.firstCol)) {\n if (cell.colAlign && !visited[cell.colAlign.uuid]) {\n visited[cell.colAlign.uuid] = true;\n out.push(cell.colAlign);\n }\n }\n }\n return out;\n }\n\n /**\n * Removes a grid model from this layout group.\n * @param gridModel The grid model to remove\n */\n removeGridModel(gridModel: GridModel): void {\n gridModel.eventHub?.removeOn(TSU.Events.EventHub.BATCH_EVENTS, this.eventHandler);\n }\n\n /**\n * Function to get a view for a cell value.\n */\n getCellView: (cell: GridCell) => GridCellView;\n\n /**\n * Gets the starting row alignments.\n */\n get startingRows(): RowAlign[] {\n return this.startingRowAligns();\n }\n\n /**\n * Gets the starting column alignments.\n */\n get startingCols(): ColAlign[] {\n return this.startingColAligns();\n }\n\n /**\n * Forces a full refresh of the layout.\n * This recalculates all row and column sizes and positions.\n * @param notify Whether to notify subscribers of the change (default: true)\n */\n refreshLayout(notify = true): void {\n const changedRowAligns = {} as any;\n const changedColAligns = {} as any;\n\n for (const rowAlign of this.startingRowAligns()) {\n if (!(rowAlign.uuid in changedRowAligns)) {\n changedRowAligns[rowAlign.uuid] = {\n align: rowAlign,\n cells: [],\n };\n }\n }\n\n for (const colAlign of this.startingColAligns()) {\n if (!(colAlign.uuid in changedColAligns)) {\n changedColAligns[colAlign.uuid] = {\n align: colAlign,\n cells: [],\n };\n }\n }\n\n // Pass the previous dimension maps for O(1) inline change detection\n const rowHeightsChanged = this.doBfsLayout(this.startingRows, changedRowAligns, this.previousRowHeights);\n const columnWidthsChanged = this.doBfsLayout(this.startingCols, changedColAligns, this.previousColumnWidths);\n\n // Notify subscribers of full refresh\n if (notify && this.layoutChangeSubscribers.size > 0) {\n this.notifyLayoutChange({\n affectedRowRange: null, // null means all rows\n affectedColRange: null, // null means all columns\n columnWidthsChanged,\n rowHeightsChanged,\n affectedGridModels: this.gridModels,\n });\n }\n }\n\n /**\n * Applies model events to update the layout.\n * @param events The events to process\n */\n protected applyModelEvents(events: TSU.Events.TEvent[]): void {\n // As the grid model changes (cell content changed, cleared etc) we need\n // to refresh our layout based on this.\n // As a first step the new height and width of all changed cells is\n // evaluted to see which rows and/or columns are affected (and need to be\n // resized/repositioned).\n const [changedRowAligns, changedColAligns, affectedGridModels] = this.changesForEvents(events);\n const hadRowChanges = Object.keys(changedRowAligns).length > 0;\n const hadColChanges = Object.keys(changedColAligns).length > 0;\n\n // Pass the previous dimension maps for O(1) inline change detection\n const rowHeightsChanged = this.doBfsLayout(this.startingRows, changedRowAligns, this.previousRowHeights);\n const columnWidthsChanged = this.doBfsLayout(this.startingCols, changedColAligns, this.previousColumnWidths);\n\n // Notify subscribers of incremental changes\n if (this.layoutChangeSubscribers.size > 0 && (hadRowChanges || hadColChanges)) {\n // Calculate affected ranges from the changed alignments\n const affectedRowRange = this.calculateAffectedRowRange(changedRowAligns);\n const affectedColRange = this.calculateAffectedColRange(changedColAligns);\n\n this.notifyLayoutChange({\n affectedRowRange,\n affectedColRange,\n columnWidthsChanged,\n rowHeightsChanged,\n affectedGridModels: affectedGridModels,\n });\n }\n }\n\n /**\n * Calculates the range of affected rows from changed row alignments.\n * Returns null if no rows changed or range cannot be determined.\n */\n protected calculateAffectedRowRange(changedRowAligns: any): { start: number; end: number } | null {\n let minRow = Infinity;\n let maxRow = -Infinity;\n\n for (const alignId in changedRowAligns) {\n const { cells } = changedRowAligns[alignId];\n for (const cell of cells) {\n const rowIndex = cell.gridRow.rowIndex;\n minRow = Math.min(minRow, rowIndex);\n maxRow = Math.max(maxRow, rowIndex);\n }\n }\n\n if (minRow === Infinity) return null;\n return { start: minRow, end: maxRow };\n }\n\n /**\n * Calculates the range of affected columns from changed column alignments.\n * Returns null if no columns changed or range cannot be determined.\n */\n protected calculateAffectedColRange(changedColAligns: any): { start: number; end: number } | null {\n let minCol = Infinity;\n let maxCol = -Infinity;\n\n for (const alignId in changedColAligns) {\n const { cells } = changedColAligns[alignId];\n for (const cell of cells) {\n const colIndex = cell.colIndex;\n minCol = Math.min(minCol, colIndex);\n maxCol = Math.max(maxCol, colIndex);\n }\n }\n\n if (minCol === Infinity) return null;\n return { start: minCol, end: maxCol };\n }\n\n /**\n * Checks if an alignment's maxLength changed from previous value.\n * Updates the stored previous value. O(1) cost.\n * @param align The alignment to check\n * @param previousMap Map storing previous lengths\n * @returns true if length changed (or is new)\n */\n private checkAndUpdateLength<T extends AlignedLine>(align: T, previousMap: Map<number, number>): boolean {\n const previous = previousMap.get(align.uuid);\n const current = align.maxLength;\n previousMap.set(align.uuid, current);\n return previous === undefined || previous !== current;\n }\n\n /**\n * Determines which rows and columns need to be updated based on events.\n * @param events The events to process\n * @returns A tuple containing the changed row alignments, column alignments, and affected grid models\n */\n protected changesForEvents(events: TSU.Events.TEvent[]): [any, any, GridModel[]] {\n // Step 1 - topologically sort RowAligns of changed cells\n // Step 2 - topologically sort ColAligns of changed cells\n // Step 3 -\n const cellVisited = {} as any;\n const changedRowAligns = {} as any;\n const changedColAligns = {} as any;\n const affectedGridModelsSet = new Set<GridModel>();\n // Going in reverse means we only get the latest event affecting a cell\n // instead of going through every change.\n // Later on we can revisit this if the events are edge triggered instead\n // of level triggered\n for (let i = events.length - 1; i >= 0; i--) {\n const event = events[i];\n const loc = event.payload.loc;\n if (cellVisited[loc]) continue;\n cellVisited[loc] = true;\n const [row, col] = loc.split(\":\").map((x: string) => parseInt(x));\n const gridModel = event.source as GridModel;\n affectedGridModelsSet.add(gridModel);\n const cell = gridModel.getRow(row).cellAt(col);\n if (cell) {\n // TODO - For now we are marking both row and col as having\n // changed for a cell. We can optimize this to only row or\n // col based on whether height or width has changed.\n if (!(cell.rowAlign.uuid in changedRowAligns)) {\n changedRowAligns[cell.rowAlign.uuid] = {\n align: cell.rowAlign,\n cells: [],\n };\n }\n changedRowAligns[cell.rowAlign.uuid][\"cells\"].push(cell);\n\n if (!(cell.colAlign.uuid in changedColAligns)) {\n changedColAligns[cell.colAlign.uuid] = {\n align: cell.colAlign,\n cells: [],\n };\n }\n changedColAligns[cell.colAlign.uuid][\"cells\"].push(cell);\n }\n }\n return [changedRowAligns, changedColAligns, Array.from(affectedGridModelsSet)];\n }\n\n /**\n * Ensures that a cell view getter function is available for an alignment.\n * @param align The alignment to check\n * @returns The cell view getter function\n */\n protected ensureGetCellView(align: AlignedLine) {\n if (!align.getCellView) {\n if (!this.getCellView) {\n return null;\n }\n align.getCellView = this.getCellView;\n }\n return align.getCellView;\n }\n\n /**\n * Performs a breadth-first layout of aligned lines.\n * @param startingLines The lines to start from\n * @param changedAligns Map of alignment IDs to changed alignments\n * @param previousLengths Map to track previous lengths for change detection\n * @returns true if any dimension (width/height) actually changed\n */\n protected doBfsLayout<T extends AlignedLine>(\n startingLines: T[],\n changedAligns: any,\n previousLengths?: Map<number, number>,\n ): boolean {\n // 1. start from the starting lines and do a BF traversal\n // 2. If a line not visited (ie laid out):\n // if it is in the changedAlign list then reval its length (w/h)\n // set its offset and length if either width or offset has changed\n // offset can be thought of changed if the preceding line's offset has changed\n // first do above for rows\n if (!this.getCellView) return false;\n let anyDimensionChanged = false;\n\n for (const alignId in changedAligns) {\n const val = changedAligns[alignId];\n this.ensureGetCellView(val.align);\n val.align.evalMaxLength(val.cells);\n\n // Check if this alignment's length actually changed (O(1))\n if (previousLengths && this.checkAndUpdateLength(val.align, previousLengths)) {\n anyDimensionChanged = true;\n }\n }\n\n let lineQueue = [] as [null | T, T][];\n const visitedLines = {} as any;\n for (const line of startingLines) lineQueue.push([null, line]);\n const lineOffsetChanged = {} as any;\n while (lineQueue.length > 0) {\n const nextQueue = [] as [null | T, T][];\n for (let i = 0; i < lineQueue.length; i++) {\n const [prevLineAlign, lineAlign] = lineQueue[i];\n visitedLines[lineAlign.uuid] = true;\n let newOffset = lineAlign.coordOffset;\n let lineChanged = lineAlign.uuid in changedAligns;\n if (prevLineAlign) {\n if (lineOffsetChanged[prevLineAlign.uuid]) {\n newOffset = prevLineAlign.coordOffset + prevLineAlign.maxLength;\n lineChanged = true;\n }\n }\n if (lineChanged) {\n this.ensureGetCellView(lineAlign);\n lineAlign.setOffset(newOffset);\n lineOffsetChanged[lineAlign.uuid] = true;\n }\n\n // Add next neighbors now\n for (const next of lineAlign.nextLines) {\n if (!visitedLines[next.uuid]) {\n nextQueue.push([lineAlign, next]);\n }\n }\n }\n lineQueue = nextQueue;\n }\n\n return anyDimensionChanged;\n }\n}\n","import * as TSU from \"@panyam/tsutils\";\nimport { AtomType, Marker, Group, Line, Atom, Space, Role } from \"./\";\nimport { CycleIterator, CyclePosition } from \"./cycle\";\nimport { WindowIterator } from \"./iterators\";\nimport { LayoutParams } from \"./layouts\";\nimport { GridModel, GridRow, GridCell, ColAlign, GridLayoutGroup } from \"./grids\";\nimport { Block, BlockItem, isLine, isBlock } from \"./notation\";\n\ntype Fraction = TSU.Num.Fraction;\nconst ZERO = TSU.Num.Fraction.ZERO;\nconst ONE = TSU.Num.Fraction.ONE;\n\n/**\n * Represents a single beat in the notation.\n * A beat contains one or more atoms and has a specific position in a bar.\n */\nexport class Beat {\n private static idCounter = 0;\n readonly uuid = Beat.idCounter++;\n // Should this be as flat Atoms or should we keep it as atoms and breakdown later?\n\n /** The atom contained in this beat */\n atom: Atom;\n protected atomIsPlaceholder = false;\n\n /**\n * Creates a new Beat.\n * @param index The index of this beat in the sequence\n * @param role The role this beat belongs to\n * @param offset The time offset of this beat from the start\n * @param duration The duration of this beat\n * @param barIndex The index of the bar containing this beat\n * @param beatIndex The index of this beat within its bar\n * @param instance The instance number of this beat\n * @param prevBeat The previous beat in the sequence, if any\n * @param nextBeat The next beat in the sequence, if any\n */\n constructor(\n public readonly index: number,\n public readonly role: Role,\n public readonly offset: Fraction,\n public readonly duration: Fraction,\n public readonly barIndex: number,\n public readonly beatIndex: number,\n public readonly instance: number,\n public readonly prevBeat: null | Beat,\n public nextBeat: null | Beat,\n ) {}\n\n /**\n * Returns a debug-friendly representation of this Beat.\n * @returns An object containing debug information\n */\n debugValue(): any {\n return {\n index: this.index,\n role: this.role.name,\n offset: this.offset.toString(),\n duration: this.duration.toString(),\n barIndex: this.barIndex,\n beatIndex: this.beatIndex,\n instance: this.instance,\n atom: this.atom.debugValue(),\n };\n }\n\n /**\n * Gets the end offset of this beat (offset + duration).\n */\n get endOffset(): Fraction {\n return this.offset.plus(this.duration);\n }\n\n /**\n * Checks if this beat is filled completely (no remaining space).\n */\n get filled(): boolean {\n return this.remaining.isZero;\n }\n\n /**\n * Gets the remaining duration available in this beat.\n */\n get remaining(): Fraction {\n return this.atom ? this.duration.minus(this.atom.duration, true) : this.duration;\n }\n\n /**\n * Adds an atom to this beat.\n * @param atom The atom to add\n * @returns True if the atom was added successfully, false if there's not enough space\n */\n add(atom: Atom): boolean {\n if (this.remaining.cmp(atom.duration) < 0) {\n return false;\n }\n if (!this.atom) {\n this.atom = atom;\n } else {\n if (!this.atomIsPlaceholder) {\n this.atomIsPlaceholder = true;\n this.atom = new Group(this.atom).setDuration(ONE, true);\n }\n (this.atom as Group).addAtoms(true, atom);\n }\n return true;\n }\n\n /**\n * Gets all markers that should be displayed before this beat.\n * @returns An array of Marker objects\n */\n get preMarkers(): Marker[] {\n const out = [] as Marker[];\n let curr: Atom | null = this.atom;\n while (curr != null) {\n for (const marker of curr.markersBefore || []) {\n out.push(marker);\n }\n if (curr.TYPE == AtomType.GROUP) {\n curr = (curr as Group).atoms.first;\n } else {\n curr = null;\n }\n }\n return out;\n }\n\n /**\n * Gets all markers that should be displayed after this beat.\n * @returns An array of Marker objects\n */\n get postMarkers(): Marker[] {\n const out = [] as Marker[];\n let curr: Atom | null = this.atom;\n while (curr != null) {\n out.splice(0, 0, ...(curr.markersAfter || []));\n if (curr.TYPE == AtomType.GROUP) {\n curr = (curr as Group).atoms.last;\n } else {\n curr = null;\n }\n }\n return out;\n }\n}\n\n/**\n * Builds a sequence of beats from atoms according to layout parameters.\n * Used to convert a flat sequence of atoms into structured beats for display.\n */\nexport class BeatsBuilder {\n /** All atoms divided into beats */\n readonly beats: Beat[] = [];\n readonly startIndex: number;\n readonly beatOffset: Fraction;\n cycleIter: CycleIterator;\n windowIter: WindowIterator;\n\n /** Callback for when an atom is added to this role */\n onAtomAdded: (atom: Atom, beat: Beat) => void;\n\n /** Callback for when a new beat is added */\n onBeatAdded: (beat: Beat) => void;\n\n /** Callback for when a beat has been filled */\n onBeatFilled: (beat: Beat) => void;\n\n /**\n * Creates a new BeatsBuilder.\n * @param role The role containing the atoms\n * @param layoutParams Layout parameters for structuring beats\n * @param startOffset The starting offset for the first beat, defaults to ZERO\n * @param atoms Initial atoms to add to the beats\n */\n constructor(\n public readonly role: Role,\n public readonly layoutParams: LayoutParams,\n public readonly startOffset: Fraction = ZERO,\n ...atoms: Atom[]\n ) {\n const [, [bar, beat, instance], beatOffset, index] = layoutParams.cycle.getPosition(startOffset);\n this.cycleIter = layoutParams.cycle.iterateBeats(bar, beat, instance);\n this.windowIter = new WindowIterator();\n this.beatOffset = beatOffset;\n\n // evaluate the start beatindex - typically it would be 0 if things start\n // at beginning of a cycle. But if the start offset is < 0 then the\n // startIndex should also shift accordingly\n this.startIndex = index;\n this.addAtoms(...atoms);\n }\n\n /**\n * Adds atoms to be processed into beats.\n * @param atoms The atoms to add\n */\n addAtoms(...atoms: Atom[]): void {\n // First add all atoms to the atom Iterator so we can\n // fetch them as FlatAtoms. This is needed because atoms\n // passed here could be unflatted (via groups) or much larger\n // than what can fit in the given role/bar etc. So this\n // flattening and windowing is needed before we add them\n // to the views - and this is done by the durationIterators.\n this.windowIter.push(...atoms);\n while (this.windowIter.hasMore) {\n // get the last/current row and add a new one if it is full\n let currBeat = this.beats[this.beats.length - 1];\n\n // First add a row if last row is filled\n if (this.beats.length == 0 || currBeat.filled) {\n // what should be the beatlengths be here?\n currBeat = this.addBeat();\n }\n\n // For this beat get symbols in all roles\n const [remAtoms, filled] = this.windowIter.get(currBeat.remaining);\n TSU.assert(remAtoms.length > 0, \"Atleast one element should have been available here\");\n // render the atoms now\n for (const atom of remAtoms) {\n // console.log(\"Adding FA: \", flatAtom.debugValue(), flatAtom.atom);\n TSU.assert(currBeat.add(atom), \"Should return true as we are already using a duration iterator here\");\n if (this.onAtomAdded) this.onAtomAdded(atom, currBeat);\n }\n if (currBeat.filled) {\n if (this.onBeatFilled) this.onBeatFilled(currBeat);\n }\n }\n }\n\n /**\n * Adds a new beat to the sequence.\n * @returns The newly created beat\n */\n protected addBeat(): Beat {\n const numBeats = this.beats.length;\n const lastBeat = numBeats == 0 ? null : this.beats[numBeats - 1];\n const nextCP: [CyclePosition, Fraction] = this.cycleIter.next().value;\n const apb = this.layoutParams.beatDuration;\n const newBeat = new Beat(\n lastBeat == null ? this.startIndex : lastBeat.index + 1,\n this.role,\n lastBeat == null ? this.startOffset.minus(this.beatOffset).timesNum(apb, true) : lastBeat.endOffset,\n nextCP[1].timesNum(apb),\n nextCP[0][0],\n nextCP[0][1],\n nextCP[0][2],\n lastBeat,\n null,\n );\n if (lastBeat == null && this.beatOffset.isGT(ZERO)) {\n // Add spaces to fill up empty beats\n newBeat.add(new Space(this.beatOffset.timesNum(apb)));\n }\n if (lastBeat) lastBeat.nextBeat = newBeat;\n this.beats.push(newBeat);\n if (this.onBeatAdded) this.onBeatAdded(newBeat);\n return newBeat;\n }\n}\n\n/**\n * Represents a column of beats in a layout grid.\n * Used for aligning beats vertically in the notation.\n */\nexport class BeatColumn extends ColAlign {\n /** Spacing between atoms in this column */\n atomSpacing = 2;\n /** Unique key for this column */\n readonly key: string;\n\n /**\n * Creates a new BeatColumn.\n * @param offset The starting offset of this column\n * @param endOffset The ending offset of this column\n * @param markerType The type of marker for this column (negative: before, positive: after, zero: normal)\n */\n constructor(\n public readonly offset: Fraction,\n public readonly endOffset: Fraction,\n public readonly markerType: number,\n ) {\n super();\n offset = offset.factorized;\n endOffset = endOffset.factorized;\n this.key = BeatColumn.keyFor(offset, endOffset, markerType);\n }\n\n /**\n * Generates a key for identifying columns with the same offsets and marker type.\n * @param offset The starting offset\n * @param endOffset The ending offset\n * @param markerType The type of marker (negative: before, positive: after, zero: normal)\n * @returns A string key\n */\n static keyFor(offset: Fraction, endOffset: Fraction, markerType = 0): string {\n offset = offset.factorized;\n endOffset = endOffset.factorized;\n if (markerType < 0) {\n // return the column for the marker \"before\" this col\n // int his case only the \"start offset\" is needed and length doesnt matter\n return \":\" + offset.toString();\n } else if (markerType > 0) {\n // return the column for the marker \"after\" this col\n // in this case only thd end offset matters\n return endOffset.toString() + \":\";\n } else {\n return offset.toString() + \":\" + endOffset.toString();\n }\n }\n}\n\n/**\n * Manages the organization of beats into columns based on their offsets.\n * Used to create a directed acyclic graph (DAG) of beat columns for layout purposes.\n *\n * Grouping of beats by their column based on the layout params.\n * The confusion is we have beats broken up and saved in columns\n * but we are loosing how a line is supposed to access it in its own way\n * we have beatsByRole for getting all beats for a role (in a line)\n * sequentially we have beatColumns for getting all beats in a particular\n * column across all lines and roles globally.\n *\n * What we want here is for a given line get all roles, their beats\n * in zipped way. eg for a Line with 3 roles and say 10 beats each\n * (with the breaks of 4, 1) we need:\n *\n * R1 B1 R1 B2 R1 B3 R1 B4\n * R2 B1 R2 B2 R2 B3 R2 B4\n * R3 B1 R3 B2 R3 B3 R3 B4\n *\n * R1 B5\n * R2 B5\n * R3 B5\n *\n * R1 B6 R1 B7 R1 B8 R1 B9\n * R2 B6 R2 B7 R2 B8 R2 B9\n * R3 B6 R3 B7 R3 B8 R3 B9\n *\n * R1 B10\n * R2 B10\n * R3 B10\n *\n *\n * Here we have 5 distinct beat columns:\n *\n * 1: R1B1, R2B1, R3B1, R1B6, R2B6, R3B6,\n * 2: R1B2, R2B2, R3B2, R1B7, R2B7, R3B7,\n * 3: R1B3, R2B3, R3B3, R1B8, R2B8, R3B8,\n * 4: R1B4, R2B4, R3B4, R1B9, R2B9, R3B9,\n * 5: R1B5, R2B5, R3B5, R1B10, R2B10, R3B10,\n *\n */\nexport class BeatColDAG {\n /** Map of column keys to BeatColumn objects */\n beatColumns = new Map<string, BeatColumn>();\n\n /**\n * Creates a new BeatColDAG.\n * @param layoutGroup The layout group to associate with this DAG\n */\n constructor(public readonly layoutGroup: GridLayoutGroup) {\n //\n }\n\n /**\n * Gets the beat column for a given duration at the specified offset.\n * Creates a new column if none exists.\n * @param offset The starting offset\n * @param endOffset The ending offset\n * @param markerType The type of marker\n * @returns The BeatColumn for the specified parameters\n */\n getBeatColumn(offset: Fraction, endOffset: Fraction, markerType = 0): BeatColumn {\n const [bcol, newcreated] = this.ensureBeatColumn(offset, endOffset, markerType);\n if (newcreated) {\n if (markerType == 0) {\n const [prevcol] = this.ensureBeatColumn(offset, endOffset, -1);\n const [nextcol] = this.ensureBeatColumn(offset, endOffset, 1);\n prevcol.addSuccessor(bcol);\n bcol.addSuccessor(nextcol);\n for (const other of this.beatColumns.values()) {\n // only join the \"marker\" columns\n if (other.markerType == -1 && endOffset.equals(other.offset)) {\n // our next col is a preecessor of other\n nextcol.addSuccessor(other);\n } else if (other.markerType == 1 && other.endOffset.equals(offset)) {\n // our prev col is a predecessor of other\n other.addSuccessor(prevcol);\n }\n }\n }\n }\n return bcol;\n }\n\n /**\n * Ensures a beat column exists for the given parameters.\n * @param offset The starting offset\n * @param endOffset The ending offset\n * @param markerType The type of marker\n * @returns A tuple containing the column and whether it was newly created\n */\n protected ensureBeatColumn(offset: Fraction, endOffset: Fraction, markerType = 0): [BeatColumn, boolean] {\n const key = BeatColumn.keyFor(offset, endOffset, markerType);\n let bcol = this.beatColumns.get(key) || null;\n const newcreated = bcol == null;\n if (!bcol) {\n bcol = new BeatColumn(offset, endOffset, markerType);\n this.beatColumns.set(key, bcol);\n }\n return [bcol, newcreated];\n }\n}\n\n/** Type alias for line IDs */\ntype LineId = number;\n/** Type alias for layout parameter IDs */\ntype LPID = number;\n\n/**\n * Manages the beat layouts for all lines in a notation.\n * Handles the creation of grid models, positioning of beats, and alignment of beats across lines.\n */\nexport class GlobalBeatLayout {\n /** Map of line IDs to grid models */\n gridModelsForLine = new Map<LineId, GridModel>();\n /** Map of line IDs to arrays of beats for each role */\n roleBeatsForLine = new Map<LineId, Beat[][]>();\n /** Map of layout parameter IDs to beat column DAGs */\n beatColDAGsByLP = new Map<LPID, BeatColDAG>();\n /** The global layout group for all grid models */\n readonly gridLayoutGroup: GridLayoutGroup;\n\n /**\n * Creates a new GlobalBeatLayout.\n * @param sharedGridLayoutGroup Optional shared GridLayoutGroup for column alignment across multiple views.\n * If not provided, a new GridLayoutGroup is created internally.\n */\n constructor(sharedGridLayoutGroup?: GridLayoutGroup) {\n this.gridLayoutGroup = sharedGridLayoutGroup ?? new GridLayoutGroup();\n }\n\n /**\n * Gets the GridModel associated with a particular line, creating one if it doesn't exist.\n * @param lineid The ID of the line\n * @returns The GridModel for the line\n */\n getGridModelForLine(lineid: LineId): GridModel {\n let out = this.gridModelsForLine.get(lineid) || null;\n if (!out) {\n out = new GridModel();\n this.gridLayoutGroup.addGridModel(out);\n this.gridModelsForLine.set(lineid, out);\n }\n return out;\n }\n\n /**\n * Gets the BeatColDAG for a specific layout parameter ID, creating one if it doesn't exist.\n * @param lpid The layout parameter ID\n * @returns The BeatColDAG for the layout parameters\n */\n protected beatColDAGForLP(lpid: LPID): BeatColDAG {\n let out = this.beatColDAGsByLP.get(lpid) || null;\n if (!out) {\n out = new BeatColDAG(this.gridLayoutGroup);\n this.beatColDAGsByLP.set(lpid, out);\n }\n return out;\n }\n\n /**\n * Adds a line to the beat layout.\n * This ensures that a line is broken down into beats and added into a dedicated GridModel.\n *\n * A line must also be given the layout params by which the beat breakdown will happen.\n * This LayoutParams object does not have to be unique per line (this non-constraint allows\n * beats to be aligned across lines).\n *\n * @param line The line to add\n */\n addLine(line: Line): void {\n const gridModel = this.getGridModelForLine(line.uuid) as GridModel;\n gridModel.eventHub?.startBatchMode();\n this.lineToRoleBeats(line, gridModel);\n gridModel.eventHub?.commitBatch();\n }\n\n /**\n * Recursively processes a block and its children to build beat layouts.\n * Uses block.children() to get expanded children (e.g., RepeatBlock expands to N copies).\n *\n * @param block The block to process\n */\n processBlock(block: Block): void {\n for (const child of block.children()) {\n this.processBlockItem(child);\n }\n }\n\n /**\n * Processes a single block item (Block, Line, or RawBlock).\n *\n * @param item The item to process\n */\n protected processBlockItem(item: BlockItem): void {\n if (isLine(item)) {\n const line = item as Line;\n if (!line.isEmpty && line.layoutParams != null) {\n this.addLine(line);\n }\n } else if (isBlock(item)) {\n this.processBlock(item as Block);\n }\n // RawBlocks are ignored (no beat layout for raw content)\n }\n\n /**\n * Converts a line into a series of beats for each role.\n * @param line The line to convert\n * @param gridModel The grid model to use\n * @returns Arrays of beats for each role\n */\n protected lineToRoleBeats(line: Line, gridModel: GridModel): Beat[][] {\n const lp = line.layoutParams;\n const roleBeats = [] as Beat[][];\n this.roleBeatsForLine.set(line.uuid, roleBeats);\n const lineOffset = line.offset.divbyNum(lp.beatDuration);\n for (const role of line.roles) {\n const bb = new BeatsBuilder(role, lp, lineOffset, ...role.atoms);\n roleBeats.push(bb.beats);\n\n // Add these to the beat layout too\n for (const beat of bb.beats) {\n // beat.ensureUniformSpaces(layoutParams.beatDuration);\n this.addBeat(beat, gridModel);\n }\n }\n return roleBeats;\n }\n\n /**\n * Adds a beat to the layout.\n * @param beat The beat to add\n * @param gridModel The grid model to add the beat to\n * @returns The grid cell containing the beat\n */\n protected addBeat(beat: Beat, gridModel: GridModel): GridCell {\n // Get the beat column at this index (and line) and add to it.\n const line = beat.role.line;\n const lp = line.layoutParams;\n const beatColDAG = this.beatColDAGForLP(lp.uuid);\n const [layoutLine, layoutColumn, rowOffset] = lp.getBeatLocation(beat);\n const colEnd = rowOffset.plus(beat.duration, true);\n const bcol = beatColDAG.getBeatColumn(rowOffset, colEnd, 0);\n\n // Since a beat's column has a \"pre\" and \"post\" col to, each\n // beat has 3 columns for it\n const roleIndex = beat.role.line.indexOfRole(beat.role.name);\n const nthLine = Math.floor(beat.index / lp.totalBeats);\n const realLine = lp.lineBreaks.length * nthLine + layoutLine;\n const realRow = line.roles.length * realLine + roleIndex;\n // pre marker goes on realCol - 1, post marker goes on realCol + 1\n const realCol = 1 + layoutColumn * 3;\n const preMarkers = beat.preMarkers;\n if (preMarkers.length > 0) {\n const val = {\n beat: beat,\n markers: preMarkers,\n };\n const precol = beatColDAG.getBeatColumn(rowOffset, colEnd, -1);\n gridModel.setValue(realRow, realCol - 1, val, (gridRow: GridRow, col: number) => {\n const cell = new GridCell(gridRow, col);\n cell.colAlign = precol;\n return cell;\n });\n }\n const postMarkers = beat.postMarkers;\n if (postMarkers.length > 0) {\n const val = {\n beat: beat,\n markers: postMarkers,\n };\n const postcol = beatColDAG.getBeatColumn(rowOffset, colEnd, 1);\n gridModel.setValue(realRow, realCol + 1, val, (gridRow: GridRow, col: number) => {\n const cell = new GridCell(gridRow, col);\n cell.colAlign = postcol;\n return cell;\n });\n }\n return gridModel.setValue(realRow, realCol, beat, (gridRow: GridRow, col: number) => {\n const cell = new GridCell(gridRow, col);\n cell.colAlign = bcol;\n return cell;\n });\n }\n}\n","import * as TSU from \"@panyam/tsutils\";\n\ntype EdgeData = any;\ntype EdgeFunctor<T> = (node: T) => ReadonlyArray<[T, EdgeData]>;\ntype IDFunc<T> = (t: T) => number | string;\n\nexport function allMinimalCycles<T>(\n nodes: ReadonlyArray<T>,\n idFunc: IDFunc<T>,\n edges: EdgeFunctor<T>,\n): ReadonlyArray<[T, EdgeData]> {\n // Tells which cycle a node is assigned to if any\n const cycles: [T, EdgeData][] = [];\n const inACycle = {} as any;\n nodes.forEach((node) => {\n // start from node and do a BFS to see what cycle a node appears in\n if (!(idFunc(node) in inACycle)) {\n const startNode = node;\n const visited = {} as any;\n let queue: [T, [EdgeData, T][]][] = [[node, []]];\n while (queue.length > 0) {\n const newQueue: [T, [EdgeData, T][]][] = [];\n for (let i = 0; i < queue.length; i++) {\n const [node, c] = queue[i];\n TSU.assert(node != null);\n const e = edges(node);\n let cycle = [...c];\n for (const [nextNode, edgeData] of e) {\n if (nextNode == startNode) {\n // we have a cycle\n cycle.push([edgeData, nextNode]);\n cycle.forEach(([e, n], i) => (inACycle[n] = true));\n cycles.push([startNode, cycle]);\n cycle = cycle.slice(0, cycle.length - 1);\n } else if (!(idFunc(nextNode) in visited)) {\n visited[idFunc(nextNode)] = true;\n newQueue.push([nextNode, [...cycle, [edgeData, nextNode]]]);\n }\n }\n }\n queue = newQueue;\n }\n }\n });\n return cycles;\n}\n\nexport function digraph(): void {\n //\n}\n","import * as TSU from \"@panyam/tsutils\";\nimport { Grammar, Sym, Str, Rule } from \"./grammar\";\n\ntype NumMap<T> = TSU.NumMap<T>;\ntype StringMap<T> = TSU.StringMap<T>;\ntype Nullable<T> = TSU.Nullable<T>;\n\nconst defaultKeyFunc = (x: any) => x.key;\n\nexport class Trie<T> {\n protected keyFunc: (t: T) => string;\n readonly root: TrieNode<T> = new TrieNode();\n\n constructor(keyFunc: (t: T) => string) {\n this.keyFunc = keyFunc;\n }\n\n add(values: T[], fromIndex = 0): TrieNode<T> {\n // we are at the bottom\n let curr = this.root;\n for (let i = fromIndex; i < values.length; i++) {\n const key = this.keyFunc(values[i]);\n if (curr.children.has(key)) {\n curr = curr.children.get(key)!;\n } else {\n const newNode = new TrieNode<T>();\n newNode.value = values[i];\n newNode.parent = curr;\n curr.children.set(key, newNode);\n curr = newNode;\n }\n }\n curr.isLeaf = true;\n return curr;\n }\n\n get debugValue(): any {\n return this.root.debugValue;\n }\n}\n\nexport class TrieNode<T> {\n isLeaf = false;\n value: Nullable<T> = null;\n parent: Nullable<TrieNode<T>> = null;\n children = new Map<string, TrieNode<T>>();\n\n get debugValue(): any {\n const out = { value: this.value, children: {} as any } as any;\n if (this.isLeaf) out[\"isLeaf\"] = true;\n for (const [key, value] of this.children.entries()) {\n out.children[key] = value.debugValue;\n }\n return out;\n }\n}\n\nexport class IDSet<T extends { id: number }> {\n protected _entries: T[] = [];\n protected _entriesByKey: StringMap<T> = {};\n protected keyFunc: (t: T) => string;\n\n constructor(keyFunc: (t: T) => string = defaultKeyFunc) {\n this.keyFunc = keyFunc;\n }\n\n clear(): void {\n this._entries = [];\n this._entriesByKey = {};\n }\n\n /**\n * Removes all entries that match a predict.\n */\n remove(predicate: (t: T) => boolean): boolean {\n const e2: T[] = [];\n this._entriesByKey = {};\n let modified = false;\n for (let l = 0; l < this._entries.length; l++) {\n const e = this._entries[l];\n if (!predicate(e)) {\n // keep it if predicate failes\n e.id = e2.length;\n e2.push(e);\n this._entriesByKey[this.keyFunc(e)] = e;\n } else {\n modified = true;\n }\n }\n this._entries = e2;\n return modified;\n }\n\n get entries(): ReadonlyArray<T> {\n return this._entries;\n }\n\n get(id: number): T {\n TSU.assert(id >= 0 && id < this._entries.length);\n return this._entries[id];\n }\n\n getByKey(key: string): Nullable<T> {\n return this._entriesByKey[key] || null;\n }\n\n ensure(entry: T, throwIfExists = false): T {\n // see if this itemset exists\n if (this.has(entry)) {\n if (throwIfExists) throw new Error(`Entry ${this.keyFunc(entry)} already exists`);\n return this._entriesByKey[this.keyFunc(entry)];\n } else {\n this._entriesByKey[this.keyFunc(entry)] = entry;\n entry.id = this._entries.length;\n this._entries.push(entry);\n return entry;\n }\n }\n\n has(entry: T): boolean {\n return this.keyFunc(entry) in this._entriesByKey;\n }\n\n get size(): number {\n return this._entries.length;\n }\n}\n\nexport class SymbolSet {\n readonly grammar: Grammar;\n readonly enforceSymbolType: Nullable<boolean>;\n entries = new Set<number>();\n hasNull = false;\n\n constructor(grammar: Grammar, enforceSymbolType: Nullable<boolean> = true) {\n this.grammar = grammar;\n this.enforceSymbolType = enforceSymbolType;\n }\n\n get debugString(): string {\n return \"<\" + this.labels().sort().join(\", \") + \">\";\n }\n\n labels(skipAux = false): string[] {\n const out: string[] = [];\n for (const i of this.entries) {\n const exp = this.grammar.getSymById(i);\n TSU.assert(exp != null);\n if (!skipAux || !exp.isAuxiliary) out.push(exp.label);\n }\n if (this.hasNull) out.push(\"\");\n return out;\n }\n\n addFrom(another: SymbolSet, includeNull = true): number {\n return another.addTo(this, includeNull);\n }\n\n addTo(another: SymbolSet, includeNull = true): number {\n const before = another.entries.size;\n for (const termid of this.entries) {\n another.entries.add(termid);\n }\n if (includeNull) {\n another.hasNull = this.hasNull || another.hasNull;\n }\n return another.entries.size - before;\n }\n\n has(term: Sym): boolean {\n return this.entries.has(term.id);\n }\n\n add(term: Sym): this {\n TSU.assert(\n this.enforceSymbolType == null || this.enforceSymbolType == term.isTerminal,\n `Terminal types being enforced: ${this.enforceSymbolType}`,\n );\n this.entries.add(term.id);\n return this;\n }\n\n delete(term: Sym): boolean {\n return this.entries.delete(term.id);\n }\n\n get size(): number {\n return this.entries.size + (this.hasNull ? 1 : 0);\n }\n}\n\n/**\n * Tells which non terminals are nullables.\n */\nexport class NullableSet {\n readonly grammar: Grammar;\n entries: Set<number>;\n private visited: any;\n\n constructor(grammar: Grammar) {\n this.grammar = grammar;\n this.refresh();\n }\n\n get nonterms(): Sym[] {\n const out: Sym[] = [];\n this.entries.forEach((id) => {\n const e = this.grammar.getSymById(id);\n TSU.assert(e != null && !e.isTerminal);\n out.push(e);\n });\n return out;\n }\n\n refresh(): void {\n // Nuke entries cache. Will force isNullable to recompute.\n this.entries = new Set();\n this.visited = {};\n\n let beforeCount = 0;\n do {\n beforeCount = this.entries.size;\n this.grammar.allNonTerminals.forEach((nt) => this.visit(nt));\n } while (beforeCount != this.entries.size);\n }\n\n protected visit(nt: Sym): void {\n for (const rule of this.grammar.rulesForNT(nt)) {\n if (this.isStrNullable(rule.rhs)) {\n this.add(nt);\n break;\n }\n }\n }\n\n isNullable(nt: Sym): boolean {\n return !nt.isTerminal && this.entries.has(nt.id);\n }\n\n isStrNullable(str: Str, fromIndex = 0, toIndex: Nullable<number> = null): boolean {\n if (toIndex == null) {\n toIndex = str.length - 1;\n }\n for (let i = fromIndex; i <= toIndex; i++) {\n if (!this.isNullable(str.syms[i])) {\n return false;\n }\n }\n return true;\n }\n\n add(nt: Sym): void {\n TSU.assert(!nt.isTerminal);\n this.entries.add(nt.id);\n }\n}\n\nclass SymSymbolSets {\n readonly grammar: Grammar;\n entries: NumMap<SymbolSet> = {};\n private _count = 0;\n\n constructor(grammar: Grammar) {\n this.grammar = grammar;\n }\n\n refresh(): void {\n this.entries = {};\n this._count = 0;\n }\n\n forEachTerm(nt: Sym, visitor: (x: Nullable<Sym>) => boolean | void): void {\n const entries = this.entriesFor(nt);\n entries.entries.forEach((x) => {\n const term = this.grammar.getSymById(x);\n TSU.assert(term != null && term.isTerminal);\n visitor(term);\n });\n if (entries.hasNull) visitor(null);\n }\n\n get debugValue(): any {\n const out = {} as any;\n for (const x in this.entries) out[this.grammar.getSymById(x as any)!.label] = this.entries[x].debugString;\n return out;\n }\n\n get count(): number {\n let c = 0;\n for (const x in this.entries) c += this.entries[x].size;\n return c;\n // TSU.assert(c == this._count, \"Count mismatch\")\n // return this._count;\n }\n\n entriesFor(sym: Sym): SymbolSet {\n if (sym.id in this.entries) {\n return this.entries[sym.id];\n } else {\n const out = new SymbolSet(this.grammar);\n this.entries[sym.id] = out;\n return out;\n }\n }\n\n /**\n * Add the null symbol into this set of terminals for a given expression.\n */\n addNull(nt: Sym): boolean {\n const entries = this.entriesFor(nt);\n if (entries.hasNull) return false;\n entries.hasNull = true;\n return true;\n }\n\n /**\n * Add a Null, term or another expression to the set of terminals\n * for a given expression. If source is an expression then all\n * of the source expression's terminal symbosl are added to exp's\n * term set.\n */\n add(nt: Sym, source: Sym, includeNull = true): boolean {\n if (nt.isTerminal) {\n TSU.assert(false, \"Should not be here\");\n }\n const entries = this.entriesFor(nt);\n if (source.isTerminal) {\n if (entries.has(source)) return false;\n // console.log(`Adding Term(${term.label}) to Set of ${exp.id}`);\n entries.add(source);\n this._count++;\n } else {\n const srcEntries = this.entriesFor(source);\n const destEntries = this.entriesFor(nt);\n const count = srcEntries.addTo(destEntries, includeNull);\n this._count += count;\n }\n return true;\n }\n}\n\n/**\n * For each symbol maps its label to a list of terminals that\n * start that non terminal.\n */\nexport class FirstSets extends SymSymbolSets {\n readonly nullables: NullableSet;\n\n constructor(grammar: Grammar, nullables?: NullableSet) {\n super(grammar);\n if (!nullables) {\n nullables = new NullableSet(grammar);\n }\n this.nullables = nullables;\n this.refresh();\n }\n\n /**\n * For a given string return the first(str) starting at a given index.\n * Including eps if it exists.\n */\n forEachTermIn(str: Str, fromIndex = 0, visitor: (term: Nullable<Sym>) => void): void {\n // This needs to be memoized by exp.id + index\n const syms = str.syms;\n const visited = {} as any;\n let allNullable = true;\n for (let j = fromIndex; allNullable && j < syms.length; j++) {\n const symj = syms[j];\n if (symj.isTerminal) {\n visitor(symj);\n allNullable = false;\n } else {\n const nt = symj as Sym;\n this.forEachTerm(nt, (term) => {\n if (term != null && !(term.id in visited)) {\n visited[term.id] = true;\n visitor(term);\n }\n });\n if (!this.nullables.isNullable(symj as Sym)) {\n allNullable = false;\n }\n }\n }\n if (allNullable) visitor(null);\n }\n\n /**\n * Reevaluates the first sets of a grammar.\n * This method assumes that the grammar's nullables are fresh.\n */\n refresh(): void {\n super.refresh();\n // this.grammar.terminals.forEach((t) => this.add(t, t));\n\n let beforeCount = 0;\n do {\n beforeCount = this.count;\n this.grammar.forEachRule(null, (rule) => {\n this.processRule(rule);\n });\n } while (beforeCount != this.count);\n }\n\n processRule(rule: Rule): void {\n const nullables = this.nullables;\n let allNullable = true;\n for (const s of rule.rhs.syms) {\n // First(s) - null will be in First(nonterm)\n // Null will onlybe added if all symbols are nullable\n this.add(rule.nt, s, false);\n if (s.isTerminal || !nullables.isNullable(s as Sym)) {\n // since s is not nullable the next rule's first set\n // cannot affect nonterm's firs set\n allNullable = false;\n break;\n }\n }\n if (allNullable) this.addNull(rule.nt);\n }\n}\n\n/**\n * For each symbol maps its label to a list of terminals that\n * start that non terminal.\n */\nexport class FollowSets extends SymSymbolSets {\n readonly firstSets: FirstSets;\n\n constructor(grammar: Grammar, firstSets?: FirstSets) {\n super(grammar);\n this.firstSets = firstSets || new FirstSets(grammar);\n this.refresh();\n }\n\n get nullables(): NullableSet {\n return this.firstSets.nullables;\n }\n\n /**\n * Reevaluates the follow sets of each expression in our grammar.\n * This method assumes that the grammar's nullables and firstSets are\n * up-to-date.\n */\n refresh(): void {\n super.refresh();\n const g = this.grammar;\n TSU.assert(g.startSymbol != null, \"Select start symbol of the grammar\");\n this.add(g.startSymbol, g.Eof);\n\n let beforeCount = 0;\n do {\n beforeCount = this.count;\n this.grammar.forEachRule(null, (rule) => this.processRule(rule));\n } while (beforeCount != this.count);\n }\n\n /**\n * Add Follows[source] into Follows[dest] recursively.\n */\n processRule(rule: Rule): void {\n const syms = rule.rhs.syms;\n const firstSets = this.firstSets;\n const nullables = this.firstSets.nullables;\n\n // Rule 1:\n // If A -> aBb1b2b3..bn:\n // Follow(B) = Follow(B) U { First(b1b2b3...bn) - eps }\n for (let i = 0; i < syms.length; i++) {\n const sym = syms[i];\n if (sym.isTerminal) continue;\n firstSets.forEachTermIn(rule.rhs, i + 1, (term) => {\n if (term != null) this.add(sym, term);\n });\n }\n\n // Rule 2:\n // If A -> aBb1b2b3..bn:\n // if Nullable(b1b2b3...bn):\n // Follow(B) = Follow(B) U Follow(N)\n for (let i = syms.length - 1; i >= 0; i--) {\n if (syms[i].isTerminal) continue;\n\n // This needs to be memoized??\n let allNullable = true;\n for (let j = i + 1; j < syms.length; j++) {\n const symj = syms[j];\n if (symj.isTerminal || !nullables.isNullable(symj as Sym)) {\n allNullable = false;\n break;\n }\n }\n if (allNullable) {\n this.add(syms[i], rule.nt);\n }\n }\n }\n}\n","import * as TSU from \"@panyam/tsutils\";\nimport { allMinimalCycles } from \"./graph\";\nimport { IDSet, SymbolSet, FirstSets, FollowSets, NullableSet } from \"./sets\";\n\ntype StringMap<T> = TSU.StringMap<T>;\ntype Nullable<T> = TSU.Nullable<T>;\n\n/**\n * Symbols represent both terminals and non-terminals in our system.\n * Chosing a convention of using a single class to represent both instead\n * of a base class with Term and NonTerm children has the following effects:\n * 1. We can change the type of a literal when doing things like reading\n * a grammar DSL when we dont konw if a symbol is a term or non-term\n * until *all* the declarations have been read and parsed.\n * 2. The down side of this we would need more explicit isTerm checks\n * but we would have done that anyway by calling getTerm and getNT\n * verions of the getSym method.\n */\nexport class Sym {\n isAuxiliary = false;\n auxType: string | null = null;\n precedence = 1;\n assocLeft = true;\n\n private static idCounter = -1;\n\n /**\n * An ID assigned to indicate order of \"creation\" of this symbol in the grammar.\n */\n creationId = -1;\n\n /**\n * ID unique across all expression within the grammar.\n */\n id: number;\n\n /**\n * Creates a new symbol in the grammar.\n *\n * @param grammar Grammar this symbol belongs to.\n * @param label Label for the symbol.\n * @param isTerminal Whether the symbol is a terminal or not.\n * @param id ID unique across all expression within the\n * grammar.\n */\n constructor(\n public readonly grammar: Grammar,\n public readonly label: string,\n public isTerminal: boolean,\n id: Nullable<number> = null,\n ) {\n this.isTerminal = isTerminal;\n this.label = label;\n if (id == null) {\n this.id = Sym.idCounter--;\n } else {\n this.id = id;\n }\n }\n\n compareTo(another: this): number {\n return this.label.localeCompare(another.label);\n }\n\n equals(another: this): boolean {\n return this.label == another.label;\n }\n\n toString(): string {\n return this.label;\n }\n}\n\nexport class Str {\n syms: Sym[];\n\n constructor(...syms: Sym[]) {\n this.syms = syms || [];\n }\n\n append(...lits: Sym[]): this {\n for (const l of lits) this.syms.push(l);\n return this;\n }\n\n extend(...strs: Str[]): this {\n for (const s of strs) this.append(...s.syms);\n return this;\n }\n\n copy(): Str {\n return new Str(...this.syms);\n }\n\n add(lit: Sym): void {\n this.syms.push(lit);\n }\n\n isTerminal(index: number): boolean {\n return this.syms[index].isTerminal;\n }\n\n get length(): number {\n return this.syms.length;\n }\n\n toString(): string {\n return this.syms.map((s) => s.toString()).join(\" \");\n }\n\n slice(startIndex: number, endIndex: number): Str {\n return new Str(...this.syms.slice(startIndex, endIndex));\n }\n\n splice(index: number, numToDelete: number, ...itemsToAdd: Sym[]): Str {\n this.syms.splice(index, numToDelete, ...itemsToAdd);\n return this;\n }\n\n compareTo(another: this): number {\n for (let i = 0; i < this.syms.length && i < another.syms.length; i++) {\n const diff = this.syms[i].compareTo(another.syms[i]);\n if (diff != 0) return diff;\n }\n return this.syms.length - another.syms.length;\n }\n\n equals(another: this): boolean {\n return this.compareTo(another) == 0;\n }\n\n /**\n * Returns true if another string is a substring within\n * this string at the given offset.\n */\n containsAt(offset: number, another: Str): boolean {\n let i = 0;\n for (; i < another.length && offset + i < this.syms.length; i++) {\n if (!this.syms[offset + i].equals(another.syms[i])) return false;\n // if (this.cardinalities[i] != another.cardinalities[i]) return false;\n }\n return i == another.length;\n }\n\n get debugString(): string {\n return this.syms.map((lit) => lit.label).join(\" \");\n }\n}\n\nexport class RuleAction {\n constructor(public value: string | number) {}\n\n get isFunction(): boolean {\n return typeof this.value === \"string\";\n }\n\n get isChildPosition(): boolean {\n return typeof this.value === \"number\";\n }\n}\n\nexport class Rule {\n id: number;\n constructor(\n public nt: Sym,\n public rhs: Str,\n public action: RuleAction | null = null,\n ) {\n if (nt.isTerminal) {\n throw new Error(\"Cannot add rules to a terminal\");\n }\n }\n\n get debugString(): string {\n return `${this.nt.label} -> ${this.rhs.debugString}`;\n }\n\n equals(another: this): boolean {\n return this.compareTo(another) == 0;\n }\n\n compareTo(another: this): number {\n TSU.assert(!isNaN(this.id));\n const diff = this.nt.compareTo(another.nt);\n if (diff == 0) {\n this.rhs.compareTo(another.rhs);\n }\n return diff;\n }\n}\n\nexport class Grammar {\n public startSymbol: Nullable<Sym> = null;\n modified = true;\n protected symbolSet = new IDSet<Sym>((s) => s.label);\n protected allRules: Rule[] = [];\n protected _rulesForNT: Nullable<StringMap<Rule[]>> = null;\n protected _followSets: Nullable<FollowSets> = null;\n\n /**\n * Prefix used for auxiliary symbols.\n */\n auxNTPrefix: string;\n\n readonly Null: Sym;\n readonly Eof: Sym;\n private _AugStartRule: Rule;\n private _hasNull = false;\n\n /**\n * A way of creating Grammars with a \"single expresssion\".\n */\n static make(callback: (g: Grammar) => void): Grammar {\n const g = new Grammar();\n callback(g);\n return g;\n }\n\n constructor(config?: any) {\n config = config || {};\n this.auxNTPrefix = config.auxNTPrefix || \"$\";\n this.Null = this.newTerm(\"\");\n this.Eof = this.newTerm(\"$end\");\n }\n\n rulesForNT(nt: Sym): Rule[] {\n TSU.assert(!nt.isTerminal);\n if (this._rulesForNT == null) {\n this._rulesForNT = {};\n for (const rule of this.allRules) {\n if (!(rule.nt.label in this._rulesForNT)) {\n this._rulesForNT[rule.nt.label] = [];\n }\n this._rulesForNT[rule.nt.label].push(rule);\n }\n }\n if (!(nt.label in this._rulesForNT)) {\n this._rulesForNT[nt.label] = [];\n }\n return this._rulesForNT[nt.label];\n }\n\n get nullables(): NullableSet {\n return this.firstSets.nullables;\n }\n\n get firstSets(): FirstSets {\n return this.followSets.firstSets;\n }\n\n get followSets(): FollowSets {\n if (this.modified || this._followSets == null) {\n this.refresh();\n }\n TSU.assert(this._followSets != null);\n return this._followSets;\n }\n\n get augStartRule(): Rule {\n return this._AugStartRule;\n }\n\n augmentStartSymbol(label = \"$accept\"): this {\n TSU.assert(this._AugStartRule == null, \"Ensure this grammar has not yet been augmented.\");\n TSU.assert(this.startSymbol != null, \"Start symbol not yet set\");\n const augSym = this.newNT(label);\n this._AugStartRule = new Rule(augSym, new Str(this.startSymbol));\n this.addRule(this._AugStartRule, 0);\n return this;\n }\n\n refresh(): this {\n this.symbolSet.entries.forEach((s, i) => (s.id = i));\n this._rulesForNT = null;\n this.allRules.forEach((rule, i) => {\n rule.id = i;\n });\n this._followSets = new FollowSets(this);\n this.modified = false;\n return this;\n }\n\n addTerminals(...terminals: string[]): void {\n for (const t of terminals) {\n this.newTerm(t);\n }\n }\n\n get terminals(): ReadonlyArray<Sym> {\n return this.symbolSet.entries.filter((x) => x.isTerminal);\n }\n\n get allNonTerminals(): ReadonlyArray<Sym> {\n return this.symbolSet.entries.filter((x) => !x.isTerminal);\n }\n\n get nonTerminals(): ReadonlyArray<Sym> {\n return this.symbolSet.entries.filter((x) => !x.isTerminal && !x.isAuxiliary);\n }\n\n get auxNonTerminals(): ReadonlyArray<Sym> {\n return this.symbolSet.entries.filter((x) => x.isAuxiliary);\n }\n\n get allSymbols(): ReadonlyArray<Sym> {\n return this.symbolSet.entries;\n }\n\n /**\n * A way to quickly iterate through all non-terminals.\n */\n forEachNT(visitor: (nt: Sym) => void | boolean | undefined | null): void {\n for (const sym of this.symbolSet.entries) {\n if (sym.isTerminal) continue;\n if (visitor(sym) == false) return;\n }\n }\n\n /**\n * A iterator across all the rules for either all non terminals in this grammar\n * for a single non terminal (if the nt value is non null).\n *\n * @param visitor\n */\n forEachRule(nt: Nullable<Sym>, visitor: (rule: Rule, index: number) => void | boolean | undefined | null): boolean {\n const rules = nt == null ? this.allRules : this.rulesForNT(nt) || [];\n for (let i = 0; i < rules.length; i++) {\n if (visitor(rules[i], i) == false) return false;\n }\n return true;\n }\n\n getRule(nt: string | Sym, index: number): Rule {\n if (typeof nt === \"string\") nt = this.getSym(nt)!;\n TSU.assert(nt != null);\n return this.rulesForNT(nt)[index];\n }\n\n /**\n * Return the the index of a rule if it already exists to prevent duplicates.\n */\n findRule(nt: Sym, production: Str): number {\n return this.rulesForNT(nt).findIndex((r) => r.nt == nt && r.rhs.equals(production));\n }\n\n /**\n * Adds a new rule to a particular non terminal of the grammar\n * Each rule represents a production of the form:\n *\n * name -> A B C D;\n *\n * Null production can be represented with an empty exps list.\n */\n add(nt: string | Sym, production: Str, action: RuleAction | null = null): Rule {\n let nonterm: Nullable<Sym> = null;\n if (typeof nt === \"string\") {\n nonterm = this.getSym(nt);\n if (nonterm == null) {\n // create it\n nonterm = this.newNT(nt);\n }\n } else {\n nonterm = this.ensureSym(nt);\n }\n return this.addRule(new Rule(nonterm, production, action));\n }\n\n /**\n * Add a rule directly.\n */\n addRule(rule: Rule, index = -1): Rule {\n if (this.findRule(rule.nt, rule.rhs) >= 0) {\n throw new Error(\"Duplicate rule: \" + rule.debugString);\n }\n rule.id = this.allRules.length;\n if (rule.rhs.length == 0) this._hasNull = true;\n if (index < 0) {\n this.allRules.push(rule);\n } else {\n this.allRules.splice(index, 0, rule);\n }\n this._rulesForNT = null;\n // this.rulesForNT(rule.nt).push(rule);\n this.modified = true;\n return rule;\n }\n\n /**\n * Removes all rules from the grammar which match the given predicate.\n */\n removeRules(pred: (r: Rule) => boolean): boolean {\n this.allRules = this.allRules.filter((r) => !pred(r));\n this._rulesForNT = null;\n this.modified = true;\n return true;\n }\n\n /**\n * Removes all symbols from the grammar and all of its productions which match\n * a particular predicate.\n */\n removeSymbols(pred: (s: Sym) => boolean): boolean {\n let modified = false;\n const newRules: Rule[] = [];\n this.allRules.forEach((r) => {\n if (pred(r.nt)) return;\n // if it was already a null production then leave it\n if (r.rhs.length == 0) {\n newRules.push(r);\n } else {\n const newRhs = new Str(...r.rhs.syms.filter((s) => !pred(s)));\n modified = modified || r.rhs.length != newRhs.length;\n if (newRhs.length > 0) {\n newRules.push(new Rule(r.nt, newRhs));\n }\n }\n });\n this.allRules = newRules;\n modified = this.symbolSet.remove(pred) || modified;\n this.modified = this.modified || modified;\n return modified;\n }\n\n /**\n * Gets or creates a terminal with the given label.\n * The grammar acts as a factory for terminal symbols\n * so that we can reuse symbols instead of having\n * users create new symbols each time.\n *\n * This also ensures that users are not able mix terminal\n * and non terminal labels.\n */\n getSymById(id: number): Nullable<Sym> {\n // if (id == Grammar.AUG_SYM_ID) return this._AugStartRule?.nt || null;\n // else if (id == this.Eof.id) return this.Eof;\n // else if (id == this.Null.id) return this.Null;\n return this.symbolSet.get(id);\n }\n\n getSym(label: string): Nullable<Sym> {\n // if (this._AugStartRule && label == this._AugStartRule.nt.label) return this._AugStartRule.nt;\n return this.symbolSet.getByKey(label);\n }\n\n ensureSym(sym: Sym, throwIfExists = false): Sym {\n const sym2 = this.symbolSet.ensure(sym, throwIfExists);\n if (sym == sym2) {\n if (sym2.creationId < 0) {\n sym2.creationId = this.symbolSet.size;\n }\n } else {\n TSU.assert(!throwIfExists, \"Should have already thrown error\");\n }\n return sym2;\n }\n\n /**\n * Ensures that a terminal by a given name exists (creating if\n * necessary). If a terminal already exists by this label then\n * an error is thrown.\n *\n * The grammar acts as a factory for terminal and non terminal symbols\n * so that we can reuse symbols instead of having users create new\n * symbols each time. This also ensures that users are not able mix\n * terminal and non terminal labels.\n */\n T(label: string, throwIfExists = false): Sym {\n let t = this.getSym(label);\n if (t != null) {\n if (throwIfExists) throw new Error(`Terminal ${label} is already exists`);\n if (!t.isTerminal) throw new Error(`Symbol (${label}) already exists as a non-terminal`);\n } else {\n t = new Sym(this, label, true);\n t = this.ensureSym(t, true);\n }\n return t;\n }\n\n /**\n * Ensures that a non term by a given name exists (creating if\n * necessary). If a terminal already exists by this label then\n * an error is thrown.\n *\n * The grammar acts as a factory for terminal and non terminal symbols\n * so that we can reuse symbols instead of having users create new\n * symbols each time. This also ensures that users are not able mix\n * terminal and non terminal labels.\n */\n NT(label: string, isAuxiliary = false, throwIfExists = false): Sym {\n let nt = this.getSym(label);\n if (nt != null) {\n if (throwIfExists) throw new Error(`Non-terminal ${label} is already exists`);\n if (nt.isTerminal) throw new Error(`Symbol (${label}) already exists as a terminal`);\n } else {\n nt = new Sym(this, label, false);\n nt.isAuxiliary = isAuxiliary;\n nt = this.ensureSym(nt, true);\n if (!isAuxiliary && this.startSymbol == null) {\n this.startSymbol = nt;\n }\n }\n return nt;\n }\n\n /**\n * Creates a terminal with the given label if one does not\n * already exist.\n */\n newTerm(label: string): Sym {\n return this.T(label, true);\n }\n\n /**\n * Creates a non terminal with the given label if it does not\n * already exist.\n */\n newNT(label: string, isAuxiliary = false): Sym {\n return this.NT(label, isAuxiliary, true);\n }\n\n /**\n * Checks if a given label is a terminal.\n */\n isTerminal(label: string): boolean {\n const t = this.getSym(label);\n return t != null && t.isTerminal;\n }\n\n /**\n * Checks if a given label is a non-terminal.\n */\n isNT(label: string): boolean {\n const t = this.getSym(label);\n return t != null && !t.isTerminal && !t.isAuxiliary;\n }\n\n /**\n * Checks if a given label is an auxiliary non-terminal.\n */\n isAuxNT(label: string): boolean {\n const t = this.getSym(label);\n return t != null && !t.isTerminal && t.isAuxiliary;\n }\n\n seq(...exps: (Str | string)[]): Str {\n if (exps.length == 1) {\n return this.normalizeRule(exps[0]);\n } else {\n const out = new Str();\n for (const e of exps) {\n const s = this.normalizeRule(e);\n // insert string here inline\n // A ( B C D ) => A B C D\n for (let i = 0; i < s.length; i++) {\n // out.add(s.syms[i], s.cardinalities[i]);\n out.add(s.syms[i]);\n }\n }\n return out;\n }\n }\n\n /**\n * Provides a union rule:\n *\n * (A | B | C | D)\n *\n * Each of A, B, C or D themselves could be strings or literals.\n */\n anyof(...rules: (Str | string)[]): Str {\n if (rules.length == 1) {\n return this.normalizeRule(rules[0]);\n } else {\n // see if there is already NT with the exact set of rules\n // reuse if it exists. That would make this method\n // Idempotent (which it needs to be).\n return new Str(this.ensureAuxNT(...rules.map((r) => this.normalizeRule(r))));\n }\n }\n\n opt(exp: Str | string): Str {\n // convert to aux rule\n const out = this.anyof(exp, new Str());\n const nt = out.syms[0];\n TSU.assert(out.syms.length == 1 && nt.isAuxiliary, \"NT must be an auxiliary symbol\");\n nt.auxType = \"opt\";\n return out;\n }\n\n atleast0(exp: Str | string, leftRec = true): Str {\n const s = this.normalizeRule(exp);\n // We want to find another auxiliary NT that has the following rules:\n // X -> exp X | ; # if leftRec = true\n //\n // X -> X exp | ; # otherwise:\n let auxNT = this.findAuxNT((auxNT) => {\n const rules = this.rulesForNT(auxNT);\n if (rules.length != 2) return false;\n\n let which = 0;\n if (rules[0].rhs.length == 0) {\n which = 1;\n } else if (rules[1].rhs.length == 0) {\n which = 0;\n } else {\n return false;\n }\n\n const rule = rules[which].rhs;\n if (rule.length != 1 + exp.length) return false;\n if (rule.syms[0].equals(auxNT)) {\n return rule.containsAt(1, s);\n } else if (rule.syms[rule.length - 1].equals(auxNT)) {\n return rule.containsAt(0, s);\n }\n return false;\n });\n if (auxNT == null) {\n auxNT = this.newAuxNT();\n auxNT.auxType = leftRec ? \"atleast0:left\" : \"atleast0\";\n this.add(auxNT, new Str());\n if (leftRec) {\n this.add(auxNT, new Str(auxNT).extend(s));\n } else {\n this.add(auxNT, s.copy().append(auxNT));\n }\n }\n return new Str(auxNT);\n }\n\n atleast1(exp: Str | string, leftRec = true): Str {\n const s = this.normalizeRule(exp);\n // We want to find another auxiliary NT that has the following rules:\n // X -> exp X | exp ; # if leftRec = true\n //\n // X -> X exp | exp ; # otherwise:\n let auxNT = this.findAuxNT((auxNT) => {\n const rules = this.rulesForNT(auxNT);\n if (rules.length != 2) return false;\n\n let which = 0;\n if (rules[0].rhs.equals(s)) {\n which = 1;\n } else if (rules[1].rhs.equals(s)) {\n which = 0;\n } else {\n return false;\n }\n\n const rule = rules[which].rhs;\n if (rule.length != 1 + exp.length) return false;\n if (rule.syms[0].equals(auxNT)) {\n return rule.containsAt(1, s);\n } else if (rule.syms[rule.length - 1].equals(auxNT)) {\n return rule.containsAt(0, s);\n }\n return false;\n });\n if (auxNT == null) {\n auxNT = this.newAuxNT();\n auxNT.auxType = leftRec ? \"atleast1:left\" : \"atleast1\";\n this.add(auxNT, s);\n if (leftRec) {\n this.add(auxNT, new Str(auxNT).extend(s));\n } else {\n this.add(auxNT, s.copy().append(auxNT));\n }\n }\n return new Str(auxNT);\n }\n\n normalizeRule(exp: Str | string): Str {\n if (typeof exp === \"string\") {\n const lit = this.getSym(exp);\n if (lit == null) throw new Error(`Invalid symbol: '${exp}'`);\n return new Str(lit);\n } else {\n // We have an expression that needs to be fronted by an\n // auxiliarry non-terminal\n return exp;\n }\n }\n\n // Override this to have a different\n protected auxNTCount = 0;\n protected newAuxNTName(): string {\n return this.auxNTPrefix + this.auxNTCount++;\n }\n\n newAuxNT(name = \"\"): Sym {\n if (name == \"\") name = this.newAuxNTName();\n return this.newNT(name, true);\n }\n\n ensureAuxNT(...rules: Str[]): Sym {\n let nt = this.findAuxNTByRules(...rules);\n if (nt == null) {\n nt = this.newAuxNT();\n nt.auxType = \"anyof\";\n for (const rule of rules) this.add(nt, rule);\n }\n return nt;\n }\n\n /**\n * Find an auxiliary rule that has the same rules as the ones here.\n * This can be used to ensure duplicate rules are not created for\n * union expressions.\n */\n findAuxNT(filter: (nt: Sym) => boolean): Nullable<Sym> {\n for (const auxNT of this.symbolSet.entries) {\n if (!auxNT.isAuxiliary) continue;\n if (filter(auxNT)) return auxNT;\n }\n return null;\n }\n\n findAuxNTByRules(...rules: Str[]): Nullable<Sym> {\n return this.findAuxNT((auxNT) => {\n const ntRules = this.rulesForNT(auxNT);\n if (ntRules.length != rules.length) return false;\n for (let i = 0; i < ntRules.length; i++) {\n if (!ntRules[i].rhs.equals(rules[i])) return false;\n }\n return true;\n });\n }\n\n print(options: any = null): string[] {\n options = options || {};\n const ruleSep = options.ruleSep || \"->\";\n const includeSemiColon = options.includeSemiColon || false;\n const lambdaSymbol = options.lambdaSymbol || \"\";\n const out: string[] = [];\n this.forEachRule(null, (rule: Rule, index: number) => {\n let r = `${rule.nt.label} ${ruleSep} `;\n if (rule.rhs.length > 0) r += rule.rhs.debugString;\n else r += lambdaSymbol;\n if (includeSemiColon) r += \" ;\";\n out.push(r);\n });\n return out;\n }\n\n /**\n * Returns a flat list of all productions in a single list.\n */\n get debugValue(): string[] {\n const out: string[] = [];\n this.forEachRule(null, (rule: Rule, index: number) => {\n out.push(`${rule.nt.label} -> ${rule.rhs.debugString}`);\n });\n return out;\n }\n\n /**\n * Returns all non terminals that can derive terminals.\n */\n get terminalDerivingSymbols(): SymbolSet {\n const out = new SymbolSet(this, null);\n let nadded = -1;\n let allDerive = true;\n while (nadded != 0) {\n nadded = 0;\n for (const rule of this.allRules) {\n allDerive = true;\n for (const sym of rule.rhs.syms) {\n if (!out.has(sym)) {\n if (sym.isTerminal) {\n out.add(sym);\n nadded++;\n } else {\n allDerive = false;\n }\n }\n }\n if (allDerive && !out.has(rule.nt)) {\n out.add(rule.nt);\n nadded++;\n }\n }\n }\n return out;\n }\n\n /*\n * Returns all non terminal that are reachable from a given symbol.\n * If the FROM symbol is omitted then the start symbol is used.\n */\n reachableSymbols(fromSymbol: Nullable<Sym> = null): SymbolSet {\n if (fromSymbol == null) {\n fromSymbol = this._AugStartRule ? this._AugStartRule.nt : this.startSymbol;\n }\n TSU.assert(fromSymbol != null, \"Start symbol does not exist\");\n const reachable = new SymbolSet(this, false).add(fromSymbol);\n let queue: Sym[] = [fromSymbol];\n while (queue.length > 0) {\n const newQueue: Sym[] = [];\n for (const curr of queue) {\n for (const rule of this.rulesForNT(curr)) {\n for (const sym of rule.rhs.syms) {\n if (!sym.isTerminal && !reachable.has(sym)) {\n newQueue.push(sym);\n reachable.add(sym);\n }\n }\n }\n }\n queue = newQueue;\n }\n return reachable;\n }\n\n /**\n * Returns all cycles in this grammar.\n */\n get cycles(): ReadonlyArray<[Sym, any]> {\n /*\n * Returns the edge of the given nonterm\n * For a nt such that:\n * S -> alpha1 X1 beta1 |\n * alpha2 X2 beta2 |\n * ...\n * alphaN XN betaN |\n *\n * S's neighbouring nodes would be Xk if all of alphak is optional\n * AND all of betak is optional\n */\n const edgeFunctor = (node: Sym): [Sym, any][] => {\n const out: [Sym, any][] = [];\n this.forEachRule(node, (rule, ruleIndex) => {\n rule.rhs.syms.forEach((s, j) => {\n if (s.isTerminal) return;\n if (this.nullables.isStrNullable(rule.rhs, 0, j - 1) && this.nullables.isStrNullable(rule.rhs, j + 1)) {\n out.push([s, [node, ruleIndex]]);\n }\n });\n });\n return out;\n };\n return allMinimalCycles(this.allNonTerminals, (val: Sym) => val.label, edgeFunctor);\n }\n\n /**\n * Returns a set of \"Starting\" non terminals which have atleast\n * one production containing left recursion.\n */\n get leftRecursion(): any {\n const edgeFunctor = (node: Sym): [Sym, any][] => {\n const out: [Sym, any][] = [];\n this.forEachRule(node, (rule, ruleIndex) => {\n rule.rhs.syms.forEach((s, j) => {\n if (s.isTerminal) return;\n out.push([s, ruleIndex]);\n // If this is symbol is not nullable then we can stop here\n return this.nullables.isNullable(s);\n });\n });\n return out;\n };\n return allMinimalCycles(this.allNonTerminals, (val: Sym) => val.id, edgeFunctor);\n }\n}\n","export enum CharClassType {\n WORD_CHAR,\n DIGITS,\n SPACES,\n}\n\nconst ZERO = \"0\".charCodeAt(0);\nconst NINE = \"9\".charCodeAt(0);\nconst lA = \"a\".charCodeAt(0);\nconst lZ = \"z\".charCodeAt(0);\nconst uA = \"A\".charCodeAt(0);\nconst uZ = \"Z\".charCodeAt(0);\nconst USCORE = \"_\".charCodeAt(0);\n\n/**\n * An abstract class to be implemented for enabling different types of char classes.\n * Char classes are a form of \"short codes\" to identify characters. eg SPACES, DIGITS etc.\n * Char classes are only shortcuts. One can get away without using them and instead explicitly\n * construct the underlying state machine or regex (eg DIGIT could be replaced with [0-9]).\n */\nexport abstract class CharClassHelper {\n matches(charCode: number, neg: boolean): boolean {\n const res = this.match(charCode);\n return neg ? !res : res;\n }\n protected abstract match(charCode: number): boolean;\n abstract reString(neg: boolean): string;\n}\n\nconst spaceChars = \" \\f\\n\\r\\t\\v\\u00a0\\u1680\\u2028\\u2029\\u202f\\u205f\\u3000\\ufeff\";\n\n/**\n * Spaces - \\s => [ \\b\\c\\u00a0\\t\\r\\n\\u2028\\u2029<BOM><USP>]\n * BOM = \\uFEFF\n * USP = Other unicode space separator\n */\nexport class Spaces extends CharClassHelper {\n match(charCode: number): boolean {\n // if (charCode == 0x180e) return true;\n if (charCode >= 0x2000 && charCode <= 0x200a) return true;\n for (let i = 0; i < spaceChars.length; i++) {\n if (spaceChars.charCodeAt(i) == charCode) return true;\n }\n return false;\n }\n\n reString(neg: boolean): string {\n return neg ? \"\\\\S\" : \"\\\\s\";\n }\n}\n\n/**\n * Char class for denoting a digit - [0-9].\n */\nexport class Digit extends CharClassHelper {\n match(charCode: number): boolean {\n return charCode >= ZERO && charCode <= NINE;\n }\n\n reString(neg: boolean): string {\n return neg ? \"\\\\D\" : \"\\\\d\";\n }\n}\n\n/**\n * Char class for denoting \"\\\\w\" - ie any WordChar\n */\nexport class WordChar extends CharClassHelper {\n match(charCode: number): boolean {\n return (\n charCode == USCORE ||\n (charCode >= ZERO && charCode <= NINE) ||\n (charCode >= lA && charCode <= lZ) ||\n (charCode >= uA && charCode <= uZ)\n );\n return true;\n }\n\n reString(neg: boolean): string {\n return neg ? \"\\\\W\" : \"\\\\w\";\n }\n}\n\nexport const CharClassHelpers: ReadonlyArray<CharClassHelper> = [new WordChar(), new Digit(), new Spaces()];\n","export enum PropertyName {\n // Binary Property Names\n gc,\n General_Category = gc,\n sc,\n Script = sc,\n scx,\n Script_Extension = scx,\n\n // Non binary property names\n Any,\n ASCII,\n AHex,\n ASCII_Hex_Digit = AHex,\n Alpha,\n Alphabetic = Alpha,\n Bidi_M,\n Bidi_Mirrored = Bidi_M,\n Bidi_C,\n Bidi_Control = Bidi_C,\n CI,\n Case_Ignorable = CI,\n Cased,\n CWCF,\n Changes_When_Casefolded = CWCF,\n CWCM,\n Changes_When_Casemapped = CWCM,\n CWL,\n Changes_When_Lowercased = CWL,\n CWKCF,\n Changes_When_NFKC_Casefolded = CWKCF,\n CWT,\n Changes_When_Titlecased = CWT,\n CWU,\n Changes_When_Uppercased = CWU,\n Dash,\n DI,\n Default_Ignorable_Code_Point = DI,\n Dep,\n Deprecated = Dep,\n Dia,\n Diacritic = Dia,\n Emoji,\n Emoji_Component,\n Emoji_Modifier,\n Emoji_Modifier_Base,\n Emoji_Presentation,\n Ext,\n Extender = Ext,\n Gr_Base,\n Grapheme_Base = Gr_Base,\n Gr_Ext,\n Grapheme_Extend = Gr_Ext,\n Hex,\n Hex_Digit = Hex,\n IDSB,\n IDS_Binary_Operator = IDSB,\n IDST,\n IDS_Trinary_Operator = IDST,\n IDC,\n ID_Continue = IDC,\n IDS,\n ID_Start = IDS,\n Ideo,\n Ideographic = Ideo,\n Join_C,\n Join_Control = Join_C,\n LOE,\n Logical_Order_Exception = LOE,\n Lower,\n Lowercase = Lower,\n Math,\n NChar,\n Noncharacter_Code_Point = NChar,\n Pat_Syn,\n Pattern_Syntax = Pat_Syn,\n Pat_WS,\n Pattern_White_Space = Pat_WS,\n QMark,\n Quotation_Mark = QMark,\n Radical,\n RI,\n Regional_Indicator = RI,\n STerm,\n Sentence_Terminal = STerm,\n SD,\n Soft_Dotted = SD,\n Term,\n Terminal_Punctuation = Term,\n UIdeo,\n Unified_Ideograph = UIdeo,\n Upper,\n Uppercase = Upper,\n VS,\n Variation_Selector = VS,\n space,\n White_Space = space,\n XIDC,\n XID_Continue = XIDC,\n XIDS,\n XID_Start = XIDS,\n}\n\nexport enum PropertyValue {\n // General Category proeprty values\n LC,\n Cased_Letter = LC,\n Pe,\n Close_Punctuation = Pe,\n Pc,\n Connector_Punctuation = Pc,\n Cc,\n cntrl = Cc,\n Control = Cc,\n Sc,\n Currency_Symbol = Sc,\n Pd,\n Dash_Punctuation = Pd,\n Nd,\n digit = Nd,\n Decimal_Number = digit,\n Me,\n Enclosing_Mark = Me,\n Pf,\n Final_Punctuation = Pf,\n Cf,\n Format = Cf,\n Pi,\n Initial_Punctuation = Pi,\n L,\n Letter = L,\n Nl,\n Letter_Number = Nl,\n Zl,\n Line_Separator = Zl,\n Ll,\n Lowercase_Letter = Ll,\n M,\n Combining_Mark = M,\n Mark,\n Sm,\n Math_Symbol = Sm,\n Lm,\n Modifier_Letter = Lm,\n Sk,\n Modifier_Symbol = Sk,\n Mn,\n Nonspacing_Mark = Mn,\n N,\n Number = N,\n Ps,\n Open_Punctuation = Ps,\n C,\n Other = C,\n Lo,\n Other_Letter = Lo,\n No,\n Other_Number = No,\n Po,\n Other_Punctuation = Po,\n So,\n Other_Symbol = So,\n Zp,\n Paragraph_Separator = Zp,\n Co,\n Private_Use = Co,\n P,\n punct = P,\n Punctuation = P,\n Z,\n Separator = Z,\n Zs,\n Space_Separator = Zs,\n Mc,\n Spacing_Mark = Mc,\n Cs,\n Surrogate = Cs,\n S,\n Symbol = S,\n Lt,\n Titlecase_Letter = Lt,\n Cn,\n Unassigned = Cn,\n Lu,\n Uppercase_Letter = Lu,\n // Script and Script Extension proeprty values\n}\n\nexport function propertyNameFor(value: string): PropertyName {\n value = value.trim();\n if (!(value in PropertyName)) {\n throw new SyntaxError(\"Invalid property name: \" + value);\n }\n return (PropertyName as any)[value];\n}\n\nexport function propertyValueFor(value: string): PropertyValue {\n value = value.trim();\n if (!(value in PropertyValue)) {\n throw new SyntaxError(\"Invalid property value: \" + value);\n }\n return (PropertyValue as any)[value];\n}\n\nexport function propertyNameString(value: number): string {\n if (!(value in PropertyName)) {\n throw new Error(\"Invalid property name: \" + value);\n }\n return PropertyName[value];\n}\n\nexport function propertyValueString(value: number): string {\n if (!(value in PropertyValue)) {\n throw new Error(\"Invalid property value: \" + value);\n }\n return PropertyValue[value];\n}\n","import * as TSU from \"@panyam/tsutils\";\nimport { TapeInterface as Tape } from \"./tape\";\nimport { Char } from \"./core\";\n\nfunction isNewLineChar(ch: string): boolean {\n return ch == \"\\r\" || ch == \"\\n\" || ch == \"\\u2028\" || ch == \"\\u2029\";\n}\n\nexport class Match {\n groups: [number, number][] = [];\n positions: number[] = [];\n constructor(public priority = 10, public matchIndex = -1, public start = -1, public end = -1) {}\n}\n\nexport enum OpCode {\n // Any character\n Any,\n // Any character not including a new line\n AnyNonNL,\n // Char and CI Chars\n Char,\n CIChar,\n // NegChar,\n // NegCIChar,\n\n // Non char opcodes\n Match,\n Noop,\n Save,\n Split,\n Jump,\n Begin, // Forward lookahead matches\n RBegin, // Reverse lookahead matches\n End,\n\n // Look ahead and Look back matchers\n // ^ and $ that are not activated on newlines\n StartingChar,\n EndingChar,\n // ^ and $ that are activated on newlines as well\n MLStartingChar,\n MLEndingChar,\n StartOfWord,\n EndOfWord,\n GroupStart,\n GroupEnd,\n\n // Stops the thread if state does not match\n EnsureState,\n}\n\nexport class Prog {\n instrs: Instr[] = [];\n stateMapping: Map<string, number>;\n\n constructor(public readonly startCondition = \"INITIAL\", public readonly scIsInclusive = true) {\n this.stateMapping = new Map<string, number>();\n this.registerState(\"INITIAL\");\n this.registerState(startCondition);\n }\n\n get length(): number {\n return this.instrs.length;\n }\n\n /**\n * Adds a state to our program and returns the state's index.\n */\n registerState(state: string): number {\n if (!this.stateMapping.has(state)) {\n this.stateMapping.set(state, this.stateMapping.size);\n }\n return this.stateMapping.get(state) || -1;\n }\n\n add(opcode: any, char: null | Char = null, ...args: number[]): Instr {\n const out = new Instr(opcode, char).add(...args);\n out.offset = this.instrs.length;\n this.instrs.push(out);\n return out;\n }\n\n static with(initializer: (prog: Prog) => void): Prog {\n const out = new Prog();\n initializer(out);\n return out;\n }\n\n debugValue(instrDebugValue: (instr: Instr) => string = InstrDebugValue): any {\n if (instrDebugValue) {\n return this.instrs.map((instr, index) => {\n if (instr.comment.trim().length > 0) return `L${index}: ${instrDebugValue(instr)} # ${instr.comment}`;\n else return `L${index}: ${instrDebugValue(instr)}`;\n });\n } else {\n return this.instrs.map((instr, index) => `L${index}: ${instr.debugValue}`);\n }\n }\n}\n\nexport class Instr {\n offset = 0;\n comment = \"\";\n args: number[] = [];\n // used for char match instructions - if opcode == Char or CIChar\n constructor(public readonly opcode: any, public char: null | Char = null) {\n this.char = char;\n }\n\n add(...args: number[]): this {\n this.args.push(...args);\n return this;\n }\n\n get debugValue(): any {\n let c = this.comment.trim();\n if (c.length > 0) c = \" # \" + c;\n return `${this.opcode} ${this.args.join(\" \")} ${this.char || \"\"} ${c}`;\n }\n}\n\n/**\n * A thread that is performing an execution of the regex VM.\n */\nexport class Thread {\n parentId = -1;\n id = 0;\n priority = 0;\n /**\n * Saved positions into the input stream for the purpose of\n * partial and custom matches.\n */\n groups: [number, number][] = [];\n positions: number[] = [];\n registers: TSU.NumMap<number> = {};\n\n /**\n * Create a thread at the given offset\n */\n constructor(public readonly offset: number = 0, public readonly gen: number = 0) {}\n\n regIncr(regId: number): void {\n if (!(regId in this.registers)) {\n throw new Error(`Register at offset ${regId} is invalid`);\n }\n this.registers[regId]++;\n }\n\n regAcquire(regId: number): void {\n if (regId in this.registers) {\n throw new Error(`Register at offset ${regId} already acquired. Release it first`);\n }\n this.registers[regId] = 0;\n }\n\n regRelease(regId: number): void {\n if (!(regId in this.registers)) {\n throw new Error(`Register at offset ${regId} is invalid`);\n }\n delete this.registers[regId];\n }\n\n regValue(regId: number): number {\n if (!(regId in this.registers)) {\n throw new Error(`Register at offset ${regId} is invalid`);\n }\n return this.registers[regId];\n }\n}\n\nexport interface VMTracer {\n threadDequeued(thread: Thread, tapeIndex: number): void;\n threadStepped(thread: Thread, tapeIndex: number, gen: number): void;\n threadQueued(thread: Thread, tapeIndex: number): void;\n}\n\nexport class VM {\n // TODO - To prevent excessive heap activity and GC\n // create a pool of threads and just have a cap on\n // match sizes\n // To eve simplify each Thread could just be something like:\n // number[] where\n // number[0] == offset\n // number[1-2*MaxSubs] = Substitutions\n // number[2*MaxSubs - 2*MaxSubs + M] = Registers\n // where M = Max number of NewReg instructions\n protected threadCounter = 0;\n protected currThreads: Thread[] = [];\n protected nextThreads: Thread[] = [];\n protected startPos = 0; // Where the match is beginning from - this will be set to tape.index when match is called\n // Initial state is always 0\n protected currState = 0;\n\n /**\n * Get the current lexer state (for incremental lexing support).\n * State is used to track context-sensitive lexing (e.g., inside string, comment).\n */\n getState(): number {\n return this.currState;\n }\n\n /**\n * Set the lexer state (for incremental lexing support).\n * Allows restarting lexing from a saved state.\n */\n setState(state: number): void {\n this.currState = state;\n }\n\n protected gen = 0;\n // Records which \"generation\" of the match a particular\n // offset is in. If a thread is added at a particular\n // offset the generation number is used to see if the\n // thread is a duplicate (and avoided if so). This\n // ensures that are linearly bounded on the number of\n // number threads as we match.\n protected genForOffset: TSU.NumMap<number> = {};\n\n tracer: VMTracer;\n constructor(\n public readonly prog: Prog,\n public readonly start = 0,\n public readonly end = -1,\n public readonly forward = true,\n configs: any = {},\n ) {\n if (end < 0) {\n end = prog.length - 1;\n }\n this.end = end;\n }\n\n savePosition(thread: Thread, pos: number, tapeIndex: number): void {\n while (thread.positions.length <= pos) thread.positions.push(-1);\n thread.positions[pos] = tapeIndex;\n }\n\n jumpBy(thread: Thread, delta = 1): Thread {\n return this.jumpTo(thread, thread.offset + delta);\n }\n\n jumpTo(thread: Thread, newOffset: number): Thread {\n // TODO - Why create new thread here - investigate if we can\n // return the same thread with the offset updated?\n // if we really want a \"history\" we could jsut keep prev offsets\n // in a list so we can keep a trace\n const out = new Thread(newOffset, this.gen);\n out.id = thread.id;\n out.parentId = thread.parentId;\n out.priority = thread.priority;\n out.positions = thread.positions;\n out.groups = thread.groups;\n out.registers = thread.registers;\n return out;\n }\n\n forkTo(thread: Thread, newOffset: number): Thread {\n const out = new Thread(newOffset, this.gen);\n out.id = ++this.threadCounter;\n out.parentId = thread.id;\n out.priority = thread.priority;\n out.positions = [...thread.positions];\n out.groups = [...thread.groups];\n out.registers = { ...thread.registers };\n return out;\n }\n\n startGroup(thread: Thread, groupIndex: number, tapeIndex: number): Thread {\n const newThread = this.forkTo(thread, thread.offset + 1);\n newThread.groups.push([groupIndex, tapeIndex]);\n return newThread;\n }\n\n endGroup(thread: Thread, groupIndex: number, tapeIndex: number): Thread {\n const newThread = this.forkTo(thread, thread.offset + 1);\n newThread.groups.push([-groupIndex, tapeIndex]);\n return newThread;\n }\n\n addThread(thread: Thread, list: Thread[], tape: Tape, delta = 0): void {\n if (\n thread.offset < this.start ||\n thread.offset > this.end ||\n this.genForOffset[thread.offset - this.start] == this.gen\n ) {\n // duplicate\n return;\n }\n this.genForOffset[thread.offset - this.start] = this.gen;\n const instr = this.prog.instrs[thread.offset];\n let nextCh: string;\n let lastCh: string;\n let newThread: Thread;\n // if (this.tracer) this.tracer.threadStepped(thread, tape.index, this.gen);\n const opcode = instr.opcode;\n switch (opcode) {\n case OpCode.Jump:\n newThread = this.jumpTo(thread, instr.args[0]);\n this.addThread(newThread, list, tape, delta);\n break;\n case OpCode.Split:\n for (let j = 0; j < instr.args.length; j++) {\n const newOff = instr.args[j];\n // TODO - only fork on position/group write instead of always forking on a split\n const newThread = j == 0 ? this.jumpTo(thread, newOff) : this.forkTo(thread, newOff);\n this.addThread(newThread, list, tape, delta);\n }\n break;\n case OpCode.Save:\n newThread = this.jumpTo(thread, thread.offset + 1);\n this.savePosition(newThread, instr.args[0], tape.index + delta);\n if (this.tracer) this.tracer.threadQueued(thread, tape.index + delta);\n this.addThread(newThread, list, tape, delta);\n break;\n case OpCode.GroupStart:\n newThread = this.startGroup(thread, instr.args[0], tape.index + delta);\n if (this.tracer) this.tracer.threadQueued(thread, tape.index + delta);\n this.addThread(newThread, list, tape, delta);\n break;\n case OpCode.GroupEnd:\n newThread = this.endGroup(thread, instr.args[0], tape.index + delta);\n if (this.tracer) this.tracer.threadQueued(thread, tape.index + delta);\n this.addThread(newThread, list, tape, delta);\n break;\n case OpCode.StartingChar:\n case OpCode.MLStartingChar:\n // only proceed further if prev was a newline or start\n lastCh = this.prevCh(tape);\n if (tape.index == 0 || (opcode == OpCode.MLStartingChar && isNewLineChar(lastCh))) {\n // have a match so can go forwrd but dont advance tape on\n // the same generation\n this.addThread(this.jumpBy(thread, 1), list, tape, delta);\n }\n break;\n case OpCode.EndingChar:\n case OpCode.MLEndingChar:\n // On end of input we dont advance tape but thread moves on\n // if at end of line boundary\n // check if next is end of input\n nextCh = this.nextCh(tape);\n if (nextCh == \"\" || (opcode == OpCode.MLEndingChar && isNewLineChar(nextCh))) {\n this.addThread(this.jumpBy(thread, 1), list, tape, delta);\n }\n break;\n case OpCode.StartOfWord:\n // only proceed further if prev was a newline or start\n /*\n lastCh = this.prevCh(tape);\n if (tape.index == 0 || (this.multiline && (isNewLineChar(lastCh) || isSpaceChar(lastCh)))) {\n // have a match so can go forwrd but dont advance tape on\n // the same generation\n this.addThread(this.jumpBy(thread, 1), list, tape, delta);\n }\n */\n break;\n case OpCode.EndOfWord:\n // On end of input we dont advance tape but thread moves on\n // if at end of line boundary\n // check if next is end of input\n /*\n nextCh = this.nextCh(tape);\n if (nextCh == \"\" || (this.multiline && (isNewLineChar(nextCh) || isSpaceChar(nextCh)))) {\n this.addThread(this.jumpBy(thread, 1), list, tape, delta);\n }\n */\n break;\n case OpCode.RBegin:\n {\n const [groupIndex, negate, end] = instr.args;\n const pos = (1 + groupIndex) * 2;\n const groupStart = thread.positions[pos];\n const [matchSuccess, matchEnd] = this.recurseMatch(\n tape,\n groupStart - 1,\n instr.offset + 1,\n end,\n false,\n negate == 1,\n );\n if (matchSuccess) {\n // TODO - Consider using a DFA for this case so we can mitigate\n // pathological cases with an exponential blowup on a success\n this.addThread(this.jumpTo(thread, end + 1), list, tape, delta);\n }\n }\n break;\n case OpCode.Begin:\n // This results in a new VM being created for this sub program and\n // kicking off a backtracking execution - Making these as explicit\n // constructs for the user to use means the user can make this choice\n // on their own voilition\n const [consume, negate, end] = instr.args;\n if (consume == 1) {\n // since this results in the consumption of a character (similar to \"Char\")\n // defer this to the list\n if (this.tracer) this.tracer.threadQueued(thread, tape.index);\n list.push(thread);\n } else {\n const [matchSuccess, matchEnd] = this.recurseMatch(\n tape,\n tape.index + 1,\n instr.offset + 1,\n end,\n true,\n negate == 1,\n );\n if (matchSuccess) {\n // TODO - Consider using a DFA for this case so we can mitigate\n // pathological cases with an exponential blowup on a success\n this.addThread(this.jumpTo(thread, end + 1), list, tape, delta);\n }\n }\n break;\n case OpCode.EnsureState:\n const states = instr.args;\n for (const state of states) {\n if (this.currState == state) {\n this.addThread(this.jumpBy(thread, 1), list, tape, delta);\n break;\n }\n }\n break;\n default:\n if (this.tracer) this.tracer.threadQueued(thread, tape.index);\n list.push(thread);\n break;\n }\n }\n\n matchCurrPos(tape: Tape, char: Char, ignoreCase = false): boolean {\n if (ignoreCase) {\n return char.match(tape.currChCodeLower) || char.match(tape.currChCodeUpper);\n } else {\n return char.match(tape.currChCode);\n }\n }\n\n protected hasMore(tape: Tape): boolean {\n return this.forward ? tape.hasMore : tape.index >= 0;\n }\n\n protected nextCh(tape: Tape): string {\n const next = tape.index + (this.forward ? 1 : -1);\n return tape.charAt(next);\n // if (next < 0 || next >= tape.input.length) return \"\";\n // return tape.input[next];\n }\n\n protected prevCh(tape: Tape): string {\n return tape.charAt(tape.index - (this.forward ? 1 : -1));\n // return tape.input[tape.index - (this.forward ? 1 : -1)];\n }\n\n /**\n * Runs the given instructions and returns a triple:\n * [matchId, matchStart, matchEnd]\n */\n match(tape: Tape): Match | null {\n // this.gen = 0; this.genForOffset = {};\n if (this.end < this.start) return null;\n this.startMatching(tape);\n let bestMatch: TSU.Nullable<Match> = null;\n while (this.currThreads.length > 0) {\n bestMatch = this.stepChar(tape, bestMatch);\n }\n // ensure tape is rewound to end of last match\n if (bestMatch != null) tape.index = bestMatch.end;\n return bestMatch;\n }\n\n recurseMatch(\n tape: Tape,\n tapeIndex: number,\n startOffset: number,\n endOffset: number,\n forward = true,\n negate = false,\n ): [boolean, number] {\n const savedPos = tape.index;\n if (!tape.canAdvance(forward ? 1 : -1)) return [negate, -1];\n tape.index = tapeIndex;\n // tape.advance(forward ? 1 : -1);\n const vm = new VM(this.prog, startOffset, endOffset, forward);\n const match = vm.match(tape);\n const newPos = tape.index;\n tape.index = savedPos; // always restore it first and let caller use it\n return [(match != null && !negate) || (match == null && negate), newPos];\n }\n\n startMatching(tape: Tape): void {\n this.currThreads = [];\n this.nextThreads = [];\n this.gen++;\n this.addThread(new Thread(this.start, this.gen), this.currThreads, tape);\n // let largestMatchEnd = -1;\n // let lastMatchIndex = -1;\n this.startPos = tape.index;\n }\n\n stepChar(tape: Tape, currMatch: TSU.Nullable<Match> = null): TSU.Nullable<Match> {\n // At this point all our threads are point to the next \"transition\" or \"match\" action.\n this.gen++;\n // console.log(`Ch (@${tape.index}): ${tape.currChCode}, Gen (${this.gen})`);\n for (let i = 0; i < this.currThreads.length; i++) {\n const thread = this.currThreads[i];\n // console.log(` Thread (${i}): ${thread.offset}(${thread.gen})`);\n const nextMatch = this.stepThread(tape, thread);\n if (nextMatch != null) {\n if (\n currMatch == null ||\n nextMatch.priority > currMatch.priority ||\n (nextMatch.priority == currMatch.priority && nextMatch.end > currMatch.end)\n ) {\n currMatch = nextMatch;\n break;\n } else if (currMatch != nextMatch) {\n // Since we kill of lower priority matches becuase of matchedInGen\n // we should not be here\n // TSU.assert(false, \"Should not be here\");\n }\n }\n }\n if (this.hasMore(tape)) {\n tape.advance(this.forward ? 1 : -1);\n }\n this.currThreads = this.nextThreads;\n this.nextThreads = [];\n return currMatch;\n }\n\n stepThread(tape: Tape, thread: Thread): TSU.Nullable<Match> {\n if (this.tracer) this.tracer.threadStepped(thread, tape.index, this.gen);\n let currMatch: TSU.Nullable<Match> = null;\n const instrs = this.prog.instrs;\n const instr = instrs[thread.offset];\n const opcode = instr.opcode;\n const args = instr.args;\n const delta = this.forward ? 1 : -1;\n // Do char match based actions\n let advanceTape = false;\n let ch: number;\n switch (opcode) {\n case OpCode.RBegin:\n throw new Error(\"Invalid state. Reverse matches must be handled in addThread\");\n break;\n case OpCode.Begin:\n const [consume, negate, end] = instr.args;\n TSU.assert(consume == 1, \"Plain lookahead cannot be here\");\n const [matchSuccess, matchEnd] = this.recurseMatch(tape, tape.index, instr.offset + 1, end, true, negate == 1);\n if (matchSuccess) {\n // TODO - Consider using a DFA for this case so we can mitigate\n // pathological cases with an exponential blowup\n // on a success we have a few options\n this.addThread(this.jumpTo(thread, end + 1), this.nextThreads, tape);\n }\n break;\n case OpCode.End:\n // Return back to calling VM - very similar to a match\n const out = new Match(-1, -1, this.startPos, tape.index);\n out.groups = thread.groups;\n out.positions = thread.positions;\n return out;\n break;\n case OpCode.Match:\n // we have a match on this thread so return it\n // Update the match if we are a higher prioirty or longer match\n // than what was already found (if any)\n if (tape.index > this.startPos) {\n const currPriority = instr.args[0];\n const matchIndex = instr.args[1];\n currMatch = new Match();\n currMatch.start = this.startPos;\n currMatch.end = tape.index;\n currMatch.priority = currPriority;\n currMatch.matchIndex = matchIndex;\n currMatch.groups = thread.groups;\n currMatch.positions = thread.positions;\n }\n break;\n case OpCode.Char:\n case OpCode.CIChar:\n if (this.hasMore(tape)) {\n advanceTape = this.matchCurrPos(tape, instr.char!, opcode == OpCode.CIChar);\n }\n break;\n /*\n case OpCode.NegChar:\n case OpCode.NegCIChar:\n if (this.hasMore(tape)) {\n advanceTape = !this.matchCurrPos(tape, args, opcode == OpCode.NegCIChar);\n }\n break;\n */\n case OpCode.AnyNonNL:\n case OpCode.Any:\n if (this.hasMore(tape)) {\n advanceTape = opcode == OpCode.Any || !isNewLineChar(tape.currCh);\n }\n break;\n }\n if (advanceTape /* && this.hasMore(tape) */) {\n this.addThread(this.jumpBy(thread, 1), this.nextThreads, tape, delta);\n }\n return currMatch;\n }\n}\n\nexport function InstrDebugValue(instr: Instr): string {\n switch (instr.opcode) {\n case OpCode.Match:\n return `Match ${instr.args[0]} ${instr.args[1]}`;\n // case OpCode.NegChar:\n // case OpCode.NegCIChar:\n case OpCode.Char:\n case OpCode.CIChar: {\n let out = `${OpCode[instr.opcode].toString()} `;\n // out += `${CharType[instr.args[0]]}`;\n // for (let i = 1; i < instr.args.length; i++) out += \" \" + instr.args[i];\n out += `${instr.char!.debugValue()}`;\n return out;\n }\n case OpCode.Any:\n return \".\";\n case OpCode.AnyNonNL:\n return \"NL.\";\n case OpCode.StartingChar:\n return \"^\";\n case OpCode.MLStartingChar:\n return \"NL^\";\n case OpCode.EndingChar:\n return \"$NL\";\n case OpCode.MLEndingChar:\n return \"$NL_MultiLine\";\n case OpCode.Save:\n return `Save ${instr.args[0]}`;\n case OpCode.GroupStart:\n return `GroupStart ${instr.args[0]}`;\n case OpCode.GroupEnd:\n return `GroupEnd ${instr.args[0]}`;\n case OpCode.Split:\n return `Split ${instr.args.join(\", \")}`;\n case OpCode.Jump:\n return `Jump ${instr.args[0]}`;\n case OpCode.Begin:\n return `Begin ${instr.args.join(\" \")}`;\n case OpCode.RBegin:\n return `RBegin ${instr.args.join(\" \")}`;\n case OpCode.End:\n return `End ${instr.args.join(\" \")}`;\n case OpCode.EnsureState:\n return `EnsureState ${instr.args.join(\" \")}`;\n default:\n throw new Error(\"Invalid Opcode: \" + instr.opcode);\n }\n}\n","import * as TSU from \"@panyam/tsutils\";\n\nimport {\n Rule,\n RegexType,\n Quant,\n Regex,\n Cat,\n Char,\n CharType,\n Var,\n BackNumRef,\n BackNamedRef,\n LookAhead,\n LookBack,\n Union,\n} from \"./core\";\nimport { OpCode, Prog, Instr } from \"./vm\";\n\nexport type RegexResolver = (name: string) => Regex;\nexport type CompilerListener = (expr: Regex, prog: Prog, start: number, length: number) => void;\n\n/**\n * The regex Compiler compiles a parsed regular expression tree into bytecode that is\n * executed by the VM.\n */\nexport class Compiler {\n emitGroups = false;\n emitPosition = true;\n constructor(\n public regexResolver: TSU.Nullable<RegexResolver>,\n public listener: TSU.Nullable<CompilerListener> = null,\n ) {}\n\n compile(rules: Rule[]): Prog {\n // Split across each of our expressions\n const out = new Prog();\n // only add the split instruction if we have more than one rule\n const split: Instr = rules.length <= 1 ? new Instr(OpCode.Split) : out.add(OpCode.Split, null);\n rules.forEach((rule, i) => {\n split.add(out.instrs.length);\n const ignoreCase = rule.expr.ignoreCase == null ? false : rule.expr.ignoreCase;\n const dotAll = rule.expr.dotAll == null ? true : rule.expr.dotAll;\n const multiline = rule.expr.multiline == null ? true : rule.expr.multiline;\n if (rule.needsSpecificStates && rule.activeStates != null) {\n const ensureInstr = out.add(OpCode.EnsureState, null);\n rule.activeStates.forEach((state) => {\n const ind = out.registerState(state);\n ensureInstr.add(ind);\n });\n }\n this.compileExpr(rule.expr, out, ignoreCase, dotAll, multiline);\n out.add(OpCode.Match, null).add(rule.priority, rule.matchIndex >= 0 ? rule.matchIndex : i);\n });\n return out;\n }\n\n /**\n * Compile a given expression into a set of instructions.\n */\n protected compileExpr(expr: Regex, prog: Prog, ignoreCase: boolean, dotAll: boolean, multiline: boolean): number {\n const start = prog.length;\n const currOffset = prog.length;\n if (expr.groupIndex >= 0) {\n if (this.emitPosition) prog.add(OpCode.Save).add((1 + expr.groupIndex) * 2);\n if (this.emitGroups) prog.add(OpCode.GroupStart).add(1 + expr.groupIndex);\n }\n if (expr.tag == RegexType.CHAR) {\n this.compileChar(expr as Char, prog, ignoreCase, dotAll, multiline);\n } else if (expr.tag == RegexType.START_OF_INPUT) {\n const ml = expr.multiline == null ? multiline : expr.multiline;\n prog.add(ml ? OpCode.MLStartingChar : OpCode.StartingChar);\n } else if (expr.tag == RegexType.END_OF_INPUT) {\n const ml = expr.multiline == null ? multiline : expr.multiline;\n prog.add(ml ? OpCode.MLEndingChar : OpCode.EndingChar);\n } else if (expr.tag == RegexType.START_OF_WORD) {\n prog.add(OpCode.StartOfWord);\n } else if (expr.tag == RegexType.END_OF_WORD) {\n prog.add(OpCode.EndOfWord);\n } else if (expr.tag == RegexType.CAT) {\n this.compileCat(expr as Cat, prog, ignoreCase, dotAll, multiline);\n } else if (expr.tag == RegexType.UNION) {\n this.compileUnion(expr as Union, prog, ignoreCase, dotAll, multiline);\n } else if (expr.tag == RegexType.QUANT) {\n this.compileQuant(expr as Quant, prog, ignoreCase, dotAll, multiline);\n } else if (expr.tag == RegexType.VAR) {\n this.compileVar(expr as Var, prog, ignoreCase, dotAll, multiline);\n } else if (expr.tag == RegexType.BACK_NAMED_REF) {\n this.compileBackNamedRef(expr as BackNamedRef, prog, ignoreCase, dotAll, multiline);\n } else if (expr.tag == RegexType.BACK_NUM_REF) {\n this.compileBackNumRef(expr as BackNumRef, prog, ignoreCase, dotAll, multiline);\n // } else if (expr.tag == RegexType.NEG) { this.compileNeg(expr as Neg, prog);\n } else if (expr.tag == RegexType.LOOK_AHEAD) {\n this.compileLookAhead(expr as LookAhead, prog, ignoreCase, dotAll, multiline);\n } else if (expr.tag == RegexType.LOOK_BACK) {\n this.compileLookBack(expr as LookBack, prog, ignoreCase, dotAll, multiline);\n } else {\n throw new Error(\"Regex Type not yet supported: \" + expr.tag);\n }\n if (expr.groupIndex >= 0) {\n if (this.emitGroups) prog.add(OpCode.GroupEnd).add(1 + expr.groupIndex);\n if (this.emitPosition) prog.add(OpCode.Save).add((1 + expr.groupIndex) * 2 + 1);\n }\n if (this.listener && prog.length > currOffset) {\n this.listener(expr, prog, currOffset, prog.length - currOffset);\n }\n return prog.length - start;\n }\n\n protected compileChar(char: Char, prog: Prog, ignoreCase: boolean, dotAll: boolean, multiline: boolean): void {\n if (char.op == CharType.AnyChar) {\n // TODO - Should neg be ignored?\n prog.add(dotAll ? OpCode.Any : OpCode.AnyNonNL);\n } else {\n const instr = prog.add(ignoreCase ? OpCode.CIChar : OpCode.Char);\n instr.char = char;\n /*\n // We have Neg or not, CI or not\n const instr = prog.add(\n ignoreCase ? (char.neg ? OpCode.NegCIChar : OpCode.CIChar) : char.neg ? OpCode.NegChar : OpCode.Char,\n );\n instr.add(char.op);\n\n // And now the arguments\n for (const arg of char.args) instr.add(arg);\n */\n }\n }\n\n protected compileCat(cat: Cat, prog: Prog, ignoreCase: boolean, dotAll: boolean, multiline: boolean): void {\n for (const child of cat.children) {\n this.compileExpr(child, prog, ignoreCase, dotAll, multiline);\n }\n }\n\n protected compileBackNumRef(\n ne: BackNumRef,\n prog: Prog,\n ignoreCase: boolean,\n dotAll: boolean,\n multiline: boolean,\n ): void {\n // TODO - This may need a resolution at \"runtime\" so the instruction\n // should reflect as such?\n // See compiler.spec.ts - \"Test Back Named Groups\"\n throw new Error(\"BackNumRef Not Implemented\");\n }\n\n protected compileBackNamedRef(\n ne: BackNamedRef,\n prog: Prog,\n ignoreCase: boolean,\n dotAll: boolean,\n multiline: boolean,\n ): void {\n // TODO - This may need a resolution at \"runtime\" so the instruction\n // should reflect as such?\n // See compiler.spec.ts - \"Test Back Named Groups\"\n throw new Error(\"BackNameRef Not Implemented\");\n }\n\n protected compileVar(v: Var, prog: Prog, ignoreCase: boolean, dotAll: boolean, multiline: boolean): void {\n const name = v.name.trim();\n const expr = this.regexResolver ? this.regexResolver(name) : null;\n if (expr == null) {\n throw new Error(`Cannot find expression: ${name}`);\n }\n this.compileExpr(expr, prog, ignoreCase, dotAll, multiline);\n }\n\n protected compileUnion(union: Union, prog: Prog, ignoreCase: boolean, dotAll: boolean, multiline: boolean): void {\n const split = prog.add(OpCode.Split);\n const jumps: Instr[] = [];\n\n for (let i = 0; i < union.options.length; i++) {\n split.add(prog.length);\n this.compileExpr(union.options[i], prog, ignoreCase, dotAll, multiline);\n if (i < union.options.length - 1) {\n jumps.push(prog.add(OpCode.Jump));\n }\n }\n for (const jmp of jumps) {\n jmp.add(prog.length);\n }\n }\n\n /**\n * Compiles a repetition (with quantifiers) into its instructions. This explicitly expands\n * a rule of the form x\\{a,b\\} to xx... (a) times followed by x? (b - a) times\n */\n protected compileQuant(quant: Quant, prog: Prog, ignoreCase: boolean, dotAll: boolean, multiline: boolean): void {\n // optimize the special cases of *, ? and +\n if (quant.minCount == 0 && quant.maxCount == TSU.Constants.MAX_INT) {\n // *\n this.compileAtleast0(quant.expr, prog, quant.greedy, ignoreCase, dotAll, multiline);\n } else if (quant.minCount == 1 && quant.maxCount == TSU.Constants.MAX_INT) {\n // +\n this.compileAtleast1(quant.expr, prog, quant.greedy, ignoreCase, dotAll, multiline);\n } else if (quant.minCount == 0 && quant.maxCount == 1) {\n // ?\n this.compileOptional(quant.expr, prog, quant.greedy, ignoreCase, dotAll, multiline);\n } else {\n // general case - Currently going with Option 1\n //\n // - convert x{a,b} to xxxxxx (a) times followed by x? b - a times\n for (let i = 0; i < quant.minCount; i++) {\n this.compileExpr(quant.expr, prog, ignoreCase, dotAll, multiline);\n }\n // generate x? b - a times\n if (quant.isUnlimited) {\n // then generate a a* here\n this.compileAtleast0(quant.expr, prog, quant.greedy, ignoreCase, dotAll, multiline);\n } else {\n for (let i = quant.minCount; i < quant.maxCount; i++) {\n this.compileOptional(quant.expr, prog, quant.greedy, ignoreCase, dotAll, multiline);\n }\n }\n }\n }\n\n protected compileAtleast1(\n expr: Regex,\n prog: Prog,\n greedy = true,\n ignoreCase: boolean,\n dotAll: boolean,\n multiline: boolean,\n ): void {\n const l1 = prog.length;\n this.compileExpr(expr, prog, ignoreCase, dotAll, multiline);\n const split = prog.add(OpCode.Split);\n const l3 = prog.length;\n if (greedy) {\n split.add(l1, l3);\n } else {\n split.add(l3, l1);\n }\n }\n\n protected compileAtleast0(\n expr: Regex,\n prog: Prog,\n greedy: boolean,\n ignoreCase: boolean,\n dotAll: boolean,\n multiline: boolean,\n ): void {\n const split = prog.add(OpCode.Split);\n const l1 = split.offset;\n const l2 = prog.length;\n this.compileExpr(expr, prog, ignoreCase, dotAll, multiline);\n prog.add(OpCode.Jump).add(l1);\n const l3 = prog.length;\n if (greedy) {\n split.add(l2, l3);\n } else {\n split.add(l3, l2);\n }\n }\n\n protected compileOptional(\n expr: Regex,\n prog: Prog,\n greedy: boolean,\n ignoreCase: boolean,\n dotAll: boolean,\n multiline: boolean,\n ): void {\n const split = prog.add(OpCode.Split);\n const l1 = prog.length;\n this.compileExpr(expr, prog, ignoreCase, dotAll, multiline);\n const l2 = prog.length;\n if (greedy) {\n split.add(l1, l2);\n } else {\n split.add(l2, l1);\n }\n }\n\n /**\n * Compiles lookahead assertions\n */\n protected compileLookAhead(\n la: LookAhead,\n prog: Prog,\n ignoreCase: boolean,\n dotAll: boolean,\n multiline: boolean,\n ): void {\n // how should this work?\n // Ensure that assertion matches first before continuing with the expression\n this.compileExpr(la.expr, prog, ignoreCase, dotAll, multiline);\n const begin = prog.add(OpCode.Begin).add(0, la.negate ? 1 : 0); // negate if needed\n this.compileExpr(la.cond, prog, ignoreCase, dotAll, multiline);\n const end = prog.add(OpCode.End).add(begin.offset);\n begin.add(end.offset);\n }\n\n /**\n * Compiles lookback assertions\n */\n protected compileLookBack(lb: LookBack, prog: Prog, ignoreCase: boolean, dotAll: boolean, multiline: boolean): void {\n // Ensure that assertion matches first before continuing with the expression\n this.compileExpr(lb.expr, prog, ignoreCase, dotAll, multiline);\n TSU.assert(lb.expr.groupIndex >= 0, \"LookBack Assertion requires expression to have a group Index\");\n const begin = prog.add(OpCode.RBegin).add(lb.expr.groupIndex, lb.negate ? 1 : 0); // negate if needed\n this.compileExpr(lb.cond.reverse(), prog, ignoreCase, dotAll, multiline);\n const end = prog.add(OpCode.End).add(begin.offset);\n begin.add(end.offset);\n }\n}\n","import * as TSU from \"@panyam/tsutils\";\nimport { Token } from \"./token\";\n\nexport class TokenizerError extends Error {\n readonly name: string = \"TokenizerError\";\n\n constructor(\n message: string,\n public offset: number,\n public length: number,\n public type: string,\n public value: any = null,\n ) {\n super(message);\n Object.setPrototypeOf(this, new.target.prototype);\n }\n}\n\nexport class UnexpectedTokenError extends Error {\n readonly name: string = \"UnexpectedTokenError\";\n expectedTokens: Token[];\n\n constructor(public foundToken: TSU.Nullable<Token>, ...expectedTokens: Token[]) {\n super(\n `Found Token: ${foundToken?.tag || \"EOF\"} (${foundToken?.value || \"\"}), Expected: ${expectedTokens.join(\", \")}`,\n );\n this.expectedTokens = expectedTokens;\n }\n}\n","export abstract class TapeInterface {\n index = 0;\n abstract charAt(index: number): string;\n abstract hasIndex(index: number): boolean;\n abstract substring(startIndex: number, endIndex: number): string;\n\n constructor(public forward = true) {}\n\n advance(delta = 1): boolean {\n const next = this.forward ? this.index + delta : this.index - delta;\n // if (!this.hasIndex(next)) return false;\n this.index = next;\n return true;\n }\n\n canAdvance(delta = 1): boolean {\n const next = this.forward ? this.index + delta : this.index - delta;\n return this.hasIndex(next);\n }\n\n get hasMore(): boolean {\n const next = this.forward ? this.index : this.index - 1;\n return this.hasIndex(next);\n // return this.forward ? this.index < this.input.length : this.index > 0;\n }\n\n get currCh(): string {\n return this.charAt(this.index);\n }\n\n get prevCh(): string {\n return this.charAt(this.index - (this.forward ? 1 : -1));\n }\n\n get nextCh(): string {\n const next = this.index + (this.forward ? 1 : -1);\n return this.charAt(next);\n }\n\n get currChCode(): number {\n if (!this.hasMore) return -1;\n return this.currCh.charCodeAt(0);\n // return this.input.charCodeAt(this.index);\n }\n\n get currChCodeLower(): number {\n if (!this.hasMore) return -1;\n return this.currCh.toLowerCase().charCodeAt(0);\n }\n\n get currChCodeUpper(): number {\n if (!this.hasMore) return -1;\n return this.currCh.toUpperCase().charCodeAt(0);\n }\n\n charCodeAt(index: number): number {\n if (!this.hasIndex(index)) return -1;\n return this.charAt(index).charCodeAt(0);\n }\n\n charCodeAtLower(index: number): number {\n if (!this.hasIndex(index)) return -1;\n return this.charAt(index).toLowerCase().charCodeAt(0);\n }\n\n charCodeAtUpper(index: number): number {\n if (!this.hasIndex(index)) return -1;\n return this.charAt(index).toUpperCase().charCodeAt(0);\n }\n}\n\n/**\n * A Tape of characters we would read with some extra helpers like rewinding\n * forwarding and prefix checking that is fed into the different tokenizers\n * used by the scannerless parsers.\n */\nexport class Tape extends TapeInterface {\n protected _rawInput: string;\n readonly input: string[];\n\n constructor(input: string, public forward = true) {\n super(forward);\n this._rawInput = input;\n this.input = [...input];\n }\n\n push(content: string): void {\n this._rawInput += content;\n this.input.push(...content);\n }\n\n substring(startIndex: number, endIndex: number): string {\n return this._rawInput.substring(startIndex, endIndex);\n // return this.input.slice(startIndex, endIndex).join(\"\");\n }\n\n hasIndex(index: number): boolean {\n return index >= 0 && index < this.input.length;\n }\n\n charAt(index: number): string {\n if (index < 0 || index >= this.input.length) return \"\";\n return this.input[index];\n }\n}\n\nexport class TapeHelper {\n /**\n * Advances the tape to the end of the first occurence of\n * the given pattern.\n */\n static advanceAfter(tape: TapeInterface, pattern: string, ensureNoPrefixSlash = true): number {\n let pos = TapeHelper.advanceTo(tape, pattern, ensureNoPrefixSlash);\n if (pos >= 0) {\n pos += pattern.length;\n tape.index = pos;\n }\n return pos;\n }\n\n /**\n * Advances the tape till the start of a given pattern.\n * This is not the most optimal implementation and just does a brute\n * force search at each index. Instead using the Regex interface\n * directly will be faster.\n */\n static advanceTo(tape: TapeInterface, pattern: string, ensureNoPrefixSlash = true): number {\n const lastIndex = tape.index;\n while (tape.hasMore) {\n const currStart = tape.index;\n if (TapeHelper.matches(tape, pattern)) {\n const endIndex = tape.index;\n tape.index = currStart;\n let numSlashes = 0;\n if (ensureNoPrefixSlash) {\n for (let i = endIndex - 1; i >= 0; i--) {\n if (tape.charAt(i) == \"\\\\\") numSlashes++;\n else break;\n }\n }\n if (numSlashes % 2 == 0) {\n return tape.index;\n }\n }\n tape.advance(1);\n }\n tape.index = lastIndex;\n throw new Error(`Unexpected end of input before (${pattern})`);\n return -1;\n }\n\n /**\n * Tells if the given prefix is matche at the current position of the tokenizer.\n */\n static matches(tape: TapeInterface, prefix: string, advance = true): boolean {\n const lastIndex = tape.index;\n let i = 0;\n let success = true;\n for (; i < prefix.length; i++) {\n if (prefix[i] != tape.currCh) {\n success = false;\n break;\n }\n tape.advance(1);\n }\n // Reset pointers if we are only peeking or match failed\n if (!advance || !success) {\n tape.index = lastIndex;\n }\n return success;\n }\n}\n","import * as TSU from \"@panyam/tsutils\";\nimport { TapeInterface as Tape } from \"./tape\";\nimport { TokenizerError, UnexpectedTokenError } from \"./errors\";\n\nexport type TokenType = number | string;\n\nexport class Token {\n private static idCounter = 0;\n // ID for uniquely identifying tokens if needed for shallow equality\n id = Token.idCounter++;\n value: any = null;\n groups: TSU.NumMap<number[]> = {};\n positions: TSU.NumMap<[number, number]> = {};\n\n // Incremental lexing support fields\n /**\n * Lexer state when this token was constructed.\n * 0 = INITIAL state. Higher numbers represent other states (e.g., inside string, comment).\n * Used for incremental lexing to restart from a token boundary.\n */\n state = 0;\n\n /**\n * Number of characters read beyond this token's lexeme to determine it.\n * Most tokens need 1 char lookahead to know they're complete (e.g., identifier ends on non-alnum).\n * Used for incremental lexing dependency tracking.\n */\n lookahead = 1;\n\n /**\n * Number of preceding tokens whose lookahead reaches this token.\n * Default 1 means the previous token's lookahead extends into this token.\n * Used for incremental lexing to find affected region on edit.\n */\n lookback = 1;\n\n constructor(public tag: TokenType, public readonly matchIndex: number, public start: number, public end: number) {}\n\n isOneOf(...expected: any[]): boolean {\n for (const tok of expected) {\n if (this.tag == tok) {\n return true;\n }\n }\n return false;\n }\n}\n\nexport type NextTokenFunc = (tape: Tape, owner: any) => Token | null;\n\n/**\n * A wrapper on a tokenizer for providing features like k-lookahead, token\n * insertion, rewinding, expectation enforcement etc.\n */\nexport class TokenBuffer {\n buffer: Token[] = [];\n\n constructor(public readonly nextToken: NextTokenFunc, public tokenizerContext: any) {}\n\n next(tape: Tape): Token | null {\n const out = this.peek(tape);\n if (out != null) {\n this.consume();\n }\n return out;\n }\n\n /**\n * Peek at the nth token in the token stream.\n */\n peek(tape: Tape, nth = 0): Token | null {\n while (this.buffer.length <= nth) {\n const tok = this.nextToken(tape, this.tokenizerContext);\n if (tok == null) return null;\n this.buffer.push(tok);\n }\n return this.buffer[nth];\n }\n\n match(\n tape: Tape,\n matchFunc: (token: Token) => boolean,\n ensure = false,\n consume = true,\n nextAction?: (token: Token) => boolean | undefined,\n ): Token | null {\n const token = this.peek(tape);\n if (token != null) {\n if (matchFunc(token)) {\n if (nextAction && nextAction != null) {\n nextAction(token);\n }\n if (consume) {\n this.consume();\n }\n } else if (ensure) {\n // Should we throw an error?\n throw new UnexpectedTokenError(token);\n } else {\n return null;\n }\n } else if (ensure) {\n throw new TokenizerError(\"Unexpected end of input\", -1, 0, \"UnexpectedEndOfInput\");\n }\n return token;\n }\n\n consume(): void {\n this.buffer.splice(0, 1);\n }\n\n consumeIf(tape: Tape, ...expected: TokenType[]): Token | null {\n return this.match(tape, (t) => t.isOneOf(...expected));\n }\n\n expectToken(tape: Tape, ...expected: TokenType[]): Token {\n return this.match(tape, (t) => t.isOneOf(...expected), true, true) as Token;\n }\n\n ensureToken(tape: Tape, ...expected: TokenType[]): Token {\n return this.match(tape, (t) => t.isOneOf(...expected), true, false) as Token;\n }\n\n nextMatches(tape: Tape, ...expected: TokenType[]): Token | null {\n const token = this.peek(tape);\n if (token == null) return null;\n for (const tok of expected) {\n if (token.tag == tok) return token;\n }\n return null;\n }\n}\n","export class GroupCounter {\n value = -1;\n next(): number {\n return ++this.value;\n }\n get current(): number {\n return this.value;\n }\n}\n\nexport function isSpace(ch: string): boolean {\n return ch == \" \" || ch == \"\\t\" || ch == \"\\n\" || ch == \"\\r\";\n}\n\n// function isSpaceChar(ch: string): boolean { return ch == \" \" || ch == \"\\t\"; }\n","import * as TSU from \"@panyam/tsutils\";\nimport {\n Quant,\n RegexType,\n StartOfInput,\n EndOfInput,\n Regex,\n Cat,\n Char,\n LeafChar,\n CharGroup,\n CharType,\n Var,\n BackNamedRef,\n BackNumRef,\n LookAhead,\n LookBack,\n Union,\n} from \"./core\";\nimport { CharClassType } from \"./charclasses\";\nimport { GroupCounter } from \"./utils\";\n\n/**\n * A RegexParser for parsing regex strings in JS RegExp format.\n * This class will seldom have to be used directly. Instead use one of the methods in {@link Builder}\n */\nexport class RegexParser {\n protected unicode: boolean;\n protected counter: GroupCounter;\n /**\n * @param pattern The pattern string being parsed.\n * @param config Configs for the regex to include whether parsing is unicode or plain ASCII.\n */\n constructor(public readonly pattern: string, config?: { unicode?: boolean }) {\n this.counter = new GroupCounter();\n this.unicode = config?.unicode || false;\n }\n\n protected reduceLeft(stack: Regex[]): Regex {\n const r = stack.length == 1 ? stack[0] : new Cat(...stack);\n // remove all elements on stack\n stack.splice(0);\n return r;\n }\n\n protected throwError(msg: string): void {\n throw new SyntaxError(`Error in JS RE '${this.pattern}': ${msg}`);\n }\n\n /**\n * Creates a regex tree given a string\n */\n parse(curr = 0, end = -1): Regex {\n const pattern = this.pattern;\n const stack: Regex[] = [];\n if (end < 0) end = pattern.length - 1;\n while (curr <= end) {\n const currCh = pattern[curr];\n // see if we have groups so they get highest preference\n if (currCh == \".\") {\n stack.push(LeafChar.Any());\n curr++;\n } else if (currCh == \"\\\\\" && pattern[curr + 1] >= \"1\" && pattern[curr + 1] <= \"9\") {\n // Numeric references\n curr++;\n let num = \"\";\n while (curr <= end && pattern[curr] >= \"0\" && pattern[curr] <= \"9\") {\n num = num + pattern[curr++];\n }\n const refNum = parseInt(num);\n if (refNum > this.counter.current + 1) {\n this.throwError(\"Invalid reference: \" + refNum);\n }\n stack.push(new BackNumRef(refNum));\n } else if (currCh == \"\\\\\" && pattern[curr + 1] == \"k\" && pattern[curr + 2] == \"<\") {\n // Named references\n curr += 3;\n let gtPos = curr;\n while (gtPos <= end && pattern[gtPos] != \">\") gtPos++;\n if (gtPos > end) this.throwError(\"Expected '>' found EOI\");\n const name = pattern.substring(curr, gtPos);\n if (name.trim() == \"\") {\n this.throwError(\"Expected name\");\n }\n stack.push(new BackNamedRef(name));\n curr = gtPos + 1;\n } else if (currCh == \"[\") {\n // character ranges\n let clPos = curr + 1;\n while (clPos <= end && pattern[clPos] != \"]\") {\n if (pattern[clPos] == \"\\\\\") clPos++;\n clPos++;\n }\n if (clPos > end) this.throwError(\"Expected ']' found EOI\");\n stack.push(this.parseCharGroup(curr + 1, clPos - 1));\n curr = clPos + 1;\n } else if (currCh == \"^\") {\n stack.push(new StartOfInput());\n curr++;\n } else if (currCh == \"$\") {\n stack.push(new EndOfInput());\n curr++;\n } else if (currCh == \"|\") {\n if (curr + 1 <= end) {\n // reduce everything \"until now\" and THEN apply\n const prev = this.reduceLeft(stack);\n // this.parse everything to the right\n const rest = this.parse(curr + 1, end);\n return new Union(prev, rest);\n }\n curr = end + 1;\n } else if (currCh == \"(\") {\n curr = this.parseGroup(stack, curr, end);\n } else if (currCh == \")\" || currCh == \"]\" || currCh == \"}\") {\n this.throwError(`Unmatched ${currCh}. Try using \\\\${currCh}`);\n } else if (pattern[curr] == \"*\" || pattern[curr] == \"?\" || pattern[curr] == \"+\" || pattern[curr] == \"{\") {\n curr = this.parseQuant(stack, curr, end);\n } else {\n // plain old alphabets\n const [result, nchars] = this.parseChar(curr, end);\n stack.push(result);\n curr += nchars;\n }\n }\n if (stack.length <= 0) {\n // this.throwError(`Invalid Regex (${curr} - ${end}): ${pattern}`);\n }\n if (stack.length == 1) return stack[0];\n return new Cat(...stack);\n }\n\n protected parseGroup(stack: Regex[], curr: number, end: number): number {\n // we have a grouping or an assertion\n let clPos = curr + 1;\n let depth = 0;\n const pattern = this.pattern;\n while (clPos <= end && (pattern[clPos] != \")\" || depth > 0)) {\n if (pattern[clPos] == \"(\") depth++;\n else if (pattern[clPos] == \")\") depth--;\n if (pattern[clPos] == \"\\\\\") clPos++;\n clPos++;\n }\n if (clPos > end) this.throwError(\"Expected ')' found EOI\");\n\n curr++;\n if (pattern[curr] == \"?\") {\n // assertions\n curr++; // skip the \"?\"\n if (pattern[curr] == \":\") {\n // A non capturing\n stack.push(this.parse(curr + 1, clPos - 1));\n } else if (pattern[curr] == \"<\" && pattern[curr + 1] != \"!\" && pattern[curr + 1] != \"=\") {\n // Named capture group\n const groupIndex = this.counter.next();\n let groupName = \"\";\n // get name of this group\n let gtPos = curr + 1;\n while (gtPos <= end && pattern[gtPos] != \">\") {\n groupName += pattern[gtPos];\n gtPos++;\n }\n const subExpr = this.parse(gtPos + 1, clPos - 1);\n subExpr.groupIndex = groupIndex;\n if (groupName.length > 0) subExpr.groupName = groupName;\n } else {\n // We have lookback/ahead assertions\n let after = true;\n if (pattern[curr] == \"<\") {\n curr++;\n after = false;\n }\n const neg = pattern[curr++] == \"!\";\n const cond = this.parse(curr, clPos - 1);\n if (after) {\n // reduce everything \"until now\" and THEN apply\n if (stack.length == 0) {\n // this.throwError(\"LookAhead condition cannot be before empty rule\");\n }\n // const endIndex = stack.length - 1;\n // stack[endIndex] = new LookAhead(stack[endIndex], cond, neg);\n const expr = new LookAhead(this.reduceLeft(stack), cond, neg);\n stack.push(expr);\n } else {\n // Lookbacks are interesting, we have something like:\n // (?<!...)abcde\n // clPos points to \")\" We need abcde also parsed\n // and then lookback applied to it\n const rest = this.parse(clPos + 1, end);\n if (rest.groupIndex < 0) {\n rest.groupIndex = this.counter.next();\n rest.groupIsSilent = true;\n }\n stack.push(new LookBack(rest, cond, neg));\n return end + 1;\n }\n }\n } else {\n // plain old grouping of the form (xyz)\n const groupIndex = this.counter.next();\n let neg = false;\n if (pattern[curr] == \"^\") {\n neg = true;\n curr++;\n }\n let subExpr = this.parse(curr, clPos - 1);\n // if (neg) subExpr = new Neg(subExpr);\n // Do the next before the previous call if we want group\n // index to match outer brackets first\n if (subExpr.groupIndex >= 0) {\n // Already set so create cat\n subExpr = new Cat(subExpr);\n }\n subExpr.groupIndex = groupIndex;\n stack.push(subExpr);\n }\n return clPos + 1;\n }\n\n protected parseCharGroup(curr: number, end: number): Char {\n const out: Char[] = [];\n // first see which characters are in this (until the end)\n let i = curr;\n let neg = false;\n const pattern = this.pattern;\n if (pattern[i] == \"^\") {\n neg = true;\n i++;\n }\n for (; i <= end; ) {\n const [currch, nchars] = this.parseChar(i, end);\n i += nchars;\n if (i < pattern.length && pattern[i] == \"-\") {\n i++;\n // TODO - Should this be for all such \"operator\" charactors?\n if (pattern[i] == \"]\" || pattern[i] == \"[\") {\n // Special case for something like:\n // [....x-] or [.....x-[:alpha:]]\n out.push(currch);\n out.push(LeafChar.Single(\"-\"));\n } else if (i <= end) {\n const [endch, nchars] = this.parseChar(i, end);\n if (currch.op != CharType.SingleChar || endch.op != CharType.SingleChar) {\n this.throwError(\"Char range cannot start or end in a char class\");\n }\n if (endch.args[0] < currch.args[0]) {\n this.throwError(\"End cannot be less than start\");\n }\n out.push(CharGroup.Range(currch, endch));\n i += nchars;\n } else {\n this.throwError(\"Unterminated char class\");\n }\n } else {\n out.push(currch);\n }\n }\n return CharGroup.Union(neg, out);\n }\n\n protected parseChar(index = 0, end = 0): [LeafChar, number] {\n if (this.pattern[index] == \"\\\\\") {\n return this.parseEscapeChar(index, end);\n } else {\n return this.parseSingleChar(index, end);\n }\n }\n\n protected parseSingleChar(index = 0, end = 0): [LeafChar, number] {\n // single char\n const ch = this.pattern.charCodeAt(index);\n return [LeafChar.Single(ch), 1];\n }\n\n protected parsePropertyEscape(index = 0, end = 0): [LeafChar, number] {\n const pattern = this.pattern;\n if (pattern[index] + 1 != \"{\") {\n this.throwError(\"Invalid property escape\");\n }\n index += 2;\n let clEnd = index;\n let eqPos = -1;\n while (clEnd <= end && pattern[clEnd] != \"}\") {\n if (pattern[clEnd] == \"=\") eqPos = clEnd;\n clEnd++;\n }\n if (clEnd > end) {\n this.throwError(\"Invalid property escape\");\n }\n // see if this is a lone property escape\n const propStr = pattern.substring(index, clEnd);\n let propName = \"General_Category\";\n let propValue = propStr;\n if (eqPos >= 0) {\n const parts = propStr.split(\"=\");\n if (parts.length != 2) this.throwError(\"Invalid property escape\");\n propName = parts[0].trim();\n propValue = parts[1].trim();\n }\n return [LeafChar.PropertyEscape(propName, propValue), 2 + clEnd + 1 - index];\n }\n\n protected parseEscapeChar(index = 0, end = 0): [LeafChar, number] {\n const pattern = this.pattern;\n TSU.assert(pattern[index] == \"\\\\\", \"Expected '\\\\'\");\n // escape char\n index++;\n if (index > end) {\n this.throwError(\"Encounted unexpected end of input after \\\\\");\n }\n const ch = pattern[index];\n if ((this.unicode && ch == \"p\") || ch == \"P\") {\n // property escapes\n return this.parsePropertyEscape(index, end);\n }\n switch (ch) {\n // char classes\n case \"w\":\n return [LeafChar.Class(CharClassType.WORD_CHAR), 2];\n case \"W\":\n return [LeafChar.Class(CharClassType.WORD_CHAR, true), 2];\n case \"d\":\n return [LeafChar.Class(CharClassType.DIGITS), 2];\n case \"D\":\n return [LeafChar.Class(CharClassType.DIGITS, true), 2];\n case \"s\":\n return [LeafChar.Class(CharClassType.SPACES), 2];\n case \"S\":\n return [LeafChar.Class(CharClassType.SPACES, true), 2];\n case \"0\":\n if (pattern[index + 1] >= \"0\" && pattern[index + 1] <= \"9\" && this.unicode) {\n this.throwError(\"Invalid decimal escape\");\n }\n return [LeafChar.Single(\"\\0\"), 2];\n case \"r\":\n return [LeafChar.Single(\"\\r\"), 2];\n case \"n\":\n return [LeafChar.Single(\"\\n\"), 2];\n case \"f\":\n return [LeafChar.Single(\"\\f\"), 2];\n case \"b\":\n return [LeafChar.Single(\"\\b\"), 2];\n case \"v\":\n return [LeafChar.Single(\"\\v\"), 2];\n case \"t\":\n return [LeafChar.Single(\"\\t\"), 2];\n case \"c\":\n // ControlEscape:\n // https://262.ecma-international.org/5.1/#sec-15.10.2.10\n if (this.unicode || index >= end) {\n this.throwError(`Invalid char sequence at ${index}, ${end}`);\n }\n const next = pattern.charCodeAt(index + 1) % 32;\n return [LeafChar.Single(next), 3];\n case \"x\":\n // 2 digit hex digits\n index++;\n if (index >= end) {\n this.throwError(`Invalid hex sequence at ${index}, ${end}`);\n }\n const hexSeq = pattern.substring(index, index + 2);\n const hexVal = parseInt(hexSeq, 16);\n TSU.assert(!isNaN(hexVal), `Invalid hex sequence: '${hexSeq}'`);\n return [LeafChar.Single(hexVal), 4];\n case \"u\": // this could \\uABCD or \\u{ABCDEF}\n index++;\n // 4 digit hex digits for unicode\n if (index > end - 3) {\n this.throwError(`Invalid unicode sequence at ${index}`);\n }\n const ucodeSeq = pattern.substring(index, index + 4);\n const ucodeVal = parseInt(ucodeSeq, 16);\n if (isNaN(ucodeVal)) {\n this.throwError(`Invalid unicode sequence: '${ucodeSeq}'`);\n }\n return [LeafChar.Single(ucodeVal), 6];\n case \"^\": // List of special operators that need to be escaped\n case \"$\":\n case \".\":\n case \"*\":\n case \"+\":\n case \"?\":\n case \"\\\\\":\n case \"'\":\n case '\"':\n case \"(\":\n case \")\":\n case \"[\":\n case \"]\":\n case \"{\":\n case \"}\":\n case \"|\":\n case \"/\":\n return [LeafChar.Single(ch), 2];\n default:\n if (this.unicode) this.throwError(\"Invalid escape character: \" + ch);\n return [LeafChar.Single(ch), 2];\n }\n }\n\n protected parseQuant(stack: Regex[], curr: number, end: number): number {\n const pattern = this.pattern;\n const lastCh = pattern[curr - 1];\n let minCount = 1,\n maxCount = 1;\n if (pattern[curr] == \"*\") {\n minCount = 0;\n maxCount = TSU.Constants.MAX_INT;\n } else if (pattern[curr] == \"+\") {\n minCount = Math.min(minCount, 1);\n maxCount = TSU.Constants.MAX_INT;\n } else if (pattern[curr] == \"?\") {\n minCount = 0;\n maxCount = Math.max(maxCount, 1);\n } else if (pattern[curr] == \"{\") {\n // find the next \"}\"\n const clPos = pattern.indexOf(\"}\", curr + 1);\n if (clPos <= curr || clPos > end) {\n this.throwError(\"Unexpected end of input while looking for '}'\");\n }\n const sub = pattern.substring(curr + 1, clPos).trim();\n const parts = sub.split(\",\").map((x) => parseInt(x.trim()));\n curr = clPos;\n if (parts.length == 1) {\n if (isNaN(parts[0])) {\n if (sub.trim().length > 0) {\n stack.push(new Var(sub.trim()));\n return curr + 1;\n } else {\n this.throwError(`Invalid quantifier: /${sub}/`);\n }\n }\n minCount = maxCount = parts[0];\n } else if (parts.length == 2) {\n minCount = isNaN(parts[0]) ? 0 : parts[0];\n maxCount = isNaN(parts[1]) ? TSU.Constants.MAX_INT : parts[1];\n if (minCount > maxCount) {\n this.throwError(`Invalid Quant /${sub}/: Min must be <= Max`);\n }\n } else if (parts.length > 2) {\n this.throwError(`Invalid quantifier spec: \"{${sub}}\"`);\n }\n } else {\n throw new Error(\"Here?\");\n }\n // Quantifiers\n if (stack.length <= 0) {\n this.throwError(\"Quantifier cannot appear before an expression\");\n }\n // no optimizations - convert the last one into a Quantifier\n // and we will start to fill in the quantities and greediness\n const last = stack[stack.length - 1];\n if (last.tag == RegexType.QUANT && (lastCh == \"*\" || lastCh == \"?\" || lastCh == \"+\" || lastCh == \"}\")) {\n this.throwError(\"Nothing to repeat\");\n }\n if (this.unicode && (last.tag == RegexType.LOOK_AHEAD || last.tag == RegexType.LOOK_BACK)) {\n this.throwError(\"Cannot have quantifier on assertion in unicode mode\");\n }\n const quant = (stack[stack.length - 1] = new Quant(last));\n quant.minCount = minCount;\n quant.maxCount = maxCount;\n // check if there is an extra lazy quantifier\n curr++;\n if (curr <= end && pattern[curr] == \"?\" && quant.greedy) {\n curr++;\n quant.greedy = false;\n }\n return curr;\n }\n}\n","import * as TSU from \"@panyam/tsutils\";\nimport { TapeInterface as Tape } from \"./tape\";\nimport {\n LookAhead,\n Quant,\n RegexType,\n StartOfInput,\n EndOfInput,\n Regex,\n Cat,\n CharType,\n Char,\n LeafChar,\n CharGroup,\n Var,\n Union,\n} from \"./core\";\nimport { CharClassType } from \"./charclasses\";\nimport { GroupCounter, isSpace } from \"./utils\";\n\nfunction advanceIf(tape: Tape, ch: string): boolean {\n const pos = tape.index;\n for (let i = 0; i < ch.length; i++) {\n if (tape.currCh != ch.charAt(i)) {\n tape.index = pos;\n return false;\n }\n tape.advance(1);\n }\n return true;\n}\n\n/**\n * A RegexParser for parsing regex strings in Flex RE format.\n * This class will seldom have to be used directly. Instead use one of the methods in {@link Builder}\n */\nexport class RegexParser {\n protected counter: GroupCounter = new GroupCounter();\n\n parse(pattern: Tape, ignoreSpaces = false, obCount = 0): Regex {\n const stack: Regex[] = [];\n\n while (pattern.hasMore) {\n const currCh = pattern.currCh;\n // see if we have groups so they get highest preference\n if (advanceIf(pattern, \".\")) {\n stack.push(LeafChar.Any());\n } else if (advanceIf(pattern, \"^\")) {\n const x = new StartOfInput();\n x.multiline = true;\n stack.push(x);\n } else if (advanceIf(pattern, \"$\")) {\n const x = new EndOfInput();\n x.multiline = true;\n stack.push(x);\n } else if (advanceIf(pattern, \"|\")) {\n // reduce everything \"until now\" and THEN apply\n const prev = this.reduceLeft(stack);\n // this.parse everything to the right\n const rest = this.parse(pattern, ignoreSpaces, obCount);\n return new Union(prev, rest);\n } else if (currCh == \"[\") {\n stack.push(this.parseCharGroup(pattern));\n } else if (currCh == \"*\" || currCh == \"?\" || currCh == \"+\" || currCh == \"{\") {\n this.parseQuant(pattern, stack);\n } else if (ignoreSpaces && isSpace(currCh)) {\n // do nothing\n pattern.advance(1);\n } else if (ignoreSpaces && advanceIf(pattern, \"/*\")) {\n // Read everything until a */\n while (pattern.currCh != \"*\" || pattern.nextCh != \"/\") {\n if (!pattern.hasMore) {\n this.throwError(pattern, \"Unterminated comment\");\n }\n pattern.advance(1);\n }\n pattern.advance(2);\n // now do nothing\n } else if (advanceIf(pattern, \"{-}\")) {\n // char class intersection\n throw new Error(\"Intersection Not yet supported\");\n } else if (advanceIf(pattern, \"{+}\")) {\n // char class union\n throw new Error(\"Union Not yet supported\");\n } else if (advanceIf(pattern, \"(\")) {\n if (advanceIf(pattern, \"?\")) {\n if (advanceIf(pattern, \"#\")) {\n while (pattern.hasMore && pattern.currCh != \")\") pattern.advance(1);\n TSU.assert(advanceIf(pattern, \")\"), \"Expected ')'\");\n } else {\n // pattern of the form (?r-s:pattern)\n let ignoreCase = false;\n let dotAll = false;\n let ignoreSpaces2 = ignoreSpaces as boolean;\n let neg = false;\n while (pattern.hasMore && pattern.currCh != \":\") {\n if (pattern.currCh == \"i\") {\n ignoreCase = neg ? false : true;\n } else if (pattern.currCh == \"s\") {\n dotAll = neg ? false : true;\n } else if (pattern.currCh == \"x\") {\n ignoreSpaces2 = neg ? false : true;\n } else if (pattern.currCh == \"-\") {\n neg = true;\n }\n pattern.advance(1);\n }\n TSU.assert(advanceIf(pattern, \":\"), \"Expected ':'\");\n const groupIndex = this.counter.next();\n let subExpr = this.parse(pattern, ignoreSpaces2, obCount + 1);\n if (subExpr.groupIndex >= 0) {\n // Already set so create cat\n subExpr = new Cat(subExpr);\n }\n subExpr.dotAll = dotAll;\n subExpr.ignoreCase = ignoreCase;\n subExpr.groupIndex = groupIndex;\n stack.push(subExpr);\n TSU.assert(advanceIf(pattern, \")\"), \"Expected ')'\");\n }\n } else {\n // parse the subgroup and give it a group number\n const groupIndex = this.counter.next();\n let subExpr = this.parse(pattern, ignoreSpaces, obCount + 1);\n if (subExpr.groupIndex >= 0) {\n // Already set so create cat\n subExpr = new Cat(subExpr);\n }\n subExpr.groupIndex = groupIndex;\n stack.push(subExpr);\n TSU.assert(advanceIf(pattern, \")\"), \"Expected ')'\");\n }\n } else if (currCh == \")\") {\n if (obCount == 0) {\n this.throwError(pattern, `Unmatched ${currCh}. Try using \\\\${currCh}`);\n }\n // stop here so we can recurse up\n break;\n } else if (currCh == \"]\" || currCh == \"}\") {\n this.throwError(pattern, `Unmatched ${currCh}. Try using \\\\${currCh}`);\n } else if (advanceIf(pattern, \"/\")) {\n // LookAheads\n const prev = this.reduceLeft(stack);\n // this.parse everything to the right\n const rest = this.parse(pattern, ignoreSpaces, obCount);\n return new LookAhead(prev, rest, false);\n } else if (advanceIf(pattern, '\"')) {\n // raw string\n while (pattern.currCh != '\"') {\n if (!pattern.hasMore) {\n this.throwError(pattern, \"Unterminated string\");\n }\n stack.push(this.parseChar(pattern));\n }\n pattern.advance(1);\n } else {\n // plain old alphabets\n stack.push(this.parseChar(pattern));\n }\n }\n if (stack.length == 1) return stack[0];\n return new Cat(...stack);\n }\n\n protected parseQuant(pattern: Tape, stack: Regex[]): void {\n let minCount = 1,\n maxCount = 1;\n if (advanceIf(pattern, \"*\")) {\n minCount = 0;\n maxCount = TSU.Constants.MAX_INT;\n } else if (advanceIf(pattern, \"+\")) {\n minCount = Math.min(minCount, 1);\n maxCount = TSU.Constants.MAX_INT;\n } else if (advanceIf(pattern, \"?\")) {\n minCount = 0;\n maxCount = Math.max(maxCount, 1);\n } else if (advanceIf(pattern, \"{\")) {\n let foundComma = false;\n let p1 = \"\";\n let p2 = \"\";\n while (pattern.hasMore && pattern.currCh != \"}\") {\n if (pattern.currCh == \",\") foundComma = true;\n else {\n if (!foundComma) p1 += pattern.currCh;\n else p2 += pattern.currCh;\n }\n pattern.advance(1);\n }\n if (!pattern.hasMore) {\n this.throwError(pattern, \"Invalid property escape\");\n }\n // see if this is a lone property escape\n p1 = p1.trim();\n p2 = p2.trim();\n // advance over the \"}\"\n pattern.advance(1);\n\n const part1 = parseInt(p1);\n const part2 = parseInt(p2);\n if (foundComma) {\n minCount = isNaN(part1) ? 0 : part1;\n maxCount = isNaN(part2) ? TSU.Constants.MAX_INT : part2;\n if (minCount > maxCount) {\n this.throwError(pattern, `Invalid Quant /${p1},${p2}/: Min must be <= Max`);\n }\n } else {\n if (isNaN(part1)) {\n if (p1.length > 0) {\n stack.push(new Var(p1));\n // nothing more\n return;\n } else {\n this.throwError(pattern, `Invalid quantifier: /${p1}/`);\n }\n minCount = maxCount = 1;\n } else {\n minCount = maxCount = part1;\n }\n }\n } else {\n this.throwError(pattern, \"Expected '{', '*', '?' or '+', Found: \" + pattern.currCh);\n }\n // Quantifiers\n if (stack.length <= 0) {\n this.throwError(pattern, \"Quantifier cannot appear before an expression\");\n }\n // no optimizations - convert the last one into a Quantifier\n // and we will start to fill in the quantities and greediness\n const last = stack[stack.length - 1];\n let quant: Quant;\n if (last.tag == RegexType.QUANT && last.groupIndex < 0) {\n // Fold repeated quants unless they are not in a group\n quant = last as Quant;\n quant.minCount = Math.min(minCount, quant.minCount);\n quant.maxCount = Math.max(maxCount, quant.maxCount);\n } else {\n quant = stack[stack.length - 1] = new Quant(last);\n quant.minCount = minCount;\n quant.maxCount = maxCount;\n }\n // check if there is an extra lazy quantifier\n if (quant.greedy && advanceIf(pattern, \"?\")) {\n quant.greedy = false;\n }\n }\n\n protected parseCharGroup(pattern: Tape): Char {\n const out: Char[] = [];\n TSU.assert(advanceIf(pattern, \"[\"), \"Expected '['\");\n // first see which characters are in this (until the end)\n const neg = advanceIf(pattern, \"^\");\n while (pattern.currCh != \"]\") {\n const currch = this.parseChar(pattern);\n if (advanceIf(pattern, \"-\")) {\n if (pattern.hasMore) {\n // TODO - Should this be for all such \"operator\" charactors?\n if (pattern.currCh == \"]\" || pattern.currCh == \"[\") {\n // Special case for something like:\n // [....x-] or [.....x-[:alpha:]]\n out.push(currch);\n out.push(LeafChar.Single(\"-\"));\n } else {\n const endch = this.parseChar(pattern);\n if (currch.op != CharType.SingleChar || endch.op != CharType.SingleChar) {\n this.throwError(pattern, \"Char range cannot start or end in a char class\");\n }\n if (endch.args[0] < currch.args[0]) {\n this.throwError(pattern, \"End cannot be less than start\");\n }\n // currch.end = endch.start;\n out.push(CharGroup.Range(currch, endch));\n }\n } else {\n this.throwError(pattern, \"Unterminated char class\");\n }\n } else {\n out.push(currch);\n }\n }\n TSU.assert(advanceIf(pattern, \"]\"), \"']' expected\");\n return CharGroup.Union(neg, out);\n }\n\n protected parseChar(pattern: Tape): LeafChar {\n if (pattern.currCh == \"\\\\\") {\n return this.parseEscapeChar(pattern);\n } else {\n return this.parseSingleChar(pattern);\n }\n }\n\n protected parseSingleChar(pattern: Tape): LeafChar {\n // single char\n const ch = pattern.currCh;\n pattern.advance(1);\n return LeafChar.Single(ch);\n }\n\n protected parsePropertyEscape(pattern: Tape): LeafChar {\n TSU.assert(advanceIf(pattern, \"\\\\{\"), \"Invalid property escape\");\n pattern.advance(2);\n let foundEq = false;\n let propName = \"\";\n let propValue = \"\";\n while (pattern.hasMore && pattern.currCh != \"}\") {\n if (pattern.currCh == \"=\") foundEq = true;\n else {\n if (!foundEq) propName += pattern.currCh;\n else propValue += pattern.currCh;\n }\n pattern.advance(1);\n }\n if (!pattern.hasMore) {\n this.throwError(pattern, \"Invalid property escape\");\n }\n // see if this is a lone property escape\n propName = propName.trim();\n propValue = propValue.trim();\n if (!foundEq) {\n propValue = propName;\n propName = \"General_Category\";\n }\n // advance over the \"}\"\n pattern.advance(1);\n return LeafChar.PropertyEscape(propName, propValue);\n }\n\n protected parseEscapeChar(pattern: Tape): LeafChar {\n TSU.assert(advanceIf(pattern, \"\\\\\"), \"Expected '\\\\'\");\n // escape char\n if (!pattern.hasMore) {\n this.throwError(pattern, \"Encounted unexpected end of input after \\\\\");\n }\n if (advanceIf(pattern, \"w\")) {\n return LeafChar.Class(CharClassType.WORD_CHAR);\n } else if (advanceIf(pattern, \"W\")) {\n return LeafChar.Class(CharClassType.WORD_CHAR, true);\n } else if (advanceIf(pattern, \"d\")) {\n return LeafChar.Class(CharClassType.DIGITS);\n } else if (advanceIf(pattern, \"D\")) {\n return LeafChar.Class(CharClassType.DIGITS, true);\n } else if (advanceIf(pattern, \"s\")) {\n return LeafChar.Class(CharClassType.SPACES);\n } else if (advanceIf(pattern, \"S\")) {\n return LeafChar.Class(CharClassType.SPACES, true);\n } else if (advanceIf(pattern, \"0\")) {\n return LeafChar.Single(\"\\0\");\n } else if (advanceIf(pattern, \"r\")) {\n return LeafChar.Single(\"\\r\");\n } else if (advanceIf(pattern, \"n\")) {\n return LeafChar.Single(\"\\n\");\n } else if (advanceIf(pattern, \"f\")) {\n return LeafChar.Single(\"\\f\");\n } else if (advanceIf(pattern, \"b\")) {\n return LeafChar.Single(\"\\b\");\n } else if (advanceIf(pattern, \"v\")) {\n return LeafChar.Single(\"\\v\");\n } else if (advanceIf(pattern, \"t\")) {\n return LeafChar.Single(\"\\t\");\n } else if (advanceIf(pattern, \"\\\\\")) {\n return LeafChar.Single(\"\\\\\");\n } else if (advanceIf(pattern, \"'\")) {\n return LeafChar.Single(\"'\");\n } else if (advanceIf(pattern, '\"')) {\n return LeafChar.Single('\"');\n } else if (advanceIf(pattern, \"x\")) {\n // 2 digit hex digits\n if (!pattern.hasMore) {\n this.throwError(pattern, `Invalid hex sequence at ${pattern.index}`);\n }\n const hexSeq = pattern.currCh + pattern.nextCh;\n const hexVal = parseInt(hexSeq, 16);\n TSU.assert(!isNaN(hexVal), `Invalid hex sequence: '${hexSeq}'`);\n pattern.advance(2);\n return LeafChar.Single(hexVal);\n } else if (advanceIf(pattern, \"u\")) {\n // 4 digit hex digits for unicode\n if (!pattern.canAdvance(3)) {\n // index >= pattern.input.length - 3) {\n this.throwError(pattern, `Invalid unicode sequence at ${pattern.index}`);\n }\n const ucodeSeq = pattern.substring(pattern.index, pattern.index + 4);\n const ucodeVal = parseInt(ucodeSeq, 16);\n if (isNaN(ucodeVal)) {\n this.throwError(pattern, `Invalid unicode sequence: '${ucodeSeq}'`);\n }\n pattern.advance(4);\n return LeafChar.Single(ucodeVal);\n }\n // default\n const ch = pattern.currCh;\n pattern.advance(1);\n return LeafChar.Single(ch);\n }\n\n protected reduceLeft(stack: Regex[]): Regex {\n const r = stack.length == 1 ? stack[0] : new Cat(...stack);\n // remove all elements on stack\n stack.splice(0);\n return r;\n }\n\n protected throwError(pattern: Tape, msg: string): void {\n throw new Error(msg);\n // this.throwError(pattern, `Error in Flex RE '${pattern.input}': ${msg}`);\n }\n}\n","import { Rule, Regex, REPatternType } from \"./core\";\nimport { RegexParser as JSREParser } from \"./jsparser\";\nimport { RegexParser as FlexREParser } from \"./flexparser\";\nimport { Tape } from \"./tape\";\n\n/**\n * Uber method to build a Regex given either a regex string or a JS regex.\n *\n * @param pattern Either a regex pattern, a JS RegExp object, or an already parsed Regex object.\n * @param config TBD\n *\n * @return A {@link Rule} object that contains the pattern as well as its normalized regex tree.\n */\nexport function build(pattern: string | RegExp | Regex, config?: any): Rule {\n if (typeof pattern === \"string\") {\n const rule = new Rule(exprFromJSRE(pattern, config), config);\n rule.pattern = pattern;\n return rule;\n } else if (pattern.constructor.name == \"RegExp\") {\n const rule = new Rule(exprFromJSRE(pattern as RegExp, config), config);\n rule.pattern = (pattern as RegExp).source;\n return rule;\n } else {\n // Already compiled expression\n return new Rule(pattern as Regex, config);\n }\n}\n\n/*\nexport function fromRE(pattern: string, config?: any): Rule {\n const expr = new JSREParser(pattern, config).parse();\n const rule = new Rule(expr, config);\n rule.pattern = pattern;\n return rule;\n}\n\nexport function fromJSRE(re: RegExp, config?: any): Rule {\n const expr = exprFromJSRE(re);\n const rule = new Rule(expr, config);\n rule.pattern = re.source;\n return rule;\n}\n\nexport function fromFlexRE(re: string, config?: any): Rule {\n const expr = exprFromFlexRE(re);\n const rule = new Rule(expr, config);\n rule.pattern = re;\n return rule;\n}\n*/\n\n/**\n * \"Flattens\" either a single REPatternType or a list of REPatternTypes into a flat list of all\n * REPatternTypes at the leaf levels.\n */\nexport function flatten(re: REPatternType | REPatternType[], index = 0, rules?: Rule[]): Rule[] {\n rules = rules || [];\n if (typeof re === \"string\") {\n rules.push(build(re, { tag: index }));\n } else if (re.constructor == RegExp) {\n rules.push(build(re, { tag: index }));\n } else if (re.constructor == Rule) {\n rules.push(re as Rule);\n } else if (re.constructor == Regex) {\n rules.push(new Rule(re as Regex));\n } else {\n const res = re as (RegExp | Rule | string)[];\n for (let i = 0; i < res.length; i++) {\n flatten(res[i], i, rules);\n }\n }\n return rules;\n}\n\n/**\n * Takes a string assumed to be in Flex RE format and parses the Regex expression out of it.\n */\nexport function exprFromFlexRE(pattern: string): Regex {\n const parser = new FlexREParser();\n try {\n const expr = parser.parse(new Tape(pattern));\n // if not specified default to false\n if (expr.dotAll == null) expr.dotAll = false;\n if (expr.multiline == null) expr.multiline = false;\n return expr;\n } catch (error) {\n console.log(\"Error in FLEX RE: \", pattern);\n throw error;\n }\n}\n\n/**\n * Takes a string assumed to be in JS RE format and parses the Regex expression out of it.\n */\nexport function exprFromJSRE(re: string | RegExp, config?: any): Regex {\n config = config || {};\n const isRegExp = typeof re !== \"string\";\n const pattern = typeof re === \"string\" ? re : re.source;\n if (isRegExp) config.unicode = (re as RegExp).unicode;\n const expr = new JSREParser(pattern, config).parse();\n if (typeof re !== \"string\") {\n expr.dotAll = re.dotAll;\n expr.ignoreCase = re.ignoreCase;\n expr.multiline = re.multiline;\n }\n return expr;\n}\n\n/**\n * A way to build a JS RE from a string literal, eg: jsRE`a*b+`\n */\nexport function jsRE(strings: TemplateStringsArray, ...keys: any[]): Regex {\n // what we have is the raw value of this template and this can be parsed by our parser\n const merged = String.raw(strings, ...keys);\n return exprFromJSRE(merged);\n}\n\n/**\n * A way to build a Flex RE from a string literal, eg: flexRE`a*b+`\n */\nexport function flexRE(strings: TemplateStringsArray, ...keys: any[]): Regex {\n const merged = String.raw(strings, ...keys);\n return exprFromFlexRE(merged);\n}\n","import * as TSU from \"@panyam/tsutils\";\nimport { Regex, Union, Rule, RuleConfig } from \"./core\";\nimport { Prog, Match, VM } from \"./vm\";\nimport { Compiler } from \"./compiler\";\nimport { TapeInterface as Tape, Tape as DefaultTape } from \"./tape\";\nimport { TokenizerError } from \"./errors\";\nimport * as Builder from \"./builder\";\nimport { Token, TokenType } from \"./token\";\n\nexport type RuleMatchHandler = (rule: Rule, tape: Tape, token: Token, owner: any) => any;\nexport type TokenizerErrorHandler = (error: Error, tape: Tape, startIndex: number) => Error | null;\n\nexport function toToken(tag: TokenType, m: Match, tape: Tape | null): Token {\n const out = new Token(tag, m.matchIndex, m.start, m.end);\n for (let i = 0; i < m.positions.length; i += 2) {\n if (m.positions[i] >= 0) {\n out.positions[Math.floor(i / 2)] = [m.positions[i], m.positions[i + 1]];\n }\n }\n for (const [groupIndex, tapeIndex] of m.groups) {\n const gi = Math.abs(groupIndex);\n if (!(gi in out.groups)) {\n out.groups[gi] = [];\n }\n out.groups[gi].push(tapeIndex);\n }\n if (tape != null) out.value = tape.substring(m.start, m.end);\n return out;\n}\n\nexport class BaseTokenizer {\n protected _prog: Prog | null = null;\n protected _vm: VM | null = null;\n\n /**\n * Error handler called when an invalid character or lexeme is encountered.\n * If this method returns back an error then the tokenization stops otherwise\n * (if a null is returned) then tokenization continues.\n *\n * @param error The error currently caught and being handled.\n * @param tape The tape currently being tokenized.\n * @param startIndex The start index when the tokenization began resulting in the error.\n */\n onError: TokenizerErrorHandler | null = null;\n\n // Stores named rules\n // Rules are a \"regex\", whether literal or not\n allRules: Rule[] = [];\n onMatchHandlers: (RuleMatchHandler | null)[] = [];\n matchHandlersByValue: any = {};\n variables = new Map<string, Regex>();\n compiler: Compiler = new Compiler((name) => {\n let out = this.variables.get(name) || null;\n if (out == null) out = this.findRuleByValue(name)?.expr || null;\n if (out == null) throw new Error(`Invalid regex reference: ${name}`);\n return out;\n });\n\n getVar(name: string): Regex | null {\n return this.variables.get(name) || null;\n }\n\n addVar(name: string, regex: Regex): this {\n let currValue = this.variables.get(name) || null;\n if (currValue == null) {\n currValue = regex;\n } else {\n currValue = new Union(currValue, regex);\n }\n this.variables.set(name, regex);\n return this;\n }\n\n findRuleByValue(value: any): Rule | null {\n return this.allRules.find((r) => r.tag == value) || null;\n }\n\n /**\n * Helper method over the addRule method that converts the pattern to its normalized expression form\n * and adds a rule to the tokenizer.\n *\n * @param pattern A raw string or a JS RegExp, or parsed Regex expression\n * (either from JS or Flex RE syntax).\n * @param config Rule configs to control priority and other aspects of rules to be used during\n * the match stage.\n * @param onMatch A callback method called when the rule is matched.\n */\n add(\n pattern: string | RegExp | Regex,\n config?: RuleConfig | RuleMatchHandler | null,\n onMatch: RuleMatchHandler | null = null,\n ): this {\n if (typeof config === \"function\") {\n onMatch = config;\n config = null;\n }\n return this.addRule(Builder.build(pattern, config), onMatch);\n }\n\n /**\n * Helper method over the addRule method that converts the pattern to its normalized expression form\n * and adds a rule to the tokenizer.\n *\n * @param rule A normalized Rule object that contains both the pattern as well as rule configs\n * to be used during the match and afterwards (if successfully matched).\n * @param onMatch A callback method called when the rule is matched.\n */\n addRule(rule: Rule, onMatch: null | RuleMatchHandler = null): this {\n rule.matchIndex = this.allRules.length;\n this.allRules.push(rule);\n this.onMatchHandlers.push(onMatch);\n this._prog = null;\n this._vm = null;\n return this;\n }\n\n /**\n * Add a token match callback by value.\n */\n on(tag: any, onMatch: RuleMatchHandler): this {\n this.matchHandlersByValue[tag] = onMatch;\n return this;\n }\n\n get prog(): Prog {\n if (this._prog == null) {\n const sortedRules = this.sortRules();\n this._prog = this.compiler.compile(sortedRules);\n }\n return this._prog;\n }\n\n get vm(): VM {\n if (this._vm == null) {\n this._vm = new VM(this.prog);\n }\n return this._vm;\n }\n\n protected sortRules(): Rule[] {\n // Sort rules so high priority ones appear first\n const sortedRules: Rule[] = this.allRules.map((rule) => rule);\n sortedRules.sort((r1, r2) => {\n if (r1.priority != r2.priority) return r2.priority - r1.priority;\n return r1.matchIndex - r2.matchIndex;\n });\n return sortedRules;\n }\n}\n\n/**\n * A batch tokenizer.\n */\nexport class Tokenizer extends BaseTokenizer {\n idCounter = 0;\n\n /**\n * Get the current lexer state (for incremental lexing support).\n * State is used to track context-sensitive lexing modes.\n */\n getState(): number {\n return this.vm.getState();\n }\n\n /**\n * Set the lexer state (for incremental lexing support).\n * Allows restarting lexing from a saved state.\n */\n setState(state: number): void {\n this.vm.setState(state);\n }\n\n /**\n * Reset the tokenizer state. Useful for incremental lexing\n * when restarting from a different position.\n */\n reset(): void {\n this.idCounter = 0;\n // Reset VM state to initial\n if (this._vm) {\n this._vm.setState(0);\n }\n }\n\n next(tape: Tape, owner: any): Token | null {\n if (!tape.hasMore) {\n return null;\n }\n const startIndex = tape.index;\n const startChar = tape.currCh;\n const m = this.vm.match(tape);\n if (m == null) {\n // no match so we have an error\n let err: Error | null = null;\n if (tape.index == startIndex + 1) {\n err = new TokenizerError(`Unexpected Character: ${startChar}`, startIndex, 1, \"UnexpectedCharacter\", startChar);\n } else {\n err = new TokenizerError(\n `Unexpected Symbol: ${tape.substring(startIndex, tape.index)}`,\n startIndex,\n tape.index - startIndex,\n \"UnexpectedLexeme\",\n );\n }\n if (this.onError) {\n err = this.onError(err, tape, startIndex);\n }\n if (err != null) {\n throw err;\n } else {\n // err has been ocnsumed so we can restart tokenizer at the current position\n return this.next(tape, owner);\n }\n }\n const rule = this.allRules[m.matchIndex];\n let token = toToken(rule.tag, m, tape);\n token.id = this.idCounter++;\n let onMatch = this.onMatchHandlers[m.matchIndex];\n if (!onMatch) {\n onMatch = this.matchHandlersByValue[rule.tag];\n }\n if (onMatch) {\n token = onMatch(rule, tape, token, owner);\n if (token == null) {\n // null is returned by onMatch to skip tokens\n return this.next(tape, owner);\n }\n } else if (rule.skip) {\n return this.next(tape, owner);\n }\n return token;\n }\n\n tokenize(tape: string | Tape, owner: any = null): Token[] {\n const tokens = [] as Token[];\n if (typeof tape === \"string\") {\n tape = new DefaultTape(tape);\n }\n let next = this.next(tape, owner);\n while (next) {\n tokens.push(next);\n try {\n next = this.next(tape, owner);\n } catch (err: any) {\n tokens.push({\n tag: \"ERROR\",\n start: err.offset,\n end: err.offset + err.length,\n value: err.message,\n } as Token);\n break;\n }\n }\n return tokens;\n }\n}\n","import { flexRE } from \"./builder\";\n\nexport const SINGLE_QUOTE_STRING = flexRE`[\"]([^\"\\\\\\n]|\\\\.|\\\\\\n)*[\"]`;\nexport const DOUBLE_QUOTE_STRING = flexRE`[']([^'\\\\\\n]|\\\\.|\\\\\\n)*[']`;\nexport const SIMPLE_JS_STRING = '\"(.*?(?<!\\\\\\\\))\"';\nexport const JS_REGEX_WITHOUT_LB = String.raw`/([^\\\\/]|\\\\.)*/([imus]*)`;\nexport const JS_REGEX = String.raw`/(.+?(?<!\\\\))/([imus]*)`;\n","import * as TSU from \"@panyam/tsutils\";\nimport * as TLEX from \"tlex\";\nimport { Sym, Grammar, Str, Rule, RuleAction } from \"./grammar\";\n\ntype Tape = TLEX.TapeInterface;\n\nconst str2regex = (s: string | number): string => {\n if (typeof s === \"number\") return \"\" + s;\n return s.replace(/[\\-\\[\\]\\/\\{\\}\\(\\)\\*\\+\\?\\.\\\\\\^\\$\\|]/g, \"\\\\$&\");\n};\n\nexport enum TokenType {\n STRING = \"STRING\",\n REGEX = \"REGEX\",\n NUMBER = \"NUMBER\",\n SPACES = \"SPACES\",\n IDENT = \"IDENT\",\n PCT_IDENT = \"PCT_IDENT\",\n STAR = \"STAR\",\n PLUS = \"PLUS\",\n QMARK = \"QMARK\",\n PIPE = \"PIPE\",\n DOLLAR_NUM = \"DOLLAR_NUM\",\n DOLLAR_IDENT = \"DOLLAR_IDENT\",\n OPEN_PAREN = \"OPEN_PAREN\",\n CLOSE_PAREN = \"CLOSE_PAREN\",\n OPEN_BRACE = \"OPEN_BRACE\",\n CLOSE_BRACE = \"CLOSE_BRACE\",\n OPEN_SQ = \"OPEN_SQ\",\n CLOSE_SQ = \"CLOSE_SQ\",\n COMMENT = \"COMMENT\",\n ARROW = \"ARROW\",\n COLCOLHYPHEN = \"COLCOLHYPHEN\",\n COLON = \"COLON\",\n SEMI_COLON = \"SEMI_COLON\",\n}\n\nexport type NewSymbolCallback = TSU.Nullable<(label: string, assumedTerminal: boolean) => Sym | void>;\nexport type TokenHandler = (token: TLEX.Token, tape: TLEX.TapeInterface, owner: any) => TLEX.Token | null;\n\nexport interface LoaderConfig {\n grammar?: Grammar;\n leftRecursive?: boolean;\n newSymbolCallback?: NewSymbolCallback;\n tokenHandlers: TSU.StringMap<TokenHandler>;\n debug?: string;\n}\n\n/**\n * Entry point in loading a grammar from a DSL spec.\n */\nexport function load(input: string, params?: LoaderConfig): [Grammar, null | TLEX.NextTokenFunc] {\n params = params || ({} as LoaderConfig);\n const g = new Grammar(params.grammar || {});\n const eparser = new Loader(input, { ...params, grammar: g });\n // g.augmentStartSymbol();\n const tokenFunc = eparser.generatedTokenizer.next.bind(eparser.generatedTokenizer);\n const debug = params.debug || \"\";\n if (debug.split(\"|\").findIndex((p: string) => p == \"all\" || p == \"lexer\") >= 0) {\n console.log(\"Prog: \\n\", `${eparser.generatedTokenizer.vm.prog.debugValue().join(\"\\n\")}`);\n }\n return [g, tokenFunc];\n}\n\n/**\n * The SemanticHandler is the bridge between the DSL, the Grammar, the Parser\n * and the caller of the parser.\n * In the DSL semantic actions can be added to tokenizer and grammar specs.\n * However the problem how to invoke them during runtime.\n *\n * For example in the grammar:\n *\n * E -> E + E { add($1, $3) }\n *\n * declares that when this rule is reduced the \"add\" function (in user land) is\n * invoked with the results of the right hand side values.\n *\n * This parsing however is done by the DSL loader and at this time the \"add\" method\n * is not declared anywhere. In fact the the declaration is only used by the parser\n * driver (after the parse tables have been constructed and parsing is started on\n * a real input). The parser here needs to supply the definition for \"add\" method.\n * Note only this only the parser can call what is needed to kick off the \"add\" method\n * to be invoked.\n *\n * So the parser will need something like:\n *\n * while (input) {\n * ....\n * reduceRule(Nt, E1, E2, E3 ..., \"action\")\n * }\n *\n * the \"action\" will be part of the SemanticHandler\n *\n * reduceRule(Nt...., \"action\") {\n * Nt.value = semanticHandler.getAction(\"action\").apply(E1, E2...., En);\n * }\n *\n * Similarly the caller of the \"parse\" method could populate the actions, eg:\n *\n * semanticHandler.register(\"action\", (a, b, c) => {\n * return ....;\n * });\n *\n * The DSL loader in turn returns a semanticHandler instance just the way it\n * creates a tokenizer.\n *\n * There are a couple of options here.\n *\n * 1. Keep actions simple and store action IDs and let the caller do all the work, eg:\n *\n * E -> E + E { add $1 $3 }\n *\n * 2. Provide a stronger expression syntax:\n *\n * Or we could add a slightly more functional syntax so that a proper interpreter like setup is possible, eg:\n *\n * E -> E + E { add(halve($1), double($3)) }\n *\n * Here instead of calling an action \"add\" we could actually store expression trees and call an interpreter\n * with attribute value bindings.\n *\n * For now we will go with (1) as it is simpler and we can always build up (2) if doing (1) alone is too verbose.\n *\n * With (1), syntax for semantic actions is:\n *\n * SemAction -> \"{\" ActionSpec \"}\" ;\n *\n * ActionSpec -> DOLLAR_NUM\n * | IDENT ( IDENT | DOLLAR_NUM | NUM | STRING | BOOLEAN | NULL ) *\n * ;\n *\n * 3. There is an evern simpler third option. Instead of the parser trying to martial parameters etc it could just\n * let the handler do the work of martialling/extracting parameters from children. This is effective and easy\n *\n * In this mode all child nodes are passed as is to the handler and it is upto the handler to return the semantic\n * value of the production.\n */\n\nexport function Tokenizer(): TLEX.Tokenizer {\n const lexer = new TLEX.Tokenizer();\n lexer.add(/->/, { tag: TokenType.ARROW });\n lexer.add(/\\[/, { tag: TokenType.OPEN_SQ });\n lexer.add(/\\]/, { tag: TokenType.CLOSE_SQ });\n lexer.add(/\\(/, { tag: TokenType.OPEN_PAREN });\n lexer.add(/\\)/, { tag: TokenType.CLOSE_PAREN });\n lexer.add(/\\{/, { tag: TokenType.OPEN_BRACE });\n lexer.add(/\\}/, { tag: TokenType.CLOSE_BRACE });\n lexer.add(/\\*/, { tag: TokenType.STAR });\n lexer.add(/\\+/, { tag: TokenType.PLUS });\n lexer.add(/\\?/, { tag: TokenType.QMARK });\n lexer.add(/;/, { tag: TokenType.SEMI_COLON });\n lexer.add(/:/, { tag: TokenType.COLON });\n lexer.add(/\\|/, { tag: TokenType.PIPE });\n lexer.add(/\\s+/m, { tag: TokenType.SPACES }, () => null);\n lexer.add(/\\/\\*.*?\\*\\//s, { tag: TokenType.COMMENT }, () => null);\n lexer.add(/\\/\\/.*$/m, { tag: TokenType.COMMENT }, () => null);\n lexer.add(TLEX.Samples.DOUBLE_QUOTE_STRING, { tag: TokenType.STRING }, (rule, tape, token) => {\n token.value = tape.substring(token.start + 1, token.end - 1);\n return token;\n });\n lexer.add(TLEX.Samples.SINGLE_QUOTE_STRING, { tag: TokenType.STRING }, (rule, tape, token) => {\n token.value = tape.substring(token.start + 1, token.end - 1);\n return token;\n });\n lexer.add(TLEX.Samples.JS_REGEX, { tag: TokenType.REGEX }, (rule, tape, token) => {\n const pattern = tape.substring(token.positions[1][0], token.positions[1][1]);\n const flags = tape.substring(token.positions[3][0], token.positions[3][1]);\n token.value = [pattern, flags];\n return token;\n });\n lexer.add(/\\d+/, { tag: TokenType.NUMBER }, (rule, tape, token) => {\n token.value = parseInt(tape.substring(token.start, token.end));\n return token;\n });\n lexer.add(/%([\\w][\\w\\d_]*)/, { tag: TokenType.PCT_IDENT }, (rule, tape, token) => {\n token.value = tape.substring(token.start + 1, token.end);\n return token;\n });\n lexer.add(/\\$\\d+/, { tag: TokenType.DOLLAR_NUM }, (rule, tape, token) => {\n token.value = parseInt(tape.substring(token.start + 1, token.end));\n return token;\n });\n lexer.add(/\\$([\\w][\\w\\d_]*)/, { tag: TokenType.DOLLAR_IDENT }, (rule, tape, token) => {\n token.value = tape.substring(token.start + 1, token.end);\n return token;\n });\n lexer.add(/[\\w][\\w\\d_]*/, { tag: TokenType.IDENT });\n return lexer;\n}\n\nexport enum NodeType {\n GRAMMAR = \"GRAMMAR\",\n DECL = \"DECL\",\n RULE = \"RULE\",\n PROD_NULL = \"PROD_NULL\",\n PROD_STR = \"PROD_STR\",\n PROD_UNION = \"PROD_UNION\",\n PROD_NAME = \"PROD_NAME\",\n PROD_STRING = \"PROD_STRING\",\n PROD_NUM = \"PROD_NUM\",\n PROD_IDENT = \"PROD_IDENT\",\n PROD_STAR = \"PROD_STAR\",\n PROD_PLUS = \"PROD_PLUS\",\n PROD_OPTIONAL = \"PROD_OPTIONAL\",\n IDENT = \"IDENT\",\n ERROR = \"ERROR\",\n COMMENT = \"COMMENT\",\n}\n\n/**\n * EBNF Grammar:\n *\n * grammar -> rules;\n *\n * decl -> rule ;\n *\n * rules -> rule | rule rules ;\n *\n * rule -> IDENT \"->\" top_productions \";\" ;\n *\n * top_productions -> ( actionSpec ) ?\n * | prod ( actionSpec ) ? top_productions\n * ;\n *\n * productions ->\n * | prod \"|\" productions\n * ;\n *\n * prod -> ( prod_group | optional_prod | IDENT ( \":\" name ) ? | STRING ) ( \"*\" | \"+\" | \"?\" ) ?\n * ;\n *\n * prod_group -> \"(\" productions \")\" ;\n *\n * optional_prod -> \"[\" productions \"]\" ;\n *\n * actionSpec := \"{\" IDENT \"(\" IDENT ( \",\" IDENT ) * \")\" \"}\"\n */\nexport class Loader {\n readonly grammar: Grammar;\n private tokenizer: TLEX.TokenBuffer;\n private leftRecursive = false;\n readonly generatedTokenizer: TLEX.Tokenizer = new TLEX.Tokenizer();\n tokenHandlers: TSU.StringMap<TokenHandler>;\n\n /*\n * The newSymbol callback provided to the contructor is a way for the client to\n * be given a chance to create a symbol given a new label that is encountered.\n * The client can either return a null to let this parser define the Symbol\n * or return a Symbol which will be associated with the given label going\n * forward.\n *\n * The newSymbol callback will ONLY be called once for each new label\n * encountered by the parser. If the client returns a duplicte symbol\n * then parsing fails.\n */\n private newSymbolCallback: NewSymbolCallback;\n private symbolsByLabel: TSU.StringMap<Sym>;\n\n /**\n * Allowed regex syntaxes - js or flex\n */\n private regexSyntax = \"js\";\n\n constructor(input: string, config?: LoaderConfig) {\n config = config || ({} as LoaderConfig);\n this.symbolsByLabel = {};\n this.grammar = config.grammar || new Grammar();\n this.leftRecursive = \"leftRecursive\" in config ? config.leftRecursive || false : true;\n this.newSymbolCallback = config.newSymbolCallback || null;\n this.tokenHandlers = config.tokenHandlers || {};\n this.parse(input);\n }\n\n /**\n * As the parser creates encounters a new literal or an identifier (hinting at\n * either a terminal or a non terminal), it needs to know which symbol to associate\n * with this lit/ident going forward.\n *\n * All symbols created for the grammar, since they are either created\n * by this parser or by the client (invokved by this parser), are\n * stored locally to be returned in this method.\n */\n symbolForLabel(label: string): TSU.Nullable<Sym> {\n return this.symbolsByLabel[label] || null;\n }\n\n /**\n * Registers a symbol for a given label.\n */\n registerSymbol(label: string, sym: Sym): void {\n TSU.assert(!(label in this.symbolsByLabel), `${label} is already registered`);\n this.symbolsByLabel[label] = sym;\n }\n\n /**\n * Ensures that a symbol exists for a given label (as found in the parser spec)\n * to be used through out the grammar.\n */\n ensureSymbol(label: string, assumedTerminal: boolean): Sym {\n let currSym = this.symbolForLabel(label);\n\n if (currSym != null) return currSym;\n else if (this.newSymbolCallback) {\n // then give the user a chance to create a symbol for this\n currSym = this.newSymbolCallback(label, assumedTerminal) || null;\n }\n if (currSym == null) {\n if (assumedTerminal) {\n currSym = this.grammar.newTerm(label);\n } else {\n currSym = this.grammar.newNT(label);\n }\n }\n // then register it so it is used going forward\n this.registerSymbol(label, currSym);\n return currSym;\n }\n\n parse(input: string): void {\n const et = Tokenizer();\n const ntFunc = (tape: Tape, owner: any) => {\n const out = et.next(tape, this);\n return out;\n };\n this.tokenizer = new TLEX.TokenBuffer(ntFunc, this);\n this.parseGrammar(new TLEX.Tape(input));\n }\n\n parseRegex(tape: TLEX.TapeInterface, tag?: string, priority = 0, syntax = \"\"): TLEX.Rule {\n if (syntax == \"\") syntax = this.regexSyntax;\n if (syntax == \"js\") {\n const tokPattern = this.tokenizer.expectToken(tape, TokenType.STRING, TokenType.NUMBER, TokenType.REGEX);\n let rule: TLEX.Rule;\n if (!tag || tag.length == 0) {\n tag = \"/\" + tokPattern.value[0] + \"/\" + tokPattern.value[1];\n }\n if (tokPattern.tag == TokenType.STRING || tokPattern.tag == TokenType.NUMBER) {\n const pattern = str2regex(tokPattern.value);\n rule = TLEX.Builder.build(pattern, { tag: tag, priority: priority + 20 });\n } else if (tokPattern.tag == TokenType.REGEX) {\n let re = tokPattern.value[0];\n if (tokPattern.value[1].length > 0) {\n // Flags given so create\n re = new RegExp(tokPattern.value[0], tokPattern.value[1]);\n }\n rule = TLEX.Builder.build(re, { tag: tag, priority: priority + 10 });\n } else {\n throw new TLEX.UnexpectedTokenError(tokPattern);\n }\n return rule;\n } else {\n // Flex style RE - no delimiters - just read until end of line and strip spaces\n let patternStr = \"\";\n while (tape.hasMore && tape.currCh != \"\\n\") {\n patternStr += tape.currCh;\n tape.advance();\n }\n patternStr = patternStr.trim();\n if (!tag || tag.length == 0) {\n tag = \"/\" + patternStr + \"/\";\n }\n return new TLEX.Rule(TLEX.Builder.exprFromFlexRE(patternStr), { tag: tag, priority: priority });\n }\n }\n\n parseGrammar(tape: TLEX.Tape): void {\n let peeked = this.tokenizer.peek(tape);\n while (peeked != null) {\n if (peeked.tag == TokenType.IDENT) {\n // declaration\n this.parseDecl(tape);\n } else if (peeked.tag == TokenType.PCT_IDENT) {\n this.tokenizer.next(tape);\n this.parseDirective(tape, peeked.value);\n } else {\n throw new SyntaxError(`Declaration must start with IDENT or PCT_IDENT. Found: '${peeked.value}' instead.`);\n }\n peeked = this.tokenizer.peek(tape);\n }\n }\n\n parseDirective(tape: TLEX.TapeInterface, directive: string): void {\n if (directive == \"start\") {\n // override start directive\n const next = this.tokenizer.expectToken(tape, TokenType.IDENT);\n this.grammar.startSymbol = this.ensureSymbol(next.value as string, false);\n } else if (directive == \"resyntax\") {\n // override start directive\n const next = this.tokenizer.expectToken(tape, TokenType.IDENT);\n if (next.value != \"js\" && next.value != \"flex\") {\n throw new SyntaxError(\"Invalid regex syntax: \" + next.value);\n }\n this.regexSyntax = next.value;\n } else if (directive.startsWith(\"skip\")) {\n const rule = this.parseRegex(tape, \"\", 30, directive.endsWith(\"flex\") ? \"flex\" : \"\");\n const tokenHandler = this.parseTokenHandler(tape);\n if (tokenHandler) {\n this.generatedTokenizer.addRule(rule, (rule, tape, token) => {\n tokenHandler(rule, tape, token, this);\n return null;\n });\n } else {\n this.generatedTokenizer.addRule(rule, () => null);\n }\n } else if (directive.startsWith(\"token\") || directive.startsWith(\"define\")) {\n const isDef = directive.startsWith(\"define\");\n const tokName = this.tokenizer.expectToken(tape, TokenType.IDENT, TokenType.STRING);\n let label = tokName.value as string;\n if (tokName.tag == TokenType.STRING || tokName.tag == TokenType.NUMBER) {\n label = `\"${tokName.value}\"`;\n }\n const rule = this.parseRegex(tape, label, 0, directive.endsWith(\"flex\") ? \"flex\" : \"\");\n if (isDef) {\n // Define a \"reusable\" regex that is not a token on its own\n this.generatedTokenizer.addVar(label, rule.expr);\n } else {\n const tokenHandler = this.parseTokenHandler(tape);\n // see if we have a handler function here\n this.generatedTokenizer.addRule(rule, tokenHandler);\n // register it\n this.ensureSymbol(label, true);\n }\n } else {\n throw new Error(\"Invalid directive: \" + directive);\n }\n }\n\n parseTokenHandler(tape: Tape): TLEX.RuleMatchHandler | null {\n if (!this.tokenizer.consumeIf(tape, TokenType.OPEN_BRACE)) {\n return null;\n }\n\n const funcName = this.tokenizer.expectToken(tape, TokenType.IDENT);\n\n // how do we use the funcName to\n const out = (rule: TLEX.Rule, tape: Tape, token: any, owner: any) => {\n const handler = this.tokenHandlers[funcName.value];\n if (!handler) throw new Error(\"Handler method not found: \" + funcName.value);\n token = handler(token, tape, owner);\n return token;\n };\n\n this.tokenizer.expectToken(tape, TokenType.CLOSE_BRACE);\n return out;\n }\n\n parseDecl(tape: Tape): void {\n const ident = this.tokenizer.expectToken(tape, TokenType.IDENT);\n if (this.tokenizer.consumeIf(tape, TokenType.ARROW, TokenType.COLON)) {\n const nt = this.ensureSymbol(ident.value as string, false);\n if (nt.isTerminal) {\n // it is a terminal so mark it as a non-term now that we\n // know there is a declaration for it.\n nt.isTerminal = false;\n } else if (nt.isAuxiliary) {\n throw new Error(\"NT is already auxiliary and cannot be reused.\");\n }\n for (const [rhs, action] of this.parseProductions(tape, this.grammar, nt)) {\n const rule = this.grammar.add(nt, rhs, action);\n }\n this.tokenizer.expectToken(tape, TokenType.SEMI_COLON);\n }\n }\n\n parseProductions(tape: Tape, grammar: Grammar, nt: TSU.Nullable<Sym>): [Str, RuleAction | null][] {\n const out: [Str, RuleAction | null][] = [];\n while (this.tokenizer.peek(tape) != null) {\n const rule = this.parseProd(tape, grammar);\n out.push(rule);\n if (this.tokenizer.consumeIf(tape, TokenType.PIPE)) {\n continue;\n } else if (this.tokenizer.nextMatches(tape, TokenType.CLOSE_SQ, TokenType.CLOSE_PAREN, TokenType.SEMI_COLON)) {\n break;\n }\n }\n return out;\n }\n\n parseProd(tape: Tape, grammar: Grammar): [Str, null | RuleAction] {\n const out = new Str();\n while (true) {\n // if we are starting with a FOLLOW symbol then return as it marks\n // the end of this production\n if (\n this.tokenizer.nextMatches(\n tape,\n TokenType.CLOSE_PAREN,\n TokenType.CLOSE_SQ,\n TokenType.SEMI_COLON,\n TokenType.PIPE,\n TokenType.OPEN_BRACE,\n )\n ) {\n break;\n // return [out, null];\n }\n\n let curr: TSU.Nullable<Str> = null;\n if (this.tokenizer.consumeIf(tape, TokenType.OPEN_PAREN)) {\n const rules = this.parseProductions(tape, grammar, null);\n if (rules.length == 0) {\n // nothing\n } else if (rules.length == 1) {\n // TODO: Consider actions in non top level rules\n curr = rules[0][0];\n } else {\n // create a new NT over this\n // TODO: Consider actions in non top level rules\n curr = grammar.anyof(...rules.map((r) => r[0]));\n }\n this.tokenizer.expectToken(tape, TokenType.CLOSE_PAREN);\n } else if (this.tokenizer.consumeIf(tape, TokenType.OPEN_SQ)) {\n const rules = this.parseProductions(tape, grammar, null);\n if (rules.length == 0) {\n // nothing\n } else if (rules.length == 1) {\n // TODO: Consider actions in non top level rules\n curr = grammar.opt(rules[0][0]);\n } else {\n // create a new NT over this\n // TODO: Consider actions in non top level rules\n curr = grammar.opt(grammar.anyof(...rules.map((r) => r[0])));\n }\n this.tokenizer.expectToken(tape, TokenType.CLOSE_SQ);\n } else if (\n this.tokenizer.nextMatches(tape, TokenType.IDENT, TokenType.STRING, TokenType.NUMBER, TokenType.REGEX)\n ) {\n const token = this.tokenizer.next(tape) as TLEX.Token;\n let label = token.value as string;\n if (token.tag == TokenType.STRING || token.tag == TokenType.NUMBER) {\n label = `\"${token.value}\"`;\n const pattern = str2regex(token.value);\n const rule = TLEX.Builder.build(pattern, { tag: label, priority: 20 });\n this.generatedTokenizer.addRule(rule);\n } else if (token.tag == TokenType.REGEX) {\n label = \"/\" + token.value[0] + \"/\" + token.value[1];\n let re = token.value[0];\n if (token.value[1].length > 0) {\n // Flags given so create\n re = new RegExp(token.value[0], token.value[1]);\n }\n const rule = TLEX.Builder.build(re, { tag: label, priority: 10 });\n this.generatedTokenizer.addRule(rule);\n } else {\n // Normal\n }\n // See if this symbol is already registered\n const currSym = this.ensureSymbol(label, true);\n curr = new Str(currSym);\n } else {\n throw new TLEX.UnexpectedTokenError(this.tokenizer.peek(tape));\n }\n\n if (curr == null) {\n throw new Error(\"Could not determine node\");\n }\n\n if (this.tokenizer.consumeIf(tape, TokenType.STAR)) {\n curr = grammar.atleast0(curr, this.leftRecursive);\n } else if (this.tokenizer.consumeIf(tape, TokenType.PLUS)) {\n curr = grammar.atleast1(curr, this.leftRecursive);\n } else if (this.tokenizer.consumeIf(tape, TokenType.QMARK)) {\n curr = grammar.opt(curr);\n }\n out.extend(curr);\n }\n let action: RuleAction | null = null;\n if (this.tokenizer.consumeIf(tape, TokenType.OPEN_BRACE)) {\n const next = this.tokenizer.expectToken(tape, TokenType.DOLLAR_NUM, TokenType.IDENT);\n action = new RuleAction(next.value);\n this.tokenizer.expectToken(tape, TokenType.CLOSE_BRACE);\n }\n return [out, action];\n }\n}\n","import * as TSU from \"@panyam/tsutils\";\nimport * as TLEX from \"tlex\";\nimport { Sym, Grammar, Rule } from \"./grammar\";\nimport {\n PTNode,\n SimpleParser as ParserBase,\n BeforeAddingChildCallback,\n RuleReductionCallback,\n NextTokenCallback,\n} from \"./parser\";\nimport { ParseError } from \"./errors\";\n\ntype Nullable<T> = TSU.Nullable<T>;\ntype NumMap<T> = TSU.NumMap<T>;\ntype StringMap<T> = TSU.StringMap<T>;\n\nexport enum LRActionType {\n ACCEPT,\n SHIFT,\n REDUCE,\n GOTO, // can *ONLY* be valid for non-terms\n}\n\nexport class LRAction {\n // Type of action\n tag: LRActionType;\n\n // Next state to go to after performing the action (if valid).\n gotoState: Nullable<number> = null;\n\n // The rule to be used for a reduce action\n rule: Nullable<Rule> = null;\n\n toString(): string {\n if (this.tag == LRActionType.ACCEPT) return \"Acc\";\n else if (this.tag == LRActionType.SHIFT) {\n return \"S\" + this.gotoState!;\n } else if (this.tag == LRActionType.REDUCE) {\n return \"R \" + this.rule!.id;\n } else {\n return \"\" + this.gotoState!;\n }\n }\n\n equals(another: LRAction): boolean {\n return this.tag == another.tag && this.gotoState == another.gotoState && this.rule == another.rule;\n }\n\n static Shift(goto: number): LRAction {\n const out = new LRAction();\n out.tag = LRActionType.SHIFT;\n out.gotoState = goto;\n return out;\n }\n\n static Reduce(rule: Rule): LRAction {\n const out = new LRAction();\n out.tag = LRActionType.REDUCE;\n out.rule = rule;\n return out;\n }\n\n static Goto(gotoState: number): LRAction {\n const out = new LRAction();\n out.tag = LRActionType.GOTO;\n out.gotoState = gotoState;\n return out;\n }\n\n static Accept(): LRAction {\n const out = new LRAction();\n out.tag = LRActionType.ACCEPT;\n return out;\n }\n}\n\n/**\n * A parsing table for LR parsers.\n */\nexport class ParseTable {\n // Records which actions have conflicts\n conflictActions: NumMap<StringMap<boolean>> = {};\n\n /**\n * Maps symbol (by id) to the action;\n */\n actions: NumMap<NumMap<LRAction[]>> = {};\n\n constructor(public readonly grammar: Grammar) {}\n\n get hasConflicts(): boolean {\n return Object.keys(this.conflictActions).length > 0;\n }\n\n /**\n * Gets the action for a given sym from a given state.\n */\n getActions(stateId: number, next: Sym, ensure = false): LRAction[] {\n let l1: NumMap<LRAction[]>;\n if (stateId in this.actions) {\n l1 = this.actions[stateId];\n } else if (ensure) {\n l1 = this.actions[stateId] = {};\n } else {\n return [];\n }\n\n if (next.id in l1) {\n return l1[next.id];\n } else if (ensure) {\n return (l1[next.id] = []);\n }\n return [];\n }\n\n addAction(stateId: number, next: Sym, action: LRAction): this {\n const actions = this.getActions(stateId, next, true);\n if (actions.findIndex((ac) => ac.equals(action)) < 0) {\n actions.push(action);\n }\n if (actions.length > 1) {\n this.conflictActions[stateId] = this.conflictActions[stateId] || {};\n this.conflictActions[stateId][next.label] = true;\n }\n return this;\n }\n\n get debugValue(): any {\n const out: any = {};\n for (const fromId in this.actions) {\n out[fromId] = {};\n for (const symId in this.actions[fromId]) {\n const sym = this.grammar.getSymById(symId as any)!;\n const actions = this.actions[fromId][sym.id] || [];\n if (actions.length > 0) {\n out[fromId][sym.label] = actions.map((a) => a.toString());\n }\n }\n }\n return out;\n }\n}\n\nexport class ParseStack {\n // A way of marking the kind of item that is on the stack\n // true => isStateId\n // false => isSymbolId\n readonly stateStack: number[] = [];\n readonly nodeStack: PTNode[] = [];\n\n push(state: number, node: PTNode): void {\n this.stateStack.push(state);\n this.nodeStack.push(node);\n }\n\n /**\n * Gets the nth item from the top of the stack.\n */\n top(nth = 0): [number, PTNode] {\n return [this.stateStack[this.stateStack.length - 1 - nth], this.nodeStack[this.nodeStack.length - 1 - nth]];\n }\n\n pop(): [number, PTNode] {\n const out = this.top();\n this.stateStack.pop();\n this.nodeStack.pop();\n return out;\n }\n\n /**\n * Pop N items from the stack.\n */\n popN(n = 1): void {\n const L = this.stateStack.length;\n this.stateStack.splice(L - n, n);\n this.nodeStack.splice(L - n, n);\n }\n\n get isEmpty(): boolean {\n return this.stateStack.length == 0 || this.nodeStack.length == 0;\n }\n}\n\nexport type ActionResolverCallback = (\n actions: LRAction[],\n stack: ParseStack,\n tokenbuffer: TLEX.TokenBuffer,\n) => LRAction;\n\nexport type RuleActionHandler = (rule: Rule, parent: PTNode, ...children: PTNode[]) => any;\n\nexport type TokenErrorCallback = (err: TLEX.TokenizerError, input: TLEX.Tape) => boolean;\n\nexport interface ParserContext {\n buildParseTree?: boolean;\n copySingleChild?: boolean;\n ruleHandlers: TSU.StringMap<RuleActionHandler>;\n beforeAddingChildNode?: BeforeAddingChildCallback;\n onReduction?: RuleReductionCallback;\n onNextToken?: NextTokenCallback;\n actionResolver?: ActionResolverCallback;\n onTokenError?: TokenErrorCallback;\n // The owner used for tokenizer to get an insight into the context\n // (to allow context sensitive scanning - aka \"scanner hacks\").\n tokenizerContext: any;\n}\n\nexport class Parser extends ParserBase {\n constructor(\n public readonly parseTable: ParseTable,\n config: any = {},\n ) {\n super();\n }\n\n get grammar(): Grammar {\n return this.parseTable.grammar;\n }\n\n /**\n * Parses the input and returns the resulting root Parse Tree node.\n */\n protected parseInput(input: TLEX.Tape, context?: ParserContext): Nullable<PTNode> {\n context = context || ({} as ParserContext);\n // Set default values for missing values\n this.tokenbuffer.tokenizerContext = context.tokenizerContext;\n if (context.buildParseTree != false) context.buildParseTree = true;\n if (context.copySingleChild != false) context.copySingleChild = true;\n let idCounter = 0;\n const stack = new ParseStack();\n stack.push(0, new PTNode(idCounter++, this.grammar.augStartRule.nt, null));\n const tokenbuffer = this.tokenbuffer;\n const g = this.grammar;\n let output: Nullable<PTNode> = null;\n\n /**\n * Pick an action among several actions based on several factors (eg\n * curr parse stack, tokenbuffer etc).\n */\n function resolveActions(actions: LRAction[]): LRAction {\n if (context?.actionResolver) {\n return context.actionResolver(actions, stack, tokenbuffer);\n } else {\n if (actions.length > 1) {\n throw new Error(\"Multiple actions found.\");\n }\n return actions[0];\n }\n }\n\n function nextToken(): TLEX.Token | null {\n try {\n return tokenbuffer.peek(input);\n } catch (err /* InvalidCharacterException */) {\n if (!context?.onTokenError || !context?.onTokenError(err as TLEX.TokenizerError, input)) {\n // no handler or handler could do nothing so throw it up again\n throw err;\n }\n\n // Handler managed to do \"something\" so retry again\n // TODO - Check offsets were modified?\n return nextToken();\n }\n }\n\n while (true) {\n // while (tokenbuffer.peek(input) != null || !stack.isEmpty) {\n let token = nextToken();\n if (token == null) {\n if (stack.isEmpty) {\n // no more to do\n break;\n }\n } else if (context.onNextToken) {\n token = context.onNextToken(token);\n }\n const nextSym = token == null ? g.Eof : this.getSym(token);\n const nextValue = token == null ? null : token.value;\n let [topState, topNode] = stack.top();\n const actions = this.parseTable.getActions(topState, nextSym);\n if (actions == null || actions.length == 0) {\n // TODO - use a error handler here\n throw new ParseError(`Unexpected Token: '${nextSym.label}'`, \"UnexpectedToken\", {\n state: topState,\n token: token,\n nextSym: nextSym,\n });\n }\n\n const action = resolveActions(actions);\n if (action.tag == LRActionType.ACCEPT) {\n break;\n } else if (action.tag == LRActionType.SHIFT) {\n tokenbuffer.next(input);\n const newNode = new PTNode(idCounter++, nextSym, nextValue);\n stack.push(action.gotoState!, newNode);\n } else {\n // reduce\n TSU.assert(action.rule != null, \"Nonterm and ruleindex must be provided for a reduction action\");\n const ruleLen = action.rule.rhs.length;\n\n // here see if a rule handler exists - if it does use it\n let newNode = new PTNode(idCounter++, action.rule.nt, null);\n // Begin the reduction here. We are breaking the reduction into\n // two parts:\n //\n // 1. Adding child nodes into the parent (reduced) node. Here\n // the beforeAddingChildNode callback is used to modify children\n // being added.\n // 2. After all children have been added to give the caller a chance\n // to handle/post-process the reduction - eg to build the semantic value.\n //\n // Our onReduction is a catch all to perform semantic actions. Instead\n // we could do rule specific ones by using the rule.action (if it exists)\n // and only invoke the onReduction if a rule specific action does not exist.\n //\n // Are these \"double steps\" needed? Can we just build parse tree, filter out\n // child nodes and eval semantic value with a single action?\n //\n // Can semanticHandler do this?\n //\n // eg with\n //\n // E -> E + E { add }\n //\n // we could have our stack looking like;\n //\n // .... s1 E s2 E\n //\n // to be reduced and add could be called with:\n //\n // add(E1, E2) - as the child nodes themselves.\n //\n // the add handler could now do a few things:\n //\n // 1. Ensure all nodes are added to E as is (resulting in 3 nodes - \"E\", \"+\", \"E\")\n // 2. Not add any nodes\n // 3. Computing the value of E and E and the sum of those and put it in the parent E.\n // 4. or all of the above.\n //\n // Doing filtering seems like a very premature usecase. In the case of incremental\n // parsing we may need all nodes to exist and filtering out can get in the way of that.\n //\n // But let us leave it for now and make any semantic handling happen *after* parse tree\n // child node filter/transformation\n if (context.buildParseTree) {\n for (let i = ruleLen - 1; i >= 0; i--) {\n const childNode: TSU.Nullable<PTNode> = stack.top(i)[1];\n if (context.beforeAddingChildNode) {\n for (const node of context.beforeAddingChildNode(newNode, childNode)) {\n newNode.add(node);\n }\n } else if (childNode != null) {\n newNode.add(childNode);\n }\n }\n }\n // Now apply the semantic handler if it exists\n if (action.rule.action) {\n // call it\n if (action.rule.action.isFunction) {\n // find the function associated with\n const handlerName = action.rule.action.value;\n const handler = context.ruleHandlers![handlerName];\n if (!handler) throw new Error(\"Action handler not found: \" + handlerName);\n // TODO - Replace the handler signature to take an\n // interface that returns the nth child node (directly from\n // the parse stack) instead of all children - this way we\n // can even avoid building a parse tree if need be and\n // decouple semantic actions from parse tree building\n newNode.value = handler(action.rule, newNode, ...newNode.children);\n } else {\n // setting value as a child's value, eg $1, $2 etc\n newNode.value = newNode.children[(action.rule.action.value as number) - 1].value;\n }\n } else if (context.onReduction) {\n // fallback to default reduction handler\n newNode = context.onReduction(newNode, action.rule);\n } else if (newNode.children.length == 1 && context.copySingleChild) {\n // If we have only 1 child set the semantic value to be child's value\n // ie values \"bubble up\"\n newNode.value = newNode.children[0].value;\n }\n\n // Perform the action reduction by popping ruleLen number of items off the stack\n // and replace the top with our newNode\n stack.popN(ruleLen);\n [topState, topNode] = stack.top();\n const newAction = resolveActions(this.parseTable.getActions(topState, action.rule.nt));\n TSU.assert(newAction != null && newAction.gotoState != null, \"Top item does not have an action.\");\n stack.push(newAction.gotoState, newNode);\n output = newNode;\n }\n }\n // It is possible that here no reductions have been done!\n return output;\n }\n}\n","import * as TSU from \"@panyam/tsutils\";\nimport * as TLEX from \"tlex\";\nimport { Sym, Grammar, Rule } from \"./grammar\";\n\ntype Nullable<T> = TSU.Nullable<T>;\n\n/**\n * As the parse tree is built, nodes are created and added to parents bottom up.\n * This method is called before a child node is added to its parent. The\n * node's left-most siblings have already been added this point.\n *\n * This method is an opportunity to filter or transfor the node or even adding\n * other nodes to the parent's child list. Note that at this point the parent\n * has *NOT* been added to its parent.\n *\n * In order to filter out the node, return null. Otherwise return a\n * PTNode instance for the actual node to be added to the parent.\n */\nexport type BeforeAddingChildCallback = (parent: PTNode, child: PTNode) => PTNode[];\n\n/**\n * This method is called when after a rule has been reduced. At this time\n * all the children have already been reduced (and called with this method).\n * Now is the opportunity for the parent node reduction to perform custom\n * actions. Note that this method cannot modify the stack. It can only be\n * used to perform things like AST building or logging etc.\n */\nexport type RuleReductionCallback = (node: PTNode, rule: Rule) => PTNode;\n\n/**\n * This method is called as soon as the next token is received from the tokenizer.\n * This allows one to filter out tokens or even transform them based on any other\n * context being maintained.\n */\nexport type NextTokenCallback = (token: TLEX.Token) => TSU.Nullable<TLEX.Token>;\n\nexport class PFNode {\n children: this[] = [];\n constructor(\n public readonly id: number,\n public readonly sym: Sym,\n public value: any,\n ...children: PFNode[]\n ) {\n this.children = (children as this[]) || [];\n }\n\n get childCount(): number {\n return this.children.length;\n }\n\n childAt(index: number): this {\n if (index < 0) return this.children[this.children.length + index] as this;\n return this.children[index] as this;\n }\n\n get isTerminal(): boolean {\n return this.sym.isTerminal;\n }\n\n add(node: this, index = -1): this {\n if (this.isTerminal) {\n throw new Error(`Cannot add children (${node.sym.label}) to a terminal node: ${this.sym.label}`);\n }\n if (index < 0) {\n this.children.push(node);\n } else {\n this.children.splice(index, 0, node);\n }\n return this;\n }\n\n splice(index: number, numToDelete: number, ...nodes: this[]): this {\n this.children.splice(index, numToDelete, ...nodes);\n return this;\n }\n\n get reprString(): string {\n /*\n let out = `Node(${this.sym.label}, {this.value}`;\n if (this.children.length > 0) out += \", \" + this.children.map((c) => c.reprString).join(\", \");\n out += \")\";\n return out;\n */\n return this.debugValue(false).join(\"\\n\");\n }\n\n debugValue(raw = true): any {\n if (raw) {\n const out: any = [this.sym.label];\n if (this.value) out.push(this.value);\n if (this.children.length > 0) out.push(this.children.map((c) => c.debugValue(raw)));\n return out;\n } else {\n const out: any[] = [];\n const value = this.value;\n out.push(this.value == null ? this.sym.label : this.sym.label + \" - \" + this.value);\n this.children.forEach((node) => (node.debugValue(raw) as string[]).forEach((l) => out.push(\" \" + l)));\n return out;\n }\n }\n}\n\nexport class PTNode extends PFNode {\n parent: Nullable<PTNode> = null;\n\n add(node: this, index = -1): this {\n super.add(node, index);\n node.parent = this;\n return this;\n }\n\n splice(index: number, numToDelete: number, ...nodes: this[]): this {\n for (const node of nodes) node.parent = this;\n return super.splice(index, numToDelete, ...nodes);\n }\n}\n\nexport abstract class ParserBase {\n tokenbuffer: TLEX.TokenBuffer;\n\n setTokenizer(tokenizer: TLEX.NextTokenFunc): this {\n this.tokenbuffer = new TLEX.TokenBuffer(tokenizer, null);\n return this;\n }\n\n abstract get grammar(): Grammar;\n\n /**\n * Converts the token to a Terminal based on the tag value.\n */\n getSym(token: TLEX.Token): Sym {\n const out = this.grammar.getSym(token.tag as string);\n if (out == null) {\n throw new Error(\"Invalid token tag: \" + token.tag + \", Value: \" + token.value);\n }\n return out;\n }\n}\n\nexport abstract class SimpleParser extends ParserBase {\n parse(input: string | TLEX.Tape, delegate: any = null): Nullable<PTNode> {\n if (typeof input === \"string\") {\n input = new TLEX.Tape(input);\n }\n return this.parseInput(input, delegate);\n }\n\n /**\n * Parses the input and returns the resulting root Parse Tree node.\n */\n protected abstract parseInput(input: TLEX.Tape, delegate: any): Nullable<PTNode>;\n}\n\nexport abstract class ParallelParser extends ParserBase {\n parse(input: string | TLEX.Tape, delegate: any = null): PFNode[] {\n if (typeof input === \"string\") {\n input = new TLEX.Tape(input);\n }\n return this.parseInput(input, delegate);\n }\n\n /**\n * Parses the input and returns the resulting root Parse Tree node.\n */\n protected abstract parseInput(input: TLEX.Tape, delegate: any): PFNode[];\n}\n","import * as TSU from \"@panyam/tsutils\";\nimport { Sym, Grammar, Rule } from \"./grammar\";\nimport { IDSet } from \"./sets\";\n\ntype Nullable<T> = TSU.Nullable<T>;\ntype NumMap<T> = TSU.NumMap<T>;\n\nexport class LRItem {\n id = 0;\n readonly rule: Rule;\n readonly position: number;\n constructor(rule: Rule, position = 0) {\n this.rule = rule;\n this.position = position;\n }\n\n advance(): LRItem {\n TSU.assert(this.position < this.rule.rhs.length);\n return new LRItem(this.rule, this.position + 1);\n }\n\n copy(): LRItem {\n return new LRItem(this.rule, this.position);\n }\n\n /**\n * TODO - Instead of using strings as keys, can we use a unique ID?\n * If we assume a max limit on number of non terminals in our grammar\n * and a max limit on the number of rules per non terminal and a\n * max limit on the size of each rule then we can uniquely identify\n * a rule and position for a non-terminal by a single (64 bit) number\n *\n * We can use the following bitpacking to nominate this:\n *\n * <padding 16 bits><nt id 16 bits><ruleIndex 16 bits><position 16 bits>\n */\n get key(): string {\n TSU.assert(!isNaN(this.rule.id), \"Rule's ID is not yet set.\");\n return this.rule.id + \":\" + this.position;\n }\n\n compareTo(another: this): number {\n let diff = this.rule.id - another.rule.id;\n if (diff == 0) diff = this.position - another.position;\n return diff;\n }\n\n equals(another: this): boolean {\n return this.compareTo(another) == 0;\n }\n\n get debugString(): string {\n const rule = this.rule;\n const pos = this.position;\n const pre = rule.rhs.syms.slice(0, pos).join(\" \");\n const post = rule.rhs.syms.slice(pos).join(\" \");\n return `${rule.id} - ${rule.nt} -> ${pre} • ${post}`;\n }\n}\n\nexport class LRItemSet {\n id = 0;\n readonly itemGraph: LRItemGraph;\n protected _key: Nullable<string> = null;\n readonly values: number[];\n protected _lookaheads: NumMap<Sym[]> = {};\n protected _hasLookAheads = false;\n\n constructor(ig: LRItemGraph, ...entries: number[]) {\n this.itemGraph = ig;\n this.values = entries;\n }\n\n copy(): LRItemSet {\n const out = new LRItemSet(this.itemGraph, ...this.values);\n out._lookaheads = { ...this._lookaheads };\n out._hasLookAheads = this._hasLookAheads;\n return out;\n }\n\n /**\n * Adds a new look ahead symbol for a given item.\n */\n addLookAhead(item: LRItem, sym: Sym): boolean {\n if (!(item.id in this._lookaheads)) {\n this._lookaheads[item.id] = [];\n }\n for (const s of this._lookaheads[item.id]) if (s == sym) return false;\n this._hasLookAheads = true;\n this._key = null;\n this._lookaheads[item.id].push(sym);\n this._lookaheads[item.id].sort((s1, s2) => s1.id - s2.id);\n return true;\n }\n\n /**\n * Clears all lookaheads from this itemset.\n */\n clearLookAheads(): void {\n this._lookaheads = {};\n }\n\n /**\n * Gets the lookahead symbols for a given item.\n */\n getLookAheads(item: LRItem): ReadonlyArray<Sym> {\n return this._lookaheads[item.id] || [];\n }\n\n // A way to cache the key of this item set.\n // Keys help make the comparison of two sets easy.\n get key(): string {\n if (this._key == null) {\n this._key = this.revalKey();\n }\n return this._key;\n }\n\n protected revalKey(): string {\n if (this.hasLookAheads) {\n this.values.sort();\n return this.values\n .map((itemId) => {\n const la = this._lookaheads[itemId] || [];\n return itemId + \"[\" + la.map((s) => s.id).join(\",\") + \"]\";\n })\n .join(\"/\");\n } else {\n this.values.sort();\n return this.values.join(\"/\");\n }\n }\n\n has(itemId: number): boolean {\n return this.values.indexOf(itemId) >= 0;\n }\n\n equals(another: LRItemSet): boolean {\n return this.key == another.key;\n }\n\n add(itemId: number): this {\n if (!this.has(itemId)) {\n this.values.push(itemId);\n this._key = null;\n }\n return this;\n }\n\n get size(): number {\n return this.values.length;\n }\n\n get debugString(): string {\n return this.debugValue.join(\"\\n\");\n }\n\n get hasLookAheads(): boolean {\n return this._hasLookAheads;\n }\n\n get debugValue(): any {\n if (this.hasLookAheads) {\n const items = this.values.map((v: number) => this.itemGraph.items.get(v));\n // sort them by rule\n items.sort((i1, i2) => i1.compareTo(i2));\n // then append the look aheads\n return items.map((item) => {\n const las = this.getLookAheads(item)\n .map((s) => s.label)\n .sort((s1, s2) => s1.localeCompare(s2))\n .join(\", \");\n return las.length > 0 ? `${item.debugString} / ( ${las} )` : item.debugString;\n });\n } else {\n const items = this.values.map((v: number) => this.itemGraph.items.get(v));\n // sort them by rule\n items.sort((i1, i2) => i1.compareTo(i2));\n return items.map((i) => i.debugString);\n }\n }\n}\n\nexport abstract class LRItemGraph {\n // List of all unique LRItems that can be used in this item graph.\n // Note that since the same Item can reside in multiple sets only\n // one is created via the newItem method and it is referred\n // everwhere it is needed.\n\n /**\n * Using IDed sets of Items and ItemSets.\n * This ensures that only one copy of an item exists\n * \"by value\".\n */\n items: IDSet<LRItem>;\n itemSets: IDSet<LRItemSet>;\n\n // Goto sets for a set and a given transition out of it\n gotoSets: NumMap<NumMap<LRItemSet>> = {};\n\n abstract closure(itemSet: LRItemSet): LRItemSet;\n abstract startSet(): LRItemSet;\n\n constructor(public readonly grammar: Grammar) {\n this.items = new IDSet();\n this.itemSets = new IDSet();\n }\n\n protected startItem(): LRItem {\n const startSymbol = this.grammar.startSymbol;\n TSU.assert(startSymbol != null, \"Start symbol must be set\");\n TSU.assert((this.grammar.augStartRule || null) != null, \"Grammar is not augmented\");\n return this.items.ensure(new LRItem(this.grammar.augStartRule));\n }\n\n reset(): void {\n this.grammar.refresh();\n this.gotoSets = {};\n this.items.clear();\n this.itemSets.clear();\n this.startSet();\n }\n\n refresh(): this {\n this.reset();\n this.grammar.refresh();\n this.evalGotoSets();\n return this;\n }\n\n /**\n * Computes all the goto sets used to create the graph of items.\n */\n protected evalGotoSets(): void {\n const out = this.itemSets;\n for (let i = 0; i < out.size; i++) {\n const currSet = out.get(i);\n // This will also include the null symbol since Grammar\n // adds Null and Eof symbols automatically\n for (const sym of this.grammar.allSymbols) {\n if (sym != this.grammar.Null) {\n const gotoSet = this.goto(currSet, sym);\n if (gotoSet.size > 0) {\n this.setGoto(currSet, sym, gotoSet);\n }\n }\n }\n }\n }\n\n /**\n * Computes the GOTO set of this ItemSet for a particular symbol transitioning\n * out of this item set.\n */\n goto(itemSet: LRItemSet, sym: Sym): LRItemSet {\n const out = this.newItemSet();\n for (const itemId of itemSet.values) {\n const item = this.items.get(itemId);\n // see if item.position points to \"sym\" in its rule\n const rule = item.rule;\n if (item.position < rule.rhs.length) {\n if (rule.rhs.syms[item.position] == sym) {\n // advance the item and add it\n this.advanceItemAndAdd(item, itemSet, out);\n }\n }\n }\n // compute the closure of the new set\n return this.closure(out);\n }\n\n protected advanceItemAndAdd(itemToAdvance: LRItem, fromItemSet: LRItemSet, toItemSet: LRItemSet): void {\n const newItem = this.items.ensure(itemToAdvance.advance());\n toItemSet.add(newItem.id);\n // copy over the look aheads\n for (const laSym of fromItemSet.getLookAheads(itemToAdvance)) {\n toItemSet.addLookAhead(newItem, laSym);\n }\n }\n\n protected newItemSet(...items: LRItem[]): LRItemSet {\n return new LRItemSet(this, ...items.map((item) => item.id));\n }\n\n get size(): number {\n return this.itemSets.size;\n }\n\n protected ensureGotoSet(fromSet: LRItemSet): NumMap<LRItemSet> {\n if (!(fromSet.id in this.gotoSets)) {\n this.gotoSets[fromSet.id] = {};\n }\n return this.gotoSets[fromSet.id];\n }\n\n setGoto(fromSet: LRItemSet, sym: Sym, toSet: LRItemSet): void {\n const entries = this.ensureGotoSet(fromSet);\n entries[sym.id] = toSet;\n }\n\n getGoto(fromSet: LRItemSet, sym: Sym): Nullable<LRItemSet> {\n return (this.gotoSets[fromSet.id] || {})[sym.id] || null;\n }\n\n forEachGoto(itemSet: LRItemSet, visitor: (sym: Sym, nextSet: LRItemSet) => boolean | void): void {\n const gotoSet = this.gotoSets[itemSet.id] || {};\n for (const symid in gotoSet) {\n const sym = this.grammar.getSymById(symid as any) as Sym;\n const next = gotoSet[symid];\n if (visitor(sym, next) == false) break;\n }\n }\n\n gotoSetFor(itemSet: LRItemSet): NumMap<LRItemSet> {\n return this.gotoSets[itemSet.id] || {};\n }\n\n get debugValue(): any {\n const out = {} as any;\n this.itemSets.entries.forEach((iset) => {\n out[iset.id] = { items: [], goto: {} };\n out[iset.id][\"items\"] = iset.debugValue;\n const g = this.gotoSets[iset.id];\n for (const symid in g) {\n const sym = this.grammar.getSymById(symid as any)!;\n out[iset.id][\"goto\"] = out[iset.id][\"goto\"] || {};\n out[iset.id][\"goto\"][sym.label] = g[symid].id;\n }\n });\n return out;\n }\n}\n\nexport class LR0ItemGraph extends LRItemGraph {\n /**\n * Creates the set for the grammar. This is done by creating an\n * augmented rule of the form S' -> S (where S is the start symbol of\n * the grammar) and creating the closure of this starting rule, ie:\n *\n * StartSet = closure({S' -> . S})\n */\n startSet(): LRItemSet {\n const startItem = this.startItem();\n const newset = this.newItemSet(startItem);\n return this.closure(newset);\n }\n\n /**\n * Computes the closure of a given item set and returns a new\n * item set.\n */\n closure(itemSet: LRItemSet): LRItemSet {\n const out = new LRItemSet(this, ...itemSet.values);\n for (let i = 0; i < out.values.length; i++) {\n const itemId = out.values[i];\n const item = this.items.get(itemId)!;\n const rule = item.rule;\n // Evaluate the closure\n // Cannot do anything past the end\n if (item.position < rule.rhs.length) {\n const sym = rule.rhs.syms[item.position];\n if (!sym.isTerminal) {\n for (const rule of this.grammar.rulesForNT(sym)) {\n const newItem = this.items.ensure(new LRItem(rule, 0));\n out.add(newItem.id);\n }\n }\n }\n }\n return out.size == 0 ? out : this.itemSets.ensure(out);\n }\n}\n\nexport class LR1ItemGraph extends LRItemGraph {\n /**\n * Overridden to include the EOF marker as the lookahead for the start state\n *\n * StartSet = closure({S' -> . S, $})\n */\n startSet(): LRItemSet {\n const startItem = this.startItem();\n const newset = this.newItemSet(startItem);\n newset.addLookAhead(startItem, this.grammar.Eof);\n return this.closure(newset);\n }\n\n /**\n * Computes the closure of this item set and returns a new\n * item set.\n */\n closure(itemSet: LRItemSet): LRItemSet {\n const out = itemSet.copy();\n for (let i = 0; i < out.values.length; i++) {\n const itemId = out.values[i];\n const item = this.items.get(itemId) as LRItem;\n // Evaluate the closure\n // Cannot do anything past the end\n if (item.position >= item.rule.rhs.length) continue;\n const rhs = item.rule.rhs;\n const B = rhs.syms[item.position];\n if (B.isTerminal) continue;\n\n for (const lookahead of out.getLookAheads(item)) {\n const suffix = rhs.copy().append(lookahead);\n this.grammar.firstSets.forEachTermIn(suffix, item.position + 1, (term) => {\n if (term != null) {\n // For each rule [ B -> beta, term ] add it to\n // our list of items if it doesnt already exist\n const bRules = this.grammar.rulesForNT(B);\n for (const br of bRules) {\n const newItem = this.items.ensure(new LRItem(br, 0));\n out.add(newItem.id);\n out.addLookAhead(newItem, term);\n }\n }\n });\n }\n }\n return out.size == 0 ? out : this.itemSets.ensure(out);\n }\n}\n","import * as TSU from \"@panyam/tsutils\";\nimport { Grammar, Str, Sym, Rule } from \"./grammar\";\nimport { LRAction, ParseTable } from \"./lr\";\nimport { LRItem, LRItemSet, LRItemGraph, LR0ItemGraph, LR1ItemGraph } from \"./lritems\";\nimport { Goto } from \"./tests/utils\";\n\nexport function makeParseTable(g: Grammar, type = \"lr1\"): [ParseTable, LRItemGraph] {\n switch (type) {\n case \"lr1\":\n return makeLRParseTable(g);\n case \"lalr\":\n return makeLALRParseTable(g);\n }\n return makeSLRParseTable(g);\n}\n\n/**\n * A SLR parse table maker.\n */\nexport function makeSLRParseTable(grammar: Grammar): [ParseTable, LRItemGraph] {\n const ig = makeSLRAutomaton(grammar);\n return [makeParseTableFromLA(ig, grammar), ig];\n}\n\nexport function makeSLRAutomaton(grammar: Grammar): LRItemGraph {\n const ig = new LR0ItemGraph(grammar).refresh();\n for (const itemSet of ig.itemSets.entries) {\n evalLASetsForSLRItem(grammar, ig, itemSet);\n }\n return ig;\n}\n\n/**\n * For a given LR(0) Item in the LR0 automaton evaluates the lookahead set\n * for an SLR1 parse table.\n *\n * The SLR lookahead is:\n *\n * SLRLA(q, A -> w) = Follow(A)\n *\n * @param grammar\n * @param ig\n * @param itemSet\n */\nexport function evalLASetsForSLRItem(grammar: Grammar, ig: LRItemGraph, itemSet: LRItemSet): void {\n // Look for transitions from this set\n for (const itemId of itemSet.values) {\n const item = ig.items.get(itemId);\n const rule = item.rule;\n if (item.position >= rule.rhs.length) {\n // if sym is in follows(nt) then add the rule\n // Reduce nt -> rule for all sym in follows(nt)\n grammar.followSets.forEachTerm(rule.nt, (term) => {\n if (term != null) {\n TSU.assert(term.isTerminal);\n itemSet.addLookAhead(item, term);\n }\n });\n }\n }\n}\n\n/**\n * A canonical LR1 parse table maker.\n */\nexport function makeLRParseTable(grammar: Grammar): [ParseTable, LRItemGraph] {\n const ig = new LR1ItemGraph(grammar).refresh();\n const parseTable = makeParseTableFromLA(ig, grammar);\n return [parseTable, ig];\n}\n\n/**\n * A LALR(1) parse table maker using Bermudez and Logothetis' (1989)\n * \"Simple computation of LALR(1) lookahead sets\" method.\n */\nexport function makeLALRParseTable(grammar: Grammar): [ParseTable, LRItemGraph] {\n // const [parseTable, ig] = makeSLRParseTable(grammar);\n const [parseTable, ig] = makeSLRParseTable(grammar);\n\n if (!parseTable.hasConflicts) {\n return [parseTable, ig];\n }\n\n // This is a really simple method compared to DeRemer and Penello's method\n // (based on relations).\n //\n // 1. First transform the grammar G into G' that is based on around the LR0\n // item graph\n const g2 = grammarFromLR0ItemGraph(ig, grammar);\n\n // Reverse of goto sets in the LR automaton to track predecessor states.\n const prevSets: TSU.NumMap<TSU.NumMap<Set<number>>> = {};\n\n for (const startState in ig.gotoSets) {\n for (const symId in ig.gotoSets[startState]) {\n const nextSet = ig.gotoSets[startState][symId];\n if (!(nextSet.id in prevSets)) {\n prevSets[nextSet.id] = {};\n }\n if (!(symId in prevSets[nextSet.id])) {\n prevSets[nextSet.id][symId] = new Set();\n }\n prevSets[nextSet.id][symId].add(startState as any as number);\n }\n }\n\n // For conflict states upgrade lookahead sets based on union of follow\n // sets of G2 for the corresponding sets\n // LALRLA(q, A -> w) =\n for (const startState in parseTable.conflictActions) {\n // So here we have a startState where a symbol was extraneously added\n // into the look ahead set. So here recompute the lookahead set\n // for this state\n const itemSet = ig.itemSets.get(startState as any as number);\n evalLASetsForLALRItem(grammar, g2, ig, itemSet, prevSets);\n }\n\n // Now that all look aheads have been recomputed - recreate\n // the parse table\n return [makeParseTableFromLA(ig, grammar), ig];\n}\n\n/**\n * Shared parse table creator for SLR/LR/LALR grammars that have lookahead\n * in the LR0 automaton.\n */\nexport function makeParseTableFromLA(ig: LRItemGraph, grammar: Grammar): ParseTable {\n const parseTable = new ParseTable(grammar);\n for (const itemSet of ig.itemSets.entries) {\n // Look for transitions from this set\n for (const itemId of itemSet.values) {\n const item = ig.items.get(itemId);\n const rule = item.rule;\n if (item.position < rule.rhs.length) {\n // possibilities of shift\n const sym = rule.rhs.syms[item.position];\n if (sym.isTerminal) {\n const nextSet = ig.getGoto(itemSet, sym);\n if (nextSet) {\n parseTable.addAction(itemSet.id, sym, LRAction.Shift(nextSet.id));\n }\n }\n } else if (!rule.nt.equals(grammar.augStartRule.nt)) {\n // We have nt -> rule DOT / t\n // AND nt != S'\n // Reduce nt -> rule for t\n const lookaheads = itemSet.getLookAheads(item);\n for (const lookahead of lookaheads) {\n parseTable.addAction(itemSet.id, lookahead, LRAction.Reduce(rule));\n }\n }\n }\n\n // Now create GOTO entries for (State,X) where X is a non-term\n ig.forEachGoto(itemSet, (sym, next) => {\n if (sym != null && !sym.isTerminal) {\n parseTable.addAction(itemSet.id, sym, LRAction.Goto(next.id));\n }\n });\n\n // If this state contains the augmented item, S' -> S . / $\n // then add accept\n const lr1Item = ig.items.ensure(new LRItem(grammar.augStartRule, 1));\n itemSet.addLookAhead(lr1Item, grammar.Eof);\n if (itemSet.has(lr1Item.id)) {\n parseTable.addAction(itemSet.id, grammar.Eof, LRAction.Accept());\n }\n }\n return parseTable;\n}\n\n/**\n * For a given LR(0) Item in the LR0 automaton evaluates the lookahead set\n * for an LALR1 parse table.\n *\n * The LALR lookahead is:\n *\n * LALRLA(q, A -> w) = {t | [r:t] in Follow[p: A], Go[p: w] = q }\n *\n * Here [r: t] refers to a state in the augmented grammar transformed from the original\n * grammar where the nonterminals and terminals are based on the transitions in the\n * LR(0) automaton. This augmented grammar is also passed in as a parameter.\n *\n * @param grammar - Original grammar\n * @param augGrammar - Augmented grammar\n * @param ig - LR0 Automaton\n * @param itemSet - The item set in the automaton (ie a particular state)\n * for which lookahead sets are to be computed.\n * @param prevSets - A mapping where prevSets[stateI][symId] is a list of\n * states X1,X2...Xn where where the transition\n * X1[symId] = stateI, X2[symId] = stateI ...\n * Xn[symId] = stateI\n */\nexport function evalLASetsForLALRItem(\n grammar: Grammar,\n augGrammar: Grammar,\n ig: LRItemGraph,\n itemSet: LRItemSet,\n prevSets: TSU.NumMap<TSU.NumMap<Set<number>>>,\n): void {\n // find p going backwards from q spelling w\n function findP(rule: Rule, i: number, currState: number, states: Set<number>): void {\n if (i < 0) {\n // we have reached the end - currState is P\n // Ensure there is a transition from currState on rule.nt\n const transitions: TSU.NumMap<LRItemSet> = ig.gotoSets[currState];\n TSU.assert((transitions[rule.nt.id] || null) != null, \"Transition on rule.nt missing from start state\");\n states.add(currState);\n } else {\n const sym = rule.rhs.syms[i];\n const prevStates = prevSets[currState][sym.id] || null;\n TSU.assert(prevStates != null, \"Prev set should not be null\");\n prevStates.forEach((nextState) => findP(rule, i - 1, nextState, states));\n }\n }\n\n itemSet.clearLookAheads();\n // Look for transitions from this set\n for (const itemId of itemSet.values) {\n const item = ig.items.get(itemId);\n const rule = item.rule;\n if (item.position >= rule.rhs.length) {\n // Here we have rule of the form A -> w in state q\n //\n // For this state we compute LALR lookaheads as:\n //\n // LALRLA(q, A -> w) = {t | [r:t] in Follow[p: A], Go[p: w] = q }\n const pSet = new Set<number>();\n findP(rule, rule.rhs.length - 1, itemSet.id, pSet);\n pSet.forEach((p) => {\n // Now find the NT [p: A] in the augmented grammar\n const pALabel = `[${p}:${rule.nt.label}]`;\n const pA = augGrammar.getSym(pALabel);\n TSU.assert(pA != null, \"Augmented grammar symbol [p:A] not found\");\n augGrammar.followSets.forEachTerm(pA, (term) => {\n if (term != null && term != augGrammar.Eof) {\n TSU.assert(term.isTerminal);\n // This term is in the form [r: T] in the augmented grammar.\n // Get the T from this and add to the look ahead set\n const label = term.label.substring(term.label.indexOf(\":\") + 1, term.label.length - 1).trim();\n const T = grammar.getSym(label);\n TSU.assert(T != null, `T (${label}) in [r:T] cannot be null`);\n itemSet.addLookAhead(item, T);\n }\n });\n });\n }\n }\n}\n\n/**\n * For a grammar G and its LR0 ItemGraph, IG, returns a transformed grammar G'\n * that is based along the transitions of IG.\n *\n * For this new Grammar G' we have:\n *\n * NonTerminals N' = { [p: A] | if Go[p: A] is defined },\n * Terminals T' = { [p: t] | if Go[p: t] is defined },\n * Start Symbol S' = [ Start : S ]\n * Productions P' = { [p1 : A ] -> [p1 : X1][p2 : X2]...[pn : Xn], if\n * [p1 : A] is in N' AND\n * [pi : Xi] is in N' U T' AND\n * A -> X1 X2 .. An is in P (of original grammar G)\n */\nexport function grammarFromLR0ItemGraph(ig: LR0ItemGraph, g: Grammar): Grammar {\n const g2 = new Grammar();\n\n function ensureG2Sym(pi: number, sym: Sym): Sym {\n const newSymLabel = `[${pi}:${sym.label}]`;\n const newSym = g2.ensureSym(new Sym(g2, newSymLabel, sym.isTerminal), false);\n if (pi == 0 && g.startSymbol == sym && g.startSymbol != newSym && !sym.isTerminal) {\n g2.startSymbol = newSym;\n }\n return newSym;\n }\n\n // Create N', T' and S'\n for (const startState in ig.gotoSets) {\n // transitions is a Map of symId -> ItemSet\n const transitions: TSU.NumMap<LRItemSet> = ig.gotoSets[startState];\n for (const symId in transitions) {\n const sym = g.getSymById(symId as any as number)!;\n ensureG2Sym(startState as any as number, sym);\n }\n }\n\n function buildRuleFrom(startSet: number, A: Sym, rule: Rule): Str {\n // Str to be built up for the production in the transformed grammar\n // - [P1:X1][P2:X2]...[Pn:Xn]\n let pi = startSet;\n const newSyms = rule.rhs.syms.map((xi, index) => {\n const nextSym = ensureG2Sym(pi, xi);\n const transitions: TSU.NumMap<LRItemSet> = ig.gotoSets[pi];\n const nextSet = transitions[xi.id] || null;\n TSU.assert(nextSet != null, \"Next set transition *must* be valid\");\n pi = nextSet.id;\n return nextSym;\n });\n return new Str(...newSyms);\n }\n\n for (const startState in ig.gotoSets) {\n // from P1 - for every transition that is a non terminal A\n // find an equivalent chain of transition starting from P1 where we have\n // [P1:X1][P2:X2]...[Pn:Xn]\n // for All A -> X1X2...Xn in G\n const transitions: TSU.NumMap<LRItemSet> = ig.gotoSets[startState];\n for (const symId in transitions) {\n const startSym = g.getSymById(symId as any as number)!;\n const p1 = startState as any as number;\n if (!startSym.isTerminal) {\n const newA = ensureG2Sym(p1, startSym);\n g.forEachRule(startSym, (rule, index) => {\n const newRHS = buildRuleFrom(p1, startSym, rule);\n const newRule = new Rule(newA, newRHS);\n g2.addRule(newRule);\n });\n }\n }\n }\n // Do another pass to evaluate P'\n return g2;\n}\n","const ALIAS = Symbol.for('yaml.alias');\nconst DOC = Symbol.for('yaml.document');\nconst MAP = Symbol.for('yaml.map');\nconst PAIR = Symbol.for('yaml.pair');\nconst SCALAR = Symbol.for('yaml.scalar');\nconst SEQ = Symbol.for('yaml.seq');\nconst NODE_TYPE = Symbol.for('yaml.node.type');\nconst isAlias = (node) => !!node && typeof node === 'object' && node[NODE_TYPE] === ALIAS;\nconst isDocument = (node) => !!node && typeof node === 'object' && node[NODE_TYPE] === DOC;\nconst isMap = (node) => !!node && typeof node === 'object' && node[NODE_TYPE] === MAP;\nconst isPair = (node) => !!node && typeof node === 'object' && node[NODE_TYPE] === PAIR;\nconst isScalar = (node) => !!node && typeof node === 'object' && node[NODE_TYPE] === SCALAR;\nconst isSeq = (node) => !!node && typeof node === 'object' && node[NODE_TYPE] === SEQ;\nfunction isCollection(node) {\n if (node && typeof node === 'object')\n switch (node[NODE_TYPE]) {\n case MAP:\n case SEQ:\n return true;\n }\n return false;\n}\nfunction isNode(node) {\n if (node && typeof node === 'object')\n switch (node[NODE_TYPE]) {\n case ALIAS:\n case MAP:\n case SCALAR:\n case SEQ:\n return true;\n }\n return false;\n}\nconst hasAnchor = (node) => (isScalar(node) || isCollection(node)) && !!node.anchor;\n\nexport { ALIAS, DOC, MAP, NODE_TYPE, PAIR, SCALAR, SEQ, hasAnchor, isAlias, isCollection, isDocument, isMap, isNode, isPair, isScalar, isSeq };\n","import { isDocument, isNode, isPair, isCollection, isMap, isSeq, isScalar, isAlias } from './nodes/identity.js';\n\nconst BREAK = Symbol('break visit');\nconst SKIP = Symbol('skip children');\nconst REMOVE = Symbol('remove node');\n/**\n * Apply a visitor to an AST node or document.\n *\n * Walks through the tree (depth-first) starting from `node`, calling a\n * `visitor` function with three arguments:\n * - `key`: For sequence values and map `Pair`, the node's index in the\n * collection. Within a `Pair`, `'key'` or `'value'`, correspondingly.\n * `null` for the root node.\n * - `node`: The current node.\n * - `path`: The ancestry of the current node.\n *\n * The return value of the visitor may be used to control the traversal:\n * - `undefined` (default): Do nothing and continue\n * - `visit.SKIP`: Do not visit the children of this node, continue with next\n * sibling\n * - `visit.BREAK`: Terminate traversal completely\n * - `visit.REMOVE`: Remove the current node, then continue with the next one\n * - `Node`: Replace the current node, then continue by visiting it\n * - `number`: While iterating the items of a sequence or map, set the index\n * of the next step. This is useful especially if the index of the current\n * node has changed.\n *\n * If `visitor` is a single function, it will be called with all values\n * encountered in the tree, including e.g. `null` values. Alternatively,\n * separate visitor functions may be defined for each `Map`, `Pair`, `Seq`,\n * `Alias` and `Scalar` node. To define the same visitor function for more than\n * one node type, use the `Collection` (map and seq), `Value` (map, seq & scalar)\n * and `Node` (alias, map, seq & scalar) targets. Of all these, only the most\n * specific defined one will be used for each node.\n */\nfunction visit(node, visitor) {\n const visitor_ = initVisitor(visitor);\n if (isDocument(node)) {\n const cd = visit_(null, node.contents, visitor_, Object.freeze([node]));\n if (cd === REMOVE)\n node.contents = null;\n }\n else\n visit_(null, node, visitor_, Object.freeze([]));\n}\n// Without the `as symbol` casts, TS declares these in the `visit`\n// namespace using `var`, but then complains about that because\n// `unique symbol` must be `const`.\n/** Terminate visit traversal completely */\nvisit.BREAK = BREAK;\n/** Do not visit the children of the current node */\nvisit.SKIP = SKIP;\n/** Remove the current node */\nvisit.REMOVE = REMOVE;\nfunction visit_(key, node, visitor, path) {\n const ctrl = callVisitor(key, node, visitor, path);\n if (isNode(ctrl) || isPair(ctrl)) {\n replaceNode(key, path, ctrl);\n return visit_(key, ctrl, visitor, path);\n }\n if (typeof ctrl !== 'symbol') {\n if (isCollection(node)) {\n path = Object.freeze(path.concat(node));\n for (let i = 0; i < node.items.length; ++i) {\n const ci = visit_(i, node.items[i], visitor, path);\n if (typeof ci === 'number')\n i = ci - 1;\n else if (ci === BREAK)\n return BREAK;\n else if (ci === REMOVE) {\n node.items.splice(i, 1);\n i -= 1;\n }\n }\n }\n else if (isPair(node)) {\n path = Object.freeze(path.concat(node));\n const ck = visit_('key', node.key, visitor, path);\n if (ck === BREAK)\n return BREAK;\n else if (ck === REMOVE)\n node.key = null;\n const cv = visit_('value', node.value, visitor, path);\n if (cv === BREAK)\n return BREAK;\n else if (cv === REMOVE)\n node.value = null;\n }\n }\n return ctrl;\n}\n/**\n * Apply an async visitor to an AST node or document.\n *\n * Walks through the tree (depth-first) starting from `node`, calling a\n * `visitor` function with three arguments:\n * - `key`: For sequence values and map `Pair`, the node's index in the\n * collection. Within a `Pair`, `'key'` or `'value'`, correspondingly.\n * `null` for the root node.\n * - `node`: The current node.\n * - `path`: The ancestry of the current node.\n *\n * The return value of the visitor may be used to control the traversal:\n * - `Promise`: Must resolve to one of the following values\n * - `undefined` (default): Do nothing and continue\n * - `visit.SKIP`: Do not visit the children of this node, continue with next\n * sibling\n * - `visit.BREAK`: Terminate traversal completely\n * - `visit.REMOVE`: Remove the current node, then continue with the next one\n * - `Node`: Replace the current node, then continue by visiting it\n * - `number`: While iterating the items of a sequence or map, set the index\n * of the next step. This is useful especially if the index of the current\n * node has changed.\n *\n * If `visitor` is a single function, it will be called with all values\n * encountered in the tree, including e.g. `null` values. Alternatively,\n * separate visitor functions may be defined for each `Map`, `Pair`, `Seq`,\n * `Alias` and `Scalar` node. To define the same visitor function for more than\n * one node type, use the `Collection` (map and seq), `Value` (map, seq & scalar)\n * and `Node` (alias, map, seq & scalar) targets. Of all these, only the most\n * specific defined one will be used for each node.\n */\nasync function visitAsync(node, visitor) {\n const visitor_ = initVisitor(visitor);\n if (isDocument(node)) {\n const cd = await visitAsync_(null, node.contents, visitor_, Object.freeze([node]));\n if (cd === REMOVE)\n node.contents = null;\n }\n else\n await visitAsync_(null, node, visitor_, Object.freeze([]));\n}\n// Without the `as symbol` casts, TS declares these in the `visit`\n// namespace using `var`, but then complains about that because\n// `unique symbol` must be `const`.\n/** Terminate visit traversal completely */\nvisitAsync.BREAK = BREAK;\n/** Do not visit the children of the current node */\nvisitAsync.SKIP = SKIP;\n/** Remove the current node */\nvisitAsync.REMOVE = REMOVE;\nasync function visitAsync_(key, node, visitor, path) {\n const ctrl = await callVisitor(key, node, visitor, path);\n if (isNode(ctrl) || isPair(ctrl)) {\n replaceNode(key, path, ctrl);\n return visitAsync_(key, ctrl, visitor, path);\n }\n if (typeof ctrl !== 'symbol') {\n if (isCollection(node)) {\n path = Object.freeze(path.concat(node));\n for (let i = 0; i < node.items.length; ++i) {\n const ci = await visitAsync_(i, node.items[i], visitor, path);\n if (typeof ci === 'number')\n i = ci - 1;\n else if (ci === BREAK)\n return BREAK;\n else if (ci === REMOVE) {\n node.items.splice(i, 1);\n i -= 1;\n }\n }\n }\n else if (isPair(node)) {\n path = Object.freeze(path.concat(node));\n const ck = await visitAsync_('key', node.key, visitor, path);\n if (ck === BREAK)\n return BREAK;\n else if (ck === REMOVE)\n node.key = null;\n const cv = await visitAsync_('value', node.value, visitor, path);\n if (cv === BREAK)\n return BREAK;\n else if (cv === REMOVE)\n node.value = null;\n }\n }\n return ctrl;\n}\nfunction initVisitor(visitor) {\n if (typeof visitor === 'object' &&\n (visitor.Collection || visitor.Node || visitor.Value)) {\n return Object.assign({\n Alias: visitor.Node,\n Map: visitor.Node,\n Scalar: visitor.Node,\n Seq: visitor.Node\n }, visitor.Value && {\n Map: visitor.Value,\n Scalar: visitor.Value,\n Seq: visitor.Value\n }, visitor.Collection && {\n Map: visitor.Collection,\n Seq: visitor.Collection\n }, visitor);\n }\n return visitor;\n}\nfunction callVisitor(key, node, visitor, path) {\n if (typeof visitor === 'function')\n return visitor(key, node, path);\n if (isMap(node))\n return visitor.Map?.(key, node, path);\n if (isSeq(node))\n return visitor.Seq?.(key, node, path);\n if (isPair(node))\n return visitor.Pair?.(key, node, path);\n if (isScalar(node))\n return visitor.Scalar?.(key, node, path);\n if (isAlias(node))\n return visitor.Alias?.(key, node, path);\n return undefined;\n}\nfunction replaceNode(key, path, node) {\n const parent = path[path.length - 1];\n if (isCollection(parent)) {\n parent.items[key] = node;\n }\n else if (isPair(parent)) {\n if (key === 'key')\n parent.key = node;\n else\n parent.value = node;\n }\n else if (isDocument(parent)) {\n parent.contents = node;\n }\n else {\n const pt = isAlias(parent) ? 'alias' : 'scalar';\n throw new Error(`Cannot replace node with ${pt} parent`);\n }\n}\n\nexport { visit, visitAsync };\n","import { isNode } from '../nodes/identity.js';\nimport { visit } from '../visit.js';\n\nconst escapeChars = {\n '!': '%21',\n ',': '%2C',\n '[': '%5B',\n ']': '%5D',\n '{': '%7B',\n '}': '%7D'\n};\nconst escapeTagName = (tn) => tn.replace(/[!,[\\]{}]/g, ch => escapeChars[ch]);\nclass Directives {\n constructor(yaml, tags) {\n /**\n * The directives-end/doc-start marker `---`. If `null`, a marker may still be\n * included in the document's stringified representation.\n */\n this.docStart = null;\n /** The doc-end marker `...`. */\n this.docEnd = false;\n this.yaml = Object.assign({}, Directives.defaultYaml, yaml);\n this.tags = Object.assign({}, Directives.defaultTags, tags);\n }\n clone() {\n const copy = new Directives(this.yaml, this.tags);\n copy.docStart = this.docStart;\n return copy;\n }\n /**\n * During parsing, get a Directives instance for the current document and\n * update the stream state according to the current version's spec.\n */\n atDocument() {\n const res = new Directives(this.yaml, this.tags);\n switch (this.yaml.version) {\n case '1.1':\n this.atNextDocument = true;\n break;\n case '1.2':\n this.atNextDocument = false;\n this.yaml = {\n explicit: Directives.defaultYaml.explicit,\n version: '1.2'\n };\n this.tags = Object.assign({}, Directives.defaultTags);\n break;\n }\n return res;\n }\n /**\n * @param onError - May be called even if the action was successful\n * @returns `true` on success\n */\n add(line, onError) {\n if (this.atNextDocument) {\n this.yaml = { explicit: Directives.defaultYaml.explicit, version: '1.1' };\n this.tags = Object.assign({}, Directives.defaultTags);\n this.atNextDocument = false;\n }\n const parts = line.trim().split(/[ \\t]+/);\n const name = parts.shift();\n switch (name) {\n case '%TAG': {\n if (parts.length !== 2) {\n onError(0, '%TAG directive should contain exactly two parts');\n if (parts.length < 2)\n return false;\n }\n const [handle, prefix] = parts;\n this.tags[handle] = prefix;\n return true;\n }\n case '%YAML': {\n this.yaml.explicit = true;\n if (parts.length !== 1) {\n onError(0, '%YAML directive should contain exactly one part');\n return false;\n }\n const [version] = parts;\n if (version === '1.1' || version === '1.2') {\n this.yaml.version = version;\n return true;\n }\n else {\n const isValid = /^\\d+\\.\\d+$/.test(version);\n onError(6, `Unsupported YAML version ${version}`, isValid);\n return false;\n }\n }\n default:\n onError(0, `Unknown directive ${name}`, true);\n return false;\n }\n }\n /**\n * Resolves a tag, matching handles to those defined in %TAG directives.\n *\n * @returns Resolved tag, which may also be the non-specific tag `'!'` or a\n * `'!local'` tag, or `null` if unresolvable.\n */\n tagName(source, onError) {\n if (source === '!')\n return '!'; // non-specific tag\n if (source[0] !== '!') {\n onError(`Not a valid tag: ${source}`);\n return null;\n }\n if (source[1] === '<') {\n const verbatim = source.slice(2, -1);\n if (verbatim === '!' || verbatim === '!!') {\n onError(`Verbatim tags aren't resolved, so ${source} is invalid.`);\n return null;\n }\n if (source[source.length - 1] !== '>')\n onError('Verbatim tags must end with a >');\n return verbatim;\n }\n const [, handle, suffix] = source.match(/^(.*!)([^!]*)$/s);\n if (!suffix)\n onError(`The ${source} tag has no suffix`);\n const prefix = this.tags[handle];\n if (prefix) {\n try {\n return prefix + decodeURIComponent(suffix);\n }\n catch (error) {\n onError(String(error));\n return null;\n }\n }\n if (handle === '!')\n return source; // local tag\n onError(`Could not resolve tag: ${source}`);\n return null;\n }\n /**\n * Given a fully resolved tag, returns its printable string form,\n * taking into account current tag prefixes and defaults.\n */\n tagString(tag) {\n for (const [handle, prefix] of Object.entries(this.tags)) {\n if (tag.startsWith(prefix))\n return handle + escapeTagName(tag.substring(prefix.length));\n }\n return tag[0] === '!' ? tag : `!<${tag}>`;\n }\n toString(doc) {\n const lines = this.yaml.explicit\n ? [`%YAML ${this.yaml.version || '1.2'}`]\n : [];\n const tagEntries = Object.entries(this.tags);\n let tagNames;\n if (doc && tagEntries.length > 0 && isNode(doc.contents)) {\n const tags = {};\n visit(doc.contents, (_key, node) => {\n if (isNode(node) && node.tag)\n tags[node.tag] = true;\n });\n tagNames = Object.keys(tags);\n }\n else\n tagNames = [];\n for (const [handle, prefix] of tagEntries) {\n if (handle === '!!' && prefix === 'tag:yaml.org,2002:')\n continue;\n if (!doc || tagNames.some(tn => tn.startsWith(prefix)))\n lines.push(`%TAG ${handle} ${prefix}`);\n }\n return lines.join('\\n');\n }\n}\nDirectives.defaultYaml = { explicit: false, version: '1.2' };\nDirectives.defaultTags = { '!!': 'tag:yaml.org,2002:' };\n\nexport { Directives };\n","import { isScalar, isCollection } from '../nodes/identity.js';\nimport { visit } from '../visit.js';\n\n/**\n * Verify that the input string is a valid anchor.\n *\n * Will throw on errors.\n */\nfunction anchorIsValid(anchor) {\n if (/[\\x00-\\x19\\s,[\\]{}]/.test(anchor)) {\n const sa = JSON.stringify(anchor);\n const msg = `Anchor must not contain whitespace or control characters: ${sa}`;\n throw new Error(msg);\n }\n return true;\n}\nfunction anchorNames(root) {\n const anchors = new Set();\n visit(root, {\n Value(_key, node) {\n if (node.anchor)\n anchors.add(node.anchor);\n }\n });\n return anchors;\n}\n/** Find a new anchor name with the given `prefix` and a one-indexed suffix. */\nfunction findNewAnchor(prefix, exclude) {\n for (let i = 1; true; ++i) {\n const name = `${prefix}${i}`;\n if (!exclude.has(name))\n return name;\n }\n}\nfunction createNodeAnchors(doc, prefix) {\n const aliasObjects = [];\n const sourceObjects = new Map();\n let prevAnchors = null;\n return {\n onAnchor: (source) => {\n aliasObjects.push(source);\n prevAnchors ?? (prevAnchors = anchorNames(doc));\n const anchor = findNewAnchor(prefix, prevAnchors);\n prevAnchors.add(anchor);\n return anchor;\n },\n /**\n * With circular references, the source node is only resolved after all\n * of its child nodes are. This is why anchors are set only after all of\n * the nodes have been created.\n */\n setAnchors: () => {\n for (const source of aliasObjects) {\n const ref = sourceObjects.get(source);\n if (typeof ref === 'object' &&\n ref.anchor &&\n (isScalar(ref.node) || isCollection(ref.node))) {\n ref.node.anchor = ref.anchor;\n }\n else {\n const error = new Error('Failed to resolve repeated object (this should not happen)');\n error.source = source;\n throw error;\n }\n }\n },\n sourceObjects\n };\n}\n\nexport { anchorIsValid, anchorNames, createNodeAnchors, findNewAnchor };\n","/**\n * Applies the JSON.parse reviver algorithm as defined in the ECMA-262 spec,\n * in section 24.5.1.1 \"Runtime Semantics: InternalizeJSONProperty\" of the\n * 2021 edition: https://tc39.es/ecma262/#sec-json.parse\n *\n * Includes extensions for handling Map and Set objects.\n */\nfunction applyReviver(reviver, obj, key, val) {\n if (val && typeof val === 'object') {\n if (Array.isArray(val)) {\n for (let i = 0, len = val.length; i < len; ++i) {\n const v0 = val[i];\n const v1 = applyReviver(reviver, val, String(i), v0);\n // eslint-disable-next-line @typescript-eslint/no-array-delete\n if (v1 === undefined)\n delete val[i];\n else if (v1 !== v0)\n val[i] = v1;\n }\n }\n else if (val instanceof Map) {\n for (const k of Array.from(val.keys())) {\n const v0 = val.get(k);\n const v1 = applyReviver(reviver, val, k, v0);\n if (v1 === undefined)\n val.delete(k);\n else if (v1 !== v0)\n val.set(k, v1);\n }\n }\n else if (val instanceof Set) {\n for (const v0 of Array.from(val)) {\n const v1 = applyReviver(reviver, val, v0, v0);\n if (v1 === undefined)\n val.delete(v0);\n else if (v1 !== v0) {\n val.delete(v0);\n val.add(v1);\n }\n }\n }\n else {\n for (const [k, v0] of Object.entries(val)) {\n const v1 = applyReviver(reviver, val, k, v0);\n if (v1 === undefined)\n delete val[k];\n else if (v1 !== v0)\n val[k] = v1;\n }\n }\n }\n return reviver.call(obj, key, val);\n}\n\nexport { applyReviver };\n","import { hasAnchor } from './identity.js';\n\n/**\n * Recursively convert any node or its contents to native JavaScript\n *\n * @param value - The input value\n * @param arg - If `value` defines a `toJSON()` method, use this\n * as its first argument\n * @param ctx - Conversion context, originally set in Document#toJS(). If\n * `{ keep: true }` is not set, output should be suitable for JSON\n * stringification.\n */\nfunction toJS(value, arg, ctx) {\n // eslint-disable-next-line @typescript-eslint/no-unsafe-return\n if (Array.isArray(value))\n return value.map((v, i) => toJS(v, String(i), ctx));\n if (value && typeof value.toJSON === 'function') {\n // eslint-disable-next-line @typescript-eslint/no-unsafe-call\n if (!ctx || !hasAnchor(value))\n return value.toJSON(arg, ctx);\n const data = { aliasCount: 0, count: 1, res: undefined };\n ctx.anchors.set(value, data);\n ctx.onCreate = res => {\n data.res = res;\n delete ctx.onCreate;\n };\n const res = value.toJSON(arg, ctx);\n if (ctx.onCreate)\n ctx.onCreate(res);\n return res;\n }\n if (typeof value === 'bigint' && !ctx?.keep)\n return Number(value);\n return value;\n}\n\nexport { toJS };\n","import { applyReviver } from '../doc/applyReviver.js';\nimport { NODE_TYPE, isDocument } from './identity.js';\nimport { toJS } from './toJS.js';\n\nclass NodeBase {\n constructor(type) {\n Object.defineProperty(this, NODE_TYPE, { value: type });\n }\n /** Create a copy of this node. */\n clone() {\n const copy = Object.create(Object.getPrototypeOf(this), Object.getOwnPropertyDescriptors(this));\n if (this.range)\n copy.range = this.range.slice();\n return copy;\n }\n /** A plain JavaScript representation of this node. */\n toJS(doc, { mapAsMap, maxAliasCount, onAnchor, reviver } = {}) {\n if (!isDocument(doc))\n throw new TypeError('A document argument is required');\n const ctx = {\n anchors: new Map(),\n doc,\n keep: true,\n mapAsMap: mapAsMap === true,\n mapKeyWarned: false,\n maxAliasCount: typeof maxAliasCount === 'number' ? maxAliasCount : 100\n };\n const res = toJS(this, '', ctx);\n if (typeof onAnchor === 'function')\n for (const { count, res } of ctx.anchors.values())\n onAnchor(res, count);\n return typeof reviver === 'function'\n ? applyReviver(reviver, { '': res }, '', res)\n : res;\n }\n}\n\nexport { NodeBase };\n","import { anchorIsValid } from '../doc/anchors.js';\nimport { visit } from '../visit.js';\nimport { ALIAS, isAlias, isCollection, isPair, hasAnchor } from './identity.js';\nimport { NodeBase } from './Node.js';\nimport { toJS } from './toJS.js';\n\nclass Alias extends NodeBase {\n constructor(source) {\n super(ALIAS);\n this.source = source;\n Object.defineProperty(this, 'tag', {\n set() {\n throw new Error('Alias nodes cannot have tags');\n }\n });\n }\n /**\n * Resolve the value of this alias within `doc`, finding the last\n * instance of the `source` anchor before this node.\n */\n resolve(doc, ctx) {\n let nodes;\n if (ctx?.aliasResolveCache) {\n nodes = ctx.aliasResolveCache;\n }\n else {\n nodes = [];\n visit(doc, {\n Node: (_key, node) => {\n if (isAlias(node) || hasAnchor(node))\n nodes.push(node);\n }\n });\n if (ctx)\n ctx.aliasResolveCache = nodes;\n }\n let found = undefined;\n for (const node of nodes) {\n if (node === this)\n break;\n if (node.anchor === this.source)\n found = node;\n }\n return found;\n }\n toJSON(_arg, ctx) {\n if (!ctx)\n return { source: this.source };\n const { anchors, doc, maxAliasCount } = ctx;\n const source = this.resolve(doc, ctx);\n if (!source) {\n const msg = `Unresolved alias (the anchor must be set before the alias): ${this.source}`;\n throw new ReferenceError(msg);\n }\n let data = anchors.get(source);\n if (!data) {\n // Resolve anchors for Node.prototype.toJS()\n toJS(source, null, ctx);\n data = anchors.get(source);\n }\n /* istanbul ignore if */\n if (data?.res === undefined) {\n const msg = 'This should not happen: Alias anchor was not resolved?';\n throw new ReferenceError(msg);\n }\n if (maxAliasCount >= 0) {\n data.count += 1;\n if (data.aliasCount === 0)\n data.aliasCount = getAliasCount(doc, source, anchors);\n if (data.count * data.aliasCount > maxAliasCount) {\n const msg = 'Excessive alias count indicates a resource exhaustion attack';\n throw new ReferenceError(msg);\n }\n }\n return data.res;\n }\n toString(ctx, _onComment, _onChompKeep) {\n const src = `*${this.source}`;\n if (ctx) {\n anchorIsValid(this.source);\n if (ctx.options.verifyAliasOrder && !ctx.anchors.has(this.source)) {\n const msg = `Unresolved alias (the anchor must be set before the alias): ${this.source}`;\n throw new Error(msg);\n }\n if (ctx.implicitKey)\n return `${src} `;\n }\n return src;\n }\n}\nfunction getAliasCount(doc, node, anchors) {\n if (isAlias(node)) {\n const source = node.resolve(doc);\n const anchor = anchors && source && anchors.get(source);\n return anchor ? anchor.count * anchor.aliasCount : 0;\n }\n else if (isCollection(node)) {\n let count = 0;\n for (const item of node.items) {\n const c = getAliasCount(doc, item, anchors);\n if (c > count)\n count = c;\n }\n return count;\n }\n else if (isPair(node)) {\n const kc = getAliasCount(doc, node.key, anchors);\n const vc = getAliasCount(doc, node.value, anchors);\n return Math.max(kc, vc);\n }\n return 1;\n}\n\nexport { Alias };\n","import { SCALAR } from './identity.js';\nimport { NodeBase } from './Node.js';\nimport { toJS } from './toJS.js';\n\nconst isScalarValue = (value) => !value || (typeof value !== 'function' && typeof value !== 'object');\nclass Scalar extends NodeBase {\n constructor(value) {\n super(SCALAR);\n this.value = value;\n }\n toJSON(arg, ctx) {\n return ctx?.keep ? this.value : toJS(this.value, arg, ctx);\n }\n toString() {\n return String(this.value);\n }\n}\nScalar.BLOCK_FOLDED = 'BLOCK_FOLDED';\nScalar.BLOCK_LITERAL = 'BLOCK_LITERAL';\nScalar.PLAIN = 'PLAIN';\nScalar.QUOTE_DOUBLE = 'QUOTE_DOUBLE';\nScalar.QUOTE_SINGLE = 'QUOTE_SINGLE';\n\nexport { Scalar, isScalarValue };\n","import { Alias } from '../nodes/Alias.js';\nimport { isNode, isPair, MAP, SEQ, isDocument } from '../nodes/identity.js';\nimport { Scalar } from '../nodes/Scalar.js';\n\nconst defaultTagPrefix = 'tag:yaml.org,2002:';\nfunction findTagObject(value, tagName, tags) {\n if (tagName) {\n const match = tags.filter(t => t.tag === tagName);\n const tagObj = match.find(t => !t.format) ?? match[0];\n if (!tagObj)\n throw new Error(`Tag ${tagName} not found`);\n return tagObj;\n }\n return tags.find(t => t.identify?.(value) && !t.format);\n}\nfunction createNode(value, tagName, ctx) {\n if (isDocument(value))\n value = value.contents;\n if (isNode(value))\n return value;\n if (isPair(value)) {\n const map = ctx.schema[MAP].createNode?.(ctx.schema, null, ctx);\n map.items.push(value);\n return map;\n }\n if (value instanceof String ||\n value instanceof Number ||\n value instanceof Boolean ||\n (typeof BigInt !== 'undefined' && value instanceof BigInt) // not supported everywhere\n ) {\n // https://tc39.es/ecma262/#sec-serializejsonproperty\n value = value.valueOf();\n }\n const { aliasDuplicateObjects, onAnchor, onTagObj, schema, sourceObjects } = ctx;\n // Detect duplicate references to the same object & use Alias nodes for all\n // after first. The `ref` wrapper allows for circular references to resolve.\n let ref = undefined;\n if (aliasDuplicateObjects && value && typeof value === 'object') {\n ref = sourceObjects.get(value);\n if (ref) {\n ref.anchor ?? (ref.anchor = onAnchor(value));\n return new Alias(ref.anchor);\n }\n else {\n ref = { anchor: null, node: null };\n sourceObjects.set(value, ref);\n }\n }\n if (tagName?.startsWith('!!'))\n tagName = defaultTagPrefix + tagName.slice(2);\n let tagObj = findTagObject(value, tagName, schema.tags);\n if (!tagObj) {\n if (value && typeof value.toJSON === 'function') {\n // eslint-disable-next-line @typescript-eslint/no-unsafe-call\n value = value.toJSON();\n }\n if (!value || typeof value !== 'object') {\n const node = new Scalar(value);\n if (ref)\n ref.node = node;\n return node;\n }\n tagObj =\n value instanceof Map\n ? schema[MAP]\n : Symbol.iterator in Object(value)\n ? schema[SEQ]\n : schema[MAP];\n }\n if (onTagObj) {\n onTagObj(tagObj);\n delete ctx.onTagObj;\n }\n const node = tagObj?.createNode\n ? tagObj.createNode(ctx.schema, value, ctx)\n : typeof tagObj?.nodeClass?.from === 'function'\n ? tagObj.nodeClass.from(ctx.schema, value, ctx)\n : new Scalar(value);\n if (tagName)\n node.tag = tagName;\n else if (!tagObj.default)\n node.tag = tagObj.tag;\n if (ref)\n ref.node = node;\n return node;\n}\n\nexport { createNode };\n","import { createNode } from '../doc/createNode.js';\nimport { isNode, isPair, isCollection, isScalar } from './identity.js';\nimport { NodeBase } from './Node.js';\n\nfunction collectionFromPath(schema, path, value) {\n let v = value;\n for (let i = path.length - 1; i >= 0; --i) {\n const k = path[i];\n if (typeof k === 'number' && Number.isInteger(k) && k >= 0) {\n const a = [];\n a[k] = v;\n v = a;\n }\n else {\n v = new Map([[k, v]]);\n }\n }\n return createNode(v, undefined, {\n aliasDuplicateObjects: false,\n keepUndefined: false,\n onAnchor: () => {\n throw new Error('This should not happen, please report a bug.');\n },\n schema,\n sourceObjects: new Map()\n });\n}\n// Type guard is intentionally a little wrong so as to be more useful,\n// as it does not cover untypable empty non-string iterables (e.g. []).\nconst isEmptyPath = (path) => path == null ||\n (typeof path === 'object' && !!path[Symbol.iterator]().next().done);\nclass Collection extends NodeBase {\n constructor(type, schema) {\n super(type);\n Object.defineProperty(this, 'schema', {\n value: schema,\n configurable: true,\n enumerable: false,\n writable: true\n });\n }\n /**\n * Create a copy of this collection.\n *\n * @param schema - If defined, overwrites the original's schema\n */\n clone(schema) {\n const copy = Object.create(Object.getPrototypeOf(this), Object.getOwnPropertyDescriptors(this));\n if (schema)\n copy.schema = schema;\n copy.items = copy.items.map(it => isNode(it) || isPair(it) ? it.clone(schema) : it);\n if (this.range)\n copy.range = this.range.slice();\n return copy;\n }\n /**\n * Adds a value to the collection. For `!!map` and `!!omap` the value must\n * be a Pair instance or a `{ key, value }` object, which may not have a key\n * that already exists in the map.\n */\n addIn(path, value) {\n if (isEmptyPath(path))\n this.add(value);\n else {\n const [key, ...rest] = path;\n const node = this.get(key, true);\n if (isCollection(node))\n node.addIn(rest, value);\n else if (node === undefined && this.schema)\n this.set(key, collectionFromPath(this.schema, rest, value));\n else\n throw new Error(`Expected YAML collection at ${key}. Remaining path: ${rest}`);\n }\n }\n /**\n * Removes a value from the collection.\n * @returns `true` if the item was found and removed.\n */\n deleteIn(path) {\n const [key, ...rest] = path;\n if (rest.length === 0)\n return this.delete(key);\n const node = this.get(key, true);\n if (isCollection(node))\n return node.deleteIn(rest);\n else\n throw new Error(`Expected YAML collection at ${key}. Remaining path: ${rest}`);\n }\n /**\n * Returns item at `key`, or `undefined` if not found. By default unwraps\n * scalar values from their surrounding node; to disable set `keepScalar` to\n * `true` (collections are always returned intact).\n */\n getIn(path, keepScalar) {\n const [key, ...rest] = path;\n const node = this.get(key, true);\n if (rest.length === 0)\n return !keepScalar && isScalar(node) ? node.value : node;\n else\n return isCollection(node) ? node.getIn(rest, keepScalar) : undefined;\n }\n hasAllNullValues(allowScalar) {\n return this.items.every(node => {\n if (!isPair(node))\n return false;\n const n = node.value;\n return (n == null ||\n (allowScalar &&\n isScalar(n) &&\n n.value == null &&\n !n.commentBefore &&\n !n.comment &&\n !n.tag));\n });\n }\n /**\n * Checks if the collection includes a value with the key `key`.\n */\n hasIn(path) {\n const [key, ...rest] = path;\n if (rest.length === 0)\n return this.has(key);\n const node = this.get(key, true);\n return isCollection(node) ? node.hasIn(rest) : false;\n }\n /**\n * Sets a value in this collection. For `!!set`, `value` needs to be a\n * boolean to add/remove the item from the set.\n */\n setIn(path, value) {\n const [key, ...rest] = path;\n if (rest.length === 0) {\n this.set(key, value);\n }\n else {\n const node = this.get(key, true);\n if (isCollection(node))\n node.setIn(rest, value);\n else if (node === undefined && this.schema)\n this.set(key, collectionFromPath(this.schema, rest, value));\n else\n throw new Error(`Expected YAML collection at ${key}. Remaining path: ${rest}`);\n }\n }\n}\n\nexport { Collection, collectionFromPath, isEmptyPath };\n","/**\n * Stringifies a comment.\n *\n * Empty comment lines are left empty,\n * lines consisting of a single space are replaced by `#`,\n * and all other lines are prefixed with a `#`.\n */\nconst stringifyComment = (str) => str.replace(/^(?!$)(?: $)?/gm, '#');\nfunction indentComment(comment, indent) {\n if (/^\\n+$/.test(comment))\n return comment.substring(1);\n return indent ? comment.replace(/^(?! *$)/gm, indent) : comment;\n}\nconst lineComment = (str, indent, comment) => str.endsWith('\\n')\n ? indentComment(comment, indent)\n : comment.includes('\\n')\n ? '\\n' + indentComment(comment, indent)\n : (str.endsWith(' ') ? '' : ' ') + comment;\n\nexport { indentComment, lineComment, stringifyComment };\n","const FOLD_FLOW = 'flow';\nconst FOLD_BLOCK = 'block';\nconst FOLD_QUOTED = 'quoted';\n/**\n * Tries to keep input at up to `lineWidth` characters, splitting only on spaces\n * not followed by newlines or spaces unless `mode` is `'quoted'`. Lines are\n * terminated with `\\n` and started with `indent`.\n */\nfunction foldFlowLines(text, indent, mode = 'flow', { indentAtStart, lineWidth = 80, minContentWidth = 20, onFold, onOverflow } = {}) {\n if (!lineWidth || lineWidth < 0)\n return text;\n if (lineWidth < minContentWidth)\n minContentWidth = 0;\n const endStep = Math.max(1 + minContentWidth, 1 + lineWidth - indent.length);\n if (text.length <= endStep)\n return text;\n const folds = [];\n const escapedFolds = {};\n let end = lineWidth - indent.length;\n if (typeof indentAtStart === 'number') {\n if (indentAtStart > lineWidth - Math.max(2, minContentWidth))\n folds.push(0);\n else\n end = lineWidth - indentAtStart;\n }\n let split = undefined;\n let prev = undefined;\n let overflow = false;\n let i = -1;\n let escStart = -1;\n let escEnd = -1;\n if (mode === FOLD_BLOCK) {\n i = consumeMoreIndentedLines(text, i, indent.length);\n if (i !== -1)\n end = i + endStep;\n }\n for (let ch; (ch = text[(i += 1)]);) {\n if (mode === FOLD_QUOTED && ch === '\\\\') {\n escStart = i;\n switch (text[i + 1]) {\n case 'x':\n i += 3;\n break;\n case 'u':\n i += 5;\n break;\n case 'U':\n i += 9;\n break;\n default:\n i += 1;\n }\n escEnd = i;\n }\n if (ch === '\\n') {\n if (mode === FOLD_BLOCK)\n i = consumeMoreIndentedLines(text, i, indent.length);\n end = i + indent.length + endStep;\n split = undefined;\n }\n else {\n if (ch === ' ' &&\n prev &&\n prev !== ' ' &&\n prev !== '\\n' &&\n prev !== '\\t') {\n // space surrounded by non-space can be replaced with newline + indent\n const next = text[i + 1];\n if (next && next !== ' ' && next !== '\\n' && next !== '\\t')\n split = i;\n }\n if (i >= end) {\n if (split) {\n folds.push(split);\n end = split + endStep;\n split = undefined;\n }\n else if (mode === FOLD_QUOTED) {\n // white-space collected at end may stretch past lineWidth\n while (prev === ' ' || prev === '\\t') {\n prev = ch;\n ch = text[(i += 1)];\n overflow = true;\n }\n // Account for newline escape, but don't break preceding escape\n const j = i > escEnd + 1 ? i - 2 : escStart - 1;\n // Bail out if lineWidth & minContentWidth are shorter than an escape string\n if (escapedFolds[j])\n return text;\n folds.push(j);\n escapedFolds[j] = true;\n end = j + endStep;\n split = undefined;\n }\n else {\n overflow = true;\n }\n }\n }\n prev = ch;\n }\n if (overflow && onOverflow)\n onOverflow();\n if (folds.length === 0)\n return text;\n if (onFold)\n onFold();\n let res = text.slice(0, folds[0]);\n for (let i = 0; i < folds.length; ++i) {\n const fold = folds[i];\n const end = folds[i + 1] || text.length;\n if (fold === 0)\n res = `\\n${indent}${text.slice(0, end)}`;\n else {\n if (mode === FOLD_QUOTED && escapedFolds[fold])\n res += `${text[fold]}\\\\`;\n res += `\\n${indent}${text.slice(fold + 1, end)}`;\n }\n }\n return res;\n}\n/**\n * Presumes `i + 1` is at the start of a line\n * @returns index of last newline in more-indented block\n */\nfunction consumeMoreIndentedLines(text, i, indent) {\n let end = i;\n let start = i + 1;\n let ch = text[start];\n while (ch === ' ' || ch === '\\t') {\n if (i < start + indent) {\n ch = text[++i];\n }\n else {\n do {\n ch = text[++i];\n } while (ch && ch !== '\\n');\n end = i;\n start = i + 1;\n ch = text[start];\n }\n }\n return end;\n}\n\nexport { FOLD_BLOCK, FOLD_FLOW, FOLD_QUOTED, foldFlowLines };\n","import { Scalar } from '../nodes/Scalar.js';\nimport { foldFlowLines, FOLD_FLOW, FOLD_QUOTED, FOLD_BLOCK } from './foldFlowLines.js';\n\nconst getFoldOptions = (ctx, isBlock) => ({\n indentAtStart: isBlock ? ctx.indent.length : ctx.indentAtStart,\n lineWidth: ctx.options.lineWidth,\n minContentWidth: ctx.options.minContentWidth\n});\n// Also checks for lines starting with %, as parsing the output as YAML 1.1 will\n// presume that's starting a new document.\nconst containsDocumentMarker = (str) => /^(%|---|\\.\\.\\.)/m.test(str);\nfunction lineLengthOverLimit(str, lineWidth, indentLength) {\n if (!lineWidth || lineWidth < 0)\n return false;\n const limit = lineWidth - indentLength;\n const strLen = str.length;\n if (strLen <= limit)\n return false;\n for (let i = 0, start = 0; i < strLen; ++i) {\n if (str[i] === '\\n') {\n if (i - start > limit)\n return true;\n start = i + 1;\n if (strLen - start <= limit)\n return false;\n }\n }\n return true;\n}\nfunction doubleQuotedString(value, ctx) {\n const json = JSON.stringify(value);\n if (ctx.options.doubleQuotedAsJSON)\n return json;\n const { implicitKey } = ctx;\n const minMultiLineLength = ctx.options.doubleQuotedMinMultiLineLength;\n const indent = ctx.indent || (containsDocumentMarker(value) ? ' ' : '');\n let str = '';\n let start = 0;\n for (let i = 0, ch = json[i]; ch; ch = json[++i]) {\n if (ch === ' ' && json[i + 1] === '\\\\' && json[i + 2] === 'n') {\n // space before newline needs to be escaped to not be folded\n str += json.slice(start, i) + '\\\\ ';\n i += 1;\n start = i;\n ch = '\\\\';\n }\n if (ch === '\\\\')\n switch (json[i + 1]) {\n case 'u':\n {\n str += json.slice(start, i);\n const code = json.substr(i + 2, 4);\n switch (code) {\n case '0000':\n str += '\\\\0';\n break;\n case '0007':\n str += '\\\\a';\n break;\n case '000b':\n str += '\\\\v';\n break;\n case '001b':\n str += '\\\\e';\n break;\n case '0085':\n str += '\\\\N';\n break;\n case '00a0':\n str += '\\\\_';\n break;\n case '2028':\n str += '\\\\L';\n break;\n case '2029':\n str += '\\\\P';\n break;\n default:\n if (code.substr(0, 2) === '00')\n str += '\\\\x' + code.substr(2);\n else\n str += json.substr(i, 6);\n }\n i += 5;\n start = i + 1;\n }\n break;\n case 'n':\n if (implicitKey ||\n json[i + 2] === '\"' ||\n json.length < minMultiLineLength) {\n i += 1;\n }\n else {\n // folding will eat first newline\n str += json.slice(start, i) + '\\n\\n';\n while (json[i + 2] === '\\\\' &&\n json[i + 3] === 'n' &&\n json[i + 4] !== '\"') {\n str += '\\n';\n i += 2;\n }\n str += indent;\n // space after newline needs to be escaped to not be folded\n if (json[i + 2] === ' ')\n str += '\\\\';\n i += 1;\n start = i + 1;\n }\n break;\n default:\n i += 1;\n }\n }\n str = start ? str + json.slice(start) : json;\n return implicitKey\n ? str\n : foldFlowLines(str, indent, FOLD_QUOTED, getFoldOptions(ctx, false));\n}\nfunction singleQuotedString(value, ctx) {\n if (ctx.options.singleQuote === false ||\n (ctx.implicitKey && value.includes('\\n')) ||\n /[ \\t]\\n|\\n[ \\t]/.test(value) // single quoted string can't have leading or trailing whitespace around newline\n )\n return doubleQuotedString(value, ctx);\n const indent = ctx.indent || (containsDocumentMarker(value) ? ' ' : '');\n const res = \"'\" + value.replace(/'/g, \"''\").replace(/\\n+/g, `$&\\n${indent}`) + \"'\";\n return ctx.implicitKey\n ? res\n : foldFlowLines(res, indent, FOLD_FLOW, getFoldOptions(ctx, false));\n}\nfunction quotedString(value, ctx) {\n const { singleQuote } = ctx.options;\n let qs;\n if (singleQuote === false)\n qs = doubleQuotedString;\n else {\n const hasDouble = value.includes('\"');\n const hasSingle = value.includes(\"'\");\n if (hasDouble && !hasSingle)\n qs = singleQuotedString;\n else if (hasSingle && !hasDouble)\n qs = doubleQuotedString;\n else\n qs = singleQuote ? singleQuotedString : doubleQuotedString;\n }\n return qs(value, ctx);\n}\n// The negative lookbehind avoids a polynomial search,\n// but isn't supported yet on Safari: https://caniuse.com/js-regexp-lookbehind\nlet blockEndNewlines;\ntry {\n blockEndNewlines = new RegExp('(^|(?<!\\n))\\n+(?!\\n|$)', 'g');\n}\ncatch {\n blockEndNewlines = /\\n+(?!\\n|$)/g;\n}\nfunction blockString({ comment, type, value }, ctx, onComment, onChompKeep) {\n const { blockQuote, commentString, lineWidth } = ctx.options;\n // 1. Block can't end in whitespace unless the last line is non-empty.\n // 2. Strings consisting of only whitespace are best rendered explicitly.\n if (!blockQuote || /\\n[\\t ]+$/.test(value)) {\n return quotedString(value, ctx);\n }\n const indent = ctx.indent ||\n (ctx.forceBlockIndent || containsDocumentMarker(value) ? ' ' : '');\n const literal = blockQuote === 'literal'\n ? true\n : blockQuote === 'folded' || type === Scalar.BLOCK_FOLDED\n ? false\n : type === Scalar.BLOCK_LITERAL\n ? true\n : !lineLengthOverLimit(value, lineWidth, indent.length);\n if (!value)\n return literal ? '|\\n' : '>\\n';\n // determine chomping from whitespace at value end\n let chomp;\n let endStart;\n for (endStart = value.length; endStart > 0; --endStart) {\n const ch = value[endStart - 1];\n if (ch !== '\\n' && ch !== '\\t' && ch !== ' ')\n break;\n }\n let end = value.substring(endStart);\n const endNlPos = end.indexOf('\\n');\n if (endNlPos === -1) {\n chomp = '-'; // strip\n }\n else if (value === end || endNlPos !== end.length - 1) {\n chomp = '+'; // keep\n if (onChompKeep)\n onChompKeep();\n }\n else {\n chomp = ''; // clip\n }\n if (end) {\n value = value.slice(0, -end.length);\n if (end[end.length - 1] === '\\n')\n end = end.slice(0, -1);\n end = end.replace(blockEndNewlines, `$&${indent}`);\n }\n // determine indent indicator from whitespace at value start\n let startWithSpace = false;\n let startEnd;\n let startNlPos = -1;\n for (startEnd = 0; startEnd < value.length; ++startEnd) {\n const ch = value[startEnd];\n if (ch === ' ')\n startWithSpace = true;\n else if (ch === '\\n')\n startNlPos = startEnd;\n else\n break;\n }\n let start = value.substring(0, startNlPos < startEnd ? startNlPos + 1 : startEnd);\n if (start) {\n value = value.substring(start.length);\n start = start.replace(/\\n+/g, `$&${indent}`);\n }\n const indentSize = indent ? '2' : '1'; // root is at -1\n // Leading | or > is added later\n let header = (startWithSpace ? indentSize : '') + chomp;\n if (comment) {\n header += ' ' + commentString(comment.replace(/ ?[\\r\\n]+/g, ' '));\n if (onComment)\n onComment();\n }\n if (!literal) {\n const foldedValue = value\n .replace(/\\n+/g, '\\n$&')\n .replace(/(?:^|\\n)([\\t ].*)(?:([\\n\\t ]*)\\n(?![\\n\\t ]))?/g, '$1$2') // more-indented lines aren't folded\n // ^ more-ind. ^ empty ^ capture next empty lines only at end of indent\n .replace(/\\n+/g, `$&${indent}`);\n let literalFallback = false;\n const foldOptions = getFoldOptions(ctx, true);\n if (blockQuote !== 'folded' && type !== Scalar.BLOCK_FOLDED) {\n foldOptions.onOverflow = () => {\n literalFallback = true;\n };\n }\n const body = foldFlowLines(`${start}${foldedValue}${end}`, indent, FOLD_BLOCK, foldOptions);\n if (!literalFallback)\n return `>${header}\\n${indent}${body}`;\n }\n value = value.replace(/\\n+/g, `$&${indent}`);\n return `|${header}\\n${indent}${start}${value}${end}`;\n}\nfunction plainString(item, ctx, onComment, onChompKeep) {\n const { type, value } = item;\n const { actualString, implicitKey, indent, indentStep, inFlow } = ctx;\n if ((implicitKey && value.includes('\\n')) ||\n (inFlow && /[[\\]{},]/.test(value))) {\n return quotedString(value, ctx);\n }\n if (/^[\\n\\t ,[\\]{}#&*!|>'\"%@`]|^[?-]$|^[?-][ \\t]|[\\n:][ \\t]|[ \\t]\\n|[\\n\\t ]#|[\\n\\t :]$/.test(value)) {\n // not allowed:\n // - '-' or '?'\n // - start with an indicator character (except [?:-]) or /[?-] /\n // - '\\n ', ': ' or ' \\n' anywhere\n // - '#' not preceded by a non-space char\n // - end with ' ' or ':'\n return implicitKey || inFlow || !value.includes('\\n')\n ? quotedString(value, ctx)\n : blockString(item, ctx, onComment, onChompKeep);\n }\n if (!implicitKey &&\n !inFlow &&\n type !== Scalar.PLAIN &&\n value.includes('\\n')) {\n // Where allowed & type not set explicitly, prefer block style for multiline strings\n return blockString(item, ctx, onComment, onChompKeep);\n }\n if (containsDocumentMarker(value)) {\n if (indent === '') {\n ctx.forceBlockIndent = true;\n return blockString(item, ctx, onComment, onChompKeep);\n }\n else if (implicitKey && indent === indentStep) {\n return quotedString(value, ctx);\n }\n }\n const str = value.replace(/\\n+/g, `$&\\n${indent}`);\n // Verify that output will be parsed as a string, as e.g. plain numbers and\n // booleans get parsed with those types in v1.2 (e.g. '42', 'true' & '0.9e-3'),\n // and others in v1.1.\n if (actualString) {\n const test = (tag) => tag.default && tag.tag !== 'tag:yaml.org,2002:str' && tag.test?.test(str);\n const { compat, tags } = ctx.doc.schema;\n if (tags.some(test) || compat?.some(test))\n return quotedString(value, ctx);\n }\n return implicitKey\n ? str\n : foldFlowLines(str, indent, FOLD_FLOW, getFoldOptions(ctx, false));\n}\nfunction stringifyString(item, ctx, onComment, onChompKeep) {\n const { implicitKey, inFlow } = ctx;\n const ss = typeof item.value === 'string'\n ? item\n : Object.assign({}, item, { value: String(item.value) });\n let { type } = item;\n if (type !== Scalar.QUOTE_DOUBLE) {\n // force double quotes on control characters & unpaired surrogates\n if (/[\\x00-\\x08\\x0b-\\x1f\\x7f-\\x9f\\u{D800}-\\u{DFFF}]/u.test(ss.value))\n type = Scalar.QUOTE_DOUBLE;\n }\n const _stringify = (_type) => {\n switch (_type) {\n case Scalar.BLOCK_FOLDED:\n case Scalar.BLOCK_LITERAL:\n return implicitKey || inFlow\n ? quotedString(ss.value, ctx) // blocks are not valid inside flow containers\n : blockString(ss, ctx, onComment, onChompKeep);\n case Scalar.QUOTE_DOUBLE:\n return doubleQuotedString(ss.value, ctx);\n case Scalar.QUOTE_SINGLE:\n return singleQuotedString(ss.value, ctx);\n case Scalar.PLAIN:\n return plainString(ss, ctx, onComment, onChompKeep);\n default:\n return null;\n }\n };\n let res = _stringify(type);\n if (res === null) {\n const { defaultKeyType, defaultStringType } = ctx.options;\n const t = (implicitKey && defaultKeyType) || defaultStringType;\n res = _stringify(t);\n if (res === null)\n throw new Error(`Unsupported default string type ${t}`);\n }\n return res;\n}\n\nexport { stringifyString };\n","import { anchorIsValid } from '../doc/anchors.js';\nimport { isPair, isAlias, isNode, isScalar, isCollection } from '../nodes/identity.js';\nimport { stringifyComment } from './stringifyComment.js';\nimport { stringifyString } from './stringifyString.js';\n\nfunction createStringifyContext(doc, options) {\n const opt = Object.assign({\n blockQuote: true,\n commentString: stringifyComment,\n defaultKeyType: null,\n defaultStringType: 'PLAIN',\n directives: null,\n doubleQuotedAsJSON: false,\n doubleQuotedMinMultiLineLength: 40,\n falseStr: 'false',\n flowCollectionPadding: true,\n indentSeq: true,\n lineWidth: 80,\n minContentWidth: 20,\n nullStr: 'null',\n simpleKeys: false,\n singleQuote: null,\n trueStr: 'true',\n verifyAliasOrder: true\n }, doc.schema.toStringOptions, options);\n let inFlow;\n switch (opt.collectionStyle) {\n case 'block':\n inFlow = false;\n break;\n case 'flow':\n inFlow = true;\n break;\n default:\n inFlow = null;\n }\n return {\n anchors: new Set(),\n doc,\n flowCollectionPadding: opt.flowCollectionPadding ? ' ' : '',\n indent: '',\n indentStep: typeof opt.indent === 'number' ? ' '.repeat(opt.indent) : ' ',\n inFlow,\n options: opt\n };\n}\nfunction getTagObject(tags, item) {\n if (item.tag) {\n const match = tags.filter(t => t.tag === item.tag);\n if (match.length > 0)\n return match.find(t => t.format === item.format) ?? match[0];\n }\n let tagObj = undefined;\n let obj;\n if (isScalar(item)) {\n obj = item.value;\n let match = tags.filter(t => t.identify?.(obj));\n if (match.length > 1) {\n const testMatch = match.filter(t => t.test);\n if (testMatch.length > 0)\n match = testMatch;\n }\n tagObj =\n match.find(t => t.format === item.format) ?? match.find(t => !t.format);\n }\n else {\n obj = item;\n tagObj = tags.find(t => t.nodeClass && obj instanceof t.nodeClass);\n }\n if (!tagObj) {\n const name = obj?.constructor?.name ?? (obj === null ? 'null' : typeof obj);\n throw new Error(`Tag not resolved for ${name} value`);\n }\n return tagObj;\n}\n// needs to be called before value stringifier to allow for circular anchor refs\nfunction stringifyProps(node, tagObj, { anchors, doc }) {\n if (!doc.directives)\n return '';\n const props = [];\n const anchor = (isScalar(node) || isCollection(node)) && node.anchor;\n if (anchor && anchorIsValid(anchor)) {\n anchors.add(anchor);\n props.push(`&${anchor}`);\n }\n const tag = node.tag ?? (tagObj.default ? null : tagObj.tag);\n if (tag)\n props.push(doc.directives.tagString(tag));\n return props.join(' ');\n}\nfunction stringify(item, ctx, onComment, onChompKeep) {\n if (isPair(item))\n return item.toString(ctx, onComment, onChompKeep);\n if (isAlias(item)) {\n if (ctx.doc.directives)\n return item.toString(ctx);\n if (ctx.resolvedAliases?.has(item)) {\n throw new TypeError(`Cannot stringify circular structure without alias nodes`);\n }\n else {\n if (ctx.resolvedAliases)\n ctx.resolvedAliases.add(item);\n else\n ctx.resolvedAliases = new Set([item]);\n item = item.resolve(ctx.doc);\n }\n }\n let tagObj = undefined;\n const node = isNode(item)\n ? item\n : ctx.doc.createNode(item, { onTagObj: o => (tagObj = o) });\n tagObj ?? (tagObj = getTagObject(ctx.doc.schema.tags, node));\n const props = stringifyProps(node, tagObj, ctx);\n if (props.length > 0)\n ctx.indentAtStart = (ctx.indentAtStart ?? 0) + props.length + 1;\n const str = typeof tagObj.stringify === 'function'\n ? tagObj.stringify(node, ctx, onComment, onChompKeep)\n : isScalar(node)\n ? stringifyString(node, ctx, onComment, onChompKeep)\n : node.toString(ctx, onComment, onChompKeep);\n if (!props)\n return str;\n return isScalar(node) || str[0] === '{' || str[0] === '['\n ? `${props} ${str}`\n : `${props}\\n${ctx.indent}${str}`;\n}\n\nexport { createStringifyContext, stringify };\n","import { isScalar, isAlias, isSeq, isMap } from '../../nodes/identity.js';\nimport { Scalar } from '../../nodes/Scalar.js';\n\n// If the value associated with a merge key is a single mapping node, each of\n// its key/value pairs is inserted into the current mapping, unless the key\n// already exists in it. If the value associated with the merge key is a\n// sequence, then this sequence is expected to contain mapping nodes and each\n// of these nodes is merged in turn according to its order in the sequence.\n// Keys in mapping nodes earlier in the sequence override keys specified in\n// later mapping nodes. -- http://yaml.org/type/merge.html\nconst MERGE_KEY = '<<';\nconst merge = {\n identify: value => value === MERGE_KEY ||\n (typeof value === 'symbol' && value.description === MERGE_KEY),\n default: 'key',\n tag: 'tag:yaml.org,2002:merge',\n test: /^<<$/,\n resolve: () => Object.assign(new Scalar(Symbol(MERGE_KEY)), {\n addToJSMap: addMergeToJSMap\n }),\n stringify: () => MERGE_KEY\n};\nconst isMergeKey = (ctx, key) => (merge.identify(key) ||\n (isScalar(key) &&\n (!key.type || key.type === Scalar.PLAIN) &&\n merge.identify(key.value))) &&\n ctx?.doc.schema.tags.some(tag => tag.tag === merge.tag && tag.default);\nfunction addMergeToJSMap(ctx, map, value) {\n value = ctx && isAlias(value) ? value.resolve(ctx.doc) : value;\n if (isSeq(value))\n for (const it of value.items)\n mergeValue(ctx, map, it);\n else if (Array.isArray(value))\n for (const it of value)\n mergeValue(ctx, map, it);\n else\n mergeValue(ctx, map, value);\n}\nfunction mergeValue(ctx, map, value) {\n const source = ctx && isAlias(value) ? value.resolve(ctx.doc) : value;\n if (!isMap(source))\n throw new Error('Merge sources must be maps or map aliases');\n const srcMap = source.toJSON(null, ctx, Map);\n for (const [key, value] of srcMap) {\n if (map instanceof Map) {\n if (!map.has(key))\n map.set(key, value);\n }\n else if (map instanceof Set) {\n map.add(key);\n }\n else if (!Object.prototype.hasOwnProperty.call(map, key)) {\n Object.defineProperty(map, key, {\n value,\n writable: true,\n enumerable: true,\n configurable: true\n });\n }\n }\n return map;\n}\n\nexport { addMergeToJSMap, isMergeKey, merge };\n","import { warn } from '../log.js';\nimport { isMergeKey, addMergeToJSMap } from '../schema/yaml-1.1/merge.js';\nimport { createStringifyContext } from '../stringify/stringify.js';\nimport { isNode } from './identity.js';\nimport { toJS } from './toJS.js';\n\nfunction addPairToJSMap(ctx, map, { key, value }) {\n if (isNode(key) && key.addToJSMap)\n key.addToJSMap(ctx, map, value);\n // TODO: Should drop this special case for bare << handling\n else if (isMergeKey(ctx, key))\n addMergeToJSMap(ctx, map, value);\n else {\n const jsKey = toJS(key, '', ctx);\n if (map instanceof Map) {\n map.set(jsKey, toJS(value, jsKey, ctx));\n }\n else if (map instanceof Set) {\n map.add(jsKey);\n }\n else {\n const stringKey = stringifyKey(key, jsKey, ctx);\n const jsValue = toJS(value, stringKey, ctx);\n if (stringKey in map)\n Object.defineProperty(map, stringKey, {\n value: jsValue,\n writable: true,\n enumerable: true,\n configurable: true\n });\n else\n map[stringKey] = jsValue;\n }\n }\n return map;\n}\nfunction stringifyKey(key, jsKey, ctx) {\n if (jsKey === null)\n return '';\n // eslint-disable-next-line @typescript-eslint/no-base-to-string\n if (typeof jsKey !== 'object')\n return String(jsKey);\n if (isNode(key) && ctx?.doc) {\n const strCtx = createStringifyContext(ctx.doc, {});\n strCtx.anchors = new Set();\n for (const node of ctx.anchors.keys())\n strCtx.anchors.add(node.anchor);\n strCtx.inFlow = true;\n strCtx.inStringifyKey = true;\n const strKey = key.toString(strCtx);\n if (!ctx.mapKeyWarned) {\n let jsonStr = JSON.stringify(strKey);\n if (jsonStr.length > 40)\n jsonStr = jsonStr.substring(0, 36) + '...\"';\n warn(ctx.doc.options.logLevel, `Keys with collection values will be stringified due to JS Object restrictions: ${jsonStr}. Set mapAsMap: true to use object keys.`);\n ctx.mapKeyWarned = true;\n }\n return strKey;\n }\n return JSON.stringify(jsKey);\n}\n\nexport { addPairToJSMap };\n","function debug(logLevel, ...messages) {\n if (logLevel === 'debug')\n console.log(...messages);\n}\nfunction warn(logLevel, warning) {\n if (logLevel === 'debug' || logLevel === 'warn') {\n console.warn(warning);\n }\n}\n\nexport { debug, warn };\n","import { createNode } from '../doc/createNode.js';\nimport { stringifyPair } from '../stringify/stringifyPair.js';\nimport { addPairToJSMap } from './addPairToJSMap.js';\nimport { NODE_TYPE, PAIR, isNode } from './identity.js';\n\nfunction createPair(key, value, ctx) {\n const k = createNode(key, undefined, ctx);\n const v = createNode(value, undefined, ctx);\n return new Pair(k, v);\n}\nclass Pair {\n constructor(key, value = null) {\n Object.defineProperty(this, NODE_TYPE, { value: PAIR });\n this.key = key;\n this.value = value;\n }\n clone(schema) {\n let { key, value } = this;\n if (isNode(key))\n key = key.clone(schema);\n if (isNode(value))\n value = value.clone(schema);\n return new Pair(key, value);\n }\n toJSON(_, ctx) {\n const pair = ctx?.mapAsMap ? new Map() : {};\n return addPairToJSMap(ctx, pair, this);\n }\n toString(ctx, onComment, onChompKeep) {\n return ctx?.doc\n ? stringifyPair(this, ctx, onComment, onChompKeep)\n : JSON.stringify(this);\n }\n}\n\nexport { Pair, createPair };\n","import { isCollection, isNode, isScalar, isSeq } from '../nodes/identity.js';\nimport { Scalar } from '../nodes/Scalar.js';\nimport { stringify } from './stringify.js';\nimport { lineComment, indentComment } from './stringifyComment.js';\n\nfunction stringifyPair({ key, value }, ctx, onComment, onChompKeep) {\n const { allNullValues, doc, indent, indentStep, options: { commentString, indentSeq, simpleKeys } } = ctx;\n let keyComment = (isNode(key) && key.comment) || null;\n if (simpleKeys) {\n if (keyComment) {\n throw new Error('With simple keys, key nodes cannot have comments');\n }\n if (isCollection(key) || (!isNode(key) && typeof key === 'object')) {\n const msg = 'With simple keys, collection cannot be used as a key value';\n throw new Error(msg);\n }\n }\n let explicitKey = !simpleKeys &&\n (!key ||\n (keyComment && value == null && !ctx.inFlow) ||\n isCollection(key) ||\n (isScalar(key)\n ? key.type === Scalar.BLOCK_FOLDED || key.type === Scalar.BLOCK_LITERAL\n : typeof key === 'object'));\n ctx = Object.assign({}, ctx, {\n allNullValues: false,\n implicitKey: !explicitKey && (simpleKeys || !allNullValues),\n indent: indent + indentStep\n });\n let keyCommentDone = false;\n let chompKeep = false;\n let str = stringify(key, ctx, () => (keyCommentDone = true), () => (chompKeep = true));\n if (!explicitKey && !ctx.inFlow && str.length > 1024) {\n if (simpleKeys)\n throw new Error('With simple keys, single line scalar must not span more than 1024 characters');\n explicitKey = true;\n }\n if (ctx.inFlow) {\n if (allNullValues || value == null) {\n if (keyCommentDone && onComment)\n onComment();\n return str === '' ? '?' : explicitKey ? `? ${str}` : str;\n }\n }\n else if ((allNullValues && !simpleKeys) || (value == null && explicitKey)) {\n str = `? ${str}`;\n if (keyComment && !keyCommentDone) {\n str += lineComment(str, ctx.indent, commentString(keyComment));\n }\n else if (chompKeep && onChompKeep)\n onChompKeep();\n return str;\n }\n if (keyCommentDone)\n keyComment = null;\n if (explicitKey) {\n if (keyComment)\n str += lineComment(str, ctx.indent, commentString(keyComment));\n str = `? ${str}\\n${indent}:`;\n }\n else {\n str = `${str}:`;\n if (keyComment)\n str += lineComment(str, ctx.indent, commentString(keyComment));\n }\n let vsb, vcb, valueComment;\n if (isNode(value)) {\n vsb = !!value.spaceBefore;\n vcb = value.commentBefore;\n valueComment = value.comment;\n }\n else {\n vsb = false;\n vcb = null;\n valueComment = null;\n if (value && typeof value === 'object')\n value = doc.createNode(value);\n }\n ctx.implicitKey = false;\n if (!explicitKey && !keyComment && isScalar(value))\n ctx.indentAtStart = str.length + 1;\n chompKeep = false;\n if (!indentSeq &&\n indentStep.length >= 2 &&\n !ctx.inFlow &&\n !explicitKey &&\n isSeq(value) &&\n !value.flow &&\n !value.tag &&\n !value.anchor) {\n // If indentSeq === false, consider '- ' as part of indentation where possible\n ctx.indent = ctx.indent.substring(2);\n }\n let valueCommentDone = false;\n const valueStr = stringify(value, ctx, () => (valueCommentDone = true), () => (chompKeep = true));\n let ws = ' ';\n if (keyComment || vsb || vcb) {\n ws = vsb ? '\\n' : '';\n if (vcb) {\n const cs = commentString(vcb);\n ws += `\\n${indentComment(cs, ctx.indent)}`;\n }\n if (valueStr === '' && !ctx.inFlow) {\n if (ws === '\\n' && valueComment)\n ws = '\\n\\n';\n }\n else {\n ws += `\\n${ctx.indent}`;\n }\n }\n else if (!explicitKey && isCollection(value)) {\n const vs0 = valueStr[0];\n const nl0 = valueStr.indexOf('\\n');\n const hasNewline = nl0 !== -1;\n const flow = ctx.inFlow ?? value.flow ?? value.items.length === 0;\n if (hasNewline || !flow) {\n let hasPropsLine = false;\n if (hasNewline && (vs0 === '&' || vs0 === '!')) {\n let sp0 = valueStr.indexOf(' ');\n if (vs0 === '&' &&\n sp0 !== -1 &&\n sp0 < nl0 &&\n valueStr[sp0 + 1] === '!') {\n sp0 = valueStr.indexOf(' ', sp0 + 1);\n }\n if (sp0 === -1 || nl0 < sp0)\n hasPropsLine = true;\n }\n if (!hasPropsLine)\n ws = `\\n${ctx.indent}`;\n }\n }\n else if (valueStr === '' || valueStr[0] === '\\n') {\n ws = '';\n }\n str += ws + valueStr;\n if (ctx.inFlow) {\n if (valueCommentDone && onComment)\n onComment();\n }\n else if (valueComment && !valueCommentDone) {\n str += lineComment(str, ctx.indent, commentString(valueComment));\n }\n else if (chompKeep && onChompKeep) {\n onChompKeep();\n }\n return str;\n}\n\nexport { stringifyPair };\n","import { isNode, isPair } from '../nodes/identity.js';\nimport { stringify } from './stringify.js';\nimport { lineComment, indentComment } from './stringifyComment.js';\n\nfunction stringifyCollection(collection, ctx, options) {\n const flow = ctx.inFlow ?? collection.flow;\n const stringify = flow ? stringifyFlowCollection : stringifyBlockCollection;\n return stringify(collection, ctx, options);\n}\nfunction stringifyBlockCollection({ comment, items }, ctx, { blockItemPrefix, flowChars, itemIndent, onChompKeep, onComment }) {\n const { indent, options: { commentString } } = ctx;\n const itemCtx = Object.assign({}, ctx, { indent: itemIndent, type: null });\n let chompKeep = false; // flag for the preceding node's status\n const lines = [];\n for (let i = 0; i < items.length; ++i) {\n const item = items[i];\n let comment = null;\n if (isNode(item)) {\n if (!chompKeep && item.spaceBefore)\n lines.push('');\n addCommentBefore(ctx, lines, item.commentBefore, chompKeep);\n if (item.comment)\n comment = item.comment;\n }\n else if (isPair(item)) {\n const ik = isNode(item.key) ? item.key : null;\n if (ik) {\n if (!chompKeep && ik.spaceBefore)\n lines.push('');\n addCommentBefore(ctx, lines, ik.commentBefore, chompKeep);\n }\n }\n chompKeep = false;\n let str = stringify(item, itemCtx, () => (comment = null), () => (chompKeep = true));\n if (comment)\n str += lineComment(str, itemIndent, commentString(comment));\n if (chompKeep && comment)\n chompKeep = false;\n lines.push(blockItemPrefix + str);\n }\n let str;\n if (lines.length === 0) {\n str = flowChars.start + flowChars.end;\n }\n else {\n str = lines[0];\n for (let i = 1; i < lines.length; ++i) {\n const line = lines[i];\n str += line ? `\\n${indent}${line}` : '\\n';\n }\n }\n if (comment) {\n str += '\\n' + indentComment(commentString(comment), indent);\n if (onComment)\n onComment();\n }\n else if (chompKeep && onChompKeep)\n onChompKeep();\n return str;\n}\nfunction stringifyFlowCollection({ items }, ctx, { flowChars, itemIndent }) {\n const { indent, indentStep, flowCollectionPadding: fcPadding, options: { commentString } } = ctx;\n itemIndent += indentStep;\n const itemCtx = Object.assign({}, ctx, {\n indent: itemIndent,\n inFlow: true,\n type: null\n });\n let reqNewline = false;\n let linesAtValue = 0;\n const lines = [];\n for (let i = 0; i < items.length; ++i) {\n const item = items[i];\n let comment = null;\n if (isNode(item)) {\n if (item.spaceBefore)\n lines.push('');\n addCommentBefore(ctx, lines, item.commentBefore, false);\n if (item.comment)\n comment = item.comment;\n }\n else if (isPair(item)) {\n const ik = isNode(item.key) ? item.key : null;\n if (ik) {\n if (ik.spaceBefore)\n lines.push('');\n addCommentBefore(ctx, lines, ik.commentBefore, false);\n if (ik.comment)\n reqNewline = true;\n }\n const iv = isNode(item.value) ? item.value : null;\n if (iv) {\n if (iv.comment)\n comment = iv.comment;\n if (iv.commentBefore)\n reqNewline = true;\n }\n else if (item.value == null && ik?.comment) {\n comment = ik.comment;\n }\n }\n if (comment)\n reqNewline = true;\n let str = stringify(item, itemCtx, () => (comment = null));\n if (i < items.length - 1)\n str += ',';\n if (comment)\n str += lineComment(str, itemIndent, commentString(comment));\n if (!reqNewline && (lines.length > linesAtValue || str.includes('\\n')))\n reqNewline = true;\n lines.push(str);\n linesAtValue = lines.length;\n }\n const { start, end } = flowChars;\n if (lines.length === 0) {\n return start + end;\n }\n else {\n if (!reqNewline) {\n const len = lines.reduce((sum, line) => sum + line.length + 2, 2);\n reqNewline = ctx.options.lineWidth > 0 && len > ctx.options.lineWidth;\n }\n if (reqNewline) {\n let str = start;\n for (const line of lines)\n str += line ? `\\n${indentStep}${indent}${line}` : '\\n';\n return `${str}\\n${indent}${end}`;\n }\n else {\n return `${start}${fcPadding}${lines.join(' ')}${fcPadding}${end}`;\n }\n }\n}\nfunction addCommentBefore({ indent, options: { commentString } }, lines, comment, chompKeep) {\n if (comment && chompKeep)\n comment = comment.replace(/^\\n+/, '');\n if (comment) {\n const ic = indentComment(commentString(comment), indent);\n lines.push(ic.trimStart()); // Avoid double indent on first line\n }\n}\n\nexport { stringifyCollection };\n","import { stringifyCollection } from '../stringify/stringifyCollection.js';\nimport { addPairToJSMap } from './addPairToJSMap.js';\nimport { Collection } from './Collection.js';\nimport { MAP, isPair, isScalar } from './identity.js';\nimport { Pair, createPair } from './Pair.js';\nimport { isScalarValue } from './Scalar.js';\n\nfunction findPair(items, key) {\n const k = isScalar(key) ? key.value : key;\n for (const it of items) {\n if (isPair(it)) {\n if (it.key === key || it.key === k)\n return it;\n if (isScalar(it.key) && it.key.value === k)\n return it;\n }\n }\n return undefined;\n}\nclass YAMLMap extends Collection {\n static get tagName() {\n return 'tag:yaml.org,2002:map';\n }\n constructor(schema) {\n super(MAP, schema);\n this.items = [];\n }\n /**\n * A generic collection parsing method that can be extended\n * to other node classes that inherit from YAMLMap\n */\n static from(schema, obj, ctx) {\n const { keepUndefined, replacer } = ctx;\n const map = new this(schema);\n const add = (key, value) => {\n if (typeof replacer === 'function')\n value = replacer.call(obj, key, value);\n else if (Array.isArray(replacer) && !replacer.includes(key))\n return;\n if (value !== undefined || keepUndefined)\n map.items.push(createPair(key, value, ctx));\n };\n if (obj instanceof Map) {\n for (const [key, value] of obj)\n add(key, value);\n }\n else if (obj && typeof obj === 'object') {\n for (const key of Object.keys(obj))\n add(key, obj[key]);\n }\n if (typeof schema.sortMapEntries === 'function') {\n map.items.sort(schema.sortMapEntries);\n }\n return map;\n }\n /**\n * Adds a value to the collection.\n *\n * @param overwrite - If not set `true`, using a key that is already in the\n * collection will throw. Otherwise, overwrites the previous value.\n */\n add(pair, overwrite) {\n let _pair;\n if (isPair(pair))\n _pair = pair;\n else if (!pair || typeof pair !== 'object' || !('key' in pair)) {\n // In TypeScript, this never happens.\n _pair = new Pair(pair, pair?.value);\n }\n else\n _pair = new Pair(pair.key, pair.value);\n const prev = findPair(this.items, _pair.key);\n const sortEntries = this.schema?.sortMapEntries;\n if (prev) {\n if (!overwrite)\n throw new Error(`Key ${_pair.key} already set`);\n // For scalars, keep the old node & its comments and anchors\n if (isScalar(prev.value) && isScalarValue(_pair.value))\n prev.value.value = _pair.value;\n else\n prev.value = _pair.value;\n }\n else if (sortEntries) {\n const i = this.items.findIndex(item => sortEntries(_pair, item) < 0);\n if (i === -1)\n this.items.push(_pair);\n else\n this.items.splice(i, 0, _pair);\n }\n else {\n this.items.push(_pair);\n }\n }\n delete(key) {\n const it = findPair(this.items, key);\n if (!it)\n return false;\n const del = this.items.splice(this.items.indexOf(it), 1);\n return del.length > 0;\n }\n get(key, keepScalar) {\n const it = findPair(this.items, key);\n const node = it?.value;\n return (!keepScalar && isScalar(node) ? node.value : node) ?? undefined;\n }\n has(key) {\n return !!findPair(this.items, key);\n }\n set(key, value) {\n this.add(new Pair(key, value), true);\n }\n /**\n * @param ctx - Conversion context, originally set in Document#toJS()\n * @param {Class} Type - If set, forces the returned collection type\n * @returns Instance of Type, Map, or Object\n */\n toJSON(_, ctx, Type) {\n const map = Type ? new Type() : ctx?.mapAsMap ? new Map() : {};\n if (ctx?.onCreate)\n ctx.onCreate(map);\n for (const item of this.items)\n addPairToJSMap(ctx, map, item);\n return map;\n }\n toString(ctx, onComment, onChompKeep) {\n if (!ctx)\n return JSON.stringify(this);\n for (const item of this.items) {\n if (!isPair(item))\n throw new Error(`Map items must all be pairs; found ${JSON.stringify(item)} instead`);\n }\n if (!ctx.allNullValues && this.hasAllNullValues(false))\n ctx = Object.assign({}, ctx, { allNullValues: true });\n return stringifyCollection(this, ctx, {\n blockItemPrefix: '',\n flowChars: { start: '{', end: '}' },\n itemIndent: ctx.indent || '',\n onChompKeep,\n onComment\n });\n }\n}\n\nexport { YAMLMap, findPair };\n","import { isMap } from '../../nodes/identity.js';\nimport { YAMLMap } from '../../nodes/YAMLMap.js';\n\nconst map = {\n collection: 'map',\n default: true,\n nodeClass: YAMLMap,\n tag: 'tag:yaml.org,2002:map',\n resolve(map, onError) {\n if (!isMap(map))\n onError('Expected a mapping for this tag');\n return map;\n },\n createNode: (schema, obj, ctx) => YAMLMap.from(schema, obj, ctx)\n};\n\nexport { map };\n","import { createNode } from '../doc/createNode.js';\nimport { stringifyCollection } from '../stringify/stringifyCollection.js';\nimport { Collection } from './Collection.js';\nimport { SEQ, isScalar } from './identity.js';\nimport { isScalarValue } from './Scalar.js';\nimport { toJS } from './toJS.js';\n\nclass YAMLSeq extends Collection {\n static get tagName() {\n return 'tag:yaml.org,2002:seq';\n }\n constructor(schema) {\n super(SEQ, schema);\n this.items = [];\n }\n add(value) {\n this.items.push(value);\n }\n /**\n * Removes a value from the collection.\n *\n * `key` must contain a representation of an integer for this to succeed.\n * It may be wrapped in a `Scalar`.\n *\n * @returns `true` if the item was found and removed.\n */\n delete(key) {\n const idx = asItemIndex(key);\n if (typeof idx !== 'number')\n return false;\n const del = this.items.splice(idx, 1);\n return del.length > 0;\n }\n get(key, keepScalar) {\n const idx = asItemIndex(key);\n if (typeof idx !== 'number')\n return undefined;\n const it = this.items[idx];\n return !keepScalar && isScalar(it) ? it.value : it;\n }\n /**\n * Checks if the collection includes a value with the key `key`.\n *\n * `key` must contain a representation of an integer for this to succeed.\n * It may be wrapped in a `Scalar`.\n */\n has(key) {\n const idx = asItemIndex(key);\n return typeof idx === 'number' && idx < this.items.length;\n }\n /**\n * Sets a value in this collection. For `!!set`, `value` needs to be a\n * boolean to add/remove the item from the set.\n *\n * If `key` does not contain a representation of an integer, this will throw.\n * It may be wrapped in a `Scalar`.\n */\n set(key, value) {\n const idx = asItemIndex(key);\n if (typeof idx !== 'number')\n throw new Error(`Expected a valid index, not ${key}.`);\n const prev = this.items[idx];\n if (isScalar(prev) && isScalarValue(value))\n prev.value = value;\n else\n this.items[idx] = value;\n }\n toJSON(_, ctx) {\n const seq = [];\n if (ctx?.onCreate)\n ctx.onCreate(seq);\n let i = 0;\n for (const item of this.items)\n seq.push(toJS(item, String(i++), ctx));\n return seq;\n }\n toString(ctx, onComment, onChompKeep) {\n if (!ctx)\n return JSON.stringify(this);\n return stringifyCollection(this, ctx, {\n blockItemPrefix: '- ',\n flowChars: { start: '[', end: ']' },\n itemIndent: (ctx.indent || '') + ' ',\n onChompKeep,\n onComment\n });\n }\n static from(schema, obj, ctx) {\n const { replacer } = ctx;\n const seq = new this(schema);\n if (obj && Symbol.iterator in Object(obj)) {\n let i = 0;\n for (let it of obj) {\n if (typeof replacer === 'function') {\n const key = obj instanceof Set ? it : String(i++);\n it = replacer.call(obj, key, it);\n }\n seq.items.push(createNode(it, undefined, ctx));\n }\n }\n return seq;\n }\n}\nfunction asItemIndex(key) {\n let idx = isScalar(key) ? key.value : key;\n if (idx && typeof idx === 'string')\n idx = Number(idx);\n return typeof idx === 'number' && Number.isInteger(idx) && idx >= 0\n ? idx\n : null;\n}\n\nexport { YAMLSeq };\n","import { isSeq } from '../../nodes/identity.js';\nimport { YAMLSeq } from '../../nodes/YAMLSeq.js';\n\nconst seq = {\n collection: 'seq',\n default: true,\n nodeClass: YAMLSeq,\n tag: 'tag:yaml.org,2002:seq',\n resolve(seq, onError) {\n if (!isSeq(seq))\n onError('Expected a sequence for this tag');\n return seq;\n },\n createNode: (schema, obj, ctx) => YAMLSeq.from(schema, obj, ctx)\n};\n\nexport { seq };\n","import { stringifyString } from '../../stringify/stringifyString.js';\n\nconst string = {\n identify: value => typeof value === 'string',\n default: true,\n tag: 'tag:yaml.org,2002:str',\n resolve: str => str,\n stringify(item, ctx, onComment, onChompKeep) {\n ctx = Object.assign({ actualString: true }, ctx);\n return stringifyString(item, ctx, onComment, onChompKeep);\n }\n};\n\nexport { string };\n","import { Scalar } from '../../nodes/Scalar.js';\n\nconst nullTag = {\n identify: value => value == null,\n createNode: () => new Scalar(null),\n default: true,\n tag: 'tag:yaml.org,2002:null',\n test: /^(?:~|[Nn]ull|NULL)?$/,\n resolve: () => new Scalar(null),\n stringify: ({ source }, ctx) => typeof source === 'string' && nullTag.test.test(source)\n ? source\n : ctx.options.nullStr\n};\n\nexport { nullTag };\n","import { Scalar } from '../../nodes/Scalar.js';\n\nconst boolTag = {\n identify: value => typeof value === 'boolean',\n default: true,\n tag: 'tag:yaml.org,2002:bool',\n test: /^(?:[Tt]rue|TRUE|[Ff]alse|FALSE)$/,\n resolve: str => new Scalar(str[0] === 't' || str[0] === 'T'),\n stringify({ source, value }, ctx) {\n if (source && boolTag.test.test(source)) {\n const sv = source[0] === 't' || source[0] === 'T';\n if (value === sv)\n return source;\n }\n return value ? ctx.options.trueStr : ctx.options.falseStr;\n }\n};\n\nexport { boolTag };\n","function stringifyNumber({ format, minFractionDigits, tag, value }) {\n if (typeof value === 'bigint')\n return String(value);\n const num = typeof value === 'number' ? value : Number(value);\n if (!isFinite(num))\n return isNaN(num) ? '.nan' : num < 0 ? '-.inf' : '.inf';\n let n = Object.is(value, -0) ? '-0' : JSON.stringify(value);\n if (!format &&\n minFractionDigits &&\n (!tag || tag === 'tag:yaml.org,2002:float') &&\n /^\\d/.test(n)) {\n let i = n.indexOf('.');\n if (i < 0) {\n i = n.length;\n n += '.';\n }\n let d = minFractionDigits - (n.length - i - 1);\n while (d-- > 0)\n n += '0';\n }\n return n;\n}\n\nexport { stringifyNumber };\n","import { Scalar } from '../../nodes/Scalar.js';\nimport { stringifyNumber } from '../../stringify/stringifyNumber.js';\n\nconst floatNaN = {\n identify: value => typeof value === 'number',\n default: true,\n tag: 'tag:yaml.org,2002:float',\n test: /^(?:[-+]?\\.(?:inf|Inf|INF)|\\.nan|\\.NaN|\\.NAN)$/,\n resolve: str => str.slice(-3).toLowerCase() === 'nan'\n ? NaN\n : str[0] === '-'\n ? Number.NEGATIVE_INFINITY\n : Number.POSITIVE_INFINITY,\n stringify: stringifyNumber\n};\nconst floatExp = {\n identify: value => typeof value === 'number',\n default: true,\n tag: 'tag:yaml.org,2002:float',\n format: 'EXP',\n test: /^[-+]?(?:\\.[0-9]+|[0-9]+(?:\\.[0-9]*)?)[eE][-+]?[0-9]+$/,\n resolve: str => parseFloat(str),\n stringify(node) {\n const num = Number(node.value);\n return isFinite(num) ? num.toExponential() : stringifyNumber(node);\n }\n};\nconst float = {\n identify: value => typeof value === 'number',\n default: true,\n tag: 'tag:yaml.org,2002:float',\n test: /^[-+]?(?:\\.[0-9]+|[0-9]+\\.[0-9]*)$/,\n resolve(str) {\n const node = new Scalar(parseFloat(str));\n const dot = str.indexOf('.');\n if (dot !== -1 && str[str.length - 1] === '0')\n node.minFractionDigits = str.length - dot - 1;\n return node;\n },\n stringify: stringifyNumber\n};\n\nexport { float, floatExp, floatNaN };\n","import { stringifyNumber } from '../../stringify/stringifyNumber.js';\n\nconst intIdentify = (value) => typeof value === 'bigint' || Number.isInteger(value);\nconst intResolve = (str, offset, radix, { intAsBigInt }) => (intAsBigInt ? BigInt(str) : parseInt(str.substring(offset), radix));\nfunction intStringify(node, radix, prefix) {\n const { value } = node;\n if (intIdentify(value) && value >= 0)\n return prefix + value.toString(radix);\n return stringifyNumber(node);\n}\nconst intOct = {\n identify: value => intIdentify(value) && value >= 0,\n default: true,\n tag: 'tag:yaml.org,2002:int',\n format: 'OCT',\n test: /^0o[0-7]+$/,\n resolve: (str, _onError, opt) => intResolve(str, 2, 8, opt),\n stringify: node => intStringify(node, 8, '0o')\n};\nconst int = {\n identify: intIdentify,\n default: true,\n tag: 'tag:yaml.org,2002:int',\n test: /^[-+]?[0-9]+$/,\n resolve: (str, _onError, opt) => intResolve(str, 0, 10, opt),\n stringify: stringifyNumber\n};\nconst intHex = {\n identify: value => intIdentify(value) && value >= 0,\n default: true,\n tag: 'tag:yaml.org,2002:int',\n format: 'HEX',\n test: /^0x[0-9a-fA-F]+$/,\n resolve: (str, _onError, opt) => intResolve(str, 2, 16, opt),\n stringify: node => intStringify(node, 16, '0x')\n};\n\nexport { int, intHex, intOct };\n","import { map } from '../common/map.js';\nimport { nullTag } from '../common/null.js';\nimport { seq } from '../common/seq.js';\nimport { string } from '../common/string.js';\nimport { boolTag } from './bool.js';\nimport { floatNaN, floatExp, float } from './float.js';\nimport { intOct, int, intHex } from './int.js';\n\nconst schema = [\n map,\n seq,\n string,\n nullTag,\n boolTag,\n intOct,\n int,\n intHex,\n floatNaN,\n floatExp,\n float\n];\n\nexport { schema };\n","import { Scalar } from '../../nodes/Scalar.js';\nimport { map } from '../common/map.js';\nimport { seq } from '../common/seq.js';\n\nfunction intIdentify(value) {\n return typeof value === 'bigint' || Number.isInteger(value);\n}\nconst stringifyJSON = ({ value }) => JSON.stringify(value);\nconst jsonScalars = [\n {\n identify: value => typeof value === 'string',\n default: true,\n tag: 'tag:yaml.org,2002:str',\n resolve: str => str,\n stringify: stringifyJSON\n },\n {\n identify: value => value == null,\n createNode: () => new Scalar(null),\n default: true,\n tag: 'tag:yaml.org,2002:null',\n test: /^null$/,\n resolve: () => null,\n stringify: stringifyJSON\n },\n {\n identify: value => typeof value === 'boolean',\n default: true,\n tag: 'tag:yaml.org,2002:bool',\n test: /^true$|^false$/,\n resolve: str => str === 'true',\n stringify: stringifyJSON\n },\n {\n identify: intIdentify,\n default: true,\n tag: 'tag:yaml.org,2002:int',\n test: /^-?(?:0|[1-9][0-9]*)$/,\n resolve: (str, _onError, { intAsBigInt }) => intAsBigInt ? BigInt(str) : parseInt(str, 10),\n stringify: ({ value }) => intIdentify(value) ? value.toString() : JSON.stringify(value)\n },\n {\n identify: value => typeof value === 'number',\n default: true,\n tag: 'tag:yaml.org,2002:float',\n test: /^-?(?:0|[1-9][0-9]*)(?:\\.[0-9]*)?(?:[eE][-+]?[0-9]+)?$/,\n resolve: str => parseFloat(str),\n stringify: stringifyJSON\n }\n];\nconst jsonError = {\n default: true,\n tag: '',\n test: /^/,\n resolve(str, onError) {\n onError(`Unresolved plain scalar ${JSON.stringify(str)}`);\n return str;\n }\n};\nconst schema = [map, seq].concat(jsonScalars, jsonError);\n\nexport { schema };\n","import { Scalar } from '../../nodes/Scalar.js';\nimport { stringifyString } from '../../stringify/stringifyString.js';\n\nconst binary = {\n identify: value => value instanceof Uint8Array, // Buffer inherits from Uint8Array\n default: false,\n tag: 'tag:yaml.org,2002:binary',\n /**\n * Returns a Buffer in node and an Uint8Array in browsers\n *\n * To use the resulting buffer as an image, you'll want to do something like:\n *\n * const blob = new Blob([buffer], { type: 'image/jpeg' })\n * document.querySelector('#photo').src = URL.createObjectURL(blob)\n */\n resolve(src, onError) {\n if (typeof atob === 'function') {\n // On IE 11, atob() can't handle newlines\n const str = atob(src.replace(/[\\n\\r]/g, ''));\n const buffer = new Uint8Array(str.length);\n for (let i = 0; i < str.length; ++i)\n buffer[i] = str.charCodeAt(i);\n return buffer;\n }\n else {\n onError('This environment does not support reading binary tags; either Buffer or atob is required');\n return src;\n }\n },\n stringify({ comment, type, value }, ctx, onComment, onChompKeep) {\n if (!value)\n return '';\n const buf = value; // checked earlier by binary.identify()\n let str;\n if (typeof btoa === 'function') {\n let s = '';\n for (let i = 0; i < buf.length; ++i)\n s += String.fromCharCode(buf[i]);\n str = btoa(s);\n }\n else {\n throw new Error('This environment does not support writing binary tags; either Buffer or btoa is required');\n }\n type ?? (type = Scalar.BLOCK_LITERAL);\n if (type !== Scalar.QUOTE_DOUBLE) {\n const lineWidth = Math.max(ctx.options.lineWidth - ctx.indent.length, ctx.options.minContentWidth);\n const n = Math.ceil(str.length / lineWidth);\n const lines = new Array(n);\n for (let i = 0, o = 0; i < n; ++i, o += lineWidth) {\n lines[i] = str.substr(o, lineWidth);\n }\n str = lines.join(type === Scalar.BLOCK_LITERAL ? '\\n' : ' ');\n }\n return stringifyString({ comment, type, value: str }, ctx, onComment, onChompKeep);\n }\n};\n\nexport { binary };\n","import { isSeq, isPair, isMap } from '../../nodes/identity.js';\nimport { createPair, Pair } from '../../nodes/Pair.js';\nimport { Scalar } from '../../nodes/Scalar.js';\nimport { YAMLSeq } from '../../nodes/YAMLSeq.js';\n\nfunction resolvePairs(seq, onError) {\n if (isSeq(seq)) {\n for (let i = 0; i < seq.items.length; ++i) {\n let item = seq.items[i];\n if (isPair(item))\n continue;\n else if (isMap(item)) {\n if (item.items.length > 1)\n onError('Each pair must have its own sequence indicator');\n const pair = item.items[0] || new Pair(new Scalar(null));\n if (item.commentBefore)\n pair.key.commentBefore = pair.key.commentBefore\n ? `${item.commentBefore}\\n${pair.key.commentBefore}`\n : item.commentBefore;\n if (item.comment) {\n const cn = pair.value ?? pair.key;\n cn.comment = cn.comment\n ? `${item.comment}\\n${cn.comment}`\n : item.comment;\n }\n item = pair;\n }\n seq.items[i] = isPair(item) ? item : new Pair(item);\n }\n }\n else\n onError('Expected a sequence for this tag');\n return seq;\n}\nfunction createPairs(schema, iterable, ctx) {\n const { replacer } = ctx;\n const pairs = new YAMLSeq(schema);\n pairs.tag = 'tag:yaml.org,2002:pairs';\n let i = 0;\n if (iterable && Symbol.iterator in Object(iterable))\n for (let it of iterable) {\n if (typeof replacer === 'function')\n it = replacer.call(iterable, String(i++), it);\n let key, value;\n if (Array.isArray(it)) {\n if (it.length === 2) {\n key = it[0];\n value = it[1];\n }\n else\n throw new TypeError(`Expected [key, value] tuple: ${it}`);\n }\n else if (it && it instanceof Object) {\n const keys = Object.keys(it);\n if (keys.length === 1) {\n key = keys[0];\n value = it[key];\n }\n else {\n throw new TypeError(`Expected tuple with one key, not ${keys.length} keys`);\n }\n }\n else {\n key = it;\n }\n pairs.items.push(createPair(key, value, ctx));\n }\n return pairs;\n}\nconst pairs = {\n collection: 'seq',\n default: false,\n tag: 'tag:yaml.org,2002:pairs',\n resolve: resolvePairs,\n createNode: createPairs\n};\n\nexport { createPairs, pairs, resolvePairs };\n","import { isScalar, isPair } from '../../nodes/identity.js';\nimport { toJS } from '../../nodes/toJS.js';\nimport { YAMLMap } from '../../nodes/YAMLMap.js';\nimport { YAMLSeq } from '../../nodes/YAMLSeq.js';\nimport { resolvePairs, createPairs } from './pairs.js';\n\nclass YAMLOMap extends YAMLSeq {\n constructor() {\n super();\n this.add = YAMLMap.prototype.add.bind(this);\n this.delete = YAMLMap.prototype.delete.bind(this);\n this.get = YAMLMap.prototype.get.bind(this);\n this.has = YAMLMap.prototype.has.bind(this);\n this.set = YAMLMap.prototype.set.bind(this);\n this.tag = YAMLOMap.tag;\n }\n /**\n * If `ctx` is given, the return type is actually `Map<unknown, unknown>`,\n * but TypeScript won't allow widening the signature of a child method.\n */\n toJSON(_, ctx) {\n if (!ctx)\n return super.toJSON(_);\n const map = new Map();\n if (ctx?.onCreate)\n ctx.onCreate(map);\n for (const pair of this.items) {\n let key, value;\n if (isPair(pair)) {\n key = toJS(pair.key, '', ctx);\n value = toJS(pair.value, key, ctx);\n }\n else {\n key = toJS(pair, '', ctx);\n }\n if (map.has(key))\n throw new Error('Ordered maps must not include duplicate keys');\n map.set(key, value);\n }\n return map;\n }\n static from(schema, iterable, ctx) {\n const pairs = createPairs(schema, iterable, ctx);\n const omap = new this();\n omap.items = pairs.items;\n return omap;\n }\n}\nYAMLOMap.tag = 'tag:yaml.org,2002:omap';\nconst omap = {\n collection: 'seq',\n identify: value => value instanceof Map,\n nodeClass: YAMLOMap,\n default: false,\n tag: 'tag:yaml.org,2002:omap',\n resolve(seq, onError) {\n const pairs = resolvePairs(seq, onError);\n const seenKeys = [];\n for (const { key } of pairs.items) {\n if (isScalar(key)) {\n if (seenKeys.includes(key.value)) {\n onError(`Ordered maps must not include duplicate keys: ${key.value}`);\n }\n else {\n seenKeys.push(key.value);\n }\n }\n }\n return Object.assign(new YAMLOMap(), pairs);\n },\n createNode: (schema, iterable, ctx) => YAMLOMap.from(schema, iterable, ctx)\n};\n\nexport { YAMLOMap, omap };\n","import { Scalar } from '../../nodes/Scalar.js';\n\nfunction boolStringify({ value, source }, ctx) {\n const boolObj = value ? trueTag : falseTag;\n if (source && boolObj.test.test(source))\n return source;\n return value ? ctx.options.trueStr : ctx.options.falseStr;\n}\nconst trueTag = {\n identify: value => value === true,\n default: true,\n tag: 'tag:yaml.org,2002:bool',\n test: /^(?:Y|y|[Yy]es|YES|[Tt]rue|TRUE|[Oo]n|ON)$/,\n resolve: () => new Scalar(true),\n stringify: boolStringify\n};\nconst falseTag = {\n identify: value => value === false,\n default: true,\n tag: 'tag:yaml.org,2002:bool',\n test: /^(?:N|n|[Nn]o|NO|[Ff]alse|FALSE|[Oo]ff|OFF)$/,\n resolve: () => new Scalar(false),\n stringify: boolStringify\n};\n\nexport { falseTag, trueTag };\n","import { Scalar } from '../../nodes/Scalar.js';\nimport { stringifyNumber } from '../../stringify/stringifyNumber.js';\n\nconst floatNaN = {\n identify: value => typeof value === 'number',\n default: true,\n tag: 'tag:yaml.org,2002:float',\n test: /^(?:[-+]?\\.(?:inf|Inf|INF)|\\.nan|\\.NaN|\\.NAN)$/,\n resolve: (str) => str.slice(-3).toLowerCase() === 'nan'\n ? NaN\n : str[0] === '-'\n ? Number.NEGATIVE_INFINITY\n : Number.POSITIVE_INFINITY,\n stringify: stringifyNumber\n};\nconst floatExp = {\n identify: value => typeof value === 'number',\n default: true,\n tag: 'tag:yaml.org,2002:float',\n format: 'EXP',\n test: /^[-+]?(?:[0-9][0-9_]*)?(?:\\.[0-9_]*)?[eE][-+]?[0-9]+$/,\n resolve: (str) => parseFloat(str.replace(/_/g, '')),\n stringify(node) {\n const num = Number(node.value);\n return isFinite(num) ? num.toExponential() : stringifyNumber(node);\n }\n};\nconst float = {\n identify: value => typeof value === 'number',\n default: true,\n tag: 'tag:yaml.org,2002:float',\n test: /^[-+]?(?:[0-9][0-9_]*)?\\.[0-9_]*$/,\n resolve(str) {\n const node = new Scalar(parseFloat(str.replace(/_/g, '')));\n const dot = str.indexOf('.');\n if (dot !== -1) {\n const f = str.substring(dot + 1).replace(/_/g, '');\n if (f[f.length - 1] === '0')\n node.minFractionDigits = f.length;\n }\n return node;\n },\n stringify: stringifyNumber\n};\n\nexport { float, floatExp, floatNaN };\n","import { stringifyNumber } from '../../stringify/stringifyNumber.js';\n\nconst intIdentify = (value) => typeof value === 'bigint' || Number.isInteger(value);\nfunction intResolve(str, offset, radix, { intAsBigInt }) {\n const sign = str[0];\n if (sign === '-' || sign === '+')\n offset += 1;\n str = str.substring(offset).replace(/_/g, '');\n if (intAsBigInt) {\n switch (radix) {\n case 2:\n str = `0b${str}`;\n break;\n case 8:\n str = `0o${str}`;\n break;\n case 16:\n str = `0x${str}`;\n break;\n }\n const n = BigInt(str);\n return sign === '-' ? BigInt(-1) * n : n;\n }\n const n = parseInt(str, radix);\n return sign === '-' ? -1 * n : n;\n}\nfunction intStringify(node, radix, prefix) {\n const { value } = node;\n if (intIdentify(value)) {\n const str = value.toString(radix);\n return value < 0 ? '-' + prefix + str.substr(1) : prefix + str;\n }\n return stringifyNumber(node);\n}\nconst intBin = {\n identify: intIdentify,\n default: true,\n tag: 'tag:yaml.org,2002:int',\n format: 'BIN',\n test: /^[-+]?0b[0-1_]+$/,\n resolve: (str, _onError, opt) => intResolve(str, 2, 2, opt),\n stringify: node => intStringify(node, 2, '0b')\n};\nconst intOct = {\n identify: intIdentify,\n default: true,\n tag: 'tag:yaml.org,2002:int',\n format: 'OCT',\n test: /^[-+]?0[0-7_]+$/,\n resolve: (str, _onError, opt) => intResolve(str, 1, 8, opt),\n stringify: node => intStringify(node, 8, '0')\n};\nconst int = {\n identify: intIdentify,\n default: true,\n tag: 'tag:yaml.org,2002:int',\n test: /^[-+]?[0-9][0-9_]*$/,\n resolve: (str, _onError, opt) => intResolve(str, 0, 10, opt),\n stringify: stringifyNumber\n};\nconst intHex = {\n identify: intIdentify,\n default: true,\n tag: 'tag:yaml.org,2002:int',\n format: 'HEX',\n test: /^[-+]?0x[0-9a-fA-F_]+$/,\n resolve: (str, _onError, opt) => intResolve(str, 2, 16, opt),\n stringify: node => intStringify(node, 16, '0x')\n};\n\nexport { int, intBin, intHex, intOct };\n","import { isMap, isPair, isScalar } from '../../nodes/identity.js';\nimport { Pair, createPair } from '../../nodes/Pair.js';\nimport { YAMLMap, findPair } from '../../nodes/YAMLMap.js';\n\nclass YAMLSet extends YAMLMap {\n constructor(schema) {\n super(schema);\n this.tag = YAMLSet.tag;\n }\n add(key) {\n let pair;\n if (isPair(key))\n pair = key;\n else if (key &&\n typeof key === 'object' &&\n 'key' in key &&\n 'value' in key &&\n key.value === null)\n pair = new Pair(key.key, null);\n else\n pair = new Pair(key, null);\n const prev = findPair(this.items, pair.key);\n if (!prev)\n this.items.push(pair);\n }\n /**\n * If `keepPair` is `true`, returns the Pair matching `key`.\n * Otherwise, returns the value of that Pair's key.\n */\n get(key, keepPair) {\n const pair = findPair(this.items, key);\n return !keepPair && isPair(pair)\n ? isScalar(pair.key)\n ? pair.key.value\n : pair.key\n : pair;\n }\n set(key, value) {\n if (typeof value !== 'boolean')\n throw new Error(`Expected boolean value for set(key, value) in a YAML set, not ${typeof value}`);\n const prev = findPair(this.items, key);\n if (prev && !value) {\n this.items.splice(this.items.indexOf(prev), 1);\n }\n else if (!prev && value) {\n this.items.push(new Pair(key));\n }\n }\n toJSON(_, ctx) {\n return super.toJSON(_, ctx, Set);\n }\n toString(ctx, onComment, onChompKeep) {\n if (!ctx)\n return JSON.stringify(this);\n if (this.hasAllNullValues(true))\n return super.toString(Object.assign({}, ctx, { allNullValues: true }), onComment, onChompKeep);\n else\n throw new Error('Set items must all have null values');\n }\n static from(schema, iterable, ctx) {\n const { replacer } = ctx;\n const set = new this(schema);\n if (iterable && Symbol.iterator in Object(iterable))\n for (let value of iterable) {\n if (typeof replacer === 'function')\n value = replacer.call(iterable, value, value);\n set.items.push(createPair(value, null, ctx));\n }\n return set;\n }\n}\nYAMLSet.tag = 'tag:yaml.org,2002:set';\nconst set = {\n collection: 'map',\n identify: value => value instanceof Set,\n nodeClass: YAMLSet,\n default: false,\n tag: 'tag:yaml.org,2002:set',\n createNode: (schema, iterable, ctx) => YAMLSet.from(schema, iterable, ctx),\n resolve(map, onError) {\n if (isMap(map)) {\n if (map.hasAllNullValues(true))\n return Object.assign(new YAMLSet(), map);\n else\n onError('Set items must all have null values');\n }\n else\n onError('Expected a mapping for this tag');\n return map;\n }\n};\n\nexport { YAMLSet, set };\n","import { stringifyNumber } from '../../stringify/stringifyNumber.js';\n\n/** Internal types handle bigint as number, because TS can't figure it out. */\nfunction parseSexagesimal(str, asBigInt) {\n const sign = str[0];\n const parts = sign === '-' || sign === '+' ? str.substring(1) : str;\n const num = (n) => asBigInt ? BigInt(n) : Number(n);\n const res = parts\n .replace(/_/g, '')\n .split(':')\n .reduce((res, p) => res * num(60) + num(p), num(0));\n return (sign === '-' ? num(-1) * res : res);\n}\n/**\n * hhhh:mm:ss.sss\n *\n * Internal types handle bigint as number, because TS can't figure it out.\n */\nfunction stringifySexagesimal(node) {\n let { value } = node;\n let num = (n) => n;\n if (typeof value === 'bigint')\n num = n => BigInt(n);\n else if (isNaN(value) || !isFinite(value))\n return stringifyNumber(node);\n let sign = '';\n if (value < 0) {\n sign = '-';\n value *= num(-1);\n }\n const _60 = num(60);\n const parts = [value % _60]; // seconds, including ms\n if (value < 60) {\n parts.unshift(0); // at least one : is required\n }\n else {\n value = (value - parts[0]) / _60;\n parts.unshift(value % _60); // minutes\n if (value >= 60) {\n value = (value - parts[0]) / _60;\n parts.unshift(value); // hours\n }\n }\n return (sign +\n parts\n .map(n => String(n).padStart(2, '0'))\n .join(':')\n .replace(/000000\\d*$/, '') // % 60 may introduce error\n );\n}\nconst intTime = {\n identify: value => typeof value === 'bigint' || Number.isInteger(value),\n default: true,\n tag: 'tag:yaml.org,2002:int',\n format: 'TIME',\n test: /^[-+]?[0-9][0-9_]*(?::[0-5]?[0-9])+$/,\n resolve: (str, _onError, { intAsBigInt }) => parseSexagesimal(str, intAsBigInt),\n stringify: stringifySexagesimal\n};\nconst floatTime = {\n identify: value => typeof value === 'number',\n default: true,\n tag: 'tag:yaml.org,2002:float',\n format: 'TIME',\n test: /^[-+]?[0-9][0-9_]*(?::[0-5]?[0-9])+\\.[0-9_]*$/,\n resolve: str => parseSexagesimal(str, false),\n stringify: stringifySexagesimal\n};\nconst timestamp = {\n identify: value => value instanceof Date,\n default: true,\n tag: 'tag:yaml.org,2002:timestamp',\n // If the time zone is omitted, the timestamp is assumed to be specified in UTC. The time part\n // may be omitted altogether, resulting in a date format. In such a case, the time part is\n // assumed to be 00:00:00Z (start of day, UTC).\n test: RegExp('^([0-9]{4})-([0-9]{1,2})-([0-9]{1,2})' + // YYYY-Mm-Dd\n '(?:' + // time is optional\n '(?:t|T|[ \\\\t]+)' + // t | T | whitespace\n '([0-9]{1,2}):([0-9]{1,2}):([0-9]{1,2}(\\\\.[0-9]+)?)' + // Hh:Mm:Ss(.ss)?\n '(?:[ \\\\t]*(Z|[-+][012]?[0-9](?::[0-9]{2})?))?' + // Z | +5 | -03:30\n ')?$'),\n resolve(str) {\n const match = str.match(timestamp.test);\n if (!match)\n throw new Error('!!timestamp expects a date, starting with yyyy-mm-dd');\n const [, year, month, day, hour, minute, second] = match.map(Number);\n const millisec = match[7] ? Number((match[7] + '00').substr(1, 3)) : 0;\n let date = Date.UTC(year, month - 1, day, hour || 0, minute || 0, second || 0, millisec);\n const tz = match[8];\n if (tz && tz !== 'Z') {\n let d = parseSexagesimal(tz, false);\n if (Math.abs(d) < 30)\n d *= 60;\n date -= 60000 * d;\n }\n return new Date(date);\n },\n stringify: ({ value }) => value?.toISOString().replace(/(T00:00:00)?\\.000Z$/, '') ?? ''\n};\n\nexport { floatTime, intTime, timestamp };\n","import { map } from '../common/map.js';\nimport { nullTag } from '../common/null.js';\nimport { seq } from '../common/seq.js';\nimport { string } from '../common/string.js';\nimport { binary } from './binary.js';\nimport { trueTag, falseTag } from './bool.js';\nimport { floatNaN, floatExp, float } from './float.js';\nimport { intBin, intOct, int, intHex } from './int.js';\nimport { merge } from './merge.js';\nimport { omap } from './omap.js';\nimport { pairs } from './pairs.js';\nimport { set } from './set.js';\nimport { intTime, floatTime, timestamp } from './timestamp.js';\n\nconst schema = [\n map,\n seq,\n string,\n nullTag,\n trueTag,\n falseTag,\n intBin,\n intOct,\n int,\n intHex,\n floatNaN,\n floatExp,\n float,\n binary,\n merge,\n omap,\n pairs,\n set,\n intTime,\n floatTime,\n timestamp\n];\n\nexport { schema };\n","import { map } from './common/map.js';\nimport { nullTag } from './common/null.js';\nimport { seq } from './common/seq.js';\nimport { string } from './common/string.js';\nimport { boolTag } from './core/bool.js';\nimport { floatNaN, floatExp, float } from './core/float.js';\nimport { intOct, intHex, int } from './core/int.js';\nimport { schema } from './core/schema.js';\nimport { schema as schema$1 } from './json/schema.js';\nimport { binary } from './yaml-1.1/binary.js';\nimport { merge } from './yaml-1.1/merge.js';\nimport { omap } from './yaml-1.1/omap.js';\nimport { pairs } from './yaml-1.1/pairs.js';\nimport { schema as schema$2 } from './yaml-1.1/schema.js';\nimport { set } from './yaml-1.1/set.js';\nimport { timestamp, intTime, floatTime } from './yaml-1.1/timestamp.js';\n\nconst schemas = new Map([\n ['core', schema],\n ['failsafe', [map, seq, string]],\n ['json', schema$1],\n ['yaml11', schema$2],\n ['yaml-1.1', schema$2]\n]);\nconst tagsByName = {\n binary,\n bool: boolTag,\n float,\n floatExp,\n floatNaN,\n floatTime,\n int,\n intHex,\n intOct,\n intTime,\n map,\n merge,\n null: nullTag,\n omap,\n pairs,\n seq,\n set,\n timestamp\n};\nconst coreKnownTags = {\n 'tag:yaml.org,2002:binary': binary,\n 'tag:yaml.org,2002:merge': merge,\n 'tag:yaml.org,2002:omap': omap,\n 'tag:yaml.org,2002:pairs': pairs,\n 'tag:yaml.org,2002:set': set,\n 'tag:yaml.org,2002:timestamp': timestamp\n};\nfunction getTags(customTags, schemaName, addMergeTag) {\n const schemaTags = schemas.get(schemaName);\n if (schemaTags && !customTags) {\n return addMergeTag && !schemaTags.includes(merge)\n ? schemaTags.concat(merge)\n : schemaTags.slice();\n }\n let tags = schemaTags;\n if (!tags) {\n if (Array.isArray(customTags))\n tags = [];\n else {\n const keys = Array.from(schemas.keys())\n .filter(key => key !== 'yaml11')\n .map(key => JSON.stringify(key))\n .join(', ');\n throw new Error(`Unknown schema \"${schemaName}\"; use one of ${keys} or define customTags array`);\n }\n }\n if (Array.isArray(customTags)) {\n for (const tag of customTags)\n tags = tags.concat(tag);\n }\n else if (typeof customTags === 'function') {\n tags = customTags(tags.slice());\n }\n if (addMergeTag)\n tags = tags.concat(merge);\n return tags.reduce((tags, tag) => {\n const tagObj = typeof tag === 'string' ? tagsByName[tag] : tag;\n if (!tagObj) {\n const tagName = JSON.stringify(tag);\n const keys = Object.keys(tagsByName)\n .map(key => JSON.stringify(key))\n .join(', ');\n throw new Error(`Unknown custom tag ${tagName}; use one of ${keys}`);\n }\n if (!tags.includes(tagObj))\n tags.push(tagObj);\n return tags;\n }, []);\n}\n\nexport { coreKnownTags, getTags };\n","class YAMLError extends Error {\n constructor(name, pos, code, message) {\n super();\n this.name = name;\n this.code = code;\n this.message = message;\n this.pos = pos;\n }\n}\nclass YAMLParseError extends YAMLError {\n constructor(pos, code, message) {\n super('YAMLParseError', pos, code, message);\n }\n}\nclass YAMLWarning extends YAMLError {\n constructor(pos, code, message) {\n super('YAMLWarning', pos, code, message);\n }\n}\nconst prettifyError = (src, lc) => (error) => {\n if (error.pos[0] === -1)\n return;\n error.linePos = error.pos.map(pos => lc.linePos(pos));\n const { line, col } = error.linePos[0];\n error.message += ` at line ${line}, column ${col}`;\n let ci = col - 1;\n let lineStr = src\n .substring(lc.lineStarts[line - 1], lc.lineStarts[line])\n .replace(/[\\n\\r]+$/, '');\n // Trim to max 80 chars, keeping col position near the middle\n if (ci >= 60 && lineStr.length > 80) {\n const trimStart = Math.min(ci - 39, lineStr.length - 79);\n lineStr = '…' + lineStr.substring(trimStart);\n ci -= trimStart - 1;\n }\n if (lineStr.length > 80)\n lineStr = lineStr.substring(0, 79) + '…';\n // Include previous line in context if pointing at line start\n if (line > 1 && /^ *$/.test(lineStr.substring(0, ci))) {\n // Regexp won't match if start is trimmed\n let prev = src.substring(lc.lineStarts[line - 2], lc.lineStarts[line - 1]);\n if (prev.length > 80)\n prev = prev.substring(0, 79) + '…\\n';\n lineStr = prev + lineStr;\n }\n if (/[^ ]/.test(lineStr)) {\n let count = 1;\n const end = error.linePos[1];\n if (end?.line === line && end.col > col) {\n count = Math.max(1, Math.min(end.col - col, 80 - ci));\n }\n const pointer = ' '.repeat(ci) + '^'.repeat(count);\n error.message += `:\\n\\n${lineStr}\\n${pointer}\\n`;\n }\n};\n\nexport { YAMLError, YAMLParseError, YAMLWarning, prettifyError };\n","const BREAK = Symbol('break visit');\nconst SKIP = Symbol('skip children');\nconst REMOVE = Symbol('remove item');\n/**\n * Apply a visitor to a CST document or item.\n *\n * Walks through the tree (depth-first) starting from the root, calling a\n * `visitor` function with two arguments when entering each item:\n * - `item`: The current item, which included the following members:\n * - `start: SourceToken[]` – Source tokens before the key or value,\n * possibly including its anchor or tag.\n * - `key?: Token | null` – Set for pair values. May then be `null`, if\n * the key before the `:` separator is empty.\n * - `sep?: SourceToken[]` – Source tokens between the key and the value,\n * which should include the `:` map value indicator if `value` is set.\n * - `value?: Token` – The value of a sequence item, or of a map pair.\n * - `path`: The steps from the root to the current node, as an array of\n * `['key' | 'value', number]` tuples.\n *\n * The return value of the visitor may be used to control the traversal:\n * - `undefined` (default): Do nothing and continue\n * - `visit.SKIP`: Do not visit the children of this token, continue with\n * next sibling\n * - `visit.BREAK`: Terminate traversal completely\n * - `visit.REMOVE`: Remove the current item, then continue with the next one\n * - `number`: Set the index of the next step. This is useful especially if\n * the index of the current token has changed.\n * - `function`: Define the next visitor for this item. After the original\n * visitor is called on item entry, next visitors are called after handling\n * a non-empty `key` and when exiting the item.\n */\nfunction visit(cst, visitor) {\n if ('type' in cst && cst.type === 'document')\n cst = { start: cst.start, value: cst.value };\n _visit(Object.freeze([]), cst, visitor);\n}\n// Without the `as symbol` casts, TS declares these in the `visit`\n// namespace using `var`, but then complains about that because\n// `unique symbol` must be `const`.\n/** Terminate visit traversal completely */\nvisit.BREAK = BREAK;\n/** Do not visit the children of the current item */\nvisit.SKIP = SKIP;\n/** Remove the current item */\nvisit.REMOVE = REMOVE;\n/** Find the item at `path` from `cst` as the root */\nvisit.itemAtPath = (cst, path) => {\n let item = cst;\n for (const [field, index] of path) {\n const tok = item?.[field];\n if (tok && 'items' in tok) {\n item = tok.items[index];\n }\n else\n return undefined;\n }\n return item;\n};\n/**\n * Get the immediate parent collection of the item at `path` from `cst` as the root.\n *\n * Throws an error if the collection is not found, which should never happen if the item itself exists.\n */\nvisit.parentCollection = (cst, path) => {\n const parent = visit.itemAtPath(cst, path.slice(0, -1));\n const field = path[path.length - 1][0];\n const coll = parent?.[field];\n if (coll && 'items' in coll)\n return coll;\n throw new Error('Parent collection not found');\n};\nfunction _visit(path, item, visitor) {\n let ctrl = visitor(item, path);\n if (typeof ctrl === 'symbol')\n return ctrl;\n for (const field of ['key', 'value']) {\n const token = item[field];\n if (token && 'items' in token) {\n for (let i = 0; i < token.items.length; ++i) {\n const ci = _visit(Object.freeze(path.concat([[field, i]])), token.items[i], visitor);\n if (typeof ci === 'number')\n i = ci - 1;\n else if (ci === BREAK)\n return BREAK;\n else if (ci === REMOVE) {\n token.items.splice(i, 1);\n i -= 1;\n }\n }\n if (typeof ctrl === 'function' && field === 'key')\n ctrl = ctrl(item, path);\n }\n }\n return typeof ctrl === 'function' ? ctrl(item, path) : ctrl;\n}\n\nexport { visit };\n","import { Note } from \"../core\";\n\nexport enum GamakaType {\n // Kampitam (~)\n // The oscilation between 2 notes - eg p , S..n S..n S..n\n Kampitham = \"Kampitham\",\n\n // Nokku (w)\n Nokku = \"Nokku\",\n\n // Spuritham (∴ / u+2234) - Stress on the second note of a jantai\n Spuritham = \"Spuritham\",\n\n // Prathyagatham (∵ / u+2235) - Similar to reverse of Spuritham (in descending order)\n Prathyagatham = \"Prathyagatham\",\n\n // Raavi (^)\n Aahaatam_Raavi = \"Raavi\",\n\n // Kandippu (✓)\n // eg - Shankarabharanam's S. ,,, n , P ,,, - where the n is subtle\n Aahaatam_Kandippu = \"Kandippu\",\n\n // Vali (⌒ - U+2312)\n Vaali = \"Vaali\",\n\n // Odukkal (x):\n // A veena gamakam where the note itself is stretched more to get the next\n // note effect (instead of plucking the next note itself).\n // Not possible where plucking of strings is not possible.\n // On voice etc it just will sound like an Eetra Jaaru.\n Odukkal = \"Odukkal\",\n\n // (/) Ascension from one note to another - eg S / P\n Jaaru_Eetra = \"EetraJaaru\",\n\n // (\\) Descending from one note to another - eg P \\ S\n Jaaru_Irakka = \"IrakkaJaaru\",\n\n // Orikkai (γ)\n // eg S~~ RN N~~S.D D~~~NP\n Orikkai = \"Orikkai\",\n}\n\nexport class Gamaka {\n constructor(public readonly type: GamakaType) {}\n debugValue(): any {\n return { type: this.type };\n }\n}\n\nexport class JaaruGamaka extends Gamaka {\n constructor(\n public readonly ascending = true,\n public readonly startingNote: null | Note = null,\n ) {\n super(ascending ? GamakaType.Jaaru_Eetra : GamakaType.Jaaru_Irakka);\n }\n\n debugValue(): any {\n const out = { ...super.debugValue(), ascending: this.ascending };\n if (this.startingNote) out[\"startingNote\"] = this.startingNote.debugValue();\n return out;\n }\n}\n\nexport function parseEmbelishment(value: string): [any, boolean] {\n value = value.substring(1);\n if (value == \"\") {\n return [new Gamaka(GamakaType.Kampitham), true];\n } else if (value == \"^\") {\n return [new Gamaka(GamakaType.Aahaatam_Raavi), true];\n } else if (value == \"~\") {\n return [new Gamaka(GamakaType.Vaali), true];\n } else if (value == \"w\" || value == \"W\") {\n return [new Gamaka(GamakaType.Nokku), true];\n } else if (value == \"∴\" || value == \":-\") {\n return [new Gamaka(GamakaType.Spuritham), true];\n } else if (value == \"∵\" || value == \"-:\") {\n return [new Gamaka(GamakaType.Prathyagatham), true];\n } else if (value == \"✓\" || value == \"./\" || value == \".\\\\\") {\n return [new Gamaka(GamakaType.Aahaatam_Kandippu), true];\n } else if (value.endsWith(\"/\")) {\n value = value.substring(0, value.length - 1).trim();\n return [new JaaruGamaka(true, value.length > 0 ? new Note(value) : null), true];\n } else if (value.endsWith(\"\\\\\")) {\n value = value.substring(0, value.length - 1);\n return [new JaaruGamaka(false, value.length > 0 ? new Note(value) : null), true];\n } else if (value == \"x\") {\n return [new Gamaka(GamakaType.Odukkal), true];\n } else if (value == \"γ\" || value == \"Y\") {\n return [new Gamaka(GamakaType.Orikkai), true];\n }\n // throw new Error(\"Invalid carnatic embelishment: \" + value);\n return [null, false];\n}\n","import { BOM, DOCUMENT, FLOW_END, SCALAR } from './cst.js';\n\n/*\nSTART -> stream\n\nstream\n directive -> line-end -> stream\n indent + line-end -> stream\n [else] -> line-start\n\nline-end\n comment -> line-end\n newline -> .\n input-end -> END\n\nline-start\n doc-start -> doc\n doc-end -> stream\n [else] -> indent -> block-start\n\nblock-start\n seq-item-start -> block-start\n explicit-key-start -> block-start\n map-value-start -> block-start\n [else] -> doc\n\ndoc\n line-end -> line-start\n spaces -> doc\n anchor -> doc\n tag -> doc\n flow-start -> flow -> doc\n flow-end -> error -> doc\n seq-item-start -> error -> doc\n explicit-key-start -> error -> doc\n map-value-start -> doc\n alias -> doc\n quote-start -> quoted-scalar -> doc\n block-scalar-header -> line-end -> block-scalar(min) -> line-start\n [else] -> plain-scalar(false, min) -> doc\n\nflow\n line-end -> flow\n spaces -> flow\n anchor -> flow\n tag -> flow\n flow-start -> flow -> flow\n flow-end -> .\n seq-item-start -> error -> flow\n explicit-key-start -> flow\n map-value-start -> flow\n alias -> flow\n quote-start -> quoted-scalar -> flow\n comma -> flow\n [else] -> plain-scalar(true, 0) -> flow\n\nquoted-scalar\n quote-end -> .\n [else] -> quoted-scalar\n\nblock-scalar(min)\n newline + peek(indent < min) -> .\n [else] -> block-scalar(min)\n\nplain-scalar(is-flow, min)\n scalar-end(is-flow) -> .\n peek(newline + (indent < min)) -> .\n [else] -> plain-scalar(min)\n*/\nfunction isEmpty(ch) {\n switch (ch) {\n case undefined:\n case ' ':\n case '\\n':\n case '\\r':\n case '\\t':\n return true;\n default:\n return false;\n }\n}\nconst hexDigits = new Set('0123456789ABCDEFabcdef');\nconst tagChars = new Set(\"0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz-#;/?:@&=+$_.!~*'()\");\nconst flowIndicatorChars = new Set(',[]{}');\nconst invalidAnchorChars = new Set(' ,[]{}\\n\\r\\t');\nconst isNotAnchorChar = (ch) => !ch || invalidAnchorChars.has(ch);\n/**\n * Splits an input string into lexical tokens, i.e. smaller strings that are\n * easily identifiable by `tokens.tokenType()`.\n *\n * Lexing starts always in a \"stream\" context. Incomplete input may be buffered\n * until a complete token can be emitted.\n *\n * In addition to slices of the original input, the following control characters\n * may also be emitted:\n *\n * - `\\x02` (Start of Text): A document starts with the next token\n * - `\\x18` (Cancel): Unexpected end of flow-mode (indicates an error)\n * - `\\x1f` (Unit Separator): Next token is a scalar value\n * - `\\u{FEFF}` (Byte order mark): Emitted separately outside documents\n */\nclass Lexer {\n constructor() {\n /**\n * Flag indicating whether the end of the current buffer marks the end of\n * all input\n */\n this.atEnd = false;\n /**\n * Explicit indent set in block scalar header, as an offset from the current\n * minimum indent, so e.g. set to 1 from a header `|2+`. Set to -1 if not\n * explicitly set.\n */\n this.blockScalarIndent = -1;\n /**\n * Block scalars that include a + (keep) chomping indicator in their header\n * include trailing empty lines, which are otherwise excluded from the\n * scalar's contents.\n */\n this.blockScalarKeep = false;\n /** Current input */\n this.buffer = '';\n /**\n * Flag noting whether the map value indicator : can immediately follow this\n * node within a flow context.\n */\n this.flowKey = false;\n /** Count of surrounding flow collection levels. */\n this.flowLevel = 0;\n /**\n * Minimum level of indentation required for next lines to be parsed as a\n * part of the current scalar value.\n */\n this.indentNext = 0;\n /** Indentation level of the current line. */\n this.indentValue = 0;\n /** Position of the next \\n character. */\n this.lineEndPos = null;\n /** Stores the state of the lexer if reaching the end of incpomplete input */\n this.next = null;\n /** A pointer to `buffer`; the current position of the lexer. */\n this.pos = 0;\n }\n /**\n * Generate YAML tokens from the `source` string. If `incomplete`,\n * a part of the last line may be left as a buffer for the next call.\n *\n * @returns A generator of lexical tokens\n */\n *lex(source, incomplete = false) {\n if (source) {\n if (typeof source !== 'string')\n throw TypeError('source is not a string');\n this.buffer = this.buffer ? this.buffer + source : source;\n this.lineEndPos = null;\n }\n this.atEnd = !incomplete;\n let next = this.next ?? 'stream';\n while (next && (incomplete || this.hasChars(1)))\n next = yield* this.parseNext(next);\n }\n atLineEnd() {\n let i = this.pos;\n let ch = this.buffer[i];\n while (ch === ' ' || ch === '\\t')\n ch = this.buffer[++i];\n if (!ch || ch === '#' || ch === '\\n')\n return true;\n if (ch === '\\r')\n return this.buffer[i + 1] === '\\n';\n return false;\n }\n charAt(n) {\n return this.buffer[this.pos + n];\n }\n continueScalar(offset) {\n let ch = this.buffer[offset];\n if (this.indentNext > 0) {\n let indent = 0;\n while (ch === ' ')\n ch = this.buffer[++indent + offset];\n if (ch === '\\r') {\n const next = this.buffer[indent + offset + 1];\n if (next === '\\n' || (!next && !this.atEnd))\n return offset + indent + 1;\n }\n return ch === '\\n' || indent >= this.indentNext || (!ch && !this.atEnd)\n ? offset + indent\n : -1;\n }\n if (ch === '-' || ch === '.') {\n const dt = this.buffer.substr(offset, 3);\n if ((dt === '---' || dt === '...') && isEmpty(this.buffer[offset + 3]))\n return -1;\n }\n return offset;\n }\n getLine() {\n let end = this.lineEndPos;\n if (typeof end !== 'number' || (end !== -1 && end < this.pos)) {\n end = this.buffer.indexOf('\\n', this.pos);\n this.lineEndPos = end;\n }\n if (end === -1)\n return this.atEnd ? this.buffer.substring(this.pos) : null;\n if (this.buffer[end - 1] === '\\r')\n end -= 1;\n return this.buffer.substring(this.pos, end);\n }\n hasChars(n) {\n return this.pos + n <= this.buffer.length;\n }\n setNext(state) {\n this.buffer = this.buffer.substring(this.pos);\n this.pos = 0;\n this.lineEndPos = null;\n this.next = state;\n return null;\n }\n peek(n) {\n return this.buffer.substr(this.pos, n);\n }\n *parseNext(next) {\n switch (next) {\n case 'stream':\n return yield* this.parseStream();\n case 'line-start':\n return yield* this.parseLineStart();\n case 'block-start':\n return yield* this.parseBlockStart();\n case 'doc':\n return yield* this.parseDocument();\n case 'flow':\n return yield* this.parseFlowCollection();\n case 'quoted-scalar':\n return yield* this.parseQuotedScalar();\n case 'block-scalar':\n return yield* this.parseBlockScalar();\n case 'plain-scalar':\n return yield* this.parsePlainScalar();\n }\n }\n *parseStream() {\n let line = this.getLine();\n if (line === null)\n return this.setNext('stream');\n if (line[0] === BOM) {\n yield* this.pushCount(1);\n line = line.substring(1);\n }\n if (line[0] === '%') {\n let dirEnd = line.length;\n let cs = line.indexOf('#');\n while (cs !== -1) {\n const ch = line[cs - 1];\n if (ch === ' ' || ch === '\\t') {\n dirEnd = cs - 1;\n break;\n }\n else {\n cs = line.indexOf('#', cs + 1);\n }\n }\n while (true) {\n const ch = line[dirEnd - 1];\n if (ch === ' ' || ch === '\\t')\n dirEnd -= 1;\n else\n break;\n }\n const n = (yield* this.pushCount(dirEnd)) + (yield* this.pushSpaces(true));\n yield* this.pushCount(line.length - n); // possible comment\n this.pushNewline();\n return 'stream';\n }\n if (this.atLineEnd()) {\n const sp = yield* this.pushSpaces(true);\n yield* this.pushCount(line.length - sp);\n yield* this.pushNewline();\n return 'stream';\n }\n yield DOCUMENT;\n return yield* this.parseLineStart();\n }\n *parseLineStart() {\n const ch = this.charAt(0);\n if (!ch && !this.atEnd)\n return this.setNext('line-start');\n if (ch === '-' || ch === '.') {\n if (!this.atEnd && !this.hasChars(4))\n return this.setNext('line-start');\n const s = this.peek(3);\n if ((s === '---' || s === '...') && isEmpty(this.charAt(3))) {\n yield* this.pushCount(3);\n this.indentValue = 0;\n this.indentNext = 0;\n return s === '---' ? 'doc' : 'stream';\n }\n }\n this.indentValue = yield* this.pushSpaces(false);\n if (this.indentNext > this.indentValue && !isEmpty(this.charAt(1)))\n this.indentNext = this.indentValue;\n return yield* this.parseBlockStart();\n }\n *parseBlockStart() {\n const [ch0, ch1] = this.peek(2);\n if (!ch1 && !this.atEnd)\n return this.setNext('block-start');\n if ((ch0 === '-' || ch0 === '?' || ch0 === ':') && isEmpty(ch1)) {\n const n = (yield* this.pushCount(1)) + (yield* this.pushSpaces(true));\n this.indentNext = this.indentValue + 1;\n this.indentValue += n;\n return yield* this.parseBlockStart();\n }\n return 'doc';\n }\n *parseDocument() {\n yield* this.pushSpaces(true);\n const line = this.getLine();\n if (line === null)\n return this.setNext('doc');\n let n = yield* this.pushIndicators();\n switch (line[n]) {\n case '#':\n yield* this.pushCount(line.length - n);\n // fallthrough\n case undefined:\n yield* this.pushNewline();\n return yield* this.parseLineStart();\n case '{':\n case '[':\n yield* this.pushCount(1);\n this.flowKey = false;\n this.flowLevel = 1;\n return 'flow';\n case '}':\n case ']':\n // this is an error\n yield* this.pushCount(1);\n return 'doc';\n case '*':\n yield* this.pushUntil(isNotAnchorChar);\n return 'doc';\n case '\"':\n case \"'\":\n return yield* this.parseQuotedScalar();\n case '|':\n case '>':\n n += yield* this.parseBlockScalarHeader();\n n += yield* this.pushSpaces(true);\n yield* this.pushCount(line.length - n);\n yield* this.pushNewline();\n return yield* this.parseBlockScalar();\n default:\n return yield* this.parsePlainScalar();\n }\n }\n *parseFlowCollection() {\n let nl, sp;\n let indent = -1;\n do {\n nl = yield* this.pushNewline();\n if (nl > 0) {\n sp = yield* this.pushSpaces(false);\n this.indentValue = indent = sp;\n }\n else {\n sp = 0;\n }\n sp += yield* this.pushSpaces(true);\n } while (nl + sp > 0);\n const line = this.getLine();\n if (line === null)\n return this.setNext('flow');\n if ((indent !== -1 && indent < this.indentNext && line[0] !== '#') ||\n (indent === 0 &&\n (line.startsWith('---') || line.startsWith('...')) &&\n isEmpty(line[3]))) {\n // Allowing for the terminal ] or } at the same (rather than greater)\n // indent level as the initial [ or { is technically invalid, but\n // failing here would be surprising to users.\n const atFlowEndMarker = indent === this.indentNext - 1 &&\n this.flowLevel === 1 &&\n (line[0] === ']' || line[0] === '}');\n if (!atFlowEndMarker) {\n // this is an error\n this.flowLevel = 0;\n yield FLOW_END;\n return yield* this.parseLineStart();\n }\n }\n let n = 0;\n while (line[n] === ',') {\n n += yield* this.pushCount(1);\n n += yield* this.pushSpaces(true);\n this.flowKey = false;\n }\n n += yield* this.pushIndicators();\n switch (line[n]) {\n case undefined:\n return 'flow';\n case '#':\n yield* this.pushCount(line.length - n);\n return 'flow';\n case '{':\n case '[':\n yield* this.pushCount(1);\n this.flowKey = false;\n this.flowLevel += 1;\n return 'flow';\n case '}':\n case ']':\n yield* this.pushCount(1);\n this.flowKey = true;\n this.flowLevel -= 1;\n return this.flowLevel ? 'flow' : 'doc';\n case '*':\n yield* this.pushUntil(isNotAnchorChar);\n return 'flow';\n case '\"':\n case \"'\":\n this.flowKey = true;\n return yield* this.parseQuotedScalar();\n case ':': {\n const next = this.charAt(1);\n if (this.flowKey || isEmpty(next) || next === ',') {\n this.flowKey = false;\n yield* this.pushCount(1);\n yield* this.pushSpaces(true);\n return 'flow';\n }\n }\n // fallthrough\n default:\n this.flowKey = false;\n return yield* this.parsePlainScalar();\n }\n }\n *parseQuotedScalar() {\n const quote = this.charAt(0);\n let end = this.buffer.indexOf(quote, this.pos + 1);\n if (quote === \"'\") {\n while (end !== -1 && this.buffer[end + 1] === \"'\")\n end = this.buffer.indexOf(\"'\", end + 2);\n }\n else {\n // double-quote\n while (end !== -1) {\n let n = 0;\n while (this.buffer[end - 1 - n] === '\\\\')\n n += 1;\n if (n % 2 === 0)\n break;\n end = this.buffer.indexOf('\"', end + 1);\n }\n }\n // Only looking for newlines within the quotes\n const qb = this.buffer.substring(0, end);\n let nl = qb.indexOf('\\n', this.pos);\n if (nl !== -1) {\n while (nl !== -1) {\n const cs = this.continueScalar(nl + 1);\n if (cs === -1)\n break;\n nl = qb.indexOf('\\n', cs);\n }\n if (nl !== -1) {\n // this is an error caused by an unexpected unindent\n end = nl - (qb[nl - 1] === '\\r' ? 2 : 1);\n }\n }\n if (end === -1) {\n if (!this.atEnd)\n return this.setNext('quoted-scalar');\n end = this.buffer.length;\n }\n yield* this.pushToIndex(end + 1, false);\n return this.flowLevel ? 'flow' : 'doc';\n }\n *parseBlockScalarHeader() {\n this.blockScalarIndent = -1;\n this.blockScalarKeep = false;\n let i = this.pos;\n while (true) {\n const ch = this.buffer[++i];\n if (ch === '+')\n this.blockScalarKeep = true;\n else if (ch > '0' && ch <= '9')\n this.blockScalarIndent = Number(ch) - 1;\n else if (ch !== '-')\n break;\n }\n return yield* this.pushUntil(ch => isEmpty(ch) || ch === '#');\n }\n *parseBlockScalar() {\n let nl = this.pos - 1; // may be -1 if this.pos === 0\n let indent = 0;\n let ch;\n loop: for (let i = this.pos; (ch = this.buffer[i]); ++i) {\n switch (ch) {\n case ' ':\n indent += 1;\n break;\n case '\\n':\n nl = i;\n indent = 0;\n break;\n case '\\r': {\n const next = this.buffer[i + 1];\n if (!next && !this.atEnd)\n return this.setNext('block-scalar');\n if (next === '\\n')\n break;\n } // fallthrough\n default:\n break loop;\n }\n }\n if (!ch && !this.atEnd)\n return this.setNext('block-scalar');\n if (indent >= this.indentNext) {\n if (this.blockScalarIndent === -1)\n this.indentNext = indent;\n else {\n this.indentNext =\n this.blockScalarIndent + (this.indentNext === 0 ? 1 : this.indentNext);\n }\n do {\n const cs = this.continueScalar(nl + 1);\n if (cs === -1)\n break;\n nl = this.buffer.indexOf('\\n', cs);\n } while (nl !== -1);\n if (nl === -1) {\n if (!this.atEnd)\n return this.setNext('block-scalar');\n nl = this.buffer.length;\n }\n }\n // Trailing insufficiently indented tabs are invalid.\n // To catch that during parsing, we include them in the block scalar value.\n let i = nl + 1;\n ch = this.buffer[i];\n while (ch === ' ')\n ch = this.buffer[++i];\n if (ch === '\\t') {\n while (ch === '\\t' || ch === ' ' || ch === '\\r' || ch === '\\n')\n ch = this.buffer[++i];\n nl = i - 1;\n }\n else if (!this.blockScalarKeep) {\n do {\n let i = nl - 1;\n let ch = this.buffer[i];\n if (ch === '\\r')\n ch = this.buffer[--i];\n const lastChar = i; // Drop the line if last char not more indented\n while (ch === ' ')\n ch = this.buffer[--i];\n if (ch === '\\n' && i >= this.pos && i + 1 + indent > lastChar)\n nl = i;\n else\n break;\n } while (true);\n }\n yield SCALAR;\n yield* this.pushToIndex(nl + 1, true);\n return yield* this.parseLineStart();\n }\n *parsePlainScalar() {\n const inFlow = this.flowLevel > 0;\n let end = this.pos - 1;\n let i = this.pos - 1;\n let ch;\n while ((ch = this.buffer[++i])) {\n if (ch === ':') {\n const next = this.buffer[i + 1];\n if (isEmpty(next) || (inFlow && flowIndicatorChars.has(next)))\n break;\n end = i;\n }\n else if (isEmpty(ch)) {\n let next = this.buffer[i + 1];\n if (ch === '\\r') {\n if (next === '\\n') {\n i += 1;\n ch = '\\n';\n next = this.buffer[i + 1];\n }\n else\n end = i;\n }\n if (next === '#' || (inFlow && flowIndicatorChars.has(next)))\n break;\n if (ch === '\\n') {\n const cs = this.continueScalar(i + 1);\n if (cs === -1)\n break;\n i = Math.max(i, cs - 2); // to advance, but still account for ' #'\n }\n }\n else {\n if (inFlow && flowIndicatorChars.has(ch))\n break;\n end = i;\n }\n }\n if (!ch && !this.atEnd)\n return this.setNext('plain-scalar');\n yield SCALAR;\n yield* this.pushToIndex(end + 1, true);\n return inFlow ? 'flow' : 'doc';\n }\n *pushCount(n) {\n if (n > 0) {\n yield this.buffer.substr(this.pos, n);\n this.pos += n;\n return n;\n }\n return 0;\n }\n *pushToIndex(i, allowEmpty) {\n const s = this.buffer.slice(this.pos, i);\n if (s) {\n yield s;\n this.pos += s.length;\n return s.length;\n }\n else if (allowEmpty)\n yield '';\n return 0;\n }\n *pushIndicators() {\n switch (this.charAt(0)) {\n case '!':\n return ((yield* this.pushTag()) +\n (yield* this.pushSpaces(true)) +\n (yield* this.pushIndicators()));\n case '&':\n return ((yield* this.pushUntil(isNotAnchorChar)) +\n (yield* this.pushSpaces(true)) +\n (yield* this.pushIndicators()));\n case '-': // this is an error\n case '?': // this is an error outside flow collections\n case ':': {\n const inFlow = this.flowLevel > 0;\n const ch1 = this.charAt(1);\n if (isEmpty(ch1) || (inFlow && flowIndicatorChars.has(ch1))) {\n if (!inFlow)\n this.indentNext = this.indentValue + 1;\n else if (this.flowKey)\n this.flowKey = false;\n return ((yield* this.pushCount(1)) +\n (yield* this.pushSpaces(true)) +\n (yield* this.pushIndicators()));\n }\n }\n }\n return 0;\n }\n *pushTag() {\n if (this.charAt(1) === '<') {\n let i = this.pos + 2;\n let ch = this.buffer[i];\n while (!isEmpty(ch) && ch !== '>')\n ch = this.buffer[++i];\n return yield* this.pushToIndex(ch === '>' ? i + 1 : i, false);\n }\n else {\n let i = this.pos + 1;\n let ch = this.buffer[i];\n while (ch) {\n if (tagChars.has(ch))\n ch = this.buffer[++i];\n else if (ch === '%' &&\n hexDigits.has(this.buffer[i + 1]) &&\n hexDigits.has(this.buffer[i + 2])) {\n ch = this.buffer[(i += 3)];\n }\n else\n break;\n }\n return yield* this.pushToIndex(i, false);\n }\n }\n *pushNewline() {\n const ch = this.buffer[this.pos];\n if (ch === '\\n')\n return yield* this.pushCount(1);\n else if (ch === '\\r' && this.charAt(1) === '\\n')\n return yield* this.pushCount(2);\n else\n return 0;\n }\n *pushSpaces(allowTabs) {\n let i = this.pos - 1;\n let ch;\n do {\n ch = this.buffer[++i];\n } while (ch === ' ' || (allowTabs && ch === '\\t'));\n const n = i - this.pos;\n if (n > 0) {\n yield this.buffer.substr(this.pos, n);\n this.pos = i;\n }\n return n;\n }\n *pushUntil(test) {\n let i = this.pos;\n let ch = this.buffer[i];\n while (!test(ch))\n ch = this.buffer[++i];\n return yield* this.pushToIndex(i, false);\n }\n}\n\nexport { Lexer };\n","import * as TSU from \"@panyam/tsutils\";\nimport { ZERO, Atom, LeafAtom, Group } from \"./core\";\n\n/**\n * Represents an item to be positioned in collision-based layout.\n */\nexport interface CollisionLayoutItem {\n /** Time offset as a fraction (numerator/denominator) */\n timeOffset: TSU.Num.Fraction;\n /** Duration of this item */\n duration: TSU.Num.Fraction;\n /** Width of pre-embellishments (extends left from glyph position) */\n glyphOffset: number;\n /** Minimum width of the item (includes all embellishments and glyph) */\n minWidth: number;\n}\n\n/**\n * Result of collision-based layout for a single item.\n */\nexport interface CollisionLayoutResult {\n /** The calculated x position for the item */\n x: number;\n /** Whether the item was pushed right due to collision */\n wasCollision: boolean;\n}\n\n/**\n * Computes collision-based positions for a sequence of items within a container.\n *\n * ## Algorithm\n *\n * 1. Calculate ideal glyph position: `glyphX = (timeOffset / totalDuration) * containerWidth`\n * 2. Pre-embellishments extend left: `realX = glyphX - glyphOffset`\n * 3. Collision check: if `realX < prevItemEndX`, then `realX = prevItemEndX`\n * 4. Track: `prevItemEndX = realX + minWidth`\n *\n * @param items Items to position (must be in time order)\n * @param totalDuration Total duration of all items\n * @param containerWidth Width of the container to position items within\n * @returns Array of positions for each item\n */\nexport function computeCollisionLayout(\n items: CollisionLayoutItem[],\n totalDuration: TSU.Num.Fraction,\n containerWidth: number,\n): CollisionLayoutResult[] {\n const results: CollisionLayoutResult[] = [];\n let prevItemEndX = 0;\n let currTime = ZERO;\n\n for (const item of items) {\n // 1. Calculate ideal glyph position based on time offset\n const glyphX = totalDuration.isZero ? 0 : currTime.timesNum(containerWidth).divby(totalDuration).floor;\n\n // 2. Pre-embellishments extend left from glyph position\n let realX = glyphX - item.glyphOffset;\n\n // 3. Collision check: push right if overlapping previous item\n const wasCollision = realX < prevItemEndX;\n if (wasCollision) {\n realX = prevItemEndX;\n }\n\n results.push({ x: realX, wasCollision });\n\n // 4. Track end position for next collision check\n prevItemEndX = realX + item.minWidth;\n\n currTime = currTime.plus(item.duration);\n }\n\n return results;\n}\n\n/**\n * Base class for all renderable objects.\n *\n * Shape caches properties like bounding boxes to improve performance,\n * since bounding box calculations can be expensive. This also allows\n * testing layouts and positioning without worrying about implementation details.\n */\nexport abstract class Shape {\n private static idCounter = 0;\n readonly shapeId: number = Shape.idCounter++;\n\n /**\n * Note that x and y coordinates are not always the x and y coordinates\n * of the bounding box.\n * E.g., a circle's x and y coordinates are its center point and not the\n * top left corner.\n * These \"main\" coordinates are referred to as control coordinates.\n */\n protected _x: number | null = null;\n protected _y: number | null = null;\n protected _width: number | null = null;\n protected _height: number | null = null;\n protected _bbox: TSU.Geom.Rect;\n protected _minSize: TSU.Geom.Size;\n protected parentShape: Shape | null = null;\n /** Child shapes contained within this shape */\n children: Shape[] = [];\n\n /**\n * Gets the bounding box of this shape.\n * Calculates it if it hasn't been calculated yet.\n */\n get bbox(): TSU.Geom.Rect {\n if (!this._bbox) {\n this._bbox = this.refreshBBox();\n }\n return this._bbox;\n }\n\n /**\n * Gets the minimum size of this shape.\n * This is usually the size of the bounding box.\n */\n get minSize(): TSU.Geom.Size {\n if (!this._minSize) {\n this._minSize = this.refreshMinSize();\n }\n return this._minSize;\n }\n\n /**\n * Refreshes the bounding box of this shape.\n * Called when the shape knows the bbox it is tracking cannot be trusted\n * and has to be refreshed by calling native methods.\n * @returns The refreshed bounding box\n */\n protected abstract refreshBBox(): TSU.Geom.Rect;\n\n /**\n * Refreshes the minimum size of this shape.\n * @returns The refreshed minimum size\n */\n protected abstract refreshMinSize(): TSU.Geom.Size;\n\n /**\n * Updates the bounds of this shape.\n * @param x New x coordinate, or null to keep current value\n * @param y New y coordinate, or null to keep current value\n * @param w New width, or null to keep current value\n * @param h New height, or null to keep current value\n * @returns The updated bounds values\n */\n protected abstract updateBounds(\n x: null | number,\n y: null | number,\n w: null | number,\n h: null | number,\n ): [number | null, number | null, number | null, number | null];\n\n /**\n * Invalidates the cached bounds of this shape.\n * Forces recalculation of bounding box and minimum size.\n */\n invalidateBounds(): void {\n this._minSize = null as unknown as TSU.Geom.Size;\n this._bbox = null as unknown as TSU.Geom.Rect;\n }\n\n /**\n * Sets the bounds of this shape.\n *\n * Note that null and NaN are valid values and mean the following:\n * - null: Don't change the value\n * - NaN: Set the value to null (use the bounding box's value)\n *\n * @param x New x coordinate, or null to keep current value\n * @param y New y coordinate, or null to keep current value\n * @param w New width, or null to keep current value\n * @param h New height, or null to keep current value\n * @param applyLayout Whether to apply layout immediately\n * @returns The updated bounds values\n */\n setBounds(\n x: number | null,\n y: number | null,\n w: number | null,\n h: number | null,\n applyLayout = false,\n ): [number | null, number | null, number | null, number | null] {\n if (x != null) {\n if (isNaN(x)) {\n this._x = null;\n } else {\n this._x = x;\n }\n }\n if (y != null) {\n if (isNaN(y)) {\n this._y = null;\n } else {\n this._y = y;\n }\n }\n if (w != null) {\n if (isNaN(w)) {\n this._width = null;\n } else {\n this._width = w;\n }\n }\n if (h != null) {\n if (isNaN(h)) {\n this._height = null;\n } else {\n this._height = h;\n }\n }\n const [nx, ny, nw, nh] = this.updateBounds(x, y, w, h);\n if (nx != null) {\n if (isNaN(nx)) {\n this._x = null;\n } else {\n this._x = nx;\n }\n }\n if (ny != null) {\n if (isNaN(ny)) {\n this._y = null;\n } else {\n this._y = ny;\n }\n }\n if (nw != null) {\n if (isNaN(nw)) {\n this._width = null;\n } else {\n this._width = nw;\n }\n }\n if (nh != null) {\n if (isNaN(nh)) {\n this._height = null;\n } else {\n this._height = nh;\n }\n }\n if (applyLayout) this.refreshLayout();\n // this.resetBBox();\n return [nx, ny, nw, nh];\n }\n\n /**\n * Checks if this shape has an explicit x coordinate.\n */\n get hasX(): boolean {\n return this._x != null && !isNaN(this._x);\n }\n\n /**\n * Checks if this shape has an explicit y coordinate.\n */\n get hasY(): boolean {\n return this._y != null && !isNaN(this._y);\n }\n\n /**\n * Checks if this shape has an explicit width.\n */\n get hasWidth(): boolean {\n return this._width != null && !isNaN(this._width);\n }\n\n /**\n * Checks if this shape has an explicit height.\n */\n get hasHeight(): boolean {\n return this._height != null && !isNaN(this._height);\n }\n\n /**\n * Gets the x coordinate within the parent's coordinate system.\n */\n get x(): number {\n return this._x || 0;\n }\n\n /**\n * Sets the x coordinate within the parent's coordinate system.\n */\n set x(x: number | null) {\n // Here a manual x is being set - how does this interfere with the bounding box?\n // We should _x to the new value to indicate a manual value was set.\n // and reset bbox so that based on this x a new bbox may need to be calculated\n this.setBounds(x == null ? NaN : x, null, null, null);\n }\n\n /**\n * Gets the y coordinate within the parent's coordinate system.\n */\n get y(): number {\n if (this._y != null) return this._y;\n return 0; // this.bbox.y;\n }\n\n /**\n * Sets the y coordinate within the parent's coordinate system.\n */\n set y(y: number | null) {\n this.setBounds(null, y == null ? NaN : y, null, null);\n }\n\n /**\n * Gets the width of this shape.\n */\n get width(): number {\n if (this._width != null) return this._width;\n return 0; // this.bbox.width;\n }\n\n /**\n * Sets the width of this shape.\n */\n set width(w: number | null) {\n this.setBounds(null, null, w == null ? NaN : w, null);\n }\n\n /**\n * Gets the height of this shape.\n */\n get height(): number {\n if (this._height != null) return this._height;\n return 0; // this.bbox.height;\n }\n\n /**\n * Sets the height of this shape.\n */\n set height(h: number | null) {\n this.setBounds(null, null, null, h == null ? NaN : h);\n }\n\n /**\n * Refreshes the layout of this shape.\n * Called when bounds or other properties have changed to give the shape an\n * opportunity to layout its children. For shapes with no children this is a no-op.\n */\n refreshLayout(): void {\n // throw new Error(\"Implement this\");\n }\n}\n\n/**\n * Represents an embellishment applied to a musical element.\n */\nexport abstract class Embelishment extends Shape {}\n\n/**\n * A shape that wraps an SVG element.\n * ElementShape provides the base class for all shapes that are rendered as SVG elements.\n */\nexport class ElementShape<T extends SVGGraphicsElement = SVGGraphicsElement> extends Shape {\n /**\n * Creates a new ElementShape.\n * @param element The SVG element this shape wraps\n */\n constructor(public readonly element: T) {\n super();\n }\n\n /**\n * Refreshes the bounding box of this element.\n * @returns The refreshed bounding box\n */\n protected refreshBBox(): TSU.Geom.Rect {\n return TSU.DOM.svgBBox(this.element);\n }\n\n /**\n * Refreshes the minimum size of this element.\n * @returns The refreshed minimum size\n */\n protected refreshMinSize(): TSU.Geom.Size {\n return TSU.DOM.svgBBox(this.element);\n }\n\n /**\n * Updates the bounds of this element.\n * @param x New x coordinate, or null to keep current value\n * @param y New y coordinate, or null to keep current value\n * @param w New width, or null to keep current value\n * @param h New height, or null to keep current value\n * @returns The updated bounds values\n */\n protected updateBounds(\n x: null | number,\n y: null | number,\n w: null | number,\n h: null | number,\n ): [number | null, number | null, number | null, number | null] {\n return [x, y, w, h];\n }\n\n /**\n * Refreshes the layout of this element.\n * Updates the element's attributes based on the shape's properties.\n */\n refreshLayout(): void {\n if (this.hasX) this.element.setAttribute(\"x\", \"\" + this._x);\n if (this.hasY) this.element.setAttribute(\"y\", \"\" + this._y);\n }\n}\n\n/**\n * Base class for views that represent atoms in the notation.\n * AtomView provides the visual representation of an atom.\n */\nexport abstract class AtomView extends Shape {\n /** Nesting depth of this atom in the structure */\n depth = 0;\n /** Index of the role containing this atom */\n roleIndex = 0;\n\n // LayoutMetrics for the AtomView so all atomviews laid out on the\n // same baseline will show up aligned vertically\n /** Baseline position for vertical alignment */\n baseline: number;\n /** Ascent (space above baseline) */\n ascent: number;\n /** Descent (space below baseline) */\n descent: number;\n /** Height of capital letters */\n capHeight: number;\n /** Space between lines */\n leading: number;\n\n /**\n * Checks if this atom view represents a leaf atom.\n */\n abstract isLeaf(): boolean;\n\n abstract get totalDuration(): TSU.Num.Fraction;\n\n /**\n * Returns the horizontal offset from the atom's origin to where the note glyph starts.\n * This accounts for left embellishments that appear before the note.\n * Used by GroupView to align note glyphs at their correct time positions.\n *\n * Default is 0 (glyph starts at origin). Subclasses with left embellishments\n * should override to return the width of left-side decorations.\n */\n get glyphOffset(): number {\n return 0;\n }\n\n /**\n * Creates the SVG elements needed for this atom view.\n * @param parent The parent SVG element to attach to\n */\n abstract createElements(parent: SVGGraphicsElement): void;\n}\n\n/**\n * A view for leaf atoms (those that cannot contain other atoms).\n */\nexport abstract class LeafAtomView extends AtomView {\n /**\n * Creates a new LeafAtomView.\n * @param leafAtom The leaf atom this view represents\n */\n constructor(public leafAtom: LeafAtom) {\n super();\n }\n\n /**\n * Leaf atom views always return true for isLeaf().\n */\n isLeaf(): boolean {\n return true;\n }\n\n /**\n * Gets a unique identifier for this view based on the atom's UUID.\n */\n get viewId(): number {\n return this.leafAtom.uuid;\n }\n\n /**\n * Returns the total duration of the atom rendered by this view.\n */\n get totalDuration(): TSU.Num.Fraction {\n return this.leafAtom.duration;\n }\n}\n\n/**\n * A view for group atoms that contain multiple child atoms.\n */\nexport abstract class GroupView extends AtomView {\n /** Space between atoms in this group */\n protected atomSpacing: number;\n /** The SVG group element for this view */\n groupElement: SVGGElement;\n /** Views for the atoms in this group */\n protected atomViews: AtomView[] = [];\n private _embelishments: Embelishment[];\n /** Whether this group represents notes by default */\n defaultToNotes = true;\n /** Whether this view needs layout */\n needsLayout = true;\n /** Scale factor for this group */\n scaleFactor = 1.0;\n /**\n * When true, shows continuation markers (\",\") for atoms with duration > 1\n * instead of just leaving empty space.\n * Disabled by default as group bracket lines provide clearer visual boundaries.\n */\n showContinuationMarkers = false;\n /** SVG elements for continuation markers */\n protected continuationMarkerElements: SVGTextElement[] = [];\n /** Actual content width after layout (position of last atom + its width) */\n contentWidth = 0;\n\n /**\n * Creates a new GroupView.\n * @param group The group atom this view represents\n * @param config Optional configuration object\n */\n constructor(\n public group: Group,\n config?: any,\n ) {\n super();\n this.atomSpacing = 2;\n this.setStyles(config || {});\n }\n\n /**\n * Returns the total duration of the group rendered by this view.\n * This returns the group's actual duration (accounting for scaling),\n * not the raw sum of child durations.\n */\n get totalDuration(): TSU.Num.Fraction {\n return this.group.duration;\n }\n\n /**\n * Creates the SVG elements needed for this group view.\n * @param parent The parent SVG element to attach to\n */\n createElements(parent: SVGGraphicsElement): void {\n this.groupElement = TSU.DOM.createSVGNode(\"g\", {\n parent: parent,\n attrs: {\n class: \"groupViewRoot\",\n id: \"groupViewRoot\" + this.group.uuid,\n },\n });\n\n // now create child atom views for each atom in this Group\n for (const atom of this.group.atoms.values()) {\n const atomView = this.createAtomView(atom);\n this.atomViews.push(atomView);\n }\n this.invalidateBounds();\n }\n\n /**\n * Group views always return false for isLeaf().\n */\n isLeaf(): boolean {\n return false;\n }\n\n /**\n * Refreshes the bounding box of this group.\n * @returns The refreshed bounding box\n */\n protected refreshBBox(): TSU.Geom.Rect {\n return TSU.DOM.svgBBox(this.groupElement);\n }\n\n /**\n * Refreshes the minimum size of this group using duration-based width calculation.\n *\n * ## Duration-Based Width Algorithm\n *\n * This algorithm ensures atoms with extended durations receive proportionally\n * more horizontal space. For example, with `\\beatDuration(4)` and input `S 2 R G M`:\n * - S has duration 1, R has duration 2, G has duration 1\n * - R should visually occupy twice the horizontal space of S or G\n *\n * ### Algorithm Steps:\n *\n * 1. **Calculate width per duration unit**: For each atom, compute the visual width\n * needed per unit of duration: `(visualWidth + spacing) / duration`\n *\n * 2. **Find maximum**: Take the maximum width-per-duration across all atoms.\n * This ensures every atom has enough space for its visual content.\n *\n * 3. **Scale by total duration**: Multiply the max width-per-duration by the\n * group's total duration to get the final group width.\n *\n * ### Example:\n * ```\n * Atoms: S(dur=1, width=10px), R(dur=2, width=10px), G(dur=1, width=10px)\n * Spacing: 5px\n *\n * Width per duration:\n * S: (10 + 5) / 1 = 15 px/unit\n * R: (10 + 5) / 2 = 7.5 px/unit\n * G: (10 + 5) / 1 = 15 px/unit\n *\n * Max width per duration: 15 px/unit\n * Total duration: 1 + 2 + 1 = 4 units\n * Group width: 15 * 4 = 60px\n *\n * Positioning:\n * S at x=0 (time 0/4 * 60 = 0)\n * R at x=15 (time 1/4 * 60 = 15)\n * G at x=45 (time 3/4 * 60 = 45)\n * ```\n *\n * @returns The refreshed minimum size\n */\n protected refreshMinSize(): TSU.Geom.Size {\n let maxHeight = 0;\n\n // Step 1: Calculate width per duration unit for each atom\n let minWidthPerDuration = 0;\n this.atomViews.forEach((av) => {\n const ms = av.minSize;\n const dur = av.totalDuration;\n if (!dur.isZero) {\n const durValue = dur.num / dur.den;\n const widthPerDur = (ms.width + this.atomSpacing) / durValue;\n // Step 2: Track maximum width per duration\n minWidthPerDuration = Math.max(minWidthPerDuration, widthPerDur);\n }\n maxHeight = Math.max(maxHeight, ms.height);\n });\n\n // Step 3: Scale by total duration\n const totalDuration = this.group.totalChildDuration;\n const totalDurValue = totalDuration.num / totalDuration.den;\n // Subtract one atomSpacing since we don't need spacing after the last atom\n const totalWidth = Math.max(0, minWidthPerDuration * totalDurValue - this.atomSpacing);\n\n return new TSU.Geom.Size(totalWidth * this.scaleFactor, maxHeight * this.scaleFactor);\n }\n\n /**\n * Creates an atom view for a specific atom.\n * @param atom The atom to create a view for\n * @returns The created atom view\n */\n abstract createAtomView(atom: Atom): AtomView;\n\n /**\n * Updates the bounds of this group.\n * @param x New x coordinate, or null to keep current value\n * @param y New y coordinate, or null to keep current value\n * @param w New width, or null to keep current value\n * @param h New height, or null to keep current value\n * @returns The updated bounds values\n */\n protected updateBounds(\n x: null | number,\n y: null | number,\n w: null | number,\n h: null | number,\n ): [number | null, number | null, number | null, number | null] {\n return [x, y, w, h];\n }\n\n /**\n * Refreshes the layout of this group using collision-based positioning.\n *\n * ## Collision-Based Layout Algorithm\n *\n * Atoms are positioned using time-based positioning with collision avoidance.\n * Each atom starts at its ideal time-based position, but is pushed right if\n * it would overlap with the previous atom (including embellishments).\n *\n * ### Algorithm:\n * ```\n * 1. Calculate ideal glyph position: glyphX = (time / totalDuration) * groupWidth\n * 2. Pre-embellishments extend left: realX = glyphX - preEmbellishmentWidth\n * 3. Collision check: if (realX < prevNoteEndX) realX = prevNoteEndX\n * 4. Position the atom at realX\n * 5. Track: prevNoteEndX = realX + atom.minSize.width\n * ```\n *\n * ### Width Source Priority:\n *\n * 1. **Column width** (preferred): If width was set via `setBounds()` from the\n * grid layout system (ColAlign), use that width. This enables global alignment\n * across all beats in the same column.\n *\n * 2. **Minimum size**: Fall back to `minSize.width` calculated by `refreshMinSize()`.\n *\n * ### Continuation Markers:\n *\n * When `showContinuationMarkers` is true (default), atoms with duration > 1\n * will have \",\" markers rendered at each additional time slot. For example,\n * an atom with duration 2 will show \"R ,\" instead of \"R \".\n *\n * ### Example (no collisions):\n * ```\n * Input: S R G M (equal duration, no embellishments)\n * Group width: 60px, Total duration: 4 units\n *\n * Positioning:\n * S at x=0 (time 0/4 * 60 = 0)\n * R at x=15 (time 1/4 * 60 = 15)\n * G at x=30 (time 2/4 * 60 = 30)\n * M at x=45 (time 3/4 * 60 = 45)\n * ```\n *\n * ### Example (with collision):\n * ```\n * Input: [Jaaru+S] R (S has 10px pre-embellishment, each atom 15px wide)\n * Group width: 60px, Total duration: 2 units\n *\n * Without collision avoidance:\n * S.glyphX = 0, S.realX = 0 - 10 = -10 (clamped to 0)\n * R.glyphX = 30, R overlaps with S\n *\n * With collision avoidance:\n * S at x=0 (prevNoteEndX becomes 15)\n * R.glyphX = 30, R.realX = 30 - 0 = 30\n * 30 >= 15, no collision, R at x=30\n * ```\n */\n refreshLayout(): void {\n let transform = \"translate(\" + this.x + \",\" + this.y + \")\";\n if (this.scaleFactor < 1) {\n transform += \" scale(\" + this.scaleFactor + \")\";\n }\n this.groupElement.setAttribute(\"transform\", transform);\n\n // BASELINE ALIGNMENT: Position atoms at bottom of allocated height.\n // This ensures atoms align across beats with different bracket heights.\n // When beats in the same row have different content heights (e.g., due to\n // nested group brackets), all beats get the same allocated height from the\n // grid. By positioning content at the bottom, atom baselines align.\n const unscaledContentHeight = this.minSize.height / this.scaleFactor;\n const unscaledAllocatedHeight = this.hasHeight ? this.height / this.scaleFactor : unscaledContentHeight;\n const currY = unscaledAllocatedHeight - unscaledContentHeight;\n\n const totalDur = this.group.totalChildDuration;\n\n // Width source priority: column width (for global alignment) > minSize\n const unscaledMinWidth = this.minSize.width / this.scaleFactor;\n const groupWidth = this.hasWidth ? this.width / this.scaleFactor : unscaledMinWidth;\n\n // Clear existing continuation markers before re-rendering\n this.clearContinuationMarkers();\n\n // Position each atom using collision-based layout\n // Atoms start at their time-based position, but are pushed right if they would\n // overlap with the previous atom (including embellishments)\n let currTime = ZERO;\n let prevNoteEndX = 0;\n this.atomViews.forEach((av, index) => {\n // 1. Calculate ideal glyph position based on time offset\n const glyphX = totalDur.isZero ? 0 : currTime.timesNum(groupWidth).divby(totalDur).floor;\n\n // 2. Pre-embellishments extend left from glyph position\n // realX is where the atom origin should be placed\n let realX = glyphX - av.glyphOffset;\n\n // 3. Collision check: push right if overlapping previous atom\n if (realX < prevNoteEndX) {\n realX = prevNoteEndX;\n }\n\n // 4. Position the atom\n av.setBounds(realX, currY, null, null, true);\n\n // 5. Track end position for next collision check\n // For groups, use contentWidth (actual content) instead of bbox.width (which may include extra space).\n // For leaf atoms, use bbox.width.\n const avWidth = (av as any).contentWidth || av.bbox.width;\n prevNoteEndX = realX + avWidth;\n\n // Render continuation markers for atoms with duration > 1\n if (this.showContinuationMarkers && !totalDur.isZero) {\n const atomDur = av.totalDuration;\n const durValue = atomDur.num / atomDur.den;\n if (durValue > 1) {\n // Render one marker at each additional time slot within the atom's duration\n const numMarkers = Math.floor(durValue) - 1;\n for (let i = 1; i <= numMarkers; i++) {\n // Marker time = currTime + (atomDuration * i / floor(duration))\n const markerTime = currTime.plus(atomDur.timesNum(i).divbyNum(Math.floor(durValue)));\n const markerX = markerTime.timesNum(groupWidth).divby(totalDur).floor;\n this.renderContinuationMarker(markerX, currY);\n }\n }\n }\n\n currTime = currTime.plus(av.totalDuration);\n });\n\n // Track actual content width for bracket sizing\n this.contentWidth = prevNoteEndX;\n\n this.invalidateBounds();\n for (const e of this.embelishments) e.refreshLayout();\n this.invalidateBounds();\n }\n\n /**\n * Clears all continuation marker elements.\n */\n protected clearContinuationMarkers(): void {\n for (const el of this.continuationMarkerElements) {\n el.remove();\n }\n this.continuationMarkerElements = [];\n }\n\n /**\n * Renders a continuation marker (\",\") at the specified position.\n * @param x X position for the marker\n * @param y Y position for the marker\n */\n protected renderContinuationMarker(x: number, y: number): void {\n const marker = TSU.DOM.createSVGNode(\"text\", {\n parent: this.groupElement,\n attrs: {\n class: \"continuationMarker\",\n x: x.toString(),\n y: y.toString(),\n },\n text: \",\",\n }) as SVGTextElement;\n this.continuationMarkerElements.push(marker);\n }\n\n /**\n * Gets the embellishments for this group.\n */\n get embelishments(): Embelishment[] {\n if (!this._embelishments) {\n this._embelishments = this.createEmbelishments();\n }\n return this._embelishments;\n }\n\n /**\n * Creates the embellishments for this group.\n * @returns An array of embellishments\n */\n protected createEmbelishments(): Embelishment[] {\n return [];\n }\n\n /**\n * Sets the styles for this group.\n * @param config Style configuration object\n */\n setStyles(config: any): void {\n if (\"atomSpacing\" in config) this.atomSpacing = config.atomSpacing;\n if (\"showContinuationMarkers\" in config) this.showContinuationMarkers = config.showContinuationMarkers;\n this.needsLayout = true;\n }\n}\n","import * as TSU from \"@panyam/tsutils\";\nimport { Note } from \"../core\";\nimport { BeatView } from \"../beatview\";\nimport { Embelishment, GroupView as GroupViewBase } from \"../shapes\";\nimport { LeafAtomView } from \"./atomviews\";\nimport { JaaruGamaka } from \"./gamakas\";\n\n/**\n * Embelishments specifically \"around\" a single atom view.\n */\nexport abstract class LeafAtomViewEmbelishment extends Embelishment {\n constructor(public readonly atomView: LeafAtomView) {\n super();\n }\n}\n\nexport class OctaveIndicator extends LeafAtomViewEmbelishment {\n dotRadius = 1;\n dotSpacing = 2.5;\n dotsElem: SVGGElement;\n\n constructor(\n public readonly noteView: LeafAtomView,\n public readonly note: Note,\n ) {\n super(noteView);\n const rootElem = this.noteView.embRoot();\n const numDots = Math.abs(note.octave);\n this.dotsElem = TSU.DOM.createSVGNode(\"g\", {\n doc: document,\n parent: rootElem,\n attrs: {\n width: this.dotRadius * 2 * numDots + (numDots - 1) * this.dotSpacing,\n height: this.dotRadius * 2,\n source: \"atom\" + this.noteView.leafAtom.uuid,\n },\n });\n let cx = 0;\n for (let i = 0; i < numDots; i++) {\n TSU.DOM.createSVGNode(\"circle\", {\n doc: document,\n parent: this.dotsElem,\n attrs: {\n cx: cx,\n cy: 0,\n r: this.dotRadius,\n class: \"notation-octave-dot\",\n },\n });\n cx += this.dotRadius + this.dotRadius + this.dotSpacing;\n }\n }\n\n protected refreshBBox(): TSU.Geom.Rect {\n return TSU.DOM.svgBBox(this.dotsElem);\n }\n\n protected refreshMinSize(): TSU.Geom.Size {\n const numDots = Math.abs(this.note.octave);\n return {\n width: this.dotRadius * 2 * numDots + (numDots - 1) * this.dotSpacing,\n height: this.dotRadius * 2,\n };\n }\n\n protected updateBounds(\n x: null | number,\n y: null | number,\n _w: null | number,\n _h: null | number,\n ): [number | null, number | null, number | null, number | null] {\n if (x == null) x = this.x;\n if (y == null) y = this.y;\n // cannot set w/h\n // this.bbox.x = x;\n // this.bbox.y = y;\n return [x, y, null, null];\n }\n\n refreshLayout(): void {\n this.dotsElem.setAttribute(\"transform\", \"translate(\" + this.x + \",\" + this.y + \")\");\n }\n}\n\n////////// Carnatic embelishments\nexport class LabelEmbelishment extends LeafAtomViewEmbelishment {\n labelElem: SVGTextElement;\n constructor(\n public readonly label: string,\n public readonly atomView: LeafAtomView,\n ) {\n super(atomView);\n const rootElem = this.atomView.embRoot();\n this.labelElem = TSU.DOM.createSVGNode(\"text\", {\n doc: document,\n parent: rootElem,\n text: label,\n attrs: {\n source: \"atom\" + this.atomView.leafAtom.uuid,\n class: \"notation-embelishment-label\",\n \"dominant-baseline\": \"hanging\",\n },\n });\n }\n\n protected refreshBBox(): TSU.Geom.Rect {\n return TSU.DOM.svgBBox(this.labelElem);\n }\n\n protected refreshMinSize(): TSU.Geom.Size {\n return TSU.DOM.svgBBox(this.labelElem);\n }\n\n protected updateBounds(\n x: null | number,\n y: null | number,\n w: null | number,\n h: null | number,\n ): [number | null, number | null, number | null, number | null] {\n return [x, y, w, h];\n }\n\n refreshLayout(): void {\n this.labelElem.setAttribute(\"x\", \"\" + this.x);\n this.labelElem.setAttribute(\"y\", \"\" + this.y);\n }\n}\n\nexport class BeatStartLines extends Embelishment {\n barSpacing = 10;\n protected line: SVGLineElement;\n\n constructor(\n public readonly source: BeatView,\n public readonly rootElement: SVGGraphicsElement,\n ) {\n super();\n this.line = TSU.DOM.createSVGNode(\"line\", {\n doc: document,\n parent: this.rootElement,\n attrs: {\n class: \"bar-start-line\",\n },\n });\n }\n\n protected refreshBBox(): TSU.Geom.Rect {\n return new TSU.Geom.Rect(0, 0, 0, 0);\n }\n\n protected refreshMinSize(): TSU.Geom.Size {\n return new TSU.Geom.Rect(0, 0, 0, 0);\n }\n\n refreshLayout(): void {\n const line = this.line;\n const x = this.source.x - this.barSpacing;\n line.setAttribute(\"x1\", \"\" + x);\n line.setAttribute(\"x2\", \"\" + x);\n const y = this.source.y + this.source.bbox.y;\n const h = this.source.bbox.height;\n line.setAttribute(\"y1\", \"\" + y);\n line.setAttribute(\"y2\", \"\" + (y + h));\n }\n\n protected updateBounds(\n x: null | number,\n y: null | number,\n w: null | number,\n h: null | number,\n ): [number | null, number | null, number | null, number | null] {\n return [x, y, null, h];\n }\n}\n\nexport class BeatEndLines extends Embelishment {\n lineSpacing = 2;\n protected lines: SVGLineElement[];\n\n constructor(\n public readonly source: BeatView,\n public readonly rootElement: SVGGraphicsElement,\n nLines = 1,\n ) {\n super();\n this.lines = [];\n for (let i = 0; i < nLines; i++) {\n this.lines.push(\n TSU.DOM.createSVGNode(\"line\", {\n doc: document,\n // parent: l2g,\n parent: this.rootElement,\n attrs: {\n class: \"bar-end-line\",\n },\n }),\n );\n }\n }\n\n protected refreshBBox(): TSU.Geom.Rect {\n return new TSU.Geom.Rect(0, 0, 0, 0);\n }\n\n protected refreshMinSize(): TSU.Geom.Size {\n return new TSU.Geom.Rect(0, 0, 0, 0);\n }\n\n protected updatePosition(x: null | number, y: null | number): [number | null, number | null] {\n return [x, y];\n }\n\n barSpacing = 0;\n\n refreshLayout(): void {\n // const x = this.source.width + this.barSpacing;\n // const y = 0;\n // const h = this.source.height;\n const x = this.source.x + this.source.width + this.barSpacing;\n const y = this.source.y + this.source.bbox.y;\n const h = this.source.bbox.height;\n let currX = x;\n for (const line of this.lines) {\n const lx = \"\" + currX;\n line.setAttribute(\"x1\", lx);\n line.setAttribute(\"x2\", lx);\n currX += 4;\n }\n for (const line of this.lines) {\n line.setAttribute(\"y1\", \"\" + y);\n line.setAttribute(\"y2\", \"\" + (y + h));\n }\n }\n\n protected updateBounds(\n _x: null | number,\n _y: null | number,\n _w: null | number,\n _h: null | number,\n ): [number | null, number | null, number | null, number | null] {\n return [null, null, null, null];\n }\n}\n\n/// Carnatic Embelishments\nexport class Kampitham extends LabelEmbelishment {\n constructor(public readonly atomView: LeafAtomView) {\n super(\"~\", atomView);\n }\n}\n\nexport class Nokku extends LabelEmbelishment {\n constructor(public readonly atomView: LeafAtomView) {\n super(\"w\", atomView);\n }\n}\n\nexport class Prathyagatham extends LabelEmbelishment {\n constructor(public readonly atomView: LeafAtomView) {\n super(\"∵\", atomView);\n }\n}\nexport class Spuritham extends LabelEmbelishment {\n constructor(public readonly atomView: LeafAtomView) {\n super(\"∴\", atomView);\n }\n}\nexport class Raavi extends LabelEmbelishment {\n constructor(public readonly atomView: LeafAtomView) {\n super(\"^\", atomView);\n }\n}\nexport class Kandippu extends LabelEmbelishment {\n constructor(public readonly atomView: LeafAtomView) {\n super(\"✓\", atomView);\n }\n}\n\nexport class Vaali extends LabelEmbelishment {\n constructor(public readonly atomView: LeafAtomView) {\n super(\"⌒\", atomView);\n }\n}\nexport class Odukkal extends LabelEmbelishment {\n constructor(public readonly atomView: LeafAtomView) {\n super(\"x\", atomView);\n }\n}\nexport class Orikkai extends LabelEmbelishment {\n constructor(public readonly atomView: LeafAtomView) {\n super(\"γ\", atomView);\n }\n}\n\nexport class Jaaru extends LeafAtomViewEmbelishment {\n pathElem: SVGPathElement;\n constructor(\n public readonly jaaru: JaaruGamaka,\n public readonly atomView: LeafAtomView,\n ) {\n super(atomView);\n // TODO - Create the \"fancier\" view\n // for now represent this with just a slant line (like a slash)\n const rootElem = this.atomView.embRoot();\n this.pathElem = TSU.DOM.createSVGNode(\"path\", {\n doc: document,\n parent: rootElem,\n attrs: {\n source: \"atom\" + this.atomView.leafAtom.uuid,\n class: \"notation-jaaru-path\",\n d: this.pathAttribute(),\n },\n });\n }\n\n pathAttribute(x = 0): string {\n const avbbox = this.atomView.glyph.minSize;\n let y2 = 0;\n const h2 = avbbox.height / 2;\n const x2 = x + h2;\n let y = this.atomView.y;\n if (this.jaaru.ascending) {\n y += avbbox.height;\n y2 = y - h2;\n } else {\n y -= h2;\n y2 = y + h2;\n }\n return [`M ${x} ${y}`, `Q ${x2} ${y} ${x2} ${y2}`].join(\" \");\n }\n\n protected refreshMinSize(): TSU.Geom.Size {\n return TSU.DOM.svgBBox(this.pathElem);\n }\n\n protected refreshBBox(): TSU.Geom.Rect {\n return TSU.DOM.svgBBox(this.pathElem);\n }\n\n protected updateBounds(\n x: null | number,\n _y: null | number,\n _w: null | number,\n _h: null | number,\n ): [number | null, number | null, number | null, number | null] {\n return [x, null, null, null];\n }\n\n refreshLayout(): void {\n this.pathElem.setAttribute(\"d\", this.pathAttribute(this.x));\n }\n}\n\n/**\n * Position mode for GroupBracket - controls how the bracket interacts with embellishments.\n */\nexport type GroupBracketPositionMode = \"above-all\" | \"below-embellishments\" | \"separate-space\";\n\n/**\n * Renders a single bracket line as the top border of a GroupView container.\n * Each nested group gets its own bracket line, creating a visual effect where\n * atoms inside deeply nested groups appear to have multiple lines above them.\n *\n * For example, with notation `A B [ S R [ P D [ W X ] ] ]`:\n * - Group 1 (outermost) has 1 bracket line\n * - Group 2 has 1 bracket line (inside Group 1's bracket)\n * - Group 3 (innermost) has 1 bracket line (inside Groups 1 & 2's brackets)\n * - Atoms W X visually appear to have 3 lines above (cumulative effect)\n */\nexport class GroupBracket extends Embelishment {\n private line: SVGLineElement | null = null;\n private leftCircle: SVGCircleElement | null = null;\n private rightCircle: SVGCircleElement | null = null;\n private bracketGroup: SVGGElement | null = null;\n\n // Configuration - exposed for experimentation\n /** Distance above group content */\n lineOffset = 2;\n /** End circle radius */\n circleRadius = 1.5;\n /** How far line extends beyond group content on each side */\n lineExtension = 2;\n\n /**\n * Position mode for embellishment interaction experimentation:\n * - 'above-all': Bracket at very top, above all embellishments\n * - 'below-embellishments': Bracket between glyphs and embellishments (default)\n * - 'separate-space': Bracket in dedicated reserved space\n */\n positionMode: GroupBracketPositionMode = \"below-embellishments\";\n\n constructor(public readonly groupView: GroupViewBase) {\n super();\n\n this.bracketGroup = TSU.DOM.createSVGNode(\"g\", {\n doc: document,\n parent: this.groupView.groupElement,\n attrs: {\n class: \"group-bracket\",\n source: \"group\" + this.groupView.group.uuid,\n },\n });\n\n this.line = TSU.DOM.createSVGNode(\"line\", {\n doc: document,\n parent: this.bracketGroup,\n attrs: {\n class: \"group-bracket-line\",\n },\n });\n\n this.leftCircle = TSU.DOM.createSVGNode(\"circle\", {\n doc: document,\n parent: this.bracketGroup,\n attrs: {\n class: \"group-bracket-circle\",\n r: String(this.circleRadius),\n },\n });\n\n this.rightCircle = TSU.DOM.createSVGNode(\"circle\", {\n doc: document,\n parent: this.bracketGroup,\n attrs: {\n class: \"group-bracket-circle\",\n r: String(this.circleRadius),\n },\n });\n }\n\n protected refreshBBox(): TSU.Geom.Rect {\n if (!this.bracketGroup) return new TSU.Geom.Rect(0, 0, 0, 0);\n return TSU.DOM.svgBBox(this.bracketGroup);\n }\n\n protected refreshMinSize(): TSU.Geom.Size {\n // Single bracket line height contribution\n return new TSU.Geom.Size(0, this.lineOffset + this.circleRadius);\n }\n\n protected updateBounds(\n x: null | number,\n y: null | number,\n w: null | number,\n h: null | number,\n ): [number | null, number | null, number | null, number | null] {\n return [x, y, w, h];\n }\n\n refreshLayout(): void {\n if (!this.line || !this.leftCircle || !this.rightCircle) return;\n\n const bbox = this.groupView.bbox;\n // Use actual content width (not bbox which may include extra space)\n const groupWidth = this.groupView.contentWidth || bbox.width;\n\n // Calculate Y position based on position mode\n let y: number;\n switch (this.positionMode) {\n case \"below-embellishments\":\n // Position just above glyph content, below other embellishments\n y = bbox.y + this.lineOffset - 2;\n break;\n case \"separate-space\":\n // Use dedicated space at very top of group bbox\n y = bbox.y - this.lineOffset;\n break;\n case \"above-all\":\n default:\n // Position above everything including embellishments\n y = bbox.y - this.lineOffset;\n break;\n }\n\n const x1 = -this.lineExtension;\n const x2 = groupWidth + this.lineExtension;\n\n this.line.setAttribute(\"x1\", String(x1));\n this.line.setAttribute(\"y1\", String(y));\n this.line.setAttribute(\"x2\", String(x2));\n this.line.setAttribute(\"y2\", String(y));\n\n this.leftCircle.setAttribute(\"cx\", String(x1));\n this.leftCircle.setAttribute(\"cy\", String(y));\n this.rightCircle.setAttribute(\"cx\", String(x2));\n this.rightCircle.setAttribute(\"cy\", String(y));\n }\n}\n","import * as TSU from \"@panyam/tsutils\";\nimport { Atom, Group, Literal, AtomType, Note, Space, Syllable } from \"../core\";\nimport {\n LeafAtomView as LeafAtomViewBase,\n GroupView as GroupViewBase,\n AtomView,\n Embelishment,\n ElementShape,\n} from \"../shapes\";\nimport {\n OctaveIndicator,\n Kampitham,\n Nokku,\n Spuritham,\n Prathyagatham,\n Orikkai,\n Odukkal,\n Raavi,\n Kandippu,\n Vaali,\n Jaaru,\n GroupBracket,\n} from \"./embelishments\";\nimport { GamakaType } from \"./gamakas\";\n\nexport class GroupView extends GroupViewBase {\n /** Height reserved for bracket line (lineOffset + circleRadius + padding) */\n static readonly BRACKET_HEIGHT = 8;\n\n createAtomView(atom: Atom): AtomView {\n // Propagate depth + 1 to child atoms\n return createAtomView(this.groupElement, atom, this.defaultToNotes, 0.7, this.depth + 1);\n }\n\n /**\n * Creates embellishments for this group, including the bracket line\n * that serves as the top border of this group container.\n */\n protected createEmbelishments(): Embelishment[] {\n const embelishments = super.createEmbelishments();\n // Add bracket line for nested groups (depth >= 1)\n if (this.depth >= 1) {\n embelishments.push(new GroupBracket(this));\n }\n return embelishments;\n }\n\n /**\n * Calculates the minimum size of this group, including space for the bracket line.\n * The bracket line adds height for nested groups (depth >= 1).\n */\n protected refreshMinSize(): TSU.Geom.Size {\n const baseSize = super.refreshMinSize();\n\n // Add height for bracket line if this is a nested group\n if (this.depth >= 1) {\n return new TSU.Geom.Size(baseSize.width, baseSize.height + GroupView.BRACKET_HEIGHT * this.scaleFactor);\n }\n\n return baseSize;\n }\n}\n\nexport abstract class LeafAtomView extends LeafAtomViewBase {\n leftSlot: Embelishment[] = [];\n topSlot: Embelishment[] = [];\n rightSlot: Embelishment[] = [];\n bottomSlot: Embelishment[] = [];\n glyph: ElementShape;\n\n // Spaces required before and after to accomodate for left and right slots\n protected postSpacingSpan: SVGTSpanElement;\n // Sometimes this.element may not be the root element if we need spacings\n // the rootElement is the top of the chain\n protected rootGroup: ElementShape;\n protected rootText: ElementShape;\n\n abstract get glyphLabel(): string;\n\n protected refreshBBox(): TSU.Geom.Rect {\n return TSU.DOM.svgBBox(this.rootGroup.element);\n }\n\n protected refreshMinSize(): TSU.Geom.Size {\n const out = { ...this.rootText.minSize };\n const totalWidth =\n this.leftSlot.reduce((a, b) => a + b.minSize.width, 0) +\n this.rightSlot.reduce((a, b) => a + b.minSize.width, 0) +\n this.leftSlot.length + // Padding of 1\n this.rightSlot.length; // Padding of 1\n const totalHeight =\n this.topSlot.reduce((a, b) => a + b.minSize.height, 0) +\n this.bottomSlot.reduce((a, b) => a + b.minSize.height, 0);\n out.width += totalWidth;\n out.height += totalHeight;\n // if (this.postSpacingSpan) out.width += this.postSpacingSpan.getBBox().width;\n return out;\n }\n\n /**\n * Returns the horizontal offset from the atom's origin to where the note glyph starts.\n * This is the total width of left embellishments (e.g., Jaaru symbols).\n */\n get glyphOffset(): number {\n return (\n this.leftSlot.reduce((a, b) => a + b.minSize.width, 0) + this.leftSlot.length // Padding of 1 per embellishment\n );\n }\n\n protected updateBounds(\n x: null | number,\n y: null | number,\n w: null | number,\n h: null | number,\n ): [number | null, number | null, number | null, number | null] {\n return [x, y, NaN, NaN];\n }\n\n protected layoutElements(): void {\n // Lays out all the child elements locally\n const textSize = this.rootText.minSize;\n // assume text is at 0,0 and lay things around it\n\n // now layout leftSlots\n let currX = 0;\n let currY = this.hasY ? this.y : 0;\n // place left embelishments\n for (const emb of this.leftSlot) {\n emb.x = currX;\n emb.refreshLayout();\n currX += emb.minSize.width + 1;\n }\n\n // now place the text\n const textX = currX;\n this.rootText.x = currX;\n this.rootText.refreshLayout();\n\n // And right embelishments\n currX += this.rootText.minSize.width;\n for (const emb of this.rightSlot) {\n emb.x = currX;\n emb.refreshLayout();\n currX += emb.minSize.width + 1;\n }\n\n // layout top and bottom if x or y has changed\n const gminSize = this.glyph.minSize;\n\n // top embelishments\n const glyphX = textX + this.glyph.x;\n const glyphY = this.glyph.y;\n currY = glyphY - this.glyph.minSize.height + 5;\n for (const emb of this.topSlot) {\n const bb = emb.minSize;\n emb.setBounds(glyphX + (gminSize.width - bb.width) / 2, currY - bb.height, null, null, true);\n currY = emb.y;\n }\n\n // bottom embelishments\n currY = glyphY + 7;\n for (const emb of this.bottomSlot) {\n const bb = emb.minSize;\n emb.setBounds(glyphX + (gminSize.width - bb.width) / 2, currY, null, null, true);\n currY = emb.y + bb.height;\n }\n this.invalidateBounds();\n }\n\n refreshLayout(): void {\n // TODO - move this code out to refreshLayout?\n // set the glyphs Y first so we can layout others\n this.layoutElements();\n this.rootGroup.element.setAttribute(\"transform\", \"translate(\" + this.x + \",\" + this.y + \")\");\n }\n\n protected addEmbelishment(slot: Embelishment[], emb: Embelishment): void {\n slot.push(emb);\n // this.addShape(emb);\n }\n\n /**\n * Orders embelishments and creates their views.\n */\n orderEmbelishments(): void {\n const atom = this.leafAtom;\n if (atom.TYPE != AtomType.SYLLABLE && atom.TYPE != AtomType.NOTE) {\n return;\n }\n const lit = atom as Literal;\n if (lit.embelishments.length == 0) return;\n for (const emb of lit.embelishments) {\n switch (emb.type) {\n case GamakaType.Kampitham:\n this.addEmbelishment(this.topSlot, new Kampitham(this));\n break;\n case GamakaType.Nokku:\n this.addEmbelishment(this.topSlot, new Nokku(this));\n break;\n case GamakaType.Spuritham:\n this.addEmbelishment(this.topSlot, new Spuritham(this));\n break;\n case GamakaType.Prathyagatham:\n this.addEmbelishment(this.topSlot, new Prathyagatham(this));\n break;\n case GamakaType.Orikkai:\n this.addEmbelishment(this.topSlot, new Orikkai(this));\n break;\n case GamakaType.Odukkal:\n this.addEmbelishment(this.topSlot, new Odukkal(this));\n break;\n case GamakaType.Aahaatam_Raavi:\n this.addEmbelishment(this.topSlot, new Raavi(this));\n break;\n case GamakaType.Aahaatam_Kandippu:\n this.addEmbelishment(this.topSlot, new Kandippu(this));\n break;\n case GamakaType.Vaali:\n this.addEmbelishment(this.topSlot, new Vaali(this));\n break;\n case GamakaType.Jaaru_Eetra:\n case GamakaType.Jaaru_Irakka:\n this.addEmbelishment(this.leftSlot, new Jaaru(emb, this));\n break;\n }\n }\n }\n\n embRoot(): SVGGraphicsElement {\n return this.rootGroup.element;\n }\n\n needsRootElement(): boolean {\n return true; // this.rightSlot.length > 0 || this.leafAtom.beforeRest;\n }\n\n createElements(parent: SVGGraphicsElement): void {\n // Create the glyph element first before anything\n // this allows embelishments to get early access to this element\n this.createGlyphRoot(parent);\n this.createGlyphElement();\n // Order embelishments (without creating any views)\n this.orderEmbelishments();\n this.createPostSpacingElement();\n this.invalidateBounds();\n }\n\n protected createGlyphRoot(parent: SVGGraphicsElement): void {\n this.rootGroup = new ElementShape(\n TSU.DOM.createSVGNode(\"g\", {\n doc: document,\n parent: parent,\n attrs: {\n atomid: this.leafAtom.uuid,\n class: \"atomViewRootGroup\",\n id: \"atomViewRootGroup\" + this.leafAtom.uuid,\n },\n }),\n );\n this.rootText = new ElementShape(\n TSU.DOM.createSVGNode(\"text\", {\n doc: document,\n parent: this.rootGroup.element,\n attrs: {\n atomid: this.leafAtom.uuid,\n class: \"atomViewTextRoot\",\n id: \"atomViewTextRoot\" + this.leafAtom.uuid,\n },\n }),\n );\n }\n\n protected createGlyphElement(): void {\n const atom = this.leafAtom;\n this.glyph = new ElementShape(\n TSU.DOM.createSVGNode(\"tspan\", {\n doc: document,\n parent: this.rootText.element,\n attrs: {\n atomid: atom.uuid,\n id: \"atomGlyph\" + atom.uuid,\n },\n text: this.glyphLabel, // + (note.beforeRest ? \" - \" : \" \"),\n }),\n );\n }\n\n protected createPostSpacingElement(): void {\n if (this.leafAtom.beforeRest) {\n this.postSpacingSpan = TSU.DOM.createSVGNode(\"tspan\", {\n doc: document,\n parent: this.rootText.element,\n attrs: {\n atomid: this.leafAtom.uuid,\n id: \"postSpacing\" + this.leafAtom.uuid,\n },\n text: this.leafAtom.beforeRest ? \" - \" : \" \",\n });\n }\n }\n}\n\nclass SpaceView extends LeafAtomView {\n get glyphLabel(): string {\n if (this.space.isSilent) return \" \";\n if (this.space.duration.isOne) return \",\";\n if (this.space.duration.cmpNum(2) == 0) return \";\";\n return \"_\";\n }\n\n get space(): Space {\n return this.leafAtom as Space;\n }\n}\n\nclass NoteView extends LeafAtomView {\n protected shiftElement: SVGTSpanElement;\n get glyphLabel(): string {\n return this.note.value;\n }\n\n needsRootElement(): boolean {\n return true; // this.note.shift == true || this.note.shift != 0 || super.needsRootElement();\n }\n\n protected createGlyphElement(): void {\n super.createGlyphElement();\n if (this.note.shift == true || this.note.shift != 0) {\n this.shiftElement = TSU.DOM.createSVGNode(\"tspan\", {\n doc: document,\n parent: this.rootText.element,\n attrs: {\n atomid: this.note.uuid,\n class: \"noteShiftTSpan\",\n id: \"noteShift\" + this.note.uuid,\n \"baseline-shift\": \"sub\",\n },\n text: (this.note.shift == true ? \"*\" : this.note.shift) + \" \",\n });\n }\n }\n\n protected moveGlyphToRoot(): void {\n // super.moveGlyphToRoot();\n if (this.shiftElement) {\n this.rootGroup.element.appendChild(this.shiftElement);\n }\n }\n\n orderEmbelishments(): void {\n const note = this.note;\n // create the embelishments if needed\n if (note.octave > 0) {\n this.topSlot.push(new OctaveIndicator(this, note));\n } else if (this.note.octave < 0) {\n this.bottomSlot.push(new OctaveIndicator(this, note));\n }\n super.orderEmbelishments();\n }\n\n get note(): Note {\n return this.leafAtom as Note;\n }\n}\n\nclass SyllableView extends LeafAtomView {\n get glyphLabel(): string {\n return this.syllable.value;\n }\n\n get syllable(): Syllable {\n return this.leafAtom as Syllable;\n }\n}\n\nexport function createAtomView(\n parent: SVGGraphicsElement,\n atom: Atom,\n litDefaultsToNote = false,\n groupViewScale = 1.0,\n depth = 0,\n): AtomView {\n let out: AtomView;\n switch (atom.TYPE) {\n // Dealing with leaf atoms\n case AtomType.SPACE:\n out = new SpaceView(atom as Space);\n break;\n case AtomType.SYLLABLE:\n out = new SyllableView(atom as Syllable);\n break;\n case AtomType.NOTE:\n out = new NoteView(atom as Note);\n break;\n case AtomType.LITERAL:\n if (litDefaultsToNote) {\n const lit = Note.fromLit(atom as Note);\n out = new NoteView(lit);\n } else {\n const lit = Syllable.fromLit(atom as Syllable);\n out = new SyllableView(lit);\n }\n break;\n case AtomType.GROUP:\n out = new GroupView(atom as Group);\n (out as GroupView).defaultToNotes = litDefaultsToNote;\n (out as GroupView).scaleFactor = groupViewScale;\n break;\n default:\n // We should never get a group as we are iterating\n // at leaf atom levels\n throw new Error(\"Invalid atom type: \" + atom.TYPE);\n }\n out.depth = depth;\n out.createElements(parent);\n return out;\n}\n","import * as TSU from \"@panyam/tsutils\";\nimport * as TLEX from \"tlex\";\nimport { load as loadGrammar, TokenHandler } from \"./dsl\";\nimport { makeParseTable } from \"./ptables\";\nimport { Parser, ParseTable } from \"./lr\";\nimport { LRItemGraph } from \"./lritems\";\nimport { logParserDebug } from \"./debug\";\n\n/**\n * Configuration options for creating a parser.\n */\nexport interface ParserOptions {\n /**\n * Parser algorithm to use.\n * - \"slr\": Simple LR - smallest tables, may have false conflicts\n * - \"lalr\": Look-Ahead LR - default, good balance of power and size\n * - \"lr1\": Canonical LR(1) - most powerful, largest tables\n * @default \"lalr\"\n */\n type?: \"slr\" | \"lalr\" | \"lr1\";\n\n /**\n * Custom tokenizer function. If not provided, one is auto-generated\n * from %token and inline token definitions in the grammar.\n */\n tokenizer?: TLEX.NextTokenFunc;\n\n /**\n * Enable debug output.\n * - \"lexer\": Log tokenizer program\n * - \"parser\": Log parse table and state transitions\n * - \"all\": Log both lexer and parser\n */\n debug?: \"all\" | \"lexer\" | \"parser\" | string;\n\n /**\n * Use left recursion for EBNF expansions (*, +).\n * @default true\n */\n leftRecursive?: boolean;\n\n /**\n * Prefix for auxiliary non-terminals created by EBNF expansions.\n * @default \"$\"\n */\n auxNTPrefix?: string;\n\n /**\n * Custom token handlers for post-processing tokens.\n */\n tokenHandlers?: TSU.StringMap<TokenHandler>;\n}\n\n/**\n * Creates a parser from a grammar DSL string.\n *\n * This is the main entry point for creating parsers in Galore.\n *\n * @param input - Grammar definition in DSL format\n * @param params - Configuration options\n * @returns A tuple of [parser, tokenFunc, itemGraph]\n * - parser: The LR parser instance\n * - tokenFunc: The generated tokenizer (or null if custom provided)\n * - itemGraph: The LR item graph (useful for debugging)\n *\n * @example\n * ```typescript\n * import { newParser } from \"galore\";\n *\n * const [parser, tokenFunc, itemGraph] = newParser(`\n * %token NUMBER /[0-9]+/\n * %skip /[ \\\\t\\\\n]+/\n *\n * Expr -> Expr \"+\" Term | Term ;\n * Term -> NUMBER ;\n * `, { type: \"lalr\" });\n *\n * const result = parser.parse(\"1 + 2\");\n * ```\n */\nexport function newLRParser(\n input: string,\n params: ParserOptions | null = null,\n): [Parser, null | TLEX.NextTokenFunc, LRItemGraph] {\n const options = params || ({} as ParserOptions);\n const [ptable, tokenFunc, itemGraph] = newParseTable(input, options);\n const parser = new Parser(ptable);\n if (options.tokenizer || tokenFunc) {\n parser.setTokenizer(options.tokenizer || tokenFunc!);\n }\n const debug = options.debug || \"\";\n if (debug.split(\"|\").findIndex((p: string) => p == \"all\" || p == \"parser\") >= 0) {\n logParserDebug(parser, itemGraph);\n }\n return [parser, tokenFunc, itemGraph];\n}\n\n/**\n * Creates a parse table from a grammar DSL string without creating a parser.\n *\n * Useful when you need access to the parse table for analysis or visualization.\n *\n * @param input - Grammar definition in DSL format\n * @param params - Configuration options\n * @returns A tuple of [parseTable, tokenFunc, itemGraph]\n *\n * @example\n * ```typescript\n * import { newParseTable, Printers } from \"galore\";\n *\n * const [ptable, tokenFunc, itemGraph] = newParseTable(grammar, { type: \"lalr\" });\n *\n * // Check for conflicts\n * if (ptable.hasConflicts) {\n * console.log(\"Conflicts:\", ptable.conflictActions);\n * }\n *\n * // Visualize the parse table\n * const html = Printers.parseTableToHtml(ptable, { itemGraph });\n * ```\n */\nexport function newParseTable(\n input: string,\n params: ParserOptions | null = null,\n): [ParseTable, null | TLEX.NextTokenFunc, LRItemGraph] {\n const options = params || ({} as ParserOptions);\n const [g, tokenFunc] = loadGrammar(input, options as any);\n g.augmentStartSymbol();\n const [ptable, itemGraph] = makeParseTable(g, options.type);\n return [ptable, tokenFunc, itemGraph];\n}\n","import { Parser, LRAction, ParseTable } from \"./lr\";\nimport { LRItemGraph } from \"./lritems\";\n\nexport function logParserDebug(parser: Parser, itemGraph?: LRItemGraph): void {\n const g = parser.grammar;\n const ptable = parser.parseTable;\n console.log(\n \"===============================\\nGrammar (as default): \\n\",\n g.debugValue.map((x, i) => `${i + 1} - ${x}`),\n \"===============================\\nGrammar (as Bison): \\n\",\n g.debugValue.map((x, i) => `${x.replace(\"->\", \":\")} ; \\n`).join(\"\"),\n \"===============================\\nParseTable: \\n\",\n JSON.stringify(mergedDebugValue(ptable, itemGraph), null, 4),\n \"===============================\\nConflicts: \\n\",\n ptable.conflictActions,\n );\n}\n\nexport function mergedDebugValue(ptable: ParseTable, itemGraph?: LRItemGraph): any {\n const merged = {} as any;\n const ptabDV = ptable.debugValue;\n const igDV = itemGraph?.debugValue;\n for (const stateId in ptabDV) {\n const actions = ptabDV[stateId];\n if (itemGraph) {\n const items = igDV[stateId];\n merged[stateId] = { items: items[\"items\"], actions: actions, goto: items[\"goto\"] };\n } else {\n merged[stateId] = actions;\n }\n }\n return merged;\n}\n"],"names":["root","factory","exports","module","define","amd","this","AtomChangeType","RoleChangeType","BlockItemChangeType","__webpack_require__","definition","key","o","Object","defineProperty","enumerable","get","obj","prop","prototype","hasOwnProperty","call","Entity","constructor","config","TYPE","uuid","counter","_parent","_eventsEnabled","metadata","Error","enableEvents","disableEvents","eventsEnabled","parent","setParent","debugValue","type","toString","equals","another","expect","clone","out","newInstance","copyTo","TimedEntity","super","duration","assert","condition","msg","MAX_INT","Math","pow","TEvent","name","source","payload","_spawnedFrom","sourceState","cancelled","timeStamp","children","spawnedFrom","setSpawnedFrom","_rootEvent","rootEvent","spawn","child","push","State","stateData","id","enter","data","handle","event","EventEmitter","_eventHub","EventHub","eventHub","hub","oldHub","eventHubChanged","console","log","_handlers","_events","_inBatchMode","on","names","callback","_addHandler","removeOn","_removeHandler","_ensurestrings","split","map","v","trim","handlerlist","handler","forEach","evHandlers","i","length","splice","emit","evt","dispatchEvent","evtCallbacks","startBatchMode","cancelBatch","commitBatch","BATCH_EVENTS","ValueList","values","_firstChild","_lastChild","_size","pushBack","toJSON","Array","from","method","tmp","count","nextSibling","eqlFunc","size","first","tmp2","isEmpty","last","reversedValues","prevSibling","add","before","prev","pushFront","value","remove","next","popBack","popFront","Size","w","h","width","height","Rect","x","y","box","copy","union","minX","min","minY","maxX","max","maxY","unionAll","boxes","b","Browser","svgBBox","element","bbox","Geom","getBBox","IS_SAFARI","clientRect","getClientRects","parentClientRect","_a","parentElement","getBoundingClientRect","createSVGNode","nodename","ns","doc","document","attrs","text","createElementNS","createElement","appendChild","attr","setAttribute","textContent","createNode","gcdof","abs","t","IS_EXPLORER","navigator","userAgent","indexOf","IS_FIREFOX","IS_OPERA","toLowerCase","UAHasChrome","UAHasSafari","IS_CHROME","Fraction","num","den","factorized","isNaN","gcd","parse","val","parts","parseInt","isWhole","isZero","isInfinity","isOne","ceil","floor","plus","plusNum","minus","minusNum","times","timesNum","divby","divbyNum","numDivby","mod","d","floorOfD","modNum","inverse","equalsNum","cmp","cmpNum","isLT","isLTE","isLTNum","isLTENum","isGT","isGTE","isGTNum","isGTENum","f1","f2","ZERO","ONE","INFINITY","Frac","a","TSU","CycleCursor","cycle","barIndex","beatIndex","instance","currBar","bars","result","beatLengths","beatCounts","beatCount","Bar","bl","bc","assign","instanceCount","totalBeatCount","total","Cycle","p","getAtIndex","globalIndex","offset","bar","beatLength","getPosition","globalOffset","cycleNum","realOffset","barDuration","iterateBeats","startBar","startBeat","startInstance","instanceIndex","reduce","DEFAULT","AtomType","Atom","parentGroup","isContinuation","_duration","markersBefore","mbef","m","markersAfter","maft","LeafAtom","beforeRest","splitAt","spillOver","createSpilloverSpace","Space","Marker","isBefore","isSilent","Literal","embelishments","embs","e","Syllable","fromLit","lit","SYLLABLE","Note","octave","shift","NOTE","Group","atoms","durationIsSpeedMultiplier","_observers","addAtoms","addObserver","observer","removeObserver","index","notifyObservers","ADD","onAtomsAdded","INSERT","_b","onAtomsInserted","REMOVE","_c","onAtomsRemoved","a1","a2","atom","totalChildDuration","setDurationAsMultiplier","asSpeedMultiplier","setDuration","requiredDuration","targetGroup","remainingDur","durationFactor","lastChild","childDuration","newDuration","newRequiredDur","insertAtomsAt","removeAtoms","beforeAtom","adjustDuration","oldChildDuration","insertIndex","addedAtoms","REST","GROUP","LABEL","scaleFactor","removedAtoms","LayoutParams","beatDuration","_rowStartOffsets","_rowEndOffsets","_rowDurations","_totalLayoutDuration","_totalBeats","_beatLayouts","lineBreaks","layout","lineBreaksEqual","_lineBreaks","every","getBeatLocation","beat","modIndex","totalBeats","cursor","refreshLayout","beatLayouts","totalLayoutDuration","cycleIter","akb","numBeats","beats","nextCP","rd","GridModel","idCounter","lastUpdatedAt","rows","rowAligns","Map","colAligns","r","firstRow","gr","numCells","rowIndex","firstCol","minCol","fc","cellsInRow","row","cell","cells","cellsInCol","col","cellAt","addRowAlign","align","set","addColAlign","addRows","insertBefore","numRows","newRow","GridRow","defaultRowAlign","addSuccessor","getRow","setValue","cellCreator","grow","GridCell","clearCellAt","GridCellEvent","CLEARED","loc","location","oldValue","UPDATED","gridRow","colIndex","rowAlign","_rowAlign","addCell","colAlign","_colAlign","grid","c","coordOffset","maxLength","RowAlign","numCols","creator","filter","AlignedLine","needsLayout","_coordOffset","_maxLength","paddingBefore","paddingAfter","prevLines","nextLines","setMaxLength","setPadding","after","beforeAddingCell","removeCell","beforeRemovingCell","setOffset","cellView","getCellView","evalMaxLength","setBounds","changedCells","minSize","Beat","role","prevBeat","nextBeat","atomIsPlaceholder","endOffset","filled","remaining","preMarkers","curr","marker","postMarkers","allMinimalCycles","nodes","idFunc","edges","cycles","inACycle","node","startNode","visited","queue","newQueue","nextNode","edgeData","n","slice","defaultKeyFunc","IDSet","keyFunc","_entries","_entriesByKey","clear","predicate","e2","modified","l","entries","getByKey","ensure","entry","throwIfExists","has","SymbolSet","grammar","enforceSymbolType","Set","hasNull","debugString","labels","sort","join","skipAux","exp","getSymById","isAuxiliary","label","addFrom","includeNull","addTo","termid","term","isTerminal","delete","NullableSet","refresh","nonterms","beforeCount","allNonTerminals","nt","visit","rule","rulesForNT","isStrNullable","rhs","isNullable","str","fromIndex","toIndex","syms","SymSymbolSets","_count","forEachTerm","visitor","entriesFor","sym","addNull","srcEntries","destEntries","FirstSets","nullables","forEachTermIn","allNullable","j","symj","forEachRule","processRule","s","FollowSets","firstSets","g","startSymbol","Eof","Sym","auxType","precedence","assocLeft","creationId","compareTo","localeCompare","Str","append","lits","extend","strs","startIndex","endIndex","numToDelete","itemsToAdd","diff","containsAt","RuleAction","isFunction","isChildPosition","Rule","action","Grammar","make","symbolSet","allRules","_rulesForNT","_followSets","_hasNull","auxNTCount","auxNTPrefix","Null","newTerm","followSets","augStartRule","_AugStartRule","augmentStartSymbol","augSym","newNT","addRule","addTerminals","terminals","nonTerminals","auxNonTerminals","allSymbols","forEachNT","rules","getRule","getSym","findRule","production","findIndex","nonterm","ensureSym","removeRules","pred","removeSymbols","newRules","newRhs","sym2","T","NT","isNT","isAuxNT","seq","exps","normalizeRule","anyof","ensureAuxNT","opt","atleast0","leftRec","auxNT","findAuxNT","which","newAuxNT","atleast1","newAuxNTName","findAuxNTByRules","ntRules","print","options","ruleSep","includeSemiColon","lambdaSymbol","terminalDerivingSymbols","nadded","allDerive","reachableSymbols","fromSymbol","reachable","ruleIndex","leftRecursion","CharClassType","charCodeAt","NINE","lA","lZ","uA","uZ","USCORE","CharClassHelper","matches","charCode","neg","res","match","CharClassHelpers","reString","spaceChars","PropertyName","PropertyValue","RegexType","CharType","OpCode","Regex","groupIndex","groupName","groupIsSilent","ignoreCase","dotAll","multiline","setOptions","isVariable","evalREString","modifiers","StartOfInput","tag","START_OF_INPUT","reverse","EndOfInput","END_OF_INPUT","Assertion","expr","cond","negate","LookAhead","LOOK_AHEAD","LookBack","LOOK_BACK","Quant","minCount","maxCount","greedy","QUANT","isUnlimited","quant","Cat","CAT","Union","UNION","option","Char","op","CHAR","ch","matchChar","LeafChar","args","Any","AnyChar","Class","charClass","CharClass","Single","SingleChar","PropertyEscape","propNameOrId","propValueOrId","SyntaxError","PropertyEscapes","String","fromCharCode","replace","CharGroup","chars","CharRange","Intersection","Range","start","end","Var","reversed","VAR","BackNamedRef","BACK_NAMED_REF","BackRef","BackNumRef","BACK_NUM_REF","skip","priority","matchIndex","activeStates","stateCanActivate","state","needsSpecificStates","isNewLineChar","Match","groups","positions","Prog","startCondition","scIsInclusive","instrs","stateMapping","registerState","opcode","char","Instr","with","initializer","instrDebugValue","InstrDebugValue","instr","comment","Thread","gen","parentId","registers","regIncr","regId","regAcquire","regRelease","regValue","VM","getState","currState","setState","prog","forward","configs","threadCounter","currThreads","nextThreads","startPos","genForOffset","savePosition","thread","pos","tapeIndex","jumpBy","delta","jumpTo","newOffset","forkTo","startGroup","newThread","endGroup","addThread","list","tape","nextCh","lastCh","Jump","Split","newOff","Save","tracer","threadQueued","GroupStart","GroupEnd","StartingChar","MLStartingChar","prevCh","EndingChar","MLEndingChar","StartOfWord","EndOfWord","RBegin","groupStart","matchSuccess","matchEnd","recurseMatch","Begin","consume","EnsureState","states","matchCurrPos","currChCodeLower","currChCodeUpper","currChCode","hasMore","charAt","startMatching","bestMatch","stepChar","startOffset","savedPos","canAdvance","newPos","currMatch","nextMatch","stepThread","advance","threadStepped","advanceTape","End","currPriority","CIChar","AnyNonNL","currCh","Compiler","regexResolver","listener","emitGroups","emitPosition","compile","ensureInstr","ind","compileExpr","currOffset","compileChar","ml","START_OF_WORD","END_OF_WORD","compileCat","compileUnion","compileQuant","compileVar","compileBackNamedRef","compileBackNumRef","compileLookAhead","compileLookBack","cat","ne","jumps","jmp","compileAtleast0","compileAtleast1","compileOptional","l1","l3","l2","la","begin","lb","TokenizerError","message","setPrototypeOf","UnexpectedTokenError","foundToken","expectedTokens","TapeInterface","hasIndex","toUpperCase","charCodeAtLower","charCodeAtUpper","Tape","input","_rawInput","content","substring","TapeHelper","advanceAfter","pattern","ensureNoPrefixSlash","advanceTo","lastIndex","currStart","numSlashes","prefix","success","Token","lookahead","lookback","isOneOf","expected","tok","TokenBuffer","nextToken","tokenizerContext","buffer","peek","nth","matchFunc","nextAction","token","consumeIf","expectToken","ensureToken","nextMatches","GroupCounter","current","isSpace","RegexParser","unicode","reduceLeft","stack","throwError","refNum","gtPos","clPos","parseCharGroup","rest","parseGroup","parseQuant","nchars","parseChar","depth","subExpr","currch","endch","parseEscapeChar","parseSingleChar","parsePropertyEscape","clEnd","eqPos","propStr","propName","propValue","WORD_CHAR","DIGITS","SPACES","hexSeq","hexVal","ucodeSeq","ucodeVal","sub","advanceIf","ignoreSpaces","obCount","ignoreSpaces2","foundComma","p1","p2","part1","part2","foundEq","build","exprFromJSRE","exprFromFlexRE","parser","FlexREParser","error","re","isRegExp","JSREParser","flexRE","strings","keys","raw","BaseTokenizer","_prog","_vm","onError","onMatchHandlers","matchHandlersByValue","variables","compiler","findRuleByValue","getVar","addVar","regex","currValue","find","onMatch","Builder","sortedRules","sortRules","vm","r1","r2","Tokenizer","reset","owner","startChar","err","gi","toToken","tokenize","tokens","DefaultTape","SINGLE_QUOTE_STRING","DOUBLE_QUOTE_STRING","JS_REGEX","str2regex","TokenType","NodeType","LRActionType","Loader","leftRecursive","generatedTokenizer","TLEX","regexSyntax","symbolsByLabel","newSymbolCallback","tokenHandlers","symbolForLabel","registerSymbol","ensureSymbol","assumedTerminal","currSym","et","lexer","ARROW","OPEN_SQ","CLOSE_SQ","OPEN_PAREN","CLOSE_PAREN","OPEN_BRACE","CLOSE_BRACE","STAR","PLUS","QMARK","SEMI_COLON","COLON","PIPE","COMMENT","STRING","REGEX","flags","NUMBER","PCT_IDENT","DOLLAR_NUM","DOLLAR_IDENT","IDENT","tokenizer","ntFunc","parseGrammar","parseRegex","syntax","tokPattern","RegExp","patternStr","peeked","parseDecl","parseDirective","directive","startsWith","endsWith","tokenHandler","parseTokenHandler","isDef","tokName","funcName","ident","parseProductions","parseProd","PFNode","childCount","childAt","reprString","PTNode","ParserBase","setTokenizer","tokenbuffer","SimpleParser","delegate","parseInput","ParseError","LRAction","gotoState","ACCEPT","SHIFT","REDUCE","Shift","goto","Reduce","Goto","GOTO","Accept","ParseTable","conflictActions","actions","hasConflicts","getActions","stateId","addAction","ac","fromId","symId","ParseStack","stateStack","nodeStack","top","pop","popN","L","Parser","parseTable","context","buildParseTree","copySingleChild","output","resolveActions","actionResolver","onTokenError","onNextToken","nextSym","nextValue","topState","topNode","newNode","ruleLen","childNode","beforeAddingChildNode","handlerName","ruleHandlers","onReduction","newAction","LRItem","position","pre","post","LRItemSet","ig","_key","_lookaheads","_hasLookAheads","itemGraph","addLookAhead","item","s1","s2","clearLookAheads","getLookAheads","revalKey","hasLookAheads","itemId","items","i1","i2","las","LRItemGraph","gotoSets","itemSets","startItem","startSet","evalGotoSets","currSet","gotoSet","setGoto","itemSet","newItemSet","advanceItemAndAdd","closure","itemToAdvance","fromItemSet","toItemSet","newItem","laSym","ensureGotoSet","fromSet","toSet","getGoto","forEachGoto","symid","gotoSetFor","iset","LR0ItemGraph","newset","LR1ItemGraph","B","suffix","bRules","br","makeSLRParseTable","evalLASetsForSLRItem","makeSLRAutomaton","makeParseTableFromLA","nextSet","lookaheads","lr1Item","evalLASetsForLALRItem","augGrammar","prevSets","findP","prevStates","nextState","pSet","pALabel","pA","ALIAS","Symbol","for","DOC","MAP","PAIR","SCALAR","SEQ","NODE_TYPE","isAlias","isDocument","isMap","isPair","isScalar","isSeq","isCollection","isNode","hasAnchor","anchor","BREAK","SKIP","visitor_","initVisitor","visit_","contents","freeze","path","ctrl","callVisitor","replaceNode","concat","ci","ck","cv","async","visitAsync","visitAsync_","Collection","Node","Value","Alias","Scalar","Seq","Pair","pt","escapeChars","escapeTagName","tn","Directives","yaml","tags","docStart","docEnd","defaultYaml","defaultTags","atDocument","version","atNextDocument","explicit","line","test","tagName","verbatim","decodeURIComponent","tagString","lines","tagEntries","tagNames","some","anchorIsValid","sa","JSON","stringify","applyReviver","reviver","isArray","len","v0","v1","undefined","k","toJS","arg","ctx","aliasCount","anchors","onCreate","keep","Number","NodeBase","create","getPrototypeOf","getOwnPropertyDescriptors","range","mapAsMap","maxAliasCount","onAnchor","TypeError","mapKeyWarned","resolve","found","aliasResolveCache","_arg","ReferenceError","getAliasCount","_onComment","_onChompKeep","src","verifyAliasOrder","implicitKey","kc","vc","isScalarValue","schema","Boolean","BigInt","valueOf","aliasDuplicateObjects","onTagObj","sourceObjects","ref","tagObj","format","identify","findTagObject","iterator","nodeClass","default","collectionFromPath","isInteger","keepUndefined","BLOCK_FOLDED","BLOCK_LITERAL","PLAIN","QUOTE_DOUBLE","QUOTE_SINGLE","configurable","writable","it","addIn","done","isEmptyPath","deleteIn","getIn","keepScalar","hasAllNullValues","allowScalar","commentBefore","hasIn","setIn","stringifyComment","indentComment","indent","lineComment","includes","FOLD_FLOW","FOLD_BLOCK","FOLD_QUOTED","foldFlowLines","mode","indentAtStart","lineWidth","minContentWidth","onFold","onOverflow","endStep","folds","escapedFolds","overflow","escStart","escEnd","consumeMoreIndentedLines","fold","getFoldOptions","isBlock","containsDocumentMarker","doubleQuotedString","json","doubleQuotedAsJSON","minMultiLineLength","doubleQuotedMinMultiLineLength","code","substr","singleQuotedString","singleQuote","quotedString","qs","hasDouble","hasSingle","blockEndNewlines","blockString","onComment","onChompKeep","blockQuote","commentString","forceBlockIndent","literal","indentLength","limit","strLen","lineLengthOverLimit","chomp","endStart","endNlPos","startEnd","startWithSpace","startNlPos","header","foldedValue","literalFallback","foldOptions","body","stringifyString","inFlow","ss","_stringify","_type","actualString","indentStep","compat","plainString","defaultKeyType","defaultStringType","directives","resolvedAliases","testMatch","getTagObject","props","stringifyProps","MERGE_KEY","merge","description","addToJSMap","addMergeToJSMap","mergeValue","srcMap","addPairToJSMap","isMergeKey","jsKey","stringKey","strCtx","falseStr","flowCollectionPadding","indentSeq","nullStr","simpleKeys","trueStr","toStringOptions","collectionStyle","repeat","createStringifyContext","inStringifyKey","strKey","jsonStr","warning","logLevel","warn","stringifyKey","jsValue","createPair","_","allNullValues","keyComment","explicitKey","vsb","vcb","valueComment","keyCommentDone","chompKeep","spaceBefore","flow","valueCommentDone","valueStr","ws","vs0","nl0","hasNewline","hasPropsLine","sp0","stringifyPair","stringifyCollection","collection","stringifyFlowCollection","stringifyBlockCollection","blockItemPrefix","flowChars","itemIndent","itemCtx","addCommentBefore","ik","fcPadding","reqNewline","linesAtValue","iv","sum","ic","trimStart","findPair","YAMLMap","replacer","sortMapEntries","pair","overwrite","_pair","sortEntries","Type","YAMLSeq","idx","asItemIndex","string","nullTag","boolTag","stringifyNumber","minFractionDigits","isFinite","is","floatNaN","NaN","NEGATIVE_INFINITY","POSITIVE_INFINITY","floatExp","parseFloat","toExponential","intIdentify","intResolve","radix","intAsBigInt","intStringify","_onError","dot","stringifyJSON","binary","Uint8Array","atob","buf","btoa","resolvePairs","cn","createPairs","iterable","pairs","YAMLOMap","bind","omap","seenKeys","boolStringify","trueTag","falseTag","float","f","sign","intBin","intOct","int","intHex","YAMLSet","keepPair","parseSexagesimal","asBigInt","stringifySexagesimal","_60","unshift","padStart","intTime","floatTime","timestamp","Date","year","month","day","hour","minute","second","millisec","date","UTC","tz","toISOString","schema$1","schema$2","cst","_visit","field","GamakaType","itemAtPath","parentCollection","coll","Shape","shapeId","_x","_y","_width","_height","parentShape","_bbox","refreshBBox","_minSize","refreshMinSize","invalidateBounds","applyLayout","nx","ny","nw","nh","updateBounds","hasX","hasY","hasWidth","hasHeight","Embelishment","ElementShape","AtomView","roleIndex","glyphOffset","LeafAtomView","leafAtom","isLeaf","viewId","totalDuration","GroupView","group","atomViews","defaultToNotes","showContinuationMarkers","continuationMarkerElements","contentWidth","atomSpacing","setStyles","createElements","groupElement","class","atomView","createAtomView","maxHeight","minWidthPerDuration","av","ms","dur","durValue","widthPerDur","totalDurValue","totalWidth","transform","unscaledContentHeight","currY","totalDur","unscaledMinWidth","groupWidth","clearContinuationMarkers","currTime","prevNoteEndX","realX","avWidth","atomDur","numMarkers","markerX","renderContinuationMarker","el","_embelishments","createEmbelishments","LeafAtomViewEmbelishment","OctaveIndicator","noteView","note","dotRadius","dotSpacing","rootElem","embRoot","numDots","dotsElem","cx","cy","_w","_h","LabelEmbelishment","labelElem","Kampitham","Nokku","Prathyagatham","Spuritham","Raavi","Kandippu","Vaali","Odukkal","Orikkai","Jaaru","jaaru","pathElem","pathAttribute","avbbox","glyph","y2","h2","x2","ascending","GroupBracket","groupView","leftCircle","rightCircle","bracketGroup","lineOffset","circleRadius","lineExtension","positionMode","x1","GroupViewBase","litDefaultsToNote","groupViewScale","SPACE","SpaceView","SyllableView","NoteView","LITERAL","baseSize","BRACKET_HEIGHT","LeafAtomViewBase","leftSlot","topSlot","rightSlot","bottomSlot","rootGroup","rootText","totalHeight","layoutElements","currX","emb","textX","gminSize","glyphX","glyphY","bb","addEmbelishment","slot","orderEmbelishments","Aahaatam_Raavi","Aahaatam_Kandippu","Jaaru_Eetra","Jaaru_Irakka","needsRootElement","createGlyphRoot","createGlyphElement","createPostSpacingElement","atomid","glyphLabel","postSpacingSpan","space","shiftElement","moveGlyphToRoot","syllable","params","ptable","tokenFunc","eparser","debug","loadGrammar","makeLRParseTable","g2","ensureG2Sym","pi","newSymLabel","newSym","startState","transitions","buildRuleFrom","A","newSyms","xi","startSym","newA","newRHS","newRule","grammarFromLR0ItemGraph","makeLALRParseTable","makeParseTable","newParseTable","merged","ptabDV","igDV","mergedDebugValue","logParserDebug","G","toEmbelishment","parseEmbelishment","errors","toCommandName","_tape","_owner","toBoolean","toNumber","toMarker","markerText","toOctavedNote","toRoleSelector","toLineAnnotation","toSingleLineRawString","toMultiLineRawString","endPat","endPos","toFrontMatter"],"ignoreList":[],"sourceRoot":""}
|