Skip to content

Commit

Permalink
[Ruby] Support code on same line as heredoc begin token
Browse files Browse the repository at this point in the history
  • Loading branch information
wbond committed Jun 8, 2016
1 parent 2ada9ca commit 6b265c9
Show file tree
Hide file tree
Showing 2 changed files with 112 additions and 68 deletions.
164 changes: 96 additions & 68 deletions Ruby/Ruby.sublime-syntax
Original file line number Diff line number Diff line change
Expand Up @@ -1345,97 +1345,125 @@ contexts:
# heredoc with embedded HTML and indented terminator
- match: '(<<[-~]"?((?:[_\w]+_|)HTML)\b"?)'
scope: punctuation.definition.string.begin.ruby
push:
- meta_scope: string.unquoted.embedded.html.ruby
- meta_content_scope: text.html.embedded.ruby
- match: ^\s*\2$
scope: punctuation.definition.string.end.ruby
pop: true
- include: scope:text.html.basic
- include: interpolated-ruby
- include: escaped-char
push: [heredoc-html, trailing-heredoc]
# heredoc with embedded SQL and indented terminator
- match: '(<<[-~]"?((?:[_\w]+_|)SQL)\b"?)'
scope: punctuation.definition.string.begin.ruby
push:
- meta_scope: string.unquoted.embedded.sql.ruby
- meta_content_scope: text.sql.embedded.ruby
- match: ^\s*\2$
scope: punctuation.definition.string.end.ruby
pop: true
- include: scope:source.sql
- include: interpolated-ruby
- include: escaped-char
push: [heredoc-sql, trailing-heredoc]
# heredoc with embedded css and indented terminator
- match: '(<<[-~]"?((?:[_\w]+_|)CSS)\b"?)'
scope: punctuation.definition.string.begin.ruby
push:
- meta_scope: string.unquoted.embedded.css.ruby
- meta_content_scope: text.css.embedded.ruby
- match: ^\s*\2$
scope: punctuation.definition.string.end.ruby
pop: true
- include: 'scope:source.css'
- include: interpolated-ruby
- include: escaped-char
push: [heredoc-css, trailing-heredoc]
# heredoc with embedded javascript and indented terminator
- match: '(<<[-~]"?((?:[_\w]+_|)(?:JS|JAVASCRIPT))\b"?)'
scope: punctuation.definition.string.begin.ruby
push:
- meta_scope: string.unquoted.embedded.js.ruby
- meta_content_scope: text.js.embedded.ruby
- match: ^\s*\2$
scope: punctuation.definition.string.end.ruby
pop: true
- include: 'scope:source.js'
- include: interpolated-ruby
- include: escaped-char
push: [heredoc-js, trailing-heredoc]
# heredoc with embedded ruby and indented terminator
- match: '(<<[-~]"?((?:[_\w]+_|)RUBY)\b"?)'
scope: punctuation.definition.string.begin.ruby
push:
- meta_scope: string.unquoted.embedded.ruby.ruby
- meta_content_scope: text.ruby.embedded.ruby
- match: ^\s*\2$
scope: punctuation.definition.string.end.ruby
pop: true
- include: interpolated-ruby
- include: escaped-char
- include: expressions
push: [heredoc-ruby, trailing-heredoc]
# Escaped to prevent recursion?
# heredoc with embedded shell and indented terminator
# - match: '(<<[-~]("?)((?:[_\w]+_|)(?:SH|SHELL))\b\1)'
# scope: punctuation.definition.string.begin.ruby
# push:
# - meta_scope: string.unquoted.embedded.shell.ruby
# - meta_content_scope: text.shell.embedded.ruby
# - match: ^\s*\2$
# scope: punctuation.definition.string.end.ruby
# pop: true
# - include: Shell-Unix-Generic.sublime-syntax
# - include: interpolated-ruby
# - include: escaped-char
# push: [heredoc-shell, trailing-heredoc]
- match: (\=)\s*(<<(\w+))
captures:
1: keyword.operator.assignment.ruby
2: punctuation.definition.string.begin.ruby
push:
- meta_scope: string.unquoted.heredoc.ruby
- match: ^\s*\3$
scope: punctuation.definition.string.end.ruby
pop: true
- include: interpolated-ruby
- include: escaped-char
push: [heredoc-assign, trailing-heredoc-no-embedding]
# heredoc with indented terminator
- match: '(<<[-~](\w+))'
scope: punctuation.definition.string.begin.ruby
push:
- meta_scope: string.unquoted.heredoc.ruby
- match: ^\s*\2$
scope: punctuation.definition.string.end.ruby
pop: true
- include: interpolated-ruby
- include: escaped-char
push: [heredoc-plain, trailing-heredoc-no-embedding]

heredoc-html:
- meta_scope: string.unquoted.embedded.html.ruby
- meta_content_scope: text.html.embedded.ruby
- match: ^\s*\2$
scope: punctuation.definition.string.end.ruby
pop: true
- include: scope:text.html.basic
- include: interpolated-ruby
- include: escaped-char

heredoc-sql:
- meta_scope: string.unquoted.embedded.sql.ruby
- meta_content_scope: text.sql.embedded.ruby
- match: ^\s*\2$
scope: punctuation.definition.string.end.ruby
pop: true
- include: scope:source.sql
- include: interpolated-ruby
- include: escaped-char

heredoc-css:
- meta_scope: string.unquoted.embedded.css.ruby
- meta_content_scope: text.css.embedded.ruby
- match: ^\s*\2$
scope: punctuation.definition.string.end.ruby
pop: true
- include: 'scope:source.css'
- include: interpolated-ruby
- include: escaped-char

heredoc-js:
- meta_scope: string.unquoted.embedded.js.ruby
- meta_content_scope: text.js.embedded.ruby
- match: ^\s*\2$
scope: punctuation.definition.string.end.ruby
pop: true
- include: 'scope:source.js'
- include: interpolated-ruby
- include: escaped-char

heredoc-ruby:
- meta_scope: string.unquoted.embedded.ruby.ruby
- meta_content_scope: text.ruby.embedded.ruby
- match: ^\s*\2$
scope: punctuation.definition.string.end.ruby
pop: true
- include: interpolated-ruby
- include: escaped-char
- include: expressions

#heredoc-shell:
# - meta_scope: string.unquoted.embedded.shell.ruby
# - meta_content_scope: text.shell.embedded.ruby
# - match: ^\s*\2$
# scope: punctuation.definition.string.end.ruby
# pop: true
# - include: Shell-Unix-Generic.sublime-syntax
# - include: interpolated-ruby
# - include: escaped-char

trailing-heredoc:
- clear_scopes: 2
- match: '$'
pop: true
- include: expressions

heredoc-assign:
- meta_scope: string.unquoted.heredoc.ruby
- match: ^\s*\3$
scope: punctuation.definition.string.end.ruby
pop: true
- include: interpolated-ruby
- include: escaped-char

heredoc-plain:
- meta_scope: string.unquoted.heredoc.ruby
- match: ^\s*\2$
scope: punctuation.definition.string.end.ruby
pop: true
- include: interpolated-ruby
- include: escaped-char

trailing-heredoc-no-embedding:
- clear_scopes: 1
- match: '$'
pop: true
- include: expressions

data-section:
- match: ^__END__\n
Expand Down
16 changes: 16 additions & 0 deletions Ruby/syntax_test_ruby.rb
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,22 @@ def #{sym}(*args, &block)
end
RUBY

DB.fetch(<<-SQL, conn).name
# ^^^^^^ string.unquoted
# ^^^^^^^^^^^^ - string.unquoted
# ^ punctuation.separator
# ^ punctuation.definition.group.end
SELECT * FROM users;
#^^^^^^^^^^^^^^^^^^^ text.sql.embedded
SQL

foo, bar = <<BAR, 2
# ^^^^^ string.unquoted
# ^^^ - string
# ^ punctuation.separator
# ^ constant.numeric
BAR

str = "number %d" % 11
# ^^ string.quoted.double.ruby constant.other.placeholder.ruby
str = 'number %d' % 11
Expand Down

0 comments on commit 6b265c9

Please sign in to comment.