Obelisk::Lexers::Crystal
Inherits Obelisk::RegexLexer < Obelisk::Lexer < Reference < Object
Crystal language lexer Optimized with regex constants and consolidated string handling
Constants
ANNOTATION_END = /\]/
ANNOTATION_START = /@\[/
Annotations
BACKTICK = /`/
BUILTIN_TYPES = /\b(?:Array|Bool|Char|Float32|Float64|Hash|Int8|Int16|Int32|Int64|Nil|Number|Object|Proc|Range|Regex|Set|String|Symbol|Time|Tuple|UInt8|UInt16|UInt32|UInt64|Void)\b/
Built-in types
CHAR_LITERAL = /'(?:[^'\\]|\\.)'/
Character literals
CLASS_NAME = /\b[A-Z][a-zA-Z0-9_]*\b/
CLASS_VAR = /@@[a-zA-Z_][a-zA-Z0-9_]*/
CONSTANT = /\b[A-Z][A-Z0-9_]*\b/
Constants and class names
DOUBLE_QUOTE = /"/
String delimiters
ESCAPE_ANY = /\\./
ESCAPE_HEX = /\\x[0-9a-fA-F]{2}/
ESCAPE_SIMPLE = /\\[\\\"'nrtbfav0]/
Escape sequences (consolidated for all string types)
ESCAPE_UNICODE = /\\u\{[0-9a-fA-F]+\}/
FUNCTION_CALL = /[a-zA-Z_][a-zA-Z0-9_]*[!?]?(?=\s*\()/
GLOBAL_VAR = /\$[a-zA-Z_][a-zA-Z0-9_]*/
HEREDOC_START = /<<-([A-Z_]+)/
Heredoc
IDENTIFIER = /[a-zA-Z_][a-zA-Z0-9_]*[!?]?/
INSTANCE_VAR = /@[a-zA-Z_][a-zA-Z0-9_]*/
Variables
INTERPOLATION_END = /\}/
INTERPOLATION_START = /#\{/
Interpolation
KEYWORDS = /\b(?:abstract|alias|annotation|as|asm|begin|break|case|class|def|do|else|elsif|end|ensure|enum|extend|false|for|fun|if|in|include|instance_sizeof|is_a\?|lib|macro|module|next|nil|of|out|pointerof|private|protected|require|rescue|return|select|self|sizeof|struct|super|then|true|type|typeof|uninitialized|union|unless|until|when|while|with|yield)\b/
Keywords
LINE_COMMENT = /#.*?(?=\n|$)/
METHOD_DEF = /\b(def)(\s+)([a-zA-Z_][a-zA-Z0-9_]*[!?]?)/
Method definitions and calls
NUMBER_BIN = /0b[01]+(_[01]+)*([ui](8|16|32|64))?/
Numbers
NUMBER_FLOAT = /\d+(\.\d+)?([eE][+-]?\d+)?(f32|f64)?/
NUMBER_HEX = /0x[0-9a-fA-F]+(_[0-9a-fA-F]+)*([ui](8|16|32|64))?/
NUMBER_INT = /\d+(_\d+)*([ui](8|16|32|64))?/
NUMBER_OCT = /0o[0-7]+(_[0-7]+)*([ui](8|16|32|64))?/
OPERATORS = /[+\-*\/%<>=!&|^~]+/
Operators
PUNCTUATION = /[.,;:()\[\]{}]/
Punctuation
REGEX_LITERAL = /\/(?:[^\/\\\n]|\\.)+\/[imx]*/
Regular expressions
SINGLE_QUOTE = /'/
STRING_BACKTICK_CONTENT = /[^`\\]+/
STRING_DOUBLE_CONTENT = /[^\"\\#]+/
String content patterns
STRING_SINGLE_CONTENT = /[^\'\\]+/
SYMBOL_DOUBLE = /:\"/
SYMBOL_SIMPLE = /:(?:[a-zA-Z_][a-zA-Z0-9_]*[!?]?|[+\-*\/%<>=!&|^~]+)/
Symbols
SYMBOL_SINGLE = /:\'/
WHITESPACE = /\s+/
Whitespace and comments
Instance methods
Analyze text to determine if this lexer can handle it Returns a score from 0.0 to 1.0
config
Sourcerules
Source