vdoc: fix panic on empty // comment on v doc -f html file.v; turn expected code block after empty example to a warning

This commit is contained in:
Delyan Angelov 2022-05-02 23:48:37 +03:00
parent cf92224248
commit 4da2908d63
No known key found for this signature in database
GPG key ID: 66886C0F12D595ED
6 changed files with 36 additions and 13 deletions

View file

@ -162,7 +162,11 @@ fn color_highlight(code string, tb &ast.Table) string {
lit = term.yellow('`$tok.lit`')
}
.comment {
lit = if tok.lit[0] == 1 { '//${tok.lit[1..]}' } else { '//$tok.lit' }
lit = if tok.lit != '' && tok.lit[0] == 1 {
'//${tok.lit[1..]}'
} else {
'//$tok.lit'
}
}
.keyword {
lit = term.bright_blue(tok.lit)
@ -209,16 +213,18 @@ fn color_highlight(code string, tb &ast.Table) string {
} else if
next_tok.kind in [.lcbr, .rpar, .eof, .comma, .pipe, .name, .rcbr, .assign, .key_pub, .key_mut, .pipe, .comma]
&& prev.kind in [.name, .amp, .rsbr, .key_type, .assign, .dot, .question, .rpar, .key_struct, .key_enum, .pipe, .key_interface]
&& (tok.lit[0].is_capital() || prev_prev.lit in ['C', 'JS']) {
&& ((tok.lit != '' && tok.lit[0].is_capital())
|| prev_prev.lit in ['C', 'JS']) {
tok_typ = .symbol
} else if next_tok.kind == .lpar || (!tok.lit[0].is_capital()
&& next_tok.kind == .lt && next_tok.pos == tok.pos + tok.lit.len) {
} else if next_tok.kind == .lpar
|| (!(tok.lit != '' && tok.lit[0].is_capital()) && next_tok.kind == .lt
&& next_tok.pos == tok.pos + tok.lit.len) {
tok_typ = .function
} else if next_tok.kind == .dot {
if tok.lit in ['C', 'JS'] {
tok_typ = .prefix
} else {
if tok.lit[0].is_capital() {
if tok.lit != '' && tok.lit[0].is_capital() {
tok_typ = .symbol
} else {
tok_typ = .module_