예제 #1
0
 public CustomTypeInstance(CustomType Type)
 {
     this.Type = Type;
 }
예제 #2
0
        public static new Expression Parse(Engine Engine, string Text, ref int Index, int LastIndex)
        {
            if (!IsParseOk(Engine, Text, ref Index, LastIndex))
            {
                return(null);
            }

            var Delta = Index;

            if (Text.Compare("class", Delta))
            {
                Delta += 5;
                ConsumeWhitespace(Text, ref Delta);

                CustomType Type = null;

                var Open = Delta;
                ConsumeValidName(Text, ref Delta);

                if (Delta > Open)
                {
                    var Name = Text.Substring(Open, Delta - Open);
                    ConsumeWhitespace(Text, ref Delta);

                    if (Text.Compare(":", Delta))
                    {
                        Delta++;
                        ConsumeWhitespace(Text, ref Delta);

                        Open = Delta;
                        ConsumeValidName(Text, ref Delta);

                        if (Delta > Open)
                        {
                            CustomType BaseType;
                            var        BaseName = Text.Substring(Open, Delta - Open);
                            ConsumeWhitespace(Text, ref Delta);

                            if ((BaseType = Engine.Types[BaseName] as CustomType) != null)
                            {
                                Type = new CustomType(Name, BaseType);
                            }
                        }
                    }
                    else
                    {
                        Type = new CustomType(Name);
                    }

                    if (Type != null && Text.Compare("{", Delta))
                    {
                        Open = Delta + 1;
                        ConsumeWhitespace(Text, ref Open);
                        ConsumeExpression(Text, ref Delta);

                        while (true)
                        {
                            Node Node = null;

                            if ((Node = Function.Parse(Engine, Text, ref Open, Delta, false)) != null)
                            {
                                Type.Functions.Add(Node as Function);
                            }
                            else
                            {
                                var Obj = Engine.Parse(Text, ref Open, Delta - 1);

                                if (Obj != null && Obj is Assign)
                                {
                                    Type.Properties.Add(Obj as Assign);
                                }
                                else
                                {
                                    break;
                                }
                            }

                            while (Text.Compare(";", Open))
                            {
                                Open++;
                            }
                            ConsumeWhitespace(Text, ref Open);
                        }

                        ConsumeWhitespace(Text, ref Delta);
                        Index = Delta;

                        Type.Register(Engine);
                        return(NoOp);
                    }
                }
            }

            return(null);
        }