Пример #1
0
        public static List <SyntaxType> ParseTypes(string text)
        {
            List <SyntaxType> result = new List <SyntaxType>();

            int offset = SkipSpace(text, 0);

            while (offset < text.Length)
            {
                SyntaxType type = new SyntaxType();
                type.comments = ParseComment(text, ref offset);

                string id = ParseName(text, ref offset);
                if (id != "class")
                {
                    throw new Exception(id);
                }

                type.name = ParseName(text, ref offset);

                offset        = Except(text, offset, ':');
                type.basename = ParseName(text, ref offset);
                if (text[offset] == '=')
                {
                    offset           = Except(text, offset, '=');
                    offset           = Except(text, offset, '0');
                    type.is_abstract = true;
                }
                offset = Except(text, offset, '{');

                while (text[offset] != '}')
                {
                    SyntaxField field = new SyntaxField();
                    field.comments = ParseComment(text, ref offset);
                    field.type     = ParseName(text, ref offset);
                    field.name     = ParseName(text, ref offset);
                    if (text[offset] == '=')
                    {
                        offset = Except(text, offset, '=');
                        ParseName(text, ref offset);

                        field.is_option = true;
                    }
                    offset = Except(text, offset, ';');
                    type.fields.Add(field);
                }
                offset = Except(text, offset, '}');

                result.Add(type);
            }

            return(result);
        }
Пример #2
0
        static List <SyntaxField> GetAllFields(List <SyntaxType> types, SyntaxType type)
        {
            SyntaxType bs = types.Find(x => x.name == type.basename);

            if (bs == null)
            {
                return(type.fields);
            }

            List <SyntaxField> bsf = GetAllFields(types, bs);

            if (type.fields.Count == 0)
            {
                return(bsf);
            }

            List <SyntaxField> r = new List <SyntaxField>();

            r.AddRange(bsf);
            r.AddRange(type.fields);
            return(r);
        }