mirror of
https://github.com/beefytech/Beef.git
synced 2025-06-08 19:48:20 +02:00
Better string interpolation expr parsing
This commit is contained in:
parent
fef4274fb8
commit
2ad5d7fac1
2 changed files with 31 additions and 2 deletions
|
@ -3355,6 +3355,7 @@ void BfParser::ParseBlock(BfBlock* astNode, int depth, bool isInterpolate)
|
||||||
int startParseBlockIdx = gParseBlockIdx;
|
int startParseBlockIdx = gParseBlockIdx;
|
||||||
|
|
||||||
bool isAsmBlock = false;
|
bool isAsmBlock = false;
|
||||||
|
bool isTernary = false;
|
||||||
|
|
||||||
SizedArray<BfAstNode*, 32> childArr;
|
SizedArray<BfAstNode*, 32> childArr;
|
||||||
|
|
||||||
|
@ -3453,7 +3454,34 @@ void BfParser::ParseBlock(BfBlock* astNode, int depth, bool isInterpolate)
|
||||||
|
|
||||||
if ((isInterpolate) && (parenDepth == 0))
|
if ((isInterpolate) && (parenDepth == 0))
|
||||||
{
|
{
|
||||||
if ((mToken == BfToken_Colon) || (mToken == BfToken_Comma))
|
if (mToken == BfToken_Question)
|
||||||
|
isTernary = true;
|
||||||
|
|
||||||
|
bool endNow = false;
|
||||||
|
if (mToken == BfToken_Colon)
|
||||||
|
{
|
||||||
|
endNow = true;
|
||||||
|
if (!childArr.IsEmpty())
|
||||||
|
{
|
||||||
|
if (auto prevToken = BfNodeDynCast<BfTokenNode>(childArr.back()))
|
||||||
|
{
|
||||||
|
if ((prevToken->mToken == BfToken_Scope) || (prevToken->mToken == BfToken_New) || (prevToken->mToken == BfToken_Bang) ||
|
||||||
|
(prevToken->mToken == BfToken_Colon))
|
||||||
|
endNow = false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if ((endNow) && (isTernary))
|
||||||
|
{
|
||||||
|
isTernary = false;
|
||||||
|
endNow = false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (mToken == BfToken_Comma)
|
||||||
|
endNow = true;
|
||||||
|
|
||||||
|
if (endNow)
|
||||||
{
|
{
|
||||||
mSrcIdx = mTokenStart;
|
mSrcIdx = mTokenStart;
|
||||||
break;
|
break;
|
||||||
|
@ -3461,7 +3489,7 @@ void BfParser::ParseBlock(BfBlock* astNode, int depth, bool isInterpolate)
|
||||||
}
|
}
|
||||||
|
|
||||||
astNode->Add(childNode);
|
astNode->Add(childNode);
|
||||||
childArr.push_back(childNode);
|
childArr.Add(childNode);
|
||||||
|
|
||||||
if ((mSyntaxToken == BfSyntaxToken_Token) && (mToken == BfToken_RBrace))
|
if ((mSyntaxToken == BfSyntaxToken_Token) && (mToken == BfToken_RBrace))
|
||||||
break;
|
break;
|
||||||
|
|
|
@ -406,6 +406,7 @@ void BfSourceClassifier::Visit(BfStringInterpolationExpression* stringInterpolat
|
||||||
VisitChild(stringInterpolationExpression->mAllocNode);
|
VisitChild(stringInterpolationExpression->mAllocNode);
|
||||||
for (auto& expr : stringInterpolationExpression->mExpressions)
|
for (auto& expr : stringInterpolationExpression->mExpressions)
|
||||||
{
|
{
|
||||||
|
SetElementType(expr, BfSourceElementType_Normal);
|
||||||
VisitChild(expr);
|
VisitChild(expr);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue