diff --git a/pz_config/__pycache__/parsers.cpython-311.pyc b/pz_config/__pycache__/parsers.cpython-311.pyc index 3182419..92f31c2 100644 Binary files a/pz_config/__pycache__/parsers.cpython-311.pyc and b/pz_config/__pycache__/parsers.cpython-311.pyc differ diff --git a/pz_config/parsers.py b/pz_config/parsers.py index d80f95b..8ceb6e1 100644 --- a/pz_config/parsers.py +++ b/pz_config/parsers.py @@ -74,13 +74,29 @@ def _parse_choices(comment_text: str) -> dict[str, str] | None: return None choices: dict[str, str] = {} - for line in comment_text.splitlines(): - m = re.match(r"^\s*(\d+)\s*=\s*(.+?)\s*$", line) - if not m: - continue - choices[m.group(1)] = m.group(2) + token_re = re.compile(r"(\d+)\s*=\s*") - return choices or None + for line in comment_text.splitlines(): + s = line.lstrip() + matches = list(token_re.finditer(s)) + if not matches: + continue + if len(matches) == 1 and matches[0].start() != 0: + # Avoid false positives such as "... (0=无限制)" inside a sentence. + continue + + for i, m in enumerate(matches): + key = m.group(1) + start = m.end() + end = matches[i + 1].start() if i + 1 < len(matches) else len(s) + label = s[start:end].strip().strip(",;|/、").strip() + if not label: + continue + choices[key] = label + + # Single "0=Disabled" style hints are common in server.ini, but they are not real enums. + # Only treat it as an enum when there are at least 2 options. + return choices if len(choices) >= 2 else None def parse_server_ini(filepath: str) -> ParsedConfig: @@ -284,4 +300,3 @@ def parse_sandboxvars_lua(filepath: str, translations_json: str | None = None) - fixed_settings.append(s) return ParsedConfig(source="lua", filepath=str(path), lines=lines, settings=fixed_settings) -