Skip to content

Commit

Permalink
Fix attribute parsing (#4530)
Browse files Browse the repository at this point in the history
Fixes `OuterParser` for attributes of the form `foo()`.
  • Loading branch information
tothtamas28 authored Jul 18, 2024
1 parent 2c95ae9 commit 788d1f3
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 4 deletions.
11 changes: 7 additions & 4 deletions pyk/src/pyk/kast/outer_parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -379,10 +379,13 @@ def _maybe_att(self) -> Att:
value: str
if self._la.type == TokenType.LPAREN:
self._consume()
if self._la.type is TokenType.ATTR_CONTENT:
value = self._consume()
else:
value = _dequote_string(self._match(TokenType.STRING))
match self._la.type:
case TokenType.ATTR_CONTENT:
value = self._consume()
case TokenType.STRING:
value = _dequote_string(self._consume())
case _:
value = ''
self._match(TokenType.RPAREN)
else:
value = ''
Expand Down
20 changes: 20 additions & 0 deletions pyk/src/tests/unit/kast/test_outer_parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,26 @@
'syntax Foo ::= "foo"',
SyntaxDefn(SortDecl('Foo'), (PriorityBlock((Production((Terminal('foo'),)),)),)),
),
(
'syntax Foo ::= "foo" [symbol]',
SyntaxDefn(SortDecl('Foo'), (PriorityBlock((Production((Terminal('foo'),), att=Att((('symbol', ''),))),)),)),
),
(
'syntax Foo ::= "foo" [symbol()]',
SyntaxDefn(SortDecl('Foo'), (PriorityBlock((Production((Terminal('foo'),), att=Att((('symbol', ''),))),)),)),
),
(
'syntax Foo ::= "foo" [symbol("")]',
SyntaxDefn(SortDecl('Foo'), (PriorityBlock((Production((Terminal('foo'),), att=Att((('symbol', ''),))),)),)),
),
(
'syntax Foo ::= "foo" [symbol(foo)]',
SyntaxDefn(SortDecl('Foo'), (PriorityBlock((Production((Terminal('foo'),), att=Att((('symbol', 'foo'),))),)),)),
),
(
'syntax Foo ::= "foo" [symbol("foo")]',
SyntaxDefn(SortDecl('Foo'), (PriorityBlock((Production((Terminal('foo'),), att=Att((('symbol', 'foo'),))),)),)),
),
(
'syntax Foo ::= Bar',
SyntaxDefn(SortDecl('Foo'), (PriorityBlock((Production((NonTerminal(Sort('Bar')),)),)),)),
Expand Down

0 comments on commit 788d1f3

Please sign in to comment.