JustBash.Commands.Awk.Evaluator (JustBash v0.4.0)

View Source

Evaluator for AWK programs.

Executes parsed AWK programs against input content, managing state and producing output.

Summary

Functions

Evaluate an expression in the given state context.

Evaluate an expression and return both the value and potentially updated state. Most expressions don't modify state, but increment/decrement expressions do.

Execute an AWK program against the given content.

Parse a value as a number.

Types

state()

@type state() :: %{
  nr: non_neg_integer(),
  nf: non_neg_integer(),
  fs: String.t(),
  ofs: String.t(),
  ors: String.t(),
  fields: [String.t()],
  variables: %{required(String.t()) => String.t()},
  arrays: %{required(String.t()) => map()},
  output: String.t(),
  exit_code: non_neg_integer() | nil,
  deadline: JustBash.Limit.Deadline.t() | nil
}

Functions

evaluate_expression(arg1, state)

@spec evaluate_expression(JustBash.Commands.Awk.AST.expr(), state()) ::
  String.t() | number()

Evaluate an expression in the given state context.

evaluate_expression_with_state(expr, state)

Evaluate an expression and return both the value and potentially updated state. Most expressions don't modify state, but increment/decrement expressions do.

execute(program, opts)

@spec execute(JustBash.Commands.Awk.AST.program(), map()) ::
  {String.t(), non_neg_integer(), map(), JustBash.t() | nil}

Execute an AWK program against the given content.

Accepts opts with :files as a list of {filename, content} tuples for proper FNR/FILENAME multi-file support.

Returns {output, exit_code, file_outputs, bash}.

execute(content, program, opts)

parse_number(value)

@spec parse_number(any()) :: number()

Parse a value as a number.