Repository navigation
Description
Unify parsing: shared infrastructure, trees with spans, evaluation kept separate
The validator reads a dozen languages: CMake, Meson, Make, shell, Dockerfile, GitHub Actions expressions, GitLab CI, Cabal, tox, JSON/TOML/XML, and tool settings. Each reader was written on its own as the need arose, so each solves the same problems its own way. Some build a real syntax tree; others flatten the file, or evaluate while they parse. This issue is about giving parsing one consistent design, so readers reuse work, behave the same at their limits, report positions the same way, and are testable layer by layer.
Where things stand
| Reader | Produces | Structure |
|---|---|---|
Meson (meson/syntax.py) |
Literal, Name, Array, Dictionary, Call, Index, Operation, Assignment, If; evaluation is a separate pass |
full tree (tokens have lines; expression nodes mostly don't) |
CMake (cmake/syntax.py) |
Invocation(name, arguments, line) and Block branches; arguments keep their kind |
command-level tree; arguments stay strings |
Cabal (haskell/cabal.py) |
Section(kind, name, line, fields, sections) |
tree |
Make (make.py) |
Makefile(rules, variables, includes), built by regex line by line, applying +=/:= while reading; conditionals not represented |
semantic model; loses information |
Dockerfile (docker/dockerfile.py) |
flat Instruction(line, keyword, arguments) |
flat |
Shell (facts/shell.py) |
flat ShellCommand(argv, env, line); &&/||, pipelines, subshells, if/for headers and substitutions are split apart or dropped |
none, and every CI step goes through it |
GitHub Actions expressions, CMake if() conditions, generator expressions |
parsers that evaluate as they go, straight to a value or Condition |
none |
JSON/TOML/XML (text.check_json, ecosystems/data.py) |
well-formed or not, with an error position | none (by design) |
Duplication and inconsistency, measured
-
Five syntax-error types:
JsonSyntaxError,CMakeSyntaxError,MesonSyntaxError,CabalSyntaxError, andfacts.wellformed.ParseError. They carry different fields and are turned intoUnknown/unreadable facts in different ways. -
Separate tokenizers in CMake, Meson, GitHub expressions and JSON. Four line-continuation implementations (Make, shell, Dockerfile,
facts/tools.py), each with its own comment and escape handling. -
Nesting limits that disagree (
ci/gitlab.py,cmake/evaluation.py,ci/github_actions.py,javascript/analysis.py,ecosystems/data.py), each behaving differently at the limit. The mutation run shows none of them is tested at the boundary:Limit Value GitLab _DEPTH10 CMake MOST_NESTED24 GitHub reusable-workflow _CALL_DEPTH4 tsconfig extendshard-coded depth < 4data files _DEEP -
18 modules call
shlexdirectly (action inputs, Dart, Clojure aliases, scanners, audits, CMake and Meson re-joining, …). They bypassfacts/shell, so they handle quoting, substitutions and comments differently from every CIrun:step. -
At least seven places expand variable references, each with its own unknown handling: CMake
${}(cmake/values.py), Make$(), shell$VAR, tox{}, GitLab$VAR, GitHub${{ }},facts/expansion. -
At least five places follow includes, each with its own cycle and depth handling:
- CMake
include/add_subdirectory; - Meson
subdir; - Make
include; - GitLab
include/extends/!reference; - tsconfig
extends; - GitHub reusable workflows and composite actions.
- CMake
-
Positions:
Originis a path plus a structured place (jobs.test.steps[3].run), with no line or column. Readers know lines (CMake, Make, Dockerfile, Cabal) or nothing (shell, expressions). OnlyParseErrorhas a column. -
Shared already, and working well:
facts/conditions(theConditionalgebra used by CMake, Meson and generator expressions),facts/wellformed(Parser, size limits,decoded) andfacts/expansion(CommandExpander,Script). The design should grow from these.
Principles
- Parse to a tree; evaluate separately. The syntax layer is pure (text → tree with spans) and never consults facts. Evaluation (variables, conditions, includes) walks the tree. Each layer gets its own tests: golden trees for syntax, value tables for evaluation. Mutation survivors then point at one layer.
- One position model. A
Span(line, column, end_line, end_column)on every node, and an optional span onOrigin. Messages,--explainand parse errors all saypath:line:columnthe same way. - One error model. A single
SyntaxErrorbase (fromfacts.wellformed.ParseError) with a position and a reason, and one rule for turning it into anUnknownor unreadable fact. Recoverable errors (skip a statement, keep going) are distinguished from fatal ones. - A shared lexing kit. A regex-table tokenizer that yields tokens with spans, plus shared helpers for line continuations (with a configurable escape character), comments and quoted strings with escapes. It is iterative, never recursive, for untrusted input, as
check_jsonalready does. - One limits policy. A
Limitsvalue covers file size, nesting depth, include depth, expansion depth and call depth, with documented defaults. Reaching a limit always yields anUnknownthat names the limit, never a silent cut-off. One shared test helper builds a chain at the limit and one past it for every limited reader. - One include follower. It owns cycle detection, depth limiting, unreadable files and provenance (which file pulled in which). It is used by every reader that follows includes.
- One template/expansion engine. A
Templatenode (literal parts and references) with a per-language reference syntax. Values are known, conditional (viafacts/conditions) or unknown. One rule decides when an unexpanded reference makes a command opaque. - The shell reader is the hub. Every embedded command line (action inputs, tox commands, Make recipes, npm scripts, Leiningen aliases, Meson/CMake re-joins) goes through
facts/shell, nevershlex.splitdirectly. - Pluggable backends. Because readers produce trees behind an interface, a reader's syntax layer can later be swapped, for example for a tree-sitter grammar (Future option: tree-sitter grammars as an optional parsing backend #299), without touching evaluation.
Incremental plan
Each step preserves behaviour, keeps the corpus (python -m corpus) unchanged unless it fixes a known bug, and is done test first.
-
Span,Originpositions and a commonSyntaxErrorbase. Migrate the five error types. -
Limitsand the boundary test helper. Move the depth constants into it and test each limit at N and N+1. -
Route every
shlexcaller throughfacts/shell(18 modules). -
A shell syntax tree:
- nodes for commands, pipelines, lists (
&&/||/;), subshells,if/for/while/case, assignments, redirections, and command and arithmetic substitutions, each with a span; - derive today's
ShellCommandstream from it.
This also gives the enforcement facts Score a project's tooling, not just pass/warn/fail #295 needs (
|| true,set +e), and fixes the class of bugs behind A customshell:wrapper (msys2 {0},script -q -e -c "bash {0}") makes the whole step one argument of the wrapper program #194 and Anecho X=… >> $GITHUB_ENVinside a shellifbranch is taken as unconditional, and later steps withif: env.X != …are dropped silently #284. - nodes for commands, pipelines, lists (
-
A Makefile tree: assignments, rules, conditionals (
ifeq/ifdef/else/endif) andincludeas nodes, with expansion in an evaluation pass. Conditionals becomeConditions, as in CMake. -
Split GitHub Actions expressions and CMake
if()conditions into parse and evaluate. Both are small. -
The shared include follower and the
Templateengine. Migrate readers one at a time. -
Dockerfile instructions with parsed flags (
--from=,--mount=) and heredocs as nodes. -
Revisit Future option: tree-sitter grammars as an optional parsing backend #299 per reader, once the tree interface exists.
Related
- Score a project's tooling, not just pass/warn/fail #295 (scoring): needs spans for disabled diagnostics, the enforcement facts (
|| true,continue-on-error) and consistent unknowns. - Use pathspec for gitignore matching #298 (pathspec): the same "use the reference implementation" thinking for gitignore matching.
- Future option: tree-sitter grammars as an optional parsing backend #299 (tree-sitter): becomes a swappable syntax backend under principle 9.
- The full mutation run (Add a mutation testing check #60): the survivors cluster in readers that evaluate as they parse (Make, shell, GitHub expressions, CMake conditions) and at untested limits. This design addresses both.
Not in scope
- A single universal grammar or parser generator. Each language keeps a hand-written or reference parser suited to it.
- New required dependencies.
- Behaviour changes beyond known bugs. Each step is shown neutral by the corpus diff.
Acceptance
- Every reader except the well-formedness-only ones produces a tree with spans, and its evaluation is a separate, separately tested pass.
- One error type, one
Limitspolicy (each limit tested at the boundary), one include follower, one expansion engine, and no directshlexuse outsidefacts/shell. - Messages and
--explaingivepath:line:columnwherever the source position is known. - A mutation run shows the reader survivors reduced, and the corpus diff is empty apart from documented fixes.
🤖 Generated with Claude Code
Activity
One position type and one syntax-error base for every reader
One limits policy: every nesting limit in project_validator/limits.py
Split embedded command lines in one place: facts/shell
Report shell syntax errors without losing what can be read; never jud…
Parse CMake if() arguments to a tree, evaluate it separately
Parse shell scripts to a syntax tree; derive the commands from it
Report shell syntax errors without losing what can be read; never jud…
A shell script nothing can be read from is unknown, not merely noted
Parse GitHub Actions expressions to a tree, evaluate it separately
Read Cabal sections written with braces
Read compound commands nested past a limit flat, never exhausting the…
Read a `for (` cut short without reading past the script's end
Parsing step 5: a makefile parses to a tree, evaluated separately
Report a YAML escape past the last character as invalid YAML, not a c…
Read nested conditions without their bodies once, not exponentially o…
Parsing step 7: one include follower, and makefiles follow theirs thr…
Parsing step 8: Dockerfile instructions with their flags, heredocs an…
Parsing step 7: GitLab, GitHub and tsconfig follow through the one fo…
Parsing step 7: one template engine for references to values
leftibot commentedon Nov 23, 2026
Done, apart from the two items held back (below). Each step landed test first, with the corpus diff checked.
Span, oneParseErrorbaseshlex)Conditionsif()and generator expressions parse to trees, evaluated separatelypath:line:column(Make, CMake, Meson, Cabal, shell scripts, CI YAML, YAML settings)Related fixes along the way: #350 (Cabal braces), #354 (a YAML escape past the last character).
By design, not unified:
meson.buildonce, from a directory tree that can't cycle.Not done:
jsonandtomllibkeep no positions.Follow-ups:
$(filter …)andMAKECMDGOALS.