Add Rust language
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83
diff --git a/components.js b/components.js
index 7bae569..a315e11 100644
--- a/components.js
+++ b/components.js
@@ -206,6 +206,10 @@ var components = {
"handlebars": {
"title": "Handlebars",
"owner": "Golmote"
+ },
+ "rust": {
+ "title": "Rust",
+ "owner": "Golmote"
}
},
"plugins": {
diff --git a/components/prism-rust.js b/components/prism-rust.js
new file mode 100644
index 0000000..f8ebd31
--- /dev/null
+++ b/components/prism-rust.js
@@ -0,0 +1,53 @@
+/* TODO
+ Add support for Markdown notation inside doc comments
+ Add support for nested block comments...
+ Match closure params even when not followed by dash or brace
+ Add better support for macro definition
+*/
+
+Prism.languages.rust = {
+ 'comment': [
+ {
+ pattern: /(^|[^\\])\/\*[\w\W]*?\*\//g,
+ lookbehind: true
+ },
+ {
+ pattern: /(^|[^\\:])\/\/.*?(\r?\n|$)/g,
+ lookbehind: true
+ }
+ ],
+ 'string': [
+ /b?r(#*)"(?:\\?.)*?"\1/g,
+ /b?("|')(?:\\?.)*?\1/g
+ ],
+ 'keyword': /\b(?:abstract|alignof|as|be|box|break|const|continue|crate|do|else|enum|extern|false|final|fn|for|if|impl|in|let|loop|match|mod|move|mut|offsetof|once|override|priv|pub|pure|ref|return|sizeof|static|self|struct|super|true|trait|type|typeof|unsafe|unsized|use|virtual|where|while|yield)\b/,
+
+ 'attribute': {
+ pattern: /#!?\[.+?\]/,
+ alias: 'attr-name'
+ },
+
+ 'function': [
+ /[a-z0-9_]+(?=\s*\()/ig,
+ // Macros can use parens or brackets
+ /[a-z0-9_]+!(?=\s*\(|\[)/ig
+ ],
+ 'macro-rules': {
+ pattern: /[a-z0-9_]+!/ig,
+ alias: 'function'
+ },
+
+ // Hex, oct, bin, dec numbers with visual separators and type suffix
+ 'number': /\b-?(?:0x[\dA-Fa-f](?:_?[\dA-Fa-f])*|0o[0-7](?:_?[0-7])*|0b[01](?:_?[01])*|(\d(_?\d)*)?\.?\d(_?\d)*([Ee][+-]?\d+)?)(?:_?(?:[iu](?:8|16|32)?|f32|f64))?\b/g,
+
+ // Closure params should not be confused with bitwise OR |
+ 'closure-params': {
+ pattern: /\|[^|]*\|(?=\s*[{-])/,
+ inside: {
+ 'punctuation': /[\|:,]/,
+ 'operator': /[&*]/
+ }
+ },
+ 'punctuation': /[{}[\];(),.:]|->/g,
+ 'operator': /[-+]{1,2}|!=?|<=?|>=?|={1,3}|&&?|\|\|?|\*|\/|\^|%|<<|>>@/g
+};
\ No newline at end of file
diff --git a/components/prism-rust.min.js b/components/prism-rust.min.js
new file mode 100644
index 0000000..86dbdb8
--- /dev/null
+++ b/components/prism-rust.min.js
@@ -0,0 +1 @@
+Prism.languages.rust={comment:[{pattern:/(^|[^\\])\/\*[\w\W]*?\*\//g,lookbehind:!0},{pattern:/(^|[^\\:])\/\/.*?(\r?\n|$)/g,lookbehind:!0}],string:[/b?r(#*)"(?:\\?.)*?"\1/g,/b?("|')(?:\\?.)*?\1/g],keyword:/\b(?:abstract|alignof|as|be|box|break|const|continue|crate|do|else|enum|extern|false|final|fn|for|if|impl|in|let|loop|match|mod|move|mut|offsetof|once|override|priv|pub|pure|ref|return|sizeof|static|self|struct|super|true|trait|type|typeof|unsafe|unsized|use|virtual|where|while|yield)\b/,attribute:{pattern:/#!?\[.+?\]/,alias:"attr-name"},"function":[/[a-z0-9_]+(?=\s*\()/gi,/[a-z0-9_]+!(?=\s*\(|\[)/gi],"macro-rules":{pattern:/[a-z0-9_]+!/gi,alias:"function"},number:/\b-?(?:0x[\dA-Fa-f](?:_?[\dA-Fa-f])*|0o[0-7](?:_?[0-7])*|0b[01](?:_?[01])*|(\d(_?\d)*)?\.?\d(_?\d)*([Ee][+-]?\d+)?)(?:_?(?:[iu](?:8|16|32)?|f32|f64))?\b/g,"closure-params":{pattern:/\|[^|]*\|(?=\s*[{-])/,inside:{punctuation:/[\|:,]/,operator:/[&*]/}},punctuation:/[{}[\];(),.:]|->/g,operator:/[-+]{1,2}|!=?|<=?|>=?|={1,3}|&&?|\|\|?|\*|\/|\^|%|<<|>>@/g};
\ No newline at end of file