Neuron®
The Neuron® is the basis for the creation of open and secure federated networks for smart societies.
Loading...
Searching...
No Matches
CreateParser.cs
1using System;
2using System.Collections.Generic;
4
6{
10 public class CreateParser : IKeyWord
11 {
15 public CreateParser()
16 {
17 }
18
22 public string KeyWord => "CREATE";
23
27 public string[] Aliases => null;
28
32 public string[] InternalKeywords => new string[]
33 {
34 "INDEX",
35 "ON"
36 };
37
44 public bool TryParse(ScriptParser Parser, out ScriptNode Result)
45 {
46 Result = null;
47
48 string s = Parser.NextToken().ToUpper();
49 if (s != "INDEX")
50 return false;
51
52 ScriptNode Name = Parser.ParseNoWhiteSpace();
53
54 s = Parser.NextToken().ToUpper();
55 if (s != "ON")
56 return false;
57
58 if (!SelectParser.TryParseSources(Parser, out SourceDefinition Source))
59 return false;
60
61 s = Parser.NextToken();
62 if (s != "(")
63 return false;
64
65 this.ParseList(Parser, out ScriptNode[] Columns, out bool[] Ascending);
66
67 if (Columns.Length == 0)
68 return false;
69
70 if (Parser.NextToken() != ")")
71 return false;
72
73 Result = new CreateIndex(Name, Source, Columns, Ascending, Parser.Start, Parser.Length, Parser.Expression);
74
75 return true;
76 }
77
78 internal void ParseList(ScriptParser Parser, out ScriptNode[] Columns, out bool[] Ascending)
79 {
80 List<ScriptNode> ColumnList = new List<ScriptNode>();
81 List<bool> AscendingList = new List<bool>();
82 string s;
83
84 do
85 {
86 ScriptNode Node = Parser.ParseIf();
87
88 switch (s = Parser.PeekNextToken().ToUpper())
89 {
90 case "ASC":
91 Parser.NextToken();
92 ColumnList.Add(Node);
93 AscendingList.Add(true);
94 s = Parser.PeekNextToken();
95 break;
96
97 case "DESC":
98 Parser.NextToken();
99 ColumnList.Add(Node);
100 AscendingList.Add(false);
101 s = Parser.PeekNextToken();
102 break;
103
104 case ",":
105 Parser.NextToken();
106 ColumnList.Add(Node);
107 AscendingList.Add(true);
108 break;
109
110 default:
111 ColumnList.Add(Node);
112 AscendingList.Add(true);
113 break;
114 }
115 }
116 while (s == ",");
117
118 Columns = ColumnList.ToArray();
119 Ascending = AscendingList.ToArray();
120 }
121
122 }
123}
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:27
string KeyWord
Keyword associated with custom parser.
Definition: CreateParser.cs:22
bool TryParse(ScriptParser Parser, out ScriptNode Result)
Tries to parse a script node.
Definition: CreateParser.cs:44
string[] InternalKeywords
Any keywords used internally by the custom parser.
Definition: CreateParser.cs:32
Abstract base class for source definitions
Interface for keywords with custom parsing.
Definition: IKeyWord.cs:9