From 1c507e858b15566471da03af813fbff5701e7674 Mon Sep 17 00:00:00 2001 From: Breck Yunits <breck7@gmail.com> Date: Sat, 7 Dec 2024 13:48:40 -1000 Subject: [PATCH] --- package.json | 2 +- parsers/Parsers.test.ts | 31 +++++++++++++++++++++++++++++++ parsers/Parsers.ts | 11 ++++++++++- particle/Particle.ts | 2 +- products/Parsers.js | 16 +++++++++++++++- products/Parsers.ts.browser.js | 16 +++++++++++++++- products/Particle.browser.js | 2 +- products/Particle.js | 2 +- releaseNotes.scroll | 3 +++ 9 files changed, 78 insertions(+), 7 deletions(-) diff --git a/package.json b/package.json index 9c13fc554..a09eb7e7b 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "scrollsdk", - "version": "100.0.0", + "version": "100.0.1", "description": "This npm package includes the Particles class, the Parsers compiler-compiler, a Parsers IDE, and more, all implemented in Particles, Parsers, and TypeScript.", "types": "./built/scrollsdk.node.d.ts", "main": "./products/Particle.js", diff --git a/parsers/Parsers.test.ts b/parsers/Parsers.test.ts index 415a5dd78..0a56c089a 100755 --- a/parsers/Parsers.test.ts +++ b/parsers/Parsers.test.ts @@ -670,6 +670,37 @@ type bar`) equal(anyProgram.getAllErrors().length, 2) } +testParticles.extendsScope = equal => { + // Arange + const rootParser = new HandParsersProgram(`cueAtom +newlangParser + root + catchAllParser catchAllErrorParser + inScope rootParser +rootParser +videoParser + extends rootParser + atoms cueAtom + cueFromId + widthParser + cueFromId + atoms cueAtom +quickVideoParser + cue qv + extends videoParser +catchAllErrorParser + baseParser errorParser`).compileAndReturnRootParser() + const program = `video + width +qv + width` + + // console.log(new rootParser(program).definition.toBrowserJavascript()) + + // Act + equal(new rootParser(program).getAllErrors().length, 0) +} + testParticles.abstractParsers = equal => { // Arrange/Act const anyProgram = makeJibberishProgram(`someAbstractClass diff --git a/parsers/Parsers.ts b/parsers/Parsers.ts index 8e992c7a2..1afa271ad 100644 --- a/parsers/Parsers.ts +++ b/parsers/Parsers.ts @@ -2241,9 +2241,18 @@ ${captures} return this._cache_ancestorParserIdsArray } + _isLooping = false protected _cache_parserDefinitionParsers: { [parserId: string]: parserDefinitionParser } get programParserDefinitionCache() { - if (!this._cache_parserDefinitionParsers) this._cache_parserDefinitionParsers = this.isRoot || this.hasParserDefinitions ? this.makeProgramParserDefinitionCache() : this.parent.programParserDefinitionCache + if (!this._cache_parserDefinitionParsers) { + if (this._isLooping) throw new Error(`Loop detected in ${this.id}`) + this._isLooping = true + this._cache_parserDefinitionParsers = + this.isRoot() || this.hasParserDefinitions + ? this.makeProgramParserDefinitionCache() + : this.parent.programParserDefinitionCache[this.get(ParsersConstants.extends)]?.programParserDefinitionCache || this.parent.programParserDefinitionCache + this._isLooping = false + } return this._cache_parserDefinitionParsers } diff --git a/particle/Particle.ts b/particle/Particle.ts index 847608dd1..1029fdae0 100644 --- a/particle/Particle.ts +++ b/particle/Particle.ts @@ -3094,7 +3094,7 @@ class Particle extends AbstractParticle { return str ? indent + str.replace(/\n/g, indent) : "" } - static getVersion = () => "100.0.0" + static getVersion = () => "100.0.1" static fromDisk(path: string): Particle { const format = this._getFileFormat(path) diff --git a/products/Parsers.js b/products/Parsers.js index 38a6841ea..2f21b4770 100644 --- a/products/Parsers.js +++ b/products/Parsers.js @@ -1443,6 +1443,10 @@ class ParsersParserConstantString extends AbstractParserConstantParser { class ParsersParserConstantFloat extends AbstractParserConstantParser {} class ParsersParserConstantBoolean extends AbstractParserConstantParser {} class AbstractParserDefinitionParser extends AbstractExtendibleParticle { + constructor() { + super(...arguments) + this._isLooping = false + } createParserCombinator() { // todo: some of these should just be on nonRootParticles const types = [ @@ -1803,9 +1807,19 @@ ${captures} return this._cache_ancestorParserIdsArray } get programParserDefinitionCache() { - if (!this._cache_parserDefinitionParsers) this._cache_parserDefinitionParsers = this.isRoot || this.hasParserDefinitions ? this.makeProgramParserDefinitionCache() : this.parent.programParserDefinitionCache + var _a + if (!this._cache_parserDefinitionParsers) { + if (this._isLooping) throw new Error(`Loop detected in ${this.id}`) + this._isLooping = true + this._cache_parserDefinitionParsers = + this.isRoot() || this.hasParserDefinitions + ? this.makeProgramParserDefinitionCache() + : ((_a = this.parent.programParserDefinitionCache[this.get(ParsersConstants.extends)]) === null || _a === void 0 ? void 0 : _a.programParserDefinitionCache) || this.parent.programParserDefinitionCache + this._isLooping = false + } return this._cache_parserDefinitionParsers } + get extendedDef() {} get hasParserDefinitions() { return !!this.getSubparticlesByParser(parserDefinitionParser).length } diff --git a/products/Parsers.ts.browser.js b/products/Parsers.ts.browser.js index 075e409bc..5ff923a38 100644 --- a/products/Parsers.ts.browser.js +++ b/products/Parsers.ts.browser.js @@ -1441,6 +1441,10 @@ class ParsersParserConstantString extends AbstractParserConstantParser { class ParsersParserConstantFloat extends AbstractParserConstantParser {} class ParsersParserConstantBoolean extends AbstractParserConstantParser {} class AbstractParserDefinitionParser extends AbstractExtendibleParticle { + constructor() { + super(...arguments) + this._isLooping = false + } createParserCombinator() { // todo: some of these should just be on nonRootParticles const types = [ @@ -1801,9 +1805,19 @@ ${captures} return this._cache_ancestorParserIdsArray } get programParserDefinitionCache() { - if (!this._cache_parserDefinitionParsers) this._cache_parserDefinitionParsers = this.isRoot || this.hasParserDefinitions ? this.makeProgramParserDefinitionCache() : this.parent.programParserDefinitionCache + var _a + if (!this._cache_parserDefinitionParsers) { + if (this._isLooping) throw new Error(`Loop detected in ${this.id}`) + this._isLooping = true + this._cache_parserDefinitionParsers = + this.isRoot() || this.hasParserDefinitions + ? this.makeProgramParserDefinitionCache() + : ((_a = this.parent.programParserDefinitionCache[this.get(ParsersConstants.extends)]) === null || _a === void 0 ? void 0 : _a.programParserDefinitionCache) || this.parent.programParserDefinitionCache + this._isLooping = false + } return this._cache_parserDefinitionParsers } + get extendedDef() {} get hasParserDefinitions() { return !!this.getSubparticlesByParser(parserDefinitionParser).length } diff --git a/products/Particle.browser.js b/products/Particle.browser.js index 466d4426f..76fc9ad75 100644 --- a/products/Particle.browser.js +++ b/products/Particle.browser.js @@ -2598,7 +2598,7 @@ Particle.iris = `sepal_length,sepal_width,petal_length,petal_width,species 4.9,2.5,4.5,1.7,virginica 5.1,3.5,1.4,0.2,setosa 5,3.4,1.5,0.2,setosa` -Particle.getVersion = () => "100.0.0" +Particle.getVersion = () => "100.0.1" class AbstractExtendibleParticle extends Particle { _getFromExtended(cuePath) { const hit = this._getParticleFromExtended(cuePath) diff --git a/products/Particle.js b/products/Particle.js index 48cd2c1a7..c422eeef0 100644 --- a/products/Particle.js +++ b/products/Particle.js @@ -2588,7 +2588,7 @@ Particle.iris = `sepal_length,sepal_width,petal_length,petal_width,species 4.9,2.5,4.5,1.7,virginica 5.1,3.5,1.4,0.2,setosa 5,3.4,1.5,0.2,setosa` -Particle.getVersion = () => "100.0.0" +Particle.getVersion = () => "100.0.1" class AbstractExtendibleParticle extends Particle { _getFromExtended(cuePath) { const hit = this._getParticleFromExtended(cuePath) diff --git a/releaseNotes.scroll b/releaseNotes.scroll index 3c2762e1e..6fa9e0bd1 100644 --- a/releaseNotes.scroll +++ b/releaseNotes.scroll @@ -20,6 +20,9 @@ node_modules/scroll-cli/microlangs/changes.parsers thinColumns 4 +📦 100.0.1 2024-12-07 +🏥 fixed bug in Parsers where inline Parsers were not in scope in child Parsers + 📦 100.0.0 2024-12-07 🎉 Finished migrating "keywordAtom" to "cueAtom" ⚠️ BREAKING: every `keywordAtom` is now `cueAtom`