From 33e8f106cac21acfb1728256fa295a9018b8844b Mon Sep 17 00:00:00 2001 From: June McEnroe Date: Tue, 12 Feb 2019 02:37:23 -0500 Subject: Add Rust to hi This also fixes the block comment pattern to match /* **/ correctly. --- bin/hi.c | 41 ++++++++++++++++++++++++++++++++++++++++- bin/man1/hi.1 | 7 ++++++- 2 files changed, 46 insertions(+), 2 deletions(-) (limited to 'bin') diff --git a/bin/hi.c b/bin/hi.c index e10d120a..0476611e 100644 --- a/bin/hi.c +++ b/bin/hi.c @@ -68,6 +68,7 @@ struct Syntax { #define WS "[[:blank:]]*" #define PATTERN_SQ "'([^']|[\\]')*'" #define PATTERN_DQ "\"([^\"]|[\\]\")*\"" +#define PATTERN_BC "/[*]" "([^*]|[*][^/])*" "[*]+/" #define PATTERN_TODO "FIXME|TODO|XXX" // C syntax {{{ @@ -103,7 +104,7 @@ static const struct Syntax CSyntax[] = { { Comment, .parent = ~SET(String), .pattern = "//.*" }, { Comment, .parent = ~SET(String), .newline = true, - .pattern = "/[*]" "([^*]|[*][^/])*" "[*]/" }, + .pattern = PATTERN_BC }, { Todo, .parent = SET(Comment), .pattern = PATTERN_TODO }, }; @@ -166,6 +167,43 @@ static const struct Syntax MdocSyntax[] = { }; // }}} +// Rust syntax {{{ +#define RUST_IDENT "[[:alpha:]][_[:alnum:]]*" +static const struct Syntax RustSyntax[] = { + { Keyword, .subexp = 2, .pattern = WB + "(" "'?static|[Ss]elf|abstract|as|async|await|become|box|break|const" + "|" "continue|crate|do|dyn|else|enum|extern|false|final|fn|for|if" + "|" "impl|in|let|loop|macro|match|mod|move|mut|override|priv|pub|ref" + "|" "return|struct|super|trait|true|try|type(of)?|union|uns(afe|ized)" + "|" "use|virtual|where|while|yield" + ")" WB }, + { Macro, .newline = true, + .pattern = "#!?[[][^]]*[]]" }, + { Macro, + .pattern = RUST_IDENT "!" }, + { Interp, + .pattern = "[$]" RUST_IDENT }, + { String, + .pattern = "b?'([^']|[\\]')'" }, + { String, + .pattern = "b?" "\"([^\"]|[\\][\n\"])*\"" }, + { Escape, .parent = SET(String), + .pattern = "[\\]([\"'0\\nrt]|u[{][0-9A-Fa-f]{1,6}[}]|x[0-9A-Fa-f]{2})" }, + { Format, .parent = SET(String), + .pattern = "[{][{]|[{][^{}]*[}]|[}][}]" }, + { String, .newline = true, + .pattern = "b?r\"[^\"]*\"" }, + { String, .newline = true, + .pattern = "b?r#+\"" "([^\"]|\"[^#])*" "\"+#+" }, + { Comment, .parent = ~SET(String), + .pattern = "//.*" }, + { Comment, .parent = ~SET(String), .newline = true, + .pattern = PATTERN_BC }, + { Todo, .parent = SET(Comment), + .pattern = PATTERN_TODO }, +}; +// }}} + // sh syntax {{{ static const struct Syntax ShSyntax[] = { { Keyword, .subexp = 2, .pattern = WB @@ -213,6 +251,7 @@ static const struct Language { { "c", "[.][ch]$", CSyntax, ARRAY_LEN(CSyntax) }, { "make", "[.]mk$|^Makefile$", MakeSyntax, ARRAY_LEN(MakeSyntax) }, { "mdoc", "[.][1-9]$", MdocSyntax, ARRAY_LEN(MdocSyntax) }, + { "rust", "[.]rs$", RustSyntax, ARRAY_LEN(RustSyntax) }, { "sh", "[.]sh$", ShSyntax, ARRAY_LEN(ShSyntax) }, { "text", "[.]txt$", NULL, 0 }, }; diff --git a/bin/man1/hi.1 b/bin/man1/hi.1 index 48df1606..537acef5 100644 --- a/bin/man1/hi.1 +++ b/bin/man1/hi.1 @@ -1,4 +1,4 @@ -.Dd February 9, 2019 +.Dd February 11, 2019 .Dt HI 1 .Os . @@ -133,6 +133,11 @@ The .Xr mdoc 7 language. . +.It Cm rust +The Rust 2018 language. +Nested raw strings and block comments +are not highlighted correctly. +. .It Cm sh The POSIX .Xr sh 1 -- cgit 1.4.1 0065c36c97d9dcad853c0c79a836ceed24e3&follow=1'>Add INSTALLING section to READMEJune McEnroe