Initial Parser Implementation and Feature Completion #1
@ -632,16 +632,52 @@ namespace arti::lang {
|
|||||||
node = std::move(newNode);
|
node = std::move(newNode);
|
||||||
}
|
}
|
||||||
else if (op == ast::PostfixOperator::SliceAccess) {
|
else if (op == ast::PostfixOperator::SliceAccess) {
|
||||||
auto idx = parseExpression();
|
bool isSlice = false;
|
||||||
|
bool skipSliceEnd = false;
|
||||||
|
bool skipSliceStart = false;
|
||||||
|
|
||||||
if (! idx) {
|
if (auto skipLeft = matchAndConsume(TokenV::opColon); ! skipLeft) {
|
||||||
return Unexpected<>{ std::move(idx).error() };
|
return Unexpected<>{ std::move(skipLeft).error() };
|
||||||
|
}
|
||||||
|
else if (skipLeft.value()) {
|
||||||
|
isSlice = true;
|
||||||
|
skipSliceStart = true;
|
||||||
|
|
||||||
|
if (auto close = matchAndConsume(TokenV::opRBracket); ! close) {
|
||||||
|
return Unexpected<>{ std::move(close).error() };
|
||||||
|
}
|
||||||
|
else if (close.value()) {
|
||||||
|
skipSliceEnd = true;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (auto range = matchAndConsume(TokenV::opColon); ! range) {
|
auto idxExpr = ast::Optional<ast::ExpressionNode>{};
|
||||||
return Unexpected<>{ std::move(range).error() };
|
|
||||||
|
if (! skipSliceStart) {
|
||||||
|
auto idx = parseExpression();
|
||||||
|
|
||||||
|
if (! idx) {
|
||||||
|
return Unexpected<>{ std::move(idx).error() };
|
||||||
|
}
|
||||||
|
|
||||||
|
if (auto range = matchAndConsume(TokenV::opColon); ! range) {
|
||||||
|
return Unexpected<>{ std::move(range).error() };
|
||||||
|
}
|
||||||
|
else if (range.value()) {
|
||||||
|
isSlice = true;
|
||||||
|
|
||||||
|
if (auto close = matchAndConsume(TokenV::opRBracket); ! close) {
|
||||||
|
return Unexpected<>{ std::move(close).error() };
|
||||||
|
}
|
||||||
|
else if (close.value()) {
|
||||||
|
skipSliceEnd = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
idxExpr = std::move(idx).value();
|
||||||
}
|
}
|
||||||
else if (range.value()) {
|
|
||||||
|
if (isSlice) {
|
||||||
auto newNode = ast::MakeNode<ast::SliceRangeExprNode>();
|
auto newNode = ast::MakeNode<ast::SliceRangeExprNode>();
|
||||||
|
|
||||||
newNode->location = {
|
newNode->location = {
|
||||||
@ -649,18 +685,22 @@ namespace arti::lang {
|
|||||||
.column = peekToken->column
|
.column = peekToken->column
|
||||||
};
|
};
|
||||||
|
|
||||||
newNode->start = std::move(idx).value();
|
if (! skipSliceStart) {
|
||||||
|
newNode->start = std::move(idxExpr).value();
|
||||||
auto endIdx = parseExpression();
|
|
||||||
|
|
||||||
if (! endIdx) {
|
|
||||||
return Unexpected<>{ std::move(endIdx).error() };
|
|
||||||
}
|
}
|
||||||
|
|
||||||
newNode->end = std::move(endIdx).value();
|
if (! skipSliceEnd) {
|
||||||
|
auto endIdx = parseExpression();
|
||||||
|
|
||||||
if (auto close = consume(TokenV::opRBracket, "']'"); ! close) {
|
if (! endIdx) {
|
||||||
return Unexpected<>{ std::move(close).error() };
|
return Unexpected<>{ std::move(endIdx).error() };
|
||||||
|
}
|
||||||
|
|
||||||
|
newNode->end = std::move(endIdx).value();
|
||||||
|
|
||||||
|
if (auto close = consume(TokenV::opRBracket, "']'"); ! close) {
|
||||||
|
return Unexpected<>{ std::move(close).error() };
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
newNode->slice = std::move(lhs);
|
newNode->slice = std::move(lhs);
|
||||||
@ -675,7 +715,7 @@ namespace arti::lang {
|
|||||||
.column = peekToken->column
|
.column = peekToken->column
|
||||||
};
|
};
|
||||||
|
|
||||||
newNode->index = std::move(idx).value();
|
newNode->index = std::move(idxExpr).value();
|
||||||
|
|
||||||
if (auto close = consume(TokenV::opRBracket, "']'"); ! close) {
|
if (auto close = consume(TokenV::opRBracket, "']'"); ! close) {
|
||||||
return Unexpected<>{ std::move(close).error() };
|
return Unexpected<>{ std::move(close).error() };
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user