/// <summary> /// Tries to get the constant string value of a given token type. This method will return false for types that don't /// map to a constant string value. /// </summary> /// <param name="type">The type to lookup</param> /// <param name="val">The literal string value expected of a token of the given type</param> /// <returns>true if 'val' was populated, false otherwise</returns> public static bool TryGetTokenTypeValue(DocumentTokenType type, out string val) { if (type == DocumentTokenType.BeginReplacementSegment) { val = "{{"; } else if (type == DocumentTokenType.EndReplacementSegment) { val = "}}"; } else if (type == DocumentTokenType.QuickTerminateReplacementSegment) { val = "!}}"; } else if (type == DocumentTokenType.BeginTerminateReplacementSegment) { val = "!{{"; } else { val = null; return(false); } return(true); }
/// <summary> /// Tries to parse a literal string value to a well known document token type. /// </summary> /// <param name="stringVal">The value to try to parse</param> /// <param name="type">The reference to populate if parsing is successful</param> /// <returns>True if the string could be successfully mapped to a DocumentTokenType, false otherwise</returns> public static bool TryParseDocumentTokenType(string stringVal, out DocumentTokenType type) { if (stringVal == "{{") { type = DocumentTokenType.BeginReplacementSegment; } else if (stringVal == "}}") { type = DocumentTokenType.EndReplacementSegment; } else if (stringVal == "!}}") { type = DocumentTokenType.QuickTerminateReplacementSegment; } else if (stringVal == "!{{") { type = DocumentTokenType.BeginTerminateReplacementSegment; } else { type = default(DocumentTokenType); return(false); } return(true); }
/// <summary> /// Gets the constant string value of a given token type. This method will throw an exception if the /// type provided does not map to a constant string value. /// </summary> /// <param name="type">The type to lookup</param> /// <returns>The literal string value expected of a token of the given type</returns> public static string GetTokenTypeValue(DocumentTokenType type) { string ret; if (TryGetTokenTypeValue(type, out ret) == false) { throw new ArgumentException("The type '" + type + "' does not have a constant string value"); } return(ret); }
private DocumentToken AdvanceAndExpect(TokenReader <DocumentToken> reader, DocumentTokenType expectedType, string expectedText, bool skipWhitespace = false) { DocumentToken read; if (reader.TryAdvance(out read, skipWhitespace: skipWhitespace) == false) { throw Unexpected(expectedText); } if (read.TokenType != expectedType) { throw Unexpected(expectedText, read); } return(read); }
/// <summary> /// Tries to parse a literal string value to a well known document token type. /// </summary> /// <param name="stringVal">The value to try to parse</param> /// <param name="type">The reference to populate if parsing is successful</param> /// <returns>True if the string could be successfully mapped to a DocumentTokenType, false otherwise</returns> public static bool TryParseDocumentTokenType(string stringVal, out DocumentTokenType type) { if (stringVal == "{{") { type = DocumentTokenType.BeginReplacementSegment; } else if (stringVal == "}}") { type = DocumentTokenType.EndReplacementSegment; } else if (stringVal == "!}}") { type = DocumentTokenType.QuickTerminateReplacementSegment; } else if (stringVal == "!{{") { type = DocumentTokenType.BeginTerminateReplacementSegment; } else { type = default(DocumentTokenType); return false; } return true; }
/// <summary> /// Tries to get the constant string value of a given token type. This method will return false for types that don't /// map to a constant string value. /// </summary> /// <param name="type">The type to lookup</param> /// <param name="val">The literal string value expected of a token of the given type</param> /// <returns>true if 'val' was populated, false otherwise</returns> public static bool TryGetTokenTypeValue(DocumentTokenType type, out string val) { if (type == DocumentTokenType.BeginReplacementSegment) { val = "{{"; } else if(type == DocumentTokenType.EndReplacementSegment) { val = "}}"; } else if(type == DocumentTokenType.QuickTerminateReplacementSegment) { val = "!}}"; } else if(type == DocumentTokenType.BeginTerminateReplacementSegment) { val = "!{{"; } else { val = null; return false; } return true; }
/// <summary> /// Gets the constant string value of a given token type. This method will throw an exception if the /// type provided does not map to a constant string value. /// </summary> /// <param name="type">The type to lookup</param> /// <returns>The literal string value expected of a token of the given type</returns> public static string GetTokenTypeValue(DocumentTokenType type) { string ret; if(TryGetTokenTypeValue(type, out ret) == false) { throw new ArgumentException("The type '"+type+"' does not have a constant string value"); } return ret; }
private DocumentToken AdvanceAndExpectConstantType(TokenReader <DocumentToken> reader, DocumentTokenType expectedType) { DocumentToken read; if (reader.TryAdvance(out read, skipWhitespace: true) == false) { throw Unexpected(DocumentToken.GetTokenTypeValue(expectedType)); } if (read.TokenType != expectedType) { throw Unexpected(DocumentToken.GetTokenTypeValue(expectedType), read); } return(read); }
private DocumentToken AdvanceAndExpectConstantType(TokenReader<DocumentToken> reader, DocumentTokenType expectedType) { DocumentToken read; if(reader.TryAdvance(out read,skipWhitespace: true) == false) { throw Unexpected(DocumentToken.GetTokenTypeValue(expectedType)); } if (read.TokenType != expectedType) { throw Unexpected(DocumentToken.GetTokenTypeValue(expectedType), read); } return read; }
private DocumentToken AdvanceAndExpect(TokenReader<DocumentToken> reader, DocumentTokenType expectedType, string expectedText, bool skipWhitespace = false) { DocumentToken read; if(reader.TryAdvance(out read,skipWhitespace: skipWhitespace) == false) { throw Unexpected(expectedText); } if (read.TokenType != expectedType) { throw Unexpected(expectedText, read); } return read; }