glimr/routing/compiler
Route Compiler
Generates optimized dispatch code from parsed routes. Takes routes from the annotation parser and produces pattern matching code with middleware support.
Types
Result of compiling routes. 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,
uses_validator: Bool,
uses_req: Bool,
uses_ctx: Bool,
line_to_route: dict.Dict(Int, String),
)
}
Constructors
-
CompileResult( imports: List(String), routes_code: String, used_methods: List(String), uses_middleware: Bool, uses_validator: Bool, uses_req: Bool, uses_ctx: Bool, line_to_route: dict.Dict(Int, String), )
Values
pub fn compile_routes(
controller_results: List(
#(String, annotation_parser.ParseResult),
),
) -> Result(CompileResult, String)
Compiles a list of parsed routes into dispatch code. Takes controller module paths and their parse results, generating 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.