@@ -103,6 +103,8 @@ private MethodScriptCompiler() {
103103
104104 private static final Pattern VAR_PATTERN = Pattern .compile ("\\ $[\\ p{L}0-9_]+" );
105105 private static final Pattern IVAR_PATTERN = Pattern .compile (IVariable .VARIABLE_NAME_REGEX );
106+ private static final Pattern NUM_PATTERN = Pattern .compile ("[0-9]+" );
107+ private static final Pattern FUNC_NAME_PATTERN = Pattern .compile ("[_a-zA-Z0-9]+" );
106108
107109 /**
108110 * Lexes the script, and turns it into a token stream.This looks through the script character by character.
@@ -593,7 +595,7 @@ public static TokenStream lex(String script, Environment env, File file,
593595 } else {
594596 // It's not a keyword, but a normal function.
595597 String funcName = buf .toString ();
596- if (funcName .matches ("[_a-zA-Z0-9]+" )) {
598+ if (FUNC_NAME_PATTERN . matcher ( funcName ) .matches ()) {
597599 tokenList .add (new Token (TType .FUNC_NAME , funcName , target ));
598600 } else {
599601 tokenList .add (new Token (TType .UNKNOWN , funcName , target ));
@@ -911,8 +913,7 @@ public static TokenStream lex(String script, Environment env, File file,
911913 if (!prevNonWhitespace .type .isIdentifier () // Don't convert "number/string/var ± ...".
912914 && prevNonWhitespace .type != TType .FUNC_END // Don't convert "func() ± ...".
913915 && prevNonWhitespace .type != TType .RSQUARE_BRACKET // Don't convert "] ± ..." (arrays).
914- && !IVAR_PATTERN .matcher (t .val ()).matches () // Don't convert "± @var".
915- && !VAR_PATTERN .matcher (t .val ()).matches ()) { // Don't convert "± $var".
916+ && NUM_PATTERN .matcher (t .val ()).matches ()) { // Only convert numbers
916917 // It is a negative/positive number: Absorb the sign.
917918 t .value = prev1 .value + t .value ;
918919 it .remove (); // Remove 'prev1'.
@@ -1769,28 +1770,35 @@ public static ParseTree compile(TokenStream stream, Environment environment,
17691770 } catch (ConfigRuntimeException ex ) {
17701771 throw new ConfigCompileException (ex );
17711772 }
1772- if (( c instanceof CInt || c instanceof CDecimal ) && next1 . type == TType . DOT && next2 . type == TType . LIT ) {
1773- // make CDouble/CDecimal here because otherwise Long.parseLong() will remove
1774- // minus zero before decimals and leading zeroes after decimals
1773+ // make CDouble/ CDecimal here because otherwise Long.parseLong() will remove
1774+ // minus zero before decimals and leading zeroes after decimals
1775+ if ( c instanceof CInt && next1 . type == TType . DOT && next2 . type == TType . LIT ) {
17751776 try {
1776- if (t .value .startsWith ("0m" )) {
1777- // CDecimal
1778- String neg = "" ;
1779- if (prev1 .value .equals ("-" )) {
1780- neg = "-" ;
1781- }
1782- c = new CDecimal (neg + t .value .substring (2 ) + '.' + next2 .value , t .target );
1783- } else {
1784- // CDouble
1785- c = new CDouble (Double .parseDouble (t .val () + '.' + next2 .val ()), t .target );
1786- }
1777+ c = new CDouble (Double .parseDouble (t .val () + '.' + next2 .val ()), t .target );
17871778 i += 2 ;
17881779 } catch (NumberFormatException e ) {
17891780 // Not a double
17901781 }
1782+ constructCount .peek ().incrementAndGet ();
1783+ } else if (c instanceof CDecimal ) {
1784+ String neg = "" ;
1785+ if (prev1 .value .equals ("-" )) {
1786+ // Absorb sign unless neg() becomes compatible with CDecimal
1787+ neg = "-" ;
1788+ tree .removeChildAt (tree .getChildren ().size () - 1 );
1789+ } else {
1790+ constructCount .peek ().incrementAndGet ();
1791+ }
1792+ if (next1 .type == TType .DOT && next2 .type == TType .LIT ) {
1793+ c = new CDecimal (neg + t .value .substring (2 ) + '.' + next2 .value , t .target );
1794+ i += 2 ;
1795+ } else {
1796+ c = new CDecimal (neg + t .value .substring (2 ), t .target );
1797+ }
1798+ } else {
1799+ constructCount .peek ().incrementAndGet ();
17911800 }
17921801 tree .addChild (new ParseTree (c , fileOptions ));
1793- constructCount .peek ().incrementAndGet ();
17941802 } else if (t .type .equals (TType .STRING ) || t .type .equals (TType .COMMAND )) {
17951803 tree .addChild (new ParseTree (new CString (t .val (), t .target ), fileOptions ));
17961804 constructCount .peek ().incrementAndGet ();
0 commit comments