BadScript 2
Loading...
Searching...
No Matches
BadInExpression.cs
Go to the documentation of this file.
6
8
13{
20 public BadInExpression(BadExpression left, BadExpression right, BadSourcePosition position) : base(
21 left,
22 right,
23 position
24 ) { }
25
27 protected override IEnumerable<BadObject> InnerExecute(BadExecutionContext context)
28 {
30 BadObject right = BadObject.Null;
31
32 foreach (BadObject o in Left.Execute(context))
33 {
34 left = o;
35
36 yield return o;
37 }
38
39 left = left.Dereference();
40
41 foreach (BadObject o in Right.Execute(context))
42 {
43 right = o;
44
45 yield return o;
46 }
47
48 right = right.Dereference();
49
50 foreach (BadObject? o in InWithOverride(context, left, right, Position))
51 {
52 yield return o;
53 }
54 }
55
63 public static BadObject In(BadExecutionContext ctx, BadObject left, BadObject right)
64 {
65 if (left is not IBadString s)
66 {
67 throw BadRuntimeException.Create(ctx.Scope, "Invalid Property Key");
68 }
69
70 return right.HasProperty(s.Value, ctx.Scope);
71 }
72
81 public static IEnumerable<BadObject> InWithOverride(
82 BadExecutionContext context,
83 BadObject left,
84 BadObject right,
85 BadSourcePosition position)
86 {
88 {
90 right,
91 left,
92 context,
94 position
95 ))
96 {
97 yield return o;
98 }
99 }
100 else
101 {
102 yield return In(context, left, right);
103 }
104 }
105
107 protected override string GetSymbol()
108 {
109 return "in";
110 }
111}
Describes a specific position inside a source file.
Contains Static Data for the BadScript Language.
Base Implementation for all Expressions used inside the Script.
static IEnumerable< BadObject > ExecuteOperatorOverride(BadObject left, BadObject right, BadExecutionContext context, string name, BadSourcePosition position)
Helper function that executes an operator override function if implemented.
BadSourcePosition Position
The source Position of the Expression.
IEnumerable< BadObject > Execute(BadExecutionContext context)
Evaluates the Expression within the current Execution Context.
Base Implementation of all Binary Expressions.
BadExpression Right
Right side of the Expression.
Implements the 'in' operator. The 'in' operator is used to check if a key is present in an instance o...
static IEnumerable< BadObject > InWithOverride(BadExecutionContext context, BadObject left, BadObject right, BadSourcePosition position)
Implements the logic of the 'in' operator but checks for an operator override first.
BadInExpression(BadExpression left, BadExpression right, BadSourcePosition position)
Constructor for the 'in' operator.
static BadObject In(BadExecutionContext ctx, BadObject left, BadObject right)
Implements the logic of the 'in' operator.
override IEnumerable< BadObject > InnerExecute(BadExecutionContext context)
The Execution Context. Every execution of a script needs a context the script is running in....
BadScope Scope
The Root Scope of the Context.
static BadRuntimeException Create(BadScope? scope, string message)
Creates a new BadScriptException.
The Base Class for all BadScript Objects.
Definition BadObject.cs:14
virtual bool HasProperty(string propName, BadScope? caller=null)
Returns true if the object contains a given property or there exists an extension for the current Ins...
Definition BadObject.cs:118
static readonly BadObject Null
The Null Value for the BadScript Language.
Definition BadObject.cs:28
Implements the Interface for Native Strings.
Definition IBadString.cs:7
Contains Shared Data Structures and Functionality.
Contains the Binary Expressions for the BadScript2 Language.
Contains the Error Objects for the BadScript2 Language.
Contains the Native Runtime Objects.
Definition BadBoolean.cs:6
Contains the Runtime Objects.
Definition BadArray.cs:10
Contains the Runtime Implementation.