Ejemplo n.º 1
0
        public static ElData Parse(ElTokenizer tokenizer)
        {
            while (tokenizer.Current.Kind == ElTokenizer.NewLineTokenKind)
            {
                tokenizer.MoveNext();
            }

            var rt = new ElData();

            if (tokenizer.Current.Kind == ElTokenizer.IdentifierTokenKind)
            {
                rt.Name = tokenizer.Current.Text;
                tokenizer.MoveNext();
            }

            if (tokenizer.Current.Kind == ElTokenizer.BeginChildrenTokenKind)
            {
                rt.Children = tokenizer.TakeWhile(_ => _.Kind != ElTokenizer.EndChildrenTokenKind)
                              .Select(_ => Parse(tokenizer))
                              .ToList();
                tokenizer.MoveNext(ElTokenizer.EndChildrenTokenKind);
            }
            else
            {
                rt.Values = tokenizer.StartWith(tokenizer.Current)
                            .TakeWhile(_ => _.Kind != ElTokenizer.NewLineTokenKind && _.Kind != ElTokenizer.EndChildrenTokenKind)
                            .Select(_ => _.Text)
                            .ToList();
            }

            return(rt);
        }
Ejemplo n.º 2
0
        public static ElData Parse(ElTokenizer tokenizer)
        {
            while (tokenizer.Current.Kind == ElTokenizer.NewLineTokenKind)
                tokenizer.MoveNext();

            var rt = new ElData();

            if (tokenizer.Current.Kind == ElTokenizer.IdentifierTokenKind)
            {
                rt.Name = tokenizer.Current.Text;
                tokenizer.MoveNext();
            }

            if (tokenizer.Current.Kind == ElTokenizer.BeginChildrenTokenKind)
            {
                rt.Children = tokenizer.TakeWhile(_ => _.Kind != ElTokenizer.EndChildrenTokenKind)
                                   .Select(_ => Parse(tokenizer))
                                   .ToList();
                tokenizer.MoveNext(ElTokenizer.EndChildrenTokenKind);
            }
            else
                rt.Values = tokenizer.StartWith(tokenizer.Current)
                                     .TakeWhile(_ => _.Kind != ElTokenizer.NewLineTokenKind && _.Kind != ElTokenizer.EndChildrenTokenKind)
                                     .Select(_ => _.Text)
                                     .ToList();

            return rt;
        }
Ejemplo n.º 3
0
        public static ElDocument Parse(string text)
        {
            var rt        = new ElDocument();
            var tokenizer = new ElTokenizer(text);
            var header    = new[] { "Elfreina", "Extension", "Model", "File", "\n", "File", "Version" };

            if (!tokenizer.Take(header.Length).Select(_ => _.Text).SequenceEqual(header))
            {
                throw new InvalidOperationException("invalid format");
            }

            rt.Version = float.Parse(tokenizer.MoveNext().EnsureKind(ElTokenizer.ValueTokenKind).Text);

            if (rt.Version >= 2)
            {
                throw new NotSupportedException("specified format version not supported");
            }

            foreach (var i in tokenizer)
            {
                if (i.Kind == ElTokenizer.IdentifierTokenKind)
                {
                    var data = ElData.Parse(tokenizer);

                    switch (data.Name)
                    {
                    case "Setting":
                        rt.Setting = ElSetting.Parse(data);

                        break;

                    case "MeshDataList":
                        rt.MeshDataList = data.Children.Where(_ => _.Name == "MeshContainer").Select(ElMeshContainer.Parse).ToList();

                        break;

                    case "HierarchyList":
                        rt.HierarchyList = data.Children.Select(ElNode.Parse).ToList();

                        break;

                    case "RenderingMeshList":
                        foreach (var j in data.Children.Where(_ => _.Name == "RenderingMesh"))
                        {
                            rt.RenderingMeshList.Add(j.Child("RenderingMeshName").Values.First().Trim('"'), j.Child("HierarchyNames").Children.Select(_ => _.Values.First().Trim('"')).ToList());
                        }

                        break;

                    case "AnimationList":
                        rt.AnimationList = data.Children.Where(_ => _.Name == "AnimationData").Select(ElAnimationData.Parse).ToList();

                        break;

                    default:
                        rt.CustomData.Add(data);

                        break;
                    }
                }
            }

            return(rt);
        }
Ejemplo n.º 4
0
        public static ElDocument Parse(string text)
        {
            var rt = new ElDocument();
            var tokenizer = new ElTokenizer(text);
            var header = new[] { "Elfreina", "Extension", "Model", "File", "\n", "File", "Version" };

            if (!tokenizer.Take(header.Length).Select(_ => _.Text).SequenceEqual(header))
                throw new InvalidOperationException("invalid format");

            rt.Version = float.Parse(tokenizer.MoveNext().EnsureKind(ElTokenizer.ValueTokenKind).Text);

            if (rt.Version >= 2)
                throw new NotSupportedException("specified format version not supported");

            foreach (var i in tokenizer)
                if (i.Kind == ElTokenizer.IdentifierTokenKind)
                {
                    var data = ElData.Parse(tokenizer);

                    switch (data.Name)
                    {
                        case "Setting":
                            rt.Setting = ElSetting.Parse(data);

                            break;
                        case "MeshDataList":
                            rt.MeshDataList = data.Children.Where(_ => _.Name == "MeshContainer").Select(ElMeshContainer.Parse).ToList();

                            break;
                        case "HierarchyList":
                            rt.HierarchyList = data.Children.Select(ElNode.Parse).ToList();

                            break;
                        case "RenderingMeshList":
                            foreach (var j in data.Children.Where(_ => _.Name == "RenderingMesh"))
                                rt.RenderingMeshList.Add(j.Child("RenderingMeshName").Values.First().Trim('"'), j.Child("HierarchyNames").Children.Select(_ => _.Values.First().Trim('"')).ToList());

                            break;
                        case "AnimationList":
                            rt.AnimationList = data.Children.Where(_ => _.Name == "AnimationData").Select(ElAnimationData.Parse).ToList();

                            break;
                        default:
                            rt.CustomData.Add(data);

                            break;
                    }
                }

            return rt;
        }