BadScript 2
Loading...
Searching...
No Matches
BadRangeExpression.cs
Go to the documentation of this file.
7
9
15{
23 left,
24 right,
25 position
26 ) { }
27
29 protected override IEnumerable<BadObject> InnerExecute(BadExecutionContext context)
30 {
32 BadObject right = BadObject.Null;
33
34 foreach (BadObject o in Left.Execute(context))
35 {
36 left = o;
37
38 yield return o;
39 }
40
41 foreach (BadObject o in Right.Execute(context))
42 {
43 right = o;
44
45 yield return o;
46 }
47
48 left = left.Dereference();
49 right = right.Dereference();
50
51 if (left is not IBadNumber lNum)
52 {
53 throw new BadRuntimeException("Left side of range operator is not a number", Position);
54 }
55
56 if (right is not IBadNumber rNum)
57 {
58 throw new BadRuntimeException("Right side of range operator is not a number", Position);
59 }
60
61 if (lNum.Value > rNum.Value)
62 {
63 throw new BadRuntimeException("Left side of range operator is greater than right side", Position);
64 }
65
66 yield return new BadInteropEnumerator(Range(lNum.Value, rNum.Value).GetEnumerator());
67 }
68
75 public static IEnumerable<BadObject> Range(decimal from, decimal to)
76 {
77 for (decimal i = from; i < to; i++)
78 {
79 yield return BadObject.Wrap(i);
80 }
81 }
82
84 protected override string GetSymbol()
85 {
86 return "..";
87 }
88}
Describes a specific position inside a source file.
Base Implementation for all Expressions used inside the Script.
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 Range Expression START..END.
static IEnumerable< BadObject > Range(decimal from, decimal to)
Returns a range of numbers.
BadRangeExpression(BadExpression left, BadExpression right, BadSourcePosition position)
Constructor of the Range Expression.
override IEnumerable< BadObject > InnerExecute(BadExecutionContext context)
The Execution Context. Every execution of a script needs a context the script is running in....
Implements a simple wrapper for C# IEnumerators to be used in BS2.
The Base Class for all BadScript Objects.
Definition BadObject.cs:14
static readonly BadObject Null
The Null Value for the BadScript Language.
Definition BadObject.cs:28
Implements the Interface for Native Numbers.
Definition IBadNumber.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 Interop Abstractions and Implementations 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.