Skip to content

Commit

Permalink
add include statement
Browse files Browse the repository at this point in the history
  • Loading branch information
C.A.P. Linssen committed Nov 28, 2024
1 parent d041b62 commit 16e9913
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 8 deletions.
2 changes: 1 addition & 1 deletion pynestml/grammars/PyNestMLParser.g4
Original file line number Diff line number Diff line change
Expand Up @@ -205,7 +205,7 @@ parser grammar PyNestMLParser;

ifStmt : ifClause elifClause* (elseClause)?;

ifClause : IF_KEYWORD expression COLON
ifClause : IF_KEYWORD expression COLON
NEWLINE INDENT stmtsBody DEDENT;

elifClause : ELIF_KEYWORD expression COLON
Expand Down
8 changes: 4 additions & 4 deletions pynestml/visitors/ast_builder_visitor.py
Original file line number Diff line number Diff line change
Expand Up @@ -348,7 +348,7 @@ def visitSmallStmt(self, ctx):
function_call = self.visit(ctx.functionCall()) if ctx.functionCall() is not None else None
declaration = self.visit(ctx.declaration()) if ctx.declaration() is not None else None
return_stmt = self.visit(ctx.returnStmt()) if ctx.returnStmt() is not None else None
include_stmt = self.visit(ctx.includeStmt()) if ctx.includeStmt() is not None else None
include_stmt = None#self.visit(ctx.includeStmt()) if ctx.includeStmt() is not None else None
node = ASTNodeFactory.create_ast_small_stmt(assignment=assignment, function_call=function_call,
declaration=declaration, return_stmt=return_stmt,
include_stmt=include_stmt,
Expand Down Expand Up @@ -523,9 +523,9 @@ def visitModelBody(self, ctx):
"""
body_elements = list()
# visit all var_block children
if ctx.includeStmt_newline() is not None:
for child in ctx.includeStmt_newline():
body_elements.append(child)
# if ctx.includeStmt_newline() is not None:
# for child in ctx.includeStmt_newline():
# body_elements.append(child)
if ctx.onReceiveBlock() is not None:
for child in ctx.onReceiveBlock():
body_elements.append(child)
Expand Down
6 changes: 3 additions & 3 deletions pynestml/visitors/ast_include_statement_visitor.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,14 +23,14 @@

import os

from pynestml.meta_model.ast_block import ASTBlock
from pynestml.meta_model.ast_block_with_variables import ASTBlockWithVariables
from pynestml.meta_model.ast_equations_block import ASTEquationsBlock
from pynestml.meta_model.ast_expression import ASTExpression
from pynestml.meta_model.ast_include_stmt import ASTIncludeStmt
from pynestml.meta_model.ast_model_body import ASTModelBody
from pynestml.meta_model.ast_small_stmt import ASTSmallStmt
from pynestml.meta_model.ast_stmt import ASTStmt
from pynestml.meta_model.ast_stmts_body import ASTStmtsBody
from pynestml.meta_model.ast_update_block import ASTUpdateBlock
from pynestml.symbols.boolean_type_symbol import BooleanTypeSymbol
from pynestml.symbols.error_type_symbol import ErrorTypeSymbol
Expand Down Expand Up @@ -82,7 +82,7 @@ def _handle_include_stmt(self, node: ASTIncludeStmt):
new_stmts = parsed_included_file
include_stmt = node.get_parent().get_parent()

if isinstance(include_stmt.get_parent(), ASTBlock):
if isinstance(include_stmt.get_parent(), ASTStmtsBody):
self._replace_statements(include_stmt, new_stmts)

elif isinstance(node.get_parent().get_parent(), ASTEquationsBlock):
Expand All @@ -93,7 +93,7 @@ def _handle_include_stmt(self, node: ASTIncludeStmt):
new_stmt = parsed_included_file
include_stmt = node.get_parent().get_parent()

if isinstance(include_stmt.get_parent(), ASTBlock):
if isinstance(include_stmt.get_parent(), ASTStmtsBody):
self._replace_statements(include_stmt, [new_stmt])

# elif isinstance(node.get_parent().get_parent(), ASTEquationsBlock):
Expand Down

0 comments on commit 16e9913

Please sign in to comment.