Skip to content

Commit f5f48e2

Browse files
Rust: Generalize declaritive and function-like macros (#742)
1 parent 55b0e59 commit f5f48e2

File tree

3 files changed

+113
-3
lines changed

3 files changed

+113
-3
lines changed

lexers/embedded/rust.xml

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -218,9 +218,6 @@
218218
<rule pattern="(DoubleEndedIterator|ExactSizeIterator|IntoIterator|PartialOrd|PartialEq|ToString|Iterator|ToOwned|Default|Result|String|FnOnce|Extend|Option|FnMut|Unpin|Sized|AsRef|AsMut|Clone|None|From|Into|Sync|drop|Send|Drop|Copy|Some|Ord|Err|Box|Vec|Eq|Ok|Fn)\b">
219219
<token type="NameBuiltin"/>
220220
</rule>
221-
<rule pattern="(is_powerpc64_feature_detected|is_aarch64_feature_detected|is_powerpc_feature_detected|is_mips64_feature_detected|is_mips_feature_detected|is_x86_feature_detected|is_arm_feature_detected|debug_assert_ne|debug_assert_eq|format_args_nl|concat_idents|unimplemented|include_bytes|compile_error|debug_assert|thread_local|trace_macros|macro_rules|format_args|module_path|unreachable|include_str|option_env|global_asm|log_syntax|stringify|assert_ne|assert_eq|llvm_asm|eprintln|include|matches|println|writeln|format|column|assert|concat|eprint|write|panic|print|file|todo|line|env|dbg|vec|cfg|asm)!">
222-
<token type="NameFunctionMagic"/>
223-
</rule>
224221
<rule pattern="::\b">
225222
<token type="Text"/>
226223
</rule>
@@ -297,6 +294,13 @@
297294
<rule pattern="\b(r#)?_?([A-Z][A-Z0-9_]*){2,}\b">
298295
<token type="NameConstant"/>
299296
</rule>
297+
<rule pattern="([a-zA-Z_]\w*!)(\s*)(\(|\[|\{)">
298+
<bygroups>
299+
<token type="NameFunctionMagic"/>
300+
<token type="TextWhitespace"/>
301+
<token type="Punctuation"/>
302+
</bygroups>
303+
</rule>
300304
<rule pattern="(r#)?[a-zA-Z_]\w*">
301305
<token type="Name"/>
302306
</rule>
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
use smallvec::{smallvec, SmallVec};
2+
3+
lazy_static::lazy_static! {
4+
static ref ONE: usize = 1;
5+
}
6+
7+
fn main() {
8+
pretty_assertions::assert_eq!(*ONE, *ONE);
9+
let _: SmallVec<[_; 16]> = smallvec![1, 2, 3];
10+
11+
// And some builtin ones
12+
println!("Hello, world!");
13+
panic!();
14+
}
Lines changed: 92 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,92 @@
1+
[
2+
{"type":"Keyword","value":"use"},
3+
{"type":"TextWhitespace","value":" "},
4+
{"type":"Name","value":"smallvec"},
5+
{"type":"Text","value":"::"},
6+
{"type":"Punctuation","value":"{"},
7+
{"type":"Name","value":"smallvec"},
8+
{"type":"Punctuation","value":","},
9+
{"type":"TextWhitespace","value":" "},
10+
{"type":"Name","value":"SmallVec"},
11+
{"type":"Punctuation","value":"};"},
12+
{"type":"TextWhitespace","value":"\n\n"},
13+
{"type":"Name","value":"lazy_static"},
14+
{"type":"Text","value":"::"},
15+
{"type":"NameFunctionMagic","value":"lazy_static!"},
16+
{"type":"TextWhitespace","value":" "},
17+
{"type":"Punctuation","value":"{"},
18+
{"type":"TextWhitespace","value":"\n "},
19+
{"type":"Keyword","value":"static"},
20+
{"type":"TextWhitespace","value":" "},
21+
{"type":"Keyword","value":"ref"},
22+
{"type":"TextWhitespace","value":" "},
23+
{"type":"NameConstant","value":"ONE"},
24+
{"type":"Text","value":": "},
25+
{"type":"KeywordType","value":"usize"},
26+
{"type":"Text","value":" "},
27+
{"type":"Operator","value":"="},
28+
{"type":"TextWhitespace","value":" "},
29+
{"type":"LiteralNumberInteger","value":"1"},
30+
{"type":"Punctuation","value":";"},
31+
{"type":"TextWhitespace","value":"\n"},
32+
{"type":"Punctuation","value":"}"},
33+
{"type":"TextWhitespace","value":"\n\n"},
34+
{"type":"Keyword","value":"fn"},
35+
{"type":"Text","value":" "},
36+
{"type":"NameFunction","value":"main"},
37+
{"type":"Punctuation","value":"()"},
38+
{"type":"TextWhitespace","value":" "},
39+
{"type":"Punctuation","value":"{"},
40+
{"type":"TextWhitespace","value":"\n "},
41+
{"type":"Name","value":"pretty_assertions"},
42+
{"type":"Text","value":"::"},
43+
{"type":"NameFunctionMagic","value":"assert_eq!"},
44+
{"type":"Punctuation","value":"("},
45+
{"type":"Operator","value":"*"},
46+
{"type":"NameConstant","value":"ONE"},
47+
{"type":"Punctuation","value":","},
48+
{"type":"TextWhitespace","value":" "},
49+
{"type":"Operator","value":"*"},
50+
{"type":"NameConstant","value":"ONE"},
51+
{"type":"Punctuation","value":");"},
52+
{"type":"TextWhitespace","value":"\n "},
53+
{"type":"KeywordDeclaration","value":"let"},
54+
{"type":"TextWhitespace","value":" "},
55+
{"type":"Name","value":"_"},
56+
{"type":"Text","value":": "},
57+
{"type":"NameClass","value":"SmallVec"},
58+
{"type":"Operator","value":"\u003c"},
59+
{"type":"Punctuation","value":"["},
60+
{"type":"Name","value":"_"},
61+
{"type":"Punctuation","value":";"},
62+
{"type":"TextWhitespace","value":" "},
63+
{"type":"LiteralNumberInteger","value":"16"},
64+
{"type":"Punctuation","value":"]"},
65+
{"type":"Operator","value":"\u003e"},
66+
{"type":"TextWhitespace","value":" "},
67+
{"type":"Operator","value":"="},
68+
{"type":"TextWhitespace","value":" "},
69+
{"type":"NameFunctionMagic","value":"smallvec!"},
70+
{"type":"Punctuation","value":"["},
71+
{"type":"LiteralNumberInteger","value":"1"},
72+
{"type":"Punctuation","value":","},
73+
{"type":"TextWhitespace","value":" "},
74+
{"type":"LiteralNumberInteger","value":"2"},
75+
{"type":"Punctuation","value":","},
76+
{"type":"TextWhitespace","value":" "},
77+
{"type":"LiteralNumberInteger","value":"3"},
78+
{"type":"Punctuation","value":"];"},
79+
{"type":"TextWhitespace","value":"\n\n "},
80+
{"type":"CommentSingle","value":"// And some builtin ones\n"},
81+
{"type":"TextWhitespace","value":" "},
82+
{"type":"NameFunctionMagic","value":"println!"},
83+
{"type":"Punctuation","value":"("},
84+
{"type":"LiteralString","value":"\"Hello, world!\""},
85+
{"type":"Punctuation","value":");"},
86+
{"type":"TextWhitespace","value":"\n "},
87+
{"type":"NameFunctionMagic","value":"panic!"},
88+
{"type":"Punctuation","value":"();"},
89+
{"type":"TextWhitespace","value":"\n"},
90+
{"type":"Punctuation","value":"}"},
91+
{"type":"TextWhitespace","value":"\n"}
92+
]

0 commit comments

Comments
 (0)