Václav Kubernát | d666296 | 2018-03-22 17:41:33 +0100 | [diff] [blame^] | 1 | /* |
| 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át | 624a887 | 2018-03-02 17:28:47 +0100 | [diff] [blame] | 8 | #include "CParser.hpp" |
| 9 | |
| 10 | TooManyArgumentsException::~TooManyArgumentsException() = default; |
| 11 | |
| 12 | CParser::CParser(const CTree& tree) |
| 13 | : m_tree(tree) |
| 14 | { |
| 15 | } |
| 16 | |
| 17 | |
Václav Kubernát | d666296 | 2018-03-22 17:41:33 +0100 | [diff] [blame^] | 18 | cd_ CParser::parseCommand(const std::string& line) |
Václav Kubernát | 624a887 | 2018-03-02 17:28:47 +0100 | [diff] [blame] | 19 | { |
Václav Kubernát | d666296 | 2018-03-22 17:41:33 +0100 | [diff] [blame^] | 20 | cd_ parsedCommand; |
| 21 | ParserContext ctx(m_tree); |
Václav Kubernát | 624a887 | 2018-03-02 17:28:47 +0100 | [diff] [blame] | 22 | auto it = line.begin(); |
Václav Kubernát | d666296 | 2018-03-22 17:41:33 +0100 | [diff] [blame^] | 23 | |
| 24 | auto grammar = x3::with<parser_context_tag>(ctx)[cd]; |
| 25 | |
| 26 | x3::phrase_parse(it, line.end(), grammar, space, parsedCommand); |
Václav Kubernát | 624a887 | 2018-03-02 17:28:47 +0100 | [diff] [blame] | 27 | if (it != line.end()) { |
| 28 | throw TooManyArgumentsException(std::string(it, line.end())); |
| 29 | } |
| 30 | |
| 31 | |
Václav Kubernát | d666296 | 2018-03-22 17:41:33 +0100 | [diff] [blame^] | 32 | return parsedCommand; |
Václav Kubernát | 624a887 | 2018-03-02 17:28:47 +0100 | [diff] [blame] | 33 | } |