예제 #1
0
        public static bool IsType(string control, VariabelDatabase db)
        {
            if(control.IndexOf("function") == 0)
            {
                if (control == "function")
                    return true;

                if(control.Substring(8,1) == "<" && control.Substring(control.Length-1, 1) == ">")
                {
                    string buffer = control.Substring(8);
                    return IsType(buffer.Substring(0, buffer.Length - 1), db);
                }
            }

            return db.isType(control);
        }
예제 #2
0
        private static bool getSingleAguments(Token token, AgumentStack agument, VariabelDatabase database, EnegyData data)
        {
            string type = null;
            string name = null;
            CVar value = null;

            //wee control if it is function :)
            if(token.getCache().ToString() == "function")
            {
                if(token.next().type() == TokenType.Greater)
                {
                    //it is a function with return type :)
                    if (!database.isType(token.next().ToString()))
                    {
                        data.setError(new ScriptError("Unknown type: " + token.getCache().ToString(), token.getCache().posision()), database);
                        return false;
                    }

                    type = "function<" + token.getCache().ToString() + ">";

                    if(token.next().type() != TokenType.Less)
                    {
                        data.setError(new ScriptError("Missing > in end of function return type agument", token.getCache().posision()), database);
                    }

                    token.next();
                }
                else
                {
                    type = "function";
                }

                //okay let try to find the name
                if (token.getCache().type() != TokenType.Variabel)
                {
                    data.setError(new ScriptError("After type there must be a variabel", token.getCache().posision()), database);
                    return false;
                }

                name = token.getCache().ToString();
            }
            else if (database.isType(token.getCache().ToString()))
            {
                //yes it is a type :)
                type = token.getCache().ToString();

                //okay let try to find the name
                if (token.next().type() != TokenType.Variabel)
                {
                    data.setError(new ScriptError("After type there must be a variabel", token.getCache().posision()), database);
                    return false;
                }

                name = token.getCache().ToString();
            }
            else
            {
                if (token.getCache().type() != TokenType.Variabel)
                {
                    data.setError(new ScriptError("Unknown agument token: " + token.getCache().ToString(), token.getCache().posision()), database);
                    return false;
                }
                name = token.getCache().ToString();
            }

            if (token.next().type() == TokenType.Assigen)
            {
                token.next();
                value = new VariabelParser().parseNoEnd(data, database, token);
                hasDefault = true;
            }
            else
            {
                if (hasDefault)
                {
                    data.setError(new ScriptError("You can not put non default after a defualt variabel!", token.getCache().posision()), database);
                    return false;
                }
            }

            agument.push(type, name, value);
            return true;
        }