Skip to content

Repository files navigation

tree-sitter-autoit

A tree-sitter grammar for AutoIt v3.

Companion to the zed-autoit Zed editor extension.

Status

Phase 2 complete — 182/182 corpus tests passing. Verified against AutoIt's bundled Examples directory (2,662 files) at 99.96% pass rate. The grammar parses real-world .au3 scripts end-to-end. Coverage:

  • Lexical: line + block comments, single/double-quoted strings with ""/'' escape, $variable / @macro identifiers, integer / float / 0x hex numbers, _ line continuation.
  • Expressions: parenthesized, unary (-, +, Not), 7-level binary precedence (right-assoc ^), postfix call / index / member, array literals ([a, b, c]), With-block leading-dot member access.
  • Statements: assignments (=, +=, -=, *=, /=, &=); declarations with Local / Global / Dim / Const / Static modifiers, array dimensions, optional initializers; Enum with optional Step.
  • Control flow: multi-line and single-line If / ElseIf / Else, While / Wend, Do / Until, For…To…Step / Next, For…In / Next, Switch (incl. Case x To y and Case Else), Select, With, Return, Exit, ExitLoop, ContinueLoop, ContinueCase.
  • Functions: Func / EndFunc with optional Volatile, parameter list with ByRef / Const modifiers and default values.
  • Directives: #include <…> / "…", #include-once, paired #region / #endregion (also orphan forms), #pragma, #RequireAdmin, #NoTrayIcon, #OnAutoItStartRegister, plus a generic catchall for #AutoIt3Wrapper_* and similar.
  • Foundation: external scanner emits statement terminators and consumes _\n line continuations; CRLF and LF are treated identically.

Sharp edges intentionally handled per the AutoIt v3 language reference: Not binds tighter than ^; Mod is a function call, not an operator; = is assignment at statement position and string equality in expressions; == is case-sensitive equality.

Use as a Rust crate

The grammar ships Rust bindings (Cargo.toml + build.rs + bindings/rust/lib.rs) so downstream Rust projects can link the parser directly. Used by the autoit-lsp language server.

[dependencies]
tree-sitter = "0.25"
tree-sitter-autoit = { git = "https://github.com/sumit-m/tree-sitter-autoit", rev = "..." }
let mut parser = tree_sitter::Parser::new();
parser.set_language(&tree_sitter_autoit::LANGUAGE.into())?;

Development

npm install
npx tree-sitter generate
npx tree-sitter test

A realistic end-to-end sample (hello.au3) lives in the sibling zed-autoit extension repo at samples/hello.au3 — point npx tree-sitter parse at it from there if you want a whole-file smoke check beyond the corpus.

You'll need tree-sitter-cli. The dev dep above pulls it in locally; install globally with npm install -g tree-sitter-cli if you prefer.

License

MIT — see LICENSE.

About

tree-sitter grammar for AutoIt v3

Resources

Stars

Watchers

Forks

Releases

Packages

Contributors

Languages