parser: deprecate import(); replace remaining import()s
parent
48f9cc1ed7
commit
a48080afec
|
@ -1,11 +1,8 @@
|
||||||
module help
|
module help
|
||||||
|
|
||||||
//TODO: move this file outside internal, and merge it with cmd/tools/modules/vhelp/vhelp.v .
|
// TODO: move this file outside internal, and merge it with cmd/tools/modules/vhelp/vhelp.v .
|
||||||
|
import os
|
||||||
import (
|
import v.pref
|
||||||
os
|
|
||||||
v.pref
|
|
||||||
)
|
|
||||||
|
|
||||||
const (
|
const (
|
||||||
unknown_topic = 'V Error: Unknown help topic provided. Use `v help` for usage information.'
|
unknown_topic = 'V Error: Unknown help topic provided. Use `v help` for usage information.'
|
||||||
|
|
|
@ -1,15 +1,13 @@
|
||||||
module js
|
module js
|
||||||
|
|
||||||
import (
|
import strings
|
||||||
strings
|
import v.ast
|
||||||
v.ast
|
import v.table
|
||||||
v.table
|
import v.depgraph
|
||||||
v.depgraph
|
import v.token
|
||||||
v.token
|
import v.pref
|
||||||
v.pref
|
import term
|
||||||
term
|
import v.util
|
||||||
v.util
|
|
||||||
)
|
|
||||||
|
|
||||||
const (
|
const (
|
||||||
//TODO
|
//TODO
|
||||||
|
@ -98,7 +96,9 @@ pub fn (g mut JsGen) enter_namespace(n string) {
|
||||||
g.out = strings.new_builder(100)
|
g.out = strings.new_builder(100)
|
||||||
g.indents[g.namespace] = 0
|
g.indents[g.namespace] = 0
|
||||||
g.out.writeln('const $n = (function () {')
|
g.out.writeln('const $n = (function () {')
|
||||||
} else {
|
}
|
||||||
|
//
|
||||||
|
else {
|
||||||
g.out = g.namespaces[g.namespace]
|
g.out = g.namespaces[g.namespace]
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -963,6 +963,7 @@ fn (mut p Parser) import_stmt() []ast.Import {
|
||||||
p.check(.key_import)
|
p.check(.key_import)
|
||||||
mut imports := []ast.Import
|
mut imports := []ast.Import
|
||||||
if p.tok.kind == .lpar {
|
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)
|
p.check(.lpar)
|
||||||
for p.tok.kind != .rpar {
|
for p.tok.kind != .rpar {
|
||||||
imports << p.parse_import()
|
imports << p.parse_import()
|
||||||
|
|
|
@ -3,19 +3,18 @@
|
||||||
// that can be found in the LICENSE file.
|
// that can be found in the LICENSE file.
|
||||||
module scanner
|
module scanner
|
||||||
|
|
||||||
import (
|
import os
|
||||||
os
|
import v.token
|
||||||
v.token
|
import v.pref
|
||||||
v.pref
|
import v.util
|
||||||
v.util
|
|
||||||
)
|
|
||||||
|
|
||||||
const (
|
const (
|
||||||
single_quote = `\'`
|
single_quote = `\'`
|
||||||
double_quote = `"`
|
double_quote = `"`
|
||||||
//is_fmt = os.getenv('VEXE').contains('vfmt')
|
//is_fmt = os.getenv('VEXE').contains('vfmt')
|
||||||
is_fmt = os.executable().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 {
|
pub struct Scanner {
|
||||||
|
@ -255,20 +254,21 @@ fn (s mut Scanner) ident_dec_number() string {
|
||||||
s.pos++
|
s.pos++
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// 5.. (a range)
|
|
||||||
else if s.text[s.pos] == `.` {
|
else if s.text[s.pos] == `.` {
|
||||||
|
// 5.. (a range)
|
||||||
is_range = true
|
is_range = true
|
||||||
s.pos--
|
s.pos--
|
||||||
}
|
}
|
||||||
|
else if s.text[s.pos] in [`e`, `E`] {
|
||||||
// 5.e5
|
// 5.e5
|
||||||
else if s.text[s.pos] in [`e`, `E`] { }
|
}
|
||||||
// 5.str()
|
|
||||||
else if s.text[s.pos].is_letter() {
|
else if s.text[s.pos].is_letter() {
|
||||||
|
// 5.str()
|
||||||
call_method = true
|
call_method = true
|
||||||
s.pos--
|
s.pos--
|
||||||
}
|
}
|
||||||
// 5.
|
|
||||||
else if s.text[s.pos] != `)` {
|
else if s.text[s.pos] != `)` {
|
||||||
|
// 5.
|
||||||
is_float_without_fraction = true
|
is_float_without_fraction = true
|
||||||
s.pos--
|
s.pos--
|
||||||
}
|
}
|
||||||
|
@ -300,16 +300,16 @@ fn (s mut Scanner) ident_dec_number() string {
|
||||||
s.pos++
|
s.pos++
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// error check: wrong digit
|
|
||||||
if has_wrong_digit {
|
if has_wrong_digit {
|
||||||
|
// error check: wrong digit
|
||||||
s.error('this number has unsuitable digit `${first_wrong_digit.str()}`')
|
s.error('this number has unsuitable digit `${first_wrong_digit.str()}`')
|
||||||
}
|
}
|
||||||
// error check: 5e
|
|
||||||
else if s.text[s.pos - 1] in [`e`, `E`] {
|
else if s.text[s.pos - 1] in [`e`, `E`] {
|
||||||
|
// error check: 5e
|
||||||
s.error('exponent has no digits')
|
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 {
|
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 {
|
if has_exp {
|
||||||
s.error('exponential part should be integer')
|
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)
|
return s.new_token(.name, name, name.len)
|
||||||
}
|
}
|
||||||
// `123`, `.123`
|
|
||||||
else if c.is_digit() || (c == `.` && nextc.is_digit()) {
|
else if c.is_digit() || (c == `.` && nextc.is_digit()) {
|
||||||
|
// `123`, `.123`
|
||||||
if !s.is_inside_string {
|
if !s.is_inside_string {
|
||||||
// In C ints with `0` prefix are octal (in V they're decimal), so discarding heading zeros is needed.
|
// In C ints with `0` prefix are octal (in V they're decimal), so discarding heading zeros is needed.
|
||||||
mut start_pos := s.pos
|
mut start_pos := s.pos
|
||||||
|
@ -669,17 +669,15 @@ pub fn (s mut Scanner) scan() token.Token {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
0xE2 {
|
0xE2 {
|
||||||
// case `≠`:
|
|
||||||
if nextc == 0x89 && s.text[s.pos + 2] == 0xA0 {
|
if nextc == 0x89 && s.text[s.pos + 2] == 0xA0 {
|
||||||
|
// case `≠`:
|
||||||
s.pos += 2
|
s.pos += 2
|
||||||
return s.new_token(.ne, '', 3)
|
return s.new_token(.ne, '', 3)
|
||||||
}
|
}
|
||||||
// ⩽
|
|
||||||
else if nextc == 0x89 && s.text[s.pos + 2] == 0xBD {
|
else if nextc == 0x89 && s.text[s.pos + 2] == 0xBD {
|
||||||
s.pos += 2
|
s.pos += 2
|
||||||
return s.new_token(.le, '', 3)
|
return s.new_token(.le, '', 3)
|
||||||
}
|
}
|
||||||
// ⩾
|
|
||||||
else if nextc == 0xA9 && s.text[s.pos + 2] == 0xBE {
|
else if nextc == 0xA9 && s.text[s.pos + 2] == 0xBE {
|
||||||
s.pos += 2
|
s.pos += 2
|
||||||
return s.new_token(.ge, '', 3)
|
return s.new_token(.ge, '', 3)
|
||||||
|
|
|
@ -3,17 +3,16 @@
|
||||||
// that can be found in the LICENSE file.
|
// that can be found in the LICENSE file.
|
||||||
module util
|
module util
|
||||||
|
|
||||||
import (
|
import os
|
||||||
os
|
import v.pref
|
||||||
v.pref
|
|
||||||
)
|
|
||||||
|
|
||||||
pub const (
|
pub const (
|
||||||
v_version = '0.1.26'
|
v_version = '0.1.26'
|
||||||
)
|
)
|
||||||
|
|
||||||
|
// math.bits is needed by strconv.ftoa
|
||||||
pub const (
|
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 .
|
// 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.
|
// NB: githash(true) must be called only when v detects that it builds itself.
|
||||||
// For all other programs, githash(false) should be used.
|
// For all other programs, githash(false) should be used.
|
||||||
pub fn githash(should_get_from_filesystem bool) string {
|
pub fn githash(should_get_from_filesystem bool) string {
|
||||||
for {
|
for {
|
||||||
// The `for` construct here is used as a goto substitute.
|
// The `for` construct here is used as a goto substitute.
|
||||||
// The code in this function will break out of the `for`
|
// The code in this function will break out of the `for`
|
||||||
// if it detects an error and can not continue.
|
// 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
|
mut should_compile := false
|
||||||
if !os.exists(tool_exe) {
|
if !os.exists(tool_exe) {
|
||||||
should_compile = true
|
should_compile = true
|
||||||
} else {
|
}
|
||||||
|
//
|
||||||
|
else {
|
||||||
if os.file_last_mod_unix(tool_exe) <= os.file_last_mod_unix(vexe) {
|
if os.file_last_mod_unix(tool_exe) <= os.file_last_mod_unix(vexe) {
|
||||||
// v was recompiled, maybe after v up ...
|
// v was recompiled, maybe after v up ...
|
||||||
// rebuild the tool too just in case
|
// rebuild the tool too just in case
|
||||||
|
@ -203,24 +204,12 @@ fn imax(a, b int) int {
|
||||||
fn replace_op(s string) string {
|
fn replace_op(s string) string {
|
||||||
last_char := s[s.len - 1]
|
last_char := s[s.len - 1]
|
||||||
suffix := match last_char {
|
suffix := match last_char {
|
||||||
`+` {
|
`+` { '_plus' }
|
||||||
'_plus'
|
`-` { '_minus' }
|
||||||
}
|
`*` { '_mult' }
|
||||||
`-` {
|
`/` { '_div' }
|
||||||
'_minus'
|
`%` { '_mod' }
|
||||||
}
|
else { '' }
|
||||||
`*` {
|
|
||||||
'_mult'
|
|
||||||
}
|
|
||||||
`/` {
|
|
||||||
'_div'
|
|
||||||
}
|
|
||||||
`%` {
|
|
||||||
'_mod'
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
''
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
return s[..s.len - 1] + suffix
|
return s[..s.len - 1] + suffix
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue