BadScript 2
Loading...
Searching...
No Matches
BadLinqCommon.cs
Go to the documentation of this file.
1using System.Collections;
2
11
16
20internal static class BadLinqCommon
21{
26
32 public static (string varName, string query) ParsePredicate(string query)
33 {
34 string[] parts = query.Split(
35 new[]
36 {
37 "=>",
38 },
39 StringSplitOptions.RemoveEmptyEntries
40 );
41 string varName = parts[0].Trim();
42 string queryStr = parts[1].Trim();
43
44 return (varName, queryStr);
45 }
46
55 public static bool InnerWhere(string varName, BadExpression query, object? o)
56 {
58
59 if (o is BadObject bo)
60 {
62 }
63 else
64 {
66 }
67
69
70 foreach (BadObject o1 in query.Execute(ctx))
71 {
72 r = o1;
73 }
74
75 r = r.Dereference();
76
77 if (r is not IBadBoolean b)
78 {
79 throw new Exception($"Error in LINQ Where: {varName} => {query} : {r.ToSafeString()} is not a boolean");
80 }
81
82 return b.Value;
83 }
84
90 public static object?[] ToArray(this IEnumerable enumerable)
91 {
92 return Enumerable.ToArray(enumerable.Cast<object?>());
93 }
94
100 public static IEnumerable<BadExpression> Parse(string src)
101 {
102 return new BadSourceParser(new BadSourceReader("<nofile>", src + ';'), BadOperatorTable.Instance).Parse();
103 }
104}
The Parser of the Language. It turns Source Code into an Expression Tree.
static IEnumerable< BadExpression > Parse(string fileName, string source)
Parses a BadExpression from the Source Reader.
Base Implementation for all Expressions used inside the Script.
Implements the Operator Table used by the Parser.
static BadOperatorTable Instance
The Operator Table Instance.
Implements the Source Code Reader.
The Execution Context. Every execution of a script needs a context the script is running in....
BadScope Scope
The Root Scope of the Context.
Provides settings for creating a new BadExecutionContext
BadExecutionContext Build()
Builds a new BadExecutionContext with the options provided in this Options Instance.
void DefineVariable(string name, BadObject value, BadScope? caller=null, BadPropertyInfo? info=null, BadObject[]? attributes=null)
Defines a new Variable in the current scope.
Definition BadScope.cs:929
The Base Class for all BadScript Objects.
Definition BadObject.cs:14
static bool CanWrap(object? o)
Returns true if the given object cam be wrapped.
Definition BadObject.cs:51
static readonly BadObject Null
The Null Value for the BadScript Language.
Definition BadObject.cs:28
Implements Common Functionality to parse Linq Queries in BadScript2.
static string varName
Parses a Predicate Query into a Variable Name and a Query Expression.
static string string query ParsePredicate(string query)
static IEnumerable< BadExpression > Parse(string src)
Parses the given source into an IEnumerable of BadExpressions.
static bool InnerWhere(string varName, BadExpression query, object? o)
The Where Lamda Function for the Linq Extensions.
static readonly BadExecutionContextOptions PredicateContextOptions
The Predicate Context Options for the Linq Extensions.
static ? object[] ToArray(this IEnumerable enumerable)
Materializes the given IEnumerable into an Array.
Implements the Interface for Native Boolean.
Definition IBadBoolean.cs:7
Contains the Expressions for the BadScript2 Language.
Contains the Operators for the BadScript2 Language.
Contains the Parser for the BadScript2 Language.
Contains the Source Reader for the BadScript2 Language.
Contains the Classes for Reflection Objects.
Contains the Native Runtime Objects.
Definition BadBoolean.cs:6
Contains the Runtime Objects.
Definition BadArray.cs:10
Contains the Runtime Implementation.
Contains the Linq Implementation and Extensions.