Neuron®
The Neuron® is the basis for the creation of open and secure federated networks for smart societies.
Loading...
Searching...
No Matches
ScriptParser.cs
3
4namespace Waher.Script.Model
5{
9 public class ScriptParser
10 {
11 private readonly Expression expression;
12 private readonly int start;
13
20 {
21 this.start = Start;
22 this.expression = Expression;
23 }
24
28 public int Start => this.start;
29
33 public int Length => this.expression.Position - this.start;
34
38 public int Position => this.expression.Position;
39
43 public Expression Expression => this.expression;
44
49 {
50 get => this.expression.CanSkipWhitespace;
51 set => this.expression.CanSkipWhitespace = value;
52 }
53
59 public char NextChar() => this.expression.NextChar();
60
67 {
68 char ch;
69
70 do
71 {
72 ch = this.NextChar();
73 }
74 while (ch != 0 && char.IsWhiteSpace(ch));
75
76 return ch;
77 }
78
82 public void UndoChar()
83 {
84 this.expression.UndoChar();
85 }
86
92 public string PeekNextChars(int NrChars)
93 {
94 return this.expression.PeekNextChars(NrChars);
95 }
96
102 public bool IsNextChars(string Token)
103 {
104 return this.expression.IsNextChars(Token);
105 }
106
114 public bool IsNextChars(char ch, int Count)
115 {
116 return this.expression.IsNextChars(ch, Count);
117 }
118
122 public void SkipChars(int NrChars)
123 {
124 this.expression.SkipChars(NrChars);
125 }
126
132 public char PeekNextChar() => this.expression.PeekNextChar();
133
139 public string NextToken() => this.expression.NextToken();
140
146 public string PeekNextToken() => this.expression.PeekNextToken();
147
152 public void SkipWhiteSpace() => this.expression.SkipWhiteSpace();
153
159 public ScriptNode AssertOperandNotNull(ScriptNode Node) => this.expression.AssertOperandNotNull(Node);
160
166 public ScriptNode AssertRightOperandNotNull(ScriptNode Node) => this.expression.AssertRightOperandNotNull(Node);
167
172 public ScriptNode ParseSequence() => this.expression.ParseSequence();
173
178 public ScriptNode ParseStatement() => this.expression.ParseStatement(false);
179
184 public ScriptNode ParseList() => this.expression.ParseList();
185
190 public ScriptNode ParseIf() => this.expression.ParseIf();
191
196 public ScriptNode ParseAssignments() => this.expression.ParseAssignments();
197
202 public ScriptNode ParseLambdaExpression() => this.expression.ParseLambdaExpression();
203
208 public ScriptNode ParseEquivalence() => this.expression.ParseEquivalence();
209
214 public ScriptNode ParseOrs() => this.expression.ParseOrs();
215
220 public ScriptNode ParseAnds() => this.expression.ParseAnds();
221
226 public ScriptNode ParseMembership() => this.expression.ParseMembership();
227
232 public ScriptNode ParseComparison() => this.expression.ParseComparison();
233
238 public ScriptNode ParseShifts() => this.expression.ParseShifts();
239
244 public ScriptNode ParseUnions() => this.expression.ParseUnions();
245
250 public ScriptNode ParseIntersections() => this.expression.ParseIntersections();
251
256 public ScriptNode ParseInterval() => this.expression.ParseInterval();
257
262 public ScriptNode ParseTerms() => this.expression.ParseTerms();
263
268 public ScriptNode ParseBinomialCoefficients() => this.expression.ParseBinomialCoefficients();
269
274 public ScriptNode ParseFactors() => this.expression.ParseFactors();
275
280 public ScriptNode ParsePowers() => this.expression.ParsePowers();
281
286 public ScriptNode ParseUnaryPrefixOperator() => this.expression.ParseUnaryPrefixOperator();
287
292 public ScriptNode ParseSuffixOperator() => this.expression.ParseSuffixOperator();
293
298 public Unit ParseUnit(bool PermitPrefix) => this.expression.ParseUnit(PermitPrefix);
299
304 public ScriptNode ParseObject() => this.expression.ParseObject();
305
309 public bool EndOfScript => this.expression.EndOfScript;
310
314 public bool InScript => this.expression.InScript;
315
321 public bool HasCharacters(int NrCharacters) => this.expression.Position <= this.expression.Script.Length - NrCharacters;
322
328 public SyntaxException SyntaxError(string Message)
329 {
330 return new SyntaxException(Message, this.Position, this.expression.Script);
331 }
332 }
333}
Class managing a script expression.
Definition: Expression.cs:39
Base class for all nodes in a parsed script tree.
Definition: ScriptNode.cs:69
Script parser, for custom parsers.
Definition: ScriptParser.cs:10
SyntaxException SyntaxError(string Message)
Returns a Syntax Error Exception object.
ScriptNode ParseAssignments()
Parses an assignment.
ScriptNode ParseIntersections()
Parses intersections.
ScriptNode ParseStatement()
Parses a statement.
string PeekNextToken()
Returns the next token to be parsed, without moving the position forward. If at the end of the expres...
ScriptNode ParsePowers()
Parses powers.
bool HasCharacters(int NrCharacters)
If there are a given number of characters left to parse.
bool IsNextChars(string Token)
If the next characters to be parsed is a given token.
ScriptNode ParseFactors()
Parses factors.
string NextToken()
Returns the next token to be parsed, and moves the position forward correspondingly....
ScriptNode ParseLambdaExpression()
Parses a lambda expression.
ScriptNode ParseBinomialCoefficients()
Parses binomial coefficients.
ScriptNode ParseTerms()
Parses terms.
int Length
Length of script parsed
Definition: ScriptParser.cs:33
ScriptNode ParseOrs()
Parses ORs.
ScriptNode ParseInterval()
Parses an interval.
ScriptNode ParseMembership()
Parses a membership operator.
ScriptNode AssertOperandNotNull(ScriptNode Node)
Throws an exception if an operand is not null.
ScriptNode ParseEquivalence()
Parses an equivalence.
int Start
Start position in expression
Definition: ScriptParser.cs:28
int Position
Current parsing position.
Definition: ScriptParser.cs:38
ScriptNode ParseComparison()
Parses a comparison.
ScriptNode ParseUnions()
Parses unions.
ScriptNode ParseIf()
Parses a conditional statement.
bool InScript
If position is in script.
ScriptNode ParseUnaryPrefixOperator()
Parses unary prefix operatorrs.
Expression Expression
Expression being parsed.
Definition: ScriptParser.cs:43
void UndoChar()
Undoes a character in the parsing of an expression.
Definition: ScriptParser.cs:82
Unit ParseUnit(bool PermitPrefix)
Parses a unit.
string PeekNextChars(int NrChars)
Returns the next given number of characters to be parsed, without moving the position forward one cha...
Definition: ScriptParser.cs:92
void SkipChars(int NrChars)
Skips a predefined number of characters.
char PeekNextChar()
Returns the next character to be parsed, without moving the position forward one character....
ScriptNode ParseSuffixOperator()
Parses suffix operators.
bool CanSkipWhitespace
If whitespace can be skipped (true), or if it has semantic meaning to the custom parser (false).
Definition: ScriptParser.cs:49
bool EndOfScript
If position is at end of script.
void SkipWhiteSpace()
If current position is whitespace, moves the current position forward to the first non-whitespace cha...
char NextChar()
Returns the next character to be parsed, and moves the position forward one character....
ScriptNode AssertRightOperandNotNull(ScriptNode Node)
Throws an exception if a right-hand side operand is not null.
ScriptNode ParseObject()
Parses an object ex nihilo.
ScriptNode ParseSequence()
Parses a sequence of statements.
ScriptNode ParseShifts()
Parses a shift operator.
char NextNonWhitespaceChar()
Returns the next non-whitespace character to be parsed, and moves the position forward accordingly....
Definition: ScriptParser.cs:66
bool IsNextChars(char ch, int Count)
If the next characters to be parsed is a given token consisting of a character being repeated a given...
ScriptNode ParseList()
Parses an element list.
ScriptNode ParseAnds()
Parses ANDs.
Represents a unit.
Definition: Unit.cs:15