Example #1
0
            /// <summary>
            /// Adds tokens to this node. The first item in the sequence should be identical to the current token of this node (if there is one)
            /// </summary>
            /// <param name="seq"></param>
            internal void AddTokens(IEnumerable<Token> seq, Token[] original) {

                // first addition
                var item = seq.FirstOrDefault();
                if (item == null) {
                    return;
                }

#if DEBUG
                // if we've already got a token it should be the same as this being added
                if (this.Token != null && !this.Token.Equals(item)) {
                    throw new ArgumentException();
                }
#endif

                this.Token = item;
                if (children.Count == 0) {
                    TokenTreeNode kid = new TokenTreeNode();
                    kid.AddTokens(seq.Skip(1), original);
                    if (kid.Token != null) {
                        children.Add(kid);
                    } else {
                        // this is a terminal for this particular sequence
                        this.fullSequence = original;
                    }
                } else {
                    TokenTreeNode match = this.FindMatch(seq.Skip(1).FirstOrDefault());
                    if (match == null) {
                        // no matching child
                        TokenTreeNode t = new TokenTreeNode();
                        t.AddTokens(seq.Skip(1), original);
                        if (t.Token != null) {
                            this.children.Add(t);
                        } else {
                            // this is a terminal for this particular sequence
                            this.fullSequence = original;
                        }
                    } else {
                        match.AddTokens(seq.Skip(1), original);
                    }
                }
            }
Example #2
0
 internal void AddTokens(Token[] seq) {
     if (seq.Length < 1) {
         throw new ArgumentException();
     }
     if (root == null) {
         this.root = new TokenTreeNode();
         TokenTreeNode t = new TokenTreeNode();
         t.AddTokens(seq, seq);
         root.AddChild(t);
     } else {
         TokenTreeNode match = this.root.FindMatch(seq[0]);
         if (match == null) {
             // no matching child
             TokenTreeNode t = new TokenTreeNode();
             t.AddTokens(seq, seq);
             if (t.Token != null) {
                 root.AddChild(t);
             }
         } else {
             match.AddTokens(seq, seq);
         }
     }
     count++;
 }
Example #3
0
 internal TokenTreeNode(string token, TokenTreeNode parent)
 {
     this.Token  = token;
     this.Parent = parent;
 }
Example #4
0
 internal TokenTree()
 {
     this._root = new TokenTreeNode(string.Empty, null);
 }
Example #5
0
 public TestTreeBuilder WithTag(TokenTreeNode tag)
 {
     node.Children.Add(tag);
     return(this);
 }
Example #6
0
 public TestTreeBuilder(TokenTreeNode node)
 {
     this.node = node;
 }
Example #7
0
 internal void AddChild(TokenTreeNode node) {
     this.children.Add(node);
 }