Skip to content

Commit

Permalink
Merge pull request #494 from Frodan/circom
Browse files Browse the repository at this point in the history
Circom
  • Loading branch information
Yoann Padioleau authored Jul 9, 2024
2 parents 2700b86 + b7e8af6 commit 49a61bc
Show file tree
Hide file tree
Showing 12 changed files with 82 additions and 0 deletions.
3 changes: 3 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
Expand Up @@ -118,3 +118,6 @@
[submodule "lang/semgrep-grammars/src/tree-sitter-move-on-aptos"]
path = lang/semgrep-grammars/src/tree-sitter-move-on-aptos
url = https://github.com/aptos-labs/tree-sitter-move-on-aptos.git
[submodule "lang/semgrep-grammars/src/tree-sitter-circom"]
path = lang/semgrep-grammars/src/tree-sitter-circom
url = https://github.com/Decurity/tree-sitter-circom.git
1 change: 1 addition & 0 deletions lang/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ SUPPORTED_TS_LANGUAGES = \
c \
cairo \
clojure \
circom \
cpp \
c-sharp \
dart \
Expand Down
1 change: 1 addition & 0 deletions lang/circom/Makefile
7 changes: 7 additions & 0 deletions lang/circom/extensions.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# File extensions for the target language, one per line. This is used for
# collecting parsing stats from the repos specified in 'projects.txt'. e.g.:
#
# .h
# .c
#
.circom
3 changes: 3 additions & 0 deletions lang/circom/fyi.list
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
semgrep-grammars/src/tree-sitter-circom/LICENSE
semgrep-grammars/src/tree-sitter-circom/grammar.js
semgrep-grammars/src/semgrep-circom/grammar.js
4 changes: 4 additions & 0 deletions lang/circom/projects.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# Git URLs of publicly-accessible projects to be used for parsing stats,
# one per line.
#
https://github.com/iden3/circomlib
1 change: 1 addition & 0 deletions lang/semgrep-grammars/lang/circom
1 change: 1 addition & 0 deletions lang/semgrep-grammars/src/semgrep-circom/Makefile
59 changes: 59 additions & 0 deletions lang/semgrep-grammars/src/semgrep-circom/grammar.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
/*
semgrep-circom
Extends the standard circom grammar with semgrep pattern constructs.
*/

const base_grammar = require('tree-sitter-circom/grammar');

module.exports = grammar(base_grammar, {
name: 'circom',

conflicts: ($, previous) => previous.concat([
]),

/*
Support for semgrep ellipsis ('...') and metavariables ('$FOO'),
if they're not already part of the base grammar.
*/
rules: {

source_file: ($, previous) => {
return choice(
previous,
repeat1($._statement),
$._expression,
);
},

_expression: ($, previous) => {
return choice(
previous,
$.ellipsis,
$.deep_ellipsis
);
},

expression_statement: ($, previous) => {
return choice(
previous,
prec.right(100, seq($.ellipsis, ';')), // expression ellipsis
prec.right(100, $.ellipsis), // statement ellipsis
);
},

for_statement: ($, previous) => {
return choice(
previous,
seq('for', '(', $.ellipsis, ')', $._statement)
);
},

ellipsis: $ => '...',

deep_ellipsis: $ => seq(
'<...', $._expression, '...>'
),

}
});
1 change: 1 addition & 0 deletions lang/semgrep-grammars/src/semgrep-circom/prep
Empty file.
1 change: 1 addition & 0 deletions lang/semgrep-grammars/src/tree-sitter-circom
Submodule tree-sitter-circom added at 659e30

0 comments on commit 49a61bc

Please sign in to comment.