Skip to content
Extraits de code Groupes Projets
Sélectionner une révision Git
  • f8e9aa493a19c0da0ce2e00d29cb3918636dc06b
  • develop par défaut protégée
  • upgrade-appservice
  • baguette-custom-fixes
  • fix-discord-reply-edited
  • update-readme-badges
6 résultats

test_matrixroomhandler.ts

Blame
  • IrAttribute.cc 2,51 Kio
    #include "IrAttribute.hh"
    #include "Lib/Script/FrontEnd/Lexer.hh"
    
    namespace Vivy::Script
    {
    std::vector<StrV>
    IrAttribute::attribute(const std::string &name) const noexcept
    {
        return attribute(StrV::fromStr(name.c_str()));
    }
    
    std::vector<StrV>
    IrAttribute::attribute(StrV askedName) const noexcept
    {
        std::vector<StrV> ret;
        ret.reserve(maxObservedItemsPerName);
        for (const auto &[name, value] : parentAttributes) {
            if (StrV::equal(name, askedName))
                ret.push_back(value);
        }
        return ret;
    }
    
    std::string
    IrAttribute::toString() const noexcept
    {
        return "IrAttribute";
    }
    
    void
    IrAttribute::parse(std::vector<Token> *tokens)
    {
        getInnerTokenOpt(tokenListPop(tokens)).assertTypeSimple(TOKEN_HASHTAG);
        getInnerTokenOpt(tokenListPop(tokens)).assertTypeSimple(TOKEN_PARENT_LEFT);
    
        Token nameToken = getInnerTokenOpt(tokenListPop(tokens));
        nameToken.assertType(Token::Type::QNAME);
        StrV name = nameToken.asQName();
    
        auto getValueAndAddAttribute = [this, name, tokens](const bool simple) -> void {
            Token valueToken = getInnerTokenOpt(tokenListPop(tokens));
            if (!valueToken.isQName()) {
                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()));
        };
    
        getInnerTokenOpt(tokenListPop(tokens)).assertTypeSimple(TOKEN_COL);
    
        /* Attributes can be a list: `#(name: [ v1, v2 ])` */
        if (getInnerTokenOpt(tokenListPeek(tokens)).isSimple(TOKEN_BRACKET_LEFT)) {
            do {
                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);
        }
    
        /* Attribute can be simple elements: `#(name: value)` */
        else {
            getValueAndAddAttribute(true);
            getInnerTokenOpt(tokenListPop(tokens)).assertTypeSimple(TOKEN_PARENT_RIGHT);
        }
    }
    }