This is a fork of Decurity/tree-sitter-circom
(forked at 0215052). What differs from upstream:
- Compiler-exact syntax. The grammar was checked construct by construct
against the official compiler's grammar (
parser/src/lang.lalrpopin iden3/circom) and against circom 2.2.3 itself. It accepts what the compiler's parser accepts and rejects what it rejects, including:- hexadecimal literals (
0xFF); - circom 2.2 buses:
busdefinitions, bus-typed signals in every header form (input Point() {tag} p[n];,Point(2) output q;,Point p;); - tuple declarations (
signal (a, b[n]) <== T()(x);,var (i, j) = ...;,component (c, d);), tuple and_placeholders on assignment left sides; - anonymous components with named inputs (
T()(a <== x, b <== y)) and anonymous-component statements; template custom/extern_c/parallelmodifiers, templates and buses without a parameter list,parallelexpressions;input signal x;header order, signal tags;log(...)with strings,assert(...);- the compiler's operator precedence tiers (bitwise and shift operators were
wrong upstream), left-associative
**, non-associative ternaries, no unary+, no doubled prefix operators; - the compiler's reserved keywords, top-level item order (pragmas, includes, definitions, main), and string literal rules.
- hexadecimal literals (
- Tree shaped for extraction. Stable field names on definitions,
declarations (one
*_declaratornode per declared name), calls, member access, statements and operators. Seesrc/node-types.json. - ABI 15, generated with tree-sitter CLI 0.26.8, loadable by
github.com/tree-sitter/go-tree-sitterv0.25.0 (ABI 13 to 15). - Go module path
github.com/GraphideHQ/tree-sitter-circom. - Real-world parse check.
script/parse-corpus.shparses every.circomfile of pinned revisions of circomlib, zk-email-verify, circom-ecdsa, semaphore, maci, circomlib-ml, iden3's compiler test circuits and others; every file the compiler accepts parses without an ERROR or MISSING node.script/parse-corpus.excludenames the files the compiler rejects.
💡 this grammar is still in development, the structure of the generated AST is not stable
This repository contains a grammar for tree-sitter.
The goal of this project is to provide an parser efficient low-dependency parser for circom which targets most circom versions in use and is designed for enabling metaprogramming.
The primary file in this repository is grammar.js which describes the tree-sitter grammar.
# Primary file:
grammar.js
# Tests:
/test/**/*
# Auto generated:
/src/**/*
index.js
binding.gyp
-> Circom Documentation:
-> Tree-sitter Solidity grammar:
Major inspriration & some structures have been taken from tree-sitter-solidity, a big thanks to the contributors to this repo!