mirror of
https://github.com/vlang/v.git
synced 2023-08-10 21:13:21 +03:00
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:
parent
cf92224248
commit
4da2908d63
@ -303,7 +303,7 @@ fn html_highlight(code string, tb &ast.Table) string {
|
||||
} else if typ == .char {
|
||||
'`$tok.lit`'
|
||||
} else if typ == .comment {
|
||||
if tok.lit[0] == 1 { '//${tok.lit[1..]}' } else { '//$tok.lit' }
|
||||
if tok.lit != '' && tok.lit[0] == 1 { '//${tok.lit[1..]}' } else { '//$tok.lit' }
|
||||
} else {
|
||||
tok.lit
|
||||
}
|
||||
|
@ -1,7 +1,13 @@
|
||||
module main
|
||||
|
||||
const (
|
||||
source_root = 'temp'
|
||||
source_root = 'temp' // some const
|
||||
another = int(5) //
|
||||
)
|
||||
const (
|
||||
windowpos_undefined_mask = C.SDL_WINDOWPOS_UNDEFINED_MASK // 0x1FFF0000u
|
||||
windowpos_undefined = C.SDL_WINDOWPOS_UNDEFINED //
|
||||
)
|
||||
Used to indicate that you don't care what the window position is.
|
||||
fn funky()
|
||||
funky - comment for function below
|
||||
funky - comment for function below
|
||||
|
9
cmd/tools/vdoc/tests/testdata/basic/main.out
vendored
9
cmd/tools/vdoc/tests/testdata/basic/main.out
vendored
@ -1,6 +1,11 @@
|
||||
module main
|
||||
|
||||
const (
|
||||
source_root = 'temp'
|
||||
source_root = 'temp' // some const
|
||||
another = int(5) //
|
||||
)
|
||||
fn funky()
|
||||
const (
|
||||
windowpos_undefined_mask = C.SDL_WINDOWPOS_UNDEFINED_MASK // 0x1FFF0000u
|
||||
windowpos_undefined = C.SDL_WINDOWPOS_UNDEFINED //
|
||||
)
|
||||
fn funky()
|
||||
|
9
cmd/tools/vdoc/tests/testdata/basic/main.v
vendored
9
cmd/tools/vdoc/tests/testdata/basic/main.v
vendored
@ -1,5 +1,12 @@
|
||||
pub const (
|
||||
source_root = 'temp'
|
||||
source_root = 'temp' // some const
|
||||
another = int(5) //
|
||||
)
|
||||
|
||||
// Used to indicate that you don't care what the window position is.
|
||||
pub const (
|
||||
windowpos_undefined_mask = C.SDL_WINDOWPOS_UNDEFINED_MASK // 0x1FFF0000u
|
||||
windowpos_undefined = C.SDL_WINDOWPOS_UNDEFINED //
|
||||
)
|
||||
|
||||
// funky - comment for function below
|
||||
|
@ -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_
|
||||
|
@ -62,13 +62,12 @@ pub fn (dc DocNode) merge_comments_without_examples() string {
|
||||
if dc.comments[i].is_multi_line_example() {
|
||||
i++
|
||||
if i == dc.comments.len || !dc.comments[i].has_triple_backtick() {
|
||||
eprintln('$dc.file_path:$dc.pos.line_nr: Expected code block after empty example line:')
|
||||
eprintln('$dc.file_path:$dc.pos.line_nr: warning: expected code block after empty example line:')
|
||||
eprintln('// ```')
|
||||
if i < dc.comments.len {
|
||||
eprintln('Found:')
|
||||
eprintln('//' + dc.comments[i].text[1..])
|
||||
}
|
||||
exit(1)
|
||||
}
|
||||
i++
|
||||
for i < dc.comments.len && !dc.comments[i].has_triple_backtick() {
|
||||
|
Loading…
Reference in New Issue
Block a user