Skip to content

Instantly share code, notes, and snippets.

@kreeger
Last active June 22, 2018 13:30
Show Gist options
  • Save kreeger/49f9bb2a15c4bda92a12 to your computer and use it in GitHub Desktop.
Save kreeger/49f9bb2a15c4bda92a12 to your computer and use it in GitHub Desktop.
My modified version of TextMate / Sublime Text's Ruby.tmLanguage file. To use with Sublime Text 3 (> v3104), it'll need to live at "~/Library/Application Support/Sublime Text 3/Packages/Ruby/Ruby.sublime-syntax".
%YAML 1.2
---
name: Ruby
comment: |
TODO: unresolved issues
text:
"p << end
print me!
end"
symptoms:
not recognized as a heredoc
solution:
there is no way to distinguish perfectly between the << operator and the start
of a heredoc. Currently, we require assignment to recognize a heredoc. More
refinement is possible.
• Heredocs with indented terminators (<<-) are always distinguishable, however.
• Nested heredocs are not really supportable at present
text:
print <<-'THERE'
This is single quoted.
The above used #{Time.now}
THERE
symtoms:
From Programming Ruby p306; should be a non-interpolated heredoc.
text:
"a\332a"
symptoms:
'\332' is not recognized as slash3.. which should be octal 332.
solution:
plain regexp.. should be easy.
text:
val?(a):p(b)
val?'a':'b'
symptoms:
':p' is recognized as a symbol.. its 2 things ':' and 'p'.
:'b' has same problem.
solution:
ternary operator rule, precedence stuff, symbol rule.
but also consider 'a.b?(:c)' ??
file_extensions:
- rb
- rbx
- rjs
- Rakefile
- rake
- cgi
- fcgi
- gemspec
- irbrc
- capfile
- prawn
- Cheffile
- Gemfile
- Guardfile
- Vagrantfile
- config.ru
- Appraisals
- Rantfile
- Brewfile
- Berksfile
- Thorfile
first_line_match: ^#!/.*\bruby
scope: source.ruby
contexts:
main:
- match: '^\s*(class)\s+(([.a-zA-Z0-9_:]+(\s*(<)\s*[.a-zA-Z0-9_:]+)?)|((<<)\s*[.a-zA-Z0-9_:]+))'
scope: meta.class.ruby
captures:
1: keyword.control.class.ruby
2: entity.name.type.class.ruby
4: entity.other.inherited-class.ruby
5: punctuation.separator.inheritance.ruby
6: variable.other.object.ruby
7: punctuation.definition.variable.ruby
- match: '^\s*(module)\s+(([A-Z]\w*(::))?([A-Z]\w*(::))?([A-Z]\w*(::))*[A-Z]\w*)'
scope: meta.module.ruby
captures:
1: keyword.control.module.ruby
2: entity.name.type.module.ruby
3: entity.other.inherited-class.module.first.ruby
4: punctuation.separator.inheritance.ruby
5: entity.other.inherited-class.module.second.ruby
6: punctuation.separator.inheritance.ruby
7: entity.other.inherited-class.module.third.ruby
8: punctuation.separator.inheritance.ruby
- match: (?<!\.)\belse(\s)+if\b
comment: else if is a common mistake carried over from other languages. it works if you put in a second end, but it’s never what you want.
scope: invalid.deprecated.ruby
- match: '(?>[a-zA-Z_]\w*(?>[?!])?)(?=:)(?!::)'
comment: symbols
scope: constant.other.symbol.ruby.19syntax
captures:
1: punctuation.definition.constant.ruby
- match: '(?<!\.)\b(BEGIN|begin|case|class|else|elsif|END|end|ensure|for|if|in|module|rescue|then|unless|until|when|while)\b(?![?!])'
comment: everything being a reserved word, not a value and needing a 'end' is a..
scope: keyword.control.ruby
- match: (?<!\.)\bdo\b\s*
comment: contextual smart pair support for block parameters
scope: keyword.control.start-block.ruby
- match: '(?<=\{)(\s+)'
comment: contextual smart pair support
scope: meta.syntax.ruby.start-block
- match: (?<!\.)\b(and|not|or)\b
comment: as above, just doesn't need a 'end' and does a logic operation
scope: keyword.operator.logical.ruby
- match: '(?<!\.)\b(alias|alias_method|break|next|redo|retry|return|super|undef|yield)\b(?![?!])|\bdefined\?|\bblock_given\?'
comment: just as above but being not a logical operation
scope: keyword.control.pseudo-method.ruby
- match: '\b(nil|true|false)\b(?![?!])'
scope: constant.language.ruby
- match: '\b(__(FILE|LINE)__|self)\b(?![?!])'
scope: variable.language.ruby
- match: '\b(initialize|new|loop|include|extend|raise|fail|attr_reader|attr_writer|attr_accessor|attr|catch|throw|private|module_function|public|protected)\b(?![?!])'
comment: everything being a method but having a special function is a..
scope: keyword.other.special-method.ruby
- match: \b(require|require_relative|gem)\b
captures:
1: keyword.other.special-method.ruby
push:
- meta_scope: meta.require.ruby
- match: $|(?=#)
captures:
1: keyword.other.special-method.ruby
pop: true
- include: main
- match: '(@)[a-zA-Z_]\w*'
scope: variable.other.readwrite.instance.ruby
captures:
1: punctuation.definition.variable.ruby
- match: '(@@)[a-zA-Z_]\w*'
scope: variable.other.readwrite.class.ruby
captures:
1: punctuation.definition.variable.ruby
- match: '(\$)[a-zA-Z_]\w*'
scope: variable.other.readwrite.global.ruby
captures:
1: punctuation.definition.variable.ruby
- match: '(\$)(!|@|&|`|''|\+|\d+|~|=|/|\\|,|;|\.|<|>|_|\*|\$|\?|:|"|-[0adFiIlpv])'
scope: variable.other.readwrite.global.pre-defined.ruby
captures:
1: punctuation.definition.variable.ruby
- match: '\b(ENV)\['
captures:
1: variable.other.constant.ruby
push:
- meta_scope: meta.environment-variable.ruby
- match: '\]'
pop: true
- include: main
- match: '\b[A-Z]\w*(?=((\.|::)[A-Za-z]|\[))'
scope: support.class.ruby
- match: '\b[A-Z]\w*\b'
scope: variable.other.constant.ruby
- match: |-
(?x)
(?=def\b) # an optimization to help Oniguruma fail fast
(?<=^|\s)(def)\s+ # the def keyword
( (?>[a-zA-Z_]\w*(?>\.|::))? # a method name prefix
(?>[a-zA-Z_]\w*(?>[?!]|=(?!>))? # the method name
|===?|>[>=]?|<=>|<[<=]?|[%&`/\|]|\*\*?|=?~|[-+]@?|\[\]=?) ) # …or an operator method
\s*(\() # the openning parenthesis for arguments
comment: the method pattern comes from the symbol pattern, see there for a explaination
captures:
1: keyword.control.def.ruby
2: entity.name.function.ruby
3: punctuation.definition.parameters.ruby
push:
- meta_scope: meta.function.method.with-arguments.ruby
- meta_content_scope: variable.parameter.function.ruby
- match: \)
captures:
0: punctuation.definition.parameters.ruby
pop: true
- include: main
- match: |-
(?x)
(?=def\b) # an optimization to help Oniguruma fail fast
(?<=^|\s)(def)\s+ # the def keyword
( (?>[a-zA-Z_]\w*(?>\.|::))? # a method name prefix
(?>[a-zA-Z_]\w*(?>[?!]|=(?!>))? # the method name
|===?|>[>=]?|<=>|<[<=]?|[%&`/\|]|\*\*?|=?~|[-+]@?|\[\]=?) ) # …or an operator method
[ \t] # the space separating the arguments
(?=[ \t]*[^\s#;]) # make sure arguments and not a comment follow
comment: same as the previous rule, but without parentheses around the arguments
captures:
1: keyword.control.def.ruby
2: entity.name.function.ruby
push:
- meta_scope: meta.function.method.with-arguments.ruby
- meta_content_scope: variable.parameter.function.ruby
- match: $
pop: true
- include: main
- match: |-
(?x)
(?=def\b) # an optimization to help Oniguruma fail fast
(?<=^|\s)(def)\b # the def keyword
( \s+ # an optional group of whitespace followed by…
( (?>[a-zA-Z_]\w*(?>\.|::))? # a method name prefix
(?>[a-zA-Z_]\w*(?>[?!]|=(?!>))? # the method name
|===?|>[>=]?|<=>|<[<=]?|[%&`/\|]|\*\*?|=?~|[-+]@?|\[\]=?) ) )? # …or an operator method
comment: the optional name is just to catch the def also without a method-name
scope: meta.function.method.without-arguments.ruby
captures:
1: keyword.control.def.ruby
3: entity.name.function.ruby
- match: '\b(0[xX]\h(?>_?\h)*|\d(?>_?\d)*(\.(?![^[:space:][:digit:]])(?>_?\d)*)?([eE][-+]?\d(?>_?\d)*)?|0[bB][01]+)\b'
scope: constant.numeric.ruby
- match: ":'"
captures:
0: punctuation.definition.constant.ruby
push:
- meta_scope: constant.other.symbol.single-quoted.ruby
- match: "'"
captures:
0: punctuation.definition.constant.ruby
pop: true
- match: '\\[''\\]'
scope: constant.character.escape.ruby
- match: ':"'
captures:
0: punctuation.definition.constant.ruby
push:
- meta_scope: constant.other.symbol.double-quoted.ruby
- match: '"'
captures:
0: punctuation.definition.constant.ruby
pop: true
- include: interpolated_ruby
- include: escaped_char
- match: /=
comment: Needs higher precidence than regular expressions.
scope: keyword.operator.assignment.augmented.ruby
- match: "'"
comment: single quoted string (does not allow interpolation)
captures:
0: punctuation.definition.string.begin.ruby
push:
- meta_scope: string.quoted.single.ruby
- match: "'"
captures:
0: punctuation.definition.string.end.ruby
pop: true
- match: \\'|\\\\
scope: constant.character.escape.ruby
- match: '"'
comment: double quoted string (allows for interpolation)
captures:
0: punctuation.definition.string.begin.ruby
push:
- meta_scope: string.quoted.double.ruby
- match: '"'
captures:
0: punctuation.definition.string.end.ruby
pop: true
- include: interpolated_ruby
- include: escaped_char
- match: "`"
comment: execute string (allows for interpolation)
captures:
0: punctuation.definition.string.begin.ruby
push:
- meta_scope: string.interpolated.ruby
- match: "`"
captures:
0: punctuation.definition.string.end.ruby
pop: true
- include: interpolated_ruby
- include: escaped_char
- match: '%x\{'
comment: execute string (allow for interpolation)
captures:
0: punctuation.definition.string.begin.ruby
push:
- meta_scope: string.interpolated.ruby
- match: '\}'
captures:
0: punctuation.definition.string.end.ruby
pop: true
- include: interpolated_ruby
- include: escaped_char
- include: nest_curly_i
- match: '%x\['
comment: execute string (allow for interpolation)
captures:
0: punctuation.definition.string.begin.ruby
push:
- meta_scope: string.interpolated.ruby
- match: '\]'
captures:
0: punctuation.definition.string.end.ruby
pop: true
- include: interpolated_ruby
- include: escaped_char
- include: nest_brackets_i
- match: '%x\<'
comment: execute string (allow for interpolation)
captures:
0: punctuation.definition.string.begin.ruby
push:
- meta_scope: string.interpolated.ruby
- match: \>
captures:
0: punctuation.definition.string.end.ruby
pop: true
- include: interpolated_ruby
- include: escaped_char
- include: nest_ltgt_i
- match: '%x\('
comment: execute string (allow for interpolation)
captures:
0: punctuation.definition.string.begin.ruby
push:
- meta_scope: string.interpolated.ruby
- match: \)
captures:
0: punctuation.definition.string.end.ruby
pop: true
- include: interpolated_ruby
- include: escaped_char
- include: nest_parens_i
- match: '%x([^\w])'
comment: execute string (allow for interpolation)
captures:
0: punctuation.definition.string.begin.ruby
push:
- meta_scope: string.interpolated.ruby
- match: \1
captures:
0: punctuation.definition.string.end.ruby
pop: true
- include: interpolated_ruby
- include: escaped_char
- match: |-
(?x)
(?:
^ # beginning of line
| (?<= # or look-behind on:
[=><~(?:\[,|&;]
| [\s;]if\s # keywords
| [\s;]elsif\s
| [\s;]while\s
| [\s;]unless\s
| [\s;]when\s
| [\s;]assert_match\s
| [\s;]or\s # boolean opperators
| [\s;]and\s
| [\s;]not\s
| [\s.]index\s # methods
| [\s.]scan\s
| [\s.]sub\s
| [\s.]sub!\s
| [\s.]gsub\s
| [\s.]gsub!\s
| [\s.]match\s
)
| (?<= # or a look-behind with line anchor:
^when\s # duplication necessary due to limits of regex
| ^if\s
| ^elsif\s
| ^while\s
| ^unless\s
)
)
\s*((/))(?![*+{}?])
comment: |
regular expressions (normal)
we only start a regexp if the character before it (excluding whitespace)
is what we think is before a regexp
captures:
1: string.regexp.classic.ruby
2: punctuation.definition.string.ruby
push:
- meta_scope: string.regexp.classic.ruby
- match: "((/)([eimnosux]*))"
captures:
1: punctuation.definition.string.ruby
pop: true
- include: regex_sub
- match: '%r\{'
comment: regular expressions (literal)
captures:
0: punctuation.definition.string.begin.ruby
push:
- meta_scope: string.regexp.mod-r.ruby
- match: '\}[eimnosux]*'
captures:
0: punctuation.definition.string.end.ruby
pop: true
- include: regex_sub
- include: nest_curly_r
- match: '%r\['
comment: regular expressions (literal)
captures:
0: punctuation.definition.string.begin.ruby
push:
- meta_scope: string.regexp.mod-r.ruby
- match: '\][eimnosux]*'
captures:
0: punctuation.definition.string.end.ruby
pop: true
- include: regex_sub
- include: nest_brackets_r
- match: '%r\('
comment: regular expressions (literal)
captures:
0: punctuation.definition.string.begin.ruby
push:
- meta_scope: string.regexp.mod-r.ruby
- match: '\)[eimnosux]*'
captures:
0: punctuation.definition.string.end.ruby
pop: true
- include: regex_sub
- include: nest_parens_r
- match: '%r\<'
comment: regular expressions (literal)
captures:
0: punctuation.definition.string.begin.ruby
push:
- meta_scope: string.regexp.mod-r.ruby
- match: '\>[eimnosux]*'
captures:
0: punctuation.definition.string.end.ruby
pop: true
- include: regex_sub
- include: nest_ltgt_r
- match: '%r([^\w])'
comment: regular expressions (literal)
captures:
0: punctuation.definition.string.begin.ruby
push:
- meta_scope: string.regexp.mod-r.ruby
- match: '\1[eimnosux]*'
captures:
0: punctuation.definition.string.end.ruby
pop: true
- include: regex_sub
- match: '%[QWSR]?\('
comment: literal capable of interpolation ()
captures:
0: punctuation.definition.string.begin.ruby
push:
- meta_scope: string.quoted.other.literal.upper.ruby
- match: \)
captures:
0: punctuation.definition.string.end.ruby
pop: true
- include: interpolated_ruby
- include: escaped_char
- include: nest_parens_i
- match: '%[QWSR]?\['
comment: "literal capable of interpolation []"
captures:
0: punctuation.definition.string.begin.ruby
push:
- meta_scope: string.quoted.other.literal.upper.ruby
- match: '\]'
captures:
0: punctuation.definition.string.end.ruby
pop: true
- include: interpolated_ruby
- include: escaped_char
- include: nest_brackets_i
- match: '%[QWSR]?\<'
comment: literal capable of interpolation <>
captures:
0: punctuation.definition.string.begin.ruby
push:
- meta_scope: string.quoted.other.literal.upper.ruby
- match: \>
captures:
0: punctuation.definition.string.end.ruby
pop: true
- include: interpolated_ruby
- include: escaped_char
- include: nest_ltgt_i
- match: '%[QWSR]?\{'
comment: "literal capable of interpolation -- {}"
captures:
0: punctuation.definition.string.begin.ruby
push:
- meta_scope: string.quoted.double.ruby.mod
- match: '\}'
captures:
0: punctuation.definition.string.end.ruby
pop: true
- include: interpolated_ruby
- include: escaped_char
- include: nest_curly_i
- match: '%[QWSR]([^\w])'
comment: literal capable of interpolation -- wildcard
captures:
0: punctuation.definition.string.begin.ruby
push:
- meta_scope: string.quoted.other.literal.upper.ruby
- match: \1
captures:
0: punctuation.definition.string.end.ruby
pop: true
- include: interpolated_ruby
- include: escaped_char
- match: '%([^\w\s=])'
comment: literal capable of interpolation -- wildcard
captures:
0: punctuation.definition.string.begin.ruby
push:
- meta_scope: string.quoted.other.literal.other.ruby
- match: \1
captures:
0: punctuation.definition.string.end.ruby
pop: true
- include: interpolated_ruby
- include: escaped_char
- match: '%[qwsi]\('
comment: literal incapable of interpolation -- ()
captures:
0: punctuation.definition.string.begin.ruby
push:
- meta_scope: string.quoted.other.literal.lower.ruby
- match: \)
captures:
0: punctuation.definition.string.end.ruby
pop: true
- match: \\\)|\\\\
scope: constant.character.escape.ruby
- include: nest_parens
- match: '%[qwsi]\<'
comment: literal incapable of interpolation -- <>
captures:
0: punctuation.definition.string.begin.ruby
push:
- meta_scope: string.quoted.other.literal.lower.ruby
- match: \>
captures:
0: punctuation.definition.string.end.ruby
pop: true
- match: \\\>|\\\\
scope: constant.character.escape.ruby
- include: nest_ltgt
- match: '%[qwsi]\['
comment: "literal incapable of interpolation -- []"
captures:
0: punctuation.definition.string.begin.ruby
push:
- meta_scope: string.quoted.other.literal.lower.ruby
- match: '\]'
captures:
0: punctuation.definition.string.end.ruby
pop: true
- match: '\\\]|\\\\'
scope: constant.character.escape.ruby
- include: nest_brackets
- match: '%[qwsi]\{'
comment: "literal incapable of interpolation -- {}"
captures:
0: punctuation.definition.string.begin.ruby
push:
- meta_scope: string.quoted.other.literal.lower.ruby
- match: '\}'
captures:
0: punctuation.definition.string.end.ruby
pop: true
- match: '\\\}|\\\\'
scope: constant.character.escape.ruby
- include: nest_curly
- match: '%[qwsi]([^\w])'
comment: literal incapable of interpolation -- wildcard
captures:
0: punctuation.definition.string.begin.ruby
push:
- meta_scope: string.quoted.other.literal.lower.ruby
- match: \1
captures:
0: punctuation.definition.string.end.ruby
pop: true
- match: \\.
comment: Cant be named because its not neccesarily an escape.
- match: '(?<!:)(:)(?>[a-zA-Z_]\w*(?>[?!]|=(?![>=]))?|===?|>[>=]?|<[<=]?|<=>|[%&`/\|]|\*\*?|=?~|[-+]@?|\[\]=?|@@?[a-zA-Z_]\w*)'
comment: symbols
scope: constant.other.symbol.ruby
captures:
1: punctuation.definition.constant.ruby
- match: ^=begin
comment: multiline comments
captures:
0: punctuation.definition.comment.ruby
push:
- meta_scope: comment.block.documentation.ruby
- match: ^=end
captures:
0: punctuation.definition.comment.ruby
pop: true
- match: '(?:^[ \t]+)?(#).*$\n?'
scope: comment.line.number-sign.ruby
captures:
1: punctuation.definition.comment.ruby
- match: '(?<!\w)\?(\\(x\h{1,2}(?!\h)\b|0[0-7]{0,2}(?![0-7])\b|[^x0MC])|(\\[MC]-)+\w|[^\s\\])'
comment: |
matches questionmark-letters.
examples (1st alternation = hex):
?\x1 ?\x61
examples (2nd alternation = octal):
?\0 ?\07 ?\017
examples (3rd alternation = escaped):
?\n ?\b
examples (4th alternation = meta-ctrl):
?\C-a ?\M-a ?\C-\M-\C-\M-a
examples (4th alternation = normal):
?a ?A ?0
?* ?" ?(
?. ?#
the negative lookbehind prevents against matching
p(42.tainted?)
scope: constant.numeric.ruby
- match: ^__END__\n
comment: __END__ marker
captures:
0: string.unquoted.program-block.ruby
push:
- meta_content_scope: text.plain
- match: (?=not)impossible
captures:
0: string.unquoted.program-block.ruby
pop: true
- match: (?=<?xml|<(?i:html\b)|!DOCTYPE (?i:html\b))
push:
- meta_scope: text.html.embedded.ruby
- match: (?=not)impossible
pop: true
- include: scope:text.html.basic
- match: '(?><<-("?)((?:[_\w]+_|)HTML)\b\1)'
comment: heredoc with embedded HTML and indented terminator
captures:
0: punctuation.definition.string.begin.ruby
push:
- meta_scope: string.unquoted.embedded.html.ruby
- meta_content_scope: text.html.embedded.ruby
- match: \s*\2$
captures:
0: punctuation.definition.string.end.ruby
pop: true
- include: heredoc
- include: scope:text.html.basic
- include: interpolated_ruby
- include: escaped_char
- match: '(?><<-("?)((?:[_\w]+_|)SQL)\b\1)'
comment: heredoc with embedded SQL and indented terminator
captures:
0: punctuation.definition.string.begin.ruby
push:
- meta_scope: string.unquoted.embedded.sql.ruby
- meta_content_scope: text.sql.embedded.ruby
- match: \s*\2$
captures:
0: punctuation.definition.string.end.ruby
pop: true
- include: heredoc
- include: scope:source.sql
- include: interpolated_ruby
- include: escaped_char
- match: '(?><<-("?)((?:[_\w]+_|)CSS)\b\1)'
comment: heredoc with embedded css and intented terminator
captures:
0: punctuation.definition.string.begin.ruby
push:
- meta_scope: string.unquoted.embedded.css.ruby
- meta_content_scope: text.css.embedded.ruby
- match: \s*\2$
captures:
0: punctuation.definition.string.end.ruby
pop: true
- include: heredoc
- include: 'scope:source.css'
- include: interpolated_ruby
- include: escaped_char
- match: '(?><<-("?)((?:[_\w]+_|)(?:JS|JAVASCRIPT))\b\1)'
comment: heredoc with embedded javascript and intented terminator
captures:
0: punctuation.definition.string.begin.ruby
push:
- meta_scope: string.unquoted.embedded.js.ruby
- meta_content_scope: text.js.embedded.ruby
- match: \s*\2$
captures:
0: punctuation.definition.string.end.ruby
pop: true
- include: heredoc
- include: 'scope:source.js'
- include: interpolated_ruby
- include: escaped_char
# - match: '(?><<-("?)((?:[_\w]+_|)(?:SH|SHELL))\b\1)'
# comment: heredoc with embedded shell and intented terminator
# captures:
# 0: punctuation.definition.string.begin.ruby
# push:
# - meta_scope: string.unquoted.embedded.shell.ruby
# - meta_content_scope: text.shell.embedded.ruby
# - match: \s*\2$
# captures:
# 0: punctuation.definition.string.end.ruby
# pop: true
# - include: heredoc
# - include: Shell-Unix-Generic.sublime-syntax
# - include: interpolated_ruby
# - include: escaped_char
- match: '(?><<-("?)((?:[_\w]+_|)RUBY)\b\1)'
comment: heredoc with embedded ruby and intented terminator
captures:
0: punctuation.definition.string.begin.ruby
push:
- meta_scope: string.unquoted.embedded.ruby.ruby
- meta_content_scope: text.ruby.embedded.ruby
- match: \s*\2$
captures:
0: punctuation.definition.string.end.ruby
pop: true
- include: heredoc
- include: main
- include: interpolated_ruby
- include: escaped_char
- match: (?>\=\s*<<(\w+))
captures:
0: punctuation.definition.string.begin.ruby
push:
- meta_scope: string.unquoted.heredoc.ruby
- match: ^\1$
captures:
0: punctuation.definition.string.end.ruby
pop: true
- include: heredoc
- include: interpolated_ruby
- include: escaped_char
- match: (?><<-(\w+))
comment: heredoc with indented terminator
captures:
0: punctuation.definition.string.begin.ruby
push:
- meta_scope: string.unquoted.heredoc.ruby
- match: \s*\1$
captures:
0: punctuation.definition.string.end.ruby
pop: true
- include: heredoc
- include: interpolated_ruby
- include: escaped_char
- match: '(?<=\{|do|\{\s|do\s)(\|)'
captures:
1: punctuation.separator.variable.ruby
push:
- meta_scope: meta.variable.block.ruby
- match: (\|)
scope: punctuation.separator.variable.ruby
pop: true
- match: "[_a-zA-Z][_a-zA-Z0-9]*"
scope: variable.other.block.ruby
- match: ","
scope: punctuation.separator.variable.ruby
- match: "=>"
scope: punctuation.separator.key-value
- match: '<<=|%=|&=|\*=|\*\*=|\+=|\-=|\^=|\|{1,2}=|<<'
scope: keyword.operator.assignment.augmented.ruby
- match: '<=>|<(?!<|=)|>(?!<|=|>)|<=|>=|===|==|=~|!=|!~|(?<=[ \t])\?'
scope: keyword.operator.comparison.ruby
- match: '(?<=[ \t])!+|\bnot\b|&&|\band\b|\|\||\bor\b|\^'
scope: keyword.operator.logical.ruby
- match: (%|&|\*\*|\*|\+|\-|/)
scope: keyword.operator.arithmetic.ruby
- match: "="
scope: keyword.operator.assignment.ruby
- match: \||~|>>
scope: keyword.operator.other.ruby
- match: ":"
scope: punctuation.separator.other.ruby
- match: \;
scope: punctuation.separator.statement.ruby
- match: ","
scope: punctuation.separator.object.ruby
- match: '\.|::'
scope: punctuation.separator.method.ruby
- match: '\{|\}'
scope: punctuation.section.scope.ruby
- match: '\[|\]'
scope: punctuation.section.array.ruby
- match: \(|\)
scope: punctuation.section.function.ruby
escaped_char:
- match: '\\(?:[0-7]{1,3}|x[\da-fA-F]{1,2}|.)'
scope: constant.character.escape.ruby
heredoc:
- match: ^<<-?\w+
push:
- match: $
pop: true
- include: main
interpolated_ruby:
- match: '#\{(\})'
scope: source.ruby.embedded.source
captures:
0: punctuation.section.embedded.ruby
1: source.ruby.embedded.source.empty
- match: '#\{'
captures:
0: punctuation.section.embedded.ruby
push:
- meta_scope: source.ruby.embedded.source
- match: '\}'
captures:
0: punctuation.section.embedded.ruby
pop: true
- include: nest_curly_and_self
- include: main
- match: '(#@)[a-zA-Z_]\w*'
scope: variable.other.readwrite.instance.ruby
captures:
1: punctuation.definition.variable.ruby
- match: '(#@@)[a-zA-Z_]\w*'
scope: variable.other.readwrite.class.ruby
captures:
1: punctuation.definition.variable.ruby
- match: '(#\$)[a-zA-Z_]\w*'
scope: variable.other.readwrite.global.ruby
captures:
1: punctuation.definition.variable.ruby
nest_brackets:
- match: '\['
captures:
0: punctuation.section.scope.ruby
push:
- match: '\]'
captures:
0: punctuation.section.scope.ruby
pop: true
- include: nest_brackets
nest_brackets_i:
- match: '\['
captures:
0: punctuation.section.scope.ruby
push:
- match: '\]'
captures:
0: punctuation.section.scope.ruby
pop: true
- include: interpolated_ruby
- include: escaped_char
- include: nest_brackets_i
nest_brackets_r:
- match: '\['
captures:
0: punctuation.section.scope.ruby
push:
- match: '\]'
captures:
0: punctuation.section.scope.ruby
pop: true
- include: regex_sub
- include: nest_brackets_r
nest_curly:
- match: '\{'
captures:
0: punctuation.section.scope.ruby
push:
- match: '\}'
captures:
0: punctuation.section.scope.ruby
pop: true
- include: nest_curly
nest_curly_and_self:
- match: '\{'
captures:
0: punctuation.section.scope.ruby
push:
- match: '\}'
captures:
0: punctuation.section.scope.ruby
pop: true
- include: nest_curly_and_self
- include: main
nest_curly_i:
- match: '\{'
captures:
0: punctuation.section.scope.ruby
push:
- match: '\}'
captures:
0: punctuation.section.scope.ruby
pop: true
- include: interpolated_ruby
- include: escaped_char
- include: nest_curly_i
nest_curly_r:
- match: '\{'
captures:
0: punctuation.section.scope.ruby
push:
- match: '\}'
captures:
0: punctuation.section.scope.ruby
pop: true
- include: regex_sub
- include: nest_curly_r
nest_ltgt:
- match: \<
captures:
0: punctuation.section.scope.ruby
push:
- match: \>
captures:
0: punctuation.section.scope.ruby
pop: true
- include: nest_ltgt
nest_ltgt_i:
- match: \<
captures:
0: punctuation.section.scope.ruby
push:
- match: \>
captures:
0: punctuation.section.scope.ruby
pop: true
- include: interpolated_ruby
- include: escaped_char
- include: nest_ltgt_i
nest_ltgt_r:
- match: \<
captures:
0: punctuation.section.scope.ruby
push:
- match: \>
captures:
0: punctuation.section.scope.ruby
pop: true
- include: regex_sub
- include: nest_ltgt_r
nest_parens:
- match: \(
captures:
0: punctuation.section.scope.ruby
push:
- match: \)
captures:
0: punctuation.section.scope.ruby
pop: true
- include: nest_parens
nest_parens_i:
- match: \(
captures:
0: punctuation.section.scope.ruby
push:
- match: \)
captures:
0: punctuation.section.scope.ruby
pop: true
- include: interpolated_ruby
- include: escaped_char
- include: nest_parens_i
nest_parens_r:
- match: \(
captures:
0: punctuation.section.scope.ruby
push:
- match: \)
captures:
0: punctuation.section.scope.ruby
pop: true
- include: regex_sub
- include: nest_parens_r
regex_sub:
- include: interpolated_ruby
- include: escaped_char
- match: '(\{)\d+(,\d+)?(\})'
scope: string.regexp.arbitrary-repitition.ruby
captures:
1: punctuation.definition.arbitrary-repitition.ruby
3: punctuation.definition.arbitrary-repitition.ruby
- match: '\[(?:\^?\])?'
captures:
0: punctuation.definition.character-class.ruby
push:
- meta_scope: string.regexp.character-class.ruby
- match: '\]'
captures:
0: punctuation.definition.character-class.ruby
pop: true
- include: escaped_char
- match: \(
captures:
0: punctuation.definition.group.ruby
push:
- meta_scope: string.regexp.group.ruby
- match: \)
captures:
0: punctuation.definition.group.ruby
pop: true
- include: regex_sub
- match: '(?<=^|\s)(#)\s[[a-zA-Z0-9,. \t?!-][^\x{00}-\x{7F}]]*$'
comment: We are restrictive in what we allow to go after the comment character to avoid false positives, since the availability of comments depend on regexp flags.
scope: comment.line.number-sign.ruby
captures:
1: punctuation.definition.comment.ruby
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment