From 35a537e9a4a6e471a17cfc99b8776bdc3135fd88 Mon Sep 17 00:00:00 2001 From: Valentin Berlier Date: Thu, 14 Jul 2022 18:38:07 +0200 Subject: [PATCH] fix: minor tweaks --- bolt/module.py | 12 ++++++------ bolt/parse.py | 2 +- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/bolt/module.py b/bolt/module.py index d034fe0..14d2ea9 100644 --- a/bolt/module.py +++ b/bolt/module.py @@ -139,9 +139,7 @@ def current(self) -> CompiledModule: @property def current_path(self) -> str: """Return the path corresponding to the currently executing module.""" - if not self.stack: - raise ValueError("No module currently executing.") - if path := self.stack[-1].resource_location: + if path := self.current.resource_location: return path raise ValueError( "Currently executing module has no associated resource location." @@ -177,7 +175,7 @@ def __getitem__(self, current: Union[TextFileBase[Any], str]) -> CompiledModule: or module.ast is compilation_unit.ast ): return module - logger.debug('Code generation due to ast update for module "%s".', name) + logger.warning('Code generation due to ast update for module "%s".', name) elif not compilation_unit.ast: previous = self.database.current @@ -188,8 +186,10 @@ def __getitem__(self, current: Union[TextFileBase[Any], str]) -> CompiledModule: filename=compilation_unit.filename, resource_location=compilation_unit.resource_location, ) - except DiagnosticError: - raise UnusableCompilationUnit("Parsing failed.", compilation_unit) + except DiagnosticError as exc: + raise UnusableCompilationUnit( + "Parsing failed.", compilation_unit + ) from exc finally: self.database.current = previous return self[current] diff --git a/bolt/parse.py b/bolt/parse.py index e874bc4..c2896d3 100644 --- a/bolt/parse.py +++ b/bolt/parse.py @@ -1065,7 +1065,7 @@ def create_macro(cls, command: AstCommand) -> AstMacro: node = command while isinstance(subcommand := node.arguments[-1], AstCommand): if isinstance(literal := node.arguments[0], AstMacroLiteral): - if literal.value == "macro": + if literal.value in ["macro", "from"]: exc = InvalidSyntax(f'Forbidden literal "{literal.value}".') raise set_location(exc, literal) identifier_parts.append(literal.value)