コード例 #1
0
 public Function(TypeAn returnType, string name, ParamsAn paramsAn, string code)
 {
     m_returnType = returnType;
     m_name       = name;
     m_params     = paramsAn;
     m_code       = code;
 }
コード例 #2
0
 public Function()
 {
     m_returnType = new TypeAn();
     m_name       = new string("");
     m_params     = new ParamsAn();
     m_code       = new string("");
 }
コード例 #3
0
        public static Function TryParseFunctionHead(string str)
        {
            str = Utils.TrimFirst(str);
            string type = Utils.GetWord(str, 0);

            if (type == "")
            {
                return(new Function());
            }

            // try to find return type
            if (!TypesAn.IsType(type))
            {
                return(new Function());
            }
            TypeAn _type = new TypeAn(type);

            int typeInd = str.IndexOf(type);

            str = str.Remove(typeInd, typeInd + type.Length);
            str = Utils.TrimFirst(str);


            // try to find name
            string functName     = "";
            bool   isNameStarted = false;

            foreach (char el in str)
            {
                if (el != ' ' && el != '(')
                {
                    isNameStarted = true;
                }

                if ((el == ' ' || el == '(') && isNameStarted)
                {
                    break;
                }
                functName += el;
            }
            int nameInd = str.IndexOf(functName);

            str = str.Remove(nameInd, nameInd + functName.Length);
            str = Utils.TrimFirst(str);

            // try to find params
            string paramsString    = "";
            bool   isParamsStarted = false;

            foreach (char symbol in str)
            {
                if (symbol == ')')
                {
                    break;
                }

                if (symbol == '(')
                {
                    isParamsStarted = true;
                    continue;
                }

                if (isParamsStarted)
                {
                    paramsString += symbol;
                }
            }
            if (!isParamsStarted)
            {
                return(new Function());
            }
            int paramsInd = str.IndexOf(paramsString);

            str = str.Remove(paramsInd, paramsString.Length);
            str = Utils.TrimFirst(str);

            // try to find code
            string codeString    = "";
            bool   isCodeStarted = false;

            foreach (char symbol in str)
            {
                if (symbol == '}')
                {
                    break;
                }

                if (symbol == '{')
                {
                    isCodeStarted = true;
                    continue;
                }

                if (isCodeStarted)
                {
                    codeString += symbol;
                }
            }
            if (!isCodeStarted)
            {
                return(new Function());
            }
            codeString = Utils.TrimFirst(codeString);

            return(new Function(_type, functName, new ParamsAn(paramsString), codeString));
        }