namespace Nuuru.Server.Services.BBCode { // ============ CONTEXT ============ /// /// Context for BBCode parsing to enable/disable certain features /// public enum BBCodeContext { /// /// Default context for booru comments - no attachments /// Comment, /// /// Forum context - enables [attachment] tags /// Forum } // ============ TOKENS ============ public abstract record BbToken; public record TextToken(string Content) : BbToken; public record NewlineToken() : BbToken; public record OpenTagToken(string Name, string? Attribute) : BbToken; public record OpenTagWithAttributesToken(string Name, Dictionary Attributes) : BbToken; public record CloseTagToken(string Name) : BbToken; // Line-start pattern tokens (marker only, parser handles content) public record GreentextToken(string Content) : BbToken; public record OrangetextToken(string Content) : BbToken; public record EmoteToken(string Name) : BbToken; // ============ AST NODES ============ public abstract class BbNode; public class TextNode(string content) : BbNode { public string Content { get; } = content; } public class NewlineNode : BbNode; public class ElementNode(string tag, string? attribute, List children) : BbNode { public string Tag { get; } = tag; public string? Attribute { get; } = attribute; public List Children { get; } = children; } public class ThumbNode(int postId) : BbNode { public int PostId { get; } = postId; } public class UrlNode(string href, List children) : BbNode { public string Href { get; } = href; public List Children { get; } = children; } public class QuoteNode( string sourceType, string sourceId, string? authorName, string? providedHash, List children) : BbNode { public string SourceType { get; } = sourceType; // "forum" or "comment" public string SourceId { get; } = sourceId; // GUID as string public string? AuthorName { get; } = authorName; public string? ProvidedHash { get; } = providedHash; public List Children { get; } = children; } public class MentionNode(Guid userId, string userName, int? postId = null, int? commentId = null) : BbNode { public Guid UserId { get; } = userId; public string UserName { get; } = userName; public int? PostId { get; } = postId; public int? CommentId { get; } = commentId; } public class AttachmentNode(Guid attachmentId, bool isThumbnail, int? width, int? height) : BbNode { public Guid AttachmentId { get; } = attachmentId; public bool IsThumbnail { get; } = isThumbnail; public int? Width { get; } = width; public int? Height { get; } = height; } public class EmoteNode(string name) : BbNode { public string Name { get; } = name; } }