Skip to content

Commit

Permalink
[Rust] Rename std_{types,traits} to prelude_*
Browse files Browse the repository at this point in the history
Reorganizing them in the process based on the modules they are defined
in.

Also split off enum names into a separate variable, although I don't
have a scope idea for them now.

Adds FromIterator, TryFrom, TryInto from the 2021 prelude.

Adds multiple types of std::sync and std::ops because they are used
frequently.
  • Loading branch information
FichteFoll committed Dec 23, 2024
1 parent dd9e855 commit 7cd2a86
Showing 1 changed file with 61 additions and 10 deletions.
71 changes: 61 additions & 10 deletions Rust/Rust.sublime-syntax
Original file line number Diff line number Diff line change
Expand Up @@ -25,25 +25,70 @@ variables:
dec_literal: '[0-9](?:[0-9_])*'
float_exponent: '[eE][+-]?[0-9_]*[0-9][0-9_]*'
type_identifier: '\b(?:[[:upper:]]|_*[[:upper:]][[:alnum:]_]*[[:lower:]][[:alnum:]_]*)\b'
std_types: |-
# https://doc.rust-lang.org/std/prelude/index.html
prelude_types: |-
(?x:
Vec|VecDeque
|BTreeMap|BTreeSet|HashMap|HashSet
|Box|Rc|Arc|
# std::boxed
|Box
# std::option
|Option|Result
# std::string
|String
# std::vec
|Vec
# Not in prelude
|VecDeque|BTreeMap|BTreeSet|HashMap|HashSet
|Rc|Arc|Mutex
)
std_traits: |-
prelude_traits: |-
(?x:
Copy|Send|Sized|Sync|Drop|Into|From|Default
|Fn|FnMut|FnOnce
# std::marker
Copy|Send|Sized|Sync|Unpin
# std::ops
|Drop|Fn|FnMut|FnOnce
# std::borrow
|ToOwned
# std::clone
|Clone
# std::cmp
|PartialEq|PartialOrd|Eq|Ord
|ToOwned|Clone|AsRef|AsMut
|Iterator|Extend|IntoIterator|DoubleEndedIterator|ExactSizeIterator
|Some|None|Ok|Err
# std::convert
|Into|From|AsRef|AsMut|TryFrom|TryInto
# std::default
|Default
# std::iter
|Iterator|Extend|IntoIterator|DoubleEndedIterator|ExactSizeIterator|FromIterator
# std::string
|ToString
)
prelude_enums: |-
(?x:
# std::option
Some|None|Ok|Err
)
# Other frequently used types of the std lib.
# https://doc.rust-lang.org/std/index.html#modules
std_types: |-
(?x:
# std::collections
VecDeque|BTreeMap|BTreeSet|HashMap|HashSet
# std::rc
|Rc
# std::sync
|Arc|Barrier|Mutex|Once|OnceLock|LazyLock|RwLock
# std::cell
|Cell|OnceCell|LazyCell|Ref|RefCell|UnsafeCell
)
std_traits: |-
(?x:
# std::ops
|(?:Add|BitAnd|BitOr|BitXor|Div|Mul|Rem|Shl|Shr|Sub)(?:Assign)?
|Deref|DerefMut|Index|IndexMut
|Neg|Not|RangeBounds
|ControlFlow
# already in prelude: Drop|Fn|FnMut|FnOnce
)
contexts:
main:
- include: statements
Expand Down Expand Up @@ -625,6 +670,12 @@ contexts:
- include: stdsimd-type-names

support-type-names:
- match: \b{{prelude_types}}\b
scope: support.type.rust
- match: \b{{prelude_traits}}\b
scope: support.type.rust
- match: \b{{prelude_enums}}\b
scope: support.type.rust
- match: \b{{std_types}}\b
scope: support.type.rust
- match: \b{{std_traits}}\b
Expand Down

0 comments on commit 7cd2a86

Please sign in to comment.