SboxSuperuser/Api/CommandTokenization.cs

A small wrapper type that exposes the result of a command tokenization operation. It stores an immutable list of decoded tokens and a safe error string if tokenization failed, and exposes IsSuccess derived from Error being null.

using SboxSuperuser.Core.Commands;

namespace SboxSuperuser;

/// <summary>Bounded tokenization result; malformed input returns no partial tokens.</summary>
public sealed class CommandTokenization
{
	/// <summary>Gets whether the complete input was accepted.</summary>
	public bool IsSuccess => Error is null;

	/// <summary>Gets immutable decoded tokens, including explicit empty quoted tokens.</summary>
	public IReadOnlyList<string> Tokens { get; }

	/// <summary>Gets a safe grammar error, or null on success.</summary>
	public string Error { get; }

	internal CommandTokenization( Tokenization result )
	{
		Tokens = result.Tokens;
		Error = result.Error;
	}
}