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

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

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.1
File Size Uploaded
tree_sitter_asn1-1.0.1.tar.gz 206.1 kB Details

Built distributions (wheels)

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

Download URL tree_sitter_asn1-1.0.1.tar.gz
Size 206.1 kB
Tags Source
SHA-256 checksum
How to use checksums
82f5f97fba38058713ec80447551e44c8efc4da14777daafc754f9931372adb2
BLAKE2b-256 checksum
How to use checksums
42770a5de7f14a7da8435fa404863b348d40424f0cea0bef7719297dffcc0a0c
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.1-cp310-abi3-win_arm64.whl

Download URL tree_sitter_asn1-1.0.1-cp310-abi3-win_arm64.whl
Size 109.3 kB
Tags CPython 3.10 Windows ARM64 abi3
SHA-256 checksum
How to use checksums
b5b28d21a83715840f0f1907675810d909cd7cbe6ed7b8acc73bca169a6da9c8
BLAKE2b-256 checksum
How to use checksums
9083578b2cad0c03e7b7f63c16c1e80a73d7848823246d5a3369ddfc29b14af1
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.1-cp310-abi3-win_amd64.whl

Download URL tree_sitter_asn1-1.0.1-cp310-abi3-win_amd64.whl
Size 112.0 kB
Tags CPython 3.10 Windows x86-64 abi3
SHA-256 checksum
How to use checksums
c067edbbff7cf3537e9821878c6d8be40c09404153956e159f9758b7fce09bd2
BLAKE2b-256 checksum
How to use checksums
35b6166b3245b1a72e710b6c1aacf6792b367d3433f1e49f41955a30627ddb16
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.1-cp310-abi3-musllinux_1_2_x86_64.whl

Download URL tree_sitter_asn1-1.0.1-cp310-abi3-musllinux_1_2_x86_64.whl
Size 130.3 kB
Tags CPython 3.10 Linux musl 1.2+ x86-64 abi3
SHA-256 checksum
How to use checksums
39b84cc5dd6a8b10aa40e7379a94c2ae50d73d2acc89ed40aa2d9f726326dffa
BLAKE2b-256 checksum
How to use checksums
9efd2db0a5cdd59414b4cddeae3858f65de707f12ea0d2bd4178618dd4210b13
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.1-cp310-abi3-musllinux_1_2_aarch64.whl

Download URL tree_sitter_asn1-1.0.1-cp310-abi3-musllinux_1_2_aarch64.whl
Size 128.0 kB
Tags CPython 3.10 Linux musl 1.2+ ARM64 abi3
SHA-256 checksum
How to use checksums
0163bf6c27ff45999448d9d8e13def71d402a805f2204382e23190cd6e847559
BLAKE2b-256 checksum
How to use checksums
3fc36382cf13ff410aeb4c0fd9885a71ec1e713ef3b49749d68822618a7bfb99
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.1-cp310-abi3-manylinux2014_aarch64.manylinux_2_17_aarch64.manylinux_2_28_aarch64.whl

Download URL tree_sitter_asn1-1.0.1-cp310-abi3-manylinux2014_aarch64.manylinux_2_17_aarch64.manylinux_2_28_aarch64.whl
Size 129.0 kB
Tags CPython 3.10 Linux glibc 2.17+ ARM64 Linux glibc 2.28+ ARM64 abi3
SHA-256 checksum
How to use checksums
98eb27c5bf6f4ad5c6b8de0ee02ce7032819c0e71b809c05b7415ff67384b77f
BLAKE2b-256 checksum
How to use checksums
6b2ee9dd4f8bbd163f8fde2955e372df8cca7921cd650e05b5bfd103342d3d9e
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.1-cp310-abi3-manylinux1_x86_64.manylinux_2_28_x86_64.manylinux_2_5_x86_64.whl

Download URL tree_sitter_asn1-1.0.1-cp310-abi3-manylinux1_x86_64.manylinux_2_28_x86_64.manylinux_2_5_x86_64.whl
Size 131.0 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
e1430db1f000ba96951130eeda83845b500990508c440458cd423cf455409997
BLAKE2b-256 checksum
How to use checksums
f6b1dbebbfcdc87409a0d58f4179f4e12732dfab722c3ac475163be9ca8bb8c7
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.1-cp310-abi3-macosx_11_0_arm64.whl

Download URL tree_sitter_asn1-1.0.1-cp310-abi3-macosx_11_0_arm64.whl
Size 114.9 kB
Tags CPython 3.10 abi3 macOS 11.0+ ARM64
SHA-256 checksum
How to use checksums
139b697a0b60a95e207e2364d3f0c861e637cb0db5f2cb6d6442c09d9dcdb154
BLAKE2b-256 checksum
How to use checksums
a700ea6c5f63609eaba239230ba73cf459cfa227325206c703102203c3e25ae7
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.1-cp310-abi3-macosx_10_9_x86_64.whl

Download URL tree_sitter_asn1-1.0.1-cp310-abi3-macosx_10_9_x86_64.whl
Size 108.0 kB
Tags CPython 3.10 abi3 macOS 10.9+ x86-64
SHA-256 checksum
How to use checksums
4a85e9d07944c7637c7b45ee583f5111a2b22af2b38aab417e4b3fde395edbc7
BLAKE2b-256 checksum
How to use checksums
958530c5335f1d144c3f468bc84ece5ca3b9e4b4858a02ad6c8881c259836975
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

1.0.3

9 release files

1.0.2

9 release files

This release

1.0.1 This release

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