From 328019eac312bc52f1c1bb5faba684d2e4358ab0 Mon Sep 17 00:00:00 2001 From: Michael Schmidt Date: Sat, 18 Jul 2020 15:29:33 +0200 Subject: [PATCH] Rust: Improvements (#2464) --- components/prism-rust.js | 39 +++- components/prism-rust.min.js | 2 +- examples/prism-rust.html | 15 +- tests/languages/rust/class-name_feature.test | 87 +++++++++ tests/languages/rust/constant_feature.test | 19 ++ tests/languages/rust/function_feature.test | 45 ++++- tests/languages/rust/issue1339.test | 8 +- tests/languages/rust/keyword_feature.test | 20 +- tests/languages/rust/namespace_feature.test | 186 +++++++++++++++++++ 9 files changed, 386 insertions(+), 35 deletions(-) create mode 100644 tests/languages/rust/class-name_feature.test create mode 100644 tests/languages/rust/constant_feature.test create mode 100644 tests/languages/rust/namespace_feature.test diff --git a/components/prism-rust.js b/components/prism-rust.js index cb42b75498..8270791534 100644 --- a/components/prism-rust.js +++ b/components/prism-rust.js @@ -31,7 +31,7 @@ alias: 'string' }, 'attribute': { - pattern: /#!?\[[^[\]]*\]/, + pattern: /#!?\[(?:[^\[\]"]|"(?:\\[\s\S]|[^\\"])*")*\]/, greedy: true, alias: 'attr-name', inside: { @@ -66,26 +66,55 @@ 'variable': /\$\w+/, 'function-definition': { - pattern: /(\bfn\s*)\w+/, + pattern: /(\bfn\s+)\w+/, lookbehind: true, alias: 'function' }, + 'type-definition': { + pattern: /(\b(?:enum|struct|union)\s+)\w+/, + lookbehind: true, + alias: 'class-name' + }, + 'module-declaration': [ + { + pattern: /(\b(?:crate|mod)\s+)[a-z][a-z_\d]*/, + lookbehind: true, + alias: 'namespace' + }, + { + pattern: /(\b(?:crate|self|super)\s*)::\s*[a-z][a-z_\d]*\b(?:\s*::(?:\s*[a-z][a-z_\d]*\s*::)*)?/, + lookbehind: true, + alias: 'namespace', + inside: { + 'punctuation': /::/ + } + } + ], 'keyword': [ // https://github.com/rust-lang/reference/blob/master/src/keywords.md /\b(?:abstract|as|async|await|become|box|break|const|continue|crate|do|dyn|else|enum|extern|final|fn|for|if|impl|in|let|loop|macro|match|mod|move|mut|override|priv|pub|ref|return|self|Self|static|struct|super|trait|try|type|typeof|union|unsafe|unsized|use|virtual|where|while|yield)\b/, - // primitives + // primitives and str // https://doc.rust-lang.org/stable/rust-by-example/primitives.html - /\b(?:[ui](?:8|16|32|64|128|size)|f(?:32|64)|bool|char)\b/ + /\b(?:[ui](?:8|16|32|64|128|size)|f(?:32|64)|bool|char|str)\b/ ], // functions can technically start with an upper-case letter, but this will introduce a lot of false positives // and Rust's naming conventions recommend snake_case anyway. // https://doc.rust-lang.org/1.0.0/style/style/naming/README.html - 'function': /\b[a-z_]\w*(?=\s*(?:::\s*<(?:[^<>]|<(?:[^<>]|<[^<>]*>)*>)*>\s*)?\()/, + 'function': /\b[a-z_]\w*(?=\s*(?:::\s*<|\())/, 'macro': { pattern: /\w+!/, alias: 'property' }, + 'constant': /\b[A-Z_][A-Z_\d]+\b/, + 'class-name': /\b[A-Z]\w*\b/, + + 'namespace': { + pattern: /(?:\b[a-z][a-z_\d]*\s*::\s*)*\b[a-z][a-z_\d]*\s*::(?!\s*<)/, + inside: { + 'punctuation': /::/ + } + }, // 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|64|size)?|f32|f64))?\b/, diff --git a/components/prism-rust.min.js b/components/prism-rust.min.js index aaad309fa5..215b6e9880 100644 --- a/components/prism-rust.min.js +++ b/components/prism-rust.min.js @@ -1 +1 @@ -!function(e){for(var t="/\\*(?:[^*/]|\\*(?!/)|/(?!\\*)|)*\\*/",a=0;a<2;a++)t=t.replace(//g,function(){return t});t=t.replace(//g,function(){return"[^\\s\\S]"}),e.languages.rust={comment:[{pattern:RegExp("(^|[^\\\\])"+t),lookbehind:!0,greedy:!0},{pattern:/(^|[^\\:])\/\/.*/,lookbehind:!0,greedy:!0}],string:{pattern:/b?"(?:\\[\s\S]|[^\\"])*"|b?r(#*)"(?:[^"]|"(?!\1))*"\1/,greedy:!0},char:{pattern:/b?'(?:\\(?:x[0-7][\da-fA-F]|u{(?:[\da-fA-F]_*){1,6}|.)|[^\\\r\n\t'])'/,greedy:!0,alias:"string"},attribute:{pattern:/#!?\[[^[\]]*\]/,greedy:!0,alias:"attr-name",inside:{string:null}},"closure-params":{pattern:/([=(,:]\s*|\bmove\s*)\|[^|]*\||\|[^|]*\|(?=\s*(?:\{|->))/,lookbehind:!0,greedy:!0,inside:{"closure-punctuation":{pattern:/^\||\|$/,alias:"punctuation"},rest:null}},"lifetime-annotation":{pattern:/'\w+/,alias:"symbol"},"fragment-specifier":{pattern:/(\$\w+:)[a-z]+/,lookbehind:!0,alias:"punctuation"},variable:/\$\w+/,"function-definition":{pattern:/(\bfn\s*)\w+/,lookbehind:!0,alias:"function"},keyword:[/\b(?:abstract|as|async|await|become|box|break|const|continue|crate|do|dyn|else|enum|extern|final|fn|for|if|impl|in|let|loop|macro|match|mod|move|mut|override|priv|pub|ref|return|self|Self|static|struct|super|trait|try|type|typeof|union|unsafe|unsized|use|virtual|where|while|yield)\b/,/\b(?:[ui](?:8|16|32|64|128|size)|f(?:32|64)|bool|char)\b/],function:/\b[a-z_]\w*(?=\s*(?:::\s*<(?:[^<>]|<(?:[^<>]|<[^<>]*>)*>)*>\s*)?\()/,macro:{pattern:/\w+!/,alias:"property"},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|64|size)?|f32|f64))?\b/,boolean:/\b(?:false|true)\b/,punctuation:/->|\.\.=|\.{1,3}|::|[{}[\];(),:]/,operator:/[-+*\/%!^]=?|=[=>]?|&[&=]?|\|[|=]?|<>?=?|[@?]/},e.languages.rust["closure-params"].inside.rest=e.languages.rust,e.languages.rust.attribute.inside.string=e.languages.rust.string}(Prism); \ No newline at end of file +!function(e){for(var a="/\\*(?:[^*/]|\\*(?!/)|/(?!\\*)|)*\\*/",t=0;t<2;t++)a=a.replace(//g,function(){return a});a=a.replace(//g,function(){return"[^\\s\\S]"}),e.languages.rust={comment:[{pattern:RegExp("(^|[^\\\\])"+a),lookbehind:!0,greedy:!0},{pattern:/(^|[^\\:])\/\/.*/,lookbehind:!0,greedy:!0}],string:{pattern:/b?"(?:\\[\s\S]|[^\\"])*"|b?r(#*)"(?:[^"]|"(?!\1))*"\1/,greedy:!0},char:{pattern:/b?'(?:\\(?:x[0-7][\da-fA-F]|u{(?:[\da-fA-F]_*){1,6}|.)|[^\\\r\n\t'])'/,greedy:!0,alias:"string"},attribute:{pattern:/#!?\[(?:[^\[\]"]|"(?:\\[\s\S]|[^\\"])*")*\]/,greedy:!0,alias:"attr-name",inside:{string:null}},"closure-params":{pattern:/([=(,:]\s*|\bmove\s*)\|[^|]*\||\|[^|]*\|(?=\s*(?:\{|->))/,lookbehind:!0,greedy:!0,inside:{"closure-punctuation":{pattern:/^\||\|$/,alias:"punctuation"},rest:null}},"lifetime-annotation":{pattern:/'\w+/,alias:"symbol"},"fragment-specifier":{pattern:/(\$\w+:)[a-z]+/,lookbehind:!0,alias:"punctuation"},variable:/\$\w+/,"function-definition":{pattern:/(\bfn\s+)\w+/,lookbehind:!0,alias:"function"},"type-definition":{pattern:/(\b(?:enum|struct|union)\s+)\w+/,lookbehind:!0,alias:"class-name"},"module-declaration":[{pattern:/(\b(?:crate|mod)\s+)[a-z][a-z_\d]*/,lookbehind:!0,alias:"namespace"},{pattern:/(\b(?:crate|self|super)\s*)::\s*[a-z][a-z_\d]*\b(?:\s*::(?:\s*[a-z][a-z_\d]*\s*::)*)?/,lookbehind:!0,alias:"namespace",inside:{punctuation:/::/}}],keyword:[/\b(?:abstract|as|async|await|become|box|break|const|continue|crate|do|dyn|else|enum|extern|final|fn|for|if|impl|in|let|loop|macro|match|mod|move|mut|override|priv|pub|ref|return|self|Self|static|struct|super|trait|try|type|typeof|union|unsafe|unsized|use|virtual|where|while|yield)\b/,/\b(?:[ui](?:8|16|32|64|128|size)|f(?:32|64)|bool|char|str)\b/],function:/\b[a-z_]\w*(?=\s*(?:::\s*<|\())/,macro:{pattern:/\w+!/,alias:"property"},constant:/\b[A-Z_][A-Z_\d]+\b/,"class-name":/\b[A-Z]\w*\b/,namespace:{pattern:/(?:\b[a-z][a-z_\d]*\s*::\s*)*\b[a-z][a-z_\d]*\s*::(?!\s*<)/,inside:{punctuation:/::/}},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|64|size)?|f32|f64))?\b/,boolean:/\b(?:false|true)\b/,punctuation:/->|\.\.=|\.{1,3}|::|[{}[\];(),:]/,operator:/[-+*\/%!^]=?|=[=>]?|&[&=]?|\|[|=]?|<>?=?|[@?]/},e.languages.rust["closure-params"].inside.rest=e.languages.rust,e.languages.rust.attribute.inside.string=e.languages.rust.string}(Prism); \ No newline at end of file diff --git a/examples/prism-rust.html b/examples/prism-rust.html index 3f56a91b6f..e7b2d1ae44 100644 --- a/examples/prism-rust.html +++ b/examples/prism-rust.html @@ -5,7 +5,7 @@

Comments

comment */

Strings

-
'C'; '\''; '\n'; '\u7FFF'; // Characters
+
'C'; '\''; '\n'; '\u{7FFF}'; // Characters
 "foo \"bar\" baz"; // String
 r##"foo #"bar"# baz"##; // Raw string with # pairs
 b'C'; b'\''; b'\n'; // Bytes
@@ -14,10 +14,7 @@ 

Strings

Numbers

-
123i;                              // type int
-123u;                              // type uint
-123_u;                             // type uint
-0xff_u8;                           // type u8
+
0xff_u8;                           // type u8
 0o70_i16;                          // type i16
 0b1111_1111_1001_0000_i32;         // type i32
 
@@ -32,9 +29,9 @@ 

Booleans

Functions and macros

println!("x is {}", x);
-fn next_two(x: int) -> (int, int) { (x + 1i, x + 2i) }
-next_two(5i);
-vec![1i, 2, 3];
+fn next_two(x: i32) -> (i32, i32) { (x + 1, x + 2) }
+next_two(5);
+vec![1, 2, 3];
 

Attributes

@@ -47,6 +44,6 @@

Attributes

Closure parameters and bitwise OR

let x = a | b;
 let y = c || d;
-let add_one = |x: int| -> int { 1i + x };
+let add_one = |x: i32| -> i32 { 1i + x };
 let printer = || { println!("x is: {}", x); };
 
diff --git a/tests/languages/rust/class-name_feature.test b/tests/languages/rust/class-name_feature.test new file mode 100644 index 0000000000..442a8a2557 --- /dev/null +++ b/tests/languages/rust/class-name_feature.test @@ -0,0 +1,87 @@ +struct foo {} + +let foo: CStr; +let foo: &'a CStr; +let foo: &'a Foo; +Option::Some(foo); +Option::None; + +// we can differentiate between enum variants and class names +// so let's make the bug a feature! +enum Foo { + Const, + Tuple(i8,i8), + Struct { + foo: u8 + } +} + +---------------------------------------------------- + +[ + ["keyword", "struct"], + ["type-definition", "foo"], + ["punctuation", "{"], + ["punctuation", "}"], + + ["keyword", "let"], + " foo", + ["punctuation", ":"], + ["class-name", "CStr"], + ["punctuation", ";"], + ["keyword", "let"], + " foo", + ["punctuation", ":"], + ["operator", "&"], + ["lifetime-annotation", "'a"], + ["class-name", "CStr"], + ["punctuation", ";"], + ["keyword", "let"], + " foo", + ["punctuation", ":"], + ["operator", "&"], + ["lifetime-annotation", "'a"], + ["class-name", "Foo"], + ["operator", "<"], + ["keyword", "dyn"], + ["class-name", "Bar"], + ["operator", ">"], + ["punctuation", ";"], + ["class-name", "Option"], + ["punctuation", "::"], + ["class-name", "Some"], + ["punctuation", "("], + "foo", + ["punctuation", ")"], + ["punctuation", ";"], + ["class-name", "Option"], + ["punctuation", "::"], + ["class-name", "None"], + ["punctuation", ";"], + + ["comment", "// we can differentiate between enum variants and class names"], + ["comment", "// so let's make the bug a feature!"], + ["keyword", "enum"], + ["type-definition", "Foo"], + ["punctuation", "{"], + ["class-name", "Const"], + ["punctuation", ","], + ["class-name", "Tuple"], + ["punctuation", "("], + ["keyword", "i8"], + ["punctuation", ","], + ["keyword", "i8"], + ["punctuation", ")"], + ["punctuation", ","], + ["class-name", "Struct"], + ["punctuation", "{"], + "\n\t\tfoo", + ["punctuation", ":"], + ["keyword", "u8"], + ["punctuation", "}"], + ["punctuation", "}"] +] + +---------------------------------------------------- + +Checks for class names and enum variants. diff --git a/tests/languages/rust/constant_feature.test b/tests/languages/rust/constant_feature.test new file mode 100644 index 0000000000..84cac8b121 --- /dev/null +++ b/tests/languages/rust/constant_feature.test @@ -0,0 +1,19 @@ +MAX +SOME_CONSTANT + +// not a constant +T + +---------------------------------------------------- + +[ + ["constant", "MAX"], + ["constant", "SOME_CONSTANT"], + + ["comment", "// not a constant"], + ["class-name", "T"] +] + +---------------------------------------------------- + +Checks for constants. diff --git a/tests/languages/rust/function_feature.test b/tests/languages/rust/function_feature.test index c4a51d434e..e8333422d7 100644 --- a/tests/languages/rust/function_feature.test +++ b/tests/languages/rust/function_feature.test @@ -4,6 +4,8 @@ foo_bar_42( foo_generic::>() +mem::transmute::, Box>() + fn apply(f: F) where F: FnOnce() { f(); } @@ -21,11 +23,40 @@ fn apply(f: F) where F: FnOnce() { ["function", "foo_generic"], ["punctuation", "::"], ["operator", "<"], - "T", + ["class-name", "T"], ["punctuation", ","], - " Option", + ["class-name", "Option"], + ["operator", "<"], + ["class-name", "T"], + ["operator", ">>"], + ["punctuation", "("], + ["punctuation", ")"], + + ["namespace", [ + "mem", + ["punctuation", "::"] + ]], + ["function", "transmute"], + ["punctuation", "::"], + ["operator", "<"], + ["class-name", "Box"], ["operator", "<"], - "T", + ["keyword", "dyn"], + ["class-name", "FnOnce"], + ["punctuation", "("], + ["punctuation", ")"], + ["operator", "+"], + ["lifetime-annotation", "'a"], + ["operator", ">"], + ["punctuation", ","], + ["class-name", "Box"], + ["operator", "<"], + ["keyword", "dyn"], + ["class-name", "FnOnce"], + ["punctuation", "("], + ["punctuation", ")"], + ["operator", "+"], + ["lifetime-annotation", "'static"], ["operator", ">>"], ["punctuation", "("], ["punctuation", ")"], @@ -33,17 +64,17 @@ fn apply(f: F) where F: FnOnce() { ["keyword", "fn"], ["function-definition", "apply"], ["operator", "<"], - "F", + ["class-name", "F"], ["operator", ">"], ["punctuation", "("], "f", ["punctuation", ":"], - " F", + ["class-name", "F"], ["punctuation", ")"], ["keyword", "where"], - " F", + ["class-name", "F"], ["punctuation", ":"], - " FnOnce", + ["class-name", "FnOnce"], ["punctuation", "("], ["punctuation", ")"], ["punctuation", "{"], diff --git a/tests/languages/rust/issue1339.test b/tests/languages/rust/issue1339.test index df5d7d8723..7f7f9a6cce 100644 --- a/tests/languages/rust/issue1339.test +++ b/tests/languages/rust/issue1339.test @@ -1,11 +1,12 @@ const ALL_CARDS: &'static [&'static char] = &["2"] + fn foo<'a> (first: &'a str, second: &'a str) => () { } ---------------------------------------------------- [ ["keyword", "const"], - " ALL_CARDS", + ["constant", "ALL_CARDS"], ["punctuation", ":"], ["operator", "&"], ["lifetime-annotation", "'static"], @@ -19,6 +20,7 @@ fn foo<'a> (first: &'a str, second: &'a str) => () { } ["punctuation", "["], ["string", "\"2\""], ["punctuation", "]"], + ["keyword", "fn"], ["function-definition", "foo"], ["operator", "<"], @@ -29,13 +31,13 @@ fn foo<'a> (first: &'a str, second: &'a str) => () { } ["punctuation", ":"], ["operator", "&"], ["lifetime-annotation", "'a"], - " str", + ["keyword", "str"], ["punctuation", ","], " second", ["punctuation", ":"], ["operator", "&"], ["lifetime-annotation", "'a"], - " str", + ["keyword", "str"], ["punctuation", ")"], ["operator", "=>"], ["punctuation", "("], diff --git a/tests/languages/rust/keyword_feature.test b/tests/languages/rust/keyword_feature.test index 5ec2bb7a6b..a55ca38deb 100644 --- a/tests/languages/rust/keyword_feature.test +++ b/tests/languages/rust/keyword_feature.test @@ -7,11 +7,11 @@ box break const continue -crate +crate; do dyn else -enum +enum; extern final fn; @@ -23,7 +23,7 @@ let loop macro match -mod +mod; move mut override @@ -34,13 +34,13 @@ return self Self static -struct +struct; super trait try type typeof -union +union; unsafe unsized use @@ -61,11 +61,11 @@ yield ["keyword", "break"], ["keyword", "const"], ["keyword", "continue"], - ["keyword", "crate"], + ["keyword", "crate"], ["punctuation", ";"], ["keyword", "do"], ["keyword", "dyn"], ["keyword", "else"], - ["keyword", "enum"], + ["keyword", "enum"], ["punctuation", ";"], ["keyword", "extern"], ["keyword", "final"], ["keyword", "fn"], ["punctuation", ";"], @@ -77,7 +77,7 @@ yield ["keyword", "loop"], ["keyword", "macro"], ["keyword", "match"], - ["keyword", "mod"], + ["keyword", "mod"], ["punctuation", ";"], ["keyword", "move"], ["keyword", "mut"], ["keyword", "override"], @@ -88,13 +88,13 @@ yield ["keyword", "self"], ["keyword", "Self"], ["keyword", "static"], - ["keyword", "struct"], + ["keyword", "struct"], ["punctuation", ";"], ["keyword", "super"], ["keyword", "trait"], ["keyword", "try"], ["keyword", "type"], ["keyword", "typeof"], - ["keyword", "union"], + ["keyword", "union"], ["punctuation", ";"], ["keyword", "unsafe"], ["keyword", "unsized"], ["keyword", "use"], diff --git a/tests/languages/rust/namespace_feature.test b/tests/languages/rust/namespace_feature.test new file mode 100644 index 0000000000..f858e07bbd --- /dev/null +++ b/tests/languages/rust/namespace_feature.test @@ -0,0 +1,186 @@ +use std::{ + fs::File, + io::{BufRead, BufReader}, + path::PathBuf, +}; +use ::serde::de::{Error, Visitor}; +use std::sync::atomic::{AtomicBool, Ordering}; +pub mod sample; +extern crate test; + +Result + +where D: serde::Deserializer<'de>, + +serde_json::from_str(&line) +self.read_records::() + +pub static ALLOCATOR: alloc::Tracing = alloc::Tracing::new(); + +unsafe fn alloc(&self, layout: std::alloc::Layout) -> *mut u8 {} + +---------------------------------------------------- + +[ + ["keyword", "use"], + ["namespace", [ + "std", + ["punctuation", "::"] + ]], + ["punctuation", "{"], + ["namespace", [ + "fs", + ["punctuation", "::"] + ]], + ["class-name", "File"], + ["punctuation", ","], + ["namespace", [ + "io", + ["punctuation", "::"] + ]], + ["punctuation", "{"], + ["class-name", "BufRead"], + ["punctuation", ","], + ["class-name", "BufReader"], + ["punctuation", "}"], + ["punctuation", ","], + ["namespace", [ + "path", + ["punctuation", "::"] + ]], + ["class-name", "PathBuf"], + ["punctuation", ","], + ["punctuation", "}"], + ["punctuation", ";"], + ["keyword", "use"], + ["punctuation", "::"], + ["namespace", [ + "serde", + ["punctuation", "::"], + "de", + ["punctuation", "::"] + ]], + ["punctuation", "{"], + ["class-name", "Error"], + ["punctuation", ","], + ["class-name", "Visitor"], + ["punctuation", "}"], + ["punctuation", ";"], + ["keyword", "use"], + ["namespace", [ + "std", + ["punctuation", "::"], + "sync", + ["punctuation", "::"], + "atomic", + ["punctuation", "::"] + ]], + ["punctuation", "{"], + ["class-name", "AtomicBool"], + ["punctuation", ","], + ["class-name", "Ordering"], + ["punctuation", "}"], + ["punctuation", ";"], + ["keyword", "pub"], + ["keyword", "mod"], + ["module-declaration", "sample"], + ["punctuation", ";"], + ["keyword", "extern"], + ["keyword", "crate"], + ["module-declaration", "test"], + ["punctuation", ";"], + + ["class-name", "Result"], + ["operator", "<"], + ["keyword", "Self"], + ["punctuation", ","], + ["class-name", "D"], + ["punctuation", "::"], + ["class-name", "Error"], + ["operator", ">"], + + ["keyword", "where"], + ["class-name", "D"], + ["punctuation", ":"], + ["namespace", [ + "serde", + ["punctuation", "::"] + ]], + ["class-name", "Deserializer"], + ["operator", "<"], + ["lifetime-annotation", "'de"], + ["operator", ">"], + ["punctuation", ","], + + ["namespace", [ + "serde_json", + ["punctuation", "::"] + ]], + ["function", "from_str"], + ["punctuation", "("], + ["operator", "&"], + "line", + ["punctuation", ")"], + ["keyword", "self"], + ["punctuation", "."], + ["function", "read_records"], + ["punctuation", "::"], + ["operator", "<"], + ["namespace", [ + "smol_str", + ["punctuation", "::"] + ]], + ["class-name", "SmolStr"], + ["operator", ">"], + ["punctuation", "("], + ["punctuation", ")"], + + ["keyword", "pub"], + ["keyword", "static"], + ["constant", "ALLOCATOR"], + ["punctuation", ":"], + ["namespace", [ + "alloc", + ["punctuation", "::"] + ]], + ["class-name", "Tracing"], + ["operator", "="], + ["namespace", [ + "alloc", + ["punctuation", "::"] + ]], + ["class-name", "Tracing"], + ["punctuation", "::"], + ["function", "new"], + ["punctuation", "("], + ["punctuation", ")"], + ["punctuation", ";"], + + ["keyword", "unsafe"], + ["keyword", "fn"], + ["function-definition", "alloc"], + ["punctuation", "("], + ["operator", "&"], + ["keyword", "self"], + ["punctuation", ","], + " layout", + ["punctuation", ":"], + ["namespace", [ + "std", + ["punctuation", "::"], + "alloc", + ["punctuation", "::"] + ]], + ["class-name", "Layout"], + ["punctuation", ")"], + ["punctuation", "->"], + ["operator", "*"], + ["keyword", "mut"], + ["keyword", "u8"], + ["punctuation", "{"], + ["punctuation", "}"] +] + +---------------------------------------------------- + +Checks for namespaces.