Neuron®
The Neuron® is the basis for the creation of open and secure federated networks for smart societies.
Loading...
Searching...
No Matches
CreateParser.cs
3
5{
9 public class CreateParser : IKeyWord
10 {
14 public CreateParser()
15 {
16 }
17
21 public string KeyWord => "CREATE";
22
26 public string[] Aliases => null;
27
31 public string[] InternalKeywords => new string[]
32 {
33 "INDEX",
34 "ON"
35 };
36
43 public bool TryParse(ScriptParser Parser, out ScriptNode Result)
44 {
45 Result = null;
46
47 string s = Parser.NextToken().ToUpper();
48 if (s != "INDEX")
49 return false;
50
51 ScriptNode Name = Parser.ParseNoWhiteSpace();
52
53 s = Parser.NextToken().ToUpper();
54 if (s != "ON")
55 return false;
56
57 if (!SelectParser.TryParseSources(Parser, out SourceDefinition Source))
58 return false;
59
60 s = Parser.NextToken();
61 if (s != "(")
62 return false;
63
64 this.ParseList(Parser, out ScriptNode[] Columns, out bool[] Ascending);
65
66 if (Columns.Length == 0)
67 return false;
68
69 if (Parser.NextToken() != ")")
70 return false;
71
72 Result = new CreateIndex(Name, Source, Columns, Ascending, Parser.Start, Parser.Length, Parser.Expression);
73
74 return true;
75 }
76
77 internal void ParseList(ScriptParser Parser, out ScriptNode[] Columns, out bool[] Ascending)
78 {
80 ChunkedList<bool> AscendingList = new ChunkedList<bool>();
81 string s;
82
83 do
84 {
85 ScriptNode Node = Parser.ParseIf();
86
87 switch (s = Parser.PeekNextToken().ToUpper())
88 {
89 case "ASC":
90 Parser.NextToken();
91 ColumnList.Add(Node);
92 AscendingList.Add(true);
93 s = Parser.PeekNextToken();
94 break;
95
96 case "DESC":
97 Parser.NextToken();
98 ColumnList.Add(Node);
99 AscendingList.Add(false);
100 s = Parser.PeekNextToken();
101 break;
102
103 case ",":
104 Parser.NextToken();
105 ColumnList.Add(Node);
106 AscendingList.Add(true);
107 break;
108
109 default:
110 ColumnList.Add(Node);
111 AscendingList.Add(true);
112 break;
113 }
114 }
115 while (s == ",");
116
117 Columns = ColumnList.ToArray();
118 Ascending = AscendingList.ToArray();
119 }
120
121 }
122}
A chunked list is a linked list of chunks of objects of type T .
Definition: ChunkedList.cs:54
void Add(T Item)
Adds an item to the collection.
Definition: ChunkedList.cs:272
T[] ToArray()
Returns an array containing all elements of the collection.
Base class for all nodes in a parsed script tree.
Definition: ScriptNode.cs:69
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....
int Length
Length of script parsed
Definition: ScriptParser.cs:33
int Start
Start position in expression
Definition: ScriptParser.cs:28
ScriptNode ParseIf()
Parses a conditional statement.
Expression Expression
Expression being parsed.
Definition: ScriptParser.cs:43
Executes an CREATE INDEX ... ON ... (...) statement against the object database.
Definition: CreateIndex.cs:13
string[] Aliases
Keyword aliases, if available, null if none.
Definition: CreateParser.cs:26
string KeyWord
Keyword associated with custom parser.
Definition: CreateParser.cs:21
bool TryParse(ScriptParser Parser, out ScriptNode Result)
Tries to parse a script node.
Definition: CreateParser.cs:43
string[] InternalKeywords
Any keywords used internally by the custom parser.
Definition: CreateParser.cs:31
Abstract base class for source definitions
Interface for keywords with custom parsing.
Definition: IKeyWord.cs:9