From ba575b00a4ea38e6e6bdd1bcd5c42c87c95a97ff Mon Sep 17 00:00:00 2001 From: Ben Kettle Date: Fri, 6 Dec 2024 14:26:40 -0800 Subject: [PATCH] chore: add toml language --- .gitmodules | 3 ++ lang/semgrep-grammars/lang/toml | 1 + .../src/semgrep-toml/Makefile | 1 + .../src/semgrep-toml/grammar.js | 29 +++++++++++++++++++ lang/semgrep-grammars/src/semgrep-toml/prep | 1 + .../src/semgrep-toml/test/corpus/semgrep.txt | 0 lang/semgrep-grammars/src/tree-sitter-toml | 1 + lang/toml/Makefile | 1 + lang/toml/extensions.txt | 6 ++++ lang/toml/fyi.list | 3 ++ lang/toml/projects.txt | 3 ++ 11 files changed, 49 insertions(+) create mode 120000 lang/semgrep-grammars/lang/toml create mode 120000 lang/semgrep-grammars/src/semgrep-toml/Makefile create mode 100644 lang/semgrep-grammars/src/semgrep-toml/grammar.js create mode 120000 lang/semgrep-grammars/src/semgrep-toml/prep create mode 100644 lang/semgrep-grammars/src/semgrep-toml/test/corpus/semgrep.txt create mode 160000 lang/semgrep-grammars/src/tree-sitter-toml create mode 120000 lang/toml/Makefile create mode 100644 lang/toml/extensions.txt create mode 100644 lang/toml/fyi.list create mode 100644 lang/toml/projects.txt diff --git a/.gitmodules b/.gitmodules index d3004c26..6265d3bf 100644 --- a/.gitmodules +++ b/.gitmodules @@ -127,3 +127,6 @@ [submodule "tree-sitter-c-sharp-pro"] path = lang/semgrep-grammars/src/tree-sitter-c-sharp-pro url = https://github.com/tree-sitter/tree-sitter-c-sharp.git +[submodule "lang/semgrep-grammars/src/tree-sitter-toml"] + path = lang/semgrep-grammars/src/tree-sitter-toml + url = git@github.com:tree-sitter-grammars/tree-sitter-toml.git diff --git a/lang/semgrep-grammars/lang/toml b/lang/semgrep-grammars/lang/toml new file mode 120000 index 00000000..d088e8f9 --- /dev/null +++ b/lang/semgrep-grammars/lang/toml @@ -0,0 +1 @@ +../src/semgrep-toml \ No newline at end of file diff --git a/lang/semgrep-grammars/src/semgrep-toml/Makefile b/lang/semgrep-grammars/src/semgrep-toml/Makefile new file mode 120000 index 00000000..16641521 --- /dev/null +++ b/lang/semgrep-grammars/src/semgrep-toml/Makefile @@ -0,0 +1 @@ +../Makefile.common \ No newline at end of file diff --git a/lang/semgrep-grammars/src/semgrep-toml/grammar.js b/lang/semgrep-grammars/src/semgrep-toml/grammar.js new file mode 100644 index 00000000..eea84b5b --- /dev/null +++ b/lang/semgrep-grammars/src/semgrep-toml/grammar.js @@ -0,0 +1,29 @@ +/* + semgrep-toml + + Extends the standard toml grammar with semgrep pattern constructs. +*/ + +const base_grammar = require('tree-sitter-toml/grammar'); + +module.exports = grammar(base_grammar, { + name: 'toml', + + conflicts: ($, previous) => previous.concat([ + ]), + + /* + Support for semgrep ellipsis ('...') and metavariables ('$FOO'), + if they're not already part of the base grammar. + */ + rules: { + /* + semgrep_ellipsis: $ => '...', + + _expression: ($, previous) => choice( + $.semgrep_ellipsis, + ...previous.members + ), + */ + } +}); diff --git a/lang/semgrep-grammars/src/semgrep-toml/prep b/lang/semgrep-grammars/src/semgrep-toml/prep new file mode 120000 index 00000000..df68f30a --- /dev/null +++ b/lang/semgrep-grammars/src/semgrep-toml/prep @@ -0,0 +1 @@ +../prep.common \ No newline at end of file diff --git a/lang/semgrep-grammars/src/semgrep-toml/test/corpus/semgrep.txt b/lang/semgrep-grammars/src/semgrep-toml/test/corpus/semgrep.txt new file mode 100644 index 00000000..e69de29b diff --git a/lang/semgrep-grammars/src/tree-sitter-toml b/lang/semgrep-grammars/src/tree-sitter-toml new file mode 160000 index 00000000..64b56832 --- /dev/null +++ b/lang/semgrep-grammars/src/tree-sitter-toml @@ -0,0 +1 @@ +Subproject commit 64b56832c2cffe41758f28e05c756a3a98d16f41 diff --git a/lang/toml/Makefile b/lang/toml/Makefile new file mode 120000 index 00000000..16641521 --- /dev/null +++ b/lang/toml/Makefile @@ -0,0 +1 @@ +../Makefile.common \ No newline at end of file diff --git a/lang/toml/extensions.txt b/lang/toml/extensions.txt new file mode 100644 index 00000000..0f49d20a --- /dev/null +++ b/lang/toml/extensions.txt @@ -0,0 +1,6 @@ +# 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 +# diff --git a/lang/toml/fyi.list b/lang/toml/fyi.list new file mode 100644 index 00000000..fe92bc41 --- /dev/null +++ b/lang/toml/fyi.list @@ -0,0 +1,3 @@ +semgrep-grammars/src/tree-sitter-toml/LICENSE +semgrep-grammars/src/tree-sitter-toml/grammar.js +semgrep-grammars/src/semgrep-toml/grammar.js diff --git a/lang/toml/projects.txt b/lang/toml/projects.txt new file mode 100644 index 00000000..5f8b20ca --- /dev/null +++ b/lang/toml/projects.txt @@ -0,0 +1,3 @@ +# Git URLs of publicly-accessible projects to be used for parsing stats, +# one per line. +#