Skip to content

Commit eb7783f

Browse files
TheIronBornjasonwilliams
authored andcommitted
Add more formatting macros to syntax checking (#258)
* make macro regex more readable * add tests
1 parent 9ef37ea commit eb7783f

File tree

2 files changed

+23
-9
lines changed

2 files changed

+23
-9
lines changed

RustEnhanced.sublime-syntax

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -162,7 +162,8 @@ contexts:
162162
- match: '\b[[:lower:]_][[:lower:][:digit:]_]*(?=\()'
163163
scope: support.function.rust
164164

165-
- match: '\b((?:format|print|println|panic|format_args|unreachable)!)\s*(\()'
165+
# macros which take format specs as the only parameter
166+
- match: '\b((?:format(?:_args)?|e?print(?:ln)?|panic|unreachable|unimplemented)!)\s*(\()'
166167
captures:
167168
1: support.macro.rust
168169
2: meta.group.rust punctuation.definition.group.begin.rust
@@ -174,7 +175,8 @@ contexts:
174175
- match: '(?=\S)'
175176
set: group-tail
176177

177-
- match: '\b((?:write|writeln)!)\s*(\()'
178+
# macros which take format specs as the second parameter
179+
- match: '\b((?:write(?:ln)?|(?:debug_)?assert)!)\s*(\()'
178180
captures:
179181
1: support.macro.rust
180182
2: meta.group.rust punctuation.definition.group.begin.rust
@@ -190,6 +192,11 @@ contexts:
190192
set: group-tail
191193
- include: group-tail
192194

195+
# macros which take format specs as the third parameter
196+
# - match: '\b((?:assert_eq|assert_ne|debug_assert_eq|debug_assert_ne)!)\s*(\()'
197+
# is more performant as the below
198+
# - match: '\b((?:debug_)?assert_(?:eq|ne)!)\s*(\()'
199+
193200
- match: '\b[[:lower:]_][[:lower:][:digit:]_]*!(?=\s*(\(|\{|\[))'
194201
scope: support.macro.rust
195202

syntax_test_rust.rs

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -276,14 +276,18 @@ impl fmt::Display for PrintableStruct {
276276
// ^ punctuation.definition.group.end
277277
write!(f, "{:10}", self.0)
278278
// ^^^^^ constant.other.placeholder
279-
write!(f, "{:^10}", self.0)
280-
// ^^^^^^ constant.other.placeholder
281-
write!(f, "{:+046.89?}", self.0)
279+
eprint!("{:^10}", self.0)
280+
// ^^^^^^^ support.macro
281+
// ^^^^^^ constant.other.placeholder
282+
eprintln!("{:+046.89?}", self.0)
283+
// ^^^^^^^^^ support.macro
282284
// ^^^^^^^^^^^ constant.other.placeholder
283-
write!(f, "{:-^#10x}", self.0)
284-
// ^^^^^^^^^ constant.other.placeholder
285-
write!(f, "{4j:#xf10}", self.0)
286-
// ^^^^^^^^^^ string.quoted.double
285+
assert!(true, "{:-^#10x}", self.0)
286+
// ^^^^^^^ support.macro
287+
// ^^^^^^^^^ constant.other.placeholder
288+
debug_assert!(true, "{4j:#xf10}", self.0)
289+
// ^^^^^^^^^^^^^ support.macro
290+
// ^^^^^^^^^^ string.quoted.double
287291
write!(f, "{{}}", self.0)
288292
// ^^^^ constant.character.escape.rust
289293
write!(get_writer(), "{}", "{}")
@@ -1045,6 +1049,9 @@ pub fn macro_tests() {
10451049
unreachable!("{:?}", e);
10461050
// ^^^^^^^^^^^^ support.macro.rust
10471051
// ^^^^ constant.other.placeholder.rust
1052+
unimplemented!("{:?}", e);
1053+
// ^^^^^^^^^^^^^^ support.macro.rust
1054+
// ^^^^ constant.other.placeholder.rust
10481055
}
10491056

10501057
#[derive(Clone)]

0 commit comments

Comments
 (0)