From 71605d3f0f62f2b1cc7f85003085938ffbd867f5 Mon Sep 17 00:00:00 2001 From: "C.A.P. Linssen" Date: Tue, 30 Apr 2024 12:42:57 +0200 Subject: [PATCH] fix special handling of NEST delay and weight variables in synapse --- pynestml/symbols/variable_symbol.py | 8 ++++++++ pynestml/utils/messages.py | 1 - pynestml/visitors/ast_builder_visitor.py | 14 ++++++++++++-- 3 files changed, 20 insertions(+), 3 deletions(-) diff --git a/pynestml/symbols/variable_symbol.py b/pynestml/symbols/variable_symbol.py index 46ceac239..66b4d0a6c 100644 --- a/pynestml/symbols/variable_symbol.py +++ b/pynestml/symbols/variable_symbol.py @@ -139,6 +139,14 @@ def get_decorators(self): """ return self.decorators + def get_namespace_decorators(self): + return self.namespace_decorators + + def get_namespace_decorator(self, namespace): + if namespace in self.namespace_decorators.keys(): + return self.namespace_decorators[namespace] + return '' + def has_vector_parameter(self): """ Returns whether this variable symbol has a vector parameter. diff --git a/pynestml/utils/messages.py b/pynestml/utils/messages.py index b411bc266..f39d9ecdb 100644 --- a/pynestml/utils/messages.py +++ b/pynestml/utils/messages.py @@ -113,7 +113,6 @@ class MessageCode(Enum): PRIORITY_DEFINED_FOR_ONLY_ONE_EVENT_HANDLER = 82 REPEATED_PRIORITY_VALUE = 83 DELAY_VARIABLE = 84 - NEST_DELAY_DECORATOR_NOT_FOUND = 85 INPUT_PORT_SIZE_NOT_INTEGER = 86 INPUT_PORT_SIZE_NOT_GREATER_THAN_ZERO = 87 INSTALL_PATH_INFO = 88 diff --git a/pynestml/visitors/ast_builder_visitor.py b/pynestml/visitors/ast_builder_visitor.py index 76a48df16..0e766d530 100644 --- a/pynestml/visitors/ast_builder_visitor.py +++ b/pynestml/visitors/ast_builder_visitor.py @@ -492,14 +492,24 @@ def visitModel(self, ctx): return model + def visitNamespaceDecoratorNamespace(self, ctx): + return str(ctx.NAME()) + + def visitNamespaceDecoratorName(self, ctx): + return str(ctx.NAME()) + def visitAnyDecorator(self, ctx): from pynestml.generated.PyNestMLLexer import PyNestMLLexer if ctx.getToken(PyNestMLLexer.DECORATOR_HETEROGENEOUS, 0) is not None: return PyNestMLLexer.DECORATOR_HETEROGENEOUS elif ctx.getToken(PyNestMLLexer.DECORATOR_HOMOGENEOUS, 0) is not None: return PyNestMLLexer.DECORATOR_HOMOGENEOUS - - return None + elif ctx.getToken(PyNestMLLexer.AT, 0) is not None: + namespaceDecoratorNamespace = self.visit(ctx.namespaceDecoratorNamespace()) if ctx.namespaceDecoratorNamespace() is not None else None + namespaceDecoratorName = self.visit(ctx.namespaceDecoratorName()) if ctx.namespaceDecoratorName() is not None else None + return ASTNodeFactory.create_ast_namespace_decorator(namespaceDecoratorNamespace, namespaceDecoratorName, source_position=create_source_pos(ctx)) + else: + return None # Visit a parse tree produced by PyNESTMLParser#modelBody. def visitModelBody(self, ctx):