Documentation Index
Fetch the complete documentation index at: https://mintlify.com/iFamishedX/mapres/llms.txt
Use this file to discover all available pages before exploring further.
MapResolver is the central engine in mapres. It coordinates every step needed to turn a template string containing placeholders into a fully-resolved output string. A single MapResolver instance holds your layers, syntax providers, pipeline stages, and cache configuration, giving you one composable object that you can share across an entire application or configure per use-case.
How resolution works
Each call tores() drives four internal steps in this exact order for every pass through the text:
-
Pipeline — each stage function in
self.pipelinereceives(text, ctx, resolver)and returns a transformed string. Stages run first so they can pre-process or sanitize input before any pattern matching occurs. -
Syntax providers — each provider in
self.syntaxsupplies a regexpatternand aget_map(ctx, resolver)method. The resolver substitutes all matches of that pattern using the provider’s map. -
Layered maps — the
LayerStackis iterated in priority order. For every DataMap or plaindictfound across all layers, the resolver collects the unique set of syntax patterns in use, then substitutes all matching placeholders by looking up keys across layers in order (first layer that has the key wins). -
Context substitution — any remaining
{key}placeholders (always brace syntax) are resolved against the**ctxkeyword arguments passed tores().
_resolve_once():
Recursive resolution
After one pass, the resolved string may still contain placeholders — for example, a map value itself contained{another_key}. _recursive() keeps calling _resolve_once() until the text stops changing or max_depth passes are exhausted:
result == current) means that strings with no further placeholders converge immediately, so max_depth only matters for deeply nested templates.
The default
max_depth is 5. Increase it if your templates have more than five levels of nesting; decrease it to 1 if you want a strict single-pass guarantee.Constructor parameters
| Parameter | Type | Default | Description |
|---|---|---|---|
layers | list | None | None | A LayerStack or list of Layer objects that supply the maps. Defaults to an empty LayerStack. |
syntax | list | None | None | A list of syntax provider objects, each exposing a .pattern string and a .get_map(ctx, resolver) method. |
pipeline | list | None | None | An ordered list of callables (text, ctx, resolver) -> str that pre-process text before map substitution. |
cache | bool | False | Enable the internal LRU cache. Cached results are keyed on (text, sorted_ctx_items). |
cache_size | int | 1024 | Maximum number of entries the LRU cache holds before evicting the oldest. |
max_depth | int | 5 | Maximum number of recursive resolution passes before the result is returned as-is. |
The res() method
res() is the single public entry point for resolving a template string:
| Argument | Description |
|---|---|
text | The template string containing placeholders to resolve. |
extra_maps | A dict of maps appended as a new Layer with priority=999 — i.e. they act as low-priority fallbacks behind all existing layers. |
override_maps | A dict of maps used to build a completely fresh LayerStack containing only a single "override" layer at priority=0. The resolver’s own self.layers are ignored for this call. |
**ctx | Arbitrary keyword arguments available as context for the brace-syntax context substitution step and accessible inside pipeline/syntax-provider callbacks. |
extra_maps vs override_maps
The global res() function
For quick scripts and prototyping, mapres ships a module-level res() function backed by a default MapResolver() instance with no layers, no syntax providers, no pipeline, and no cache: