private void CheckIdentifierAfterTrim(string identifier, IdentifierParseOptions options) { if (!IsValidIdentifier(identifier, options)) { throw FormatException(ProjectTreeFormatError.IdExpected_EncounteredOnlyWhiteSpace, "Expected identifier, but encountered only white space."); } }
private bool IsValidIdentifier(string identifier, IdentifierParseOptions options) { if ((options & IdentifierParseOptions.Required) == IdentifierParseOptions.Required) { return(identifier.Length != 0); } return(true); }
public string ReadIdentifier(IdentifierParseOptions options) { string identifier = ReadIdentifierCore(options); CheckIdentifier(identifier, options); identifier = identifier.TrimEnd((char)TokenType.WhiteSpace); CheckIdentifierAfterTrim(identifier, options); return(identifier); }
private void CheckIdentifier(string identifier, IdentifierParseOptions options) { if (IsValidIdentifier(identifier, options)) { return; } // Are we at the end of the string? Token?token = ReadToken(); // Consume token, so "position" is correct if (token == null) { throw FormatException(ProjectTreeFormatError.IdExpected_EncounteredEndOfString, $"Expected identifier, but encountered end-of-string."); } // Otherwise, we must have hit a delimiter as whitespace will have been consumed as part of the identifier throw FormatException(ProjectTreeFormatError.IdExpected_EncounteredDelimiter, $"Expected identifier, but encountered '{token.Value.Value}'."); }
private string ReadIdentifierCore(IdentifierParseOptions options) { StringBuilder identifier = new StringBuilder(); Token?token; while ((token = PeekToken()) != null) { Token t = token.Value; if (t.IsDelimiter) { break; } ReadToken(); identifier.Append(t.Value); } return(identifier.ToString()); }