Skip to content

Commit

Permalink
Only allow letters as first character in _modname (runtimeverificat…
Browse files Browse the repository at this point in the history
…ion/pyk#1067)

Related:
* #4158

---------

Co-authored-by: devops <[email protected]>
  • Loading branch information
2 people authored and Baltoli committed Apr 10, 2024
1 parent 5b5c66a commit de73a7f
Show file tree
Hide file tree
Showing 5 changed files with 29 additions and 17 deletions.
4 changes: 2 additions & 2 deletions pyk/docs/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@
project = 'pyk'
author = 'Runtime Verification, Inc'
copyright = '2024, Runtime Verification, Inc'
version = '0.1.774'
release = '0.1.774'
version = '0.1.775'
release = '0.1.775'

# -- General configuration ---------------------------------------------------
# https://www.sphinx-doc.org/en/master/usage/configuration.html#general-configuration
Expand Down
2 changes: 1 addition & 1 deletion pyk/package/version
Original file line number Diff line number Diff line change
@@ -1 +1 @@
0.1.774
0.1.775
2 changes: 1 addition & 1 deletion pyk/pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ build-backend = "poetry.core.masonry.api"

[tool.poetry]
name = "pyk"
version = "0.1.774"
version = "0.1.775"
description = ""
authors = [
"Runtime Verification, Inc. <[email protected]>",
Expand Down
34 changes: 24 additions & 10 deletions pyk/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 pyk/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 de73a7f

Please sign in to comment.