diff --git a/.ctags.d/v.ctags b/.ctags.d/v.ctags new file mode 100644 index 0000000000..7d36bdf174 --- /dev/null +++ b/.ctags.d/v.ctags @@ -0,0 +1,44 @@ +## TODO: support more precise struct/const/enum fields + +--langdef=V +--map-V=+.v +--map-V=+.vv +--map-V=+.vsh +--kinddef-V=m,imodule,imported modules +--kinddef-V=M,module,modules +--kinddef-V=C,cfunction,cfunctions +--kinddef-V=f,function,functions +--kinddef-V=h,method,functions +--kinddef-V=c,const,constants +--kinddef-V=v,variable,variables +--kinddef-V=s,struct,structs +--kinddef-V=e,enum,enums +--kinddef-V=i,interface,interfaces +--kinddef-V=S,sfield,struct field +--kinddef-V=E,efield,enum field +--_roledef-V=m.imported,imported module +--_roledef-V=M.declared,module declaration +--regex-V=/^module[[:blank:]]+([0-9a-zA-Z]+)[[:blank:]]*$/\1/M/{_role=declared}{scope=push} +--regex-V=/^import[[:blank:]]+(([0-9a-zA-Z]+)?|.*\.([a-zA-Z_][0-9a-zA-Z]+))[[:blank:]]*$/\2\3/m/{_role=imported}{scope=ref} +--regex-V=/^[[:blank:]]*fn[[:blank:]]+C\.([a-zA-Z_][0-9a-zA-Z_]*)\(/C.\1/C/ +--regex-V=/^(pub)?[[:blank:]]*fn[[:blank:]]+([a-zA-Z_][0-9a-zA-Z_]*)\(/\2/f/ +--regex-V=/^(pub)?[[:blank:]]*fn[[:blank:]]+\(.*\)[[:blank:]]*([a-zA-Z_][0-9a-zA-Z_]*)\(/\2/h/ +--regex-V=/^(pub)?[[:blank:]]*struct[[:blank:]]+([a-zA-Z_][0-9a-zA-Z_]*)[[:blank:]]*\{/\2/s/{scope=push} +--regex-V=/^(pub)?[[:blank:]]*enum[[:blank:]]+([a-zA-Z_][0-9a-zA-Z_]*)[[:blank:]]*\{/\2/e/{scope=push} +--regex-V=/^(pub)?[[:blank:]]*interface[[:blank:]]+([a-zA-Z_][0-9a-zA-Z_]*)[[:blank:]]*\{/\2/i/{scope=push} +--regex-V=/^[[:blank:]]*([a-zA-Z_][0-9a-zA-Z_]+)[[:blank:]]*(,)?[[:blank:]]*(\/\/.*)?$/\1/E/{scope=ref} +--regex-V=/^[[:blank:]]*([a-zA-Z_][0-9a-zA-Z_]+)[[:blank:]]+\??\&?(\[[0-9]*\])?([a-zA-Z_][0-9a-zA-Z_.]+)[[:blank:]]*(\/\/.*)?$/\1/S/{scope=ref} +--regex-V=/^[[:blank:]]*\}[[:blank:]]*$//{scope=pop}{placeholder} + +## Variables: +--regex-V=/^[[:blank:]]*(mut[[:blank:]]*)([a-zA-Z_][0-9a-zA-Z_]+)[[:blank:]]*:=/\2/v/{scope=ref} + +## Consts: +--regex-V=/^(pub)?[[:blank:]]*const[[:blank:]]+\([[:blank:]]*/const/c/{scope=push} +##NB: the next variable regexp should work only inside const ( ), but currently works for ordinary assignments too: +--regex-V=/^[[:blank:]]*([a-zA-Z_][0-9a-zA-Z_]+)[[:blank:]]*=/\1/v/{scope=ref} +--regex-V=/^[[:blank:]]*\)[[:blank:]]*$//{scope=pop}{placeholder} + +--extras=+q +--extras=+r +--fields=+r diff --git a/cmd/v/internal/help/build.txt b/cmd/v/internal/help/build.txt index 7c89477728..3aa323df3c 100644 --- a/cmd/v/internal/help/build.txt +++ b/cmd/v/internal/help/build.txt @@ -89,6 +89,18 @@ The build flags are shared by the build and run commands: -v, -vv, -vvv Enable varying verbosity in the V compiler while compiling + -print_v_files + Just print the list of all parsed .v files, then stop processing further. + This is useful for running external processing tools: + ./v -print_v_files cmd/v | etags -L - + ... will generate a TAGS file, that emacs can then use to jump + to the definition of functions used by v itself. For vim: + ./v -print_v_files cmd/v | ctags -L - + ... will generate a simillar tags file, that vi compatible editors can use. + NB: an useful, although not entirely accurate regexp based Universal Ctags options file + for V is located in `.ctags.d/v.ctags` . If you use https://ctags.io/ , it will be used + up automatically, or you can specify it explicitly with --options=.ctags.d/v.ctags . + For C-specific build flags, use `v help build-c`. See also: diff --git a/cmd/v/v.v b/cmd/v/v.v index 8d99096370..d445d19805 100644 --- a/cmd/v/v.v +++ b/cmd/v/v.v @@ -174,6 +174,9 @@ fn parse_args(args []string) (&pref.Preferences, string) { '-x64' { res.backend = .x64 } + '-print_v_files' { + res.print_v_files = true + } '-os' { target_os := cmdline.option(current_args, '-os', '') i++ diff --git a/vlib/v/builder/builder.v b/vlib/v/builder/builder.v index 9656c35efe..c64de9da9d 100644 --- a/vlib/v/builder/builder.v +++ b/vlib/v/builder/builder.v @@ -82,6 +82,13 @@ pub fn (mut b Builder) parse_imports() { } } b.resolve_deps() + // + if b.pref.print_v_files { + for p in b.parsed_files { + println(p.path) + } + exit(0) + } } pub fn (mut b Builder) resolve_deps() { diff --git a/vlib/v/builder/c.v b/vlib/v/builder/c.v index bae0db0f0f..252e63b5ca 100644 --- a/vlib/v/builder/c.v +++ b/vlib/v/builder/c.v @@ -33,10 +33,11 @@ pub fn (mut b Builder) gen_c(v_files []string) string { pub fn (mut b Builder) build_c(v_files []string, out_file string) { b.out_name_c = out_file b.info('build_c($out_file)') + output := b.gen_c(v_files) mut f := os.create(out_file) or { panic(err) } - f.writeln(b.gen_c(v_files)) + f.writeln(output) f.close() // os.write_file(out_file, b.gen_c(v_files)) } diff --git a/vlib/v/builder/js.v b/vlib/v/builder/js.v index 3917c98399..c18342c307 100644 --- a/vlib/v/builder/js.v +++ b/vlib/v/builder/js.v @@ -29,10 +29,11 @@ pub fn (mut b Builder) gen_js(v_files []string) string { pub fn (mut b Builder) build_js(v_files []string, out_file string) { b.out_name_js = out_file b.info('build_js($out_file)') + output := b.gen_js(v_files) mut f := os.create(out_file) or { panic(err) } - f.writeln(b.gen_js(v_files)) + f.writeln(output) f.close() } diff --git a/vlib/v/pref/pref.v b/vlib/v/pref/pref.v index a8b92034d7..a03ea645c9 100644 --- a/vlib/v/pref/pref.v +++ b/vlib/v/pref/pref.v @@ -80,6 +80,7 @@ pub mut: mod string run_args []string // `v run x.v 1 2 3` => `1 2 3` printfn_list []string // a list of generated function names, whose source should be shown, for debugging + print_v_files bool // when true, just print the list of all parsed .v files then stop. } pub fn backend_from_string(s string) ?Backend {