Fix parsing ' in filenames

Fixes #672
This commit is contained in:
Timmy Welch 2024-12-06 21:29:26 -08:00
parent 0fa329ca75
commit bf0a46055a
2 changed files with 39 additions and 7 deletions

View File

@ -213,8 +213,11 @@ def lex_filename(lex: Lexer) -> LexerFunc | None:
r = lex.peek()
if r.isdigit():
return lex_number
lex.accept_run(is_symbol)
lex.emit(ItemType.Symbol)
if is_symbol(r):
lex.accept_run(is_symbol)
lex.emit(ItemType.Symbol)
else:
return lex_text
elif r.isnumeric():
lex.backup()
return lex_number
@ -305,7 +308,7 @@ def lex_space(lex: Lexer) -> LexerFunc:
def lex_text(lex: Lexer) -> LexerFunc:
while True:
r = lex.get()
if is_alpha_numeric(r):
if is_alpha_numeric(r) or r in "'":
if r.isnumeric(): # E.g. v1
word = lex.input[lex.start : lex.pos]
if key.get(word.casefold(), None) == ItemType.InfoSpecifier:
@ -313,10 +316,7 @@ def lex_text(lex: Lexer) -> LexerFunc:
lex.emit(key[word.casefold()])
return lex_filename
else:
if r == "'" and lex.peek().casefold() == "s":
lex.get()
else:
lex.backup()
lex.backup()
word = lex.input[lex.start : lex.pos + 1]
if word.casefold() in key:

View File

@ -25,6 +25,38 @@ datadir = importlib.resources.files(__package__).joinpath("data")
cbz_path = datadir.joinpath("Cory Doctorow's Futuristic Tales of the Here and Now #001 - Anda's Game (2007).cbz")
names: list[tuple[str, str, dict[str, str | bool], tuple[bool, bool]]] = [
(
"De Psy #6 Bonjour l'angoisse!.cbz",
"'",
{
"issue": "6",
"series": "De Psy",
"title": "Bonjour l'angoisse!",
"volume": "",
"year": "",
"remainder": "",
"issue_count": "",
"alternate": "",
"archive": "cbz",
},
(False, True),
),
(
"Airfiles #4 The 'Big Show'.cbz",
"'",
{
"issue": "4",
"series": "Airfiles",
"title": "The 'Big Show'",
"volume": "",
"year": "",
"remainder": "",
"issue_count": "",
"alternate": "",
"archive": "cbz",
},
(False, True),
),
(
"Conceptions #1 Conceptions I.cbz",
"&",