1+ using SER . ArgumentSystem . Arguments ;
2+ using SER . ArgumentSystem . BaseArguments ;
3+ using SER . Helpers . Exceptions ;
4+ using SER . MethodSystem . BaseMethods ;
5+ using SER . MethodSystem . MethodDescriptors ;
6+ using SER . MethodSystem . Structures ;
7+ using SER . ValueSystem ;
8+
9+ namespace SER . MethodSystem . Methods . ParsingMethods ;
10+
11+ public class ParseResultMethod : ReturningMethod , ICanError , IReferenceResolvingMethod
12+ {
13+ public override string Description => "Returns information from the parsing result." ;
14+
15+ public override Type [ ] ? ReturnTypes => null ;
16+
17+ public Type ReferenceType => typeof ( ParseResult ) ;
18+
19+ public string [ ] ErrorReasons =>
20+ [
21+ "Tried to access the value when the parsing was not successful"
22+ ] ;
23+
24+ public override Argument [ ] ExpectedArguments =>
25+ [
26+ new ReferenceArgument < ParseResult > ( "parsing result" ) ,
27+ new OptionsArgument ( "info" ,
28+ new ( "success" , "Returns true if the parsing was successful" ) ,
29+ new ( "value" , "The value that got parsed" )
30+ )
31+ ] ;
32+
33+ public override void Execute ( )
34+ {
35+ var parseResult = Args . GetReference < ParseResult > ( "parsing result" ) ;
36+ ReturnValue = Args . GetOption ( "info" ) switch
37+ {
38+ "success" => new BoolValue ( parseResult . Success ) ,
39+ "value" => parseResult . Value ?? throw new ScriptRuntimeError ( ErrorReasons [ 0 ] ) ,
40+ _ => throw new AndrzejFuckedUpException ( )
41+ } ;
42+ }
43+ }
0 commit comments