parser: deprecate import(); replace remaining import()s

pull/4602/head
Alexander Medvednikov 2020-04-26 07:35:59 +02:00
parent 48f9cc1ed7
commit a48080afec
5 changed files with 45 additions and 60 deletions

View File

@ -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
)
import os
import v.pref
const (
unknown_topic = 'V Error: Unknown help topic provided. Use `v help` for usage information.'

View File

@ -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]
}
}

View File

@ -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()

View File

@ -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)

View File

@ -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 .
@ -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
}