From 046b4d524f483352dda0b45ca53d86d2a80f985c Mon Sep 17 00:00:00 2001 From: "Gregory S. Tucker" Date: Sun, 18 Oct 2026 18:11:20 +0000 Subject: [PATCH] Read a component CATEGORY given as a bare name visitCategory called ctx.Identifer(), so `CATEGORY samples` raised AttributeError; only the quoted form worked. --- src/mccode_antlr/comp/visitor.py | 2 +- tests/test_comp_category.py | 10 ++++++++++ 2 files changed, 11 insertions(+), 1 deletion(-) create mode 100644 tests/test_comp_category.py diff --git a/src/mccode_antlr/comp/visitor.py b/src/mccode_antlr/comp/visitor.py index 7a89577a..29f46bf8 100644 --- a/src/mccode_antlr/comp/visitor.py +++ b/src/mccode_antlr/comp/visitor.py @@ -77,7 +77,7 @@ def visitComponentDefineCopy(self, ctx: Parser.ComponentDefineCopyContext): def visitCategory(self, ctx: Parser.CategoryContext): # Return the provided identifier or string literal, minus quotes - self.state.category = str(ctx.StringLiteral())[1:-1] if ctx.Identifier() is None else str(ctx.Identifer()) + self.state.category = str(ctx.StringLiteral())[1:-1] if ctx.Identifier() is None else str(ctx.Identifier()) def visitComponent_define_parameters(self, ctx: Parser.Component_define_parametersContext): for parameter in self.visit(ctx.component_parameters()): diff --git a/tests/test_comp_category.py b/tests/test_comp_category.py new file mode 100644 index 00000000..0dff2d77 --- /dev/null +++ b/tests/test_comp_category.py @@ -0,0 +1,10 @@ +"""A component's CATEGORY may be a bare name or a quoted string.""" +import pytest + +from mccode_antlr.comp import Comp + + +@pytest.mark.parametrize('category', ['samples', '"samples"']) +def test_category_is_read_either_way(category): + source = f'DEFINE COMPONENT T\nSETTING PARAMETERS ()\nCATEGORY {category}\nEND\n' + assert Comp.from_source(None, None, source).category == 'samples'