Skip to content

Commit

Permalink
Merge pull request atom#18257 from atom/mb-bundle-rust-grammar
Browse files Browse the repository at this point in the history
Provide built-in Rust support using Tree-sitter
  • Loading branch information
Max Brunsfeld authored Oct 19, 2018
2 parents b72fe01 + 14817cb commit e82629c
Show file tree
Hide file tree
Showing 6 changed files with 211 additions and 0 deletions.
14 changes: 14 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,7 @@
"language-python": "https://www.atom.io/api/packages/language-python/versions/0.51.6/tarball",
"language-ruby": "https://www.atom.io/api/packages/language-ruby/versions/0.72.11/tarball",
"language-ruby-on-rails": "https://www.atom.io/api/packages/language-ruby-on-rails/versions/0.25.3/tarball",
"language-rust-bundled": "file:packages/language-rust-bundled",
"language-sass": "https://www.atom.io/api/packages/language-sass/versions/0.62.0/tarball",
"language-shellscript": "https://www.atom.io/api/packages/language-shellscript/versions/0.27.8/tarball",
"language-source": "https://www.atom.io/api/packages/language-source/versions/0.9.0/tarball",
Expand Down Expand Up @@ -252,6 +253,7 @@
"language-python": "0.51.6",
"language-ruby": "0.72.11",
"language-ruby-on-rails": "0.25.3",
"language-rust-bundled": "file:./packages/language-rust-bundled",
"language-sass": "0.62.0",
"language-shellscript": "0.27.8",
"language-source": "0.9.0",
Expand Down
3 changes: 3 additions & 0 deletions packages/language-rust-bundled/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# language-rust

This package provides Rust syntax highlighting in Atom based on syntax trees provided by [tree-sitter-rust](https://github.com/tree-sitter/tree-sitter-rust).
150 changes: 150 additions & 0 deletions packages/language-rust-bundled/grammars/tree-sitter-rust.cson
Original file line number Diff line number Diff line change
@@ -0,0 +1,150 @@
name: 'Rust'
scopeName: 'source.rust'
type: 'tree-sitter'
parser: 'tree-sitter-rust'

fileTypes: [
'rs'
]

comments:
start: '// '

folds: [
{
type: 'block_comment'
}
{
start: {index: 0, type: '{'}
end: {index: -1, type: '}'}
}
{
start: {index: 0, type: '['}
end: {index: -1, type: ']'}
}
{
start: {index: 0, type: '('}
end: {index: -1, type: ')'}
}
{
start: {index: 0, type: '<'}
end: {index: -1, type: '>'}
}
]

scopes:
'type_identifier': 'support.type'
'primitive_type': 'support.type'
'field_identifier': 'variable.other.member'

'line_comment': 'comment.block'
'block_comment': 'comment.block'

'identifier': [
{match: '^[A-Z\\d_]+$', scopes: 'constant.other'}
]

'''
identifier,
call_expression > identifier,
call_expression > field_expression > field_identifier,
call_expression > scoped_identifier > identifier:nth-child(2)
''': [
{match: '^[A-Z]', scopes: 'entity.name.class'}
]

'''
macro_invocation > identifier,
macro_definition > identifier,
call_expression > identifier,
call_expression > field_expression > field_identifier,
call_expression > scoped_identifier > identifier:nth-child(2),
generic_function > identifier,
generic_function > field_expression > field_identifier,
generic_function > scoped_identifier > identifier,
function_item > identifier,
function_signature_item > identifier,
''': 'entity.name.function'

'''
use_list > self,
scoped_use_list > self,
scoped_identifier> self,
use_list > crate,
scoped_use_list > crate,
scoped_identifier> crate,
use_list > super,
scoped_use_list > super,
scoped_identifier> super
''': 'keyword.control'

'''
use_wildcard > identifier:nth-child(0),
scoped_type_identifier > identifier:nth-child(0),
scoped_type_identifier > scoped_identifier:nth-child(0) > identifier,
scoped_identifier > identifier:nth-child(0),
scoped_identifier > scoped_identifier:nth-child(0) > identifier,
use_declaration > identifier,
use_declaration > scoped_identifier > identifier,
use_list > identifier,
use_list > scoped_identifier > identifier,
meta_item > identifier
''': [
{match: '^[A-Z]', scopes: 'support.type'}
]

'lifetime > identifier': 'constant.variable'

'"let"': 'storage.modifier'
'"const"': 'storage.modifier'
'"static"': 'storage.modifier'
'"extern"': 'storage.modifier'
'"fn"': 'storage.modifier'
'"type"': 'storage.modifier'
'"impl"': 'storage.modifier'
'"dyn"': 'storage.modifier'
'"trait"': 'storage.modifier'
'"mod"': 'storage.modifier'
'"pub"': 'storage.modifier'
'"crate"': 'storage.modifier'
'"default"': 'storage.modifier'
'"struct"': 'storage.modifier'
'"enum"': 'storage.modifier'
'"union"': 'storage.modifier'
'mutable_specifier': 'storage.modifier'

'"unsafe"': 'keyword.control'
'"use"': 'keyword.control'
'"match"': 'keyword.control'
'"if"': 'keyword.control'
'"in"': 'keyword.control'
'"else"': 'keyword.control'
'"move"': 'keyword.control'
'"while"': 'keyword.control'
'"loop"': 'keyword.control'
'"for"': 'keyword.control'
'"let"': 'keyword.control'
'"return"': 'keyword.control'
'"continue"': 'keyword.control'
'"break"': 'keyword.control'
'"where"': 'keyword.control'
'"ref"': 'keyword.control'
'"macro_rules!"': 'keyword.control'

'"as"': 'keyword.operator'

'char_literal': 'string.quoted.single'
'string_literal': 'string.quoted.double'
'raw_string_literal': 'string.quoted.other'
'boolean_literal': 'constant.language.boolean'
'integer_literal': 'constant.numeric.decimal'
'float_literal': 'constant.numeric.decimal'
'escape_sequence': 'constant.character.escape'

'attribute_item, inner_attribute_item': 'entity.other.attribute-name'

'''
"as",
"*",
"&",
''': 'keyword.operator'
18 changes: 18 additions & 0 deletions packages/language-rust-bundled/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
{
"name": "language-rust-bundled",
"version": "0.1.0",
"description": "Rust support for Atom",
"keywords": [
"language",
"grammar",
"rust"
],
"repository": "https://github.com/atom/atom",
"license": "MIT",
"dependencies": {
"tree-sitter-rust": "^0.13.4"
},
"engines": {
"atom": ">=1.0.0 <2.0.0"
}
}
24 changes: 24 additions & 0 deletions packages/language-rust-bundled/settings/rust.cson
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
'.source.rust':
'editor':
'commentStart': '// '
'increaseIndentPattern': '(?x)
^ .* \\{ [^}"\']* $
|^ .* \\( [^\\)"\']* $
|^ \\s* \\{ \\} $
'
'decreaseIndentPattern': '(?x)
^ \\s* (\\s* /[*] .* [*]/ \\s*)* \\}
|^ \\s* (\\s* /[*] .* [*]/ \\s*)* \\)
'
'tabLength': 4
'softTabs': true
'preferredLineLength': 99
'bracket-matcher':
autocompleteCharacters: [
'()'
'[]'
'{}'
'<>'
'""'
'``'
]

0 comments on commit e82629c

Please sign in to comment.