Skip to content

Commit 296b8e9

Browse files
TheIronBornJayflux
authored andcommitted
a few small syntax checking improvements (#239)
* a few small syntax checking improvements * use variables in storage type * add exponent syntax tests
1 parent f4f8926 commit 296b8e9

File tree

2 files changed

+25
-11
lines changed

2 files changed

+25
-11
lines changed

RustEnhanced.sublime-syntax

Lines changed: 16 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,10 @@ file_extensions:
77
scope: source.rust
88
variables:
99
identifier: '(?:[[:alpha:]][_[:alnum:]]*|_[_[:alnum:]]+)'
10-
escaped_byte: '\\(x\h{2}|n|r|t|0|"|''|\\)'
11-
escaped_char: '\\(x\h{2}|n|r|t|0|"|''|\\|u\{\h{1,6}\})'
10+
escaped_byte: '\\([nrt0\"''\\]|x\h{2})'
11+
escaped_char: '\\([nrt0\"''\\]|x\h{2}|u\{\h{1,6}\})'
1212
int_suffixes: '[iu](?:8|16|32|64|size)'
13+
float_suffixes: 'f(32|64)'
1314
contexts:
1415
main:
1516
- include: statements
@@ -310,8 +311,8 @@ contexts:
310311
scope: keyword.operator.rust
311312
- match: '[!]?(?=\bSync|Send\b)'
312313
scope: keyword.operator.rust
313-
- match: \b(Copy|Send|Sized|Sync|Drop|Fn|FnMut|FnOnce|Box|ToOwned|Clone|PartialEq|PartialOrd|Eq|Ord|AsRef|AsMut|Into|From|Default|Iterator|Extend|IntoIterator|DoubleEndedIterator|ExactSizeIterator|Option|Some|None|Result|Ok|Err|SliceConcatExt|String|ToString|Vec)\b
314-
scope: support.type.rust
314+
- match: \b(Copy|Send|Sized|Sync|Drop|Fn|FnMut|FnOnce|Box|ToOwned|Clone|PartialEq|PartialOrd|Eq|Ord|AsRef|AsMut|Into|From|Default|Iterator|Extend|IntoIterator|DoubleEndedIterator|ExactSizeIterator|Option|Some|None|Result|Ok|Err|SliceConcatExt|String|ToString|Vec)\b
315+
scope: support.type.rust
315316

316317
return-type:
317318
- match: '\bimpl\b'
@@ -394,7 +395,7 @@ contexts:
394395
type:
395396
- match: '{{identifier}}(?=<)'
396397
push: generic-angles
397-
- match: \b(Self|i8|i16|i32|i64|isize|u8|u16|u32|u64|usize|f32|f64|bool|char|str)\b
398+
- match: \b(Self|{{int_suffixes}}|{{float_suffixes}}|bool|char|str)\b
398399
scope: storage.type.rust
399400

400401
generic-angles:
@@ -982,30 +983,34 @@ contexts:
982983
scope: constant.other.placeholder.rust
983984
984985
numbers:
985-
- match: '\b((?:\d[\d_]*)?\d\.)(\d[\d_]*(?:[eE][+-]?[\d_]*\d[\d_]*)?)(f32|f64)?'
986+
- match: '\b((?:\d[\d_]*)?\.)(\d[\d_]*(?:[eE][+-]?[\d_]+)?)({{float_suffixes}})?'
986987
captures:
987988
1: constant.numeric.float.rust
988989
2: constant.numeric.float.rust
989990
3: storage.type.numeric.rust
990-
- match: '\b((?:\d[\d_]*)?\d\.)(?!\.)'
991+
- match: '\b(\d[\d_]*\.)(?!\.)'
991992
scope: constant.numeric.float.rust
992-
- match: '\b(\d[\d_]*)(f32|f64)\b'
993+
- match: '\b(\d[\d_]*)({{float_suffixes}})\b'
994+
captures:
995+
1: constant.numeric.float.rust
996+
2: storage.type.numeric.rust
997+
- match: '\b(\d[\d_]*(?:\.[\d_]+)?[eE][-+]?[\d_]+)({{float_suffixes}})?\b'
993998
captures:
994999
1: constant.numeric.float.rust
9951000
2: storage.type.numeric.rust
9961001
- match: '\b(\d[\d_]*)({{int_suffixes}})?\b'
9971002
captures:
9981003
1: constant.numeric.integer.decimal.rust
9991004
2: storage.type.numeric.rust
1000-
- match: '\b(0x[\h_]*\h[\h_]*)({{int_suffixes}})?\b'
1005+
- match: '\b(0x[\h_]+)({{int_suffixes}})?\b'
10011006
captures:
10021007
1: constant.numeric.integer.hexadecimal.rust
10031008
2: storage.type.numeric.rust
1004-
- match: '\b(0o[0-7_]*[0-7][0-7_]*)({{int_suffixes}})?\b'
1009+
- match: '\b(0o[0-7_]+)({{int_suffixes}})?\b'
10051010
captures:
10061011
1: constant.numeric.integer.octal.rust
10071012
2: storage.type.numeric.rust
1008-
- match: '\b(0b[0-1_]*[0-1][0-1_]*)({{int_suffixes}})?\b'
1013+
- match: '\b(0b[0-1_]+)({{int_suffixes}})?\b'
10091014
captures:
10101015
1: constant.numeric.integer.binary.rust
10111016
2: storage.type.numeric.rust

syntax_test_rust.rs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,15 @@ let raw_bytes = br#"This won't escape anything either \x01 \""#;
9898
// <- constant.numeric.float
9999
// <- storage.type - constant.numeric.float
100100
//^^ storage.type - constant.numeric.float
101+
1e+8;
102+
// <- constant.numeric.float
103+
// <- constant.numeric.float
104+
//^^ constant.numeric.float
105+
1.0E-8234987_f64;
106+
// <- constant.numeric.float
107+
// <- constant.numeric.float
108+
//^^^^^^^^^^^ constant.numeric.float
109+
// ^^^ storage.type - constant.numeric.float
101110

102111
0x0;
103112
// <- constant.numeric.integer.hexadecimal

0 commit comments

Comments
 (0)