File tree Expand file tree Collapse file tree 1 file changed +16
-7
lines changed
Expand file tree Collapse file tree 1 file changed +16
-7
lines changed Original file line number Diff line number Diff line change 1- using SER . ScriptSystem ;
1+ using SER . Helpers . ResultSystem ;
2+ using SER . ScriptSystem ;
23using SER . ValueSystem ;
34
45namespace SER . TokenSystem . Tokens ;
@@ -7,19 +8,27 @@ public class NumberToken : LiteralValueToken<NumberValue>
78{
89 protected override IParseResult InternalParse ( Script scr )
910 {
10- if ( decimal . TryParse ( RawRep , out var value ) )
11+ if ( TryParse ( RawRep ) . WasSuccessful ( out var value ) )
1112 {
1213 Value = value ;
1314 return new Success ( ) ;
1415 }
1516
16- if ( RawRep . EndsWith ( "%" ) &&
17- decimal . TryParse ( RawRep . Substring ( 0 , RawRep . Length - 1 ) , out var value2 ) )
17+ return new Ignore ( ) ;
18+ }
19+
20+ public static TryGet < decimal > TryParse ( string stringRep )
21+ {
22+ if ( decimal . TryParse ( stringRep , out var value ) )
1823 {
19- Value = value2 / 100 ;
20- return new Success ( ) ;
24+ return value ;
2125 }
2226
23- return new Ignore ( ) ;
27+ if ( stringRep . EndsWith ( "%" ) && decimal . TryParse ( stringRep . TrimEnd ( '%' ) , out value ) )
28+ {
29+ return value / 100 ;
30+ }
31+
32+ return $ "Value '{ stringRep } ' is not a valid number";
2433 }
2534}
You can’t perform that action at this time.
0 commit comments