JsonRemedy.Layer2.StructuralRepair (json_remedy v0.1.3)
View SourceLayer 2: Structural Repair - Fixes missing, extra, and mismatched delimiters using a state machine.
This layer handles:
- Missing closing delimiters ({ [
- Extra closing delimiters } ]
- Mismatched delimiters (closing with wrong type)
- Complex nested structure issues
Uses a state machine approach to track parsing context and handle structural repairs.
Summary
Functions
Return a human-readable name for this layer.
Return the priority order for this layer. Layer 2 (Structural Repair) should run after Layer 1 (Content Cleaning).
Process input string and apply Layer 2 structural repairs using state machine.
Check if this layer can handle the given input. Layer 2 detects structural issues with delimiters.
Validate layer configuration and options. Layer 2 accepts options for controlling structural repair behavior.
Types
@type context_frame() :: %{type: delimiter_type(), position: non_neg_integer()}
@type delimiter_type() :: :brace | :bracket
@type layer_result() :: JsonRemedy.LayerBehaviour.layer_result()
@type parser_state() :: :root | :object | :array
@type repair_action() :: JsonRemedy.LayerBehaviour.repair_action()
@type repair_context() :: JsonRemedy.LayerBehaviour.repair_context()
@type state_map() :: %{ position: non_neg_integer(), current_state: parser_state(), context_stack: [context_frame()], repairs: [repair_action()], in_string: boolean(), escape_next: boolean(), result_chars: [String.t()], input: String.t() }
Functions
@spec name() :: String.t()
Return a human-readable name for this layer.
@spec priority() :: 2
Return the priority order for this layer. Layer 2 (Structural Repair) should run after Layer 1 (Content Cleaning).
@spec process(input :: String.t(), context :: repair_context()) :: layer_result()
Process input string and apply Layer 2 structural repairs using state machine.
Returns:
{:ok, processed_input, updated_context}
- Layer completed successfully{:continue, input, context}
- Layer doesn't apply, pass to next layer{:error, reason}
- Layer failed, stop pipeline
Check if this layer can handle the given input. Layer 2 detects structural issues with delimiters.
Validate layer configuration and options. Layer 2 accepts options for controlling structural repair behavior.