18 using System.Collections.Generic;
19 using System.Collections.ObjectModel;
26 namespace Deveel.Data.Sql.Parser {
34 ChildNodes =
new ReadOnlyCollection<ISqlNode>(
new ISqlNode[0]);
35 Tokens =
new ReadOnlyCollection<Token>(
new Token[0]);
42 protected ISqlNode Parent {
get;
private set; }
48 protected string NodeName {
get;
private set; }
55 protected IEnumerable<ISqlNode> ChildNodes {
get;
private set; }
63 protected IEnumerable<Token> Tokens {
get;
private set; }
66 void IAstNodeInit.Init(AstContext context, ParseTreeNode parseNode) {
67 NodeName = parseNode.Term == null ? GetType().Name : parseNode.Term.Name;
69 var tokens =
new List<Token>();
71 var iToken = parseNode.FindToken();
73 tokens.Add(
new Token(iToken.Location.Column, iToken.Location.Line, iToken.Text, iToken.Value));
76 var childNodes =
new List<ISqlNode>();
78 foreach (var childNode
in parseNode.ChildNodes) {
80 if (childNode.Term is KeyTerm) {
81 var childIToken = childNode.FindToken();
82 child =
new SqlKeyNode(
new Token(childIToken.Location.Column, childIToken.Location.Line, childIToken.Text, childIToken.Value));
87 child = OnChildNode(child);
91 (child as ISqlChildNode).SetParent(
this);
93 childNodes.Add(child);
94 tokens.AddRange(child.
Tokens);
98 ChildNodes = childNodes.ToArray();
99 Tokens = tokens.ToArray();
105 get {
return NodeName; }
109 get {
return Parent; }
113 get {
return ChildNodes; }
117 get {
return Tokens; }
Defines the contract for nodes in an AST model for a SQL grammar analysis and parsing.
Represents a keyword found during the compilation of a source text.
virtual ISqlNode OnChildNode(ISqlNode node)
During the initialization of the node from the parser, this method is called for every child node add...
string NodeName
Gets the name of the node analyzed from the parser.
virtual void OnNodeInit()
After the initialization of the node from the parser, this method is invoked to let the specific init...
This is a single token within a string parsed.
IEnumerable< ISqlNode > ChildNodes
Gets a read-only enumeration of the children nodes, if any.
IEnumerable< Token > Tokens
Gets an enumeration of the tokens composing the this node.
ISqlNode Parent
Gets a reference to the parent ISqlNode, if any.
The default implementation of ISqlNode, that is a node in the text analysis parsing of SQL commands...