Пример #1
0
        private void ParseGroup(ref ConfigGroup par, ParseTreeNode groupnode)
        {
            if (groupnode.Term.Name != "Group")
            {
                throw new InvalidDataException("Groupの形式ではありません");
            }
            var gname  = groupnode.ChildNodes[0].Token.ValueString;
            var cnodes = groupnode.ChildNodes[1].ChildNodes;
            var pdg    = new ConfigGroup();

            foreach (var i in cnodes)
            {
                switch (i.ChildNodes[0].Term.Name)
                {
                case "Property":
                    ParseProperty(ref pdg, i.ChildNodes[0]);
                    break;

                case "Group":
                    ParseGroup(ref pdg, i.ChildNodes[0]);
                    break;

                default:
                    throw new InvalidDataException("何かがおかしい");
                }
            }
            par.Groups[gname] = pdg;
        }
Пример #2
0
        private void Parse()
        {
            RawTree = Parser.Parse(RawString);
            if (RawTree.Root == null)
            {
                throw new InvalidDataException("無効なKb10uyConfigです");
            }
            var gs = RawTree.Root.ChildNodes;
            var dg = new ConfigGroup();   //形式的にダミーを作ってそれから取得

            foreach (var g in gs)
            {
                ParseGroup(ref dg, g);
            }
            groups = dg.gs;
        }
Пример #3
0
        private void ParseProperty(ref ConfigGroup par, ParseTreeNode propnode)
        {
            var types = propnode.ChildNodes[0].ChildNodes[0].Token.ValueString;
            var cty   = typeset[types];
            var name  = propnode.ChildNodes[1].Token.ValueString;

            //値のパース
            if (propnode.ChildNodes[2].ChildNodes[0].Term.Name != types)
            {
                throw new InvalidDataException(String.Format("型の不一致が発生しています : 宣言 {0} に対して {1} の値", types, propnode.ChildNodes[2].ChildNodes[0].Term.Name));
            }
            ConfigValue val = new ConfigValue();;

            ParseValue(ref val, propnode.ChildNodes[2].ChildNodes[0]);
            par.Properties[name] = val;
        }
Пример #4
0
        private IList <string> SerializeGroup(ConfigGroup gr, string name, int inl)
        {
            var ret = new List <string>();

            ret.Add("\t".Repeat(inl)
                    + String.Format("\"{0}\" : ", name)
                    + "{");
            foreach (var g in gr.Groups)
            {
                ret.AddRange(SerializeGroup(g.Value, g.Key, inl + 1));
            }
            foreach (var p in gr.Properties)
            {
                ret.Add(SerializeProperty(p.Value, p.Key, inl + 1));
            }
            ret.Add("\t".Repeat(inl) + "}");
            return(ret);
        }