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

v0.0.3 - Add support for Vyper 0.4.0 #35

Merged
merged 10 commits into from
Aug 24, 2024
Merged
Changes from 1 commit
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
Prev Previous commit
Next Next commit
Handle newlines with module def/stmt
benber86 committed Aug 24, 2024
commit 3ce846240a22158e28a99f6acbb9d7d74e56d82f
9 changes: 9 additions & 0 deletions src/mamushi/formatting/whitespace.py
Original file line number Diff line number Diff line change
@@ -61,6 +61,13 @@ def whitespace(leaf: Leaf) -> str:
):
return NO

elif (
prevp.parent
and prevp.parent.parent
and prevp.parent.parent.type == tokens.INITIALIZES_STMT
):
return NO

elif p.type == tokens.KWARG:
if prev.type != tokens.COMMA:
return NO
@@ -98,6 +105,8 @@ def whitespace(leaf: Leaf) -> str:
tokens.INDEXED_ARGS,
tokens.LOG_STMT,
tokens.CONSTANT,
tokens.IMPLEMENTS,
tokens.USES,
tokens.IMMUTABLE,
}
):
18 changes: 13 additions & 5 deletions src/mamushi/parsing/grammar.lark
Original file line number Diff line number Diff line change
@@ -14,7 +14,10 @@ module: ( DOCSTRING
| flag_def
| event_def
| transient_def
| exports_decl
| implements_def
| uses_def
| exports_def
| initializes_stmt
| function_def
| immutable_def
| _NEWLINE )*
@@ -116,10 +119,16 @@ _INTERFACE_DECL: "interface"
mutability: NAME
interface_function: function_sig ":" mutability
interface_def: _INTERFACE_DECL NAME ":" _NEWLINE _INDENT ( interface_function _NEWLINE)+ _DEDENT
_IMPLEMENTS_DECL: "implements"
implements_def: _IMPLEMENTS_DECL ":" NAME

exports_decl: "exports" ":" (attribute | tuple)
implements_def: "implements" ":" NAME
uses_def: "uses" ":" NAME
exports_def: "exports" ":" (attribute | tuple)

_INITIALIZES_DECL: "initializes"
initializes_stmt: _INITIALIZES_DECL ":" initializes_list
initializes_list: NAME ("," NAME)* [initializes_dependency]
initializes_dependency: "[" NAME ":=" NAME ("," NAME ":=" NAME)* "]"


// Statements
// If and For blocks create a new block, and thus are complete when de-indented
@@ -335,7 +344,6 @@ _number: DEC_NUMBER
BOOL.2: "True" | "False"

ELLIPSIS: "..."
_WS: /[ \t\f\r\n]*/

// TODO: Remove Docstring from here, and add to first part of body
?literal: ( _number | strings | DOCSTRING | BOOL | ELLIPSIS)
10 changes: 10 additions & 0 deletions src/mamushi/parsing/tokens.py
Original file line number Diff line number Diff line change
@@ -142,6 +142,8 @@
GETTER_SUFIX = "_with_getter"
CONSTANT = "constant"
IMMUTABLE = "immutable"
IMPLEMENTS = "implements"
USES = "uses"
INDEXED_ARGS = "indexed_event_arg"
ATOM = "atom"

@@ -171,10 +173,14 @@
PASS_STMT = "pass_stmt"
BREAK_STMT = "break_stmt"
CONTINUE_STMT = "continue_stmt"
INITIALIZES_STMT = "initializes_stmt"
RAISE = "raise"
RAISE_WITH_REASON = "raise_with_reason"
IMMUTABLE_DEF = "immutable_def"
INTERFACE_DEF = "interface_def"
IMPLEMENTS_DEF = "implements_def"
USES_DEF = "uses_def"
EXPORTS_DEF = "exports_def"
STRUCT_DEF = "struct_def"
ENUM_DEF = "enum_def"
EVENT_DEF = "event_def"
@@ -192,6 +198,10 @@
RAISE,
RAISE_WITH_REASON,
LOG_STMT,
INITIALIZES_STMT,
IMPLEMENTS_DEF,
USES_DEF,
EXPORTS_DEF,
CONSTANT_DEF,
IMMUTABLE_DEF,
INTERFACE_DEF,
71 changes: 71 additions & 0 deletions tests/data/modules/modules_blank_lines.vy
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
from ..abc import efg


implements: xyz







implements: jkl


uses: rst
uses: rst



uses: rst


initializes: xyz[abc := abc]
initializes: xyz[abc := abc]




initializes: xyz[abc := abc]

initializes: xyz[abc := abc]



exports: (



# @notice comment


abc.gef,

xyz.stu,
)
# output
from ..abc import efg

implements: xyz

implements: jkl

uses: rst
uses: rst

uses: rst

initializes: xyz[abc := abc]
initializes: xyz[abc := abc]

initializes: xyz[abc := abc]

initializes: xyz[abc := abc]

exports: (
# @notice comment


abc.gef,
xyz.stu,
)