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

with abilities in lambda expr and type #280

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
13 changes: 11 additions & 2 deletions src/main/grammars/MoveParser.bnf
Original file line number Diff line number Diff line change
Expand Up @@ -676,7 +676,7 @@ PathType ::= PathImpl

TupleType ::= '(' Type ',' (Type ','?)* ')' { pin = 3 }

LambdaType ::= '|' !',' <<comma_separated_list LambdaTypeParam>>? '|' Type?
LambdaType ::= '|' !',' <<comma_separated_list LambdaTypeParam>>? '|' Type? WithAbilities?
LambdaTypeParam ::= Type

TypeParameterList ::= '<' TypeParameter_with_recover* '>'
Expand Down Expand Up @@ -1099,7 +1099,16 @@ upper TupleLitExprUpper ::= ',' [ Expr (',' Expr)* ','? ] ')' {
elementType = TupleLitExpr
}

LambdaExpr ::= LambdaParameterList Expr? { pin = 1 }
LambdaExpr ::= LambdaParameterList Expr? WithAbilities? { pin = 1 }
WithAbilities ::= with WithAbility_items
{
pin = 1
}
private WithAbility_items ::= Ability ( '+' Ability )*
{
recoverWhile = WithAbility_items_recover
}
private WithAbility_items_recover ::= !(';' | Expr_first | ')')

LambdaParameterList ::= '|' !',' <<comma_separated_list LambdaParameter>>? '|'
LambdaParameter ::= PatBinding TypeAscription?
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ class CompleteParsingTest: MvParsingTestCase("complete") {
fun `test loop labels`() = doTest()
fun `test assign bin expr`() = doTest()
fun `test lambdas`() = doTest()
fun `test new lambdas`() = doTest()

fun doTest() {
super.doTest(true, true)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
module 0x1::new_lambdas {
fun main() {
let a: |u8| u8 with store + drop;
|a: u8| 1 with store + drop;
}
}
85 changes: 85 additions & 0 deletions src/test/resources/org/move/lang/parser/complete/new_lambdas.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
FILE
MvModuleImpl(MODULE)
PsiElement(module)('module')
PsiWhiteSpace(' ')
MvAddressRefImpl(ADDRESS_REF)
PsiElement(DIEM_ADDRESS)('0x1')
PsiElement(::)('::')
PsiElement(IDENTIFIER)('new_lambdas')
PsiWhiteSpace(' ')
PsiElement({)('{')
PsiWhiteSpace('\n ')
MvFunctionImpl(FUNCTION)
PsiElement(fun)('fun')
PsiWhiteSpace(' ')
PsiElement(IDENTIFIER)('main')
MvFunctionParameterListImpl(FUNCTION_PARAMETER_LIST)
PsiElement(()('(')
PsiElement())(')')
PsiWhiteSpace(' ')
MvCodeBlockImpl(CODE_BLOCK)
PsiElement({)('{')
PsiWhiteSpace('\n ')
MvLetStmtImpl(LET_STMT)
PsiElement(let)('let')
PsiWhiteSpace(' ')
MvPatBindingImpl(PAT_BINDING)
PsiElement(IDENTIFIER)('a')
PsiElement(:)(':')
PsiWhiteSpace(' ')
MvLambdaTypeImpl(LAMBDA_TYPE)
PsiElement(|)('|')
MvLambdaTypeParamImpl(LAMBDA_TYPE_PARAM)
MvPathTypeImpl(PATH_TYPE)
MvPathImpl(PATH)
PsiElement(IDENTIFIER)('u8')
PsiElement(|)('|')
PsiWhiteSpace(' ')
MvPathTypeImpl(PATH_TYPE)
MvPathImpl(PATH)
PsiElement(IDENTIFIER)('u8')
PsiWhiteSpace(' ')
MvWithAbilitiesImpl(WITH_ABILITIES)
PsiElement(with_kw)('with')
PsiWhiteSpace(' ')
MvAbilityImpl(ABILITY)
PsiElement(IDENTIFIER)('store')
PsiWhiteSpace(' ')
PsiElement(+)('+')
PsiWhiteSpace(' ')
MvAbilityImpl(ABILITY)
PsiElement(IDENTIFIER)('drop')
PsiElement(;)(';')
PsiWhiteSpace('\n ')
MvExprStmtImpl(EXPR_STMT)
MvLambdaExprImpl(LAMBDA_EXPR)
MvLambdaParameterListImpl(LAMBDA_PARAMETER_LIST)
PsiElement(|)('|')
MvLambdaParameterImpl(LAMBDA_PARAMETER)
MvPatBindingImpl(PAT_BINDING)
PsiElement(IDENTIFIER)('a')
PsiElement(:)(':')
PsiWhiteSpace(' ')
MvPathTypeImpl(PATH_TYPE)
MvPathImpl(PATH)
PsiElement(IDENTIFIER)('u8')
PsiElement(|)('|')
PsiWhiteSpace(' ')
MvLitExprImpl(LIT_EXPR)
PsiElement(INTEGER_LITERAL)('1')
PsiWhiteSpace(' ')
MvWithAbilitiesImpl(WITH_ABILITIES)
PsiElement(with_kw)('with')
PsiWhiteSpace(' ')
MvAbilityImpl(ABILITY)
PsiElement(IDENTIFIER)('store')
PsiWhiteSpace(' ')
PsiElement(+)('+')
PsiWhiteSpace(' ')
MvAbilityImpl(ABILITY)
PsiElement(IDENTIFIER)('drop')
PsiElement(;)(';')
PsiWhiteSpace('\n ')
PsiElement(})('}')
PsiWhiteSpace('\n')
PsiElement(})('}')