Skip to content

Commit

Permalink
get rid of ModuleBlock
Browse files Browse the repository at this point in the history
  • Loading branch information
mkurnikov committed Aug 7, 2024
1 parent dcb1ad9 commit 6acf7f0
Show file tree
Hide file tree
Showing 117 changed files with 13,601 additions and 13,945 deletions.
86 changes: 48 additions & 38 deletions src/main/grammars/MoveParser.bnf
Original file line number Diff line number Diff line change
Expand Up @@ -187,25 +187,30 @@ AttrItemInitializer ::= '=' Expr { pin = 1 }

NamedAddressDef ::= address IDENTIFIER '=' AddressRef ';' { pin = 3 }

Script ::= SCRIPT_KW ScriptBlock { pin = 1 }
ScriptBlock ::= '{' ScriptBlockItems '}' {
Script ::= SCRIPT_KW '{' ScriptItem_with_recover* '}'
{
pin = 1
implements = [
"org.move.lang.core.psi.ext.MvItemsOwner"
]
}
private ScriptBlockItems ::= ScriptItem*
ScriptBlock ::= '{' ScriptItem_with_recover* '}' {
// pin = 1
// implements = [
// "org.move.lang.core.psi.ext.MvItemsOwner"
// ]
}

private ScriptItem ::= !('}' | <<eof>>) ScriptItem_item
private ScriptItem_with_recover ::= !('}' | <<eof>>) ScriptItem
{
pin = 1
recoverWhile = ScriptItem_recover
}
// top-level recovery
private ScriptItemFirst ::= use | CONST_KW | fun
private ScriptItem_recover ::= !('}' | <<eof>> | ScriptItemFirst)
private ScriptItem_recover ::= !('}' | ScriptItem_first)
private ScriptItem_first ::= use | CONST_KW | fun

private ScriptItem_item ::= UseStmt | Const | FunctionInner
private ScriptItem ::= UseStmt | Const | FunctionInner

private address ::= <<addressKeyword>>
private has ::= <<hasKeyword>>
Expand All @@ -228,49 +233,49 @@ private AddressBlockItems ::= Module*
}
private AddressBlockItems_recover ::= !'}'

Module ::= Attr* MODULE_KW (AddressRef '::')? IDENTIFIER ModuleBlock
Module ::= Attr* MODULE_KW (AddressRef '::')? IDENTIFIER '{' ModuleItem_with_recover* '}'
{
pin = "MODULE_KW"
name = "module declaration"
implements = [
"org.move.lang.core.psi.MvQualNamedElement"
"org.move.lang.core.psi.MvNameIdentifierOwner"
"org.move.lang.core.psi.ext.MvDocAndAttributeOwner"
"org.move.lang.core.psi.ext.MvItemsOwner"
]
mixin = "org.move.lang.core.psi.ext.MvModuleMixin"
stubClass = "org.move.lang.core.stubs.MvModuleStub"
elementTypeFactory = "org.move.lang.core.stubs.StubsKt.factory"
hooks = [ leftBinder = "ADJACENT_LINE_COMMENTS" ]
}

ModuleBlock ::= '{' ModuleBlockItems '}'
ModuleBlock ::= '{' ModuleItem_with_recover* '}'
{
pin = 1
implements = [
"org.move.lang.core.psi.ext.MvItemsOwner"
]
}
private ModuleBlockItems ::= ModuleItem*
private ModuleItem ::= !('}' | <<eof>>) ModuleItem_item
private ModuleItem_with_recover ::= !('}' | <<eof>>) ModuleItem
{
pin = 1
recoverWhile = Item_recover
recoverWhile = ModuleItem_recover
}
private ModuleItem_recover ::= !('}' | ModuleItem_first)
// top-level recovery
private Item_first ::= use | public | native | fun | CONST_KW | STRUCT_KW | spec | '#'
| "friend" | "entry" | "inline" | "enum"
private Item_recover ::= !('}' | <<eof>> | Item_first)

private ModuleItem_item ::= UseStmt
| FriendDecl
| StructItem
| Enum
| FunctionItem
| SpecFunctionItem
| Const
| Schema
| ModuleItemSpec
| ItemSpec
private ModuleItem_first ::= use | public | native | fun | CONST_KW | STRUCT_KW | spec
| Attr_first | "friend" | "entry" | "inline" | "enum"

private ModuleItem ::= UseStmt
| FriendDecl
| StructItem
| Enum
| FunctionItem
| SpecFunctionItem
| Const
| Schema
| ModuleItemSpec
| ItemSpec

Const ::= Attr* CONST_KW IDENTIFIER TypeAnnotation Initializer ';'
{
Expand Down Expand Up @@ -464,7 +469,7 @@ private FunctionSignatureInner ::= IDENTIFIER TypeParameterList?
{
recoverWhile = "FunctionSignatureInner_recover"
}
private FunctionSignatureInner_recover ::= !('{' | '}' | ';' | <<eof>> | Item_first)
private FunctionSignatureInner_recover ::= !('{' | '}' | ';' | <<eof>> | ModuleItem_first)

private friend ::= <<friendKeyword>>
private enum ::= <<enumKeyword>>
Expand Down Expand Up @@ -683,28 +688,33 @@ BindingPat ::= IDENTIFIER !'::' {
mixin = "org.move.lang.core.psi.ext.MvBindingPatMixin"
}

TuplePat ::= '(' <<non_empty_comma_sep_items Pat>>? ')'
TuplePat ::= '(' ParenListElemPat_with_recover* ')'
private ParenListElemPat_with_recover ::= !')' Pat (',' | &')') {
pin = 1
recoverWhile = ParenListElemPat_recover
}
private ParenListElemPat_recover ::= !(')' | Pat_first)

StructPat ::= PathImpl StructPatFieldsBlock
StructPatFieldsBlock ::= '{' StructPatField_with_recover* '}'
StructPat ::= PathImpl '{' FieldPat_with_recover* '}'
//StructPatFieldsBlock ::= '{' FieldPat_with_recover* '}'

private StructPatField_with_recover ::= !'}' StructPatField (',' | &'}')
private FieldPat_with_recover ::= !'}' FieldPat (',' | &'}')
{
pin = 1
recoverWhile = StructPatField_recover
recoverWhile = FieldPat_recover

}
private StructPatField_recover ::= !('}' | IDENTIFIER)
private FieldPat_recover ::= !('}' | IDENTIFIER)

StructPatField ::= (BindingPat !':') | (IDENTIFIER StructPatFieldBinding)
FieldPat ::= (BindingPat !':') | (IDENTIFIER FieldPatBinding)
{
implements = [
"org.move.lang.core.resolve.ref.MvStructPatFieldReferenceElement"
"org.move.lang.core.psi.ext.MvStructRefField"
"org.move.lang.core.psi.ext.MvFieldRef"
]
mixin = "org.move.lang.core.psi.ext.MvStructPatFieldMixin"
mixin = "org.move.lang.core.psi.ext.MvFieldPatMixin"
}
StructPatFieldBinding ::= ':' Pat
FieldPatBinding ::= ':' Pat

private Pat_first ::= '_' | '(' | Path_first | AnyLitToken_first

Expand Down Expand Up @@ -950,7 +960,7 @@ StructLitField ::= IDENTIFIER StructLitFieldInit?
{
implements = [
"org.move.lang.core.resolve.ref.MvStructFieldLitReferenceElement"
"org.move.lang.core.psi.ext.MvStructRefField"
"org.move.lang.core.psi.ext.MvFieldRef"
]
mixin = "org.move.lang.core.psi.ext.MvStructLitFieldMixin"
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ class HighlightingAnnotator: MvAnnotatorBase() {
if (element is MvNamedFieldDecl) return MvColor.FIELD
if (element is MvStructDotField) return MvColor.FIELD
if (element is MvMethodCall) return MvColor.METHOD_CALL
if (element is MvStructPatField) return MvColor.FIELD
if (element is MvFieldPat) return MvColor.FIELD
if (element is MvStructLitField) return MvColor.FIELD
if (element is MvConst) return MvColor.CONSTANT
if (element is MvModule) return MvColor.MODULE
Expand Down
12 changes: 5 additions & 7 deletions src/main/kotlin/org/move/ide/annotator/MvErrorAnnotator.kt
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ class MvErrorAnnotator: MvAnnotatorBase() {
override fun visitStructPat(o: MvStructPat) {
val nameElement = o.path.referenceNameElement ?: return
val refStruct = o.path.maybeStruct ?: return
val fieldNames = o.patFields.map { it.referenceName }
val fieldNames = o.fieldPatList.map { it.referenceName }
checkMissingFields(
moveHolder, nameElement, fieldNames.toSet(), refStruct
)
Expand Down Expand Up @@ -183,10 +183,10 @@ class MvErrorAnnotator: MvAnnotatorBase() {
}

private fun checkConstDef(holder: MvAnnotationHolder, const: MvConst) {
val owner = const.parent?.parent ?: return
val owner = const.parent ?: return
val allConsts = when (owner) {
is MvModule -> owner.consts()
is MvScript -> owner.consts()
is MvModule -> owner.constList
is MvScript -> owner.constList
else -> return
}
checkDuplicates(holder, const, allConsts.asSequence())
Expand Down Expand Up @@ -372,9 +372,7 @@ private fun checkFunctionDuplicates(
) {
val fnName = fn.name ?: return
val functions =
fn.module?.allFunctions()
?: fn.script?.allFunctions()
?: emptyList()
fn.module?.allFunctions() ?: fn.script?.functionList ?: emptyList()
val duplicateFunctions = getDuplicates(functions.asSequence())

if (fnName !in duplicateFunctions.map { it.name }) {
Expand Down
19 changes: 11 additions & 8 deletions src/main/kotlin/org/move/ide/folding/MvFoldingBuilder.kt
Original file line number Diff line number Diff line change
Expand Up @@ -64,8 +64,9 @@ class MvFoldingBuilder: CustomFoldingBuilder(), DumbAware {
): MvVisitor() {

override fun visitCodeBlock(o: MvCodeBlock) = fold(o)
override fun visitScriptBlock(o: MvScriptBlock) = fold(o)
override fun visitModuleBlock(o: MvModuleBlock) = fold(o)

override fun visitModule(o: MvModule) = foldBetween(o, o.lBrace, o.rBrace)
override fun visitScript(o: MvScript) = foldBetween(o, o.lBrace, o.rBrace)

override fun visitSpecCodeBlock(block: MvSpecCodeBlock) {
if (block.children.isNotEmpty()) {
Expand All @@ -83,16 +84,18 @@ class MvFoldingBuilder: CustomFoldingBuilder(), DumbAware {
}

override fun visitFunctionParameterList(o: MvFunctionParameterList) {
if (o.functionParameterList.isNotEmpty())
fold(o)
if (o.functionParameterList.isEmpty()) return
fold(o)
}

override fun visitBlockFields(o: MvBlockFields) {
if (o.namedFieldDeclList.isNotEmpty())
fold(o)
}
override fun visitBlockFields(o: MvBlockFields) = fold(o)
override fun visitEnumBody(o: MvEnumBody) = fold(o)
override fun visitMatchBody(o: MvMatchBody) = fold(o)
override fun visitStructLitFieldsBlock(o: MvStructLitFieldsBlock) = fold(o)

override fun visitUseStmt(o: MvUseStmt) = foldRepeatingItems(o, o.use, o.use, usesRanges)
override fun visitUseGroup(o: MvUseGroup) = fold(o)

override fun visitConst(o: MvConst) = foldRepeatingItems(o, o.constKw, o.constKw, constRanges)

private fun fold(element: PsiElement) {
Expand Down
Loading

0 comments on commit 6acf7f0

Please sign in to comment.