SnmpKit.SnmpLib.MIB.Compiler (snmpkit v0.6.6)
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
- Lexical Analysis - Tokenize MIB source
- Parsing - Build Abstract Syntax Tree (AST)
- Semantic Analysis - Validate and resolve symbols
- Code Generation - Generate optimized runtime format
- 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
@type compile_result() :: {:ok, compiled_mib()} | {:error, [SnmpKit.SnmpLib.MIB.Error.t()]} | {:warning, compiled_mib(), [SnmpKit.SnmpLib.MIB.Error.t()]}
Functions
@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}]}
@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"}]}
@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", ...}}
@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", ...}}