private static void ToGroupedTokenString(IParseTreeNode node, StringBuilder builder, bool mayNeedParens)
 {
     if (node.Symbol is Token)
     {
         builder.Append(node.Symbol.Name);
     }
     else
     {
         var writeParens = mayNeedParens && node.Children.Count > 1;
         if (writeParens)
         {
             builder.Append('(');
         }
         for (var i = 0; i < node.Children.Count; ++i)
         {
             if (i > 0)
             {
                 builder.Append(' ');
             }
             ToGroupedTokenString(node.Children[i], builder, mayNeedParens: node.Children.Count > 1);
         }
         if (writeParens)
         {
             builder.Append(')');
         }
     }
 }
        private static string ToGroupedTokenString(IParseTreeNode node)
        {
            var builder = new StringBuilder();

            ToGroupedTokenString(node.Flatten(), builder, mayNeedParens: false);
            return(builder.ToString());
        }
        private void OnRuleParsed(Rule rule)
        {
            var children = new IParseTreeNode[rule.Symbols.Count];

            for (var i = rule.Symbols.Count - 1; i >= 0; --i)
            {
                children[i] = this.nodes.Pop();
            }
            this.nodes.Push(new Node {
                NonTerminal = (NonTerminal)rule.Produced, Children = children
            });
        }
        public virtual void Visit(IParseTreeNode node)
        {
            var ruleNode = node as ParseTreeRuleNode;

            if (ruleNode != null)
            {
                switch (ruleNode.Rule)
                {
                case Rule.CompileUnit:
                    VisitCompileUnit(ruleNode);
                    break;

                case Rule.HiveExpression:
                    VisitHiveExpression(ruleNode);
                    break;

                case Rule.Block:
                    VisitBlock(ruleNode);
                    break;

                case Rule.RootKey:
                    VisitRootKey(ruleNode);
                    break;

                case Rule.RegistryExpression:
                    VisitRegistryExpression(ruleNode);
                    break;

                case Rule.AddKey:
                    VisitAddKey(ruleNode);
                    break;

                case Rule.DeleteKey:
                    VisitDeleteKey(ruleNode);
                    break;

                case Rule.KeyName:
                    VisitKeyName(ruleNode);
                    break;

                case Rule.KeyValue:
                    VisitKeyValue(ruleNode);
                    break;

                case Rule.KeyType:
                    VisitKeyType(ruleNode);
                    break;

                default:
                    break;
                }
            }
        }
Beispiel #5
0
        public ParseTreeRuleNode ParseRegistryExpression()
        {
            IParseTreeNode node = ParseAddKey();

            if (node != null)
            {
                return(new ParseTreeRuleNode(Rule.RegistryExpression, node));
            }

            node = ParseDeleteKey();
            if (node != null)
            {
                return(new ParseTreeRuleNode(Rule.RegistryExpression, node));
            }

            return(null);
        }
Beispiel #6
0
 public void OnSymbolParsed(Symbol symbol, Rule rule)
 {
     if (rule == null)
     {
         this.nodes.Push(new LeafNode {
             Token = (Token)symbol
         });
     }
     else
     {
         var children = new IParseTreeNode[rule.Symbols.Count];
         for (var i = rule.Symbols.Count - 1; i >= 0; --i)
         {
             children[i] = this.nodes.Pop();
         }
         this.nodes.Push(new Node {
             NonTerminal = (NonTerminal)symbol, Children = children
         });
     }
 }