SnmpKit.SnmpLib.MIB.Compiler (snmpkit v0.6.4)

Main MIB compiler that orchestrates the entire compilation process.

This module provides the main interface for compiling MIB files from source to executable format. It coordinates between the lexer, parser, semantic analyzer, and code generator to produce optimized compiled MIBs.

Compilation Process

  1. Lexical Analysis - Tokenize MIB source
  2. Parsing - Build Abstract Syntax Tree (AST)
  3. Semantic Analysis - Validate and resolve symbols
  4. Code Generation - Generate optimized runtime format
  5. Persistence - Save compiled MIB for loading

Usage

# Compile a single MIB file
{:ok, compiled} = SnmpKit.SnmpLib.MIB.Compiler.compile("MY-MIB.mib")

# Compile with options
{:ok, compiled} = SnmpKit.SnmpLib.MIB.Compiler.compile("MY-MIB.mib",
  output_dir: "/tmp/mibs",
  format: :binary,
  optimize: true
)

# Compile multiple MIBs
{:ok, results} = SnmpKit.SnmpLib.MIB.Compiler.compile_all([
  "SNMPv2-SMI.mib",
  "MY-MIB.mib"
])

Summary

Functions

Compile a MIB file from filesystem path.

Compile multiple MIB files in dependency order.

Compile a MIB from string content.

Load a previously compiled MIB.

Types

compile_opts()

@type compile_opts() :: [
  output_dir: Path.t(),
  format: :erlang | :binary | :json,
  optimize: boolean(),
  validate: boolean(),
  include_paths: [Path.t()],
  warnings_as_errors: boolean()
]

compile_result()

@type compile_result() ::
  {:ok, compiled_mib()}
  | {:error, [SnmpKit.SnmpLib.MIB.Error.t()]}
  | {:warning, compiled_mib(), [SnmpKit.SnmpLib.MIB.Error.t()]}

compiled_mib()

@type compiled_mib() :: %{
  name: binary(),
  version: binary(),
  format: atom(),
  path: Path.t(),
  metadata: map(),
  oid_tree: SnmpKit.SnmpLib.MIB.AST.oid_tree(),
  symbols: map(),
  dependencies: [binary()]
}

Functions

compile(mib_path, opts \\ [])

@spec compile(Path.t(), compile_opts()) :: compile_result()

Compile a MIB file from filesystem path.

Examples

iex> SnmpKit.SnmpLib.MIB.Compiler.compile("test/fixtures/TEST-MIB.mib")
{:ok, %{name: "TEST-MIB", ...}}

iex> SnmpKit.SnmpLib.MIB.Compiler.compile("missing.mib")
{:error, [%SnmpKit.SnmpLib.MIB.Error{type: :file_not_found}]}

compile_all(mib_files, opts \\ [])

@spec compile_all([Path.t()], compile_opts()) ::
  {:ok, [compiled_mib()]}
  | {:error, [{Path.t(), [SnmpKit.SnmpLib.MIB.Error.t()]}]}

Compile multiple MIB files in dependency order.

Examples

iex> SnmpKit.SnmpLib.MIB.Compiler.compile_all(["SNMPv2-SMI.mib", "MY-MIB.mib"])
{:ok, [%{name: "SNMPv2-SMI"}, %{name: "MY-MIB"}]}

compile_string(mib_content, opts \\ [])

@spec compile_string(binary(), compile_opts()) :: compile_result()

Compile a MIB from string content.

This delegates to the Parser module which implements the full compilation pipeline using YACC-based parsing.

Examples

iex> SnmpKit.SnmpLib.MIB.Compiler.compile_string(mib_content)
{:ok, %{name: "TEST-MIB", ...}}

load_compiled(compiled_path)

@spec load_compiled(Path.t()) :: {:ok, compiled_mib()} | {:error, term()}

Load a previously compiled MIB.

Examples

iex> SnmpKit.SnmpLib.MIB.Compiler.load_compiled("priv/mibs/TEST-MIB.mib")
{:ok, %{name: "TEST-MIB", ...}}