mirror of
https://github.com/vlang/v.git
synced 2023-08-10 21:13:21 +03:00
parser: clean up submodule implementation a bit
This commit is contained in:
parent
87762d6cf3
commit
68228f9977
@ -71,6 +71,10 @@ const (
|
|||||||
MainFn= &Fn{name:'main'}
|
MainFn= &Fn{name:'main'}
|
||||||
)
|
)
|
||||||
|
|
||||||
|
const (
|
||||||
|
MaxModuleDepth = 4
|
||||||
|
)
|
||||||
|
|
||||||
fn (c mut V) new_parser(path string, run Pass) Parser {
|
fn (c mut V) new_parser(path string, run Pass) Parser {
|
||||||
c.log('new_parser("$path")')
|
c.log('new_parser("$path")')
|
||||||
c.cgen.run = run
|
c.cgen.run = run
|
||||||
@ -296,20 +300,17 @@ fn (p mut Parser) import_statement() {
|
|||||||
}
|
}
|
||||||
mut pkg := p.lit.trim_space()
|
mut pkg := p.lit.trim_space()
|
||||||
// submodule support
|
// submodule support
|
||||||
// limit depth to 4 for now
|
|
||||||
max_module_depth := 4
|
|
||||||
mut depth := 1
|
mut depth := 1
|
||||||
for p.peek() == .dot {
|
p.next()
|
||||||
p.next() // SKIP DOT
|
for p.tok == .dot {
|
||||||
p.next() // SUBMODULE
|
p.check(.dot)
|
||||||
submodule := p.lit.trim_space()
|
submodule := p.check_name()
|
||||||
pkg = pkg + '.' + submodule
|
pkg += '.' + submodule
|
||||||
depth++
|
depth++
|
||||||
if depth > max_module_depth {
|
if depth > MaxModuleDepth {
|
||||||
panic('Sorry. Module depth of $max_module_depth exceeded: $pkg ($submodule is too deep).')
|
p.error('module depth of $MaxModuleDepth exceeded: $pkg')
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
p.next()
|
|
||||||
p.fgenln(' ' + pkg)
|
p.fgenln(' ' + pkg)
|
||||||
// Make sure there are no duplicate imports
|
// Make sure there are no duplicate imports
|
||||||
if p.table.imports.contains(pkg) {
|
if p.table.imports.contains(pkg) {
|
||||||
|
Loading…
Reference in New Issue
Block a user