Skip to main content

Tree Sitter Grammar for ASN.1

This is a complete and working ASN.1 grammar for tree-sitter. It is based off of the BNF provided in the ITU-T Recommendations X.680 through X.683.

It fully supports parameterization, XML values, information objects, defined syntax, encoding control notation (ECN), etc.

The queries highlights.scm and folds.scm works with nvim-treesitter to provide highlighting and folding. Indents are currently experimental with nvim-treesitter, and didn't work quite right from my experience, and I don't think textobjects.scm is really used anywhere.

Building and testing

Install Node.js dependencies (this also compiles the Node addon):

npm install

After changing grammar.js (or src/scanner.c), regenerate the parser and rebuild the Node addon. tree-sitter test uses the CLI parser; the Node tests in bindings/node load build/Release/tree_sitter_asn1_binding.node, which is not updated by tree-sitter generate alone.

npx tree-sitter generate
npx node-gyp rebuild

There are three overlapping test entry points:

Command What it runs
npx tree-sitter test Corpus only: each example in test/corpus must parse to the expected syntax tree.
make test Corpus, then tree-sitter parse --quiet --stat on every test/asn1/*.asn1 and *.asn file (must parse with no errors; trees are not checked). Uses tree-sitter from PATH, or TS=....
npm test Corpus, then the Node tests in bindings/node/*_test.js: load the native addon, a few CST assertions, and the same test/asn1 fixtures parsed through Node.

make test and npx tree-sitter test both use the CLI parser. npm test uses that CLI for the corpus, then the Node addon for everything else, so regenerate and npx node-gyp rebuild after grammar changes before relying on npm test.

CMake’s ts-test target matches make test. Other language bindings have their own tests (cargo test, go test, and so on).

The playground is npm start (tree-sitter build --wasm then tree-sitter playground).

Why did you have to include an external parser?

This custom parser exists to deal with a very specific issue. If the AssignedIdentifier is not used in the GlobalModuleReference production, and the GlobalModuleReference production is followed by another SymbolsFromModule production that starts with an imported symbol that starts with a lowercased letter, said symbol may be interpreted as the DefinedValue alternative of the AssignedIdentifier production. Then the parser would read a comma or FROM after the symbol and fail, because it expected another symbol.

The solution to this is to read ahead and check if the next non-whitespace token is a comma or FROM. If either of these cases are true, we know that we just read a symbol from the subsequent SymbolsFromModule production rather than a DefinedValue for the AssignedIdentifier production.

Releasing a new Version

Run

# Set the version
npx tree-sitter version $DESIRED_VERSION
# Re-generate the C files, because the version number is incorporate into them.
npx tree-sitter generate
# Apparently needed for the Rust crate to publish
cargo update

Publishing to Various Package Repositories

  • Maven Central (I would have to create the bindings myself, and I have not used Java in 10 years.)
  • jsr.io The NodeJS bindings currently use CommonJS, but JSR requires ESM.
  • NPM
  • PyPI
  • Crates

Metadata

Release files for tree-sitter-asn1 1.0.3

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for tree-sitter-asn1 1.0.3
File Size Uploaded
tree_sitter_asn1-1.0.3.tar.gz 206.0 kB Details

Built distributions (wheels)

Table of built distributions (wheels) for tree-sitter-asn1 1.0.3
File
tree_sitter_asn1-1.0.3-cp310-abi3-win_arm64.whl CPython 3.10 abi3 Windows ARM64 Details
tree_sitter_asn1-1.0.3-cp310-abi3-win_amd64.whl CPython 3.10 abi3 Windows x86-64 Details
tree_sitter_asn1-1.0.3-cp310-abi3-musllinux_1_2_x86_64.whl CPython 3.10 abi3 Linux musl 1.2+ x86-64 Details
tree_sitter_asn1-1.0.3-cp310-abi3-musllinux_1_2_aarch64.whl CPython 3.10 abi3 Linux musl 1.2+ ARM64 Details
tree_sitter_asn1-1.0.3-cp310-abi3-manylinux2014_aarch64.manylinux_2_17_aarch64.manylinux_2_28_aarch64.whl CPython 3.10 abi3 Linux glibc 2.17+ ARM64, Linux glibc 2.28+ ARM64 Details
tree_sitter_asn1-1.0.3-cp310-abi3-manylinux1_x86_64.manylinux_2_28_x86_64.manylinux_2_5_x86_64.whl CPython 3.10 abi3 Linux glibc 2.5+ x86-64, Linux glibc 2.28+ x86-64 Details
tree_sitter_asn1-1.0.3-cp310-abi3-macosx_11_0_arm64.whl CPython 3.10 abi3 macOS 11.0+ ARM64 Details
tree_sitter_asn1-1.0.3-cp310-abi3-macosx_10_9_x86_64.whl CPython 3.10 abi3 macOS 10.9+ x86-64 Details

Total release size: 1.2 MB

Release files / tree_sitter_asn1-1.0.3.tar.gz

Download URL tree_sitter_asn1-1.0.3.tar.gz
Size 206.0 kB
Tags Source
SHA-256 checksum
How to use checksums
bd14c34f1ab9bb9c6282113bb431e57042f352323c96a572697db0743c061951
BLAKE2b-256 checksum
How to use checksums
783afa9914b268af85d7668ea730e966bfd369fb36d916d3ae965dd00d5b012d
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

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 Sep 7, 2026.

Transparency log

Release files / tree_sitter_asn1-1.0.3-cp310-abi3-win_arm64.whl

Download URL tree_sitter_asn1-1.0.3-cp310-abi3-win_arm64.whl
Size 109.3 kB
Tags CPython 3.10 Windows ARM64 abi3
SHA-256 checksum
How to use checksums
020f2d5532107705a3a60113b3d9160008ce8fdeeb582fb49dda19612d082cee
BLAKE2b-256 checksum
How to use checksums
5a34643e0464fd4c4c81b608892afb53299e116795573b9d90baa047c53e7743
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

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 Sep 7, 2026.

Transparency log

Release files / tree_sitter_asn1-1.0.3-cp310-abi3-win_amd64.whl

Download URL tree_sitter_asn1-1.0.3-cp310-abi3-win_amd64.whl
Size 112.0 kB
Tags CPython 3.10 Windows x86-64 abi3
SHA-256 checksum
How to use checksums
e0f6d7742e7858d3a596daee217a359a00b8fa79c409e7aa39a1ef3af425a535
BLAKE2b-256 checksum
How to use checksums
3bc679b5a0152e3e4909a56659a154abcabed874082fb687e4e45d8a6ee46bcf
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

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 Sep 7, 2026.

Transparency log

Release files / tree_sitter_asn1-1.0.3-cp310-abi3-musllinux_1_2_x86_64.whl

Download URL tree_sitter_asn1-1.0.3-cp310-abi3-musllinux_1_2_x86_64.whl
Size 130.2 kB
Tags CPython 3.10 Linux musl 1.2+ x86-64 abi3
SHA-256 checksum
How to use checksums
dc205ce819c12e076209cef3310180cb496baacce6a4fd7ca841ea90858fdb46
BLAKE2b-256 checksum
How to use checksums
b478ee8ee2ce43263a873d398064872c7846a69ac3bf62dc6cea87ce7c110b7d
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

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 Sep 7, 2026.

Transparency log

Release files / tree_sitter_asn1-1.0.3-cp310-abi3-musllinux_1_2_aarch64.whl

Download URL tree_sitter_asn1-1.0.3-cp310-abi3-musllinux_1_2_aarch64.whl
Size 127.8 kB
Tags CPython 3.10 Linux musl 1.2+ ARM64 abi3
SHA-256 checksum
How to use checksums
184dd2da41ba5f3b38b80f16a7304f97cd856fb13ca8a5f70f9fef7783e12584
BLAKE2b-256 checksum
How to use checksums
3cc66a29b7f6ea1d1ff4cff0ee2b0abe82945622c63575f372bb953430d687e0
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

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 Sep 7, 2026.

Transparency log

Release files / tree_sitter_asn1-1.0.3-cp310-abi3-manylinux2014_aarch64.manylinux_2_17_aarch64.manylinux_2_28_aarch64.whl

Download URL tree_sitter_asn1-1.0.3-cp310-abi3-manylinux2014_aarch64.manylinux_2_17_aarch64.manylinux_2_28_aarch64.whl
Size 128.8 kB
Tags CPython 3.10 Linux glibc 2.17+ ARM64 Linux glibc 2.28+ ARM64 abi3
SHA-256 checksum
How to use checksums
3432c0361583c3199eae10bf8424f1286dcac2ed0e9662ea2ef42247de3eba43
BLAKE2b-256 checksum
How to use checksums
e6760a282331a51036a183447162fc82e81293c4af034f9136a8bec65cbd7657
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

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 Sep 7, 2026.

Transparency log

Release files / tree_sitter_asn1-1.0.3-cp310-abi3-manylinux1_x86_64.manylinux_2_28_x86_64.manylinux_2_5_x86_64.whl

Download URL tree_sitter_asn1-1.0.3-cp310-abi3-manylinux1_x86_64.manylinux_2_28_x86_64.manylinux_2_5_x86_64.whl
Size 130.9 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
a76eab4a2a544602d7988ce94f748bfba5c052d2305adbd1e4f3f5d417e62e11
BLAKE2b-256 checksum
How to use checksums
513b37ff4654d21d03f62037ffdea8083503ff07463b5918923296c3ba0999ea
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

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 Sep 7, 2026.

Transparency log

Release files / tree_sitter_asn1-1.0.3-cp310-abi3-macosx_11_0_arm64.whl

Download URL tree_sitter_asn1-1.0.3-cp310-abi3-macosx_11_0_arm64.whl
Size 114.7 kB
Tags CPython 3.10 abi3 macOS 11.0+ ARM64
SHA-256 checksum
How to use checksums
286a5236920af00eb882b4f11b27abea6f442552c82ed2fcb11d6cd2c3e657df
BLAKE2b-256 checksum
How to use checksums
15510ab3517d17875fb968db1f73fa65b0f4ee1b259bc62b8a2640758e5458d4
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

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 Sep 7, 2026.

Transparency log

Release files / tree_sitter_asn1-1.0.3-cp310-abi3-macosx_10_9_x86_64.whl

Download URL tree_sitter_asn1-1.0.3-cp310-abi3-macosx_10_9_x86_64.whl
Size 107.9 kB
Tags CPython 3.10 abi3 macOS 10.9+ x86-64
SHA-256 checksum
How to use checksums
d39d6bc61f3274899bb9b508740bb8500927f867cd9c97ee0f5023feeca7a3f5
BLAKE2b-256 checksum
How to use checksums
e189d7c29cf195f6af420c32f578ffa55addb39895ef985ed3ed0ac1322b90b3
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

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 Sep 7, 2026.

Transparency log

Release history Release notifications | RSS feed

1.0.4

9 release files

This release

1.0.3 This release

9 release files

1.0.2

9 release files

1.0.1

9 release files

1.0.0

9 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page