Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions assets/highlighting-tests/ruby.rb
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,9 @@
'single quotes with escape: \' \n \t \\'
"double quotes with escape: \" \n \t \\"
"interpolated: #{1 + 1} and a # that is not a comment"
"escaped \#{1 + 1} is not interpolated"
`echo shell command`
`echo #{Time.now}`

# Symbols and variables
:symbol
Expand Down
25 changes: 18 additions & 7 deletions crates/lsh/definitions/ruby.lsh
Original file line number Diff line number Diff line change
Expand Up @@ -27,30 +27,41 @@ pub fn ruby() {
} else if /'/ {
single_quote_string();
} else if /"/ {
double_quote_string();
until /$/ {
yield string;
if /\\./ {
// Escape sequences. `\#{` escapes interpolation, so this must come first.
} else if /#\{[^}]*\}/ {
// Interpolation. Nested braces, as in `#{ {a: 1} }`, are not supported.
yield variable;
} else if /"/ {
yield string;
break;
}
}
} else if /`/ {
until /$/ {
yield string;
if /\\./ {
// Escape sequences
} else if /#\{[^}]*\}/ {
yield variable;
} else if /`/ {
yield string;
break;
}
}
} else if /(?:begin|break|case|do|elsif|else|end|ensure|for|if|in|next|redo|rescue|retry|return|then|unless|until|when|while)\>/ {
yield keyword.control;
} else if /def\s+\w+\.(\w+[!?=]?)/ {
// Singleton method, as in `def self.foo`.
yield keyword.other;
yield $1 as method;
} else if /def\s+(\w+[!?=]?)/ {
} else if /def\s+(?:\w+\.)?(\w+[!?=]?)/ {
// The optional prefix covers singleton methods, as in `def self.foo`.
yield keyword.other;
yield $1 as method;
} else if /(?:BEGIN|END|__ENCODING__|__FILE__|__LINE__|alias|and|class|defined\?|def|module|not|or|self|super|undef|yield)\>/ {
yield keyword.other;
} else if /(?:true|false|nil)\>/ {
yield constant.language;
} else if /(?i:-?(?:0x[\da-f_]+|0b[01_]+|0o[0-7_]+|[\d_]+\.[\d_]+(?:e[+-]?[\d_]+)?|[\d_]+(?:e[+-]?[\d_]+)?)r?i?)/ {
} else if /(?i:-?(?:0x[\da-f_]+|0b[01_]+|0o[0-7_]+|[\d_]+(?:\.[\d_]+)?(?:e[+-]?[\d_]+)?)r?i?)/ {
// Floats need digits on both sides of the dot, so that `1..2` and
// `1.upto(2)` don't swallow the dot.
if /\w+/ {
Expand Down