From 91b40304b7b5fa2660af0d759db12c45ecfe22a9 Mon Sep 17 00:00:00 2001 From: Nick Treleaven Date: Mon, 4 Apr 2022 07:21:54 +0100 Subject: [PATCH] vdoc: highlight `..`, `...` as punctuation & postfix ops as operators (#13924) --- cmd/tools/vdoc/html.v | 5 +++-- cmd/tools/vdoc/utils.v | 5 +++-- vlib/v/token/token.v | 5 +++++ 3 files changed, 11 insertions(+), 4 deletions(-) diff --git a/cmd/tools/vdoc/html.v b/cmd/tools/vdoc/html.v index efba062bb4..7f5356dc4f 100644 --- a/cmd/tools/vdoc/html.v +++ b/cmd/tools/vdoc/html.v @@ -348,14 +348,15 @@ fn html_highlight(code string, tb &ast.Table) string { .key_true, .key_false { tok_typ = .boolean } - .lpar, .lcbr, .rpar, .rcbr, .lsbr, .rsbr, .semicolon, .colon, .comma, .dot { + .lpar, .lcbr, .rpar, .rcbr, .lsbr, .rsbr, .semicolon, .colon, .comma, .dot, + .dotdot, .ellipsis { tok_typ = .punctuation } else { if token.is_key(tok.lit) || token.is_decl(tok.kind) { tok_typ = .keyword } else if tok.kind == .decl_assign || tok.kind.is_assign() || tok.is_unary() - || tok.kind.is_relational() || tok.kind.is_infix() { + || tok.kind.is_relational() || tok.kind.is_infix() || tok.kind.is_postfix() { tok_typ = .operator } } diff --git a/cmd/tools/vdoc/utils.v b/cmd/tools/vdoc/utils.v index 08f800abd6..cbfe3238fe 100644 --- a/cmd/tools/vdoc/utils.v +++ b/cmd/tools/vdoc/utils.v @@ -241,7 +241,8 @@ fn color_highlight(code string, tb &ast.Table) string { .key_true, .key_false { tok_typ = .boolean } - .lpar, .lcbr, .rpar, .rcbr, .lsbr, .rsbr, .semicolon, .colon, .comma, .dot { + .lpar, .lcbr, .rpar, .rcbr, .lsbr, .rsbr, .semicolon, .colon, .comma, .dot, + .dotdot, .ellipsis { tok_typ = .punctuation } .key_none { @@ -251,7 +252,7 @@ fn color_highlight(code string, tb &ast.Table) string { if token.is_key(tok.lit) || token.is_decl(tok.kind) { tok_typ = .keyword } else if tok.kind == .decl_assign || tok.kind.is_assign() || tok.is_unary() - || tok.kind.is_relational() || tok.kind.is_infix() { + || tok.kind.is_relational() || tok.kind.is_infix() || tok.kind.is_postfix() { tok_typ = .operator } } diff --git a/vlib/v/token/token.v b/vlib/v/token/token.v index 82a93a11c5..59c200d335 100644 --- a/vlib/v/token/token.v +++ b/vlib/v/token/token.v @@ -494,6 +494,11 @@ pub fn (kind Kind) is_infix() bool { .right_shift, .unsigned_right_shift, .arrow] } +[inline] +pub fn (kind Kind) is_postfix() bool { + return kind in [.inc, .dec, .question] +} + pub fn kind_to_string(k Kind) string { return match k { .unknown { 'unknown' }