spring_controller_parser

Crates.iospring_controller_parser
lib.rsspring_controller_parser
version0.1.3
created_at2025-11-10 15:20:01.245889+00
updated_at2025-11-10 20:34:01.491242+00
descriptionA Rust pest parser for Java Spring controllers
homepage
repositoryhttps://github.com/Relrige/spring_controller_parser
max_upload_size
id1925694
size31,972
(Relrige)

documentation

README

spring-controller-pest

A Rust crate that parses Java Spring @Controller and @RestController classes and their request-mapping method using pest.


Overview

Project name: spring-controller-pest

Technical description

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.

What is parsed

  • Controller annotations: @Controller, @RestController
  • Class name
  • Class-level mapping: @RequestMapping("/api")
  • Method-level mappings: @GetMapping, @PostMapping, etc.
  • Method signatures

How parsing results are used

The extracted AST can be used to:

  • Generate documentation or OpenAPI specifications

  • Check endpoint coverage

  • Build mock API servers

Grammar

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)* ~
    "}"
}

Commit count: 0

cargo fmt