mirror of
https://github.com/vlang/v.git
synced 2023-08-10 21:13:21 +03:00
submodules
This commit is contained in:
parent
36908fa304
commit
8a2d25247f
@ -717,7 +717,7 @@ fn (v mut V) add_user_v_files() {
|
|||||||
// Parse lib imports
|
// Parse lib imports
|
||||||
if v.pref.build_mode == .default_mode {
|
if v.pref.build_mode == .default_mode {
|
||||||
for i := 0; i < v.table.imports.len; i++ {
|
for i := 0; i < v.table.imports.len; i++ {
|
||||||
pkg := v.table.imports[i]
|
pkg := v.module_path(v.table.imports[i])
|
||||||
vfiles := v.v_files_from_dir('$TmpPath/vlib/$pkg')
|
vfiles := v.v_files_from_dir('$TmpPath/vlib/$pkg')
|
||||||
// Add all imports referenced by these libs
|
// Add all imports referenced by these libs
|
||||||
for file in vfiles {
|
for file in vfiles {
|
||||||
@ -730,7 +730,7 @@ fn (v mut V) add_user_v_files() {
|
|||||||
// TODO this used to crash compiler?
|
// TODO this used to crash compiler?
|
||||||
// for pkg in v.table.imports {
|
// for pkg in v.table.imports {
|
||||||
for i := 0; i < v.table.imports.len; i++ {
|
for i := 0; i < v.table.imports.len; i++ {
|
||||||
pkg := v.table.imports[i]
|
pkg := v.module_path(v.table.imports[i])
|
||||||
idir := os.getwd()
|
idir := os.getwd()
|
||||||
mut import_path := '$idir/$pkg'
|
mut import_path := '$idir/$pkg'
|
||||||
if(!os.file_exists(import_path)) {
|
if(!os.file_exists(import_path)) {
|
||||||
@ -749,7 +749,8 @@ fn (v mut V) add_user_v_files() {
|
|||||||
println(v.table.imports)
|
println(v.table.imports)
|
||||||
}
|
}
|
||||||
// Only now add all combined lib files
|
// Only now add all combined lib files
|
||||||
for pkg in v.table.imports {
|
for _pkg in v.table.imports {
|
||||||
|
pkg := v.module_path(_pkg)
|
||||||
idir := os.getwd()
|
idir := os.getwd()
|
||||||
mut module_path := '$idir/$pkg'
|
mut module_path := '$idir/$pkg'
|
||||||
// If we are in default mode, we don't parse vlib .v files, but header .vh files in
|
// If we are in default mode, we don't parse vlib .v files, but header .vh files in
|
||||||
@ -790,6 +791,15 @@ fn get_arg(joined_args, arg, def string) string {
|
|||||||
return res
|
return res
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn (v &V) module_path(pkg string) string {
|
||||||
|
// submodule support
|
||||||
|
if pkg.contains('.') {
|
||||||
|
// return pkg.replace('.', path_sep)
|
||||||
|
return pkg.replace('.', '/')
|
||||||
|
}
|
||||||
|
return pkg
|
||||||
|
}
|
||||||
|
|
||||||
fn (v &V) log(s string) {
|
fn (v &V) log(s string) {
|
||||||
if !v.pref.is_verbose {
|
if !v.pref.is_verbose {
|
||||||
return
|
return
|
||||||
|
@ -289,7 +289,21 @@ fn (p mut Parser) import_statement() {
|
|||||||
if p.tok != NAME {
|
if p.tok != NAME {
|
||||||
p.error('bad import format')
|
p.error('bad import format')
|
||||||
}
|
}
|
||||||
pkg := p.lit.trim_space()
|
mut pkg := p.lit.trim_space()
|
||||||
|
// submodule support
|
||||||
|
// limit depth to 4 for now
|
||||||
|
max_module_depth := 4
|
||||||
|
mut depth := 1
|
||||||
|
for p.peek() == DOT {
|
||||||
|
p.next() // SKIP DOT
|
||||||
|
p.next() // SUBMODULE
|
||||||
|
submodule := p.lit.trim_space()
|
||||||
|
pkg = pkg + '.' + submodule
|
||||||
|
depth++
|
||||||
|
if depth > max_module_depth {
|
||||||
|
panic('Sorry. Module depth of $max_module_depth exceeded: $pkg ($submodule is too deep).')
|
||||||
|
}
|
||||||
|
}
|
||||||
p.next()
|
p.next()
|
||||||
p.fgenln(' ' + pkg)
|
p.fgenln(' ' + pkg)
|
||||||
// Make sure there are no duplicate imports
|
// Make sure there are no duplicate imports
|
||||||
|
5
compiler/tests/submodule_test.v
Normal file
5
compiler/tests/submodule_test.v
Normal file
@ -0,0 +1,5 @@
|
|||||||
|
import encoding.base64
|
||||||
|
|
||||||
|
pub fn test_submodules() {
|
||||||
|
assert base64.decode('c3VibW9kdWxlcyBhcmUgd29ya2luZyE=') == 'submodules are working!'
|
||||||
|
}
|
@ -1,4 +1,4 @@
|
|||||||
import base64
|
import encoding.base64
|
||||||
|
|
||||||
struct testpair {
|
struct testpair {
|
||||||
decoded string
|
decoded string
|
Loading…
Reference in New Issue
Block a user