BadScript 2
Loading...
Searching...
No Matches
BadFormattedStringExpression.cs
Go to the documentation of this file.
6
11
16{
20 private readonly BadExpression[] m_Expressions;
21
28 public BadFormattedStringExpression(BadExpression[] exprs, string str, BadSourcePosition position) : base(
29 str,
30 position
31 )
32 {
33 m_Expressions = exprs;
34 }
35
39 public IEnumerable<BadExpression> Expressions => m_Expressions;
40
44 public int ExpressionCount => m_Expressions.Length;
45
47 public override void Optimize()
48 {
49 for (int i = 0; i < m_Expressions.Length; i++)
50 {
52 }
53 }
54
56 protected override IEnumerable<BadObject> InnerExecute(BadExecutionContext context)
57 {
58 if (m_Expressions.Length == 0)
59 {
60 yield return Value;
61
62 yield break;
63 }
64
65 List<BadObject> objs = new List<BadObject>();
66
67 foreach (BadExpression expr in m_Expressions)
68 {
70
71 foreach (BadObject o in expr.Execute(context))
72 {
73
74 obj = o;
75
76 yield return o;
77 }
78
79 objs.Add(obj.Dereference());
80 }
81
82 yield return string.Format(Value, objs.Cast<object?>().ToArray());
83 }
84
86 public override IEnumerable<BadExpression> GetDescendants()
87 {
88 foreach (BadExpression expr in m_Expressions)
89 {
90 foreach (BadExpression e in expr.GetDescendantsAndSelf())
91 {
92 yield return e;
93 }
94 }
95
96 foreach (BadExpression e in base.GetDescendants())
97 {
98 yield return e;
99 }
100 }
101}
Describes a specific position inside a source file.
static BadExpression Optimize(BadExpression expr)
Optimizes the given expression.
Base Implementation for all Expressions used inside the Script.
IEnumerable< BadExpression > GetDescendantsAndSelf()
Returns all Descendants of the Expression and the Expression itself.
IEnumerable< BadExpression > GetDescendants()
Returns all Descendants of the Expression.
IEnumerable< BadObject > Execute(BadExecutionContext context)
Evaluates the Expression within the current Execution Context.
override IEnumerable< BadObject > InnerExecute(BadExecutionContext context)
BadFormattedStringExpression(BadExpression[] exprs, string str, BadSourcePosition position)
Constructor of the Formatted String Expression.
IEnumerable< BadExpression > Expressions
The Expressions that will be evaluated during the creation of the formatted string.
override void Optimize()
Uses the Constant Folding Optimizer to optimize the expression.
readonly BadExpression[] m_Expressions
The Expressions that will be evaluated during the creation of the formatted string.
The Execution Context. Every execution of a script needs a context the script is running in....
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
Contains Shared Data Structures and Functionality.
Contains the BadScript2 Constant Folding Optimizations.
Contains the Constant Expressions for the BadScript2 Language.
Contains the Variable Expressions for the BadScript2 Language.
Contains the Runtime Objects.
Definition BadArray.cs:10
Contains the Runtime Implementation.