using System; using YesNt.Interpreter.Enums; namespace YesNt.Interpreter.Attributes; /// /// Marks a method as a YesNt statement handler. /// The interpreter matches source lines against the keyword according to /// and rules, then invokes the decorated method /// with the remaining argument text. /// /// /// Methods decorated with this attribute must be instance methods on a class that inherits /// and must accept a single parameter. /// [AttributeUsage(AttributeTargets.Method, AllowMultiple = false)] public class StatementAttribute : Attribute { /// Gets the keyword that identifies this statement in source code. public string Name { get; } /// Gets where in the line the keyword is searched for. public SearchMode SearchMode { get; } /// Gets which sides of the keyword must be padded with a space. public SpaceAround SpaceAround { get; } /// Gets or sets the syntax-highlight color used by the code editor. public ConsoleColor Color { get; set; } /// /// Gets or sets the execution priority. Statements with a lower value /// run before those with a higher value. Defaults to . /// public Priority Priority { get; set; } = Priority.Normal; /// /// Gets or sets a value indicating whether this statement is still invoked while the interpreter /// is in search mode (scanning for a label or function definition). Defaults to . /// public bool ExecuteInSearchMode { get; set; } /// /// Gets or sets a value indicating whether the full current line (including the keyword itself) /// is passed as the argument, rather than stripping the keyword prefix/suffix first. /// Defaults to . /// public bool KeepStatementInArgs { get; set; } /// /// Gets a value indicating whether this statement should be excluded from syntax highlighting. /// Set to when no is provided. /// public bool IgnoreSyntaxHighlighting { get; } /// /// Gets or sets an optional sub-string that must also be present in the line for this statement /// to match. Used to differentiate overloaded keywords (e.g. call vs call … with …). /// public string Separator { get; set; } /// /// Gets or sets the name of the statement that marks the end of this block. /// Used for block boundary caching (e.g., "while" has BlockPair = "end_while"). /// public string BlockPair { get; set; } /// /// Gets or sets a value indicating whether this statement is the end of a block. /// Used for block boundary caching (e.g., "end_while" has IsBlockEnd = true). /// public bool IsBlockEnd { get; set; } /// /// Gets or sets a value indicating whether this statement is an intermediate part of a block /// (e.g., "else:" between "if" and "end_if"). /// public bool IsBlockIntermediate { get; set; } /// /// Initializes a new with a syntax-highlight color. /// /// The keyword that identifies this statement. /// Where in the line the keyword is matched. /// Which sides of the keyword require a surrounding space. /// The color used for syntax highlighting in the code editor. public StatementAttribute(string name, SearchMode searchMode, SpaceAround spaceAround, ConsoleColor color) { Name = name; SearchMode = searchMode; SpaceAround = spaceAround; Color = color; } /// /// Initializes a new without a syntax-highlight color. /// The statement will be excluded from syntax highlighting. /// /// The keyword that identifies this statement. /// Where in the line the keyword is matched. /// Which sides of the keyword require a surrounding space. public StatementAttribute(string name, SearchMode searchMode, SpaceAround spaceAround) { Name = name; SearchMode = searchMode; SpaceAround = spaceAround; IgnoreSyntaxHighlighting = true; } }