vfmt: fix same line stmt comments
parent
fe05f310fb
commit
df45932c03
|
@ -677,6 +677,7 @@ pub:
|
||||||
is_multi bool
|
is_multi bool
|
||||||
line_nr int
|
line_nr int
|
||||||
pos token.Position
|
pos token.Position
|
||||||
|
same_line bool
|
||||||
}
|
}
|
||||||
|
|
||||||
pub struct ConcatExpr {
|
pub struct ConcatExpr {
|
||||||
|
|
|
@ -681,7 +681,13 @@ fn (f mut Fmt) or_expr(or_block ast.OrExpr) {
|
||||||
|
|
||||||
fn (f mut Fmt) comment(node ast.Comment) {
|
fn (f mut Fmt) comment(node ast.Comment) {
|
||||||
if !node.text.contains('\n') {
|
if !node.text.contains('\n') {
|
||||||
f.writeln('// $node.text')// $node.pos.line_nr')
|
is_separate_line := node.text.starts_with('|')
|
||||||
|
if is_separate_line {
|
||||||
|
f.writeln('// ${node.text[1..]}')// $node.pos.line_nr')
|
||||||
|
} else {
|
||||||
|
f.out.go_back(1)
|
||||||
|
f.writeln('// $node.text')
|
||||||
|
}
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
lines := node.text.split_into_lines()
|
lines := node.text.split_into_lines()
|
||||||
|
|
|
@ -11,8 +11,8 @@ import (
|
||||||
v.util
|
v.util
|
||||||
)
|
)
|
||||||
|
|
||||||
|
// Full list of C reserved words, from: https://en.cppreference.com/w/c/keyword
|
||||||
const (
|
const (
|
||||||
// Full list of C reserved words, from: https://en.cppreference.com/w/c/keyword
|
|
||||||
c_reserved = ['delete', 'exit', 'unix',
|
c_reserved = ['delete', 'exit', 'unix',
|
||||||
'error', 'calloc', 'malloc', 'free', 'panic',
|
'error', 'calloc', 'malloc', 'free', 'panic',
|
||||||
'auto', 'char', 'default', 'do', 'double', 'extern', 'float', 'inline', 'int', 'long', 'register',
|
'auto', 'char', 'default', 'do', 'double', 'extern', 'float', 'inline', 'int', 'long', 'register',
|
||||||
|
@ -59,9 +59,6 @@ const (
|
||||||
'\t\t\t\t\t\t\t\t']
|
'\t\t\t\t\t\t\t\t']
|
||||||
)
|
)
|
||||||
|
|
||||||
fn foo(file []ast.File) {}
|
|
||||||
fn foo2(file []int) {}
|
|
||||||
|
|
||||||
pub fn cgen(files []ast.File, table &table.Table, pref &pref.Preferences) string {
|
pub fn cgen(files []ast.File, table &table.Table, pref &pref.Preferences) string {
|
||||||
// println('start cgen2')
|
// println('start cgen2')
|
||||||
mut g := Gen{
|
mut g := Gen{
|
||||||
|
@ -228,6 +225,7 @@ pub fn (g mut Gen) write_typedef_types() {
|
||||||
g.definitions.writeln(');')
|
g.definitions.writeln(');')
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
//
|
||||||
else {
|
else {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
|
@ -732,17 +732,21 @@ pub fn (s mut Scanner) scan() token.Token {
|
||||||
start := s.pos + 1
|
start := s.pos + 1
|
||||||
s.ignore_line()
|
s.ignore_line()
|
||||||
s.line_comment = s.text[start + 1..s.pos]
|
s.line_comment = s.text[start + 1..s.pos]
|
||||||
// if s.comments_mode == .parse_comments {
|
|
||||||
// println('line c $s.line_comment')
|
|
||||||
// }
|
|
||||||
comment := s.line_comment.trim_space()
|
comment := s.line_comment.trim_space()
|
||||||
// s.line_comment = comment
|
|
||||||
if s.comments_mode == .parse_comments {
|
if s.comments_mode == .parse_comments {
|
||||||
// println('line c "$comment" z=')
|
// Find out if this comment is on its own line (for vfmt)
|
||||||
|
mut is_separate_line_comment := true
|
||||||
|
for j := start-2; s.text[j] != `\n`; j-- {
|
||||||
|
if !(s.text[j] in [`\t`, ` `]) {
|
||||||
|
is_separate_line_comment = false
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if is_separate_line_comment {
|
||||||
|
comment = '|' + comment
|
||||||
|
}
|
||||||
|
s.pos--
|
||||||
// fix line_nr, \n was read, and the comment is marked
|
// fix line_nr, \n was read, and the comment is marked
|
||||||
// on the next line
|
// on the next line
|
||||||
s.pos--
|
|
||||||
// println("'" + s.text[s.pos].str() + "'")
|
|
||||||
s.line_nr--
|
s.line_nr--
|
||||||
return s.new_token(.comment, comment)
|
return s.new_token(.comment, comment)
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue