From 68228f9977daddef2bd2b4b61814db0fa41d7fb2 Mon Sep 17 00:00:00 2001 From: Alexander Medvednikov Date: Wed, 10 Jul 2019 09:02:04 +0200 Subject: [PATCH] parser: clean up submodule implementation a bit --- compiler/parser.v | 21 +++++++++++---------- 1 file changed, 11 insertions(+), 10 deletions(-) diff --git a/compiler/parser.v b/compiler/parser.v index 27537942aa..1b596ed8e0 100644 --- a/compiler/parser.v +++ b/compiler/parser.v @@ -71,6 +71,10 @@ const ( MainFn= &Fn{name:'main'} ) +const ( + MaxModuleDepth = 4 +) + fn (c mut V) new_parser(path string, run Pass) Parser { c.log('new_parser("$path")') c.cgen.run = run @@ -296,20 +300,17 @@ fn (p mut Parser) import_statement() { } 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 + p.next() + for p.tok == .dot { + p.check(.dot) + submodule := p.check_name() + pkg += '.' + submodule depth++ - if depth > max_module_depth { - panic('Sorry. Module depth of $max_module_depth exceeded: $pkg ($submodule is too deep).') + if depth > MaxModuleDepth { + p.error('module depth of $MaxModuleDepth exceeded: $pkg') } } - p.next() p.fgenln(' ' + pkg) // Make sure there are no duplicate imports if p.table.imports.contains(pkg) {