diff --git a/.gitmodules b/.gitmodules index ab3e25e9..f38ed35a 100644 --- a/.gitmodules +++ b/.gitmodules @@ -115,3 +115,6 @@ [submodule "lang/semgrep-grammars/src/tree-sitter-ql"] path = lang/semgrep-grammars/src/tree-sitter-ql url = https://github.com/tree-sitter/tree-sitter-ql +[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 diff --git a/lang/move-on-aptos/Makefile b/lang/move-on-aptos/Makefile new file mode 120000 index 00000000..16641521 --- /dev/null +++ b/lang/move-on-aptos/Makefile @@ -0,0 +1 @@ +../Makefile.common \ No newline at end of file diff --git a/lang/move-on-aptos/extensions.txt b/lang/move-on-aptos/extensions.txt new file mode 100644 index 00000000..96bb0ad6 --- /dev/null +++ b/lang/move-on-aptos/extensions.txt @@ -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 +# +.move \ No newline at end of file diff --git a/lang/move-on-aptos/fyi.list b/lang/move-on-aptos/fyi.list new file mode 100644 index 00000000..7f6f9840 --- /dev/null +++ b/lang/move-on-aptos/fyi.list @@ -0,0 +1,3 @@ +semgrep-grammars/src/tree-sitter-move-on-aptos/LICENSE +semgrep-grammars/src/tree-sitter-move-on-aptos/grammar.js +semgrep-grammars/src/semgrep-move-on-aptos/grammar.js diff --git a/lang/move-on-aptos/projects.txt b/lang/move-on-aptos/projects.txt new file mode 100644 index 00000000..551ad3f1 --- /dev/null +++ b/lang/move-on-aptos/projects.txt @@ -0,0 +1,8 @@ +# Git URLs of publicly-accessible projects to be used for parsing stats, +# one per line. +# +https://github.com/aptos-labs/aptos-core +https://github.com/sea-protocol/seaprotocol +https://github.com/wormhole-foundation/wormhole +https://github.com/aptos-labs/aptos-networks +https://github.com/pancakeswap/pancake-contracts-move \ No newline at end of file diff --git a/lang/semgrep-grammars/lang/move-on-aptos b/lang/semgrep-grammars/lang/move-on-aptos new file mode 120000 index 00000000..2eab4f09 --- /dev/null +++ b/lang/semgrep-grammars/lang/move-on-aptos @@ -0,0 +1 @@ +../src/semgrep-move-on-aptos \ No newline at end of file diff --git a/lang/semgrep-grammars/src/semgrep-move-on-aptos/Makefile b/lang/semgrep-grammars/src/semgrep-move-on-aptos/Makefile new file mode 120000 index 00000000..16641521 --- /dev/null +++ b/lang/semgrep-grammars/src/semgrep-move-on-aptos/Makefile @@ -0,0 +1 @@ +../Makefile.common \ No newline at end of file diff --git a/lang/semgrep-grammars/src/semgrep-move-on-aptos/grammar.js b/lang/semgrep-grammars/src/semgrep-move-on-aptos/grammar.js new file mode 100644 index 00000000..53fc2516 --- /dev/null +++ b/lang/semgrep-grammars/src/semgrep-move-on-aptos/grammar.js @@ -0,0 +1,112 @@ +/* + semgrep-move-on-aptos + + Extends the standard move-on-aptos grammar with semgrep pattern constructs. +*/ + +const base_grammar = require('tree-sitter-move-on-aptos/grammar'); + +const FIELD_PREC = 14; + +module.exports = grammar(base_grammar, { + name: 'move_on_aptos', + + conflicts: ($, previous) => previous.concat([ + [$.quantifier, $._quantifier_directive], + [$.var_name, $._bind], + ]), + + /* + Support for semgrep ellipsis ('...') and metavariables ('$FOO'), + if they're not already part of the base grammar. + */ + rules: { + // Semgrep components, source: semgrep-rust + ellipsis: $ => '...', + deep_ellipsis: $ => seq('<...', $._expr, '...>'), + typed_metavariable: $ => seq($.identifier, ':', $.type), + + // Alternate "entry point". Allows parsing a standalone expression. + semgrep_expression: $ => seq('__SEMGREP_EXPRESSION', $._expr), + + // Alternate "entry point". Allows parsing a standalone list of sequence items (statements). + semgrep_statement: $ => seq('__SEMGREP_STATEMENT', repeat1($._sequence_item)), + + // Extend the source_file rule to allow semgrep constructs + source_file: ($, previous) => choice( + previous, + $.semgrep_expression, + $.semgrep_statement, + ), + + // Module declaration + declaration: ($, previous) => choice( + previous, + $.ellipsis, + ), + + // Spec block members + _spec_block_member: ($, previous) => choice( + previous, + $.ellipsis, + ), + + // struct field annotations + field_annot: ($, previous) => choice( + previous, + $.ellipsis, + ), + + // struct field bindings + // (e.g. `let T { field_1, ... } = 0;`) + bind_field: ($, previous) => choice( + previous, + $.ellipsis, + ), + + // attribute + // (e.g. `#[..., attr(...)]`) + attribute: ($, previous) => choice( + previous, + $.ellipsis, + ), + + // use member + // (e.g. `use module_ident::...;`, `use module_ident::{..., item_ident}`) + _use_member: ($, previous) => choice( + previous, + $.ellipsis, + ), + + // expression + _expr: ($, previous) => choice( + ...previous.members, + $.ellipsis, + $.deep_ellipsis, + $.field_access_ellipsis_expr, + ), + + // type parameter + // (e.g. `T: ..., U: ..., ...`) + parameter: ($, previous) => choice( + previous, + $.ellipsis, + ), + + // trailing field access + // (e.g. `foo.bar().baz(). ...`) + field_access_ellipsis_expr: $ => prec.left(FIELD_PREC, seq( + field('element', $._dot_or_index_chain), '.', $.ellipsis, + )), + + // identifier, extended to support metavariables + identifier: ($, previous) => token(choice( + previous, + // Metavariables + alias(choice( + /\$[A-Z_][A-Z_0-9]*/, + /\$\.\.\.[A-Z_][A-Z_0-9]*/, + ), $.meta_var), + )), + } +}); diff --git a/lang/semgrep-grammars/src/semgrep-move-on-aptos/prep b/lang/semgrep-grammars/src/semgrep-move-on-aptos/prep new file mode 120000 index 00000000..df68f30a --- /dev/null +++ b/lang/semgrep-grammars/src/semgrep-move-on-aptos/prep @@ -0,0 +1 @@ +../prep.common \ No newline at end of file diff --git a/lang/semgrep-grammars/src/semgrep-move-on-aptos/test/corpus/semgrep.txt b/lang/semgrep-grammars/src/semgrep-move-on-aptos/test/corpus/semgrep.txt new file mode 100644 index 00000000..e69de29b diff --git a/lang/semgrep-grammars/src/tree-sitter-move-on-aptos b/lang/semgrep-grammars/src/tree-sitter-move-on-aptos new file mode 160000 index 00000000..6eaf726b --- /dev/null +++ b/lang/semgrep-grammars/src/tree-sitter-move-on-aptos @@ -0,0 +1 @@ +Subproject commit 6eaf726bcc766bb9421160109652867ac189757e