A tree-sitter grammar for AutoIt v3.
Companion to the zed-autoit Zed editor extension.
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/@macroidentifiers, integer / float /0xhex 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 withLocal/Global/Dim/Const/Staticmodifiers, array dimensions, optional initializers;Enumwith optionalStep. - 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 yandCase Else),Select,With,Return,Exit,ExitLoop,ContinueLoop,ContinueCase. - Functions:
Func/EndFuncwith optionalVolatile, parameter list withByRef/Constmodifiers 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
_\nline 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.
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())?;npm install
npx tree-sitter generate
npx tree-sitter testA 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.
MIT — see LICENSE.