Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/mccode_antlr/comp/visitor.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()):
Expand Down
10 changes: 10 additions & 0 deletions tests/test_comp_category.py
Original file line number Diff line number Diff line change
@@ -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'
Loading