From 3887b9387d98f5394dc8b45f6f42e4a541ea4828 Mon Sep 17 00:00:00 2001 From: Roy Qu Date: Tue, 23 Apr 2024 13:05:54 +0800 Subject: [PATCH] enhancement: Support lambda expression without a parameter list. --- RedPandaIDE/parser/cppparser.cpp | 21 +++++++++++++-------- 1 file changed, 13 insertions(+), 8 deletions(-) diff --git a/RedPandaIDE/parser/cppparser.cpp b/RedPandaIDE/parser/cppparser.cpp index 5271747f..e05d7b1b 100644 --- a/RedPandaIDE/parser/cppparser.cpp +++ b/RedPandaIDE/parser/cppparser.cpp @@ -2905,14 +2905,18 @@ void CppParser::handleLambda(int index, int maxIndex) QSet captures = parseLambdaCaptures(index); int startLine=mTokenizer[index]->line; int argStart=index+1; - if (mTokenizer[argStart]->text!='(') + int argEnd, bodyStart; + if (mTokenizer[argStart]->text == '(' ) { + argEnd = mTokenizer[argStart]->matchIndex; + bodyStart=indexOfNextLeftBrace(argEnd+1, maxIndex); + if (bodyStart>=maxIndex) { + return; + } + } else if (mTokenizer[argStart]->text == '{') { + argEnd = argStart; + bodyStart = argStart; + } else return; - int argEnd= mTokenizer[argStart]->matchIndex; - //TODO: parse captures - int bodyStart=indexOfNextLeftBrace(argEnd+1, maxIndex); - if (bodyStart>=maxIndex) { - return; - } int bodyEnd = mTokenizer[bodyStart]->matchIndex; if (bodyEnd>maxIndex) { return; @@ -2931,7 +2935,8 @@ void CppParser::handleLambda(int index, int maxIndex) StatementAccessibility::None, StatementProperty::HasDefinition); lambdaBlock->lambdaCaptures = captures; - scanMethodArgs(lambdaBlock,argStart); + if (argEnd > argStart) + scanMethodArgs(lambdaBlock,argStart); addSoloScopeLevel(lambdaBlock,mTokenizer[bodyStart]->line); int oldIndex = mIndex; mIndex = bodyStart+1;