|
| 1 | +# Rust syntax file for Diffuse |
| 2 | +# Copyright (C) 2022 Alexander Lopatin (@alopatindev), Romain Failliot <[email protected]> |
| 3 | + |
| 4 | +# DISCLAIMER: this is a raw support for Rust language, help wanted. |
| 5 | + |
| 6 | +syntax Rust normal text |
| 7 | +syntax_files Rust '\.rs$' |
| 8 | + |
| 9 | +# Colours |
| 10 | +colour rust_comment 0.2 0.4 0.64 |
| 11 | +colour rust_fixme 1.0 0.5 0.0 |
| 12 | +colour rust_import 0.77 0.63 0.0 |
| 13 | +colour rust_keyword 0.77 0.63 0.0 |
| 14 | +colour rust_type 0.3 0.6 0.02 |
| 15 | +colour rust_literal 1.0 0.2 0.8 |
| 16 | +colour rust_char 0.8 0.0 0.0 |
| 17 | +colour rust_string 0.8 0.0 0.0 |
| 18 | +colour rust_escapedchar 0.46 0.31 0.48 |
| 19 | +colour rust_string_multilinechar 0.46 0.31 0.48 |
| 20 | +colour rust_punctuation 0.5 0.5 0.5 |
| 21 | +colour rust_macro 0.01 0.6 0.9 |
| 22 | + |
| 23 | +# Whitespace (TODO) |
| 24 | +# Doc: https://doc.rust-lang.org/reference/whitespace.html |
| 25 | +syntax_pattern normal normal text '[ \t\r\n]+' |
| 26 | + |
| 27 | +# Macro (TODO) |
| 28 | +#syntax_pattern normal macro rust_macro '[a-z_]+[a-z0-9_]*!' ignorecase |
| 29 | + |
| 30 | +# Line comment |
| 31 | +# Doc: https://doc.rust-lang.org/reference/comments.html |
| 32 | +syntax_pattern normal line_comment rust_comment '//' |
| 33 | +syntax_pattern line_comment normal rust_comment '(\r\n|\r|\n)$' |
| 34 | +syntax_pattern line_comment line_comment rust_comment '\\(\r\n|\r|\n)$' |
| 35 | +syntax_pattern line_comment line_comment rust_fixme '\b(TODO|FIXME|XXX|NOTE)\b' |
| 36 | +syntax_pattern line_comment line_comment rust_comment '.[^\\TFX\r\n]*' |
| 37 | + |
| 38 | +# Block comment |
| 39 | +syntax_pattern normal block_comment rust_comment '/\*' |
| 40 | +syntax_pattern block_comment normal rust_comment '\*/' |
| 41 | +syntax_pattern block_comment block_comment rust_fixme '\b(TODO|FIXME|XXX|NOTE)\b' |
| 42 | +syntax_pattern block_comment block_comment rust_comment '.[^\*TFX]*' |
| 43 | + |
| 44 | +# Keywords (TODO) |
| 45 | +# Doc: https://doc.rust-lang.org/reference/keywords.html#weak-keywords |
| 46 | +#syntax_pattern normal normal rust_string '\b\'[a-z_]+[a-z0-9_]*\b' ignorecase |
| 47 | +#syntax_pattern normal normal rust_string '\b\'[a-z_]+\b' ignorecase |
| 48 | +syntax_pattern normal normal rust_string "\b'[a-z_]+\b" ignorecase |
| 49 | + |
| 50 | +# Char |
| 51 | +syntax_pattern normal normal rust_char "'.'" |
| 52 | +syntax_pattern normal char rust_char "'(?=\\\\)" |
| 53 | +syntax_pattern char normal rust_char "'" |
| 54 | +syntax_pattern char char rust_escapedchar "\\\\([0-7]{1,3}|x[0-9a-f]{1,2}|u\{[0-9a-f]{1,6}\}|.)" |
| 55 | + |
| 56 | +# String |
| 57 | +# Doc: https://doc.rust-lang.org/reference/tokens.html#string-literals |
| 58 | +syntax_pattern normal string rust_string '"' |
| 59 | +syntax_pattern string normal rust_string '"' |
| 60 | +syntax_pattern string string rust_escapedchar '(\\([0-7]{1,3}|x[0-9a-f]{1,2}|u\{[0-9a-f]{1,6}\}|.))+' ignorecase |
| 61 | +syntax_pattern string string rust_string_multilinechar '\\$' |
| 62 | +syntax_pattern string string rust_string '[^\\"]+' |
| 63 | + |
| 64 | +# Raw quote-string, level 0 |
| 65 | +# Doc: https://doc.rust-lang.org/reference/tokens.html#raw-string-literals |
| 66 | +syntax_pattern normal raw_string_0 rust_string 'r"' |
| 67 | +syntax_pattern raw_string_0 normal rust_string '"' |
| 68 | +syntax_pattern raw_string_0 raw_string_0 rust_string '[^"$]+' |
| 69 | + |
| 70 | +# Raw sharp-string, level 1 |
| 71 | +syntax_pattern normal raw_string_1 rust_string 'r#"' |
| 72 | +syntax_pattern raw_string_1 normal rust_string '"#' |
| 73 | +syntax_pattern raw_string_1 raw_string_1 rust_string '.*?((?="#)|\r?\n)' |
| 74 | + |
| 75 | +# Raw sharp-string, level 2 |
| 76 | +syntax_pattern normal raw_string_2 rust_string 'r##"' |
| 77 | +syntax_pattern raw_string_2 normal rust_string '"##' |
| 78 | +syntax_pattern raw_string_2 raw_string_2 rust_string '.*?((?="##)|\r?\n)' |
| 79 | + |
| 80 | +# Raw sharp-string, level 3 |
| 81 | +syntax_pattern normal raw_string_3 rust_string 'r###"' |
| 82 | +syntax_pattern raw_string_3 normal rust_string '"###' |
| 83 | +syntax_pattern raw_string_3 raw_string_3 rust_string '.*?((?="###)|\r?\n)' |
| 84 | + |
| 85 | +# Raw sharp-string, level 4 |
| 86 | +syntax_pattern normal raw_string_4 rust_string 'r####"' |
| 87 | +syntax_pattern raw_string_4 normal rust_string '"####' |
| 88 | +syntax_pattern raw_string_4 raw_string_4 rust_string '.*?((?="####)|\r?\n)' |
| 89 | + |
| 90 | +# Raw sharp-string, level 5 |
| 91 | +# Limit is 256 '#', but 5 seems reasonable for now |
| 92 | +syntax_pattern normal raw_string_5 rust_string 'r#####"' |
| 93 | +syntax_pattern raw_string_5 normal rust_string '"#####' |
| 94 | +syntax_pattern raw_string_5 raw_string_5 rust_string '.*?((?="#####)|\r?\n)' |
| 95 | + |
| 96 | +# Suffixes (TODO) |
| 97 | +# Doc: https://doc.rust-lang.org/reference/tokens.html#suffixes |
| 98 | +syntax_pattern normal normal rust_literal '\b[0-9_]+(isize|usize|char|bool|u8|u16|u32|u64|u128|f32|f64|i8|i16|i32|i64|i128|)\b' |
| 99 | +syntax_pattern normal normal rust_literal '\b0b[01_]+(isize|usize|char|bool|u8|u16|u32|u64|u128|f32|f64|i8|i16|i32|i64|i128|)\b' |
| 100 | +syntax_pattern normal normal rust_literal '\b0o[0-7_]+(isize|usize|char|bool|u8|u16|u32|u64|u128|f32|f64|i8|i16|i32|i64|i128|)\b' |
| 101 | +syntax_pattern normal normal rust_literal '\b0x[0-9a-f_]+(isize|usize|char|bool|u8|u16|u32|u64|u128|f32|f64|i8|i16|i32|i64|i128|)\b' |
| 102 | +syntax_pattern normal normal rust_literal '\b[0-9_]+E\+[0-9_]+(f32|f64)\b' |
| 103 | +syntax_pattern normal normal rust_literal '\b(true|false)\b' |
| 104 | + |
| 105 | +# import keywords |
| 106 | +syntax_pattern normal normal rust_import '\b(use|mod)\b' |
| 107 | + |
| 108 | +# typing keywords |
| 109 | +syntax_pattern normal normal rust_type '\b(isize|usize|char|bool|u8|u16|u32|u64|u128|f32|f64|i8|i16|i32|i64|i128|str|Self)\b' |
| 110 | + |
| 111 | +# keywords |
| 112 | +syntax_pattern normal normal rust_keyword '\b(as|break|const|continue|crate|else|enum|extern|false|fn|for|if|impl|in|let|loop|match|move|mut|pub|ref|return|self|Self|static|struct|super|trait|true|type|unsafe|where|while|async|await|dyn|abstract|become|box|do|final|macro|override|priv|typeof|unsized|virtual|yield|try|union)\b' |
| 113 | + |
| 114 | +# punctuation |
| 115 | +syntax_pattern normal normal rust_punctuation '[!~%\|\&\^\(\)\<\>\*\-\+=\{\}\[\]:;,\?$]+' |
| 116 | +syntax_pattern normal normal rust_punctuation '[/\.]' |
| 117 | + |
| 118 | +# parsing optimization |
| 119 | +syntax_pattern normal normal text '[a-z_][a-z_0-9]*' ignorecase |
0 commit comments