From a801eb5a0fa6d98fa6cdbafe7a6deef9219616fd Mon Sep 17 00:00:00 2001 From: "K. Lux" Date: Thu, 19 Nov 2020 00:04:01 +0100 Subject: [PATCH 1/3] Rust lexer: move keywords from funcs_macros to types 'drop', 'Some', 'None', 'Ok' and 'Err' are types, not macros. --- pygments/lexers/rust.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/pygments/lexers/rust.py b/pygments/lexers/rust.py index 6a28a88083..8f376672f4 100644 --- a/pygments/lexers/rust.py +++ b/pygments/lexers/rust.py @@ -40,11 +40,10 @@ class RustLexer(RegexLexer): 'ExactSizeIterator', 'Option', 'Result', 'Box', 'ToOwned', 'String', 'ToString', 'Vec', 'Clone', 'Copy', 'Default', 'Eq', 'Hash', 'Ord', 'PartialEq', - 'PartialOrd', 'Ord', + 'PartialOrd', 'Ord', 'drop', 'Some', 'None', 'Ok', 'Err', ), suffix=r'\b'), Name.Builtin) builtin_funcs_macros = (words(( - 'drop', 'Some', 'None', 'Ok', 'Err', 'asm!', 'assert!', 'assert_eq!', 'assert_ne!', 'cfg!', 'column!', 'compile_error!', 'concat!', 'concat_idents!', 'dbg!', 'debug_assert!', 'debug_assert_eq!', 'debug_assert_ne!', 'env!', 'eprint!', 'eprintln!', From 60d8a7f185be149a59456f3db50441651bb19e9b Mon Sep 17 00:00:00 2001 From: "K. Lux" Date: Thu, 19 Nov 2020 00:12:55 +0100 Subject: [PATCH 2/3] Rust lexer: bug fix with regex lexer and '!' + r'\b' Rust macros end with a '!'. The word border (regex '\b') for such expressions is located before the '!' (e. g. "print\b!(...)"). The regex here used the suffix option, which added an r'\b' after each regex (e. g. r'print!\b'). Therefore, the supplied regular expressions didn't match the rust macros. To fix this problem, the suffix is removed. As every macro ends with an '!' (which implicitely includes a word border before), it's not necessary anyway. --- pygments/lexers/rust.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pygments/lexers/rust.py b/pygments/lexers/rust.py index 8f376672f4..584916a53e 100644 --- a/pygments/lexers/rust.py +++ b/pygments/lexers/rust.py @@ -52,7 +52,7 @@ class RustLexer(RegexLexer): 'module_path!', 'option_env!', 'panic!', 'print!', 'println!', 'stringify!', 'thread_local!', 'todo!', 'trace_macros!', 'unimplemented!', 'unreachable!', 'vec!', 'write!', 'writeln!', - ), suffix=r'\b'), Name.Builtin) + )), Name.Builtin) tokens = { 'root': [ From 28b83f979be23dc5e966d13f6eb8f2efd3eca27b Mon Sep 17 00:00:00 2001 From: "K. Lux" Date: Thu, 19 Nov 2020 00:44:42 +0100 Subject: [PATCH 3/3] Rust lexer: changing rust macro type Rust macros seem to fit more into the "magic function" category than into the "builtin" one. --- pygments/lexers/rust.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pygments/lexers/rust.py b/pygments/lexers/rust.py index 584916a53e..0d4bf5fcb3 100644 --- a/pygments/lexers/rust.py +++ b/pygments/lexers/rust.py @@ -52,7 +52,7 @@ class RustLexer(RegexLexer): 'module_path!', 'option_env!', 'panic!', 'print!', 'println!', 'stringify!', 'thread_local!', 'todo!', 'trace_macros!', 'unimplemented!', 'unreachable!', 'vec!', 'write!', 'writeln!', - )), Name.Builtin) + )), Name.Function.Magic) tokens = { 'root': [