@@ -66,34 +66,6 @@ const makeProgram = (parsersCode: string, code: string) => {
66
66
return new rootParser ( code )
67
67
}
68
68
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
-
97
69
testParticles . jibberish = equal => {
98
70
// Arrange
99
71
const sampleJibberishCode = Disk . read ( path . join ( jibberishRootDir , "sample.jibberish" ) )
@@ -514,49 +486,6 @@ testParticles.blobParsers = equal => {
514
486
equal ( anyProgram . topDownArray . map ( ( particle : any ) => particle . parserId ) . length > 0 , true , "passed blob regression" )
515
487
}
516
488
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
-
560
489
// todo: reenable once we have the requirement of at least 1 root particle
561
490
// testParticles.requiredParsers = equal => {
562
491
// // Arrange/Act
@@ -749,15 +678,64 @@ testParticles.invalidParsersRegression = equal => {
749
678
equal ( typeof compiledParser , "string" )
750
679
}
751
680
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
+
753
703
// 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`
755
730
756
731
// Act
757
- const bundle = jibberishParsersProgram . toBundle ( )
732
+ basicProgram . registerParsers ( adiosParser )
733
+ basicProgram . appendLine ( "adios" )
734
+ basicProgram . appendLine ( "bye" )
758
735
759
736
// 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" )
761
739
}
762
740
763
741
const jibberishParsersProgram = new HandParsersProgram ( jibberishParsersCode )
0 commit comments