Exemple #1
0
        public bool Parse(idScriptParser parser)
        {
            // first token should be function call
            // then a potentially variable set of parms
            // ended with a ;
            idToken    token;
            GuiCommand cmd = new GuiCommand();

            if ((token = parser.ReadToken()) == null)
            {
                parser.Error("Unexpected end of file");
                return(false);
            }

            _handler = null;

            string tokenLower = token.ToString().ToLower();

            foreach (GuiCommand tmp in CommandList)
            {
                if (tmp.Name.ToLower() == tokenLower)
                {
                    _handler = tmp.Handler;
                    cmd      = tmp;
                    break;
                }
            }

            if (_handler == null)
            {
                parser.Error("Unknown script call {0}", token.ToString());
            }

            // now read parms til ;
            // all parms are read as idWinStr's but will be fixed up later
            // to be proper types
            while (true)
            {
                if ((token = parser.ReadToken()) == null)
                {
                    parser.Error("Unexpected end of file");
                    return(false);
                }

                tokenLower = token.ToString().ToLower();

                if (tokenLower == ";")
                {
                    break;
                }
                else if (tokenLower == "}")
                {
                    parser.UnreadToken(token);
                    break;
                }

                idWinString str = new idWinString(string.Empty);
                str.Set(token.ToString());

                _parameters.Add(new idWinGuiScript(true, str));
            }

            //
            //  verify min/max params
            if ((_handler != null) && ((_parameters.Count < cmd.MinParameterCount) || (_parameters.Count > cmd.MaxParameterCount)))
            {
                parser.Error("incorrect number of parameters for script {0}", cmd.Name);
            }
            //

            return(true);
        }
Exemple #2
0
		public bool Parse(idScriptParser parser)
		{
			// first token should be function call
			// then a potentially variable set of parms
			// ended with a ;
			idToken token;
			GuiCommand cmd = new GuiCommand();

			if((token = parser.ReadToken()) == null)
			{
				parser.Error("Unexpected end of file");
				return false;
			}

			_handler = null;

			string tokenLower = token.ToString().ToLower();

			foreach(GuiCommand tmp in CommandList)
			{
				if(tmp.Name.ToLower() == tokenLower)
				{
					_handler = tmp.Handler;
					cmd = tmp;
					break;
				}
			}

			if(_handler == null)
			{
				parser.Error("Unknown script call {0}", token.ToString());
			}

			// now read parms til ;
			// all parms are read as idWinStr's but will be fixed up later 
			// to be proper types
			while(true)
			{
				if((token = parser.ReadToken()) == null)
				{
					parser.Error("Unexpected end of file");
					return false;
				}

				tokenLower = token.ToString().ToLower();

				if(tokenLower == ";")
				{
					break;
				}
				else if(tokenLower == "}")
				{
					parser.UnreadToken(token);
					break;
				}

				idWinString str = new idWinString(string.Empty);
				str.Set(token.ToString());

				_parameters.Add(new idWinGuiScript(true, str));
			}

			// 
			//  verify min/max params
			if((_handler != null) && ((_parameters.Count < cmd.MinParameterCount) || (_parameters.Count > cmd.MaxParameterCount)))
			{
				parser.Error("incorrect number of parameters for script {0}", cmd.Name);
			}
			// 

			return true;
		}