Neuron®
The Neuron® is the basis for the creation of open and secure federated networks for smart societies.
Loading...
Searching...
No Matches
InsertParser.cs
1using System;
4
6{
10 public class InsertParser : IKeyWord
11 {
15 public InsertParser()
16 {
17 }
18
22 public string KeyWord => "INSERT";
23
27 public string[] Aliases => null;
28
32 public string[] InternalKeywords => new string[]
33 {
34 "LAZY",
35 "INTO",
36 "VALUES",
37 "OBJECT",
38 "OBJECTS"
39 };
40
47 public bool TryParse(ScriptParser Parser, out ScriptNode Result)
48 {
49 Result = null;
50
51 string s = Parser.NextToken().ToUpper();
52 bool Lazy = s == "LAZY";
53
54 if (Lazy)
55 s = Parser.NextToken().ToUpper();
56
57 if (s != "INTO")
58 return false;
59
60 if (!SelectParser.TryParseSources(Parser, out SourceDefinition Source))
61 return false;
62
63 switch (Parser.PeekNextToken().ToUpper())
64 {
65 case "(":
66 Parser.NextToken();
67
68 ScriptNode Node = Parser.ParseList();
69 if (!(Node is ElementList Columns))
70 Columns = new ElementList(new ScriptNode[] { Node }, Node.Start, Node.Length, Node.Expression);
71
72 if (Parser.NextToken() != ")")
73 return false;
74
75 if (string.Compare(Parser.NextToken(), "VALUES", true) != 0)
76 return false;
77
78 if (Parser.NextToken() != "(")
79 return false;
80
81 Node = Parser.ParseList();
82 if (!(Node is ElementList Values))
83 Values = new ElementList(new ScriptNode[] { Node }, Node.Start, Node.Length, Node.Expression);
84
85 if (Values.Elements.Length != Columns.Elements.Length)
86 return false;
87
88 if (Parser.NextToken() != ")")
89 return false;
90
91 Result = new InsertValues(Source, Columns, Values, Lazy, Parser.Start, Parser.Length, Parser.Expression);
92 return true;
93
94 case "SELECT":
95 Node = Parser.ParseStatement();
96 if (!(Node is Select Select))
97 return false;
98
99 Result = new InsertSelect(Source, Select, Lazy, Parser.Start, Parser.Position, Parser.Expression);
100 return true;
101
102 case "OBJECT":
103 case "OBJECTS":
104 Parser.NextToken();
105
106 Node = Parser.ParseList();
107 if (!(Node is ElementList Objects))
108 Objects = new ElementList(new ScriptNode[] { Node }, Node.Start, Node.Length, Node.Expression);
109
110 Result = new InsertObjects(Source, Objects, Lazy, Parser.Start, Parser.Length, Parser.Expression);
111 return true;
112
113 default:
114 return false;
115 }
116 }
117
118 }
119}
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
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...
string NextToken()
Returns the next token to be parsed, and moves the position forward correspondingly....
int Length
Length of script parsed
Definition: ScriptParser.cs:33
int Start
Start position in expression
Definition: ScriptParser.cs:28
int Position
Current parsing position.
Definition: ScriptParser.cs:38
Expression Expression
Expression being parsed.
Definition: ScriptParser.cs:43
ScriptNode ParseList()
Parses an element list.
Represents a list of elements.
Definition: ElementList.cs:15
Executes an INSERT ... OBJECT[S] ... statement against the object database.
Executes an INSERT SELECT statement against the object database.
Definition: InsertSelect.cs:19
Executes an INSERT ... VALUES ... statement against the object database.
Definition: InsertValues.cs:16
bool TryParse(ScriptParser Parser, out ScriptNode Result)
Tries to parse a script node.
Definition: InsertParser.cs:47
string KeyWord
Keyword associated with custom parser.
Definition: InsertParser.cs:22
string[] InternalKeywords
Any keywords used internally by the custom parser.
Definition: InsertParser.cs:32
string[] Aliases
Keyword aliases, if available, null if none.
Definition: InsertParser.cs:27
Executes a SELECT statement against the object database.
Definition: Select.cs:20
Abstract base class for source definitions
Interface for keywords with custom parsing.
Definition: IKeyWord.cs:9