Add ast-grep custom-language wiring for .hew#2147
Merged
Merged
Conversation
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/
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.
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
Wire ast-grep to parse
.hewvia the tree-sitter-hew grammar, so structural search and rewrite work in this repo.sgconfig.ymlregistershewas a custom language (relativelibraryPath,expandoChar: _); ast-grep auto-discovers it from anywhere in the tree.scripts/build-ast-grep-lang.shcompiles the grammar into.ast-grep/hew-lang.sofrom a siblingtree-sitter-hewcheckout (or$TREE_SITTER_HEW_DIR).The compiled library is platform-specific and git-ignored (existing
*.sorule); contributors run the build script once after cloning.Verification
scripts/build-ast-grep-lang.shbuilds the library, thenast-grep run --lang hew -p 'fn $NAME($$$) { $$$ }' std/matches across the standard library.git statusshows only these two files; the.sostays ignored.Notes
Item-level patterns (
fn,impl,supervisor, …) work directly. Expression-level patterns use ast-grep'scontext+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.