Repository navigation
feat: parse command - #13
Merged
Merged
Conversation
The chain parse, link resolution and FRID walk move from check into parse_spec, which reads the linked files only when load_resources is set. check calls it with the flag on and behaves as before.
New CLI command, plain-parser parse <file.plain>, with the same options as check. It prints every module of the requires chain with its tree and each link target with its resolved path. Unlike check, it does not read the linked files. A relative --template-dir is now searched, and shown in errors, as an absolute path, as codeplain does.
The `resources` map of `parse` held the absolute path of each linked file, so the same project printed a different result on every machine and, on Windows, a path mixing `\` and `/`. The only information in that path is which lookup directory matched, so the value is now that directory relative to the entry module's directory, with `/` as separator, and the target appended as written. Joining the value onto the entry module's directory names the file the parser matched. Resolution itself is unchanged: `find_resource_dir` is the one search, `resolve_linked_resource` still returns the joined path for the link existence check, and `parse_spec` holds the output contract that the `parse` command serialises. When no relative path exists (another drive on Windows) the value is the absolute path, still with `/`.
NejcS
approved these changes
Oct 14, 2026
NejcS
left a comment
There was a problem hiding this comment.
Tested parse and check on a few projects
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.
Adds
plain-parser parse <file.plain>. It prints the parse result as one JSON document on stdout.parsetakes the same options ascheck:--template-dir DIRand--config-name NAME. Lookup directories are the.plainfile's own directory, then--template-dir, which falls back to thetemplate-dirkey ofconfig.yamlnext to the.plainfile or in the working directory, exactly ascheckdoes today. Where a project should declare its lookup directories is an open question and is not touched here.Why
parsecommand that prints the parsed and validated trees makes that possible without a per-parser harness.Main decisions
parseandcheckhave different jobs.parseprints the parse result as JSON, in a format that stays stable, or the first error.checkvalidates a spec: the module, itsrequireschain and its linked files. Today it isparseplus codeplain's rules for linked files.cli.parse_spec.checkis meant to grow into a diagnostic check that lists every error at once and runs further checks. Two commands let it grow without changing the output contract ofparse.parsenever reads linked files.checkkeeps codeplain's rule: no binary files, no large base64 blobs.requireschain, each with its tree. Deepest ancestor first, the entry last.cargo metadataandgo list -deps -jsonresolve a project for other tools and print the dependencies with the root.go list -depsalso lists each package after its dependencies, the order used here.resourcesmaps each link target, as written, to its path relative to the entry module's directory, with/as separator:notes.mdwhen found next to the module,../tpl/notes.mdwhen found in a template directory...is kept and symlinks are not resolved. Joining the value onto the entry module's directory gives exactly the path codeplain builds when it opens the file./.cli.parse_specholds the output contract andparseserialises it, so a library caller and a subprocess caller get the same values. Resolution is unchanged:loaders.find_resource_diris the one search, used by the link existence check and byparse.checkdoes today. The same argument applies to them, but their text is codeplain's and is compared as a whole, so changing it is part of the move to language-neutral error codes, not of this PR. Until then the corpus replaces those directories with a case-root placeholder.\and/. The relative value states the match and nothing else, so the same project prints the same result on every machine and a success golden needs no path normalisation...is kept: removing it as text can name a different file when a folder on the path is a symlink. Resolving symlinks would print a path that differs from codeplain's and depends on how the machine is set up.format_version,typeandmessageand exits 1.check.typeis the Python class name for now. Language-neutral error codes are a separate change.parseprints. Nobody parses stderr text.--template-dirnow appears as an absolute path in "link does not exist" errors, as in codeplain.Library
cli.parse_spec,loaders.find_resource_dir,loaders.relative_resource_path.Where to look
cli.parse_spec: the operation both commands share, and the output contract.loaders.find_resource_dir,loaders.relative_resource_path: the search and the value it prints.cli.parse: JSON output, encoding and exit codes.