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

PARSER: Parse correctly IrAttribute

parent 2fa4c782
Aucune branche associée trouvée
Aucune étiquette associée trouvée
1 requête de fusion!25Draft: New Vivy module spec
......@@ -37,12 +37,20 @@ IrAttribute::parse(std::vector<Token> *tokens)
nameToken.assertType(Token::Type::QNAME);
StrV name = nameToken.asQName();
auto getValueAndAddAttribute = [this, name, tokens]() -> void {
auto getValueAndAddAttribute = [this, name, tokens](const bool simple) -> void {
Token valueToken = getInnerTokenOpt(tokenListPop(tokens));
if (!valueToken.isQName()) {
throw std::runtime_error("Simple attribute detected (of the form `#(name: value)`), "
if (simple) {
throw std::runtime_error(
"Simple attribute detected (of the form `#(name: value)`), "
"but found unexpected value token: " +
valueToken.toString());
} else {
throw std::runtime_error(
"List attribute detected (of the form `#(name: [value, value, value])`), "
"but found unexpected value token: " +
valueToken.toString());
}
}
parentAttributes.push_back(std::make_pair(name, valueToken.asQName()));
};
......@@ -52,7 +60,8 @@ IrAttribute::parse(std::vector<Token> *tokens)
/* Attributes can be a list: `#(name: [ v1, v2 ])` */
if (getInnerTokenOpt(tokenListPeek(tokens)).isSimple(TOKEN_BRACKET_LEFT)) {
do {
getValueAndAddAttribute();
tokenListPop(tokens); /* Pop [ or , */
getValueAndAddAttribute(false);
} while (getInnerTokenOpt(tokenListPeek(tokens)).isSimple(TOKEN_COMMA));
getInnerTokenOpt(tokenListPop(tokens)).assertTypeSimple(TOKEN_BRACKET_RIGHT);
getInnerTokenOpt(tokenListPop(tokens)).assertTypeSimple(TOKEN_PARENT_RIGHT);
......@@ -60,7 +69,7 @@ IrAttribute::parse(std::vector<Token> *tokens)
/* Attribute can be simple elements: `#(name: value)` */
else {
getValueAndAddAttribute();
getValueAndAddAttribute(true);
getInnerTokenOpt(tokenListPop(tokens)).assertTypeSimple(TOKEN_PARENT_RIGHT);
}
}
......
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