diff --git a/src/Lib/Script/Ast/IrAttribute.cc b/src/Lib/Script/Ast/IrAttribute.cc index eee7967ad38ba734cd12159e6f3c200832c7fc5d..40c26dbd08c5844983718d01baca746d91409e66 100644 --- a/src/Lib/Script/Ast/IrAttribute.cc +++ b/src/Lib/Script/Ast/IrAttribute.cc @@ -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)`), " - "but found unexpected value token: " + - valueToken.toString()); + 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); } }