Skip to content
Extraits de code Groupes Projets
Vérifiée Valider 99de86a4 rédigé par Kubat's avatar Kubat
Parcourir les fichiers

SCRIPT: Parse a module declaration

parent 9c523380
Aucune branche associée trouvée
Aucune étiquette associée trouvée
1 requête de fusion!25Draft: New Vivy module spec
......@@ -3,6 +3,7 @@
#include "IrRoot.hh"
#include "IrFunction.hh"
#include "IrJob.hh"
#include "Lib/Script/FrontEnd/Lexer.hh"
/*
** Protected way of getting a thing from a vector if the inner elements
......@@ -144,8 +145,25 @@ IrModule::addJob(IrJob *obj)
}
void
IrModule::parse(std::vector<Token> *)
IrModule::parse(std::vector<Token> *tokens)
{
throw std::logic_error("Not implemented");
if (tokenListIsEmpty(tokens)) {
throw std::runtime_error("Can't parse an empty token list to build an "
"IrModule declaration statement");
}
if (tokens->size() != 3) {
Token firstToken = getInnerTokenOpt(tokenListPop(tokens));
throw std::runtime_error(
firstToken.location().toString() +
": Invalid syntax, to declare a module use `module mod-name;`, here you have " +
std::to_string(tokens->size()) + " tokens!");
}
getInnerTokenOpt(tokenListPop(tokens)).assertTypeSimple(TOKEN_MODULE);
Token nameToken = getInnerTokenOpt(tokenListPop(tokens));
nameToken.assertType(Token::Type::QNAME);
moduleName = nameToken.asQName();
getInnerTokenOpt(tokenListPop(tokens)).assertTypeSimple(TOKEN_SEMICOL);
}
}
......@@ -67,12 +67,6 @@ while (tokenListIsNotEmpty(tokens)) {
}
std::vector<Token> tokensToNextSemiCol =
tokenListPopToNextSimpleToken(tokens, TOKEN_SEMICOL);
if (tokensToNextSemiCol.size() != 3) {
throw std::runtime_error(
firstToken.location().toString() +
": Invalid syntax, to declare a module use `module mod-name;`, here you have " +
std::to_string(tokensToNextSemiCol.size()) + " tokens!");
}
mainVivyModule = IrElement::create<IrModule>(this, &tokensToNextSemiCol);
addModule(mainVivyModule);
createdElement = mainVivyModule;
......
0% Chargement en cours ou .
You are about to add 0 people to the discussion. Proceed with caution.
Veuillez vous inscrire ou vous pour commenter