glimr/routing/compiler

Route Compiler

Parses route definition files and generates optimized dispatch code. Handles route grouping, middleware, and path parameters.

Types

Result of compiling a route file. Contains the extracted imports, generated dispatch code, used HTTP methods, and line-to-route mapping for error reporting.

pub type CompileResult {
  CompileResult(
    imports: List(String),
    routes_code: String,
    used_methods: List(String),
    uses_middleware: Bool,
    line_to_route: dict.Dict(Int, String),
  )
}

Constructors

  • CompileResult(
      imports: List(String),
      routes_code: String,
      used_methods: List(String),
      uses_middleware: Bool,
      line_to_route: dict.Dict(Int, String),
    )

Represents a parsed route from a route definition file. ParsedRoute holds HTTP method routes with handlers and middleware. ParsedRedirect holds redirect configurations.

pub type ParsedRoute {
  ParsedRoute(
    method: String,
    path: String,
    handler: String,
    middleware: List(String),
  )
  ParsedRedirect(from: String, to: String, status: Int)
}

Constructors

  • ParsedRoute(
      method: String,
      path: String,
      handler: String,
      middleware: List(String),
    )
  • ParsedRedirect(from: String, to: String, status: Int)

Values

pub fn compile_file(
  source_path: String,
) -> Result(CompileResult, String)

Compiles a route definition file into dispatch code. Reads the source file, parses routes, and generates optimized pattern matching code.

pub fn write_compiled_file(
  compile_result: CompileResult,
  dest_path: String,
) -> Result(Nil, String)

Writes the compiled route file to disk. Assembles imports, dispatch code, and function wrapper, then validates with gleam check before formatting.

Search Document