From 74c5b90dd386885af190dca0a44e1fd35b08bd88 Mon Sep 17 00:00:00 2001 From: kapkekes Date: Sun, 20 Oct 2024 00:12:12 +0700 Subject: [PATCH] [cocas] Add check for empty section attributes --- cocas/assembler/ast_builder.py | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/cocas/assembler/ast_builder.py b/cocas/assembler/ast_builder.py index a90a2f0..498a735 100644 --- a/cocas/assembler/ast_builder.py +++ b/cocas/assembler/ast_builder.py @@ -96,11 +96,21 @@ def check_label_is_ext(label: LabelDeclarationNode): raise AssemblerException(AssemblerExceptionTag.ASM, label.location.file, label.location.line, "Only external labels are allowed at the top of a file") - def visitSection_attr(self, ctx: AsmParser.Section_attrContext) -> str: + def visitSection_attr(self, ctx: AsmParser.Section_attrContext | None) -> str | None: + if ctx is None: + return None + return ctx.WORD().getText() - def visitSection_attrs(self, ctx: AsmParser.Section_attrsContext) -> list[str]: - return [self.visitSection_attr(section_attr) for section_attr in ctx.section_attr()] + def visitSection_attrs(self, ctx: AsmParser.Section_attrsContext | None) -> list[str]: + if ctx is None: + return [] + + return [ + attribute + for sa in ctx.section_attr() + if (attribute := self.visitSection_attr(sa)) is not None + ] def visitAbsoluteSection(self, ctx: AsmParser.AbsoluteSectionContext) -> AbsoluteSectionNode: header = ctx.asect_header()