@@ -278,48 +278,58 @@ public int Interperate(LineWithTokens[] LineTokens)
278278 Method . MethodSettings settings = method . Settings ;
279279 bool nocol = ( settings & Method . MethodSettings . NoCol ) != 0 ;
280280 int next = nocol ? 0 : 1 ;
281- if ( ! nocol && line . Tokens [ 1 ] . Type != TokenType . Colon )
282- {
283- throw new Exception ( "Expected \" :\" identifier to set method perameters" ) ;
284- }
285281 Var [ ] vars = [ ] ;
286-
287- if ( method . Params != null && method . Params . Length > 0 )
282+ if ( line . Tokens . Length != 1 )
288283 {
289- string all ; string [ ] vals ;
290- try
284+ if ( ! nocol && line . Tokens [ 1 ] . Type != TokenType . Colon )
291285 {
292- all = string . Join ( " " , line . Tokens . Skip ( next + 1 ) . Select ( x => x . StringValue ) ) ;
293- if ( all . Split ( ',' ) . Length > method . Params . Select ( x => x . Required ) . ToArray ( ) . Length )
294- throw new Exception ( $ "Expects { ( method . Params . Any ( x=> x . Required ) ? "at least" : "" ) } { ( method . Params . Any ( x => x . Required ) ? method . Params . Select ( x=> x . Required ) . ToArray ( ) . Length : method . Params . Length ) } parameter for method \" { method . Name } \" but { all . Split ( ',' ) . Length } were inputted") ;
295- vals = all . Split ( ',' ) . Select ( x => x . Trim ( ) ) . Select ( ( x , y ) => GetValue ( x , method . Params [ y ] . DataType ) . ToString ( ) ) . Where ( x => x != "" ) . ToArray ( ) ;
286+ throw new Exception ( "Expected \" :\" identifier to set method perameters" ) ;
296287 }
297- catch ( Exception e )
298- {
299- if ( e . Message . StartsWith ( "Expects " ) ) throw new Exception ( e . Message ) ;
300- throw new Exception ( "Error getting values for method paramters" ) ;
301- }
302- if ( vals . Length > 0 )
288+
289+ if ( method . Params != null && method . Params . Length > 0 )
303290 {
304- for ( int i = 0 ; i < method . Params . Length ; i ++ )
291+ string all ; string [ ] vals ;
292+ try
305293 {
306- if ( ! method . Params [ i ] . Required && vals . Length - 1 < i )
307- continue ;
308- vars = [ .. vars , new Var ( method . Params [ i ] . Name , vals [ i ] , line . Line , stackNumber : StackNumber , type : method . Params [ i ] . DataType , required : method . Params [ i ] . Required ) ] ;
294+ all = string . Join ( " " , line . Tokens . Skip ( next + 1 ) . Select ( x => x . StringValue ) ) ;
295+ if ( all . Split ( ',' ) . Length > method . Params . Select ( x => x . Required ) . ToArray ( ) . Length )
296+ throw new Exception ( $ "Expects { ( method . Params . Any ( x=> x . Required ) ? "at least" : "" ) } { ( method . Params . Any ( x => x . Required ) ? method . Params . Select ( x=> x . Required ) . ToArray ( ) . Length : method . Params . Length ) } parameter for method \" { method . Name } \" but { all . Split ( ',' ) . Length } were inputted") ;
297+ vals = all . Split ( ',' ) . Select ( x => x . Trim ( ) ) . Select ( ( x , y ) => GetValue ( x , method . Params [ y ] . DataType ) . ToString ( ) ) . Where ( x => x != "" ) . ToArray ( ) ;
309298 }
310- if ( vars . Where ( x => x . Required ) . ToArray ( ) . Length != method . Params . Where ( x => x . Required ) . ToArray ( ) . Length )
299+ catch ( Exception e )
311300 {
312- throw new Exception ( "Not all parameters are set" ) ;
301+ if ( e . Message . StartsWith ( "Expects " ) ) throw new Exception ( e . Message ) ;
302+ throw new Exception ( "Error getting values for method paramters" ) ;
313303 }
314- }
315- else
316- {
317- if ( line . Tokens . Length > 1 )
304+ if ( vals . Length > 0 )
318305 {
319- throw new Exception ( "Method does not require any parameters" ) ;
306+ for ( int i = 0 ; i < method . Params . Length ; i ++ )
307+ {
308+ if ( ! method . Params [ i ] . Required && vals . Length - 1 < i )
309+ continue ;
310+ vars = [ .. vars , new Var ( method . Params [ i ] . Name , vals [ i ] , line . Line , stackNumber : StackNumber , type : method . Params [ i ] . DataType , required : method . Params [ i ] . Required ) ] ;
311+ }
312+ if ( vars . Where ( x => x . Required ) . ToArray ( ) . Length != method . Params . Where ( x => x . Required ) . ToArray ( ) . Length )
313+ {
314+ throw new Exception ( "Not all parameters are set" ) ;
315+ }
316+ }
317+ else
318+ {
319+ if ( line . Tokens . Length > 1 )
320+ {
321+ throw new Exception ( "Method does not require any parameters" ) ;
322+ }
320323 }
321324 }
322325 }
326+ else
327+ {
328+ if ( method . Params != null && method . Params . Select ( x => x . Required ) . ToArray ( ) . Length > 0 )
329+ {
330+ throw new Exception ( $ "Method \" { method . Name } \" expects parameters") ;
331+ }
332+ }
323333
324334 Return = MethodRun ( method , vars ) ;
325335 break ;
0 commit comments