From 96fc57eae9e223cdebbc28fb69859555d035bf4f Mon Sep 17 00:00:00 2001 From: pad Date: Tue, 18 Jul 2023 19:06:28 +0200 Subject: [PATCH] Add tree-sitter-make This is actually a fork of tree-sitter-make because the original author does not seem responsive. See https://github.com/alemuller/tree-sitter-make/pull/19 test plan: ./test-lang make --- .gitmodules | 3 ++ lang/Makefile | 2 ++ lang/make/Makefile | 1 + lang/make/extensions.txt | 6 ++++ lang/make/fyi.list | 3 ++ lang/make/projects.txt | 3 ++ lang/semgrep-grammars/lang/make | 1 + .../src/semgrep-make/Makefile | 1 + .../src/semgrep-make/grammar.js | 29 +++++++++++++++++++ lang/semgrep-grammars/src/semgrep-make/prep | 1 + .../src/semgrep-make/test/corpus/semgrep.txt | 0 lang/semgrep-grammars/src/tree-sitter-make | 1 + 12 files changed, 51 insertions(+) create mode 120000 lang/make/Makefile create mode 100644 lang/make/extensions.txt create mode 100644 lang/make/fyi.list create mode 100644 lang/make/projects.txt create mode 120000 lang/semgrep-grammars/lang/make create mode 120000 lang/semgrep-grammars/src/semgrep-make/Makefile create mode 100644 lang/semgrep-grammars/src/semgrep-make/grammar.js create mode 120000 lang/semgrep-grammars/src/semgrep-make/prep create mode 100644 lang/semgrep-grammars/src/semgrep-make/test/corpus/semgrep.txt create mode 160000 lang/semgrep-grammars/src/tree-sitter-make diff --git a/.gitmodules b/.gitmodules index 1840b4fa..e9d8bd06 100644 --- a/.gitmodules +++ b/.gitmodules @@ -106,3 +106,6 @@ [submodule "lang/semgrep-grammars/src/tree-sitter-promql"] path = lang/semgrep-grammars/src/tree-sitter-promql url = https://github.com/MichaHoffmann/tree-sitter-promql.git +[submodule "lang/semgrep-grammars/src/tree-sitter-make"] + path = lang/semgrep-grammars/src/tree-sitter-make + url = https://github.com/returntocorp/tree-sitter-make diff --git a/lang/Makefile b/lang/Makefile index a97cdae4..2ebcb6fd 100644 --- a/lang/Makefile +++ b/lang/Makefile @@ -30,6 +30,7 @@ SUPPORTED_TS_LANGUAGES = \ jsonnet \ kotlin \ lua \ + make \ ocaml \ php \ promql \ @@ -78,6 +79,7 @@ SUPPORTED_DIALECTS = \ julia \ kotlin \ lua \ + make \ ocaml \ php \ promql \ diff --git a/lang/make/Makefile b/lang/make/Makefile new file mode 120000 index 00000000..16641521 --- /dev/null +++ b/lang/make/Makefile @@ -0,0 +1 @@ +../Makefile.common \ No newline at end of file diff --git a/lang/make/extensions.txt b/lang/make/extensions.txt new file mode 100644 index 00000000..0f49d20a --- /dev/null +++ b/lang/make/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/make/fyi.list b/lang/make/fyi.list new file mode 100644 index 00000000..b72d8fe0 --- /dev/null +++ b/lang/make/fyi.list @@ -0,0 +1,3 @@ +semgrep-grammars/src/tree-sitter-make/LICENSE +semgrep-grammars/src/tree-sitter-make/grammar.js +semgrep-grammars/src/semgrep-make/grammar.js diff --git a/lang/make/projects.txt b/lang/make/projects.txt new file mode 100644 index 00000000..5f8b20ca --- /dev/null +++ b/lang/make/projects.txt @@ -0,0 +1,3 @@ +# Git URLs of publicly-accessible projects to be used for parsing stats, +# one per line. +# diff --git a/lang/semgrep-grammars/lang/make b/lang/semgrep-grammars/lang/make new file mode 120000 index 00000000..0fe4d0b6 --- /dev/null +++ b/lang/semgrep-grammars/lang/make @@ -0,0 +1 @@ +../src/semgrep-make \ No newline at end of file diff --git a/lang/semgrep-grammars/src/semgrep-make/Makefile b/lang/semgrep-grammars/src/semgrep-make/Makefile new file mode 120000 index 00000000..16641521 --- /dev/null +++ b/lang/semgrep-grammars/src/semgrep-make/Makefile @@ -0,0 +1 @@ +../Makefile.common \ No newline at end of file diff --git a/lang/semgrep-grammars/src/semgrep-make/grammar.js b/lang/semgrep-grammars/src/semgrep-make/grammar.js new file mode 100644 index 00000000..33968dfa --- /dev/null +++ b/lang/semgrep-grammars/src/semgrep-make/grammar.js @@ -0,0 +1,29 @@ +/* + semgrep-make + + Extends the standard make grammar with semgrep pattern constructs. +*/ + +const base_grammar = require('tree-sitter-make/grammar'); + +module.exports = grammar(base_grammar, { + name: 'make', + + 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-make/prep b/lang/semgrep-grammars/src/semgrep-make/prep new file mode 120000 index 00000000..df68f30a --- /dev/null +++ b/lang/semgrep-grammars/src/semgrep-make/prep @@ -0,0 +1 @@ +../prep.common \ No newline at end of file diff --git a/lang/semgrep-grammars/src/semgrep-make/test/corpus/semgrep.txt b/lang/semgrep-grammars/src/semgrep-make/test/corpus/semgrep.txt new file mode 100644 index 00000000..e69de29b diff --git a/lang/semgrep-grammars/src/tree-sitter-make b/lang/semgrep-grammars/src/tree-sitter-make new file mode 160000 index 00000000..03b0c47e --- /dev/null +++ b/lang/semgrep-grammars/src/tree-sitter-make @@ -0,0 +1 @@ +Subproject commit 03b0c47e1272b40f5dbaa9962a1783a32e55a4f4