public static CodeType GetCodeTypeFromContext(ParseInfo parseInfo, DeltinScriptParser.Code_typeContext typeContext)
        {
            if (typeContext == null)
            {
                return(null);
            }

            CodeType type = null;

            if (typeContext.PART() != null)
            {
                type = parseInfo.TranslateInfo.Types.GetCodeType(typeContext.PART().GetText(), parseInfo.Script.Diagnostics, DocRange.GetRange(typeContext));
            }

            // Get generics
            if (typeContext.generics() != null)
            {
                // Create a list to store the generics.
                List <CodeType> generics = new List <CodeType>();

                // Get the generics.
                foreach (var genericContext in typeContext.generics().code_type())
                {
                    generics.Add(GetCodeTypeFromContext(parseInfo, genericContext));
                }

                if (type is Lambda.ValueBlockLambda)
                {
                    type = new Lambda.ValueBlockLambda(generics[0], generics.Skip(1).ToArray());
                }
                else if (type is Lambda.BlockLambda)
                {
                    type = new Lambda.BlockLambda(generics.ToArray());
                }
                else if (type is Lambda.MacroLambda)
                {
                    type = new Lambda.MacroLambda(generics[0], generics.Skip(1).ToArray());
                }
            }

            if (type != null)
            {
                type.Call(parseInfo, DocRange.GetRange(typeContext.PART()));
            }

            if (typeContext.INDEX_START() != null)
            {
                for (int i = 0; i < typeContext.INDEX_START().Length; i++)
                {
                    type = new ArrayType(type);
                }
            }

            return(type);
        }
示例#2
0
        public static CodeType GetCodeTypeFromContext(ParseInfo parseInfo, DeltinScriptParser.Code_typeContext typeContext)
        {
            if (typeContext == null)
            {
                return(null);
            }
            CodeType type = parseInfo.TranslateInfo.GetCodeType(typeContext.PART().GetText(), parseInfo.Script.Diagnostics, DocRange.GetRange(typeContext));

            if (type != null)
            {
                type.Call(parseInfo.Script, DocRange.GetRange(typeContext));

                if (typeContext.INDEX_START() != null)
                {
                    for (int i = 0; i < typeContext.INDEX_START().Length; i++)
                    {
                        type = new ArrayType(type);
                    }
                }
            }
            return(type);
        }