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.4

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.4
File Size Uploaded
tree_sitter_asn1-1.0.4.tar.gz 205.6 kB Details

Built distributions (wheels)

Table of built distributions (wheels) for tree-sitter-asn1 1.0.4
File
tree_sitter_asn1-1.0.4-cp310-abi3-win_arm64.whl CPython 3.10 abi3 Windows ARM64 Details
tree_sitter_asn1-1.0.4-cp310-abi3-win_amd64.whl CPython 3.10 abi3 Windows x86-64 Details
tree_sitter_asn1-1.0.4-cp310-abi3-musllinux_1_2_x86_64.whl CPython 3.10 abi3 Linux musl 1.2+ x86-64 Details
tree_sitter_asn1-1.0.4-cp310-abi3-musllinux_1_2_aarch64.whl CPython 3.10 abi3 Linux musl 1.2+ ARM64 Details
tree_sitter_asn1-1.0.4-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.4-cp310-abi3-manylinux1_x86_64.manylinux_2_28_x86_64.manylinux_2_5_x86_64.whl CPython 3.10 abi3 Linux glibc 2.28+ x86-64, Linux glibc 2.5+ x86-64 Details
tree_sitter_asn1-1.0.4-cp310-abi3-macosx_11_0_arm64.whl CPython 3.10 abi3 macOS 11.0+ ARM64 Details
tree_sitter_asn1-1.0.4-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.4.tar.gz

Download URL tree_sitter_asn1-1.0.4.tar.gz
Size 205.6 kB
Tags Source
SHA-256 checksum
How to use checksums
63747d493002c67b4361af9322ad1369a137b59b9bfdd7d3e07d46620a2877a1
BLAKE2b-256 checksum
How to use checksums
00b4f57141013926e507dc023550f87a6931ef2afbf26dcc0815de9200c0569f
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.4-cp310-abi3-win_arm64.whl

Download URL tree_sitter_asn1-1.0.4-cp310-abi3-win_arm64.whl
Size 108.6 kB
Tags CPython 3.10 Windows ARM64 abi3
SHA-256 checksum
How to use checksums
96347c6aa59231a6539a16c8752dc9180c96f1a0a86ea579a9f3bde80230f9aa
BLAKE2b-256 checksum
How to use checksums
782505cf0fbbdffc0ccbcc5cbdd6308ea737691c50022524d02a730996df40e1
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.4-cp310-abi3-win_amd64.whl

Download URL tree_sitter_asn1-1.0.4-cp310-abi3-win_amd64.whl
Size 111.3 kB
Tags CPython 3.10 Windows x86-64 abi3
SHA-256 checksum
How to use checksums
adf6af5b4f0b9dd2a447861334fb9f4e4ed31d7b0cb5e308c2634beedcffe26b
BLAKE2b-256 checksum
How to use checksums
f083ebc5d3062c952f563994eff6ae79e741216f44e44015806aa925a6274c3d
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.4-cp310-abi3-musllinux_1_2_x86_64.whl

Download URL tree_sitter_asn1-1.0.4-cp310-abi3-musllinux_1_2_x86_64.whl
Size 129.5 kB
Tags CPython 3.10 Linux musl 1.2+ x86-64 abi3
SHA-256 checksum
How to use checksums
aaeedb3b6ed40976b94f41eac98ec90b5fb54ff70275bace4c883d3dc4b03cab
BLAKE2b-256 checksum
How to use checksums
e92674c018fa754e3e69dfef0f82183c91af5def7e446188a35a10d5ed65798a
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.4-cp310-abi3-musllinux_1_2_aarch64.whl

Download URL tree_sitter_asn1-1.0.4-cp310-abi3-musllinux_1_2_aarch64.whl
Size 127.1 kB
Tags CPython 3.10 Linux musl 1.2+ ARM64 abi3
SHA-256 checksum
How to use checksums
22b559c0c891e89b70a2173bd65f97832ba2048a0bf860904e5b2cb79b06dc49
BLAKE2b-256 checksum
How to use checksums
c9f63ebb630994b39d8168e8ac8d43eb968f1d700704f8431af0a367b18ea399
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.4-cp310-abi3-manylinux2014_aarch64.manylinux_2_17_aarch64.manylinux_2_28_aarch64.whl

Download URL tree_sitter_asn1-1.0.4-cp310-abi3-manylinux2014_aarch64.manylinux_2_17_aarch64.manylinux_2_28_aarch64.whl
Size 128.1 kB
Tags CPython 3.10 Linux glibc 2.17+ ARM64 Linux glibc 2.28+ ARM64 abi3
SHA-256 checksum
How to use checksums
5d4d46cbcf9c83eb73951bd53ac12d5ee6fc7d2d1bfff80263722a009240d03a
BLAKE2b-256 checksum
How to use checksums
c65707b9acbab8bb19fd61f0c04c09b52468c0ae65d2e17dcb09f57299cb708e
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.4-cp310-abi3-manylinux1_x86_64.manylinux_2_28_x86_64.manylinux_2_5_x86_64.whl

Download URL tree_sitter_asn1-1.0.4-cp310-abi3-manylinux1_x86_64.manylinux_2_28_x86_64.manylinux_2_5_x86_64.whl
Size 130.2 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
8fcb43f3a32bba67ca0416ecb3de055d72c96570f4a07de33de7b0f4cf6a7a4b
BLAKE2b-256 checksum
How to use checksums
b6edd7d66f88815f64eee0a5ce62d56fbc1ab13dd308a674570d2e3ffaeed50b
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.4-cp310-abi3-macosx_11_0_arm64.whl

Download URL tree_sitter_asn1-1.0.4-cp310-abi3-macosx_11_0_arm64.whl
Size 114.0 kB
Tags CPython 3.10 abi3 macOS 11.0+ ARM64
SHA-256 checksum
How to use checksums
a71d40c8ccae2295ab6da08b83ec19764ac3fdc680c01b1e7cc6a569573b43cc
BLAKE2b-256 checksum
How to use checksums
9c92701d7da32c1f839694fda3b1fdb97046f2b0f80ec10d4b077e3c7ff5decd
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.4-cp310-abi3-macosx_10_9_x86_64.whl

Download URL tree_sitter_asn1-1.0.4-cp310-abi3-macosx_10_9_x86_64.whl
Size 107.2 kB
Tags CPython 3.10 abi3 macOS 10.9+ x86-64
SHA-256 checksum
How to use checksums
6e8a037276505d86a60d464193ff92f3de0df7662a5b6b575455103ab81263cd
BLAKE2b-256 checksum
How to use checksums
c4714827bc843282f967f61953b495f310e4ea3a9b60f08f21a7113a47d56d9c
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

This release

1.0.4 This release

9 release files

1.0.3

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