Skip to content

Commit

Permalink
Renamed ParserCombinator to ParserPool
Browse files Browse the repository at this point in the history
  • Loading branch information
breck7 committed Jan 31, 2025
1 parent 958e131 commit 73e1a58
Show file tree
Hide file tree
Showing 7 changed files with 56 additions and 56 deletions.
8 changes: 4 additions & 4 deletions designer/DesignerApp.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@ declare var dumbdownParser: any
declare type html = string

class DesignerApp extends AbstractParticleComponentParser {
createParserCombinator() {
return new Particle.ParserCombinator(undefined, {
createParserPool() {
return new Particle.ParserPool(undefined, {
githubTriangleComponent,
samplesComponent,
tableComponent,
Expand Down Expand Up @@ -516,8 +516,8 @@ class explainResultsComponent extends AbstractParticleComponentParser {
}

class tableComponent extends AbstractParticleComponentParser {
createParserCombinator() {
return new Particle.ParserCombinator(undefined, {
createParserPool() {
return new Particle.ParserPool(undefined, {
compiledResultsComponent: compiledResultsComponent,
executionResultsComponent: executionResultsComponent,
explainResultsComponent: explainResultsComponent
Expand Down
40 changes: 20 additions & 20 deletions parsers/Parsers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -519,8 +519,8 @@ abstract class ParserBackedParticle extends Particle {
this._cache_programAtomTypeStringMTime = particleMTime
}

createParserCombinator() {
return this.isRoot() ? new Particle.ParserCombinator(BlobParser) : new Particle.ParserCombinator(this.parent._getParser()._getCatchAllParser(this.parent), {})
createParserPool() {
return this.isRoot() ? new Particle.ParserPool(BlobParser) : new Particle.ParserPool(this.parent._getParserPool()._getCatchAllParser(this.parent), {})
}

get parserId(): particlesTypes.parserId {
Expand Down Expand Up @@ -756,8 +756,8 @@ ${indent}${closeSubparticlesString}`
}

class BlobParser extends ParserBackedParticle {
createParserCombinator() {
return new Particle.ParserCombinator(BlobParser, {})
createParserPool() {
return new Particle.ParserPool(BlobParser, {})
}

getErrors(): particlesTypes.ParticleError[] {
Expand All @@ -767,8 +767,8 @@ class BlobParser extends ParserBackedParticle {

// todo: can we remove this? hard to extend.
class UnknownParserParticle extends ParserBackedParticle {
createParserCombinator() {
return new Particle.ParserCombinator(UnknownParserParticle, {})
createParserPool() {
return new Particle.ParserPool(UnknownParserParticle, {})
}

getErrors(): particlesTypes.ParticleError[] {
Expand Down Expand Up @@ -1292,7 +1292,7 @@ class UnknownParserError extends AbstractParticleError {
get message(): string {
const particle = this.getParticle()
const parentParticle = particle.parent
const options = parentParticle._getParser().getCueOptions()
const options = parentParticle._getParserPool().getCueOptions()
return super.message + ` Invalid parser "${particle.cue}". Valid parsers are: ${Utils._listToEnglishText(options, 7)}.`
}

Expand Down Expand Up @@ -1513,7 +1513,7 @@ class ParsersEnumTestParticle extends AbstractParsersAtomTestParser {
}

class atomTypeDefinitionParser extends AbstractExtendibleParticle {
createParserCombinator() {
createParserPool() {
const types: particlesTypes.stringMap = {}
types[ParsersConstants.regex] = ParsersRegexTestParser
types[ParsersConstants.reservedAtoms] = ParsersReservedAtomsTestParser
Expand All @@ -1526,7 +1526,7 @@ class atomTypeDefinitionParser extends AbstractExtendibleParticle {
types[ParsersConstants.max] = Particle
types[ParsersConstants.description] = Particle
types[ParsersConstants.extends] = Particle
return new Particle.ParserCombinator(undefined, types)
return new Particle.ParserPool(undefined, types)
}

get id() {
Expand Down Expand Up @@ -1752,7 +1752,7 @@ class OmnifixAtomParser extends AbstractAtomParser {
class ParsersExampleParser extends Particle {}

class ParsersCompilerParser extends Particle {
createParserCombinator() {
createParserPool() {
const types = [
ParsersConstantsCompiler.stringTemplate,
ParsersConstantsCompiler.indentCharacter,
Expand All @@ -1765,7 +1765,7 @@ class ParsersCompilerParser extends Particle {
types.forEach(type => {
map[type] = Particle
})
return new Particle.ParserCombinator(undefined, map)
return new Particle.ParserPool(undefined, map)
}
}

Expand Down Expand Up @@ -1807,7 +1807,7 @@ class ParsersParserConstantFloat extends AbstractParserConstantParser {}
class ParsersParserConstantBoolean extends AbstractParserConstantParser {}

abstract class AbstractParserDefinitionParser extends AbstractExtendibleParticle {
createParserCombinator() {
createParserPool() {
// todo: some of these should just be on nonRootParticles
const types = [
ParsersConstants.popularity,
Expand Down Expand Up @@ -1847,7 +1847,7 @@ abstract class AbstractParserDefinitionParser extends AbstractExtendibleParticle
map[ParsersConstantsConstantTypes.float] = ParsersParserConstantFloat
map[ParsersConstants.compilerParser] = ParsersCompilerParser
map[ParsersConstants.example] = ParsersExampleParser
return new Particle.ParserCombinator(undefined, map, [{ regex: HandParsersProgram.parserFullRegex, parser: parserDefinitionParser }])
return new Particle.ParserPool(undefined, map, [{ regex: HandParsersProgram.parserFullRegex, parser: parserDefinitionParser }])
}

toTypeScriptInterface(used = new Set<string>()) {
Expand Down Expand Up @@ -1955,7 +1955,7 @@ ${properties.join("\n")}

// todo: remove
get runTimeCuesInScope(): particlesTypes.parserId[] {
return this._getParser().getCueOptions()
return this._getParserPool().getCueOptions()
}

private _getMyAtomTypeDefs() {
Expand Down Expand Up @@ -2093,7 +2093,7 @@ ${properties.join("\n")}
private get parserAsJavascript(): particlesTypes.javascriptCode {
if (this._isBlobParser())
// todo: do we need this?
return "createParserCombinator() { return new Particle.ParserCombinator(this._getBlobParserCatchAllParser())}"
return "createParserPool() { return new Particle.ParserPool(this._getBlobParserCatchAllParser())}"
const parserInfo = this._createParserInfo(this._getMyInScopeParserIds())
const myCueMap = parserInfo.cueMap
const regexRules = parserInfo.regexTests
Expand All @@ -2105,7 +2105,7 @@ ${properties.join("\n")}
const catchAllParser = this.catchAllParserToJavascript
if (!hasCues && !catchAllParser && !regexRules.length) return ""

const cuesStr = hasCues ? `Object.assign(Object.assign({}, super.createParserCombinator()._getCueMapAsObject()), {` + cues.map(cue => `"${cue}" : ${myCueMap[cue].parserIdFromDefinition}`).join(",\n") + "})" : "undefined"
const cuesStr = hasCues ? `Object.assign(Object.assign({}, super.createParserPool()._getCueMapAsObject()), {` + cues.map(cue => `"${cue}" : ${myCueMap[cue].parserIdFromDefinition}`).join(",\n") + "})" : "undefined"

const regexStr = regexRules.length
? `[${regexRules
Expand All @@ -2119,8 +2119,8 @@ ${properties.join("\n")}

const scopedParserJavascript = this.myScopedParserDefinitions.map(def => def.asJavascriptClass).join("\n\n")

return `createParserCombinator() {${scopedParserJavascript}
return new Particle.ParserCombinator(${catchAllStr}, ${cuesStr}, ${regexStr})
return `createParserPool() {${scopedParserJavascript}
return new Particle.ParserPool(${catchAllStr}, ${cuesStr}, ${regexStr})
}`
}

Expand Down Expand Up @@ -2407,10 +2407,10 @@ class parserDefinitionParser extends AbstractParserDefinitionParser {}
// HandParsersProgram is a constructor that takes a parsers file, and builds a new
// constructor for new language that takes files in that language to execute, compile, etc.
class HandParsersProgram extends AbstractParserDefinitionParser {
createParserCombinator() {
createParserPool() {
const map: particlesTypes.stringMap = {}
map[ParsersConstants.comment] = Particle
return new Particle.ParserCombinator(UnknownParserParticle, map, [
return new Particle.ParserPool(UnknownParserParticle, map, [
{ regex: HandParsersProgram.blankLineRegex, parser: Particle },
{ regex: HandParsersProgram.parserFullRegex, parser: parserDefinitionParser },
{ regex: HandParsersProgram.atomTypeFullRegex, parser: atomTypeDefinitionParser }
Expand Down
20 changes: 10 additions & 10 deletions particle/Particle.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1747,8 +1747,8 @@ testParticles.simpleParticleLanguage = equal => {
// Arrange
class MathProgramParser extends Particle {
// Look! You created a top down parser!
createParserCombinator() {
return new Particle.ParserCombinator(undefined, { "+": AdditionParticleParser, "-": SubstractionParticleParser })
createParserPool() {
return new Particle.ParserPool(undefined, { "+": AdditionParticleParser, "-": SubstractionParticleParser })
}

execute() {
Expand Down Expand Up @@ -2607,14 +2607,14 @@ testParticles.setAtom = equal => {
testParticles.particleLanguageDependingOnParent = equal => {
// Arrange
class ReverseEtnParticle extends Particle {
createParserCombinator() {
return new Particle.ParserCombinator(Particle, {})
createParserPool() {
return new Particle.ParserPool(Particle, {})
}
}

class TestLanguage extends Particle {
createParserCombinator() {
return new Particle.ParserCombinator(ReverseEtnParticle, {})
createParserPool() {
return new Particle.ParserPool(ReverseEtnParticle, {})
}
}

Expand Down Expand Up @@ -2712,13 +2712,13 @@ testParticles.parseParticle = equal => {
// Arrange
class LeafParticle extends Particle {}
class SubclassParticle extends Particle {
createParserCombinator() {
return new Particle.ParserCombinator(SubclassParticle, {}, [{ regex: /^leaf/, parser: LeafParticle }])
createParserPool() {
return new Particle.ParserPool(SubclassParticle, {}, [{ regex: /^leaf/, parser: LeafParticle }])
}
}
class TestLanguageParticle extends Particle {
createParserCombinator() {
return new Particle.ParserCombinator(TestLanguageParticle, {}, [
createParserPool() {
return new Particle.ParserPool(TestLanguageParticle, {}, [
{ regex: /^particle/, parser: Particle },
{ regex: /^sub/, parser: SubclassParticle }
])
Expand Down
24 changes: 12 additions & 12 deletions particle/Particle.ts
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ enum ParticlesConstants {
extends = "extends"
}

class ParserCombinator {
class ParserPool {
// todo: should getErrors be under here? At least for certain types of errors?
private _catchAllParser: particlesTypes.ParticleParser
private _cueMap: Map<string, Function>
Expand Down Expand Up @@ -101,7 +101,7 @@ class ParserCombinator {
return obj
}

_getParser(line: string, contextParticle: particlesTypes.particle, atomBreakSymbol = TN_WORD_BREAK_SYMBOL): particlesTypes.ParticleParser {
_getMatchingParser(line: string, contextParticle: particlesTypes.particle, atomBreakSymbol = TN_WORD_BREAK_SYMBOL): particlesTypes.ParticleParser {
return this._getCueMap().get(this._getCue(line, atomBreakSymbol)) || this._getParserFromRegexTests(line) || this._getCatchAllParser(contextParticle)
}

Expand All @@ -110,7 +110,7 @@ class ParserCombinator {

const parent = contextParticle.parent

if (parent) return parent._getParser()._getCatchAllParser(parent)
if (parent) return parent._getParserPool()._getCatchAllParser(parent)

return contextParticle.constructor
}
Expand Down Expand Up @@ -1706,7 +1706,7 @@ class Particle extends AbstractParticle {
}

protected _insertLineAndSubparticles(line: string, subparticles?: particlesTypes.subparticles, index = this.length) {
const parser: any = this._getParser()._getParser(line, this)
const parser: any = this._getParserPool()._getMatchingParser(line, this)
const newParticle = new parser(subparticles, line, this)
const adjustedIndex = index < 0 ? this.length + index : index

Expand Down Expand Up @@ -1750,7 +1750,7 @@ class Particle extends AbstractParticle {
}
const lineContent = line.substr(currentIndentCount)
const parent = parentStack[parentStack.length - 1]
const parser: any = parent._getParser()._getParser(lineContent, parent)
const parser: any = parent._getParserPool()._getMatchingParser(lineContent, parent)
lastParticle = new parser(undefined, lineContent, parent)
parent._getSubparticlesArray().push(lastParticle)
})
Expand Down Expand Up @@ -1950,15 +1950,15 @@ class Particle extends AbstractParticle {
return this.isRoot() || this.parent.isRoot() ? undefined : this.parent.parent
}

private static _parserCombinators = new Map<any, ParserCombinator>()
private static _parserPools = new Map<any, ParserPool>()

_getParser() {
if (!Particle._parserCombinators.has(this.constructor)) Particle._parserCombinators.set(this.constructor, this.createParserCombinator())
return Particle._parserCombinators.get(this.constructor)
_getParserPool() {
if (!Particle._parserPools.has(this.constructor)) Particle._parserPools.set(this.constructor, this.createParserPool())
return Particle._parserPools.get(this.constructor)
}

createParserCombinator(): ParserCombinator {
return new ParserCombinator(this.constructor)
createParserPool(): ParserPool {
return new ParserPool(this.constructor)
}

private static _uniqueId: int
Expand All @@ -1974,7 +1974,7 @@ class Particle extends AbstractParticle {
return (<any>FileFormat)[format] ? format : FileFormat.particles
}

static ParserCombinator = ParserCombinator
static ParserPool = ParserPool

static iris = `sepal_length,sepal_width,petal_length,petal_width,species
6.1,3,4.9,1.8,virginica
Expand Down
4 changes: 2 additions & 2 deletions particleComponentFramework/ParticleComponentFramework.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ const { TestRacer } = require("../products/TestRacer.js")
const testParticles: any = {}

class TestApp extends AbstractParticleComponentParser {
createParserCombinator() {
return new Particle.ParserCombinator(undefined, {
createParserPool() {
return new Particle.ParserPool(undefined, {
headerComponent: headerComponent
})
}
Expand Down
12 changes: 6 additions & 6 deletions particleComponentFramework/sweepercraft/SweeperCraft.ts
Original file line number Diff line number Diff line change
Expand Up @@ -462,8 +462,8 @@ const linkToObject = (link: string): Object => {
}

class SweeperCraftApp extends AbstractParticleComponentParser {
createParserCombinator() {
return new Particle.ParserCombinator(undefined, {
createParserPool() {
return new Particle.ParserPool(undefined, {
headerComponent,
boardComponent,
controlsComponent,
Expand Down Expand Up @@ -835,8 +835,8 @@ class headerComponent extends AbstractSweeperCraftComponent {
}

class boardComponent extends AbstractSweeperCraftComponent {
createParserCombinator() {
return new Particle.ParserCombinator(undefined, {
createParserPool() {
return new Particle.ParserPool(undefined, {
rowComponent: rowComponent
})
}
Expand All @@ -855,8 +855,8 @@ class boardComponent extends AbstractSweeperCraftComponent {
}

class rowComponent extends AbstractParticleComponentParser {
createParserCombinator() {
return new Particle.ParserCombinator(undefined, {
createParserPool() {
return new Particle.ParserPool(undefined, {
squareComponent: squareComponent
})
}
Expand Down
4 changes: 2 additions & 2 deletions sandbox/SandboxApp.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ const { Fusion, FusionFile } = require("../products/Fusion.js")
// Todo: add inputs at the top to change the edge, particle, and atom delimiters.

class SandboxApp extends AbstractParticleComponentParser {
createParserCombinator() {
return new Particle.ParserCombinator(undefined, {
createParserPool() {
return new Particle.ParserPool(undefined, {
tableComponent,
shareComponent,
githubTriangleComponent,
Expand Down

0 comments on commit 73e1a58

Please sign in to comment.