From 64a33a1ecda0430610dc20d9798d9238547c59e7 Mon Sep 17 00:00:00 2001 From: Kubat <mael.martin31@gmail.com> Date: Thu, 10 Feb 2022 21:38:45 +0100 Subject: [PATCH] PARSER: Parse correctly IrAttribute --- src/Lib/Script/Ast/IrAttribute.cc | 21 +++++++++++++++------ 1 file changed, 15 insertions(+), 6 deletions(-) diff --git a/src/Lib/Script/Ast/IrAttribute.cc b/src/Lib/Script/Ast/IrAttribute.cc index eee7967a..40c26dbd 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); } } -- GitLab