Skip to content

Commit

Permalink
[Ruby] Safe accessor (#4109)
Browse files Browse the repository at this point in the history
Fixes #3813
  • Loading branch information
michaelblyons authored Dec 21, 2024
1 parent 8da5d88 commit 5e29f3e
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 7 deletions.
8 changes: 4 additions & 4 deletions Ruby/Ruby.sublime-syntax
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,7 @@ contexts:
pop: true

name-parts:
- match: ({{identifier}})?(?:(::)|(\.))
- match: ({{identifier}})?(?:(::)|(&?\.))
captures:
1: support.other.namespace.ruby
2: punctuation.accessor.double-colon.ruby
Expand Down Expand Up @@ -572,7 +572,7 @@ contexts:
- match: '!+|&&|\|\|'
scope: keyword.operator.logical.ruby
push: after-operator
- match: '[~&|^]'
- match: '(?:[~|^]|&(?!\.))'
scope: keyword.operator.bitwise.ruby
push: after-operator
- match: \?
Expand Down Expand Up @@ -626,7 +626,7 @@ contexts:
- match: ''
set: after-identifier
# This consumes attribute access so we don't need a lookbehind for .
- match: \.(?={{identifier}}{{method_punctuation}})
- match: '&?\.(?={{identifier}}{{method_punctuation}})'
scope: punctuation.accessor.dot.ruby
push:
- include: well-known-methods
Expand All @@ -637,7 +637,7 @@ contexts:
- match: '{{identifier}}{{method_punctuation}}'
# This consumes module/class accessor so we don't need a lookbehind for ::
push: after-identifier
- match: \.
- match: '&?\.'
scope: punctuation.accessor.dot.ruby
- match: '::'
scope: punctuation.accessor.double-colon.ruby
Expand Down
12 changes: 9 additions & 3 deletions Ruby/syntax_test_ruby.rb
Original file line number Diff line number Diff line change
Expand Up @@ -409,6 +409,10 @@ def #{sym}(*args, &block)
#^^ meta.number.integer.decimal.ruby constant.numeric.value.ruby
# ^ punctuation.accessor - constant.numeric - invalid.illegal
# ^^ - constant.numeric - invalid.illegal - storage.type.numeric
12&.ir
#^^ meta.number.integer.decimal.ruby constant.numeric.value.ruby
# ^^ punctuation.accessor - constant.numeric - invalid.illegal - keyword.operator
# ^^ - constant.numeric - invalid.illegal - storage.type.numeric

12.34
#^^^^^ meta.number.float.decimal.ruby constant.numeric.value.ruby
Expand Down Expand Up @@ -978,12 +982,14 @@ def #{sym}(*args, &block)
# ^ punctuation.terminator.statement.ruby
.
# ^ punctuation.accessor.dot.ruby
&.
# ^^ punctuation.accessor.dot.ruby
::
# ^^ punctuation.accessor.double-colon.ruby
<<=
# ^^^ keyword.operator.assignment.augmented.ruby
&&=
# ^^^ keyword.operator.assignment.augmented.ruby
# ^^^ keyword.operator.assignment.augmented.ruby - punctuation
||=
# ^^^ keyword.operator.assignment.augmented.ruby
**=
Expand Down Expand Up @@ -1037,7 +1043,7 @@ def #{sym}(*args, &block)
<
# ^ keyword.operator.comparison.ruby
&&
# ^^ keyword.operator.logical.ruby
# ^^ keyword.operator.logical.ruby - punctuation
||
# ^^ keyword.operator.logical.ruby
!
Expand All @@ -1049,7 +1055,7 @@ def #{sym}(*args, &block)
~
# ^ keyword.operator.bitwise.ruby
&
# ^ keyword.operator.bitwise.ruby
# ^ keyword.operator.bitwise.ruby - punctuation
|
# ^ keyword.operator.bitwise.ruby
^
Expand Down

0 comments on commit 5e29f3e

Please sign in to comment.