Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Optimize grammar. Fix bug with component array access #4

Merged
merged 5 commits into from
Oct 14, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,5 @@ dist
!parser/generate.go
parser/*

iden3-circuits
iden3-circuits
test-data
3 changes: 3 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,6 @@
[submodule "circomlib"]
path = circomlib
url = https://github.com/iden3/circomlib.git
[submodule "passport-zk-circuits"]
path = passport-zk-circuits
url = [email protected]:rarimo/passport-zk-circuits.git
2 changes: 1 addition & 1 deletion base_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import (

// TestParseAllCircuits recursively parses all circuit files in the directory
func TestParseAllCircuits(t *testing.T) {
baseDirs := []string{"iden3-circuits/circuits", "circomlib/circuits", "data"}
baseDirs := []string{"iden3-circuits/circuits", "circomlib/circuits", "data", "passport-zk-circuits/circuits"}

for _, baseDir := range baseDirs {
err := filepath.Walk(baseDir, func(path string, info os.FileInfo, err error) error {
Expand Down
40 changes: 23 additions & 17 deletions grammar/Circom.g4
Original file line number Diff line number Diff line change
Expand Up @@ -30,17 +30,17 @@ functionBlock
;

functionStmt
: functionBlock #FuncBlock
| ID SELF_OP ';' #FuncSelfOp
| varDeclaration ';' #FuncVarDeclaration
| identifier (ASSIGNMENT | ASSIGNMENT_OP) expression ';' #FuncAssignmentExpression
| '(' argsWithUnderscore ')' ASSIGNMENT expression ';' #FuncVariadicAssignment
| 'if' parExpression functionStmt ('else' functionStmt)? #IfFuncStmt
| 'while' parExpression functionStmt #WhileFuncStmt
| 'for' '(' forControl ')' functionStmt #ForFuncStmt
| 'return' expression ';' #ReturnFuncStmt
| 'assert' parExpression ';' #AssertFuncStmt
| logStmt ';' #LogFuncStmt
: functionBlock #FuncBlock
| ID arrayDimension* SELF_OP ';' #FuncSelfOp
| varDeclaration ';' #FuncVarDeclaration
| identifier (ASSIGNMENT | ASSIGNMENT_OP) expression ';' #FuncAssignmentExpression
| '(' argsWithUnderscore ')' ASSIGNMENT ('(' expressionList ')' | expression) ';' #FuncVariadicAssignment
| 'if' parExpression functionStmt ('else' functionStmt)? #IfFuncStmt
| 'while' parExpression functionStmt #WhileFuncStmt
| 'for' '(' forControl ')' functionStmt #ForFuncStmt
| 'return' expression ';' #ReturnFuncStmt
| 'assert' parExpression ';' #AssertFuncStmt
| logStmt ';' #LogFuncStmt
;

templateDeclaration
Expand All @@ -61,20 +61,20 @@ publicInputsList

templateStmt
: templateBlock
| ID SELF_OP ';'
| ID arrayDimension* SELF_OP ';'
| varDeclaration ';'
| signalDeclaration ';'
| componentDeclaration ';'
| blockInstantiation ';'
| (identifier ('.' ID)?) ASSIGNMENT expression ';'
| identifier ASSIGNMENT expression ';'
| expression CONSTRAINT_EQ expression ';'
| element (LEFT_ASSIGNMENT | ASSIGNMENT_OP) expression ';'
| '(' element (',' element)* ')' LEFT_ASSIGNMENT expression ';'
| '(' element (',' element)* ')' LEFT_ASSIGNMENT '(' expression (',' expression)* ')' ';'
| expression RIGHT_ASSIGNMENT element ';'
| expression RIGHT_ASSIGNMENT '(' element (',' element)* ')' ';'
| '_' (ASSIGNMENT | LEFT_ASSIGNMENT) (expression | blockInstantiation) ';'
| (expression | blockInstantiation) RIGHT_ASSIGNMENT '_' ';'
| '(' argsWithUnderscore ')' (ASSIGNMENT | LEFT_ASSIGNMENT) (blockInstantiation | expression) ';'
| '(' argsWithUnderscore ')' (ASSIGNMENT | LEFT_ASSIGNMENT) ('(' expressionList ')' | blockInstantiation | expression) ';'
| blockInstantiation RIGHT_ASSIGNMENT '(' argsWithUnderscore ')' ';'
| 'if' parExpression templateStmt ('else' templateStmt)?
| 'while' parExpression templateStmt
Expand Down Expand Up @@ -144,7 +144,11 @@ varDeclaration
| varDefinition (',' identifier)*
;

rhsValue: expression | blockInstantiation ;
rhsValue
: '(' expressionList ')'
| expression
| blockInstantiation
;

componentCall
: '(' expressionList? ')'
Expand All @@ -156,7 +160,9 @@ blockInstantiation: 'parallel'? ID '(' expressionList? ')' componentCall? ;

expressionList: expression (',' expression)* ;

identifier: (ID | (ID '.' ID)) arrayDimension* ;
identifier
: ID arrayDimension* ('.' ID)? arrayDimension*
;

arrayDimension: '[' expression ']' ;

Expand Down
1 change: 1 addition & 0 deletions passport-zk-circuits
Submodule passport-zk-circuits added at 15c721
Loading