JsonRemedy.Layer2.StructuralRepair (json_remedy v0.1.3)

View Source

Layer 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

context_frame()

@type context_frame() :: %{type: delimiter_type(), position: non_neg_integer()}

delimiter_type()

@type delimiter_type() :: :brace | :bracket

layer_result()

@type layer_result() :: JsonRemedy.LayerBehaviour.layer_result()

parser_state()

@type parser_state() :: :root | :object | :array

repair_action()

@type repair_action() :: JsonRemedy.LayerBehaviour.repair_action()

repair_context()

@type repair_context() :: JsonRemedy.LayerBehaviour.repair_context()

state_map()

@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

name()

@spec name() :: String.t()

Return a human-readable name for this layer.

priority()

@spec priority() :: 2

Return the priority order for this layer. Layer 2 (Structural Repair) should run after Layer 1 (Content Cleaning).

process(input, context)

@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

supports?(input)

@spec supports?(input :: String.t()) :: boolean()

Check if this layer can handle the given input. Layer 2 detects structural issues with delimiters.

validate_options(options)

@spec validate_options(options :: keyword()) :: :ok | {:error, String.t()}

Validate layer configuration and options. Layer 2 accepts options for controlling structural repair behavior.