// Port of Go conf/lex.go token types. using System.Text.Json; namespace NATS.Server.Configuration; public enum TokenType { Error, Eof, Key, Text, String, Bool, Integer, Float, DateTime, ArrayStart, ArrayEnd, MapStart, MapEnd, Variable, Include, Comment, } public readonly record struct Token(TokenType Type, string Value, int Line, int Position); /// /// Pedantic token wrapper matching Go conf/parse.go token accessors. /// public sealed class PedanticToken { private readonly Token _item; private readonly object? _value; private readonly bool _usedVariable; private readonly string _sourceFile; /// /// Creates a parser token wrapper that preserves resolved value and source metadata. /// /// Raw lexer token captured from the configuration source. /// Optional parsed value override when token text has been normalized. /// Indicates whether this token originated from variable substitution. /// Source file path associated with this token, when available. public PedanticToken(Token item, object? value = null, bool usedVariable = false, string sourceFile = "") { _item = item; _value = value; _usedVariable = usedVariable; _sourceFile = sourceFile ?? string.Empty; } /// /// Serializes the token value into JSON, matching Go parser diagnostics formatting. /// public string MarshalJson() => JsonSerializer.Serialize(Value()); /// /// Returns the resolved token value, or raw token text when no typed value is stored. /// public object? Value() => _value ?? _item.Value; /// /// Returns the 1-based source line where the token was parsed. /// public int Line() => _item.Line; /// /// Returns whether variable interpolation contributed to this token. /// public bool IsUsedVariable() => _usedVariable; /// /// Returns the source file path associated with this token. /// public string SourceFile() => _sourceFile; /// /// Returns the 1-based character position of the token on its source line. /// public int Position() => _item.Position; }