Route Ruby through the structural matcher
ober
f8cf35a486b5a84092936b8ac1610c06cdc0811d
--- a/HANDOFF_OPUS_4_8.md +++ b/HANDOFF_OPUS_4_8.md @@ -7,7 +7,7 @@ Packaged Semgrep oracle: `/Users/user/.local/bin/semgrep` Branch: `java-structural-migration` (off `main`; carries java+scala+rust); Go and PHP migrations already merged. -## Summary: Go, PHP, Java, Scala, Rust all run on the real structural matcher +## Summary: Go, PHP, Java, Scala, Rust, Ruby all on the real structural matcher Five languages migrated off the regex generic-matcher approximation onto the real tree-sitter structural matcher; `generic-language?` (scan.ss ~809) no @@ -16,7 +16,7 @@ compiled into `jerboa-treesitter`: go/php/scala/rust (ABI 15), java (ABI 14, within the runtime's 13-15 window); scala/rust/php carry external scanners, go/java are parser-only. `make test` 321/321; smoke 15/15 (parse case per lang). Per-language normalize-oracle fixture results: java 42/42, scala 18/18, -rust 11/11, php 29/29, go 16/16. +rust 11/11, ruby 4/4, php 29/29, go 16/16. ### Java/Scala/Rust migration (branch `java-structural-migration`) @@ -124,8 +124,8 @@ The two remaining fixtures are blocked by the same gap that limits ~12 languages, so closing them is the tip of the larger work: 1. **AST matching for the "generic" languages (the big one).** - python/js/ts/go/php/java/scala/rust now use the tree-sitter structural - matcher. Ruby, C#, Swift, Dart, Kotlin, C, C++ remain `generic-language?` + python/js/ts/go/php/java/scala/rust/ruby now use the tree-sitter structural + matcher. C#, Swift, Dart, Kotlin, C, C++ remain `generic-language?` (scan.ss ~809) and use the regex-based `scan-generic-pattern`. That matcher approximates patterns with regexes and cannot express several Semgrep constructs. Real tree-sitter grammars for these languages would replace the --- a/lib/semgrep/match/structural.sls +++ b/lib/semgrep/match/structural.sls @@ -580,6 +580,9 @@ [(string=? language "rust") (or (string=? type "source_file") (string=? type "expression_statement"))] + [(string=? language "ruby") + (or (string=? type "program") + (string=? type "expression_statement"))] [else #f])) (def (normalized-pattern-root language root) (let loop ([current root] [owned '()]) --- a/lib/semgrep/parse/parse-target.sls +++ b/lib/semgrep/parse/parse-target.sls @@ -28,6 +28,7 @@ [(string=? canonical "java") 'java] [(string=? canonical "scala") 'scala] [(string=? canonical "rust") 'rust] + [(string=? canonical "ruby") 'ruby] [else (error 'parse-target-string "unsupported language in current MVP" --- a/lib/semgrep/scan.sls +++ b/lib/semgrep/scan.sls @@ -749,7 +749,6 @@ (string=? canonical "move_on_aptos") (string=? canonical "julia") (string=? canonical "kotlin") - (string=? canonical "ruby") (string=? canonical "cpp")))) (def (c-language? language) (let ([canonical (or (canonical-language language) --- a/src/.jerbuild-hashes +++ b/src/.jerbuild-hashes @@ -2,12 +2,12 @@ ("src/semgrep/result.ss" . "22D23E40B49BA529") ("src/semgrep/output/json.ss" . "293881CFA2ADB7BC") ("src/semgrep/lang.ss" . "6982E07679D20836") - ("src/semgrep/parse/parse-target.ss" . "3FE8E8985B2E3461") - ("src/semgrep/scan.ss" . "70E81C1629B569BB") - ("src/semgrep/fix.ss" . "2E5B65B1FEF3B2B1") + ("src/semgrep/parse/parse-target.ss" . "AD193DA8CA67B2B2") + ("src/semgrep/scan.ss" . "82F2DEBA214D9CFD") ("src/semgrep/output/text.ss" . "BE476CB84B807FBA") - ("src/semgrep/rule.ss" . "E12C108153C181FA") + ("src/semgrep/fix.ss" . "2E5B65B1FEF3B2B1") ("src/semgrep/schema/lang.ss" . "CAE2CA859C9A9FD0") - ("src/semgrep/match/structural.ss" . "331D07881B8C8C56") + ("src/semgrep/rule.ss" . "E12C108153C181FA") + ("src/semgrep/match/structural.ss" . "3CE2210D6FE588E4") ("src/semgrep/main.ss" . "A4EC9E7F2A09D25E") ("src/semgrep/cli.ss" . "EBDC4B1DAD3F13CC")) --- a/src/semgrep/match/structural.ss +++ b/src/semgrep/match/structural.ss @@ -604,6 +604,9 @@ [(string=? language "rust") (or (string=? type "source_file") (string=? type "expression_statement"))] + [(string=? language "ruby") + (or (string=? type "program") + (string=? type "expression_statement"))] [else #f])) (def (normalized-pattern-root language root) --- a/src/semgrep/parse/parse-target.ss +++ b/src/semgrep/parse/parse-target.ss @@ -20,6 +20,7 @@ [(string=? canonical "java") 'java] [(string=? canonical "scala") 'scala] [(string=? canonical "rust") 'rust] + [(string=? canonical "ruby") 'ruby] [else (error 'parse-target-string "unsupported language in current MVP" language)]))) --- a/src/semgrep/scan.ss +++ b/src/semgrep/scan.ss @@ -821,7 +821,6 @@ (string=? canonical "move_on_aptos") (string=? canonical "julia") (string=? canonical "kotlin") - (string=? canonical "ruby") (string=? canonical "cpp")))) (def (c-language? language)