Extend using-for.

This commit is contained in:
hrkrshnn
2022-03-14 12:33:44 +01:00
committed by chriseth
parent db30f4d495
commit 672951ccc7
55 changed files with 992 additions and 150 deletions
+20 -2
View File
@@ -117,6 +117,9 @@ ASTPointer<SourceUnit> Parser::parse(CharStream& _charStream)
case Token::Type:
nodes.push_back(parseUserDefinedValueTypeDefinition());
break;
case Token::Using:
nodes.push_back(parseUsingDirective());
break;
case Token::Function:
nodes.push_back(parseFunctionDefinition(true));
break;
@@ -962,7 +965,22 @@ ASTPointer<UsingForDirective> Parser::parseUsingDirective()
ASTNodeFactory nodeFactory(*this);
expectToken(Token::Using);
ASTPointer<IdentifierPath> library(parseIdentifierPath());
vector<ASTPointer<IdentifierPath>> functions;
bool const usesBraces = m_scanner->currentToken() == Token::LBrace;
if (usesBraces)
{
do
{
advance();
functions.emplace_back(parseIdentifierPath());
}
while (m_scanner->currentToken() == Token::Comma);
expectToken(Token::RBrace);
}
else
functions.emplace_back(parseIdentifierPath());
ASTPointer<TypeName> typeName;
expectToken(Token::For);
if (m_scanner->currentToken() == Token::Mul)
@@ -971,7 +989,7 @@ ASTPointer<UsingForDirective> Parser::parseUsingDirective()
typeName = parseTypeName();
nodeFactory.markEndPosition();
expectToken(Token::Semicolon);
return nodeFactory.createNode<UsingForDirective>(library, typeName);
return nodeFactory.createNode<UsingForDirective>(move(functions), usesBraces, typeName);
}
ASTPointer<ModifierInvocation> Parser::parseModifierInvocation()