@@ -112,57 +112,57 @@ instructionTests =
112112 describe " instruction" $ do
113113 it " can parse an assignment by name" $ property $
114114 \ (Ident xs) -> fmap toLower xs `notElem` reservedWords
115- ==> parse instruction " " (fromString $ xs ++ " = 1.0" ) `shouldParse`
115+ ==> parse instruction " " (fromString $ xs ++ " = 1.0; " ) `shouldParse`
116116 Assign (NonLocal $ QbName xs) (ELit (LitF 1 ))
117117 it " can parse an assignment by checksum" $ property $
118- \ c@ (Checksum x) -> parse instruction " " (fromString $ " %$" ++ show c ++ " = 1.0" ) `shouldParse`
118+ \ c@ (Checksum x) -> parse instruction " " (fromString $ " %$" ++ show c ++ " = 1.0; " ) `shouldParse`
119119 Assign (Local $ QbCrc x) (ELit (LitF 1 ))
120120 it " can parse an if with no else branches" $
121- parse instruction " " " if 1.0\n doSomething()\n endif " `shouldParse`
122- IfElse (ELit (LitF 1 ), [BareExpr $ BareCall (QbName " doSomething" ) [] ]) [] []
121+ parse instruction " " " if ( 1.0) { \n doSomething(); \n } " `shouldParse`
122+ IfElse (Paren ( ELit (LitF 1 ) ), [BareExpr $ BareCall (QbName " doSomething" ) [] ]) [] []
123123 it " can parse an if/elseif" $
124- parse instruction " " " if 1.0\n doSomething()\n elseif 2.0\n doNothing()\n endif "
125- `shouldParse` IfElse (ELit (LitF 1 ), [BareExpr $ BareCall (QbName " doSomething" ) [] ])
126- [(ELit (LitF 2 ), [BareExpr $ BareCall (QbName " doNothing" ) [] ])]
124+ parse instruction " " " if ( 1.0) { \n doSomething(); \n } elseif ( 2.0) { \n doNothing(); \n } "
125+ `shouldParse` IfElse (Paren ( ELit (LitF 1 ) ), [BareExpr $ BareCall (QbName " doSomething" ) [] ])
126+ [(Paren ( ELit (LitF 2 ) ), [BareExpr $ BareCall (QbName " doNothing" ) [] ])]
127127 []
128128 it " can parse an if/else" $
129- parse instruction " " " if 1.0\n doSomething()\n else \n doNothing()\n endif "
130- `shouldParse` IfElse (ELit (LitF 1 ), [BareExpr $ BareCall (QbName " doSomething" ) [] ])
129+ parse instruction " " " if ( 1.0) { \n doSomething(); \n } else { \n doNothing(); \n } "
130+ `shouldParse` IfElse (Paren ( ELit (LitF 1 ) ), [BareExpr $ BareCall (QbName " doSomething" ) [] ])
131131 []
132132 [BareExpr $ BareCall (QbName " doNothing" ) [] ]
133133 it " can parse an if/elseif/else" $
134- parse instruction " " " if 1.0\n doSomething()\n elseif 2.0\n doNothing()\n else \n doNothing()\n endif "
135- `shouldParse` IfElse (ELit (LitF 1 ), [BareExpr $ BareCall (QbName " doSomething" ) [] ])
136- [( ELit (LitF 2 ), [BareExpr $ BareCall (QbName " doNothing" ) [] ])]
134+ parse instruction " " " if ( 1.0) { \n doSomething(); \n } elseif ( 2.0) { \n doNothing(); \n } else{ \n doNothing(); \n } "
135+ `shouldParse` IfElse (Paren ( ELit (LitF 1 ) ), [BareExpr $ BareCall (QbName " doSomething" ) [] ])
136+ [( Paren ( ELit (LitF 2 ) ), [BareExpr $ BareCall (QbName " doNothing" ) [] ])]
137137 [BareExpr $ BareCall (QbName " doNothing" ) [] ]
138138 it " can parse a begin/repeat" $
139- parse instruction " " " begin \n doSomething()\n repeat (4) " `shouldParse`
140- Repeat (Just . ELit . SmallLit . LitN $ 4 ) [BareExpr $ BareCall (QbName " doSomething" ) [] ]
139+ parse instruction " " " repeat (4) { \n doSomething(); \n } " `shouldParse`
140+ Repeat (Just . Paren . ELit . SmallLit . LitN $ 4 ) [BareExpr $ BareCall (QbName " doSomething" ) [] ]
141141 it " can parse an infinite begin/repeat" $
142- parse instruction " " " begin \n doSomething()\n repeat " `shouldParse`
142+ parse instruction " " " repeat { \n doSomething(); \n } " `shouldParse`
143143 Repeat Nothing [BareExpr $ BareCall (QbName " doSomething" ) [] ]
144144 it " can parse a switch without default" $
145- parse instruction " " " switch %i \n case 1:\n doSomething()\n break\n endswitch " `shouldParse`
146- Switch (ELit . SmallLit . LitKey . Local . QbName $ " i" )
145+ parse instruction " " " switch (%i) { \n case 1:\n doSomething(); \n break; \n } " `shouldParse`
146+ Switch (Paren . ELit . SmallLit . LitKey . Local . QbName $ " i" )
147147 [(LitN 1 , [BareExpr $ BareCall (QbName " doSomething" ) [] , Break ] )]
148148 []
149149 it " can parse a switch with default" $
150- parse instruction " " " switch %i \n case 1:\n doSomething()\n break\n default:\n doNothing()\n endswitch " `shouldParse`
151- Switch (ELit . SmallLit . LitKey . Local . QbName $ " i" )
150+ parse instruction " " " switch (%i) { \n case 1:\n doSomething(); \n break; \n default:\n doNothing(); \n } " `shouldParse`
151+ Switch (Paren . ELit . SmallLit . LitKey . Local . QbName $ " i" )
152152 [(LitN 1 , [BareExpr $ BareCall (QbName " doSomething" ) [] , Break ] )]
153153 [BareExpr $ BareCall (QbName " doNothing" ) [] ]
154154 it " can parse a break" $
155- parse instruction " " " break" `shouldParse` Break
155+ parse instruction " " " break; " `shouldParse` Break
156156 it " can parse a no-value return" $
157- parse instruction " " " return" `shouldParse` Return Nothing
157+ parse instruction " " " return; " `shouldParse` Return Nothing
158158 it " can parse a non-keyword return" $
159- parse instruction " " " return 3" `shouldParse` Return (Just (Nothing , ELit (SmallLit (LitN 3 ))))
159+ parse instruction " " " return 3; " `shouldParse` Return (Just (Nothing , ELit (SmallLit (LitN 3 ))))
160160 it " can parse a keyword return" $
161- parse instruction " " " return (x=2.0)" `shouldParse` Return (Just (Just $ QbName " x" , ELit (LitF 2 )))
161+ parse instruction " " " return (x=2.0); " `shouldParse` Return (Just (Just $ QbName " x" , ELit (LitF 2 )))
162162 it " can parse a keyword return by crc" $
163- parse instruction " " " return ($1234abcd=2.0)" `shouldParse` Return (Just (Just $ QbCrc 0x1234abcd , ELit (LitF 2 )))
163+ parse instruction " " " return ($1234abcd=2.0); " `shouldParse` Return (Just (Just $ QbCrc 0x1234abcd , ELit (LitF 2 )))
164164 it " can parse a bare call expression" $
165- parse instruction " " " doSomething()"
165+ parse instruction " " " doSomething(); "
166166 `shouldParse` BareExpr (BareCall (QbName " doSomething" ) [] )
167167
168168termTests :: Spec
@@ -244,15 +244,15 @@ structTests :: Spec
244244structTests =
245245 describe " struct" $ do
246246 it " should parse a 1-item struct" $ do
247- parse struct " " " {\n\t qbkey x = $00000000;\n }" `shouldParse`
247+ parse struct " " " {qbkey x = $00000000;}" `shouldParse`
248248 Struct [StructItem QbTKey (QbName " x" ) (QbKey $ QbCrc 0 )]
249- parse struct " " " {\n\t qbkeyref x = $00000000;\n }" `shouldParse`
249+ parse struct " " " {qbkeyref x = $00000000;}" `shouldParse`
250250 Struct [StructItem QbTKeyRef (QbName " x" ) (QbKeyRef $ QbCrc 0 )]
251251 it " can parse arrays of all types" $ do
252- parse struct " " " {\n\t array <int> _ = [1,2,3];\n }" `shouldParse`
252+ parse struct " " " {array <int> _ = [1,2,3];}" `shouldParse`
253253 Struct [StructItem (QbTArray QbTInteger ) (QbCrc 0 ) (QbArray . QbArr QbTInteger
254254 $ [QbInteger 1 , QbInteger 2 , QbInteger 3 ])]
255- parse struct " " " {\n\t array <float> _ = [1.0, 2.0, 3.0];\n }" `shouldParse`
255+ parse struct " " " {array <float> _ = [1.0, 2.0, 3.0];}" `shouldParse`
256256 Struct [StructItem (QbTArray QbTFloat ) (QbCrc 0 ) (QbArray . QbArr QbTFloat
257257 $ [QbFloat 1 , QbFloat 2 , QbFloat 3 ])]
258258 parse struct " " " {\n\t array<string> _ = ['a', 'b'];\n }" `shouldParse`
@@ -283,6 +283,8 @@ qbScriptTests :: Spec
283283qbScriptTests =
284284 describe " qbScript" $ do
285285 it " should parse an empty script" $
286- parse qbScript " " " script() \n endscript " `shouldParse` QbScript Nothing []
286+ parse qbScript " " " script () { \n } " `shouldParse` QbScript Nothing []
287287 -- TODO: sample scripts
288- return ()
288+ it " should parse repeat inside if" $
289+ parse qbScript " " " script() { if(<...>) { repeat { break; }}}" `shouldParse`
290+ QbScript Nothing [IfElse (Paren . ELit $ LitPassthrough , [Repeat Nothing [Break ]]) [] [] ]
0 commit comments