private static string FormatMessage(IHoconLineInfo lineInfo, HoconPath path, string message) { var sb = new StringBuilder(); // don't add a fullstop and space when message ends with a new line if (!message.EndsWith(Environment.NewLine, StringComparison.Ordinal)) { sb.Append(message.Trim()); if (!message.EndsWith(".")) { sb.Append("."); } sb.Append(" "); } var addComma = false; if (path != null) { sb.Append(string.Format(CultureInfo.InvariantCulture, "At path '{0}'", path)); addComma = true; } if (lineInfo != null) { sb.Append(addComma ? ", " : "At "); sb.Append(string.Format(CultureInfo.InvariantCulture, "line {0}, position {1}", lineInfo.LineNumber, lineInfo.LinePosition)); } sb.Append("."); return(sb.ToString()); }
public Token(string value, TokenType type, TokenLiteralType literalType, IHoconLineInfo source) { Type = type; LiteralType = literalType; Value = value; if (source != null) { LineNumber = source.LineNumber; LinePosition = source.LinePosition - (value?.Length ?? 0); } }
/// <summary> /// Initializes a new instance of the <see cref="HoconSubstitution" /> class. /// </summary> /// <param name="parent">The <see cref="HoconValue" /> parent of this substitution.</param> /// <param name="path">The <see cref="HoconPath" /> that this substitution is pointing to.</param> /// <param name="required">Marks wether this substitution uses the ${? notation or not.</param> /// /// /// <param name="lineInfo">The <see cref="IHoconLineInfo" /> of this substitution, used for exception generation purposes.</param> internal HoconSubstitution(IHoconElement parent, HoconPath path, IHoconLineInfo lineInfo, bool required) { if (parent == null) { throw new ArgumentNullException(nameof(parent), "HoconSubstitution parent can not be null."); } if (!(parent is HoconValue)) { throw new HoconException("HoconSubstitution parent must be HoconValue."); } Parent = parent; LinePosition = lineInfo.LinePosition; LineNumber = lineInfo.LineNumber; Required = required; Path = path; _parentsToResolveFor.Add(Parent as HoconValue); }
public static Token Error(IHoconLineInfo source) { return(new Token("", TokenType.Error, TokenLiteralType.None, source)); }
public static Token Include(string path, IHoconLineInfo source) { return(new Token(path, TokenType.Include, TokenLiteralType.None, source)); }
public static Token TripleQuotedLiteralValue(string value, IHoconLineInfo source) { return(LiteralValue(value, TokenLiteralType.TripleQuotedLiteralValue, source)); }
/// <summary> /// Creates a string literal token with a given <paramref name="value"/>. /// </summary> /// <param name="value">The value to associate with this token.</param> /// <param name="literalType">The <see cref="TokenLiteralType"/> of this <see cref="Token"/>.</param> /// <param name="source">The <see cref="IHoconLineInfo"/> of this <see cref="Token"/>, used for exception generation purposes.</param> /// <returns>A string literal token with the given value.</returns> public static Token LiteralValue(string value, TokenLiteralType literalType, IHoconLineInfo source) { return(new Token(value, TokenType.LiteralValue, literalType, source)); }
/* * /// <summary> * /// Initializes a new instance of the <see cref="Token"/> class. * /// </summary> * /// <param name="type">The type of token to associate with.</param> * /// <param name="source">The <see cref="IHoconLineInfo"/> of this <see cref="Token"/>, used for exception generation purposes.</param> * public Token(TokenType type, IHoconLineInfo source) * : this(null, type, TokenLiteralType.None, source) * { } */ /// <summary> /// Creates a substitution token with a given <paramref name="path"/>. /// </summary> /// <param name="path">The path to associate with this token.</param> /// <param name="source">The <see cref="IHoconLineInfo"/> of this <see cref="Token"/>, used for exception generation purposes.</param> /// <param name="questionMarked">Designate whether the substitution <see cref="Token"/> was declared as `${?`.</param> /// <returns>A substitution token with the given path.</returns> public static Token Substitution(string path, IHoconLineInfo source, bool questionMarked) { return(new Token(path, questionMarked ? TokenType.SubstituteOptional : TokenType.SubstituteRequired, TokenLiteralType.None, source)); }
public Token(string value, TokenType type, IHoconLineInfo source) : this(value, type, TokenLiteralType.None, source) { }
internal static HoconParserException Create(IHoconLineInfo lineInfo, HoconPath path, string message, Exception ex) { message = FormatMessage(lineInfo, path, message); return(new HoconParserException(lineInfo, message, ex)); }
internal static HoconParserException Create(IHoconLineInfo lineInfo, HoconPath path, string message) { return(Create(lineInfo, path, message, null)); }
internal HoconParserException(IHoconLineInfo info, string message, Exception innerException) : base(message, innerException) { LineNumber = info.LineNumber; LinePosition = info.LinePosition; }
internal HoconParserException(IHoconLineInfo info) { LineNumber = info.LineNumber; LinePosition = info.LinePosition; }