TextFSM.Template (TextFSM v0.1.2)

Copy Markdown View Source

Represents the structure of a TextFSM template.

A template consists of:

  • Value definitions: The columns to be extracted.
  • States: Named collections of rules defining how to process text and transition between states.
  • EOF behavior: How to handle the end of the input (record or not).

Summary

Functions

Retrieves a specific rule from a state by index.

Parses the given binary as template.

Returns the names of all values defined in the template.

Types

eof_state()

@type eof_state() :: :record | :no_record

state_name()

@type state_name() :: String.t()

t()

@type t() :: %TextFSM.Template{
  eof_state: eof_state(),
  states: [TextFSM.Template.State.t()],
  value_definitions: [TextFSM.Template.ValueDefinition.t()]
}

value_name()

@type value_name() :: String.t()

Functions

get_rule(template, state, idx)

@spec get_rule(t(), state_name(), non_neg_integer()) ::
  nil | TextFSM.Template.State.Rule.t()

Retrieves a specific rule from a state by index.

This is mostly used internally by the Engine to fetch the next rule to evaluate.

Parameters

  • template - The TextFSM.Template struct.
  • state - The name of the state (String).
  • idx - The 0-based index of the rule within that state.

Returns

  • TextFSM.Template.State.Rule.t() - The rule at the specified index.
  • nil - If the state or rule index does not exist.

template(binary, opts \\ [])

@spec template(binary(), keyword()) ::
  {:ok, [term()], rest, context, line, byte_offset}
  | {:error, reason, rest, context, line, byte_offset}
when line: {pos_integer(), byte_offset},
     byte_offset: non_neg_integer(),
     rest: binary(),
     reason: String.t(),
     context: map()

Parses the given binary as template.

Returns {:ok, [token], rest, context, position, byte_offset} or {:error, reason, rest, context, line, byte_offset} where position describes the location of the template (start position) as {line, offset_to_start_of_line}.

To column where the error occurred can be inferred from byte_offset - offset_to_start_of_line.

Options

  • :byte_offset - the byte offset for the whole binary, defaults to 0
  • :line - the line and the byte offset into that line, defaults to {1, byte_offset}
  • :context - the initial context value. It will be converted to a map

value_names(template)

@spec value_names(t()) :: [value_name()]

Returns the names of all values defined in the template.

Parameters

Returns

  • [String.t()] - A list of value name strings.