From 1e4f8b9469bbfb58eb320b29a1a56cbb1055746d Mon Sep 17 00:00:00 2001 From: Amarin Phaosawasdi Date: Tue, 30 Jan 2024 05:56:31 -0800 Subject: [PATCH] elixir: support metavariable atoms --- .../src/semgrep-elixir/grammar.js | 15 ++++++++++++--- .../src/semgrep-elixir/test/corpus/semgrep.txt | 11 +++++++++++ 2 files changed, 23 insertions(+), 3 deletions(-) diff --git a/lang/semgrep-grammars/src/semgrep-elixir/grammar.js b/lang/semgrep-grammars/src/semgrep-elixir/grammar.js index 3c1a9cc4..c5326353 100644 --- a/lang/semgrep-grammars/src/semgrep-elixir/grammar.js +++ b/lang/semgrep-grammars/src/semgrep-elixir/grammar.js @@ -29,14 +29,23 @@ module.exports = grammar(base_grammar, { }, _keyword: ($, previous) => { - return choice( - ...previous.members, - $.metavariable_keyword + return choice( + ...previous.members, + $.metavariable_keyword ); }, metavariable_keyword: $ => seq($._semgrep_metavariable, /:\s/), + _atom: ($, previous) => { + return choice( + ...previous.members, + $.metavariable_atom + ); + }, + + metavariable_atom: $ => seq(":", $._semgrep_metavariable), + _semgrep_metavariable: $ => token(/\$[A-Z_][A-Z_0-9]*/), // Ellipsis diff --git a/lang/semgrep-grammars/src/semgrep-elixir/test/corpus/semgrep.txt b/lang/semgrep-grammars/src/semgrep-elixir/test/corpus/semgrep.txt index ef12d544..ef9c008f 100644 --- a/lang/semgrep-grammars/src/semgrep-elixir/test/corpus/semgrep.txt +++ b/lang/semgrep-grammars/src/semgrep-elixir/test/corpus/semgrep.txt @@ -29,6 +29,17 @@ Metavariables as key value pairs (metavariable_keyword) (identifier)))))) +===================================== +Metavariables as atoms +===================================== + +:$FOO + +--- + +(source + (metavariable_atom)) + ===================================== Ellipsis in calls =====================================