tree-sitter-snowflake
v0.3.0
Published
Tree-sitter grammar for Snowflake SQL
Maintainers
Readme
tree-sitter-snowflake
A tree-sitter grammar for Snowflake SQL, written from scratch (see NOTICE). It covers Snowflake only: no other SQL dialect and no fallback. A file it cannot parse produces ERROR nodes for the consumer to measure, never a best-effort tree. See Syntax coverage for the supported statements.
Installation
cargo add tree-sitter-snowflake
npm install tree-sitter-snowflakeThe optional snowflake-handlers companion, for extracting and parsing embedded procedure and function bodies, is on crates.io as well: cargo add snowflake-handlers.
Requirements
The Rust crate compiles the committed C parser through cc, so it needs a C compiler and Rust 1.85 or later; the snowflake-handlers crate needs Rust 1.90 or later. The Node package declares tree-sitter ^0.25 as an optional peer dependency.
Usage
let mut parser = tree_sitter::Parser::new();
parser.set_language(&tree_sitter_snowflake::LANGUAGE.into())?;
let tree = parser.parse("SELECT 1;", None);import Snowflake from 'tree-sitter-snowflake';
const program = Snowflake.nodeTypeInfo.find((node) => node.type === 'program');
console.log(program?.children?.types);nodeTypeInfo holds the entries from src/node-types.json; an entry's optional children property is an object with multiple, required, and types properties, not an array, and leaf entries can omit both fields and children.
Procedure and function bodies in JavaScript, Python, Java, and Scala are exposed as nodes; the companion snowflake-handlers crate extracts and parses them. See Embedded bodies and Consumer integration.
How to contribute
Branch from dev. Build with npm ci --ignore-scripts && npm rebuild tree-sitter-cli && npx --no-install tree-sitter generate && cargo build, run the checks listed in CONTRIBUTING.md, and open a pull request against dev. For how the pieces fit together, see ARCHITECTURE.md.
