idTech4.Text.idLexer.ReadToken C# (CSharp) Method

ReadToken() public method

Reads the next token.
public ReadToken ( ) : idToken
return idToken
		public idToken ReadToken()
		{
			idToken token = new idToken();

			if(this.IsLoaded == false)
			{
				idConsole.Error("idLexer.ReadToken: no file loaded");
				return null;
			}

			// if there is a token available (from unreadToken)
			if(_tokenAvailable == true)
			{
				_tokenAvailable = false;
				return _token;
			}

			// save script position
			_lastScriptPosition = _scriptPosition;

			// save line counter
			_lastLine = _line;

			// start of the white space
			_whiteSpaceStartPosition = _scriptPosition;
			token.WhiteSpaceStartPosition = _scriptPosition;

			// read white space before token
			if(ReadWhiteSpace() == false)
			{
				return null;
			}

			// end of the white space
			_whiteSpaceEndPosition = _scriptPosition;
			token.WhiteSpaceEndPosition = _scriptPosition;

			// line the token is on
			token.Line = _line;

			// number of lines crossed before token
			token.LinesCrossed = _line - _lastLine;
			token.Options = 0;

			char c = GetBufferCharacter(_scriptPosition);

			// if we're keeping everything as whitespace deliminated strings
			if((_options & LexerOptions.OnlyStrings) == LexerOptions.OnlyStrings)
			{
				// if there is a leading quote
				if((c == '"') || (c == '\''))
				{
					if(ReadString(token, c) == false)
					{
						return null;
					}
				}
				else if(ReadName(token) == false)
				{
					return null;
				}
			}
			// if there is a number
			else if(((c >= '0') && (c <= '9')) 
				|| ((c == '.') && ((GetBufferCharacter(_scriptPosition + 1) >= '0') && (GetBufferCharacter(_scriptPosition + 1) <= '9'))))
			{
				if(ReadNumber(token) == false)
				{
					return null;
				}

				// if names are allowed to start with a number
				if((_options & LexerOptions.AllowNumberNames) == LexerOptions.AllowNumberNames)
				{
					c = GetBufferCharacter(_scriptPosition);

					if(((c >= 'a') && (c <= 'z')) || ((c >= 'A') && (c <= 'Z')) || (c == '_'))
					{
						if(ReadName(token) == false)
						{
							return null;
						}
					}
				}
			}
			// if there is a leading quote
			else if((c == '"') || (c == '\''))
			{
				if(ReadString(token, c) == false)
				{
					return null;
				}
			}
			// if there is a name
			else if(((c >= 'a') && (c <= 'z')) || ((c >= 'A') && (c <= 'Z')) || (c == '_'))
			{
				if(ReadName(token) == false)
				{
					return null;
				}
			}
			// names may also start with a slash when pathnames are allowed
			else if(((_options & LexerOptions.AllowPathNames) == LexerOptions.AllowPathNames) && ((c == '/') || (c == '\\') || (c == '.')))
			{
				if(ReadName(token) == false)
				{
					return null;
				}
			}
			// check for punctuations
			else if(ReadPunctuation(token) == false)
			{
				Error("unknown punctuation {0}", c);
				return null;
			}

			// succesfully read a token
			return token;
		}

Usage Example

		private void ParseJoint(idLexer lexer, idMD5Joint joint, ref idJointQuaternion defaultPose)
		{
			//
			// parse name
			//
			joint.Name = lexer.ReadToken().ToString();

			//
			// parse parent
			//
			int parentIndex = lexer.ParseInt();

			if(parentIndex >= 0)
			{
				if(parentIndex >= (_joints.Length - 1))
				{
					lexer.Error("Invalid parent for joint '{0}'", joint.Name);
				}

				joint.Parent = _joints[parentIndex];
			}
		
			//
			// parse default pose
			//
			float[] tmp = lexer.Parse1DMatrix(3);
			defaultPose.Translation = new Vector3(tmp[0], tmp[1], tmp[2]);

			tmp = lexer.Parse1DMatrix(3);
			defaultPose.Quaternion = new Quaternion(tmp[0], tmp[1], tmp[2], 0);
			defaultPose.Quaternion.W = idHelper.CalculateW(defaultPose.Quaternion);
		}
All Usage Examples Of idTech4.Text.idLexer::ReadToken