Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/distributed-lab/circom-parser
Circom circuit parser built with ANTLR4
https://github.com/distributed-lab/circom-parser
antlr antlr4 circom parser zk
Last synced: about 2 months ago
JSON representation
Circom circuit parser built with ANTLR4
- Host: GitHub
- URL: https://github.com/distributed-lab/circom-parser
- Owner: distributed-lab
- License: mit
- Created: 2024-08-13T10:27:00.000Z (5 months ago)
- Default Branch: main
- Last Pushed: 2024-10-31T15:35:10.000Z (2 months ago)
- Last Synced: 2024-11-13T15:06:30.854Z (about 2 months ago)
- Topics: antlr, antlr4, circom, parser, zk
- Language: TypeScript
- Homepage: https://www.npmjs.com/package/@distributedlab/circom-parser
- Size: 2.15 MB
- Stars: 3
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Circom Parser
A TypeScript package for parsing [Circom](https://docs.circom.io) code using [ANTLR (ANother Tool for Language Recognition)](https://github.com/distributed-lab/circom-g4-grammar) grammar.
It includes built-in visitors and utilities that allow you to parse, traverse, and manipulate Circom circuits.
## Installation
```bash
npm install @distributedlab/circom-parser
```## Usage
### Custom Visitor Creation
To create your own visitor, simply extend the CircomVisitor class and override the visit methods you need.
```typescript
import { CircomVisitor, AnyRuleContext } from '@distributed-lab/circom-parser';export default class MyCircomVisitor extends CircomVisitor {
visitAnyRule = (ctx: AnyRuleContext) => {
// override the visit logic here
}
}
```### Custom Visitor Usage
After creating your custom visitor, you can use it with the CircomParser to traverse and manipulate the parse tree.
```typescript
import { getCircomParser, ParserError } from '@distributed-lab/circom-parser';import { MyCircomVisitor } from './MyCircomVisitor';
const { parser, errorListener } = getCircomParser(source);
const templateVisitor = new MyCircomVisitor();
templateVisitor.visit(parser.circuit());
if (errorListener.hasErrors()) {
throw new ParserError(errorListener.getErrors());
}
```