Neuron®
The Neuron® is the basis for the creation of open and secure federated networks for smart societies.
Loading...
Searching...
No Matches
RecordParser.cs
3
5{
9 public enum RecordOperation
10 {
14 New,
15
19 Update,
20
24 Delete
25 }
26
30 public class RecordParser : IKeyWord
31 {
35 public RecordParser()
36 {
37 }
38
42 public string KeyWord => "RECORD";
43
47 public string[] Aliases => null;
48
52 public string[] InternalKeywords => new string[]
53 {
54 "INTO",
55 "NEW",
56 "UPDATE",
57 "DELETE",
58 "OBJECT",
59 "OBJECTS"
60 };
61
68 public bool TryParse(ScriptParser Parser, out ScriptNode Result)
69 {
70 Result = null;
71
72 string s = Parser.NextToken().ToUpper();
73
74 if (s != "INTO")
75 return false;
76
77 if (!SelectParser.TryParseSources(Parser, out SourceDefinition Source))
78 return false;
79
80 RecordOperation? Operation = null;
81
82 while (true)
83 {
84 switch (Parser.PeekNextToken().ToUpper())
85 {
86 case "NEW":
87 if (Operation.HasValue)
88 return false;
89
90 Parser.NextToken();
91 Operation = RecordOperation.New;
92 continue;
93
94 case "UPDATE":
95 if (Operation.HasValue)
96 return false;
97
98 Parser.NextToken();
99 Operation = RecordOperation.Update;
100 continue;
101
102 case "DELETE":
103 if (Operation.HasValue)
104 return false;
105
106 Parser.NextToken();
107 Operation = RecordOperation.Delete;
108 continue;
109
110 case "OBJECT":
111 case "OBJECTS":
112 Parser.NextToken();
113
114 ScriptNode Node = Parser.ParseList();
115 if (!(Node is ElementList Objects))
116 Objects = new ElementList(new ScriptNode[] { Node }, Node.Start, Node.Length, Node.Expression);
117
118 Result = new RecordObjects(Source, Operation ?? RecordOperation.New,
119 Objects, Parser.Start, Parser.Length, Parser.Expression);
120 return true;
121
122 default:
123 return false;
124 }
125 }
126 }
127
128 }
129}
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....
int Length
Length of script parsed
Definition: ScriptParser.cs:33
int Start
Start position in expression
Definition: ScriptParser.cs:28
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 a DELETE statement against the object database.
Definition: Delete.cs:13
bool TryParse(ScriptParser Parser, out ScriptNode Result)
Tries to parse a script node.
Definition: RecordParser.cs:68
string[] Aliases
Keyword aliases, if available, null if none.
Definition: RecordParser.cs:47
string[] InternalKeywords
Any keywords used internally by the custom parser.
Definition: RecordParser.cs:52
string KeyWord
Keyword associated with custom parser.
Definition: RecordParser.cs:42
Executes an RECORD ... OBJECT[S] ... statement against the ledger.
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
RecordOperation
Ledger operation to record.
Definition: RecordParser.cs:10