Skip to main content

SAS language grammar for tree-sitter

Project description

tree-sitter-sas

A tree-sitter grammar for the SAS programming language.

npm crates.io PyPI CI License: MIT

Node bindings

Available on npm as tree-sitter-sas.

npm install tree-sitter-sas

Prebuilt native binaries ship for linux-x64, darwin-x64, and darwin-arm64 — no compile step required.

Rust bindings

Available on crates.io as tree-sitter-sas.

[dependencies]
tree-sitter-sas = "0.3"

Python bindings

Available on PyPI as tree-sitter-sas.

pip install tree-sitter-sas

Go bindings

import "github.com/ix-infrastructure/tree-sitter-sas/bindings/go"

Swift bindings

Add to Package.swift:

.package(url: "https://github.com/ix-infrastructure/tree-sitter-sas", from: "0.3.1")

Architecture

flowchart LR
    subgraph source ["Grammar source"]
        G["grammar.js\n(tree-sitter DSL)"]
        SC["src/scanner.c\n(external scanner)"]
    end

    GEN(["tree-sitter generate"])

    subgraph generated ["Generated parser"]
        PC["src/parser.c"]
        NT["src/node-types.json"]
    end

    subgraph queries ["Queries"]
        HL["queries/highlights.scm\n(syntax highlighting)"]
        TG["queries/tags.scm\n(symbol index)"]
    end

    subgraph bindings ["Language bindings"]
        N["Node · npm"]
        R["Rust · crates.io"]
        PY["Python · PyPI"]
        GO["Go"]
        SW["Swift"]
    end

    G & SC --> GEN --> PC & NT
    NT -.-> HL & TG
    PC --> N & R & PY & GO & SW

grammar.js defines the language using the tree-sitter DSL. src/scanner.c is an external lexer that disambiguates %-prefixed macro keywords (%let, %macro, %mend, %include) from user-defined macro calls — it emits a keyword token only when the keyword is not immediately followed by an identifier character, so %letput and %macroFoo correctly fall through to macro_call_statement instead. Running tree-sitter generate produces the LR parser (src/parser.c) and the node type schema (src/node-types.json).

Language coverage

Construct Node type
DATA step data_step
PROC step proc_step
%MACRO / %MEND definition macro_definition
%name(args) call statement macro_call_statement
%name(args) inline call macro_call
%LET var = value macro_variable_assignment
&var, &&var, &var. references macro_variable_ref
%INCLUDE 'path' include_statement
LIBNAME libref ... libname_statement
OPTIONS ... options_statement
/* ... */ block comments block_comment
* ... ; line comments line_comment
%* ... ; macro comments percent_comment
Everything else generic_statement (flat fallback)

Statements not matched by a specific rule are absorbed by generic_statement, which preserves the source text without losing parse continuity. The tree is always complete — unknown or proc-specific syntax never breaks the parse.

Known deviations

generic_statement as a catch-all

SAS has hundreds of proc-specific statements (MODEL, CLASS, OUTPUT inside PROC REG, etc.) that would require individual rules to represent structurally. This grammar uses generic_statement as a flat fallback for any semicolon-terminated statement not matched by a more specific rule. The tradeoff: internal proc statement structure is not captured in the tree, but the tree is always well-formed and the surrounding program structure is always intact.

Macro keyword disambiguation via external scanner

%KEYWORD tokens share a prefix with user-defined macro calls. The external scanner in src/scanner.c resolves the ambiguity: it emits a structured keyword token only when the keyword is not immediately followed by [A-Za-z0-9_]. This means %letput is a macro call, not a %let statement — matching SAS's own behavior.

Bare % in non-macro contexts

A literal % can appear in non-macro positions (e.g. width=20% in ODS style attributes). The external scanner emits a _bare_pct token for these cases, which is absorbed into generic_statement content without triggering a macro parse path.

References

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_sas-0.4.2.tar.gz (86.2 kB view details)

Uploaded Source

Built Distributions

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

tree_sitter_sas-0.4.2-cp310-abi3-win_arm64.whl (55.4 kB view details)

Uploaded CPython 3.10+Windows ARM64

tree_sitter_sas-0.4.2-cp310-abi3-win_amd64.whl (57.3 kB view details)

Uploaded CPython 3.10+Windows x86-64

tree_sitter_sas-0.4.2-cp310-abi3-musllinux_1_2_x86_64.whl (68.4 kB view details)

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

tree_sitter_sas-0.4.2-cp310-abi3-musllinux_1_2_aarch64.whl (68.7 kB view details)

Uploaded CPython 3.10+musllinux: musl 1.2+ ARM64

tree_sitter_sas-0.4.2-cp310-abi3-manylinux2014_aarch64.manylinux_2_17_aarch64.manylinux_2_28_aarch64.whl (69.3 kB view details)

Uploaded CPython 3.10+manylinux: glibc 2.17+ ARM64manylinux: glibc 2.28+ ARM64

tree_sitter_sas-0.4.2-cp310-abi3-manylinux1_x86_64.manylinux_2_28_x86_64.manylinux_2_5_x86_64.whl (69.0 kB view details)

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

tree_sitter_sas-0.4.2-cp310-abi3-macosx_11_0_arm64.whl (56.7 kB view details)

Uploaded CPython 3.10+macOS 11.0+ ARM64

tree_sitter_sas-0.4.2-cp310-abi3-macosx_10_9_x86_64.whl (53.8 kB view details)

Uploaded CPython 3.10+macOS 10.9+ x86-64

File details

Details for the file tree_sitter_sas-0.4.2.tar.gz.

File metadata

  • Download URL: tree_sitter_sas-0.4.2.tar.gz
  • Upload date:
  • Size: 86.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for tree_sitter_sas-0.4.2.tar.gz
Algorithm Hash digest
SHA256 0bf60b6434015b36a0105bbb8b78b2f46568566b5849a74bee3000d39f3926cb
MD5 f10adb675761dd7790194cfb0e7e378d
BLAKE2b-256 237b5644acdbef190098d022ca2feb747e0b9de8bd0aed974e0bfba1f11fd6ff

See more details on using hashes here.

File details

Details for the file tree_sitter_sas-0.4.2-cp310-abi3-win_arm64.whl.

File metadata

File hashes

Hashes for tree_sitter_sas-0.4.2-cp310-abi3-win_arm64.whl
Algorithm Hash digest
SHA256 d3d4676498418e4d622c244ad36b898d9aaf23ce4cf656ec266673af933642da
MD5 eca26ef82149463b2d5f7ca4df0f3ab3
BLAKE2b-256 3a931a638a8df76af05abb73ef6e2b22d35e898d3cb15ccbe446b8d125288887

See more details on using hashes here.

File details

Details for the file tree_sitter_sas-0.4.2-cp310-abi3-win_amd64.whl.

File metadata

File hashes

Hashes for tree_sitter_sas-0.4.2-cp310-abi3-win_amd64.whl
Algorithm Hash digest
SHA256 ca96574dfae47f5a94e2273e38ece25863fd48a4ae5a3d2c03ac2056935a2ce5
MD5 9cbd336044ec01cd41b9224f071650ac
BLAKE2b-256 dbe0fa793931bc57c6dccf10cd2ffdc2a96366d157a2f8cc612e7f0829370f3f

See more details on using hashes here.

File details

Details for the file tree_sitter_sas-0.4.2-cp310-abi3-musllinux_1_2_x86_64.whl.

File metadata

File hashes

Hashes for tree_sitter_sas-0.4.2-cp310-abi3-musllinux_1_2_x86_64.whl
Algorithm Hash digest
SHA256 1be73663c7385e3e894f8b10ecdae636c1d77ea5e921b2d2aee32999c416914d
MD5 3c8568f66e3f7e3a124576f2e87a1597
BLAKE2b-256 b43b2295752b3ef6863ef0e1039748f0b8922527ba287017a4f55dcf1a7c30f8

See more details on using hashes here.

File details

Details for the file tree_sitter_sas-0.4.2-cp310-abi3-musllinux_1_2_aarch64.whl.

File metadata

File hashes

Hashes for tree_sitter_sas-0.4.2-cp310-abi3-musllinux_1_2_aarch64.whl
Algorithm Hash digest
SHA256 0d6a4e7518a1465ed4f2e783ae0901f6e7b660c892379f9447466f94ab8011e2
MD5 fc3bbc3e2bd61dd40c64f8ffd17fbe3f
BLAKE2b-256 c073c6bfe22d61537015a90d3b2c13749ea8db0524ce1b94e4cb728c3a344179

See more details on using hashes here.

File details

Details for the file tree_sitter_sas-0.4.2-cp310-abi3-manylinux2014_aarch64.manylinux_2_17_aarch64.manylinux_2_28_aarch64.whl.

File metadata

File hashes

Hashes for tree_sitter_sas-0.4.2-cp310-abi3-manylinux2014_aarch64.manylinux_2_17_aarch64.manylinux_2_28_aarch64.whl
Algorithm Hash digest
SHA256 074fd05168c7d8ec9e173d4d98ba9698a94b9a7d0a78b5896cb7d110a0d43158
MD5 3a73aa491cb19e76f248608b0255b053
BLAKE2b-256 9623b9a577b563fb6f0cd5b6f280e83290190be8080a4ed580c20224325b1d31

See more details on using hashes here.

File details

Details for the file tree_sitter_sas-0.4.2-cp310-abi3-manylinux1_x86_64.manylinux_2_28_x86_64.manylinux_2_5_x86_64.whl.

File metadata

File hashes

Hashes for tree_sitter_sas-0.4.2-cp310-abi3-manylinux1_x86_64.manylinux_2_28_x86_64.manylinux_2_5_x86_64.whl
Algorithm Hash digest
SHA256 46931772298910d76cf1f3bc64bd49eaca6e6d954646ebfb6f6c02470975a308
MD5 2eebc8e5d6af18fa813469f382322842
BLAKE2b-256 3b12f3508c424a57970717569962d7563db1fe8070f73670fc7fb016b7917dcc

See more details on using hashes here.

File details

Details for the file tree_sitter_sas-0.4.2-cp310-abi3-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for tree_sitter_sas-0.4.2-cp310-abi3-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 684197a93b0d3df37740b3186a150107abeffa5577173d6a0e04b9ee726549a0
MD5 c4fc34912f1f634e44be7de7d573d17c
BLAKE2b-256 85fa6f91ae2c330c9266d11fe19a616a582ecfa6cceb57088d3d5cbe1f3b7c26

See more details on using hashes here.

File details

Details for the file tree_sitter_sas-0.4.2-cp310-abi3-macosx_10_9_x86_64.whl.

File metadata

File hashes

Hashes for tree_sitter_sas-0.4.2-cp310-abi3-macosx_10_9_x86_64.whl
Algorithm Hash digest
SHA256 4bf2d35f18920a1eb2d7088b2a49462e75a496edb4b8b56696bc7e0399f52cd5
MD5 372ed5f6d89807d2fd27565acb66f0da
BLAKE2b-256 23d892640ff898e0de9ed85b11ec0b8e1dc2913de9f61082a3cb95c0899a5613

See more details on using hashes here.

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