Skip to content
Merged
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
30 changes: 21 additions & 9 deletions languages/ruby/highlights.scm
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,14 @@
(global_variable)
] @variable

(constant) @type

((constant) @constant
(#match? @constant "^[A-Z\\d_]+$"))

; Keywords — definition
[
"alias"
"class"
"def"
"module"
Expand All @@ -25,12 +31,15 @@

; Keywords — loop
[
"do"
"for"
"redo"
"until"
"while"
] @keyword.control.repeat

(do
"do" @keyword.control.repeat)

; Keywords — flow return/jump
[
"break"
Expand All @@ -47,16 +56,24 @@
"rescue"
] @keyword.exception

; Keywords — general
; Keywords — operator
[
"alias"
"and"
"end"
"in"
"not"
"or"
] @keyword.operator

; Keywords — general
[
"BEGIN"
"END"
"end"
] @keyword

(do_block
"do" @keyword)

((identifier) @keyword
(#any-of? @keyword "private" "protected" "public"))

Expand Down Expand Up @@ -118,11 +135,6 @@
(hash_splat_nil
"nil" @constant.builtin)

(constant) @type

((constant) @constant
(#match? @constant "^[A-Z\\d_]+$"))

(superclass
(constant) @type.super)

Expand Down
110 changes: 62 additions & 48 deletions tests/languages/ruby/highlights.rb
Original file line number Diff line number Diff line change
Expand Up @@ -32,53 +32,53 @@ class << TestSingleton::Class

# Keywords — conditional
case expr
in 5
in 5,
in ^foo
in ^(1+1)
in 1, 2
in 1, 2,
in 1, 2, 3
in 1, 2, 3,
in 1, 2, 3, *
in 1, *x, 3
in *
in *, 3, 4
in *, 3, *
in *a, 3, *b
in a:
in a: 5
in a: 5,
in a: 5, b:, **
in a: 5, b:, **map
in a: 5, "b":, **nil
in **nil
in [5]
in [5,]
in [1, 2]
in [1, 2,]
in [1, 2, 3]
in [1, 2, 3,]
in [1, 2, 3, *]
in [1, *x, 3]
in [*]
in [*, 3, 4]
in [*, 3, *]
in [*a, 3, *b]
in {a:}
in {a: 5}
in {a: 5,}
in {a: 5, b:, **}
in {a: 5, b:, **map}
in {a: 5, b:, **nil}
in {**nil}
in {}
in []
in -5 | +10
in (nil | self | true | false | __LINE__ | __FILE__ | __ENCODING__)
end

case fun(..., **hash_splat)
in 5
in 5,
in ^foo
in ^(1+1)
in 1, 2
in 1, 2,
in 1, 2, 3
in 1, 2, 3,
in 1, 2, 3, *
in 1, *x, 3
in *
in *, 3, 4
in *, 3, *
in *a, 3, *b
in a:
in a: 5
in a: 5,
in a: 5, b:, **
in a: 5, b:, **map
in a: 5, "b":, **nil
in **nil
in [5]
in [5,]
in [1, 2]
in [1, 2,]
in [1, 2, 3]
in [1, 2, 3,]
in [1, 2, 3, *]
in [1, *x, 3]
in [*]
in [*, 3, 4]
in [*, 3, *]
in [*a, 3, *b]
in {a:}
in {a: 5}
in {a: 5,}
in {a: 5, b:, **}
in {a: 5, b:, **map}
in {a: 5, b:, **nil}
in {**nil}
in {}
in []
in -5 | +10
in (nil | self | true | false | __LINE__ | __FILE__ | __ENCODING__)
end

case fun(..., &block, **hash_splat)
when *splat then true
end

Expand All @@ -97,6 +97,7 @@ class << TestSingleton::Class

# Keywords — loop
while true do
redo
break
end

Expand Down Expand Up @@ -147,14 +148,23 @@ class << TestSingleton::Class
def method;
super
end
def METHOD;
end
def self.singleton_method = nil
def setter=
end
def method_params(var, optional = nil, &block, ..., kw:, *opts, **hash, **nil)
end
fun { || nil }
fun do ||
nil
end
lambda = -> () { nil }

# Method/function calls
method var
METHOD var

# Operator overloading definitions
def +(a)
end
Expand Down Expand Up @@ -225,6 +235,10 @@ def `(a)
refine foo
using foo

# BEGIN/END code blocks
BEGIN {}
END {}

# String literals
"string"
'string'
Expand Down Expand Up @@ -276,7 +290,7 @@ def `(a)
nil

# Hash
{ s1: nil, s1!: nil, s1?: nil, "?s1": nil, :s2 => nil, :"?s2" => nil, "string" => nil}
{ s1: nil, s1!: nil, s1?: nil, "?s1": nil, :s2 => nil, :"?s2" => nil, "string" => nil }

# Unary operators
not true
Expand Down
Loading
Loading