From 6ea1184a522207820d45c420fc89790203fef57c Mon Sep 17 00:00:00 2001 From: Maksim Kurnikov Date: Fri, 7 Feb 2025 17:52:42 +0100 Subject: [PATCH] with abilities in lambda expr and type --- src/main/grammars/MoveParser.bnf | 13 ++- .../move/lang/parser/CompleteParsingTest.kt | 1 + .../lang/parser/complete/new_lambdas.move | 6 ++ .../move/lang/parser/complete/new_lambdas.txt | 85 +++++++++++++++++++ 4 files changed, 103 insertions(+), 2 deletions(-) create mode 100644 src/test/resources/org/move/lang/parser/complete/new_lambdas.move create mode 100644 src/test/resources/org/move/lang/parser/complete/new_lambdas.txt diff --git a/src/main/grammars/MoveParser.bnf b/src/main/grammars/MoveParser.bnf index 09079509..9cd4199d 100644 --- a/src/main/grammars/MoveParser.bnf +++ b/src/main/grammars/MoveParser.bnf @@ -676,7 +676,7 @@ PathType ::= PathImpl TupleType ::= '(' Type ',' (Type ','?)* ')' { pin = 3 } -LambdaType ::= '|' !',' <>? '|' Type? +LambdaType ::= '|' !',' <>? '|' Type? WithAbilities? LambdaTypeParam ::= Type TypeParameterList ::= '<' TypeParameter_with_recover* '>' @@ -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 ::= '|' !',' <>? '|' LambdaParameter ::= PatBinding TypeAscription? diff --git a/src/test/kotlin/org/move/lang/parser/CompleteParsingTest.kt b/src/test/kotlin/org/move/lang/parser/CompleteParsingTest.kt index 2534387d..fdf50203 100644 --- a/src/test/kotlin/org/move/lang/parser/CompleteParsingTest.kt +++ b/src/test/kotlin/org/move/lang/parser/CompleteParsingTest.kt @@ -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) diff --git a/src/test/resources/org/move/lang/parser/complete/new_lambdas.move b/src/test/resources/org/move/lang/parser/complete/new_lambdas.move new file mode 100644 index 00000000..20a628d5 --- /dev/null +++ b/src/test/resources/org/move/lang/parser/complete/new_lambdas.move @@ -0,0 +1,6 @@ +module 0x1::new_lambdas { + fun main() { + let a: |u8| u8 with store + drop; + |a: u8| 1 with store + drop; + } +} diff --git a/src/test/resources/org/move/lang/parser/complete/new_lambdas.txt b/src/test/resources/org/move/lang/parser/complete/new_lambdas.txt new file mode 100644 index 00000000..7d93d9a7 --- /dev/null +++ b/src/test/resources/org/move/lang/parser/complete/new_lambdas.txt @@ -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(})('}') \ No newline at end of file