1
0
mirror of https://github.com/vlang/v.git synced 2023-08-10 21:13:21 +03:00

module aliasing and sub modules for import () syntax

This commit is contained in:
joe-conigliaro 2019-07-24 07:12:55 +10:00 committed by Alexander Medvednikov
parent 527b9e13fa
commit b06cfd702d

View File

@ -306,21 +306,16 @@ fn (p mut Parser) imports() {
if p.tok == .lpar { if p.tok == .lpar {
p.check(.lpar) p.check(.lpar)
for p.tok != .rpar && p.tok != .eof { for p.tok != .rpar && p.tok != .eof {
pkg := p.lit.trim_space() p.register_import()
p.next()
// TODO: aliased for import() syntax
// p.import_table.register_alias(alias, pkg)
// p.import_table.register_import(pkg)
if p.table.imports.contains(pkg) {
continue
}
p.table.imports << pkg
p.table.register_package(pkg)
} }
p.check(.rpar) p.check(.rpar)
return return
} }
// `import foo` // `import foo`
p.register_import()
}
fn (p mut Parser) register_import() {
if p.tok != .name { if p.tok != .name {
p.error('bad import format') p.error('bad import format')
} }
@ -344,7 +339,6 @@ fn (p mut Parser) imports() {
p.check(.key_as) p.check(.key_as)
mod_alias = p.check_name() mod_alias = p.check_name()
} }
p.fgenln(' ' + pkg)
// add import to file scope import table // add import to file scope import table
p.import_table.register_alias(mod_alias, pkg) p.import_table.register_alias(mod_alias, pkg)
// Make sure there are no duplicate imports // Make sure there are no duplicate imports
@ -354,6 +348,8 @@ fn (p mut Parser) imports() {
p.log('adding import $pkg') p.log('adding import $pkg')
p.table.imports << pkg p.table.imports << pkg
p.table.register_package(pkg) p.table.register_package(pkg)
p.fgenln(' ' + pkg)
} }
fn (p mut Parser) const_decl() { fn (p mut Parser) const_decl() {