Skip to content

Commit

Permalink
vdoc: highlight .., ... as punctuation & postfix ops as operators (
Browse files Browse the repository at this point in the history
  • Loading branch information
ntrel committed Apr 4, 2022
1 parent 1211b2e commit 91b4030
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 4 deletions.
5 changes: 3 additions & 2 deletions cmd/tools/vdoc/html.v
Expand Up @@ -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
}
}
Expand Down
5 changes: 3 additions & 2 deletions cmd/tools/vdoc/utils.v
Expand Up @@ -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 {
Expand All @@ -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
}
}
Expand Down
5 changes: 5 additions & 0 deletions vlib/v/token/token.v
Expand Up @@ -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' }
Expand Down

0 comments on commit 91b4030

Please sign in to comment.