@@ -580,82 +580,35 @@ private void doDebugOutput(String nodeName, List<ParseTree> children) {
580580 }
581581
582582 public boolean match (String command ) {
583+ String [] cmds = command .split (" " );
584+ return match (cmds );
585+ }
586+
587+ public boolean match (String [] args ) {
583588 if (cleft == null ) {
584589 //The compilation error happened during the signature declaration, so
585590 //we can't match it, nor can we even tell if it's what they intended for us to run.
586591 return false ;
587592 }
588593 boolean caseSensitive = Prefs .CaseSensitive ();
589- String [] cmds = command .split (" " );
590- List <String > args = new ArrayList <>(Arrays .asList (cmds ));
591- boolean isAMatch = true ;
592- StringBuilder lastVar = new StringBuilder ();
593- int lastJ = 0 ;
594594 for (int j = 0 ; j < cleft .size (); j ++) {
595- if (!isAMatch ) {
596- break ;
597- }
598- lastJ = j ;
599595 Mixed c = cleft .get (j );
600- if (args .size () <= j ) {
601- if (!Construct .IsCType (c , ConstructType .VARIABLE ) || !((Variable ) c ).isOptional ()) {
602- isAMatch = false ;
603- }
604- break ;
596+ if (args .length <= j ) {
597+ // If this optional, the rest are too.
598+ return c instanceof Variable v && v .isOptional ();
605599 }
606- String arg = args . get ( j );
607- if (! Construct . IsCType ( c , ConstructType . VARIABLE )) {
600+ if (!( c instanceof Variable )) {
601+ String arg = args [ j ];
608602 if (caseSensitive && !c .val ().equals (arg ) || !caseSensitive && !c .val ().equalsIgnoreCase (arg )) {
609- isAMatch = false ;
610- continue ;
603+ return false ;
611604 }
612- } else {
605+ } else if ((( Variable ) c ). isOptional ()) {
613606 //It's a variable. If it's optional, the rest of them are optional too, so as long as the size of
614607 //args isn't greater than the size of cleft, it's a match
615- if (((Variable ) c ).isOptional ()) {
616- if (args .size () <= cleft .size ()) {
617- return true ;
618- } else {
619- Mixed fin = cleft .get (cleft .size () - 1 );
620- if (fin instanceof Variable ) {
621- if (((Variable ) fin ).isFinal ()) {
622- return true ;
623- }
624- }
625- return false ;
626- }
627- }
628- }
629- if (j == cleft .size () - 1 ) {
630- if (Construct .IsCType (cleft .get (j ), ConstructType .VARIABLE )) {
631- Variable lv = (Variable ) cleft .get (j );
632- if (lv .isFinal ()) {
633- for (int a = j ; a < args .size (); a ++) {
634- if (lastVar .length () == 0 ) {
635- lastVar .append (args .get (a ));
636- } else {
637- lastVar .append (" " ).append (args .get (a ));
638- }
639- }
640- }
641- }
642- }
643- }
644- boolean lastIsFinal = false ;
645- if (cleft .get (cleft .size () - 1 ) instanceof Variable ) {
646- Variable v = (Variable ) cleft .get (cleft .size () - 1 );
647- if (v .isFinal ()) {
648- lastIsFinal = true ;
608+ return args .length <= cleft .size () || cleft .get (cleft .size () - 1 ) instanceof Variable v && v .isFinal ();
649609 }
650610 }
651- if ((cleft .get (lastJ ) instanceof Variable && ((Variable ) cleft .get (lastJ )).isOptional ())) {
652- return true ;
653- }
654-
655- if (cleft .size () != cmds .length && !lastIsFinal ) {
656- isAMatch = false ;
657- }
658- return isAMatch ;
611+ return args .length == cleft .size () || cleft .get (cleft .size () - 1 ) instanceof Variable v && v .isFinal ();
659612 }
660613
661614 public List <Variable > getVariables (String command ) {
0 commit comments