tree-sitter-mib
A tree-sitter grammar for SNMP MIB modules: the ASN.1 subset defined by the Structure of Management Information.
| Covers | RFCs |
|---|---|
SMIv1 modules, OBJECT-TYPE, TRAP-TYPE |
1155, 1212, 1215 |
SMIv2 MODULE-IDENTITY, OBJECT-IDENTITY, OBJECT-TYPE, NOTIFICATION-TYPE |
2578 |
TEXTUAL-CONVENTION |
2579 |
OBJECT-GROUP, NOTIFICATION-GROUP, MODULE-COMPLIANCE, AGENT-CAPABILITIES |
2580 |
ASN.1 types (SEQUENCE, SEQUENCE OF, CHOICE, tagged [APPLICATION n] IMPLICIT), size/range constraints, MACRO definitions |
X.208 subset |
Real-world coverage
The parser was run against three collections of MIBs:
| Corpus | Files | Parsed without errors |
|---|---|---|
net-snmp standard MIBs (/usr/share/snmp/mibs) |
63 | 100% |
| VMware / IBM vendor MIBs | 13 | 100% |
| netdisco-mibs (≈200 vendors) | 4,849 | 99.77% |
The 11 netdisco files that do not parse are malformed. They are listed, with
the reason for each, in test/corpus-known-failures.txt.
CI re-parses the whole collection on every change and fails on any new failure.
Being forgiving
The grammar aims to give a useful tree for the MIBs people actually have,
rather than to validate them (use smilint
for that). Specifically, it accepts:
- clauses of a macro invocation in any order;
- missing or trailing commas in
IMPORTS, enumerations,SEQUENCEbodies and object lists; - object names with an upper-case initial (
TrafficShield4100 OBJECT IDENTIFIER ::= …), which appear as ordinaryidentifiernodes; - type names with a lower-case initial (
fooEntry ::= SEQUENCE …,SYNTAX SEQUENCE OF fooEntry); - enumeration labels that start with a digit (
10mbitHalfDuplex(2)); - identifiers as range bounds (
Unsigned32 (1..maxGroups)).
Known simplifications:
- A comment runs from
--to the end of the line. Strict ASN.1 also lets a second--close a comment mid-line, but MIBs routinely draw lines of dashes and almost nothing relies on the strict rule, so this grammar follows what net-snmp does in practice. - The body of a
MACRO ::= BEGIN … ENDdefinition (found only in the SMI base modules) is kept as a flatmacro_bodytoken stream. - A
DEFVAL { … }holding a BITS set or an OID becomes a singlebraced_valuenode, because{ a }can mean either.
Tree shape
ifIndex OBJECT-TYPE
SYNTAX InterfaceIndex
MAX-ACCESS read-only
STATUS current
DESCRIPTION "A unique value for each interface."
::= { ifEntry 1 }
(object_type
name: (identifier)
(syntax_clause type: (defined_type name: (type_reference)))
(access_clause value: (access))
(status_clause value: (status))
(description_clause value: (string))
value: (object_identifier_value (identifier) (number)))
Using it from Python
pip install "tree-sitter-mib[core]" # "core" pulls in the tree-sitter runtime
import tree_sitter_mib
from tree_sitter import Language, Parser, Query, QueryCursor
language = Language(tree_sitter_mib.language())
parser = Parser(language)
tree = parser.parse(open("IF-MIB.txt", "rb").read())
# Every object, notification, group, ... that is assigned an OID
tags = Query(language, tree_sitter_mib.TAGS_QUERY)
for node in QueryCursor(tags).captures(tree.root_node).get("name", []):
print(node.text.decode())
tree_sitter_mib.HIGHLIGHTS_QUERY holds the highlighting query.
Queries
queries/highlights.scm: syntax highlighting. Generic captures come first and specific ones later, because later patterns win in both the tree-sitter CLI and Neovim.queries/tags.scm: definitions (definition.module,definition.constantfor anything assigned an OID,definition.type,definition.macro) and references, for code navigation.queries/folds.scm: folding for macro invocations, imports and type bodies.
Development
The tree-sitter CLI is pinned to an exact version as tree-sitter-cli in
package.json, and CI and the release workflow install that same version. CI
fails if src/ differs from what it generates, so use the pinned CLI through
npx rather than a globally installed one:
npm install
npx tree-sitter generate # regenerate src/ after editing grammar.js
npx tree-sitter test # corpus, highlight and tag tests
npx tree-sitter parse -q -s path/to/*.mib
# Re-run the real-world corpus check that CI runs
git clone https://github.com/netdisco/netdisco-mibs /tmp/netdisco-mibs
PATH="$PWD/node_modules/.bin:$PATH" scripts/check-corpus.sh /tmp/netdisco-mibs
To move to a newer CLI, change the pinned version in package.json, run
npm install and npx tree-sitter generate, and commit the result.
The grammar is in grammar.js, the tests are in test/corpus,
test/highlight and test/tags, and examples/ holds a sample module.
Bindings for C, Node, Python and Rust were generated by tree-sitter init.
Everything is configured in tree-sitter.json.
CI and releases
-
CI (
.github/workflows/ci.yml) runs on pushes tomainand on pull requests, on Linux, macOS and Windows. It checks thatsrc/is up to date, runstree-sitter test, tests the Rust, Node and Python bindings, and re-parses the netdisco-mibs corpus. It also builds the same Python sdist and wheels a release would upload (six platforms, each wheel installed and tested), without publishing them. -
Release (
.github/workflows/release.yml) runs when a release is published on GitHub (Releases → Draft a new release, choose a tag such asv0.2.0, then Publish release). The tag is the version: the package manifests in the repository stay at a0.0.0placeholder, and each release job writes the tag's version into them before building. Nothing needs to be bumped or committed beforehand.Every release gets a Wasm build and a complete source tarball attached, with build-provenance attestations. Publishing to package registries is opt-in per registry, and releases marked as a pre-release are never published to them. Tags must look like
v1.2.3.Registry Turn on Credentials PyPI (TestPyPI first) variable PUBLISH_PYPI=truenone: Trusted Publishing with workflow release.yml, registered on test.pypi.org with environmenttestpypiand on pypi.org with environmentpypinpm variable PUBLISH_NPM=truesecret NPM_TOKENcrates.io variable PUBLISH_CRATES=truesecret CARGO_REGISTRY_TOKENPython packages are uploaded to TestPyPI first, installed back from there and tested, and only then uploaded to PyPI. Every registry upload deploys through a GitHub environment (
testpypi,pypi,npm,crates) that only acceptsv*tags; add required reviewers to an environment to make its deployments wait for approval.
License
MIT
Metadata
Release files for tree-sitter-mib 0.4.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| tree_sitter_mib-0.4.0.tar.gz | 59.1 kB | With provenance | Details for tree_sitter_mib-0.4.0.tar.gz |
Built distributions (wheels)
Total release size: 431.2 kB
Release files / tree_sitter_mib-0.4.0.tar.gz
| Download URL | tree_sitter_mib-0.4.0.tar.gz |
|---|---|
| Size | 59.1 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
35e97b9a2ae326995075d3114214d5e85f2ae58213917d666855d03107905ec9
|
|
BLAKE2b-256 checksum How to use checksums |
69462dd731e67a7f69c6f8874b915613f49ef4cc5c9a9a6ee545bc40d571de42
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.16
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Nov 27, 2026.
Transparency logRelease files / tree_sitter_mib-0.4.0-cp310-abi3-win_arm64.whl
| Download URL | tree_sitter_mib-0.4.0-cp310-abi3-win_arm64.whl |
|---|---|
| Size | 42.9 kB |
| Tags | CPython 3.10 Windows ARM64 abi3 |
|
SHA-256 checksum How to use checksums |
ec007762f3aafac103a2a891d76fb349d89e299cefffcdcddb0c153055a20978
|
|
BLAKE2b-256 checksum How to use checksums |
3b553eba167c422bf4dac634d5aca565910d2cb5d9f77b9567dcc13d955b9664
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.16
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Nov 27, 2026.
Transparency logRelease files / tree_sitter_mib-0.4.0-cp310-abi3-win_amd64.whl
| Download URL | tree_sitter_mib-0.4.0-cp310-abi3-win_amd64.whl |
|---|---|
| Size | 43.7 kB |
| Tags | CPython 3.10 Windows x86-64 abi3 |
|
SHA-256 checksum How to use checksums |
544774c24d8d112eb5c7c05c09078e4390a4867d4edc67d08ed5e1ce7f1f8da2
|
|
BLAKE2b-256 checksum How to use checksums |
2ef7400ab2dfd22aef59e2a872fe8670bf82cfa1996812731d25d71a2242acf9
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.16
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Nov 27, 2026.
Transparency logRelease files / tree_sitter_mib-0.4.0-cp310-abi3-musllinux_1_2_x86_64.whl
| Download URL | tree_sitter_mib-0.4.0-cp310-abi3-musllinux_1_2_x86_64.whl |
|---|---|
| Size | 50.4 kB |
| Tags | CPython 3.10 Linux musl 1.2+ x86-64 abi3 |
|
SHA-256 checksum How to use checksums |
a4edce83f7fb83b136b8404711b28f0e6ee5ea90e5aa98b92e5db7eceb654491
|
|
BLAKE2b-256 checksum How to use checksums |
aaffb3b9e19695a00d28e69fea0eb384c7fd82e41226982f0f6aee78bfed3bc4
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.16
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Nov 27, 2026.
Transparency logRelease files / tree_sitter_mib-0.4.0-cp310-abi3-musllinux_1_2_aarch64.whl
| Download URL | tree_sitter_mib-0.4.0-cp310-abi3-musllinux_1_2_aarch64.whl |
|---|---|
| Size | 50.5 kB |
| Tags | CPython 3.10 Linux musl 1.2+ ARM64 abi3 |
|
SHA-256 checksum How to use checksums |
80664e73191a0cd3d083cb590675fe00d80e145cb082da7ad18eacbb06250d3d
|
|
BLAKE2b-256 checksum How to use checksums |
bb86742695c7f99863a3077fef62a0d09d468e2016428eb3148ec208cbb1a36e
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.16
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Nov 27, 2026.
Transparency logRelease files / tree_sitter_mib-0.4.0-cp310-abi3-manylinux2014_aarch64.manylinux_2_17_aarch64.manylinux_2_28_aarch64.whl
| Download URL | tree_sitter_mib-0.4.0-cp310-abi3-manylinux2014_aarch64.manylinux_2_17_aarch64.manylinux_2_28_aarch64.whl |
|---|---|
| Size | 51.0 kB |
| Tags | CPython 3.10 Linux glibc 2.17+ ARM64 Linux glibc 2.28+ ARM64 abi3 |
|
SHA-256 checksum How to use checksums |
955e01955473017a4a50ca73760a2e8d95a20670d1632ea7cf7f8dbac606d82b
|
|
BLAKE2b-256 checksum How to use checksums |
40e77fbd448f1401c82a37c87008c0b97f8ef4394fc9dc3a44341f000625ac6d
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.16
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Nov 27, 2026.
Transparency logRelease files / tree_sitter_mib-0.4.0-cp310-abi3-manylinux1_x86_64.manylinux_2_28_x86_64.manylinux_2_5_x86_64.whl
| Download URL | tree_sitter_mib-0.4.0-cp310-abi3-manylinux1_x86_64.manylinux_2_28_x86_64.manylinux_2_5_x86_64.whl |
|---|---|
| Size | 50.5 kB |
| Tags | CPython 3.10 Linux glibc 2.28+ x86-64 Linux glibc 2.5+ x86-64 abi3 |
|
SHA-256 checksum How to use checksums |
82335ab5fd1b1a61c878f40fba4dbfc221ca493ba8513ea7f95935f2aca70fae
|
|
BLAKE2b-256 checksum How to use checksums |
645a973374d19c8506f22a7ba734e851821ffac436c6d7f62867c517abf613f8
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.16
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Nov 27, 2026.
Transparency logRelease files / tree_sitter_mib-0.4.0-cp310-abi3-macosx_11_0_arm64.whl
| Download URL | tree_sitter_mib-0.4.0-cp310-abi3-macosx_11_0_arm64.whl |
|---|---|
| Size | 42.4 kB |
| Tags | CPython 3.10 abi3 macOS 11.0+ ARM64 |
|
SHA-256 checksum How to use checksums |
dacc500d9616b5fe68903120c6b0a93a0272b036bb87e3bc81328416e98d78a6
|
|
BLAKE2b-256 checksum How to use checksums |
f8352967430ad0398702c712a3d52178eb914101440fe9729f442a3f4d62fbca
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.16
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Nov 27, 2026.
Transparency logRelease files / tree_sitter_mib-0.4.0-cp310-abi3-macosx_10_9_x86_64.whl
| Download URL | tree_sitter_mib-0.4.0-cp310-abi3-macosx_10_9_x86_64.whl |
|---|---|
| Size | 40.6 kB |
| Tags | CPython 3.10 abi3 macOS 10.9+ x86-64 |
|
SHA-256 checksum How to use checksums |
1fc27e8f3141fcbe0100449434a6ba651997017499c17e0774e93b7d08c77779
|
|
BLAKE2b-256 checksum How to use checksums |
9dc040a93b1ae31555e45ea720ffb50b917e795bbdbf7210693097a65eadf88f
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.16
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Nov 27, 2026.
Transparency logSecurity for tree-sitter-mib 0.4.0
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
Full provenance
All 9 files in this release have been uploaded with provenance metadata.
Attestation for tree_sitter_mib-0.4.0.tar.gz
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Nov 27, 2026.
Transparency logA note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.