submodules

This commit is contained in:
joe-conigliaro 2019-07-07 09:22:47 +10:00 committed by Alexander Medvednikov
parent 36908fa304
commit 8a2d25247f
5 changed files with 34 additions and 5 deletions

View file

@ -289,7 +289,21 @@ fn (p mut Parser) import_statement() {
if p.tok != NAME {
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.fgenln(' ' + pkg)
// Make sure there are no duplicate imports