1
0
mirror of https://github.com/vlang/v.git synced 2023-08-10 21:13:21 +03:00

doc: vfmt and make compile

This commit is contained in:
Alexander Medvednikov 2020-09-09 14:24:42 +02:00
parent cb43084e26
commit 78e28a72ed

View File

@ -14,7 +14,7 @@ import v.util
pub struct Doc { pub struct Doc {
pub mut: pub mut:
input_path string = '' input_path string
prefs &pref.Preferences = &pref.Preferences{} prefs &pref.Preferences = &pref.Preferences{}
table &table.Table = &table.Table{} table &table.Table = &table.Table{}
pub_only bool = true pub_only bool = true
@ -34,10 +34,10 @@ pub:
pub struct DocNode { pub struct DocNode {
pub mut: pub mut:
name string name string
content string = '' content string
comment string comment string
pos DocPos = DocPos{-1, -1} pos DocPos = DocPos{-1, -1}
file_path string = '' file_path string
attrs map[string]string attrs map[string]string
} }
@ -60,29 +60,29 @@ pub fn get_comment_block_right_before(comments []ast.Comment) string {
if last_comment_line_nr != 0 && cmt.pos.line_nr < last_comment_line_nr - 1 { if last_comment_line_nr != 0 && cmt.pos.line_nr < last_comment_line_nr - 1 {
// skip comments that are not part of a continuous block, // skip comments that are not part of a continuous block,
// located right above the top level statement. // located right above the top level statement.
// break // break
} }
mut cmt_content := cmt.text.trim_left('|') mut cmt_content := cmt.text.trim_left('|')
if cmt_content.len == cmt.text.len || cmt.is_multi { if cmt_content.len == cmt.text.len || cmt.is_multi {
// ignore /* */ style comments for now // ignore /* */ style comments for now
continue continue
// if cmt_content.len == 0 { // if cmt_content.len == 0 {
// continue // continue
// } // }
// mut new_cmt_content := '' // mut new_cmt_content := ''
// mut is_codeblock := false // mut is_codeblock := false
// // println(cmt_content) // // println(cmt_content)
// lines := cmt_content.split_into_lines() // lines := cmt_content.split_into_lines()
// for j, line in lines { // for j, line in lines {
// trimmed := line.trim_space().trim_left(cmt_prefix) // trimmed := line.trim_space().trim_left(cmt_prefix)
// if trimmed.starts_with('- ') || (trimmed.len >= 2 && trimmed[0].is_digit() && trimmed[1] == `.`) || is_codeblock { // if trimmed.starts_with('- ') || (trimmed.len >= 2 && trimmed[0].is_digit() && trimmed[1] == `.`) || is_codeblock {
// new_cmt_content += line + '\n' // new_cmt_content += line + '\n'
// } else if line.starts_with('```') { // } else if line.starts_with('```') {
// is_codeblock = !is_codeblock // is_codeblock = !is_codeblock
// new_cmt_content += line + '\n' // new_cmt_content += line + '\n'
// } else { // } else {
// new_cmt_content += trimmed + '\n' // new_cmt_content += trimmed + '\n'
// } // }
// } // }
// return new_cmt_content // return new_cmt_content
} }
@ -156,7 +156,9 @@ pub fn (d Doc) get_name(stmt ast.Stmt) string {
pub fn new_vdoc_preferences() &pref.Preferences { pub fn new_vdoc_preferences() &pref.Preferences {
// vdoc should be able to parse as much user code as possible // vdoc should be able to parse as much user code as possible
// so its preferences should be permissive: // so its preferences should be permissive:
return &pref.Preferences{ enable_globals: true } return &pref.Preferences{
enable_globals: true
}
} }
pub fn new(input_path string) Doc { pub fn new(input_path string) Doc {
@ -424,13 +426,8 @@ fn (mut d Doc) generate() ?Doc {
ast.InterfaceDecl { node.attrs['category'] = 'Interfaces' } ast.InterfaceDecl { node.attrs['category'] = 'Interfaces' }
ast.StructDecl { node.attrs['category'] = 'Structs' } ast.StructDecl { node.attrs['category'] = 'Structs' }
ast.TypeDecl { node.attrs['category'] = 'Typedefs' } ast.TypeDecl { node.attrs['category'] = 'Typedefs' }
ast.FnDecl { ast.FnDecl { node.attrs['category'] = if node.attrs['parent'] in ['void', ''] ||
node.attrs['category'] = if node.attrs['parent'] in ['void', ''] || !node.attrs.exists('parent') { !node.attrs.exists('parent') { 'Functions' } else { 'Methods' } }
'Functions'
} else {
'Methods'
}
}
else {} else {}
} }
d.contents << node d.contents << node