diff --git a/cmd/v/internal/help/help.v b/cmd/v/internal/help/help.v index cb12ab39e1..2cba8ec352 100644 --- a/cmd/v/internal/help/help.v +++ b/cmd/v/internal/help/help.v @@ -1,11 +1,8 @@ module help -//TODO: move this file outside internal, and merge it with cmd/tools/modules/vhelp/vhelp.v . - -import ( - os - v.pref -) +// TODO: move this file outside internal, and merge it with cmd/tools/modules/vhelp/vhelp.v . +import os +import v.pref const ( unknown_topic = 'V Error: Unknown help topic provided. Use `v help` for usage information.' diff --git a/vlib/v/gen/js/js.v b/vlib/v/gen/js/js.v index 046c43fc5d..38a70077a2 100644 --- a/vlib/v/gen/js/js.v +++ b/vlib/v/gen/js/js.v @@ -1,15 +1,13 @@ module js -import ( - strings - v.ast - v.table - v.depgraph - v.token - v.pref - term - v.util -) +import strings +import v.ast +import v.table +import v.depgraph +import v.token +import v.pref +import term +import v.util const ( //TODO @@ -98,7 +96,9 @@ pub fn (g mut JsGen) enter_namespace(n string) { g.out = strings.new_builder(100) g.indents[g.namespace] = 0 g.out.writeln('const $n = (function () {') - } else { + } + // + else { g.out = g.namespaces[g.namespace] } } diff --git a/vlib/v/parser/parser.v b/vlib/v/parser/parser.v index ec8d361b5f..e0584dd5e9 100644 --- a/vlib/v/parser/parser.v +++ b/vlib/v/parser/parser.v @@ -963,6 +963,7 @@ fn (mut p Parser) import_stmt() []ast.Import { p.check(.key_import) mut imports := []ast.Import if p.tok.kind == .lpar { + p.warn('`import()` has been deprecated, use `import x` instead. run `v fmt` to handle the transition') p.check(.lpar) for p.tok.kind != .rpar { imports << p.parse_import() diff --git a/vlib/v/scanner/scanner.v b/vlib/v/scanner/scanner.v index e83c231250..3604da620a 100644 --- a/vlib/v/scanner/scanner.v +++ b/vlib/v/scanner/scanner.v @@ -3,19 +3,18 @@ // that can be found in the LICENSE file. module scanner -import ( - os - v.token - v.pref - v.util -) +import os +import v.token +import v.pref +import v.util const ( single_quote = `\'` double_quote = `"` //is_fmt = os.getenv('VEXE').contains('vfmt') is_fmt = os.executable().contains('vfmt') - num_sep = `_` // char used as number separator +// char used as number separator + num_sep = `_` ) pub struct Scanner { @@ -255,20 +254,21 @@ fn (s mut Scanner) ident_dec_number() string { s.pos++ } } - // 5.. (a range) else if s.text[s.pos] == `.` { + // 5.. (a range) is_range = true s.pos-- } + else if s.text[s.pos] in [`e`, `E`] { // 5.e5 - else if s.text[s.pos] in [`e`, `E`] { } - // 5.str() + } else if s.text[s.pos].is_letter() { + // 5.str() call_method = true s.pos-- } - // 5. else if s.text[s.pos] != `)` { + // 5. is_float_without_fraction = true s.pos-- } @@ -300,16 +300,16 @@ fn (s mut Scanner) ident_dec_number() string { s.pos++ } } - // error check: wrong digit if has_wrong_digit { + // error check: wrong digit s.error('this number has unsuitable digit `${first_wrong_digit.str()}`') } - // error check: 5e else if s.text[s.pos - 1] in [`e`, `E`] { + // error check: 5e s.error('exponent has no digits') } - // error check: 1.23.4, 123.e+3.4 else if s.pos < s.text.len && s.text[s.pos] == `.` && !is_range && !is_float_without_fraction && !call_method { + // error check: 1.23.4, 123.e+3.4 if has_exp { s.error('exponential part should be integer') } @@ -425,8 +425,8 @@ pub fn (s mut Scanner) scan() token.Token { } return s.new_token(.name, name, name.len) } - // `123`, `.123` else if c.is_digit() || (c == `.` && nextc.is_digit()) { + // `123`, `.123` if !s.is_inside_string { // In C ints with `0` prefix are octal (in V they're decimal), so discarding heading zeros is needed. mut start_pos := s.pos @@ -669,17 +669,15 @@ pub fn (s mut Scanner) scan() token.Token { } } 0xE2 { - // case `≠`: if nextc == 0x89 && s.text[s.pos + 2] == 0xA0 { + // case `≠`: s.pos += 2 return s.new_token(.ne, '', 3) } - // ⩽ else if nextc == 0x89 && s.text[s.pos + 2] == 0xBD { s.pos += 2 return s.new_token(.le, '', 3) } - // ⩾ else if nextc == 0xA9 && s.text[s.pos + 2] == 0xBE { s.pos += 2 return s.new_token(.ge, '', 3) diff --git a/vlib/v/util/util.v b/vlib/v/util/util.v index 012d3252d2..87c255d222 100644 --- a/vlib/v/util/util.v +++ b/vlib/v/util/util.v @@ -3,17 +3,16 @@ // that can be found in the LICENSE file. module util -import ( - os - v.pref -) +import os +import v.pref pub const ( v_version = '0.1.26' ) +// math.bits is needed by strconv.ftoa pub const ( - builtin_module_parts = ['math.bits' /* needed by strconv.ftoa */, 'strconv', 'strconv.ftoa', 'hash.wyhash', 'strings'] + builtin_module_parts = ['math.bits', 'strconv', 'strconv.ftoa', 'hash.wyhash', 'strings'] ) // vhash() returns the build string C.V_COMMIT_HASH . See cmd/tools/gen_vc.v . @@ -47,7 +46,7 @@ pub fn full_v_version() string { // NB: githash(true) must be called only when v detects that it builds itself. // For all other programs, githash(false) should be used. pub fn githash(should_get_from_filesystem bool) string { - for { + for { // The `for` construct here is used as a goto substitute. // The code in this function will break out of the `for` // if it detects an error and can not continue. @@ -113,7 +112,9 @@ pub fn launch_tool(is_verbose bool, tool_name string) { mut should_compile := false if !os.exists(tool_exe) { should_compile = true - } else { + } + // + else { if os.file_last_mod_unix(tool_exe) <= os.file_last_mod_unix(vexe) { // v was recompiled, maybe after v up ... // rebuild the tool too just in case @@ -203,24 +204,12 @@ fn imax(a, b int) int { fn replace_op(s string) string { last_char := s[s.len - 1] suffix := match last_char { - `+` { - '_plus' - } - `-` { - '_minus' - } - `*` { - '_mult' - } - `/` { - '_div' - } - `%` { - '_mod' - } - else { - '' - } + `+` { '_plus' } + `-` { '_minus' } + `*` { '_mult' } + `/` { '_div' } + `%` { '_mod' } + else { '' } } return s[..s.len - 1] + suffix }