Add load_area and a JSON CLI; fix section skipping and record diagnostics - #19
Merged
Merged
Conversation
ParseError now carries reason, filename, 1-based line and column, and section fields alongside the unchanged formatted message. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01LsTyuYeZHogKAnGhufs9gN
load_area parses with an explicit dialect, or tries the detected dialect and then the ROM, Merc and SMAUG readers, returning the first parse with rooms. The CLI accepts --type, prints JSON to stdout, reports failures as one JSON line on stderr with exit status 1, and runs via python -m. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01LsTyuYeZHogKAnGhufs9gN
skip_section stopped at the first "#" anywhere in the body, truncating sections such as #SOCIALS and inventing bogus sections from the rest. It now skips to the next line that starts with "#" and an uppercase section name (or "#$"), keeping the whole body. Fixes #5 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01LsTyuYeZHogKAnGhufs9gN
Text readers still let a later record replace an earlier one with the same vnum, but now note each replacement as a duplicate_vnum diagnostic per family, and each skipped section as a skipped_section diagnostic. Every reader serializes the list under "diagnostics" in as_dict/as_json. Refs #2 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01LsTyuYeZHogKAnGhufs9gN
Delete SmaugAreaFile.load_room, which called a nonexistent read_room_data, and its read_line helper. jump_to_section now finds the header at a line start and raises ParseError when it is absent instead of moving to a meaningless offset. Merc and SWR resets share the model's arg2 suffix helper instead of byte-identical copies. Fixes #10 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01LsTyuYeZHogKAnGhufs9gN
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
cli.load_area(path, dialect=None)(fixes the red CI:test_medievia.pycalls it).dialectis aDIALECTSkey (rom,merc,smaug,circle,tba,medievia,godwars,swr,coffeemud), an area-file class, orNone. An explicit dialect is parsed as-is and its errors propagate. WithNone, the detected dialect runs first, then ROM, Merc and SMAUG (files only). The first parse with rooms wins. If no parse has rooms, the first parse that succeeded is returned. If nothing parses, the detected dialect's error is raised. If detection itself failed, itsValueErroris raised, chained from the fallback error that got furthest into the file.area-reader [--type auto|rom|merc|smaug|circle|tba|medievia|godwars|swr|coffeemud] <path>. On success it prints JSON to stdout and exits 0. On failure it prints one JSON line to stderr and exits 1:{"error", "file", "line", "column", "section"}.python -m area_reader.cliworks, and logging goes to stderr.ParseErrornow hasreason,filename, and 1-basedline/columnfields, plussectionfor the text readers. The formatted message is unchanged.#plus an uppercase name (or#$), so a#inside the body no longer cuts it short.{"kind": "duplicate_vnum", "family", "vnum"}. Each skipped section is recorded as{"kind": "skipped_section", "section"}. Every reader serializes the list as"diagnostics"inas_dict/as_json.skipped_sectionsstays as it was. Duplicate detection covers the text readers (ROM/Merc/SMAUG/SWR/GodWars); the Circle-family and CoffeeMud readers emit an empty list.SmaugAreaFile.load_room(it called a nonexistentread_room_data) and itsread_line.jump_to_sectionnow matches the header at a line start and raisesParseErrorwhen the section is missing. Merc and SWR sharemodel.native_reset_arg2_suffix. The Medievia suffix behaves differently, so it is kept.detect_area_typeis unchanged.Fixes #5
Fixes #10
Partially addresses #2 (records duplicates; does not change overwrite behaviour)
Verification
1077 passedload_areareturns the same parser as the sweep's fallback loop for every file (0 mismatches).🤖 Generated with Claude Code
https://claude.ai/code/session_01LsTyuYeZHogKAnGhufs9gN