MCPcopy Create free account
hub / github.com/breck7/scroll / parserAsJavascript

Method parserAsJavascript

external/.scrollLibs.js:19645–19671  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

19643 return ""
19644 }
19645 get parserAsJavascript() {
19646 if (this._isBlobParser())
19647 // todo: do we need this?
19648 return "createParserPool() { return new Particle.ParserPool(this._getBlobParserCatchAllParser())}"
19649 const parserInfo = this._createParserInfo(this._getMyInScopeParserIds())
19650 const myCueMap = parserInfo.cueMap
19651 const regexRules = parserInfo.regexTests
19652 // todo: use constants in first atom maps?
19653 // todo: cache the super extending?
19654 const cues = Object.keys(myCueMap)
19655 const hasCues = cues.length
19656 const catchAllParser = this.catchAllParserToJavascript
19657 if (!hasCues && !catchAllParser && !regexRules.length) return ""
19658 const cuesStr = hasCues ? `Object.assign(Object.assign({}, super.createParserPool()._getCueMapAsObject()), {` + cues.map(cue => `"${cue}" : ${myCueMap[cue].parserIdFromDefinition}`).join(",\n") + "})" : "undefined"
19659 const regexStr = regexRules.length
19660 ? `[${regexRules
19661 .map(rule => {
19662 return `{regex: /${rule.regex}/, parser: ${rule.parser}}`
19663 })
19664 .join(",")}]`
19665 : "undefined"
19666 const catchAllStr = catchAllParser ? catchAllParser : this._amIRoot() ? `this._getBlobParserCatchAllParser()` : "undefined"
19667 const scopedParserJavascript = this.myScopedParserDefinitions.map(def => def.asJavascriptClass).join("\n\n")
19668 return `createParserPool() {${scopedParserJavascript}
19669 return new Particle.ParserPool(${catchAllStr}, ${cuesStr}, ${regexStr})
19670 }`
19671 }
19672 get myScopedParserDefinitions() {
19673 return this.getSubparticlesByParser(parserDefinitionParser)
19674 }

Callers

nothing calls this directly

Calls 6

_isBlobParserMethod · 0.95
_createParserInfoMethod · 0.95
_amIRootMethod · 0.95
mapMethod · 0.80
joinMethod · 0.45

Tested by

no test coverage detected