Skip to content

Commit 91b6790

Browse files
Create ParseResultMethod.cs
1 parent ff195fb commit 91b6790

File tree

1 file changed

+43
-0
lines changed

1 file changed

+43
-0
lines changed
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
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

Comments
 (0)