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

run vfmt on fn.v

This commit is contained in:
Alexander Medvednikov 2019-12-18 09:04:35 +03:00
parent 81045023c4
commit 569b32bd1e
6 changed files with 347 additions and 323 deletions

3
v.v
View File

@ -21,9 +21,8 @@ const (
fn main() {
//t := time.ticks()
//defer { println(time.ticks() - t) }
// There's no `flags` module yet, so args have to be parsed manually
args := compiler.env_vflags_and_os_args()
options, command := compiler.get_v_options_and_main_command( args )
options, command := compiler.get_v_options_and_main_command( args )
// external tool
if command in simple_tools {
compiler.launch_tool('v' + command)

File diff suppressed because it is too large Load Diff

View File

@ -1159,6 +1159,20 @@ pub fn vfmt(args[]string) {
println('v fmt can only be used on .v files')
exit(1)
}
println('WIP')
/*
vexe := vexe_path()
//launch_tool('vfmt', '-d vfmt')
vroot := os.dir(vexe)
os.chdir(vroot)
ret := os.system('$vexe -o $vroot/tools/vfmt -d vfmt v.v')
if ret != 0 {
println('err')
return
}
os.exec('$vroot/tools/vfmt $file') or { panic(err) }
//if !os.exists('
*/
}
pub fn create_symlink() {

View File

@ -853,6 +853,9 @@ fn (p &Parser) strtok() string {
return p.lit
}
if p.tok == .chartoken {
if p.lit == '`' {
return '`\\$p.lit`'
}
return '`$p.lit`'
}
if p.tok == .str {
@ -964,7 +967,7 @@ fn (p mut Parser) get_type() string {
// Register anon fn type
fn_typ := Type{
name: f.typ_str() // 'fn (int, int) string'
mod: p.mod
func: f
}
@ -2902,6 +2905,7 @@ fn (p mut Parser) attribute() {
fn (p mut Parser) defer_st() {
p.check(.key_defer)
p.fspace()
p.check(.lcbr)
pos := p.cgen.lines.len
// Save everything inside the defer block to `defer_text`.

View File

@ -75,8 +75,6 @@ fn new_scanner_file(file_path string) &Scanner {
fn new_scanner(text string) &Scanner {
return &Scanner{
text: text
// fmt_out: strings.new_builder(1000)
print_line_on_error: true
print_colored_error: true
print_rel_paths_on_error: true

View File

@ -243,16 +243,16 @@ fn (p &Parser) gen_fmt() {
if s == '' {
return
}
if !p.file_name.contains('scanner.v') {return}
if !p.file_name.contains('fn.v') {return}
path := os.tmpdir() + '/' + p.file_name
println('generating ${path}')
mut out := os.create(path) or {
verror('failed to create fmt.v')
return
}
println('replacing ${p.file_path}...')
os.mv(path, p.file_path)
println('replacing ${p.file_path}...\n')
out.writeln(s)//p.scanner.fmt_out.str().trim_space())
out.close()
os.mv(path, p.file_path)
}