public static bool TryParseOperatorToken(FbxAsciiFileInfo fbxAsciiFileInfo, out Token operatorToken) { var c = fbxAsciiFileInfo.PeekChar(); if (c.Equals('{')) { operatorToken = Token.CreateOpenBrace(); } else if (c.Equals('}')) { operatorToken = Token.CreateCloseBrace(); } else if (c.Equals('*')) { operatorToken = Token.CreateAsterix(); } else if (c.Equals(',')) { operatorToken = Token.CreateComma(); } else { operatorToken = null; return(false); } fbxAsciiFileInfo.ReadChar(); return(true); }
public static bool TryParseStringToken(FbxAsciiFileInfo fbxAsciiFileInfo, out StringToken stringToken) { var c = fbxAsciiFileInfo.PeekChar(); if (c != '"') { stringToken = null; return(false); } fbxAsciiFileInfo.ReadChar(); var stringBuilder = new StringBuilder(); while (fbxAsciiFileInfo.PeekChar() != '"') { stringBuilder.Append(fbxAsciiFileInfo.ReadChar()); if (fbxAsciiFileInfo.IsEndOfStream()) { throw new FbxException(fbxAsciiFileInfo, "Unexpected end of stream; expecting end quote"); } } fbxAsciiFileInfo.ReadChar(); stringToken = new StringToken(stringBuilder.ToString()); return(true); }
public static bool TryParseNumberToken(FbxAsciiFileInfo fbxAsciiFileInfo, out Token numberToken) { var c = fbxAsciiFileInfo.PeekChar(); var isFirst = true; if (!c.IsDigit(isFirst)) { numberToken = null; return(false); } var stringBuilder = new StringBuilder(); while (c.IsDigit(isFirst) && !fbxAsciiFileInfo.IsEndOfStream()) { stringBuilder.Append(fbxAsciiFileInfo.ReadChar()); isFirst = false; c = fbxAsciiFileInfo.PeekChar(); } var value = stringBuilder.ToString(); if (!value.TryParseNumberToken(out numberToken)) { throw new FbxException(fbxAsciiFileInfo, $"Invalid number '{value}'"); } return(true); }
public static bool TryParseLiteralToken(this Stream stream, FbxAsciiFileInfo fbxAsciiFileInfo, out string literal) { var c = PeekChar(stream, fbxAsciiFileInfo); if (c != '"') { literal = null; return(false); } stream.ReadChar(fbxAsciiFileInfo); var stringBuilder = new StringBuilder(); while (stream.PeekChar(fbxAsciiFileInfo) != '"') { stringBuilder.Append(stream.ReadChar(fbxAsciiFileInfo)); if (stream.IsEndOfStream()) { throw new FbxException(fbxAsciiFileInfo, "Unexpected end of stream; expecting end quote"); } } stream.ReadChar(fbxAsciiFileInfo); literal = stringBuilder.ToString(); return(true); }
public static char PeekChar(this Stream stream, FbxAsciiFileInfo fbxAsciiFileInfo) { if (fbxAsciiFileInfo.PeekedChar != '\0') { return(fbxAsciiFileInfo.PeekedChar); } return(GetChar(stream, fbxAsciiFileInfo)); }
public static bool TryParseOperatorToken(this Stream stream, FbxAsciiFileInfo fbxAsciiFileInfo, out char op) { var c = PeekChar(stream, fbxAsciiFileInfo); if (!"{}*:,".Contains(c.ToString())) { op = '\0'; return(false); } op = stream.ReadChar(fbxAsciiFileInfo); return(true); }
public static char ReadChar(this Stream stream, FbxAsciiFileInfo fbxAsciiFileInfo) { char c; if (fbxAsciiFileInfo.PeekedChar != '\0') { c = fbxAsciiFileInfo.PeekedChar; fbxAsciiFileInfo.PeekedChar = '\0'; return(c); } c = GetChar(stream, fbxAsciiFileInfo); fbxAsciiFileInfo.Column++; return(c); }
public static bool TryConsumeWhiteSpace(FbxAsciiFileInfo fbxAsciiFileInfo) { var c = fbxAsciiFileInfo.PeekChar(); if (!(char.IsWhiteSpace(c) || c.IsLineEnd())) { return(false); } var stringBuilder = new StringBuilder(); while ((char.IsWhiteSpace(c) || c.IsLineEnd()) && !fbxAsciiFileInfo.IsEndOfStream()) { stringBuilder.Append(fbxAsciiFileInfo.ReadChar()); c = fbxAsciiFileInfo.PeekChar(); } return(true); }
public static bool TryParseCommentToken(FbxAsciiFileInfo fbxAsciiFileInfo, out CommentToken commentToken) { var c = fbxAsciiFileInfo.PeekChar(); if (c != ';') { commentToken = null; return(false); } var stringBuilder = new StringBuilder(); while (!c.IsLineEnd() && !fbxAsciiFileInfo.IsEndOfStream()) { stringBuilder.Append(fbxAsciiFileInfo.ReadChar()); c = fbxAsciiFileInfo.PeekChar(); } commentToken = new CommentToken(stringBuilder.ToString()); return(true); }
public static bool TryParseCommentToken(this Stream stream, FbxAsciiFileInfo fbxAsciiFileInfo, out string comment) { var c = PeekChar(stream, fbxAsciiFileInfo); if (c != ';') { comment = null; return(false); } var stringBuilder = new StringBuilder(); while (!c.IsLineEnd() && !stream.IsEndOfStream()) { stringBuilder.Append(stream.ReadChar(fbxAsciiFileInfo)); c = stream.PeekChar(fbxAsciiFileInfo); } comment = stringBuilder.ToString(); return(true); }
public static bool TryParseIdentifierToken(this Stream stream, FbxAsciiFileInfo fbxAsciiFileInfo, out string identifier) { var c = PeekChar(stream, fbxAsciiFileInfo); if (!c.IsIdentifierChar()) { identifier = null; return(false); } var stringBuilder = new StringBuilder(); while (c.IsIdentifierChar() && !stream.IsEndOfStream()) { stringBuilder.Append(stream.ReadChar(fbxAsciiFileInfo)); c = stream.PeekChar(fbxAsciiFileInfo); } identifier = stringBuilder.ToString(); return(true); }
public static bool TryParseIdentifierOrCharToken(FbxAsciiFileInfo fbxAsciiFileInfo, out Token token) { var c = fbxAsciiFileInfo.PeekChar(); if (!c.IsIdentifierChar()) { token = null; return(false); } var stringBuilder = new StringBuilder(); while (c.IsIdentifierChar() && !fbxAsciiFileInfo.IsEndOfStream()) { stringBuilder.Append(fbxAsciiFileInfo.ReadChar()); c = fbxAsciiFileInfo.PeekChar(); } TryConsumeWhiteSpace(fbxAsciiFileInfo); var identifier = stringBuilder.ToString(); if (fbxAsciiFileInfo.PeekChar() == ':') { fbxAsciiFileInfo.ReadChar(); token = new IdentifierToken(identifier); return(true); } if (identifier.Equals("T") || identifier.Equals("F") || identifier.Equals("Y") || identifier.Equals("N")) { token = new BooleanToken(identifier.Equals("T") || identifier.Equals("Y")); return(true); } throw new FbxException(fbxAsciiFileInfo, "Unexpected '" + identifier + "', expected ':' or a single-char literal"); }
public static bool TryParseWhiteSpaceToken(this Stream stream, FbxAsciiFileInfo fbxAsciiFileInfo, out string whitespace) { var c = PeekChar(stream, fbxAsciiFileInfo); if (!(char.IsWhiteSpace(c) || c.IsLineEnd())) { whitespace = null; return(false); } var stringBuilder = new StringBuilder(); while ((char.IsWhiteSpace(c) || c.IsLineEnd()) && !stream.IsEndOfStream()) { if (stream.ReadChar(fbxAsciiFileInfo) == '\n') { fbxAsciiFileInfo.Column = 0; fbxAsciiFileInfo.Line++; } c = stream.PeekChar(fbxAsciiFileInfo); } whitespace = stringBuilder.ToString(); return(true); }
private static char GetChar(Stream stream, FbxAsciiFileInfo fbxAsciiFileInfo) { stream.Read(fbxAsciiFileInfo.Buffer, 0, 1); fbxAsciiFileInfo.PeekedChar = (char)fbxAsciiFileInfo.Buffer[0]; return(fbxAsciiFileInfo.PeekedChar); }