pub struct GradleParser;Expand description
Parses Gradle build files (build.gradle, build.gradle.kts).
Extracts dependencies from Gradle build scripts using a custom token-based lexer and recursive descent parser. Supports both Groovy and Kotlin DSL syntax.
§Supported Patterns
- String notation:
implementation 'group:name:version' - Named parameters:
implementation group: 'x', name: 'y', version: 'z' - Map format:
implementation([group: 'x', name: 'y']) - Nested functions:
implementation(enforcedPlatform("...")) - Project references:
implementation(project(":module")) - String interpolation:
implementation("group:name:${version}")
§Implementation
Uses a custom token-based lexer (870 lines) instead of tree-sitter for:
- Lighter binary size (no external parser dependencies)
- Easier maintenance for DSL-specific quirks
- Better error messages for malformed input
§Example
use provenant::parsers::{GradleParser, PackageParser};
use std::path::Path;
let path = Path::new("testdata/gradle-golden/groovy1/build.gradle");
let package_data = GradleParser::extract_first_package(path);
assert!(!package_data.dependencies.is_empty());Trait Implementations§
Source§impl PackageParser for GradleParser
impl PackageParser for GradleParser
Source§const PACKAGE_TYPE: PackageType = PackageType::Maven
const PACKAGE_TYPE: PackageType = PackageType::Maven
Package URL type identifier for this parser (e.g., PackageType::Npm, PackageType::Pypi).
Source§fn is_match(path: &Path) -> bool
fn is_match(path: &Path) -> bool
Checks if the given file path matches this parser’s expected format. Read more
Source§fn extract_packages(path: &Path) -> Vec<PackageData>
fn extract_packages(path: &Path) -> Vec<PackageData>
Extracts all packages from the given file path. Read more
Source§fn extract_first_package(path: &Path) -> PackageData
fn extract_first_package(path: &Path) -> PackageData
Returns the first package from
extract_packages(),
or a default PackageData if the file contains no packages.Auto Trait Implementations§
impl Freeze for GradleParser
impl RefUnwindSafe for GradleParser
impl Send for GradleParser
impl Sync for GradleParser
impl Unpin for GradleParser
impl UnsafeUnpin for GradleParser
impl UnwindSafe for GradleParser
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
Converts
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
Converts
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more