Some enhancements in the parser
- Fix MemberExpression and IfStatementPart not receiving annotations - Enable parsing of elif-statements - Refactor some code
This commit is contained in:
parent
2be3deb5f6
commit
a3f40d51ef
2 changed files with 42 additions and 36 deletions
|
@ -67,7 +67,7 @@ namespace bolt {
|
|||
|
||||
OperatorTable ExprOperators;
|
||||
|
||||
Token* peekFirstTokenAfterModifiers();
|
||||
Token* peekFirstTokenAfterAnnotationsAndModifiers();
|
||||
|
||||
Token* expectToken(NodeKind Ty);
|
||||
|
||||
|
|
|
@ -78,7 +78,7 @@ namespace bolt {
|
|||
ExprOperators.add("$", OperatorFlags_InfixR, 0);
|
||||
}
|
||||
|
||||
Token* Parser::peekFirstTokenAfterModifiers() {
|
||||
Token* Parser::peekFirstTokenAfterAnnotationsAndModifiers() {
|
||||
std::size_t I = 0;
|
||||
for (;;) {
|
||||
auto T0 = Tokens.peek(I++);
|
||||
|
@ -737,11 +737,14 @@ after_tuple_elements:
|
|||
switch (T2->getKind()) {
|
||||
case NodeKind::IntegerLiteral:
|
||||
case NodeKind::Identifier:
|
||||
{
|
||||
Tokens.get();
|
||||
Tokens.get();
|
||||
E = new MemberExpression { E->Annotations, E, static_cast<Dot*>(T1), T2 };
|
||||
E->Annotations.clear();
|
||||
auto Annotations = E->Annotations;
|
||||
E->Annotations = {};
|
||||
E = new MemberExpression { Annotations, E, static_cast<Dot*>(T1), T2 };
|
||||
break;
|
||||
}
|
||||
default:
|
||||
goto finish;
|
||||
}
|
||||
|
@ -780,7 +783,7 @@ finish:
|
|||
return Operator;
|
||||
}
|
||||
auto Annotations = Operator->Annotations;
|
||||
Operator->Annotations.clear();
|
||||
Operator->Annotations = {};
|
||||
return new CallExpression(Annotations, Operator, Args);
|
||||
}
|
||||
|
||||
|
@ -884,6 +887,7 @@ finish:
|
|||
|
||||
IfStatement* Parser::parseIfStatement() {
|
||||
std::vector<IfStatementPart*> Parts;
|
||||
auto Annotations = parseAnnotations();
|
||||
auto IfKeyword = expectToken<class IfKeyword>();
|
||||
auto Test = parseExpression();
|
||||
if (!Test) {
|
||||
|
@ -911,10 +915,13 @@ finish:
|
|||
}
|
||||
}
|
||||
Tokens.get()->unref(); // Always a LineFoldEnd
|
||||
Parts.push_back(new IfStatementPart(IfKeyword, Test, T1, Then));
|
||||
Parts.push_back(new IfStatementPart(Annotations, IfKeyword, Test, T1, Then));
|
||||
for (;;) {
|
||||
auto T3 = Tokens.peek();
|
||||
if (T3->getKind() == NodeKind::ElseKeyword || T3->getKind() == NodeKind::ElifKeyword) {
|
||||
auto T3 = peekFirstTokenAfterAnnotationsAndModifiers();
|
||||
if (T3->getKind() != NodeKind::ElseKeyword && T3->getKind() != NodeKind::ElifKeyword) {
|
||||
break;
|
||||
}
|
||||
auto Annotations = parseAnnotations();
|
||||
Tokens.get();
|
||||
Expression* Test = nullptr;
|
||||
if (T3->getKind() == NodeKind::ElifKeyword) {
|
||||
|
@ -940,12 +947,11 @@ finish:
|
|||
}
|
||||
}
|
||||
Tokens.get()->unref(); // Always a LineFoldEnd
|
||||
Parts.push_back(new IfStatementPart(T3, Test, T4, Alt));
|
||||
Parts.push_back(new IfStatementPart(Annotations, T3, Test, T4, Alt));
|
||||
if (T3->getKind() == NodeKind::ElseKeyword) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
return new IfStatement(Parts);
|
||||
}
|
||||
|
||||
|
@ -1097,7 +1103,7 @@ finish:
|
|||
}
|
||||
|
||||
Node* Parser::parseLetBodyElement() {
|
||||
auto T0 = peekFirstTokenAfterModifiers();
|
||||
auto T0 = peekFirstTokenAfterAnnotationsAndModifiers();
|
||||
switch (T0->getKind()) {
|
||||
case NodeKind::LetKeyword:
|
||||
return parseLetDeclaration();
|
||||
|
@ -1516,7 +1522,7 @@ next_member:
|
|||
}
|
||||
|
||||
Node* Parser::parseSourceElement() {
|
||||
auto T0 = peekFirstTokenAfterModifiers();
|
||||
auto T0 = peekFirstTokenAfterAnnotationsAndModifiers();
|
||||
switch (T0->getKind()) {
|
||||
case NodeKind::LetKeyword:
|
||||
return parseLetDeclaration();
|
||||
|
|
Loading…
Reference in a new issue