Skip to content

Commit

Permalink
[Ruby] Safe accessor
Browse files Browse the repository at this point in the history
  • Loading branch information
michaelblyons committed Dec 7, 2024
1 parent 1fb3a48 commit 6759669
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 6759669

Please sign in to comment.