Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
83 commits
Select commit Hold shift + click to select a range
5f66905
skip trivial first tokens in parsing
NTTVy03 Nov 9, 2024
6913c55
remove comment in input test
NTTVy03 Nov 13, 2024
b2a750f
Merge branch 'master' of https://github.com/vuvoth/ccls
NTTVy03 Nov 18, 2024
caac481
manage out-of-bound case, update input test
NTTVy03 Nov 18, 2024
8efa4f7
update input test
NTTVy03 Nov 18, 2024
c78761e
update input test
NTTVy03 Dec 6, 2024
bfd1f15
make test programs private
NTTVy03 Dec 8, 2024
e054b57
remove comments in syntax tests
NTTVy03 Dec 8, 2024
15c9e5f
format
NTTVy03 Dec 8, 2024
c76246b
make Pragma optional, remove ROOT
NTTVy03 Dec 8, 2024
cd125ab
rename close() params, use advance() in eat(), fix typo scope
NTTVy03 Dec 8, 2024
15470b1
parse params using list_identity
NTTVy03 Dec 8, 2024
6dbb51a
return Option in token_value() and position_of()
NTTVy03 Dec 10, 2024
6d5f0c6
do not allow <--, <== in var declaration
NTTVy03 Dec 10, 2024
fbdc5b9
make public signal optional in main component
NTTVy03 Dec 10, 2024
07c4171
fix format before merge
NTTVy03 Dec 13, 2024
0bf3a04
remove empty test
NTTVy03 Dec 17, 2024
f1b0c39
replace expect by eat in block
NTTVy03 Dec 17, 2024
a10be25
add scope parsing test
NTTVy03 Dec 17, 2024
47df964
fix space in scope parsing test
NTTVy03 Dec 17, 2024
5c6cb56
update snapshot test for syntax
NTTVy03 Dec 19, 2024
372efd3
refactor syntax test
NTTVy03 Dec 19, 2024
46929c2
update input tests with snapshot
NTTVy03 Dec 20, 2024
d811037
change param type in find signal into str
NTTVy03 Dec 25, 2024
cafff02
add snapshot guild
NTTVy03 Dec 27, 2024
03da99a
add some combine arithmetic operators
NTTVy03 Dec 27, 2024
7792a96
error report in expect and expect_any
NTTVy03 Dec 27, 2024
6ac9ac9
update snapshot for combine operators
NTTVy03 Dec 27, 2024
ec73df8
update snapshot test
NTTVy03 Dec 28, 2024
5bdda2f
fix wrap trivial tokens before open a tree
NTTVy03 Dec 28, 2024
8e4853d
update template happy test
NTTVy03 Dec 28, 2024
bb95297
add operators into token kinds
NTTVy03 Dec 28, 2024
6949ca6
Merge branch 'fix-parser' into master
NTTVy03 Dec 30, 2024
7753149
Merge pull request #1 from vuvoth/master
NTTVy03 Dec 30, 2024
97bb689
add operators test
NTTVy03 Dec 30, 2024
179f6bc
re-priority token kinds
NTTVy03 Dec 30, 2024
40268bf
fix clippy check
NTTVy03 Dec 30, 2024
156b872
fix clippy check
NTTVy03 Dec 30, 2024
d18fba0
rebase add-token-kinds
NTTVy03 Dec 30, 2024
84e960b
fix clippy check
NTTVy03 Dec 30, 2024
d9f369e
Merge branch 'master' of https://github.com/NTTVy03/ccls
NTTVy03 Dec 30, 2024
a1bd25e
fix clippy
NTTVy03 Dec 30, 2024
3a08797
remove duplicate declaration in grammar tests
NTTVy03 Dec 30, 2024
39f1e12
add missing signal assign tokens
NTTVy03 Dec 30, 2024
f4db959
fix grammar of for statement
NTTVy03 Dec 30, 2024
a9edb76
add statements test
NTTVy03 Dec 30, 2024
c5a17c3
fix declaration, support matrix
NTTVy03 Dec 30, 2024
605c16b
fix format
NTTVy03 Dec 30, 2024
c9d93f7
refactor declaration
NTTVy03 Dec 31, 2024
8e92b83
use list identity parser in tuple
NTTVy03 Dec 31, 2024
6f6d678
fix right curly count in block
NTTVy03 Dec 31, 2024
df3113d
extract function params
NTTVy03 Dec 31, 2024
f68d36a
add declaration test
NTTVy03 Dec 31, 2024
ccc7226
comment statement in declaration test
NTTVy03 Jan 2, 2025
9a17705
fix format
NTTVy03 Jan 2, 2025
09bb4fa
add function parse test
NTTVy03 Jan 2, 2025
8089756
add comments
NTTVy03 Jan 6, 2025
0bf4056
comments: example in goto_definition_handler
NTTVy03 Jan 15, 2025
13769d6
go-to-defitition in function
NTTVy03 Jan 15, 2025
e8da632
lookup in params
NTTVy03 Jan 15, 2025
ca35cc2
remove lookup signal in function
NTTVy03 Jan 15, 2025
5ca451e
merge master after PR #68 into go-to-def-in-function
NTTVy03 Feb 3, 2025
37c39e5
merge main after PR #66
NTTVy03 Feb 9, 2025
b1cc42c
fix main component grammar
NTTVy03 Feb 22, 2025
87ed2f4
chore: remove all unused files from the project
NTTVy03 May 13, 2025
e153499
chore: refactor Cargo.toml files to use workspace.dependencies
NTTVy03 May 13, 2025
b048d63
refactor: extract syntax test utils into a separate test module
NTTVy03 May 13, 2025
35bf9e5
docs: update README with installation, build, and debug instructions
NTTVy03 May 13, 2025
c0834e8
docs: remove unused note for snapshot
NTTVy03 May 13, 2025
c82896c
chore: rename circom token to circomkw
NTTVy03 May 14, 2025
39f9e5b
refactor: update endline token to support multiple newlines
NTTVy03 May 14, 2025
4f1d82c
chore: clean up trivial token skipping in circom grammar
NTTVy03 May 17, 2025
d34f5c1
chore: update include grammar with fixes, tests, and cleanup
NTTVy03 May 17, 2025
386e216
docs: update docs for pragma, include
NTTVy03 May 17, 2025
62b3a7d
style: update template grammar
NTTVy03 May 17, 2025
d681ad0
style: update function grammar
NTTVy03 May 17, 2025
9cf8ef5
style: update main component grammar
NTTVy03 May 17, 2025
295cb5a
style: update template instantiation grammar
NTTVy03 May 17, 2025
5f9f4c5
style: update function grammar
NTTVy03 May 17, 2025
493f7ea
fix: fix function name
NTTVy03 May 17, 2025
0fae661
chore: remove unused file
NTTVy03 May 17, 2025
43e11cd
Merge remote-tracking branch 'origin/master' into fix/syntax-tree
NTTVy03 May 18, 2025
3a7bc13
fix: remove install circom
NTTVy03 May 18, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 12 additions & 16 deletions crates/lsp/src/database.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,23 +19,19 @@ use syntax::{

/**
* We will store
* Open data -> Parse -> output -> Syntax -> analyzer -> db{
FileID {
Template {
signal,

}
}

value
Template map: { Hash(FileID, token) -> Template}
Vars map: {Hash(FileID, template, token)} -> Var}
Component map {Hash(FileID, template, token)} -> ComponentInfo
Signals map {Hash(FileID, template, token)} -> Signal


* Open data -> Parse -> output -> Syntax -> analyzer -> db
{
FileID {
Template {
signal,
}
}

}
Template map: { Hash(FileID, token) -> Template}
Vars map: {Hash(FileID, template, token)} -> Var}
Component map {Hash(FileID, template, token)} -> ComponentInfo
Signals map {Hash(FileID, template, token)} -> Signal
}
*/

#[derive(Clone, Copy, Debug, Hash, PartialEq, Eq)]
Expand Down
51 changes: 35 additions & 16 deletions crates/parser/src/grammar.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,38 +12,57 @@ mod pragma;
mod statement;
mod template;

/**
* parse circom program
*/

pub mod entry {

use crate::token_kind::TokenKind;

use super::*;

/// Parses a full Circom program from top-level constructs.
///
/// This function handles parsing of all valid top-level elements in a Circom file,
/// such as pragmas, templates, includes, component instantiations, and function
/// definitions. Invalid tokens are flagged with an error.
///
/// Grammar:
/// * `<CircomProgram>` ::= { `<Pragma>` | `<Include>` | `<Template>` | `<Component>` | `<Function>` }
///
/// Example:
/// ```ignore
/// pragma circom 2.0.0;
/// include "utils.circom";
///
/// template Adder(a, b) {
/// signal input a;
/// signal input b;
/// signal output c;
/// c <== a + b;
/// }
///
/// function double(x) -> y {
/// y = x * 2;
/// }
///
/// component main = Adder(1, 2);
/// ```
/// * `<Pragma>`: `pragma circom 2.0.0;`
/// * `<Include>`: `include "utils.circom";`
/// * `<Template>`: A circuit blueprint, e.g. `template Adder(...) { ... }`
/// * `<Function>`: A reusable logic function, e.g. `function double(...) -> ... { ... }`
/// * `<Component>`: An instance of a template, e.g. `component main = Adder(...);`
///
pub fn circom_program(p: &mut Parser) {
let m = p.open();

while p.at_any(&[
TokenKind::BlockComment,
TokenKind::CommentLine,
TokenKind::EndLine,
TokenKind::WhiteSpace,
]) {
p.skip();
}

while !p.eof() {
match p.current() {
PragmaKw => pragma::pragma(p),
TemplateKw => template::template(p),
IncludeKw => include::include(p),
ComponentKw => main_component::main_component(p),
FunctionKw => function::function_parse(p),
FunctionKw => function::function(p),
_ => p.advance_with_error("invalid token"),
}
}

p.close(m, CircomProgram);
}

Expand Down
56 changes: 45 additions & 11 deletions crates/parser/src/grammar/function.rs
Original file line number Diff line number Diff line change
@@ -1,22 +1,56 @@
use list::tuple_identifier;

use crate::grammar::*;
use block::block;
use list::parameter_list;

// fucntion name()
pub fn function_parse(p: &mut Parser) {
/// Functions define generic abstract pieces of code that can perform some computations
/// to obtain a value or an expression to be returned.
///
/// Grammar:
/// * `function <FunctionName> <ParameterList> <FunctionBody>`
///
/// Example:
/// ```ignore
/// function nbits(a) {
/// var n = 1;
/// var r = 0;
/// while (n-1<a) {
/// r++;
/// n *= 2;
/// }
/// return r;
/// }
/// ```
/// * `<FunctionName>`: `nbits`
/// * `<ParameterList>`: `(a)`
/// * `<FunctionBody>`: `{ var n = 1; ... return r; }`
///
pub fn function(p: &mut Parser) {
let m = p.open();

p.expect(FunctionKw);

let fn_name_marker = p.open();
p.expect(Identifier);
p.close(fn_name_marker, FunctionName);
function_name(p);

let parameter_marker = p.open();
tuple_identifier(p);
p.close(parameter_marker, ParameterList);
parameter_list(p);

block::block(p);
let body_marker = p.open();
block(p);
p.close(body_marker, FunctionBody);

p.close(m, FunctionDef);
}

/// Function name used to identify a function.
///
/// Grammar: `Identifier`
///
/// Example:
/// ```ignore
/// MyFunction
/// ```
/// * `Identifier`: `MyFunction`.
pub fn function_name(p: &mut Parser) {
let m = p.open();
p.expect(Identifier);
p.close(m, FunctionName);
}
14 changes: 11 additions & 3 deletions crates/parser/src/grammar/include.rs
Original file line number Diff line number Diff line change
@@ -1,11 +1,19 @@
use super::*;

/// In order to use code in other files, we have to
/// include them in our program.
///
/// Grammar:
/// * `include "<filename>";`
///
/// Example:
/// ```ignore
/// include "circuit.circom";
/// ```
pub(super) fn include(p: &mut Parser) {
// assert!(p.at(IncludeKw));

let m = p.open();
p.expect(IncludeKw);
p.expect(CircomString);
p.expect(Semicolon);
p.close(m, IncludeKw);
p.close(m, Include);
}
81 changes: 43 additions & 38 deletions crates/parser/src/grammar/list.rs
Original file line number Diff line number Diff line change
@@ -1,59 +1,65 @@
use crate::grammar::{expression::expression, *};

/**
* grammar: "(expression-1, expression-2,..., expression-n)"
* can be an empty ()
*/
pub(super) fn tuple_expression(p: &mut Parser) {
// let m = p.open();
p.expect(LParen);
/// Argument list used to pass parameters to a template/function instantiation.
///
/// Grammar: `(expression-1, expression-2,..., expression-n)`
///
/// Example:
/// ```ignore
/// component comp = MyTemplate( 2,3 );
/// ```
/// * `expression-1`: `2`
/// * `expression-2`: `3`
pub fn argument_list(p: &mut Parser) {
let m = p.open();

// expression-1, expression-2,..., expression-n)
while !p.at(RParen) && !p.eof() {
expression(p);
tuple_expression(p);

// there are no expressions remaining
if !p.eat(Comma) {
break;
}
}
p.close(m, ArgumentList);
}

p.expect(RParen);
/// Parameter list used to pass parameters to a template/function definition.
///
/// Grammar: `(iden-1, iden-2,..., iden-n)`
/// Can be an empty `()`.
///
/// Example:
/// ```ignore
/// template MyTemplate( a, b ) {
/// ...
/// }
/// ```
/// * `iden-1`: `a`
/// * `iden-2`: `b`
pub fn parameter_list(p: &mut Parser) {
let m = p.open();

// p.close(m, ExpressionList);
tuple_identifier(p);

p.close(m, ParameterList);
}

/**
* grammar: "(iden1, iden2,..., idenn)"
* can be an empty ()
*/
pub(super) fn tuple_identifier(p: &mut Parser) {
// let m = p.open();
/// Grammar: `(expression-1, expression-2,..., expression-n)`
/// Can be an empty `()`.
pub(super) fn tuple_expression(p: &mut Parser) {
p.expect(LParen);

// iden1, iden2, iden3
while p.at(Identifier) && !p.eof() {
p.expect(Identifier);
while !p.at(RParen) && !p.eof() {
expression(p);

if !p.eat(Comma) {
break;
}
}

p.expect(RParen);
// p.close(m, IdentifierList);
}

/**
* grammar: "[iden1, iden2,..., idenn]"
* can be an empty ()
* only use in main component.
*/
pub(super) fn list_identifier(p: &mut Parser) {
// let m = p.open();
p.expect(LBracket);
/// Grammar: `(iden-1, iden-2,..., iden-n)`
/// Can be an empty `()`.
pub(super) fn tuple_identifier(p: &mut Parser) {
p.expect(LParen);

// iden1, iden2, iden3
while p.at(Identifier) && !p.eof() {
p.expect(Identifier);

Expand All @@ -62,6 +68,5 @@ pub(super) fn list_identifier(p: &mut Parser) {
}
}

p.expect(RBracket);
// p.close(m, IdentifierList);
p.expect(RParen);
}
Loading