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

Commit

Permalink
Merge branch 'master' into _update-deps/runtimeverification/k
Browse files Browse the repository at this point in the history
  • Loading branch information
tothtamas28 authored Apr 5, 2024
2 parents 8557e78 + 7ee5e70 commit 0130e9a
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 13 deletions.
34 changes: 24 additions & 10 deletions src/pyk/kast/outer_lexer.py
Original file line number Diff line number Diff line change
Expand Up @@ -113,8 +113,9 @@ class Token(NamedTuple):
_DIGIT: Final = set('0123456789')
_LOWER: Final = set('abcdefghijklmnopqrstuvwxyz')
_UPPER: Final = set('ABCDEFGHIJKLMNOPQRSTUVWXYZ')
_ALPHA: Final = set().union(_LOWER).union(_UPPER)
_ALNUM: Final = set(_ALPHA).union(_DIGIT)
_ALPHA: Final = _LOWER.union(_UPPER)
_ALNUM: Final = _ALPHA.union(_DIGIT)
_WORD: Final = {'_'}.union(_ALNUM)


class State(Enum):
Expand Down Expand Up @@ -456,29 +457,42 @@ def _hash_upper_id(la: str, it: Iterator[str]) -> tuple[Token, str]:


_MODNAME_KEYWORDS: Final = {'private', 'public'}
_MODNAME_CHARS: Final = {'-', '_'}.union(_ALNUM)


def _modname(la: str, it: Iterator) -> tuple[Token, str]:
r"""[a-zA-Z]\w*(-\w+)*"""

la = _skip_ws_and_comments(la, it)

consumed = []

if la == '#':
if la not in _ALPHA:
raise _unexpected_character(la)

consumed.append(la)
la = next(it, '')

while la in _WORD:
consumed.append(la)
la = next(it, '')

if not la:
raise _unexpected_character(la)
while True:
if la != '-':
break

consumed.append(la)
la = next(it, '')

allow_dash = False
while la in _MODNAME_CHARS:
if la == '-' and not allow_dash:
if la not in _WORD:
raise _unexpected_character(la)
allow_dash = la != '-'

consumed.append(la)
la = next(it, '')

while la in _WORD:
consumed.append(la)
la = next(it, '')

text = ''.join(consumed)
if text in _MODNAME_KEYWORDS:
return _KEYWORDS[text], la
Expand Down
4 changes: 1 addition & 3 deletions src/tests/unit/kast/test_outer_lexer.py
Original file line number Diff line number Diff line change
Expand Up @@ -304,10 +304,8 @@ def test_default(text: str, expected_token: Token, expected_remaining: str) -> N
('private MODULE', Token('private', TokenType.KW_PRIVATE), ' MODULE'),
('public', Token('public', TokenType.KW_PUBLIC), ''),
('module', Token('module', TokenType.MODNAME), ''),
('module ', Token('module', TokenType.MODNAME), ' '),
('MODULE', Token('MODULE', TokenType.MODNAME), ''),
('#module', Token('#module', TokenType.MODNAME), ''),
('#module#module', Token('#module', TokenType.MODNAME), '#module'),
('module#module', Token('module', TokenType.MODNAME), '#module'),
('mo-du-le', Token('mo-du-le', TokenType.MODNAME), ''),
('m0-DU_l3', Token('m0-DU_l3', TokenType.MODNAME), ''),
('TEST-MODULE', Token('TEST-MODULE', TokenType.MODNAME), ''),
Expand Down

0 comments on commit 0130e9a

Please sign in to comment.