diff --git a/src/mccode_antlr/comp/visitor.py b/src/mccode_antlr/comp/visitor.py index 7a89577..29f46bf 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 0000000..0dff2d7 --- /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'