コード例 #1
0
        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, ParseType typeContext)
        {
            if (typeContext == null)
            {
                return(null);
            }

            CodeType type = null;

            if (!typeContext.IsDefault)
            {
                type = parseInfo.TranslateInfo.Types.GetCodeType(typeContext.Identifier.Text, parseInfo.Script.Diagnostics, typeContext.Identifier.Range);
            }

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

                // Get the generics.
                foreach (var genericContext in typeContext.TypeArgs)
                {
                    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, typeContext.Identifier.Range);
            }

            for (int i = 0; i < typeContext.ArrayCount; i++)
            {
                type = new ArrayType(type);
            }

            return(type);
        }