Skip to content

Commit 2525d68

Browse files
authored
ScrollSDK 107. Change Scroll to be single pass parser. (#198)
* Async fix * Code removal * Code removal * Code removal * Code removal * Remove _rootNodeJsHeader, whatever that was * Code removal * Add runtime parsers method * Move timeIndex to scroll * Prepare Release Candidate * Perf work * Add replace with method * add switchParserPool method * Release candidate * Update release notes
1 parent 3b25dff commit 2525d68

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

59 files changed

+1049
-1971
lines changed

designer/DesignerApp.ts

Lines changed: 1 addition & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,6 @@ declare var parsersParser: any
99
// todo: get typings in here.
1010
declare var CodeMirror: any
1111
declare var saveAs: any
12-
declare var JSZip: any
13-
declare var dumbdownParser: any
1412
declare type html = string
1513

1614
class DesignerApp extends AbstractParticleComponentParser {
@@ -91,26 +89,6 @@ class DesignerApp extends AbstractParticleComponentParser {
9189
this._setParsersAndCode(parsers.text, sample)
9290
}
9391

94-
// TODO: ADD TESTS!!!!!
95-
async downloadBundleCommand() {
96-
const parsersProgram = new HandParsersProgram(this.getParsersCode())
97-
const bundle = parsersProgram.toBundle()
98-
const languageName = parsersProgram.extensionName
99-
return this._makeZipBundle(languageName + ".zip", bundle)
100-
}
101-
102-
private async _makeZipBundle(fileName: string, bundle: any) {
103-
const zip = new JSZip()
104-
Object.keys(bundle).forEach(key => {
105-
zip.file(key, bundle[key])
106-
})
107-
108-
zip.generateAsync({ type: "blob" }).then((content: any) => {
109-
// see FileSaver.js
110-
saveAs(content, fileName)
111-
})
112-
}
113-
11492
private _toIceTray(program: any) {
11593
const columns = program.programWidth
11694

@@ -284,7 +262,7 @@ class DesignerApp extends AbstractParticleComponentParser {
284262
const errs = this.parsersProgram.getAllErrors().map((err: any) => err.toObject())
285263
this.willowBrowser.setHtmlOfElementWithIdHack("parsersErrorsConsole", errs.length ? new Particle(errs).toFormattedTable(200) : "0 errors")
286264
const parsersProgram = new HandParsersProgram(this.parsersInstance.getValue())
287-
const readme = new dumbdownParser(parsersProgram.toReadMe()).compile()
265+
const readme = parsersProgram.toReadMe()
288266

289267
this.willowBrowser.setHtmlOfElementWithIdHack("readmeComponent", readme)
290268
}

designer/index.html

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,15 +11,13 @@
1111
<script type="text/javascript" src="../sandbox/lib/placeholder.js"></script>
1212
<script type="text/javascript" src="../sandbox/lib/javascript.js"></script>
1313
<script type="text/javascript" src="../sandbox/lib/FileSaver.min.js"></script>
14-
<script type="text/javascript" src="../sandbox/lib/jszip.min.js"></script>
1514
<script src="../products/Utils.browser.js"></script>
1615
<script src="../products/Particle.browser.js"></script>
1716
<script src="../products/Parsers.ts.browser.js"></script>
1817
<script src="../products/ParsersCodeMirrorMode.browser.js"></script>
1918
<script src="../products/stump.browser.js"></script>
2019
<script src="../products/hakon.browser.js"></script>
2120
<script src="../products/parsers.browser.js"></script>
22-
<script src="../products/dumbdown.browser.js"></script>
2321
<script src="../products/ParticleComponentFramework.browser.js"></script>
2422
<script type="text/javascript" src="../products/DesignerApp.browser.js"></script>
2523
<link rel="shortcut icon" type="image/x-icon" href="../images/favicon.ico" />

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "scrollsdk",
3-
"version": "106.0.1",
3+
"version": "107.0.0",
44
"description": "This npm package includes the Particles class, the Parsers compiler-compiler, a Parsers IDE, and more, all implemented in Particles, Parsers, and TypeScript.",
55
"types": "./built/scrollsdk.node.d.ts",
66
"main": "./products/Particle.js",

parsers/Parsers.test.ts

Lines changed: 53 additions & 75 deletions
Original file line numberDiff line numberDiff line change
@@ -66,34 +66,6 @@ const makeProgram = (parsersCode: string, code: string) => {
6666
return new rootParser(code)
6767
}
6868

69-
testParticles.trainAndPredict = equal => {
70-
// Arrange/Act
71-
const parsersProgram = new HandParsersProgram(hakonParsers)
72-
const hakonParser = parsersProgram.compileAndReturnRootParser()
73-
const testBlankProgram = new hakonParser()
74-
const handParsersProgram = testBlankProgram.handParsersProgram
75-
const examples = handParsersProgram.getParticlesByGlobPath("* example").map((particle: any) => particle.subparticlesToString())
76-
const model = parsersProgram.trainModel(examples)
77-
78-
// Assert
79-
const predictions = handParsersProgram.predictSubparticles(model, testBlankProgram)
80-
equal(predictions[0].id, "selectorParser")
81-
82-
// Act
83-
const bodyParticle = testBlankProgram.appendLine("body")
84-
85-
// Assert
86-
const predictions2 = handParsersProgram.predictSubparticles(model, bodyParticle)
87-
equal(predictions2[0].id, "propertyParser")
88-
89-
// Act
90-
const fontSizeParticle = testBlankProgram.appendLine("font-size")
91-
92-
// Assert
93-
const predictions3 = handParsersProgram.predictParents(model, fontSizeParticle)
94-
equal(predictions3[0].id, "selectorParser")
95-
}
96-
9769
testParticles.jibberish = equal => {
9870
// Arrange
9971
const sampleJibberishCode = Disk.read(path.join(jibberishRootDir, "sample.jibberish"))
@@ -514,49 +486,6 @@ testParticles.blobParsers = equal => {
514486
equal(anyProgram.topDownArray.map((particle: any) => particle.parserId).length > 0, true, "passed blob regression")
515487
}
516488

517-
testParticles.sublimeSyntaxFile = equal => {
518-
// Arrange/Act
519-
const parsersProgram = new HandParsersProgram(jibberishParsersCode)
520-
const code = parsersProgram.toSublimeSyntaxFile()
521-
522-
// Assert
523-
equal(code.includes("scope:"), true)
524-
}
525-
526-
testParticles.toStumpString = equal => {
527-
// Arrange/Act
528-
const parsersProgram = new HandParsersProgram(arrowParsers).compileAndReturnRootParser()
529-
const code = new parsersProgram().definition.getParserDefinitionByParserId("chargeParser").toStumpString()
530-
const expected = `div
531-
label amount
532-
input
533-
name amount
534-
type number
535-
placeholder 9.99
536-
min 0
537-
max 99999
538-
div
539-
label currency
540-
select
541-
name currency
542-
option usd
543-
option cad
544-
option jpy
545-
div
546-
label cardNumber
547-
input
548-
name cardNumber
549-
placeholder 1111222233334444
550-
div
551-
label token
552-
input
553-
name token
554-
placeholder sk_test_4eC39H`
555-
556-
// Assert
557-
equal(code, expected, "form correct")
558-
}
559-
560489
// todo: reenable once we have the requirement of at least 1 root particle
561490
// testParticles.requiredParsers = equal => {
562491
// // Arrange/Act
@@ -749,15 +678,64 @@ testParticles.invalidParsersRegression = equal => {
749678
equal(typeof compiledParser, "string")
750679
}
751680

752-
testParticles.bundler = equal => {
681+
testParticles.addRunTimeParser = equal => {
682+
const parsers = `// Atom Parsers
683+
nameAtom
684+
description A person's name
685+
paint string
686+
cueAtom
687+
paint keyword
688+
689+
// Line Parsers
690+
newlangParser
691+
root
692+
description A basic root parser.
693+
catchAllParser catchAllErrorParser
694+
inScope helloParser
695+
helloParser
696+
int luckyNumber 7
697+
catchAllAtomType nameAtom
698+
atoms cueAtom
699+
cue hello
700+
catchAllErrorParser
701+
baseParser errorParser`
702+
753703
// Arrange
754-
const jibberishParsersProgram = new HandParsersProgram(jibberishParsersCode)
704+
const parsersProgram = new HandParsersProgram(parsers)
705+
const rootParser = parsersProgram.compileAndReturnRootParser()
706+
707+
// Act/Assert
708+
const basicProgram = new rootParser(`hello Mom`)
709+
equal(basicProgram.particleAt(0).luckyNumber, 7, "Basics work")
710+
711+
const byeParser = `byeParser
712+
int luckyNumber 42
713+
atoms cueAtom
714+
extends helloParser
715+
cue bye`
716+
717+
// Act
718+
// Now we need to add a Parser.
719+
basicProgram.registerParsers(byeParser)
720+
basicProgram.appendLine("bye")
721+
722+
// Assert
723+
equal(basicProgram.particleAt(1).luckyNumber, 42, "registerParsers work")
724+
725+
const adiosParser = `adiosParser
726+
int luckyNumber 15
727+
atoms cueAtom
728+
extends helloParser
729+
cueFromId`
755730

756731
// Act
757-
const bundle = jibberishParsersProgram.toBundle()
732+
basicProgram.registerParsers(adiosParser)
733+
basicProgram.appendLine("adios")
734+
basicProgram.appendLine("bye")
758735

759736
// Assert
760-
equal(bundle["readme.md"].includes("stats"), true)
737+
equal(basicProgram.particleAt(2).luckyNumber, 15, "adding multiple parsers works")
738+
equal(basicProgram.particleAt(3).luckyNumber, 42, "earlier additions work")
761739
}
762740

763741
const jibberishParsersProgram = new HandParsersProgram(jibberishParsersCode)

0 commit comments

Comments
 (0)