Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feat(move-on-aptos): v2 features #503

Merged
merged 2 commits into from
Aug 8, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions lang/semgrep-grammars/src/semgrep-move-on-aptos/grammar.js
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ module.exports = grammar(base_grammar, {
choice(
$._function_signature,
$._struct_signature,
$._enum_signature,
)
),

Expand Down Expand Up @@ -215,6 +216,20 @@ module.exports = grammar(base_grammar, {
field('element', $._dot_or_index_chain), '.', $.ellipsis,
)),

// enum variant
// (e.g. `enum Foo { ..., Bar }`)
_variant: ($, previous) => choice(
previous,
$.ellipsis,
),

// match arm
// (e.g. `match foo { ..., bar => baz }`)
match_arm: ($, previous) => choice(
previous,
$.ellipsis,
),

// identifier, extended to support metavariables
identifier: ($, previous) => token(choice(
previous,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -215,9 +215,11 @@ module 0xdeadbeef::mod {
(identifier)
(type_params
(type_param
(identifier))
(type_param
(identifier)))
(type_param
(ellipsis)))
(type_param
(ellipsis))))
(abilities
(ability))
(body
Expand Down Expand Up @@ -503,4 +505,70 @@ let $LEFT3 = ... . ... .func(...);
(ellipsis))
(identifier)
(call_args
(ellipsis))))))
(ellipsis))))))

=======================
Vector Expression
=======================

let vec_val = vector[...];
let copied = vec_val[0] + vector[1][0];

let vec_2 = vector[1, 2, 3];

---

(source_file
(semgrep_statement
(let_expr
(bind_list
(var_name
(identifier)))
(vector_value_expr
(ellipsis)))
(let_expr
(bind_list
(var_name
(identifier)))
(bin_op_expr
(mem_access
(var
(name_access_chain
(identifier)))
(value
(number)))
(binary_operator)
(mem_access
(vector_value_expr
(value
(number)))
(value
(number)))))
(let_expr
(bind_list
(var_name
(identifier)))
(vector_value_expr
(value
(number))
(value
(number))
(value
(number))))))

=======================
Return Expression
=======================

return | a;

---

(source_file
(semgrep_statement
(bin_op_expr
(return_expr)
(binary_operator)
(var
(name_access_chain
(identifier))))))
Loading
Loading