using System.Diagnostics.CodeAnalysis;
Console.Write(new Lexer("56 ").MakeToken());
public string MakeToken()
StringBuilder str = new("[");
if (currChar is null) Advance();
StringBuilder num = new("");
while (currChar is not null)
if(int.TryParse($"{currChar}", out _))
Token integer = Token.Int.With(value: int.
Parse(num.ToString()).ToString());
str.Append(integer.ToString() + ", ");
str.Remove(str.Length - 2, str.Length);
public char? Advance(ushort count = 1)
pos = pos + count < text.Length? pos + count: null;
currChar = int.TryParse($"{pos}", out var p)? text[p]: null;
public static readonly Token Int = new("INT");
public string TokenType { get; init; }
public string? Value { get; init; }
public Token([NotNull] string tokenType, string? value = null)
public Token With(string? tt = null, string? value = null) => new()
TokenType = tt ?? this.TokenType, Value = value
public override string ToString() => Value is null?
TokenType: $"{TokenType}: {Value}";