| Crates.io | spring_controller_parser |
| lib.rs | spring_controller_parser |
| version | 0.1.3 |
| created_at | 2025-11-10 15:20:01.245889+00 |
| updated_at | 2025-11-10 20:34:01.491242+00 |
| description | A Rust pest parser for Java Spring controllers |
| homepage | |
| repository | https://github.com/Relrige/spring_controller_parser |
| max_upload_size | |
| id | 1925694 |
| size | 31,972 |
A Rust crate that parses Java Spring
@Controllerand@RestControllerclasses and their request-mapping method using pest.
Project name: spring-controller-pest
The parser uses the pest parsing library to analyze Java Spring controller files by recognizing structural patterns and not full Java syntax. It identifies controller annotations (@Controller, @RestController), class declarations, and mapping annotations (@RequestMapping, @GetMapping, etc.), along with method signatures.
During parsing, pest matches these tokens using defined grammar rules, then the library builds an AST (It can be Controller, ControllerMethod structs) containing the class name, mappings, and method details.
@Controller, @RestController@RequestMapping("/api")@GetMapping, @PostMapping, etc.The extracted AST can be used to:
Generate documentation or OpenAPI specifications
Check endpoint coverage
Build mock API servers
WHITESPACE = _{ " " | "\t" | "\r" | "\n" }
controller_file = { SOI ~ controller_block* ~ EOI }
mapping_annotation = {
"@RequestMapping" ~ mapping_args? |
"@GetMapping" ~ mapping_args? |
"@PostMapping" ~ mapping_args? |
"@DeleteMapping" ~ mapping_args? |
"@PatchMapping" ~ mapping_args? |
"@PutMapping" ~ mapping_args?
}
mapping_args = { "(" ~ (!")" ~ ANY)* ~ ")" }
identifier = @{ (ASCII_ALPHANUMERIC | "_")+ }
class_decl = { "class" ~ identifier }
method = {
( "public" | "protected" | "private" ) ~
(!"(" ~ ANY)* ~
"(" ~ (!")" ~ ANY)* ~ ")" ~
WHITESPACE* ~
"{" ~ (!"}" ~ ANY)* ~ "}"
}
controller_annotation = { "@Controller" | "@RestController" }
controller_block = {
controller_annotation ~
(!class_decl ~ ANY)* ~
class_decl ~
(!"}" ~ method)* ~
"}"
}