Obelisk::Lexers::Ruby
Inherits Obelisk::RegexLexer < Obelisk::Lexer < Reference < Object
Ruby language lexer Optimized with regex constants and consolidated string handling
Constants
BACKTICK = /`/
BUILTINS = /\b(?:abort|at_exit|autoload|binding|caller|catch|chomp|chop|eval|exec|exit|fail|fork|gets|global_variables|gsub|lambda|load|local_variables|open|p|print|printf|proc|putc|puts|raise|rand|readline|readlines|require|require_relative|sleep|spawn|sprintf|srand|sub|syscall|system|test|throw|trap|warn)\b/
Built-in functions (simplified from ~60 to most common)
CLASS_NAME = /\b[A-Z][a-zA-Z0-9_]*\b/
CLASS_VAR = /@@[a-zA-Z_]\w*/
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_OCTAL = /\\[0-7]{1,3}/
ESCAPE_SIMPLE = /\\[\\\"'nrtbfav0]/
Escape sequences (consolidated for all string types)
ESCAPE_SINGLE_BACKSLASH = /\\[\\']/
ESCAPE_UNICODE = /\\u\{[0-9a-fA-F]+\}/
ESCAPE_UNICODE_SHORT = /\\u[0-9a-fA-F]{4}/
FUNCTION_CALL = /[a-zA-Z_]\w*[!?]?(?=\s*\()/
GLOBAL_VAR = /\$[a-zA-Z_]\w*/
GLOBAL_VAR_NUMBERED = /\$\d+/
GLOBAL_VAR_OPTION = /\$-[0adFiIlpvw]/
GLOBAL_VAR_SPECIAL = /\$[!@&`'+~=\/\\,;.<>_*$?:"]/
HASH_ROCKET = /=>/
HEREDOC_START = /<<[-~]?(['"]?)([A-Z_]+)\1/
Heredoc
IDENTIFIER = /[a-zA-Z_]\w*[!?]?/
INSTANCE_VAR = /@[a-zA-Z_]\w*/
Variables
INTERPOLATION_END = /\}/
INTERPOLATION_SIMPLE_GVAR = /#\$\w+/
INTERPOLATION_SIMPLE_IVAR = /#@@?\w+/
INTERPOLATION_START = /#\{/
Interpolation
KEYWORDS = /\b(?:BEGIN|END|alias|begin|break|case|class|def|defined\?|do|else|elsif|end|ensure|for|if|in|module|next|nil|redo|rescue|retry|return|self|super|then|undef|unless|until|when|while|yield)\b/
Keywords
LINE_COMMENT = /#.*?(?=\n|$)/
METHOD_DEF = /\b(def)(\s+)([a-zA-Z_]\w*[!?=]?)/
Method definitions and calls
NUMBER_BIN = /0b[01_]+/
Numbers
NUMBER_EXP = /\d+[eE][+-]?\d+/
NUMBER_FLOAT = /\d+\.\d+([eE][+-]?\d+)?/
NUMBER_HEX = /0x[0-9a-fA-F_]+/
NUMBER_INT = /\d+(_\d+)*/
NUMBER_OCT = /0o[0-7_]+/
OPERATOR_WORDS = /\b(?:and|not|or)\b/
Operator words
OPERATORS = /[+\-*\/%<>=!&|^~]+/
Operators
PERCENT_ANGLE_START = /%[qQ]?</
PERCENT_CURLY_START = /%[qQ]?\{/
Percent strings
PERCENT_OTHER_START = /%[qQ]?([^\w\s])/
PERCENT_PAREN_START = /%[qQ]?\(/
PERCENT_SQUARE_START = /%[qQ]?\[/
PSEUDO_VARIABLES = /\b(?:__FILE__|__LINE__|__ENCODING__)\b/
Pseudo-variables
PUNCTUATION = /[.,;:()\[\]{}]/
Punctuation
RANGE_OPERATOR = /\.\.\.?/
REGEX_LITERAL = /\/(?:[^\/\\\n]|\\.)+\/[mixounse]*/
Regular expressions
SHEBANG = /^!/
SINGLE_QUOTE = /'/
STRING_BACKTICK_CONTENT = /[^`\\#]+/
STRING_DOUBLE_CONTENT = /[^"\\#]+/
String content patterns
STRING_SINGLE_CONTENT = /[^'\\]+/
SYMBOL_DOUBLE = /:"/
SYMBOL_SIMPLE = /:(?:[a-zA-Z_]\w*[!?]?|[+\-*\/%<>=!&|^~]+)/
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