Rust syntax highlighting
This commit is contained in:
parent
48be61e127
commit
ad1e5693c4
|
@ -197,3 +197,73 @@
|
|||
end
|
||||
end
|
||||
```
|
||||
|
||||
- `rust`
|
||||
|
||||
- patterns
|
||||
```rust
|
||||
// this is a comment
|
||||
/* this is a multiline comment */
|
||||
|
||||
"string" 'c' 'ł'
|
||||
b"string" b'ł'
|
||||
r"string" r#"string"# r##"string"## r###"string"###
|
||||
0b11001100 0b11001100_u8
|
||||
0o1234567_f32
|
||||
0xDEADBEEF 0xDEADBEEF_i16
|
||||
2137
|
||||
3.14159265 2.3e-32
|
||||
+ - * / % == ~= <= >= & .
|
||||
#![doc = ""]
|
||||
identifier macro! function() 'static
|
||||
T Vec<i32>
|
||||
union Example
|
||||
europeanunion A
|
||||
```
|
||||
|
||||
- keywords
|
||||
```rust
|
||||
_ as async await break const continue dyn else enum extern fn for if impl in let loop
|
||||
macro_rules! match mod move mut pub ref return static struct trait type unsafe use where while
|
||||
|
||||
crate self Self super
|
||||
|
||||
true false
|
||||
|
||||
abstract become box do final macro override priv try typeof unsized virtual yield
|
||||
```
|
||||
|
||||
- sample
|
||||
```rust
|
||||
use chrono::{Datelike, Utc};
|
||||
use serde::{Deserialize, Serialize};
|
||||
|
||||
#[derive(Debug, Clone, Copy, PartialEq, Eq, Deserialize, Serialize)]
|
||||
#[serde(rename_all = "snake_case")]
|
||||
pub enum Season {
|
||||
Spring,
|
||||
Summer,
|
||||
Autumn,
|
||||
Winter,
|
||||
}
|
||||
|
||||
impl Season {
|
||||
pub fn on(month: u32, day: u32) -> Option<Season> {
|
||||
let md = (month, day);
|
||||
Some(match () {
|
||||
_ if ((1, 1)..=(3, 20)).contains(&md) => Season::Winter,
|
||||
_ if ((3, 21)..=(6, 21)).contains(&md) => Season::Spring,
|
||||
_ if ((6, 22)..=(9, 22)).contains(&md) => Season::Summer,
|
||||
_ if ((9, 23)..=(12, 21)).contains(&md) => Season::Autumn,
|
||||
_ if ((12, 22)..=(12, 31)).contains(&md) => Season::Winter,
|
||||
// Just in case something really darn weird happens to the calendar.
|
||||
_ => return None,
|
||||
})
|
||||
}
|
||||
|
||||
pub fn current() -> Option<Season> {
|
||||
let now = Utc::now();
|
||||
Self::on(now.month(), now.day())
|
||||
}
|
||||
}
|
||||
```
|
||||
|
|
119
static/syntax/rust.json
Normal file
119
static/syntax/rust.json
Normal file
|
@ -0,0 +1,119 @@
|
|||
{
|
||||
"patterns": [
|
||||
{ "regex": "\\/\\/.*", "is": "comment" },
|
||||
{
|
||||
"regex": "\\/\\*.*?\\*\\/",
|
||||
"flags": ["dotMatchesNewline"],
|
||||
"is": "comment"
|
||||
},
|
||||
{ "regex": "'(\\\\'|[^'])'", "is": "string" },
|
||||
{ "regex": "\"(\\\\\"|[^\"])*\"", "is": "string" },
|
||||
{ "regex": "b'(\\\\'|[^'])'", "is": "string" },
|
||||
{ "regex": "b\"(\\\\\"|[^\"])*\"", "is": "string" },
|
||||
{ "regex": "r\"(\\\\\"|[^\"])*\"", "is": "string" },
|
||||
{ "regex": "r#\"(\\\\\"|[^\"])*\"#", "is": "string" },
|
||||
{ "regex": "r##\"(\\\\\"|[^\"])*\"##", "is": "string" },
|
||||
{ "regex": "r###\"(\\\\\"|[^\"])*\"###", "is": "string" },
|
||||
{ "regex": "0[bB][01_]+([uif](8|16|32|64|128))?", "is": "literal" },
|
||||
{ "regex": "0[oO][0-7_]+([uif](8|16|32|64|128))?", "is": "literal" },
|
||||
{
|
||||
"regex": "0[xX][0-9a-fA-F_]+([uif](8|16|32|64|128))?",
|
||||
"is": "literal"
|
||||
},
|
||||
{ "regex": "[0-9_]+n", "is": "literal" },
|
||||
{ "regex": "[0-9_]+(\\.[0-9_]*([eE][-+]?[0-9_]+)?)?", "is": "literal" },
|
||||
{ "regex": "[+=/*^%<>!~|&\\.?:@-]+", "is": "operator" },
|
||||
{ "regex": "#!\\[", "is": "default" },
|
||||
{
|
||||
"regex": "[a-zA-Z_][a-zA-Z0-9_]*(\\()",
|
||||
"is": { "default": "function", "captures": ["default"] }
|
||||
},
|
||||
{ "regex": "[a-zA-Z_][a-zA-Z0-9_]*!", "is": "function" },
|
||||
{ "regex": "[A-Z_][a-zA-Z0-9_]*", "is": "keyword2" },
|
||||
{
|
||||
"regex": "union\\s+([a-zA-Z_][a-zA-Z0-9_]*)",
|
||||
"is": {
|
||||
"default": "keyword1",
|
||||
"captures": ["keyword2"]
|
||||
}
|
||||
},
|
||||
{ "regex": "[a-zA-Z_][a-zA-Z0-9_]*", "is": "identifier" },
|
||||
{ "regex": "'[a-zA-Z_][a-zA-Z0-9_]*", "is": "literal" }
|
||||
],
|
||||
"keywords": {
|
||||
"_": { "into": "keyword1" },
|
||||
"as": { "into": "keyword1" },
|
||||
"async": { "into": "keyword1" },
|
||||
"await": { "into": "keyword1" },
|
||||
"break": { "into": "keyword1" },
|
||||
"const": { "into": "keyword1" },
|
||||
"continue": { "into": "keyword1" },
|
||||
"dyn": { "into": "keyword1" },
|
||||
"else": { "into": "keyword1" },
|
||||
"enum": { "into": "keyword1" },
|
||||
"extern": { "into": "keyword1" },
|
||||
"fn": { "into": "keyword1" },
|
||||
"for": { "into": "keyword1" },
|
||||
"if": { "into": "keyword1" },
|
||||
"impl": { "into": "keyword1" },
|
||||
"in": { "into": "keyword1" },
|
||||
"let": { "into": "keyword1" },
|
||||
"loop": { "into": "keyword1" },
|
||||
"macro_rules!": { "into": "keyword1" },
|
||||
"match": { "into": "keyword1" },
|
||||
"mod": { "into": "keyword1" },
|
||||
"move": { "into": "keyword1" },
|
||||
"mut": { "into": "keyword1" },
|
||||
"pub": { "into": "keyword1" },
|
||||
"ref": { "into": "keyword1" },
|
||||
"return": { "into": "keyword1" },
|
||||
"static": { "into": "keyword1" },
|
||||
"struct": { "into": "keyword1" },
|
||||
"trait": { "into": "keyword1" },
|
||||
"type": { "into": "keyword1" },
|
||||
"unsafe": { "into": "keyword1" },
|
||||
"use": { "into": "keyword1" },
|
||||
"where": { "into": "keyword1" },
|
||||
"while": { "into": "keyword1" },
|
||||
|
||||
"crate": { "into": "keyword2" },
|
||||
"self": { "into": "keyword2" },
|
||||
"Self": { "into": "keyword2" },
|
||||
"super": { "into": "keyword2" },
|
||||
|
||||
"bool": { "into": "keyword2" },
|
||||
"i8": { "into": "keyword2" },
|
||||
"i16": { "into": "keyword2" },
|
||||
"i32": { "into": "keyword2" },
|
||||
"i64": { "into": "keyword2" },
|
||||
"i128": { "into": "keyword2" },
|
||||
"isize": { "into": "keyword2" },
|
||||
"u8": { "into": "keyword2" },
|
||||
"u16": { "into": "keyword2" },
|
||||
"u32": { "into": "keyword2" },
|
||||
"u64": { "into": "keyword2" },
|
||||
"u128": { "into": "keyword2" },
|
||||
"usize": { "into": "keyword2" },
|
||||
"f32": { "into": "keyword2" },
|
||||
"f64": { "into": "keyword2" },
|
||||
"char": { "into": "keyword2" },
|
||||
"str": { "into": "keyword2" },
|
||||
|
||||
"true": { "into": "literal" },
|
||||
"false": { "into": "literal" },
|
||||
|
||||
"abstract": { "into": "error reserved-word" },
|
||||
"become": { "into": "error reserved-word" },
|
||||
"box": { "into": "error reserved-word" },
|
||||
"do": { "into": "error reserved-word" },
|
||||
"final": { "into": "error reserved-word" },
|
||||
"macro": { "into": "error reserved-word" },
|
||||
"override": { "into": "error reserved-word" },
|
||||
"priv": { "into": "error reserved-word" },
|
||||
"try": { "into": "error reserved-word" },
|
||||
"typeof": { "into": "error reserved-word" },
|
||||
"unsized": { "into": "error reserved-word" },
|
||||
"virtual": { "into": "error reserved-word" },
|
||||
"yield": { "into": "error reserved-word" }
|
||||
}
|
||||
}
|
Loading…
Reference in a new issue