From 979a54e2b8710c4b4e993298a852dd53297d7f8c Mon Sep 17 00:00:00 2001 From: Timmy Welch Date: Sat, 1 Jun 2024 00:00:09 -0700 Subject: [PATCH] Fix lexing a dot '.' as a symbol Fixes #652 --- comicapi/filenamelexer.py | 2 +- comicapi/filenameparser.py | 7 ++++++- testing/filenames.py | 32 ++++++++++++++++++++++++++++++++ 3 files changed, 39 insertions(+), 2 deletions(-) diff --git a/comicapi/filenamelexer.py b/comicapi/filenamelexer.py index d094e60..1726e15 100644 --- a/comicapi/filenamelexer.py +++ b/comicapi/filenamelexer.py @@ -414,7 +414,7 @@ def is_operator(character: str) -> bool: def is_symbol(character: str) -> bool: - return unicodedata.category(character)[0] in "PS" + return unicodedata.category(character)[0] in "PS" and character != "." def Lex(filename: str, allow_issue_start_with_letter: bool = False) -> Lexer: diff --git a/comicapi/filenameparser.py b/comicapi/filenameparser.py index 6d50b02..660bd98 100644 --- a/comicapi/filenameparser.py +++ b/comicapi/filenameparser.py @@ -891,7 +891,12 @@ def parse_series(p: Parser, i: filenamelexer.Item | None) -> ParserFunc: break prev_space = False - + if ( + current + and current[-1].typ == filenamelexer.ItemType.Dot + and p.peek().typ in (filenamelexer.ItemType.ArchiveType,) + ): + current.pop() p.series.append(current) return parse diff --git a/testing/filenames.py b/testing/filenames.py index 58612ea..29e1d51 100644 --- a/testing/filenames.py +++ b/testing/filenames.py @@ -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]]] = [ + ( + "Conceptions #1 Conceptions I.cbz", + "&", + { + "issue": "1", + "series": "Conceptions", + "title": "Conceptions I", + "volume": "", + "year": "", + "remainder": "", + "issue_count": "", + "alternate": "", + "archive": "cbz", + }, + (False, True), + ), + ( + "Series #1 Stop it!.cbz", + "&", + { + "issue": "1", + "series": "Series", + "title": "Stop it!", + "volume": "", + "year": "", + "remainder": "", + "issue_count": "", + "alternate": "", + "archive": "cbz", + }, + (False, True), + ), ( "Drystan & Esyllt #3", "&",