SnmpKit.MIB.SnmpTokenizer (snmpkit v2.0.1)
True 1:1 Elixir port of Erlang SNMP tokenizer (snmpc_tok.erl).
This is a direct translation of the official Erlang SNMP tokenizer from OTP lib/snmp/src/compile/snmpc_tok.erl
Original copyright: Ericsson AB 1996-2025 (Apache License 2.0)
Summary
Types
A token is {category, line} for reserved words and punctuation, or
{category, line, value} for :integer, :string, :variable,
:atom and :quote. Identifier values (:variable, :atom) are
binaries, never runtime-created atoms, so an untrusted MIB cannot grow
the atom table. :quote carries the quoted characters as a reversed
charlist, matching the OTP snmpc_tok convention the grammar expects.
A lexical warning: {line, message}. Modelled on libsmi's lexer diagnostics.
Functions
Returns a specification to start this module under a supervisor.
Format error message. Equivalent to snmpc_tok:format_error/1
Get all remaining tokens. Equivalent to snmpc_tok:get_all_tokens/1
Get next token from tokenizer. Equivalent to snmpc_tok:get_token/1
Null get_line function. Equivalent to snmpc_tok:null_get_line/0
Tokenize MIB text and return lexical warnings alongside the tokens.
Start tokenizer gen_server. Equivalent to snmpc_tok:start_link/2
Stop tokenizer. Equivalent to snmpc_tok:stop/1
Test function. Equivalent to snmpc_tok:test/0
Tokenize a string directly. Equivalent to snmpc_tok:tokenize/2
Types
@type state() :: %SnmpKit.MIB.SnmpTokenizer{ chars: charlist(), get_line_fun: function() | nil, line: pos_integer(), warnings: term() }
@type token() :: {atom(), pos_integer()} | {atom(), pos_integer(), any()}
A token is {category, line} for reserved words and punctuation, or
{category, line, value} for :integer, :string, :variable,
:atom and :quote. Identifier values (:variable, :atom) are
binaries, never runtime-created atoms, so an untrusted MIB cannot grow
the atom table. :quote carries the quoted characters as a reversed
charlist, matching the OTP snmpc_tok convention the grammar expects.
@type warning() :: {non_neg_integer(), String.t()}
A lexical warning: {line, message}. Modelled on libsmi's lexer diagnostics.
Functions
Returns a specification to start this module under a supervisor.
See Supervisor.
Format error message. Equivalent to snmpc_tok:format_error/1
Get all remaining tokens. Equivalent to snmpc_tok:get_all_tokens/1
Get next token from tokenizer. Equivalent to snmpc_tok:get_token/1
@spec null_get_line() :: :eof
Null get_line function. Equivalent to snmpc_tok:null_get_line/0
Tokenize MIB text and return lexical warnings alongside the tokens.
Accepts a binary or a charlist. A binary that is not valid UTF-8 is decoded as Latin-1 with a warning instead of failing, since vendor MIBs are often saved in legacy code pages. Warnings follow libsmi's lexer checks: underscores or trailing hyphens in identifiers, hex strings with an odd digit count, binary strings whose length is not a multiple of eight, and non-radix characters inside those literals.
Start tokenizer gen_server. Equivalent to snmpc_tok:start_link/2
@spec stop(pid()) :: :ok
Stop tokenizer. Equivalent to snmpc_tok:stop/1
Test function. Equivalent to snmpc_tok:test/0
Tokenize a string directly. Equivalent to snmpc_tok:tokenize/2