Skip to content

Add ast-grep custom-language wiring for .hew#2147

Merged
slepp merged 3 commits into
mainfrom
ast-grep-wiring
Jun 22, 2026
Merged

Add ast-grep custom-language wiring for .hew#2147
slepp merged 3 commits into
mainfrom
ast-grep-wiring

Conversation

@slepp

@slepp slepp commented Jun 22, 2026

Copy link
Copy Markdown
Contributor

Summary

Wire ast-grep to parse .hew via the tree-sitter-hew grammar, so structural search and rewrite work in this repo.

  • sgconfig.yml registers hew as a custom language (relative libraryPath, expandoChar: _); ast-grep auto-discovers it from anywhere in the tree.
  • scripts/build-ast-grep-lang.sh compiles the grammar into .ast-grep/hew-lang.so from a sibling tree-sitter-hew checkout (or $TREE_SITTER_HEW_DIR).

The compiled library is platform-specific and git-ignored (existing *.so rule); contributors run the build script once after cloning.

Verification

  • scripts/build-ast-grep-lang.sh builds the library, then ast-grep run --lang hew -p 'fn $NAME($$$) { $$$ }' std/ matches across the standard library.
  • git status shows only these two files; the .so stays ignored.

Notes

Item-level patterns (fn, impl, supervisor, …) work directly. Expression-level patterns use ast-grep's context + selector, since a bare top-level expression isn't valid Hew.

Out of scope

The grammar itself lives in the tree-sitter-hew repository; this only adds the ast-grep integration.

ast-grep does not parse .hew natively. Register Hew as a custom language so
structural search and rewrite work across the codebase:

- sgconfig.yml registers the `hew` language, backed by a compiled copy of the
  tree-sitter-hew grammar at .ast-grep/hew-lang.so (relative path; ast-grep
  auto-discovers the config from anywhere in the tree).
- scripts/build-ast-grep-lang.sh compiles that grammar into the git-ignored
  library; run it once after cloning, or after the grammar changes.

Example:
  ast-grep run --lang hew --pattern 'fn $NAME($$$) -> $RET { $$$ }' std/
@slepp slepp enabled auto-merge (squash) June 22, 2026 21:03
Structural lint rules run by `ast-grep scan` (wired via sgconfig.yml ruleDirs),
each validated against the current tree (see per-domain _REPORT.md):

- Rust fail-closed (error): `.ok()?` in the lowering pipeline and `Ty::Var`
  constructed after inference (CLAUDE.md §2/§3).
- Rust panic/NYI (warning): bare `unreachable!()`, `todo!`/`unimplemented!`,
  empty `.expect("")`.
- Rust concurrency/drop (advisory): poisoned-lock unwraps, and `mem::forget`/
  `Box::leak` escapes to audit for drop-safety (CLAUDE.md §1/§9).
- Hew (.hew): redundant constructs — `len() == 0` -> `is_empty()`, a boolean
  `match` -> `is_some()`, `== ""` -> `is_empty()`, no-op `clone` of a literal.

scripts/ast-grep-lint.sh runs the set and fails only on error-severity findings.
@slepp slepp merged commit fd5eefb into main Jun 22, 2026
11 checks passed
@slepp slepp deleted the ast-grep-wiring branch June 22, 2026 21:47
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant