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

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

Built distributions (wheels)

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

Download URL tree_sitter_asn1-1.0.2.tar.gz
Size 206.1 kB
Tags Source
SHA-256 checksum
How to use checksums
f322f6f517767542c3703e2468aa255eb9092d0046306d7aa5a59b9b11ea30e2
BLAKE2b-256 checksum
How to use checksums
1da4c81d72280bef10819d246c408e4ec7464b5f75c822f8662b0ed87b181b58
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.2-cp310-abi3-win_arm64.whl

Download URL tree_sitter_asn1-1.0.2-cp310-abi3-win_arm64.whl
Size 109.4 kB
Tags CPython 3.10 Windows ARM64 abi3
SHA-256 checksum
How to use checksums
8a845296437b92cc06f576e37e177a9189094b5aee35adaf43919ace81c9cfa0
BLAKE2b-256 checksum
How to use checksums
070c29ae87571eacc7fec5bbc56974272e6987283af3c379ac1e56f24aeaf509
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.2-cp310-abi3-win_amd64.whl

Download URL tree_sitter_asn1-1.0.2-cp310-abi3-win_amd64.whl
Size 112.0 kB
Tags CPython 3.10 Windows x86-64 abi3
SHA-256 checksum
How to use checksums
a82d2d956aa96aadb697de445c34d86c9b174def0ff9e110b4616f6ad3288f0e
BLAKE2b-256 checksum
How to use checksums
430845bf4c057cf42f9313c7c781b0973b76ff0e28008331de542c5cd680cb8d
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.2-cp310-abi3-musllinux_1_2_x86_64.whl

Download URL tree_sitter_asn1-1.0.2-cp310-abi3-musllinux_1_2_x86_64.whl
Size 130.4 kB
Tags CPython 3.10 Linux musl 1.2+ x86-64 abi3
SHA-256 checksum
How to use checksums
82a1813793d8f51ecce0df38e546cfaff1f3eb978c04ef811070ee8fb5a32070
BLAKE2b-256 checksum
How to use checksums
b6e6b6cf5afbddeca83e81d9ef8c28e52e7be194e0b8cd02d44b4ef709c8012f
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.2-cp310-abi3-musllinux_1_2_aarch64.whl

Download URL tree_sitter_asn1-1.0.2-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
c469dc9fd63443bd895259c4289aced53ce811752453ff97b47d233bf101d351
BLAKE2b-256 checksum
How to use checksums
345eaa854785f29e91afd7da21c2468cc67c7da08050c417fd150eddba96eae2
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.2-cp310-abi3-manylinux2014_aarch64.manylinux_2_17_aarch64.manylinux_2_28_aarch64.whl

Download URL tree_sitter_asn1-1.0.2-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
53a3bb5c79e9330986feac1576c6a79cba00102cd4b71b3e35ee7b693fd7a6f1
BLAKE2b-256 checksum
How to use checksums
3e22e4146c4cb678ba7bc66e2475a0003658ec1f18ec9d71c747efcf85f40051
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.2-cp310-abi3-manylinux1_x86_64.manylinux_2_28_x86_64.manylinux_2_5_x86_64.whl

Download URL tree_sitter_asn1-1.0.2-cp310-abi3-manylinux1_x86_64.manylinux_2_28_x86_64.manylinux_2_5_x86_64.whl
Size 131.1 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
91d263ac036dd262dc7a063057abee80a24da1cd8e1fb162e34dd5ef5e70b838
BLAKE2b-256 checksum
How to use checksums
1b4bc718240aefd2047e96ccde6238c655a4eb6063bef768b6f5161ac95fce28
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.2-cp310-abi3-macosx_11_0_arm64.whl

Download URL tree_sitter_asn1-1.0.2-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
63a6dc1d5650f4ace89ca986324a3cade5d684e808e67087617552bcd4058258
BLAKE2b-256 checksum
How to use checksums
71f263665cb4401675ea57acab76e880eb97f8b6bf8aea9b7486a3a255473d94
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.2-cp310-abi3-macosx_10_9_x86_64.whl

Download URL tree_sitter_asn1-1.0.2-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
e5a6542ff3870d46769084f0020a7d8e08b7ea1119f964f50e56347db67d9537
BLAKE2b-256 checksum
How to use checksums
2c0aeeb6c974d5b1d65746888c340fc4944dd132fbb8dfe55c540ebb753c3db3
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

This release

1.0.2 This release

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