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