Skip to content
This repository has been archived by the owner on Apr 25, 2024. It is now read-only.

Commit

Permalink
_INIT_LOC -> INIT_LOC
Browse files Browse the repository at this point in the history
  • Loading branch information
gtrepta committed Apr 15, 2024
1 parent 0038e51 commit 0f53acf
Show file tree
Hide file tree
Showing 2 changed files with 74 additions and 74 deletions.
20 changes: 10 additions & 10 deletions src/pyk/kast/outer_lexer.py
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ def __add__(self, other: object) -> Loc:
return NotImplemented


_INIT_LOC: Final = Loc(1, 0)
INIT_LOC: Final = Loc(1, 0)


class Token(NamedTuple):
Expand All @@ -89,7 +89,7 @@ def let(self, *, text: str | None = None, type: TokenType | None = None, loc: Lo
return Token(text=text, type=type, loc=loc)


_EOF_TOKEN: Final = Token('', TokenType.EOF, _INIT_LOC)
_EOF_TOKEN: Final = Token('', TokenType.EOF, INIT_LOC)

_SIMPLE_CHARS: Final = {
',': TokenType.COMMA,
Expand Down Expand Up @@ -739,7 +739,7 @@ def _strip_bubble_attr(bubble: str) -> tuple[str, list[Token]]:
next(it) # skip "["
la = next(it, '')

tokens = [Token('[', TokenType.LBRACK, _INIT_LOC)]
tokens = [Token('[', TokenType.LBRACK, INIT_LOC)]
attr_tokens = _attr(la, it)
try:
while True:
Expand Down Expand Up @@ -769,37 +769,37 @@ def _attr(la: str, it: Iterator[str]) -> Generator[Token, None, str]:
la = _skip_ws_and_comments(la, it)

if la == '(': # TAG_STATE
yield Token('(', TokenType.LPAREN, _INIT_LOC)
yield Token('(', TokenType.LPAREN, INIT_LOC)
la = next(it, '')

if la == '"':
text, token_type, la = _string(la, it)
yield Token(text, token_type, _INIT_LOC)
yield Token(text, token_type, INIT_LOC)
else:
content, la = _attr_content(la, it)
if content:
# allows 'key()'
yield Token(content, TokenType.ATTR_CONTENT, _INIT_LOC)
yield Token(content, TokenType.ATTR_CONTENT, INIT_LOC)

if la != ')':
raise _unexpected_character(la)

yield Token(')', TokenType.RPAREN, _INIT_LOC)
yield Token(')', TokenType.RPAREN, INIT_LOC)

la = next(it, '')
la = _skip_ws_and_comments(la, it)

if la != ',':
break

yield Token(',', TokenType.COMMA, _INIT_LOC)
yield Token(',', TokenType.COMMA, INIT_LOC)
la = next(it, '')
la = _skip_ws_and_comments(la, it)

if la != ']':
raise _unexpected_character(la)

yield Token(']', TokenType.RBRACK, _INIT_LOC)
yield Token(']', TokenType.RBRACK, INIT_LOC)
la = next(it, '')

return la # noqa: B901
Expand Down Expand Up @@ -840,7 +840,7 @@ def _attr_key(la: str, it: Iterator[str]) -> tuple[Token, str]:
la = next(it, '')

attr_key = ''.join(consumed)
return Token(attr_key, TokenType.ATTR_KEY, _INIT_LOC), la
return Token(attr_key, TokenType.ATTR_KEY, INIT_LOC), la


_ATTR_CONTENT_FORBIDDEN: Final = {'', '\n', '\r', '"'}
Expand Down
128 changes: 64 additions & 64 deletions src/tests/unit/kast/test_outer_lexer.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
import pytest

from pyk.kast.outer_lexer import (
_INIT_LOC,
INIT_LOC,
Loc,
LocationIterator,
Token,
Expand Down Expand Up @@ -458,132 +458,132 @@ def test_klabel(text: str, expected_token: Token, expected_remaining: str) -> No


ATTR_TEST_DATA: Final = (
('a]', [Token('a', TokenType.ATTR_KEY, _INIT_LOC), Token(']', TokenType.RBRACK, _INIT_LOC)], ''),
(' a ] ', [Token('a', TokenType.ATTR_KEY, _INIT_LOC), Token(']', TokenType.RBRACK, _INIT_LOC)], ' '),
('a<b>]', [Token('a<b>', TokenType.ATTR_KEY, _INIT_LOC), Token(']', TokenType.RBRACK, _INIT_LOC)], ''),
('1a-B<-->]', [Token('1a-B<-->', TokenType.ATTR_KEY, _INIT_LOC), Token(']', TokenType.RBRACK, _INIT_LOC)], ''),
('a]', [Token('a', TokenType.ATTR_KEY, INIT_LOC), Token(']', TokenType.RBRACK, INIT_LOC)], ''),
(' a ] ', [Token('a', TokenType.ATTR_KEY, INIT_LOC), Token(']', TokenType.RBRACK, INIT_LOC)], ' '),
('a<b>]', [Token('a<b>', TokenType.ATTR_KEY, INIT_LOC), Token(']', TokenType.RBRACK, INIT_LOC)], ''),
('1a-B<-->]', [Token('1a-B<-->', TokenType.ATTR_KEY, INIT_LOC), Token(']', TokenType.RBRACK, INIT_LOC)], ''),
(
'a()] ',
[
Token('a', TokenType.ATTR_KEY, _INIT_LOC),
Token('(', TokenType.LPAREN, _INIT_LOC),
Token(')', TokenType.RPAREN, _INIT_LOC),
Token(']', TokenType.RBRACK, _INIT_LOC),
Token('a', TokenType.ATTR_KEY, INIT_LOC),
Token('(', TokenType.LPAREN, INIT_LOC),
Token(')', TokenType.RPAREN, INIT_LOC),
Token(']', TokenType.RBRACK, INIT_LOC),
],
' ',
),
(
'a("")]',
[
Token('a', TokenType.ATTR_KEY, _INIT_LOC),
Token('(', TokenType.LPAREN, _INIT_LOC),
Token('""', TokenType.STRING, _INIT_LOC),
Token(')', TokenType.RPAREN, _INIT_LOC),
Token(']', TokenType.RBRACK, _INIT_LOC),
Token('a', TokenType.ATTR_KEY, INIT_LOC),
Token('(', TokenType.LPAREN, INIT_LOC),
Token('""', TokenType.STRING, INIT_LOC),
Token(')', TokenType.RPAREN, INIT_LOC),
Token(']', TokenType.RBRACK, INIT_LOC),
],
'',
),
(
'a("hello")]',
[
Token('a', TokenType.ATTR_KEY, _INIT_LOC),
Token('(', TokenType.LPAREN, _INIT_LOC),
Token('"hello"', TokenType.STRING, _INIT_LOC),
Token(')', TokenType.RPAREN, _INIT_LOC),
Token(']', TokenType.RBRACK, _INIT_LOC),
Token('a', TokenType.ATTR_KEY, INIT_LOC),
Token('(', TokenType.LPAREN, INIT_LOC),
Token('"hello"', TokenType.STRING, INIT_LOC),
Token(')', TokenType.RPAREN, INIT_LOC),
Token(']', TokenType.RBRACK, INIT_LOC),
],
'',
),
(
'a( )] ',
[
Token('a', TokenType.ATTR_KEY, _INIT_LOC),
Token('(', TokenType.LPAREN, _INIT_LOC),
Token(' ', TokenType.ATTR_CONTENT, _INIT_LOC),
Token(')', TokenType.RPAREN, _INIT_LOC),
Token(']', TokenType.RBRACK, _INIT_LOC),
Token('a', TokenType.ATTR_KEY, INIT_LOC),
Token('(', TokenType.LPAREN, INIT_LOC),
Token(' ', TokenType.ATTR_CONTENT, INIT_LOC),
Token(')', TokenType.RPAREN, INIT_LOC),
Token(']', TokenType.RBRACK, INIT_LOC),
],
' ',
),
(
'a(())] ',
[
Token('a', TokenType.ATTR_KEY, _INIT_LOC),
Token('(', TokenType.LPAREN, _INIT_LOC),
Token('()', TokenType.ATTR_CONTENT, _INIT_LOC),
Token(')', TokenType.RPAREN, _INIT_LOC),
Token(']', TokenType.RBRACK, _INIT_LOC),
Token('a', TokenType.ATTR_KEY, INIT_LOC),
Token('(', TokenType.LPAREN, INIT_LOC),
Token('()', TokenType.ATTR_CONTENT, INIT_LOC),
Token(')', TokenType.RPAREN, INIT_LOC),
Token(']', TokenType.RBRACK, INIT_LOC),
],
' ',
),
(
'a(/*)] ',
[
Token('a', TokenType.ATTR_KEY, _INIT_LOC),
Token('(', TokenType.LPAREN, _INIT_LOC),
Token('/*', TokenType.ATTR_CONTENT, _INIT_LOC),
Token(')', TokenType.RPAREN, _INIT_LOC),
Token(']', TokenType.RBRACK, _INIT_LOC),
Token('a', TokenType.ATTR_KEY, INIT_LOC),
Token('(', TokenType.LPAREN, INIT_LOC),
Token('/*', TokenType.ATTR_CONTENT, INIT_LOC),
Token(')', TokenType.RPAREN, INIT_LOC),
Token(']', TokenType.RBRACK, INIT_LOC),
],
' ',
),
(
'a(()())] ',
[
Token('a', TokenType.ATTR_KEY, _INIT_LOC),
Token('(', TokenType.LPAREN, _INIT_LOC),
Token('()()', TokenType.ATTR_CONTENT, _INIT_LOC),
Token(')', TokenType.RPAREN, _INIT_LOC),
Token(']', TokenType.RBRACK, _INIT_LOC),
Token('a', TokenType.ATTR_KEY, INIT_LOC),
Token('(', TokenType.LPAREN, INIT_LOC),
Token('()()', TokenType.ATTR_CONTENT, INIT_LOC),
Token(')', TokenType.RPAREN, INIT_LOC),
Token(']', TokenType.RBRACK, INIT_LOC),
],
' ',
),
(
'a( tag content (()) () )]',
[
Token('a', TokenType.ATTR_KEY, _INIT_LOC),
Token('(', TokenType.LPAREN, _INIT_LOC),
Token(' tag content (()) () ', TokenType.ATTR_CONTENT, _INIT_LOC),
Token(')', TokenType.RPAREN, _INIT_LOC),
Token(']', TokenType.RBRACK, _INIT_LOC),
Token('a', TokenType.ATTR_KEY, INIT_LOC),
Token('(', TokenType.LPAREN, INIT_LOC),
Token(' tag content (()) () ', TokenType.ATTR_CONTENT, INIT_LOC),
Token(')', TokenType.RPAREN, INIT_LOC),
Token(']', TokenType.RBRACK, INIT_LOC),
],
'',
),
(
'a,b,c]',
[
Token('a', TokenType.ATTR_KEY, _INIT_LOC),
Token(',', TokenType.COMMA, _INIT_LOC),
Token('b', TokenType.ATTR_KEY, _INIT_LOC),
Token(',', TokenType.COMMA, _INIT_LOC),
Token('c', TokenType.ATTR_KEY, _INIT_LOC),
Token(']', TokenType.RBRACK, _INIT_LOC),
Token('a', TokenType.ATTR_KEY, INIT_LOC),
Token(',', TokenType.COMMA, INIT_LOC),
Token('b', TokenType.ATTR_KEY, INIT_LOC),
Token(',', TokenType.COMMA, INIT_LOC),
Token('c', TokenType.ATTR_KEY, INIT_LOC),
Token(']', TokenType.RBRACK, INIT_LOC),
],
'',
),
(
' /* 1 */ a /* 2 */ , b /* 3 */ ]',
[
Token('a', TokenType.ATTR_KEY, _INIT_LOC),
Token(',', TokenType.COMMA, _INIT_LOC),
Token('b', TokenType.ATTR_KEY, _INIT_LOC),
Token(']', TokenType.RBRACK, _INIT_LOC),
Token('a', TokenType.ATTR_KEY, INIT_LOC),
Token(',', TokenType.COMMA, INIT_LOC),
Token('b', TokenType.ATTR_KEY, INIT_LOC),
Token(']', TokenType.RBRACK, INIT_LOC),
],
'',
),
(
'a<A>("hello"), b(foo(bar(%), baz))]',
[
Token('a<A>', TokenType.ATTR_KEY, _INIT_LOC),
Token('(', TokenType.LPAREN, _INIT_LOC),
Token('"hello"', TokenType.STRING, _INIT_LOC),
Token(')', TokenType.RPAREN, _INIT_LOC),
Token(',', TokenType.COMMA, _INIT_LOC),
Token('b', TokenType.ATTR_KEY, _INIT_LOC),
Token('(', TokenType.LPAREN, _INIT_LOC),
Token('foo(bar(%), baz)', TokenType.ATTR_CONTENT, _INIT_LOC),
Token(')', TokenType.RPAREN, _INIT_LOC),
Token(']', TokenType.RBRACK, _INIT_LOC),
Token('a<A>', TokenType.ATTR_KEY, INIT_LOC),
Token('(', TokenType.LPAREN, INIT_LOC),
Token('"hello"', TokenType.STRING, INIT_LOC),
Token(')', TokenType.RPAREN, INIT_LOC),
Token(',', TokenType.COMMA, INIT_LOC),
Token('b', TokenType.ATTR_KEY, INIT_LOC),
Token('(', TokenType.LPAREN, INIT_LOC),
Token('foo(bar(%), baz)', TokenType.ATTR_CONTENT, INIT_LOC),
Token(')', TokenType.RPAREN, INIT_LOC),
Token(']', TokenType.RBRACK, INIT_LOC),
],
'',
),
Expand Down

0 comments on commit 0f53acf

Please sign in to comment.