Skip to content

Commit 8524d74

Browse files
cursoragentscript3r
andcommitted
Checkpoint before follow-up message
Co-authored-by: script3r <[email protected]>
1 parent d713d0d commit 8524d74

File tree

7 files changed

+77
-4
lines changed

7 files changed

+77
-4
lines changed

Cargo.lock

Lines changed: 11 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,4 +38,3 @@ tree-sitter-go = "0.21"
3838
# tree-sitter-swift = "0.7"
3939
# tree-sitter-kotlin = "0.3"
4040
# Note: Additional languages disabled due to inconsistent tree-sitter APIs
41-

crates/cli/src/main.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,11 @@ fn main() -> Result<()> {
9292
&[Language::Go],
9393
patterns.clone(),
9494
).with_context(|| "Failed to create Go AST detector")?),
95+
Box::new(AstBasedDetector::with_patterns(
96+
"ast-detector-php",
97+
&[Language::Php],
98+
patterns.clone(),
99+
).with_context(|| "Failed to create PHP AST detector")?),
95100
];
96101

97102
let mut cfg = Config {

crates/scanner-core/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ tree-sitter-python = { workspace = true }
2424
tree-sitter-javascript = { workspace = true }
2525
tree-sitter-java = { workspace = true }
2626
tree-sitter-go = { workspace = true }
27-
# tree-sitter-php = { workspace = true }
27+
tree-sitter-php = { workspace = true }
2828
# tree-sitter-swift = { workspace = true }
2929
# tree-sitter-kotlin = { workspace = true }
3030

crates/scanner-core/src/ast.rs

Lines changed: 30 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,13 @@ impl AstDetector {
5555
parsers.insert(ScanLanguage::Python, Self::create_parser(tree_sitter_python::language())?);
5656
parsers.insert(ScanLanguage::Java, Self::create_parser(tree_sitter_java::language())?);
5757
parsers.insert(ScanLanguage::Go, Self::create_parser(tree_sitter_go::language())?);
58-
// Note: PHP, Swift, Kotlin, Objective-C and Erlang disabled due to inconsistent tree-sitter APIs
58+
59+
// Try to add PHP parser - check if it has the language() function
60+
if let Ok(php_parser) = Self::try_create_php_parser() {
61+
parsers.insert(ScanLanguage::Php, php_parser);
62+
}
63+
64+
// Note: Swift, Kotlin, Objective-C and Erlang disabled due to inconsistent tree-sitter APIs
5965

6066
Ok(Self {
6167
parsers,
@@ -70,6 +76,15 @@ impl AstDetector {
7076
Ok(parser)
7177
}
7278

79+
fn try_create_php_parser() -> Result<Parser> {
80+
let mut parser = Parser::new();
81+
// Try the standard language() function first
82+
let language = tree_sitter_php::language();
83+
parser.set_language(&language)
84+
.map_err(|e| anyhow!("Failed to set PHP parser language: {}", e))?;
85+
Ok(parser)
86+
}
87+
7388
/// Load AST patterns from patterns.toml or use defaults
7489
pub fn load_patterns_from_file(patterns_file: &str) -> Result<Vec<AstPattern>> {
7590
let patterns_content = std::fs::read_to_string(patterns_file)?;
@@ -298,6 +313,18 @@ impl AstDetector {
298313
metadata: HashMap::new(),
299314
},
300315

316+
// PHP OpenSSL function calls
317+
AstPattern {
318+
query: r#"
319+
(function_call_expression
320+
function: (name) @func
321+
(#match? @func "openssl_.*"))
322+
"#.to_string(),
323+
language: ScanLanguage::Php,
324+
match_type: AstMatchType::Library { name: "OpenSSL".to_string() },
325+
metadata: HashMap::new(),
326+
},
327+
301328
]
302329
}
303330

@@ -322,7 +349,8 @@ impl AstDetector {
322349
ScanLanguage::Python => tree_sitter_python::language(),
323350
ScanLanguage::Java => tree_sitter_java::language(),
324351
ScanLanguage::Go => tree_sitter_go::language(),
325-
_ => return Ok(matches), // Skip unsupported languages (PHP, Swift, Kotlin, ObjC, Erlang)
352+
ScanLanguage::Php => tree_sitter_php::language(),
353+
_ => return Ok(matches), // Skip unsupported languages (Swift, Kotlin, ObjC, Erlang)
326354
};
327355

328356
// Execute each pattern that matches this language

test_Cargo.toml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
[dependencies]
2+
tree-sitter = "0.22"
3+
tree-sitter-php = "0.22"

test_parsers.rs

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
#!/usr/bin/env cargo +nightly -Zscript
2+
3+
//! Test script to check tree-sitter parser APIs
4+
5+
use tree_sitter::Parser;
6+
7+
fn main() -> Result<(), Box<dyn std::error::Error>> {
8+
println!("Testing tree-sitter parser APIs...");
9+
10+
// Test PHP parser
11+
println!("PHP parser:");
12+
match create_php_parser() {
13+
Ok(_) => println!(" ✅ PHP parser works"),
14+
Err(e) => println!(" ❌ PHP parser failed: {}", e),
15+
}
16+
17+
Ok(())
18+
}
19+
20+
fn create_php_parser() -> Result<Parser, Box<dyn std::error::Error>> {
21+
let mut parser = Parser::new();
22+
23+
// Try different API patterns for PHP
24+
let language = tree_sitter_php::language();
25+
parser.set_language(&language)?;
26+
Ok(parser)
27+
}

0 commit comments

Comments
 (0)