From c1289db74c761bc56dc208fd999fa8c10beb7acd Mon Sep 17 00:00:00 2001 From: frodan Date: Mon, 16 Sep 2024 17:41:35 +0700 Subject: [PATCH] update circom semgrep grammar --- .../src/semgrep-circom/grammar.js | 39 +++++++++++++++---- lang/semgrep-grammars/src/tree-sitter-circom | 2 +- 2 files changed, 33 insertions(+), 8 deletions(-) diff --git a/lang/semgrep-grammars/src/semgrep-circom/grammar.js b/lang/semgrep-grammars/src/semgrep-circom/grammar.js index 87b3bb9..688b51b 100644 --- a/lang/semgrep-grammars/src/semgrep-circom/grammar.js +++ b/lang/semgrep-grammars/src/semgrep-circom/grammar.js @@ -12,10 +12,6 @@ module.exports = grammar(base_grammar, { 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) => { @@ -39,12 +35,41 @@ module.exports = grammar(base_grammar, { _expression: ($, previous) => { return choice( - previous, - $.ellipsis, - $.deep_ellipsis + previous, + $.ellipsis, + $.deep_ellipsis ); }, + main_component_definition: ($, previous) => { + return choice( + previous, + seq( + 'component', + 'main', + optional($.main_component_public_signals), + '=', + field('value', choice($.ellipsis, $.deep_ellipsis)), + $._semicolon + + ), + ) + }, + + _component_declaration: ($, previous) => { + return choice( + previous, + seq( + field('name', $.identifier), + optional(field('type', $.array_type)), + optional(seq( + '=', + field('value', choice($.ellipsis, $.deep_ellipsis)) + )) + ) + ) + }, + expression_statement: ($, previous) => { return choice( previous, diff --git a/lang/semgrep-grammars/src/tree-sitter-circom b/lang/semgrep-grammars/src/tree-sitter-circom index c4df066..0215052 160000 --- a/lang/semgrep-grammars/src/tree-sitter-circom +++ b/lang/semgrep-grammars/src/tree-sitter-circom @@ -1 +1 @@ -Subproject commit c4df0664be207e2eae9f5507f9f5f00ea0a952c9 +Subproject commit 02150524228b1e6afef96949f2d6b7cc0aaf999e