Example #1
0
        /// <summary>
        /// Constructs patchpaths in a PatchTree hierarchy so that no absolute paths
        /// have to be saved within a PatchTree.
        /// </summary>
        public void CreatePatchPaths(string basePath)
        {
            var patchPath = Path.Combine(basePath, Id);

            PatchPath = patchPath;
            SubNodes.ForEach(x => x.CreatePatchPaths(basePath));
        }
Example #2
0
        public override string ToBbCode()
        {
            var content = string.Concat(SubNodes.Select(s => s.ToBbCode()).ToArray());

            var defAttr = Tag.FindAttribute(string.Empty);

            var attrStringBuilder = new StringBuilder();

            if (defAttr != null)
            {
                if (AttributeValues.ContainsKey(defAttr))
                {
                    var attrString = $"={AttributeValues[defAttr]}";

                    attrStringBuilder.Append(attrString);
                }
            }
            foreach (var attrKvp in AttributeValues)
            {
                if (string.IsNullOrEmpty(attrKvp.Key.Name))
                {
                    continue;
                }

                var attrString = $" {attrKvp.Key.Name}={attrKvp.Value}";

                attrStringBuilder.Append(attrString);
            }

            var attrs = attrStringBuilder.ToString();

            var result = $"[{Tag.Name}{attrs}]{content}[/{Tag.Name}]";

            return(result);
        }
Example #3
0
        public UnaryOperatorNode(NodeType NodeType, Node Argument)
            : base(NodeType, null, false)
        {
            SubNodes.Add(Argument);

            this.DataType = GetResultType(Argument);
        }
Example #4
0
        /// <summary>
        /// Get the node content as a formatted BBCode string.
        /// </summary>
        public override string ToBBCode()
        {
            string content = string.Concat(SubNodes.Select(s => s.ToBBCode()).ToArray());

            string      attrs   = "";
            BBAttribute defAttr = Tag.FindAttribute("");

            if (defAttr != null)
            {
                if (AttributeValues.ContainsKey(defAttr))
                {
                    attrs += "=" + AttributeValues[defAttr];
                }
            }

            foreach (var attrKvp in AttributeValues)
            {
                if (attrKvp.Key.Name == "")
                {
                    continue;
                }

                attrs += " " + attrKvp.Key.Name + "=" + attrKvp.Value;
            }

            return("[" + Tag.Name + attrs + "]" + content + "[/" + Tag.Name + "]");
        }
Example #5
0
        public GraphNode GetNamedField(string name)
        {
            // search at the current level
            return(SubNodes.Where(p => p.Name == name).SingleOrDefault());

            // todo: search parent levels
        }
Example #6
0
        public DictionaryNode(BinaryReader bin)
        {
            //Offset = (UInt32)bin.BaseStream.Position;
            NodeType = bin.ReadByte();
            if (NodeType != 0xC1)
            {
                throw new Exception("Not a dictionary node !");
            }
            List <byte> _count = new List <byte>();

            _count.AddRange(bin.ReadBytes(3));
            _count.Add(0x00);
            uint count = BitConverter.ToUInt32(_count.ToArray(), 0);

            if (count == 0)
            {
                return;
            }
            for (int i = 0; i < count; i++)
            {
                //Debug.Print("DICTIONARY SUBNODE AT: " + HelpFunctions.GetHexString((int)bin.BaseStream.Position));
                GenericNode g            = new GenericNode();
                List <byte> _stringIndex = new List <byte>();
                _stringIndex.AddRange(bin.ReadBytes(3));
                _stringIndex.Add(0x00);
                g.StringIndex = BitConverter.ToUInt32(_stringIndex.ToArray(), 0);
                g.NodeType    = bin.ReadByte();
                g.Value       = bin.ReadBytes(4);
                if (g.Value == null)
                {
                    throw new Exception("Value can't be null");
                }
                if (g.NodeType == 0xC1)
                {
                    long OldPos = bin.BaseStream.Position;
                    bin.BaseStream.Position = BitConverter.ToUInt32(g.Value, 0);
                    //Debug.Print(HelpFunctions.GetHexString(NodeType) + " node at: " + HelpFunctions.GetHexString((int)bin.BaseStream.Position));
                    DictionaryNode dict = new DictionaryNode(bin);
                    if (dict.SubNodes.Count != 0)
                    {
                        g.SubNodes = dict.SubNodes;
                    }
                    bin.BaseStream.Position = OldPos;
                }
                else if (g.NodeType == 0xC0)
                {
                    long OldPos = bin.BaseStream.Position;
                    bin.BaseStream.Position = BitConverter.ToUInt32(g.Value, 0);
                    //Debug.Print(HelpFunctions.GetHexString(NodeType) + " node at: " + HelpFunctions.GetHexString((int)bin.BaseStream.Position));
                    ArrayNode arr = new ArrayNode(bin);
                    if (arr.SubNodes.Count != 0)
                    {
                        g.SubNodes = arr.SubNodes;
                    }
                    bin.BaseStream.Position = OldPos;
                }// else Debug.Print(HelpFunctions.GetHexString(NodeType) + " node at: " + HelpFunctions.GetHexString((int)bin.BaseStream.Position));

                SubNodes.Add(g);
            }
        }
Example #7
0
 public void RemoveChild(BaseNode node)
 {
     if (SubNodes.Contains(node))
     {
         SubNodes.Remove(node);
     }
 }
Example #8
0
 /// <summary>
 /// Добавить дочерний элемент.
 /// </summary>
 private void AddNode()
 {
     SubNodes.AddLast(new Node()
     {
         Value = "Новый элемент", Parent = this
     });
 }
Example #9
0
        string GetContent()
        {
            var content = string.Concat(SubNodes.Select(s => s.ToHtml()).ToArray());

            return(Tag.ContentTransformer == null
                ? content
                : Tag.ContentTransformer(content));
        }
Example #10
0
        public BinaryOperatorNode(NodeType NodeType, Node Left, Node Right)
            : base(NodeType, null, false)
        {
            SubNodes.Add(Left);
            SubNodes.Add(Right);

            this.DataType = GetResultType(Left, Right);
        }
        public override string ToText()
        {
            var result =
                string.Concat(
                    SubNodes
                    .Select(s => s.ToText())
                    .ToArray());

            return(result);
        }
Example #12
0
 public override IASTNode Parse(IASTNodeFactory nodeFactory, IAParser aParser, ATokens tokens)
 {
     while (tokens.CurrentToken != null && !aParser.Acceptable(tokens, ASTEndParenthesesNode.KeyWord) && !aParser.Acceptable(tokens, ASTCommaNode.KeyWord))
     {
         IASTNode node = nodeFactory.CreateNode(tokens.CurrentToken.Text, tokens.CurrentToken.AddSpace);
         node.Parse(nodeFactory, aParser, tokens);
         SubNodes.Add(node);
     }
     return(this);
 }
Example #13
0
File: Node.cs Project: p0k0/t-tn
        public virtual void AppendSub(Node newSubNode)
        {
            if (newSubNode == null)
            {
                return;
            }

            newSubNode.Parent = this;
            SubNodes.Add(newSubNode);
        }
Example #14
0
 public Node <T> TryFind(char symbol)
 {
     if (SubNodes.TryGetValue(symbol, out Node <T> value))
     {
         return(value);
     }
     else
     {
         return(null);
     }
 }
Example #15
0
        /// <summary>
        /// Removes provided item (<paramref name="item"/>) from the node.
        /// </summary>
        ///
        /// <param name="item">Item to be removed from the node</param>
        ///
        /// <seealso cref="INode{TItem, TNode}.Clear"/>
        protected internal void RemoveOwnItem(TItem item)
        {
            // remove the item from the node
            _items.Remove(item);
            // update its parent node
            item.ParentNode = null;

            if (IsEmpty())
            {
                // remove subnodes if subtree of this node is empty
                SubNodes.Clear();
            }
        }
Example #16
0
        /// <summary>
        /// Initializes a new instance of the <see cref="MathExpressionFunctionNode"/> class.
        /// </summary>
        /// <param name="expressionType"></param>
        /// <param name="functionNameFragment">The function name fragment.</param>
        /// <param name="subNodes">The sub nodes (parameters).</param>
        /// <param name="function">The delegate to calculate function value.</param>
        /// <exception cref="ArgumentException">null sub node</exception>
        public MathExpressionFunctionNode(
            ExpressionTypeDescriptor expressionType,
            ISourceCodeFragment functionNameFragment,
            IEnumerable <IParsingProduct> subNodes,
            Func <object[], object> function)
            : base(expressionType, functionNameFragment, subNodes)
        {
            _function = function;

            if (SubNodes.Cast <IExecutableExpressionNode>().Any(n => n == null))
            {
                throw new ArgumentException("null sub node");
            }
        }
Example #17
0
        /// <summary>
        /// Creates sub-nodes for the node.
        /// </summary>
        protected internal void CreateSubNodes()
        {
            var subBoundsSize = Bounds.size * .5f;

            if (subBoundsSize.x < TreeRoot.MinimumPossibleNodeSize ||
                subBoundsSize.z < TreeRoot.MinimumPossibleNodeSize)
            {
                // new sub-node bounds are too small
                return;
            }

            var centerOffset = subBoundsSize * .5f;

            // top left node [-x +z]
            centerOffset.x *= -1f;
            SubNodes.Insert((int)IntraLocation.UPPER_LEFT, new TNode()
            {
                TreeRoot   = TreeRoot,
                ParentNode = (TNode)this,
                Bounds     = new Bounds(Bounds.center + centerOffset, subBoundsSize),
            });

            // top right node [+x +z]
            centerOffset.x *= -1f;
            SubNodes.Insert((int)IntraLocation.UPPER_RIGHT, new TNode()
            {
                TreeRoot   = TreeRoot,
                ParentNode = (TNode)this,
                Bounds     = new Bounds(Bounds.center + centerOffset, subBoundsSize),
            });

            // bottom right node [+x -z]
            centerOffset.z *= -1f;
            SubNodes.Insert((int)IntraLocation.LOWER_RIGHT, new TNode()
            {
                TreeRoot   = TreeRoot,
                ParentNode = (TNode)this,
                Bounds     = new Bounds(Bounds.center + centerOffset, subBoundsSize),
            });

            // bottom left node [-x -z]
            centerOffset.x *= -1f;
            SubNodes.Insert((int)IntraLocation.LOWER_LEFT, new TNode()
            {
                TreeRoot   = TreeRoot,
                ParentNode = (TNode)this,
                Bounds     = new Bounds(Bounds.center + centerOffset, subBoundsSize),
            });
        }
Example #18
0
 public override IASTNode Parse(IASTNodeFactory nodeFactory, IAParser aParser, ATokens tokens)
 {
     tokens.GetNextToken();
     while (tokens.CurrentToken != null && !aParser.Acceptable(tokens, ASTEndParenthesesNode.KeyWord))
     {
         IASTNode newNode = aParser.NodeFactory.CreateNode(tokens.CurrentToken.Text, tokens.CurrentToken.AddSpace);
         newNode.Parse(aParser.NodeFactory, aParser, tokens);
         SubNodes.Add(newNode);
     }
     if (!aParser.Acceptable(tokens, ASTEndParenthesesNode.KeyWord))
     {
         throw new AParserException("Didn't find closing parentheses");
     }
     SubNodes.Add(aParser.Accept(tokens, ASTEndParenthesesNode.KeyWord));
     return(this);
 }
Example #19
0
        protected void ParseParameters(IASTNodeFactory nodeFactory, IAParser aParser, ATokens tokens)
        {
            SubNodes.Add(aParser.Accept(tokens, ASTStartParenthesesNode.KeyWord));

            while (tokens.CurrentToken != null && !aParser.Acceptable(tokens, ASTEndParenthesesNode.KeyWord))
            {
                IASTNode node = nodeFactory.CreateFunctionParameterNode(tokens.CurrentToken.AddSpace);
                node.Parse(nodeFactory, aParser, tokens);
                SubNodes.Add(node);

                if (aParser.Acceptable(tokens, ASTCommaNode.KeyWord))
                {
                    SubNodes.Add(aParser.Accept(tokens, ASTCommaNode.KeyWord));
                }
            }

            SubNodes.Add(aParser.Accept(tokens, ASTEndParenthesesNode.KeyWord));
        }
Example #20
0
        /// <summary>
        /// Adds a sub category
        /// </summary>
        /// <param name="name">Name of the sub category</param>
        /// <exception cref="ArgumentException">If a category with the specified name already exists</exception>
        /// <exception cref="ArgumentNullException">If name is null</exception>
        public override LanguageNode AddNode(string name)
        {
            if (SubNodes.ContainsKey(name))
            {
                throw new ArgumentException("A category with specified name already exists.", "name");
            }

            if (string.IsNullOrEmpty(name))
            {
                throw new ArgumentNullException("name");
            }

            lock (SubNodes)
            {
                SubNodes.Add(name, new MemLanguageNode(DefaultLCID, name));
                SubNodes[name].ParentNode = this;

                return(SubNodes[name]);
            }
        }
Example #21
0
            private int SumValue()
            {
                if (!SubNodes.Any())
                {
                    return(Metadata.Sum());
                }

                var output = 0;

                foreach (var item in Metadata)
                {
                    if (item < 1 || item > SubNodes.Count())
                    {
                        continue;
                    }

                    output += SubNodes[item - 1].SumValue();
                }

                return(output);
            }
        public override string ToLegacyBBCode()
        {
            var content = string.Concat(SubNodes.Select(s => s.ToLegacyBBCode()).ToArray());

            var attrs      = "";
            var defAttr    = Tag.FindAttribute("");
            var attachFlag = "";

            if (defAttr != null && AttributeValues.ContainsKey(defAttr))
            {
                attrs += "=" + AttributeValues[defAttr];
            }
            foreach (var attrKvp in AttributeValues)
            {
                if (Tag.Name.Equals("attachment", StringComparison.OrdinalIgnoreCase) && string.IsNullOrWhiteSpace(attachFlag) && attrKvp.Key.ID.Equals("num", StringComparison.OrdinalIgnoreCase) && int.TryParse(attrKvp.Value, out var id))
                {
                    attachFlag = $"<!-- ia{id} -->";
                }

                if (attrKvp.Key.Name == "")
                {
                    continue;
                }
                attrs += " " + attrKvp.Key.Name + "=" + attrKvp.Value;
            }

            var toReturn = new StringBuilder("[").Append(Tag.Name).Append(HttpUtility.HtmlEncode(attrs));

            if (!string.IsNullOrWhiteSpace(Tag.BBCodeUid))
            {
                toReturn.Append(':').Append(Tag.BBCodeUid);
            }

            string nonEmptyContent = content, trailingWhitespace = "";

            if (Tag.EnableIterationElementBehavior && !string.IsNullOrWhiteSpace(content) && char.IsWhiteSpace(content[^ 1]))
Example #23
0
 public Seq <Node> GetChildren(Predicate <Node> pred)
 {
     return(pred != null?SubNodes.Filter(pred) : new Seq <Node>());
 }
Example #24
0
 public Node GetChild(Predicate <Node> pred)
 {
     return(pred != null?SubNodes.FirstMatch(pred) : null);
 }
Example #25
0
        public ArrayNode(BinaryReader bin)
        {
            //Offset = (UInt32)bin.BaseStream.Position;
            NodeType = bin.ReadByte();
            if (NodeType != 0xC0)
            {
                throw new Exception("Not an array node !");
            }
            List <byte> _count = new List <byte>();

            _count.AddRange(bin.ReadBytes(3));
            _count.Add(0x00);
            uint Count = BitConverter.ToUInt32(_count.ToArray(), 0);

            if (Count == 0)
            {
                return;
            }
            byte[] NodeTypes;
            NodeTypes = bin.ReadBytes((int)Count);
            if (bin is BigEndianReader)
            {
                Array.Reverse(NodeTypes);
            }
            while ((bin.BaseStream.Position % 4) != 0)
            {
                bin.ReadByte();                                        //Padding
            }
            for (int i = 0; i < Count; i++)
            {
                // Debug.Print("ARRAY SUBNODE AT: " + HelpFunctions.GetHexString((int)bin.BaseStream.Position));
                GenericNode g = new GenericNode();
                g.NodeType = NodeTypes[i];
                g.Value    = bin.ReadBytes(4);
                if (g.NodeType == 0xC1)
                {
                    long OldPos = bin.BaseStream.Position;
                    bin.BaseStream.Position = BitConverter.ToUInt32(g.Value, 0);
                    //Debug.Print(HelpFunctions.GetHexString(NodeType) + " node at: " + HelpFunctions.GetHexString((int)bin.BaseStream.Position));
                    DictionaryNode dict = new DictionaryNode(bin);
                    if (dict.SubNodes.Count != 0)
                    {
                        g.SubNodes = dict.SubNodes;
                    }
                    bin.BaseStream.Position = OldPos;
                }
                else if (g.NodeType == 0xC0)
                {
                    long OldPos = bin.BaseStream.Position;
                    bin.BaseStream.Position = BitConverter.ToUInt32(g.Value, 0);
                    //Debug.Print(HelpFunctions.GetHexString(NodeType) + " node at: " + HelpFunctions.GetHexString((int)bin.BaseStream.Position));
                    ArrayNode Arr = new ArrayNode(bin);
                    if (Arr.SubNodes.Count != 0)
                    {
                        g.SubNodes = Arr.SubNodes;
                    }
                    bin.BaseStream.Position = OldPos;
                }//else Debug.Print(HelpFunctions.GetHexString(NodeType) + " node at: " + HelpFunctions.GetHexString((int)bin.BaseStream.Position));


                SubNodes.Add(g);
            }
        }
Example #26
0
 public override string ToText()
 {
     return(string.Concat(SubNodes.Select(s => s.ToText()).ToArray()));
 }
Example #27
0
 public InstanceFieldNode(Node InstanceNode, System.Reflection.FieldInfo FieldInfo)
     : base(NodeType.InstanceField, FieldInfo.FieldType, false)
 {
     SubNodes.Add(InstanceNode);
     m_FieldInfo = FieldInfo;
 }
 public CucumberExpression(CucumberExpressionAstNode node) : base(RuleType.CucumberExpression, null)
 {
     SubNodes.AddRange(node.SubNodes);
 }
Example #29
0
 public NamedFieldNode(Node InstanceNode, string FieldName, Type FieldType)
     : base(NodeType.NamedField, FieldType, false)
 {
     SubNodes.Add(InstanceNode);
     m_FieldName = FieldName;
 }
Example #30
0
 public void Clear()
 {
     _items.Clear();
     SubNodes.Clear();
 }