blob: 618a721bb1e4915a8c2163c17fb55bffab5bb853 [file] [log] [blame]
Václav Kubernátd6662962018-03-22 17:41:33 +01001/*
2 * Copyright (C) 2018 CESNET, https://photonics.cesnet.cz/
3 * Copyright (C) 2018 FIT CVUT, https://fit.cvut.cz/
4 *
5 * Written by Václav Kubernát <kubervac@fit.cvut.cz>
6 *
7*/
Václav Kubernát624a8872018-03-02 17:28:47 +01008#include "CParser.hpp"
9
10TooManyArgumentsException::~TooManyArgumentsException() = default;
11
12CParser::CParser(const CTree& tree)
13 : m_tree(tree)
14{
15}
16
17
Václav Kubernátd6662962018-03-22 17:41:33 +010018cd_ CParser::parseCommand(const std::string& line)
Václav Kubernát624a8872018-03-02 17:28:47 +010019{
Václav Kubernátd6662962018-03-22 17:41:33 +010020 cd_ parsedCommand;
21 ParserContext ctx(m_tree);
Václav Kubernát624a8872018-03-02 17:28:47 +010022 auto it = line.begin();
Václav Kubernátd6662962018-03-22 17:41:33 +010023
24 auto grammar = x3::with<parser_context_tag>(ctx)[cd];
25
26 x3::phrase_parse(it, line.end(), grammar, space, parsedCommand);
Václav Kubernát624a8872018-03-02 17:28:47 +010027 if (it != line.end()) {
28 throw TooManyArgumentsException(std::string(it, line.end()));
29 }
30
31
Václav Kubernátd6662962018-03-22 17:41:33 +010032 return parsedCommand;
Václav Kubernát624a8872018-03-02 17:28:47 +010033}