Neuron®
The Neuron® is the basis for the creation of open and secure federated networks for smart societies.
Loading...
Searching...
No Matches
UpdateParser.cs
1using System;
2using System.Collections.Generic;
7
9{
13 public class UpdateParser : IKeyWord
14 {
18 public UpdateParser()
19 {
20 }
21
25 public string KeyWord => "UPDATE";
26
30 public string[] Aliases => null;
31
35 public string[] InternalKeywords => new string[]
36 {
37 "LAZY",
38 "SET",
39 "WHERE"
40 };
41
48 public bool TryParse(ScriptParser Parser, out ScriptNode Result)
49 {
50 Result = null;
51
52 string s = Parser.PeekNextToken().ToUpper();
53 bool Lazy = s == "LAZY";
54
55 if (Lazy)
56 Parser.NextToken();
57
58 if (!SelectParser.TryParseSources(Parser, out SourceDefinition Source))
59 return false;
60
61 s = Parser.NextToken().ToUpper();
62 if (s != "SET")
63 return false;
64
65 List<Assignment> SetOperations = new List<Assignment>();
66 ScriptNode Node = Parser.ParseList();
67
68 if (!(Node is ElementList List))
69 List = new ElementList(new ScriptNode[] { Node }, Node.Start, Node.Length, Node.Expression);
70
71 foreach (ScriptNode Operation in List.Elements)
72 {
73 if (Operation is EqualTo EqualTo)
74 {
76 SetOperations.Add(new Assignment(Ref.VariableName, EqualTo.RightOperand, EqualTo.Start, EqualTo.Length, EqualTo.Expression));
77 else
78 return false;
79 }
80 else if (Operation is Assignment Assignment)
81 SetOperations.Add(Assignment);
82 else
83 return false;
84 }
85
86 ScriptNode Where = null;
87
88 s = Parser.PeekNextToken().ToUpper();
89 if (s == "WHERE")
90 {
91 Parser.NextToken();
92 Where = Parser.ParseOrs();
93 }
94
95 Result = new Update(Source, SetOperations.ToArray(), Where, Lazy, Parser.Start, Parser.Length, Parser.Expression);
96
97 return true;
98 }
99
100 }
101}
ScriptNode RightOperand
Right operand.
ScriptNode LeftOperand
Left operand.
Base class for all nodes in a parsed script tree.
Definition: ScriptNode.cs:69
int Length
Length of expression covered by node.
Definition: ScriptNode.cs:101
Expression Expression
Expression of which the node is a part.
Definition: ScriptNode.cs:177
int Start
Start position in script expression.
Definition: ScriptNode.cs:92
Script parser, for custom parsers.
Definition: ScriptParser.cs:10
string PeekNextToken()
Returns the next token to be parsed, without moving the position forward. If at the end of the expres...
string NextToken()
Returns the next token to be parsed, and moves the position forward correspondingly....
ScriptNode ParseList()
Parses an element list.
Represents a variable reference.
Represents a list of elements.
Definition: ElementList.cs:15
string[] InternalKeywords
Any keywords used internally by the custom parser.
Definition: UpdateParser.cs:35
string KeyWord
Keyword associated with custom parser.
Definition: UpdateParser.cs:25
string[] Aliases
Keyword aliases, if available, null if none.
Definition: UpdateParser.cs:30
bool TryParse(ScriptParser Parser, out ScriptNode Result)
Tries to parse a script node.
Definition: UpdateParser.cs:48
Abstract base class for source definitions
Executes an UPDATE statement against the object database.
Definition: Update.cs:16
Interface for keywords with custom parsing.
Definition: IKeyWord.cs:9