Skip to main content

AL for Business Central

Project description

tree-sitter-al

A tree-sitter parser for the AL programming language used in Microsoft Dynamics 365 Business Central.

PyPI crates.io npm

Parser Status

Validated against 15,358 production AL files from the Business Central codebase:

Metric Value
Success rate 100% (15,358 / 15,358 files)
Tests 1,404
parser.c size ~11 MB
grammar.js ~3,100 lines
Named keywords 82 (queryable via highlights/tags)
Scanner tokens 8 (stateful, depth-tracking)
Query files 5 (highlights, locals, tags, indents, folds)

Installation

Rust

cargo add tree-sitter-al
use tree_sitter::Parser;

let mut parser = Parser::new();
let language = tree_sitter_al::LANGUAGE;
parser.set_language(&language.into()).expect("Error loading AL grammar");
let tree = parser.parse("codeunit 50100 MyCodeunit { }", None).unwrap();
println!("{}", tree.root_node().to_sexp());

Query constants are also available:

use tree_sitter_al::{HIGHLIGHTS_QUERY, TAGS_QUERY, LOCALS_QUERY, FOLDS_QUERY, INDENTS_QUERY};

Python (tree-sitter 0.24+)

pip install tree-sitter-al
import tree_sitter
import tree_sitter_al

lang = tree_sitter.Language(tree_sitter_al.language())
parser = tree_sitter.Parser(lang)
tree = parser.parse(b'codeunit 50100 MyCodeunit { }')
print(tree.root_node.sexp())

Node.js

npm install tree-sitter-al

Pre-built binaries

Download from GitHub Releases:

File Platform Use case
tree-sitter-al.wasm All web-tree-sitter
tree-sitter-al.so Linux x86_64 ast-grep, native bindings
tree-sitter-al.dll Windows x86_64 ast-grep, native bindings
tree-sitter-al.dylib macOS ARM64 ast-grep, native bindings

V2 Architecture

The grammar was rewritten from scratch in March 2026, achieving a 10x reduction in parser size while improving correctness.

Before / After

Metric V1 V2
parser.c 106 MB (can't push to GitHub) 10.6 MB
Errors 14 0
Success rate 99.91% 100%
Symbols 2,249 ~740
States 29,126 ~5,300
grammar.js 8,500 lines ~3,100 lines
Tests 1,225 1,404
Keywords invisible in queries 82 named nodes
Query files 3 (partial) 5 (comprehensive)

Key design decisions

  • Stateful external scanner — 8 scanner tokens handle property disambiguation, depth tracking (#if/#endif nesting), named begin/end keywords at depth 0, and split-construct detection via lookahead.
  • Parse structure, don't validate — Accept any Name = Value ; as a property. Semantic validation belongs in linters/LSP servers, not the parser.
  • Generic preprocessor — One preproc_conditional rule + ~15 dedicated rules for genuinely complex split constructs (begin/end, var/begin, brace-close across #if/#else branches).
  • 82 named keyword nodes — All keywords including begin/end are named nodes, enabling proper syntax highlighting and code navigation queries.

See docs/v2-blog-post-notes.md for the full rewrite narrative.

Development

Prerequisites

  • Node.js (v16+)
  • tree-sitter CLI: npm install -g tree-sitter-cli

Building

tree-sitter generate    # Generate parser from grammar.js
tree-sitter test        # Run test suite

Validation

./validate-grammar.sh        # Quick: generation, tests, orphan/duplicate detection
./validate-grammar.sh --full # Full: includes production AL file parsing

Parsing AL files

tree-sitter parse path/to/file.al
tree-sitter parse path/to/file.al -d    # Debug output
tree-sitter parse path/to/file.al -q    # Quiet (errors only)

Key files

File Purpose
grammar.js Main grammar definition
src/scanner.c External scanner (8 tokens: property, depth tracking, named begin/end, split detection)
test/corpus/ Test suite (1,404 tests)
queries/ Syntax highlighting, code navigation, folding, indentation

Contributing

See CLAUDE.md for detailed development guidelines including architecture, debugging, and conventions.


Author: Torben Leth (sshadows@sshadows.dk) License: MIT (see LICENSE)

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

tree_sitter_al-2.5.0.tar.gz (1.7 MB view details)

Uploaded Source

Built Distributions

If you're not sure about the file name format, learn more about wheel file names.

tree_sitter_al-2.5.0-cp312-abi3-win_amd64.whl (550.6 kB view details)

Uploaded CPython 3.12+Windows x86-64

tree_sitter_al-2.5.0-cp312-abi3-win32.whl (546.1 kB view details)

Uploaded CPython 3.12+Windows x86

tree_sitter_al-2.5.0-cp312-abi3-musllinux_1_2_x86_64.whl (608.2 kB view details)

Uploaded CPython 3.12+musllinux: musl 1.2+ x86-64

tree_sitter_al-2.5.0-cp312-abi3-manylinux1_x86_64.manylinux_2_28_x86_64.manylinux_2_5_x86_64.whl (611.5 kB view details)

Uploaded CPython 3.12+manylinux: glibc 2.28+ x86-64manylinux: glibc 2.5+ x86-64

tree_sitter_al-2.5.0-cp312-abi3-macosx_11_0_arm64.whl (617.8 kB view details)

Uploaded CPython 3.12+macOS 11.0+ ARM64

File details

Details for the file tree_sitter_al-2.5.0.tar.gz.

File metadata

  • Download URL: tree_sitter_al-2.5.0.tar.gz
  • Upload date:
  • Size: 1.7 MB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for tree_sitter_al-2.5.0.tar.gz
Algorithm Hash digest
SHA256 2861fee21021f5f5cf42150966f3c1f8c8a0d53f482b87e9f3a949cc15b063d2
MD5 04026e015a5ef5328ce9d2e0904d6ea8
BLAKE2b-256 47d4f85154556448a4258902c05678ae6cae0a27bdbdd40743e0f768bfe591d7

See more details on using hashes here.

Provenance

The following attestation bundles were made for tree_sitter_al-2.5.0.tar.gz:

Publisher: publish-pypi.yml on SShadowS/tree-sitter-al

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file tree_sitter_al-2.5.0-cp312-abi3-win_amd64.whl.

File metadata

File hashes

Hashes for tree_sitter_al-2.5.0-cp312-abi3-win_amd64.whl
Algorithm Hash digest
SHA256 1ed4f2c24cb0ce9f3e65838836c302e55a7cc354338127cd8cdf8e81b23cb9c1
MD5 de5e84a5fdc46fa8578961c763df3527
BLAKE2b-256 cea63fb3104da85233c55e55c41677e44d4a52ed1e2270e66ba731a3edd477ac

See more details on using hashes here.

Provenance

The following attestation bundles were made for tree_sitter_al-2.5.0-cp312-abi3-win_amd64.whl:

Publisher: publish-pypi.yml on SShadowS/tree-sitter-al

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file tree_sitter_al-2.5.0-cp312-abi3-win32.whl.

File metadata

  • Download URL: tree_sitter_al-2.5.0-cp312-abi3-win32.whl
  • Upload date:
  • Size: 546.1 kB
  • Tags: CPython 3.12+, Windows x86
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for tree_sitter_al-2.5.0-cp312-abi3-win32.whl
Algorithm Hash digest
SHA256 f021c5b077f50d902863e5c2c8a61a434fcf51e91291b5c167bbc061307464b4
MD5 a97f4f9d20ccb941fd434ff82af57607
BLAKE2b-256 94f8f9956698b91096cfd18910c4d47d307e8f48f896852e173787cbb9e634ca

See more details on using hashes here.

Provenance

The following attestation bundles were made for tree_sitter_al-2.5.0-cp312-abi3-win32.whl:

Publisher: publish-pypi.yml on SShadowS/tree-sitter-al

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file tree_sitter_al-2.5.0-cp312-abi3-musllinux_1_2_x86_64.whl.

File metadata

File hashes

Hashes for tree_sitter_al-2.5.0-cp312-abi3-musllinux_1_2_x86_64.whl
Algorithm Hash digest
SHA256 c480a35d7d34d3506dda672b85c867d51f17ab581532ad7379877f6f030e82e2
MD5 e48f6bfc15d4499eaefc22d9a8d910b9
BLAKE2b-256 02209c8b47eae347ff7918c9a6b6a63299b59d793de4979444c503f5ddf93fbc

See more details on using hashes here.

Provenance

The following attestation bundles were made for tree_sitter_al-2.5.0-cp312-abi3-musllinux_1_2_x86_64.whl:

Publisher: publish-pypi.yml on SShadowS/tree-sitter-al

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file tree_sitter_al-2.5.0-cp312-abi3-manylinux1_x86_64.manylinux_2_28_x86_64.manylinux_2_5_x86_64.whl.

File metadata

File hashes

Hashes for tree_sitter_al-2.5.0-cp312-abi3-manylinux1_x86_64.manylinux_2_28_x86_64.manylinux_2_5_x86_64.whl
Algorithm Hash digest
SHA256 f7e8c07947d64d504b8e4ca818a3773b0f6f19fa1ed30dddc14ba6b4d9555e29
MD5 25ab1cd4ae84e44f572ef7171c1dac1c
BLAKE2b-256 6ada588d17420837a38360ed20605e72ae519ae21aa210a7c7e0292054b57b0a

See more details on using hashes here.

Provenance

The following attestation bundles were made for tree_sitter_al-2.5.0-cp312-abi3-manylinux1_x86_64.manylinux_2_28_x86_64.manylinux_2_5_x86_64.whl:

Publisher: publish-pypi.yml on SShadowS/tree-sitter-al

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file tree_sitter_al-2.5.0-cp312-abi3-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for tree_sitter_al-2.5.0-cp312-abi3-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 2e4ad2d4759e8fafbb7419f14b7f91e272acae920f50d62a1f93804bd4c84e1a
MD5 117f51080428408b6b57336580ed77b9
BLAKE2b-256 be5ead725a6eb36c4bf9ed3ba1ed58a8cafd6f53ab985beed252610f3b6f026c

See more details on using hashes here.

Provenance

The following attestation bundles were made for tree_sitter_al-2.5.0-cp312-abi3-macosx_11_0_arm64.whl:

Publisher: publish-pypi.yml on SShadowS/tree-sitter-al

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page