-
Notifications
You must be signed in to change notification settings - Fork 12
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
Add Move support for semgrep #500
Merged
Merged
Changes from all commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
4ad49d6
update
chargarlic 303b4c8
add files
chargarlic 922f6db
hardcode release to personal repo
chargarlic ec51a5a
Merge branch 'main' into chargarlic/add-support-move
chargarlic d32d4f6
fix ref
chargarlic 09f21fd
Makefile update
chargarlic a336f29
Revert submodules to specific commits
chargarlic 4f31e18
update references to move-on-sui
chargarlic 4bcd90d
update
chargarlic a3e88b0
add references
chargarlic a1d7898
update symlinks
chargarlic File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -86,6 +86,7 @@ SUPPORTED_DIALECTS = \ | |
kotlin \ | ||
lua \ | ||
make \ | ||
move-on-sui \ | ||
move-on-aptos \ | ||
ocaml \ | ||
php \ | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
../Makefile.common |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
semgrep-grammars/src/tree-sitter-move-on-sui/LICENSE | ||
semgrep-grammars/src/tree-sitter-move-on-sui/grammar.js | ||
semgrep-grammars/src/semgrep-move-on-sui/grammar.js |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
# Git URLs of publicly-accessible projects to be used for parsing stats, | ||
# one per line. | ||
# | ||
https://github.com/AftermathFinance/move-interfaces | ||
https://github.com/Bucket-Protocol/bucket-interface | ||
https://github.com/MystenLabs/sui-axelar |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
module hello_sui::hello { | ||
public fun say_hello() { | ||
let message = b"Hello, World!"; | ||
// Print the message | ||
std::debug::print(message); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,110 @@ | ||
// Copyright (c) Mysten Labs, Inc. | ||
// SPDX-License-Identifier: Apache-2.0 | ||
|
||
/// The `string` module defines the `String` type which represents UTF8 encoded strings. | ||
module std::string { | ||
use std::ascii; | ||
use std::vector; | ||
use std::option::{Self, Option}; | ||
|
||
/// An invalid UTF8 encoding. | ||
const EINVALID_UTF8: u64 = 1; | ||
|
||
/// Index out of range. | ||
const EINVALID_INDEX: u64 = 2; | ||
|
||
/// A `String` holds a sequence of bytes which is guaranteed to be in utf8 format. | ||
struct String has copy, drop, store { | ||
bytes: vector<u8>, | ||
} | ||
|
||
/// Creates a new string from a sequence of bytes. Aborts if the bytes do not represent valid utf8. | ||
public fun utf8(bytes: vector<u8>): String { | ||
assert!(internal_check_utf8(&bytes), EINVALID_UTF8); | ||
String{bytes} | ||
} | ||
|
||
/// Convert an ASCII string to a UTF8 string | ||
public fun from_ascii(s: ascii::String): String { | ||
String { bytes: ascii::into_bytes(s) } | ||
} | ||
|
||
/// Convert an UTF8 string to an ASCII string. | ||
/// Aborts if `s` is not valid ASCII | ||
public fun to_ascii(s: String): ascii::String { | ||
let String { bytes } = s; | ||
ascii::string(bytes) | ||
} | ||
|
||
/// Tries to create a new string from a sequence of bytes. | ||
public fun try_utf8(bytes: vector<u8>): Option<String> { | ||
if (internal_check_utf8(&bytes)) { | ||
option::some(String{bytes}) | ||
} else { | ||
option::none() | ||
} | ||
} | ||
|
||
/// Returns a reference to the underlying byte vector. | ||
public fun bytes(s: &String): &vector<u8> { | ||
&s.bytes | ||
} | ||
|
||
/// Checks whether this string is empty. | ||
public fun is_empty(s: &String): bool { | ||
vector::is_empty(&s.bytes) | ||
} | ||
|
||
/// Returns the length of this string, in bytes. | ||
public fun length(s: &String): u64 { | ||
vector::length(&s.bytes) | ||
} | ||
|
||
/// Appends a string. | ||
public fun append(s: &mut String, r: String) { | ||
vector::append(&mut s.bytes, r.bytes) | ||
} | ||
|
||
/// Appends bytes which must be in valid utf8 format. | ||
public fun append_utf8(s: &mut String, bytes: vector<u8>) { | ||
append(s, utf8(bytes)) | ||
} | ||
|
||
/// Insert the other string at the byte index in given string. The index must be at a valid utf8 char | ||
/// boundary. | ||
public fun insert(s: &mut String, at: u64, o: String) { | ||
let bytes = &s.bytes; | ||
assert!(at <= vector::length(bytes) && internal_is_char_boundary(bytes, at), EINVALID_INDEX); | ||
let l = length(s); | ||
let front = sub_string(s, 0, at); | ||
let end = sub_string(s, at, l); | ||
append(&mut front, o); | ||
append(&mut front, end); | ||
*s = front; | ||
} | ||
|
||
/// Returns a sub-string using the given byte indices, where `i` is the first byte position and `j` is the start | ||
/// of the first byte not included (or the length of the string). The indices must be at valid utf8 char boundaries, | ||
/// guaranteeing that the result is valid utf8. | ||
public fun sub_string(s: &String, i: u64, j: u64): String { | ||
let bytes = &s.bytes; | ||
let l = vector::length(bytes); | ||
assert!( | ||
j <= l && i <= j && internal_is_char_boundary(bytes, i) && internal_is_char_boundary(bytes, j), | ||
EINVALID_INDEX | ||
); | ||
String{bytes: internal_sub_string(bytes, i, j)} | ||
} | ||
|
||
/// Computes the index of the first occurrence of a string. Returns `length(s)` if no occurrence found. | ||
public fun index_of(s: &String, r: &String): u64 { | ||
internal_index_of(&s.bytes, &r.bytes) | ||
} | ||
|
||
|
||
// Native API | ||
native fun internal_check_utf8(v: &vector<u8>): bool; | ||
native fun internal_is_char_boundary(v: &vector<u8>, i: u64): bool; | ||
native fun internal_sub_string(v: &vector<u8>, i: u64, j: u64): vector<u8>; | ||
native fun internal_index_of(v: &vector<u8>, r: &vector<u8>): u64; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
../src/semgrep-move-on-sui |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
../Makefile.common |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
/* | ||
semgrep-move-on-sui | ||
|
||
Extends the standard move grammar with semgrep pattern constructs. | ||
*/ | ||
|
||
const base_grammar = require('tree-sitter-move-on-sui/grammar'); | ||
|
||
module.exports = grammar(base_grammar, { | ||
name: 'move', | ||
|
||
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 | ||
), | ||
*/ | ||
} | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
../prep.common |
Empty file.
Submodule tree-sitter-move-on-sui
added at
b454ad
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this needed to be move_on_sui, otherwise
./test-lang move-on-sui was failing with an OCaml linking error.