Token ReadToken() { while (_tokenStack.Count == 0) { if (_fbxAsciiFileInfo.IsEndOfStream()) { _tokenStack.Push(Token.CreateEndOfStream()); } else if (AsciiTokenParser.TryConsumeWhiteSpace(_fbxAsciiFileInfo)) { continue; } else if (AsciiTokenParser.TryParseCommentToken(_fbxAsciiFileInfo, out var _)) { continue; } else if (AsciiTokenParser.TryParseOperatorToken(_fbxAsciiFileInfo, out var operatorToken)) { _tokenStack.Push(operatorToken); } else if (AsciiTokenParser.TryParseNumberToken(_fbxAsciiFileInfo, out var numberToken)) { _tokenStack.Push(numberToken); } else if (AsciiTokenParser.TryParseStringToken(_fbxAsciiFileInfo, out var stringToken)) { _tokenStack.Push(stringToken); } else if (AsciiTokenParser.TryParseIdentifierOrCharToken(_fbxAsciiFileInfo, out var token)) { _tokenStack.Push(token); } else { throw new FbxException(_fbxAsciiFileInfo, $"Unknown character {_fbxAsciiFileInfo.PeekChar()}"); } } return(_tokenStack.Pop()); }
/// <summary> /// Reads a full document from the stream /// </summary> /// <returns>The complete document object</returns> public FbxDocument Read() { var ret = new FbxDocument(); // Read version string const string versionString = @"; FBX (\d)\.(\d)\.(\d) project file"; AsciiTokenParser.TryConsumeWhiteSpace(_fbxAsciiFileInfo); bool hasVersionString = false; if (AsciiTokenParser.TryParseCommentToken(_fbxAsciiFileInfo, out var commentToken)) { var match = Regex.Match(commentToken.Value, versionString); hasVersionString = match.Success; if (hasVersionString) { ret.Version = (FbxVersion)( int.Parse(match.Groups[1].Value) * 1000 + int.Parse(match.Groups[2].Value) * 100 + int.Parse(match.Groups[3].Value) * 10 ); } } if (!hasVersionString && _errorLevel >= ErrorLevel.Strict) { throw new FbxException(_fbxAsciiFileInfo, "Invalid version string; first line must match \"" + versionString + "\""); } FbxNode node; while ((node = ReadNode()) != null) { ret.AddNode(node); } return(ret); }