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

Extract Signatures #11

Merged
merged 6 commits into from
Jul 2, 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
6 changes: 4 additions & 2 deletions batch-test.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ def list_move_codes(path: str) -> List[str]:


PROMPT_EXTRACT = re.compile(r'\(([A-Z]+( [^\[\]]+)?) \[(\d+), \d+\] - \[(\d+), \d+\]\)')
BAD_LINE = re.compile(r'^(abort|return) [^;\r\n]*$')
BAD_LINE = re.compile(r'^(abort|return) [^\r\n]*$')
MOVE_MODULE_PATH = 'aptos-labs/move-modules'


Expand All @@ -50,7 +50,9 @@ def decompiled_workaround(file: str, prompt: str) -> bool:
if line_begin >= len(lines):
return False
line = lines[line_begin].strip()
return BAD_LINE.match(line) is not None
if BAD_LINE.match(line) is not None:
return True
return line[-1] != ';'


def visit_file(file: str) -> TestResult:
Expand Down
35 changes: 22 additions & 13 deletions grammar.js
Original file line number Diff line number Diff line change
Expand Up @@ -487,8 +487,9 @@ module.exports = grammar({
address_block: $ => seq(
'address',
$._leading_name_access,
'{', repeat(seq(optional($.attributes), $.module)), '}'
'{', repeat($._address_member), '}'
),
_address_member: $ => seq(optional($.attributes), $.module),

// Parse a module:
// Module =
Expand All @@ -502,15 +503,17 @@ module.exports = grammar({
// )*
// "}"
// ModuleMemberModifiers = <ModuleMemberModifier>*
_module_ident: $ => 'module',
_module_keyword: $ => 'module',

// (<LeadingNameAccess>::)?<ModuleName>
_module_path: $ => seq(
optional(seq(field('path', $._leading_name_access), '::')),
field('name', $.identifier),
),
module: $ => seq(
// TODO(doc): doc comments are not supported by now.
choice('spec', $._module_ident),
// (<LeadingNameAccess>::)?<ModuleName>
seq(
optional(seq(field('path', $._leading_name_access), '::')),
field('module_name', $.identifier)
),
choice('spec', $._module_keyword),
$._module_path,
'{', repeat($.declaration), '}'
),

Expand Down Expand Up @@ -789,15 +792,18 @@ module.exports = grammar({
// OptionalTypeParameters = '<' Comma<TypeParameter> ">" | <empty>
// Sequence = <UseDecl>* (<SequenceItem> ";")* <Exp>?
function_decl: $ => seq(
$._function_signature,
// Sequence
choice(field('body', $.block), ';'),
),
_function_signature: $ => seq(
optional('inline'),
'fun',
field('name', $.identifier),
field('type_parameters', optional($.type_params)),
field('parameters', $.parameters),
optional(seq(':', field('return_type', $.type))),
optional(field('specifier', $._specifier)),
// Sequence
choice(field('body', $.block), ';'),
),
_specifier: $ => choice(
field('pure', alias('pure', $.pure)),
Expand Down Expand Up @@ -854,10 +860,13 @@ module.exports = grammar({
// StructTypeParameter = '<' Comma<TypeParameterWithPhantomDecl> '>'
// TypeParameterWithPhantomDecl = "phantom"? <TypeParameter>
struct_decl: $ => seq(
$._struct_signature,
choice(alias($.struct_body, $.body), ';'),
),
_struct_signature: $ => seq(
'struct',
$._struct_def_name,
optional(seq('has', $.abilities)),
choice(alias($.struct_body, $.body), ';'),
),
struct_body: $ => seq('{', sepByComma($.field_annot), '}'),
_struct_def_name: $ => seq(
Expand Down Expand Up @@ -930,13 +939,13 @@ module.exports = grammar({
// "}"
script: $ => seq(
'script', '{',
repeat(alias($._script_user_decl, $.declaration)),
repeat(alias($._script_use_decl, $.declaration)),
repeat(alias($._script_constant_decl, $.declaration)),
alias($._script_func_decl, $.declaration),
repeat(alias($._script_spec_block, $.declaration)),
'}'
),
_script_user_decl: $ => seq(optional($.attributes), $.use_decl),
_script_use_decl: $ => seq(optional($.attributes), $.use_decl),
_script_constant_decl: $ => seq(optional($.attributes), $.constant_decl),
_script_func_decl: $ => seq(
optional($.attributes),
Expand Down
204 changes: 115 additions & 89 deletions src/grammar.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading
Loading