add list parsing
Change-Id: Id4be03cedd687892b6f4ae45d90afee8e2a4a43c
diff --git a/src/CParser.cpp b/src/CParser.cpp
index 618a721..0762468 100644
--- a/src/CParser.cpp
+++ b/src/CParser.cpp
@@ -5,10 +5,13 @@
* Written by Václav Kubernát <kubervac@fit.cvut.cz>
*
*/
+#include <iostream>
#include "CParser.hpp"
TooManyArgumentsException::~TooManyArgumentsException() = default;
+InvalidCommandException::~InvalidCommandException() = default;
+
CParser::CParser(const CTree& tree)
: m_tree(tree)
{
@@ -21,13 +24,16 @@
ParserContext ctx(m_tree);
auto it = line.begin();
- auto grammar = x3::with<parser_context_tag>(ctx)[cd];
+ boost::spirit::x3::error_handler<std::string::const_iterator> errorHandler(it, line.end(), std::cerr);
+ auto grammar =
+ x3::with<parser_context_tag>(ctx)[
+ x3::with<x3::error_handler_tag>(std::ref(errorHandler))[cd]
+ ];
+ bool result = x3::phrase_parse(it, line.end(), grammar, space, parsedCommand);
- x3::phrase_parse(it, line.end(), grammar, space, parsedCommand);
- if (it != line.end()) {
- throw TooManyArgumentsException(std::string(it, line.end()));
+ if (!result || it != line.end()) {
+ throw InvalidCommandException(std::string(it, line.end()) + " this was left of input");
}
-
return parsedCommand;
}