@@ -712,10 +712,7 @@ private static void PurgeUnused()
712712 #region Applying Patches
713713
714714 // Name is group 1, index is group 2, vector related filed is group 3, vector separator is group 4, operator is group 5
715- private static Regex parseValue = new Regex ( @"([\w\&\-\.\?\*+/^!\(\) ]+(?:,[^*\d][\w\&\-\.\?\*\(\) ]*)*)(?:,(-?[0-9\*]+))?(?:\[((?:[0-9\*]+)+)(?:,(.))?\])?(?:\s*([+\-*/^!]))?" ) ;
716-
717- // Path is group 1, operator is group 5
718- private static Regex parseAssign = new Regex ( @"(.*)(?:\s)+([+\-*/^!])?" ) ;
715+ private static Regex parseValue = new Regex ( @"([\w\&\-\.\?\*+/^!\(\) ]+(?:,[^*\d][\w\&\-\.\?\*\(\) ]*)*)(?:,(-?[0-9\*]+))?(?:\[((?:[0-9\*]+)+)(?:,(.))?\])?" ) ;
719716
720717 // ModifyNode applies the ConfigNode mod as a 'patch' to ConfigNode original, then returns the patched ConfigNode.
721718 // it uses FindConfigNodeIn(src, nodeType, nodeName, nodeTag) to recurse.
@@ -737,17 +734,10 @@ public static ConfigNode ModifyNode(NodeStack original, ConfigNode mod, PatchCon
737734
738735 Command cmd = CommandParser . Parse ( modVal . name , out string valName ) ;
739736
737+ Operator op = OperatorParser . Parse ( valName , out valName ) ;
738+
740739 if ( cmd == Command . Special )
741740 {
742- Match assignMatch = parseAssign . Match ( valName ) ;
743- if ( ! assignMatch . Success )
744- {
745- context . progress . Error ( context . patchUrl , "Error - Cannot parse value assigning command: " + valName ) ;
746- continue ;
747- }
748-
749- valName = assignMatch . Groups [ 1 ] . Value ;
750-
751741 ConfigNode . Value val = RecurseVariableSearch ( valName , nodeStack . Push ( mod ) , context ) ;
752742
753743 if ( val == null )
@@ -756,30 +746,30 @@ public static ConfigNode ModifyNode(NodeStack original, ConfigNode mod, PatchCon
756746 continue ;
757747 }
758748
759- if ( assignMatch . Groups [ 2 ] . Success )
749+ if ( op != Operator . Assign )
760750 {
761751 if ( double . TryParse ( modVal . value , NumberStyles . Float , CultureInfo . InvariantCulture . NumberFormat , out double s )
762752 && double . TryParse ( val . value , NumberStyles . Float , CultureInfo . InvariantCulture . NumberFormat , out double os ) )
763753 {
764- switch ( assignMatch . Groups [ 2 ] . Value [ 0 ] )
754+ switch ( op )
765755 {
766- case '*' :
756+ case Operator . Multiply :
767757 val . value = ( os * s ) . ToString ( CultureInfo . InvariantCulture ) ;
768758 break ;
769759
770- case '/' :
760+ case Operator . Divide :
771761 val . value = ( os / s ) . ToString ( CultureInfo . InvariantCulture ) ;
772762 break ;
773763
774- case '+' :
764+ case Operator . Add :
775765 val . value = ( os + s ) . ToString ( CultureInfo . InvariantCulture ) ;
776766 break ;
777767
778- case '-' :
768+ case Operator . Subtract :
779769 val . value = ( os - s ) . ToString ( CultureInfo . InvariantCulture ) ;
780770 break ;
781771
782- case '!' :
772+ case Operator . Exponentiate :
783773 val . value = Math . Pow ( os , s ) . ToString ( CultureInfo . InvariantCulture ) ;
784774 break ;
785775 }
@@ -841,10 +831,6 @@ public static ConfigNode ModifyNode(NodeStack original, ConfigNode mod, PatchCon
841831 if ( newNode . values [ i ] . name == valName )
842832 valCount ++ ;
843833
844- char op = ' ' ;
845- if ( match . Groups [ 5 ] . Success )
846- op = match . Groups [ 5 ] . Value [ 0 ] ;
847-
848834 string varValue ;
849835 switch ( cmd )
850836 {
@@ -1582,7 +1568,7 @@ private static string FindAndReplaceValue(
15821568 ref string valName ,
15831569 string value ,
15841570 ConfigNode newNode ,
1585- char op ,
1571+ Operator op ,
15861572 int index ,
15871573 out ConfigNode . Value origVal ,
15881574 PatchContext context ,
@@ -1611,9 +1597,9 @@ private static string FindAndReplaceValue(
16111597 {
16121598 value = backupValue ;
16131599 oValue = strArray [ posIndex ] ;
1614- if ( op != ' ' )
1600+ if ( op != Operator . Assign )
16151601 {
1616- if ( op == '^' )
1602+ if ( op == Operator . RegexReplace )
16171603 {
16181604 try
16191605 {
@@ -1643,23 +1629,23 @@ private static string FindAndReplaceValue(
16431629 {
16441630 switch ( op )
16451631 {
1646- case '*' :
1632+ case Operator . Multiply :
16471633 value = ( os * s ) . ToString ( CultureInfo . InvariantCulture ) ;
16481634 break ;
16491635
1650- case '/' :
1636+ case Operator . Divide :
16511637 value = ( os / s ) . ToString ( CultureInfo . InvariantCulture ) ;
16521638 break ;
16531639
1654- case '+' :
1640+ case Operator . Add :
16551641 value = ( os + s ) . ToString ( CultureInfo . InvariantCulture ) ;
16561642 break ;
16571643
1658- case '-' :
1644+ case Operator . Subtract :
16591645 value = ( os - s ) . ToString ( CultureInfo . InvariantCulture ) ;
16601646 break ;
16611647
1662- case '!' :
1648+ case Operator . Exponentiate :
16631649 value = Math . Pow ( os , s ) . ToString ( CultureInfo . InvariantCulture ) ;
16641650 break ;
16651651 }
0 commit comments