glimr/routing/annotation_parser

Annotation Parser

Parses route annotations from controller files. Extracts HTTP method routes, middleware, and redirects from doc comments preceding handler functions.

Types

Represents a function parameter with its name and type. This is used to track handler signature for flexible parameter ordering.

pub type FunctionParam {
  FunctionParam(name: String, param_type: String)
}

Constructors

  • FunctionParam(name: String, param_type: String)

Result of parsing a controller file. Contains group-level middleware that applies to all routes, the list of parsed routes, and import validation flags.

pub type ParseResult {
  ParseResult(
    group_middleware: List(String),
    routes: List(ParsedRoute),
    has_wisp_request_import: Bool,
    has_ctx_context_import: Bool,
    validator_data_imports: List(String),
  )
}

Constructors

  • ParseResult(
      group_middleware: List(String),
      routes: List(ParsedRoute),
      has_wisp_request_import: Bool,
      has_ctx_context_import: Bool,
      validator_data_imports: List(String),
    )

Represents a parsed route from controller annotations. Contains method, path, handler function name, middleware, optional validator, and optional redirect configuration.

pub type ParsedRoute {
  ParsedRoute(
    method: String,
    path: String,
    handler: String,
    middleware: List(String),
    validator: option.Option(String),
    params: List(FunctionParam),
  )
  ParsedRedirect(from: String, to: String, status: Int)
}

Constructors

  • ParsedRoute(
      method: String,
      path: String,
      handler: String,
      middleware: List(String),
      validator: option.Option(String),
      params: List(FunctionParam),
    )
  • ParsedRedirect(from: String, to: String, status: Int)

Values

pub fn module_from_path(path: String) -> Result(String, Nil)

File paths from glob need to be converted to module paths for generating import statements. The src/ prefix and .gleam extension aren’t part of the Gleam module path.

pub fn parse(content: String) -> ParseResult

Parses a controller file for route annotations. Extracts group middleware from file-level comments and routes from doc comments preceding handler functions.

Search Document