Skip to content
Extraits de code Groupes Projets
Sélectionner une révision Git
  • 0c4265d1566d74cfc8f4f36305845d1ea85d7d41
  • master par défaut protégée
  • develop
  • feature/demande
  • feature/user_infos
  • feature/connexion
  • feature/match
  • feature/modif_info
  • feature/accueil
  • feature/modifier_mdp
10 résultats

header.php

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);
        }
    }
    }