コード例 #1
0
 public MyYamlNode(string name, int indentAmount, MyYamlNode parent)
 {
     this.name         = name;
     this.indentAmount = indentAmount;
     this.nodes        = new List <MyYamlNode>();
     this.parent       = parent;
 }
コード例 #2
0
        //OVERLOADING
        private void LoadChildren(YamlSequenceNode sequence, MyYamlNode parent)
        {
            foreach (var child in sequence.Children)
            {
                if (child is YamlScalarNode)
                {
                    var scalar = child as YamlScalarNode;
                    parent.AddChildren(MyNodeFactory.CreateMyYamlScalarNode("", scalar.Tag, scalar.Value, scalar.Style, indentAmount, parent, scalar.Start.Line, scalar.Start.Column));
                }
                else if (child is YamlSequenceNode)
                {
                    parent.AddChildren(MyNodeFactory.CreateMyYamlSequenceNode("", indentAmount, parent));

                    MyYamlSequenceNode new_parent = (MyYamlSequenceNode)parent.nodes[parent.nodes.Count - 1];
                    LoadChildren(child as YamlSequenceNode, new_parent);
                }
                else if (child is YamlMappingNode)
                {
                    parent.AddChildren(MyNodeFactory.CreateMyYamlMappingNode("", indentAmount, parent));

                    MyYamlMappingNode new_parent = (MyYamlMappingNode)parent.nodes[parent.nodes.Count - 1];
                    LoadChildren(child as YamlMappingNode, new_parent);
                }
            }
        }
コード例 #3
0
 public override void AddChildren(MyYamlNode child)
 {
 }
コード例 #4
0
        public MyYamlScalarNode(string name, string tag, string value, ScalarStyle style, int indentAmount, MyYamlNode parent, int aLine, int aCol) : base(name, indentAmount, parent)
        {
            this.value      = value;
            this.tag        = tag;
            this.value_type = "string";
            this.style      = style;

            line = aLine;
            col  = aCol;

            int  value_int             = 0;
            bool successfullyParsedInt = int.TryParse(this.value, out value_int);

            if (successfullyParsedInt)
            {
                this.value_type = "int";
            }

            bool value_bool             = true;
            bool successfullyParsedBool = bool.TryParse(this.value, out value_bool);

            if (successfullyParsedBool)
            {
                this.value_type = "bool";
            }

            this.nodes = null;
        }
コード例 #5
0
 public static MyYamlMappingNode CreateMyYamlMappingNode(string name, int indentAmount, MyYamlNode parent)
 {
     return(new MyYamlMappingNode(name, indentAmount, parent));
 }
コード例 #6
0
 public static MyYamlScalarNode CreateMyYamlScalarNode(string name, string tag, string value, ScalarStyle style, int indentAmount, MyYamlNode parent, int aLine, int aCol)
 {
     return(new MyYamlScalarNode(name, tag, value, style, indentAmount, parent, aLine, aCol));
 }
コード例 #7
0
 public override void AddChildren(MyYamlNode child)
 {
     this.nodes.Add(child);
 }
コード例 #8
0
 public MyYamlSequenceNode(string name, int indentAmount, MyYamlNode parent) : base(name, indentAmount, parent)
 {
 }
コード例 #9
0
 public abstract void AddChildren(MyYamlNode child);
コード例 #10
0
 public MyYamlMappingNode(string name, int indentAmount, MyYamlNode parent) : base(name, indentAmount, parent)
 {
 }
コード例 #11
0
        //OVERLOADING
        private void LoadChildren(YamlMappingNode mapping, MyYamlNode parent)
        {
            var children = mapping?.Children;

            if (children == null)
            {
                return;
            }

            foreach (var child in children)
            {
                var key = child.Key as YamlScalarNode;

                //alias/anchor error on yamlStream fix:
                if (key.Value[0] == '*' || key.Value[key.Value.Length - 1] == '*')
                {
                    key.Value = "\"" + key.Value + "\"";
                }

                if (child.Value is YamlScalarNode)
                {
                    var scalar = child.Value as YamlScalarNode;
                    //Fix yamlStream syntax error
                    //removes unnecessary '/' after folder name in includes
                    if (!(string.IsNullOrEmpty(scalar.Value)) && (scalar.Value[scalar.Value.Length - 1] == '\\' || scalar.Value[scalar.Value.Length - 1] == '/'))
                    {
                        scalar.Value = scalar.Value.Remove(scalar.Value.Length - 1);
                    }

                    //if the value is single quoted and contains a "'" we need to replace it with "''"
                    if (scalar.Value.Contains("'") && scalar.Style == YamlDotNet.Core.ScalarStyle.SingleQuoted)
                    {
                        scalar.Value = scalar.Value.Replace("'", "''");
                    }

                    //if the value is double quoted and contains a '"' we need to replace it with '"'
                    if (scalar.Value.Contains("\"") && scalar.Style == YamlDotNet.Core.ScalarStyle.DoubleQuoted)
                    {
                        scalar.Value = scalar.Value.Replace("\"", "\\\"");
                    }

                    parent.AddChildren(MyNodeFactory.CreateMyYamlScalarNode(key.Value, scalar.Tag, scalar.Value, scalar.Style, indentAmount, parent, key.Start.Line, key.Start.Column));

                    if (scalar.Tag == "!include")
                    {
                        if (File.Exists(directory + scalar.Value))
                        {
                            MyYamlFileFactory.CreateMyYamlFile(directory + scalar.Value);
                        }
                        else
                        {
                            Logger.Instance.WriteLine("Could not find file '" + directory + scalar.Value + "'.");
                        }
                    }
                    if (scalar.Tag == "!include_dir_named" || scalar.Tag == "!include_dir_merge_named" || scalar.Tag == "!include_dir_merge_list")
                    {
                        CreateDirectoryIfDoesntExist(directory, scalar.Value);

                        string[] files = System.IO.Directory.GetFiles(directory + scalar.Value + "\\", "*.yaml");
                        foreach (var value in files)
                        {
                            var file_to_import = Path.GetFileName(value);
                            if (File.Exists(directory + scalar.Value + "\\" + file_to_import))
                            {
                                MyYamlFileFactory.CreateMyYamlFile(directory + scalar.Value + "\\" + file_to_import);
                            }
                            else
                            {
                                Logger.Instance.WriteLine("Could not find file '" + directory + scalar.Value + "\\" + file_to_import + "'.");
                            }
                        }
                    }
                }
                else if (child.Value is YamlSequenceNode)
                {
                    parent.AddChildren(MyNodeFactory.CreateMyYamlSequenceNode(key.Value, indentAmount, parent));

                    indentAmount += 2;
                    MyYamlSequenceNode new_parent = (MyYamlSequenceNode)parent.nodes[parent.nodes.Count - 1];
                    LoadChildren(child.Value as YamlSequenceNode, new_parent);
                    indentAmount -= 2;
                }
                else if (child.Value is YamlMappingNode)
                {
                    parent.AddChildren(MyNodeFactory.CreateMyYamlMappingNode(key.Value, indentAmount, parent));

                    indentAmount += 2;
                    MyYamlMappingNode new_parent = (MyYamlMappingNode)parent.nodes[parent.nodes.Count - 1];
                    LoadChildren(child.Value as YamlMappingNode, new_parent);
                    indentAmount -= 2;
                }
            }
        }