X-Git-Url: http://g0dil.de/git?a=blobdiff_plain;f=Console%2FParse.cc;h=c06a2bc9b9f42a9b0f1cd47844dc765e5c2f27bf;hb=bf1d8ba5ce6fc6a169a938183f8d01c8bdbccf32;hp=f143149c6d624ec86febecf0a10124d304a38aac;hpb=d620e7ff9b68377ea20ca266c23cc3f05781868c;p=senf.git diff --git a/Console/Parse.cc b/Console/Parse.cc index f143149..c06a2bc 100644 --- a/Console/Parse.cc +++ b/Console/Parse.cc @@ -27,8 +27,11 @@ #include "Parse.ih" // Custom includes -#include "../Utils/String.hh" +#include #include +#include +#include "../Utils/String.hh" +#include "../Utils/Exception.hh" //#include "Parse.mpp" #define prefix_ @@ -38,6 +41,8 @@ namespace senf { namespace console { namespace detail { +#ifndef DOXYGEN + struct ParserAccess { static void init(ParseCommandInfo & info) @@ -130,6 +135,12 @@ namespace detail { ParserAccess::setBuiltin(info_, ParseCommandInfo::BuiltinEXIT); ParserAccess::finalize(info_); cb_(info_); } + void builtin_help(std::vector & path) + { ParserAccess::init(info_); + ParserAccess::setBuiltin(info_, ParseCommandInfo::BuiltinHELP); + setBuiltinPathArg(path); + ParserAccess::finalize(info_); cb_(info_); } + void setBuiltinPathArg(std::vector & path) { ParserAccess::startArgument(info_); @@ -140,11 +151,15 @@ namespace detail { } }; +#endif + }}} /////////////////////////////////////////////////////////////////////////// // senf::console::ParseCommandInfo +#ifndef DOXYGEN + struct senf::console::ParseCommandInfo::MakeRange { typedef ParseCommandInfo::argument_value_type result_type; @@ -159,6 +174,8 @@ struct senf::console::ParseCommandInfo::MakeRange } }; +#endif + prefix_ void senf::console::ParseCommandInfo::finalize() { arguments_.resize( tempArguments_.size() ); @@ -178,7 +195,7 @@ prefix_ std::ostream & senf::console::operator<<(std::ostream & stream, if (info.builtin() == ParseCommandInfo::NoBuiltin) stream << senf::stringJoin(info.commandPath(), "/"); else { - char const * builtins[] = { "", "cd", "ls", "pushd", "popd", "exit" }; + char const * builtins[] = { "", "cd", "ls", "pushd", "popd", "exit", "help" }; stream << "builtin-" << builtins[info.builtin()]; } @@ -202,6 +219,8 @@ prefix_ std::ostream & senf::console::operator<<(std::ostream & stream, /////////////////////////////////////////////////////////////////////////// // senf::console::CommandParser +#ifndef DOXYGEN + struct senf::console::CommandParser::Impl { typedef detail::CommandGrammar Grammar; @@ -213,6 +232,8 @@ struct senf::console::CommandParser::Impl Impl() : dispatcher(), context(), grammar(dispatcher, context) {} }; +#endif + prefix_ senf::console::CommandParser::CommandParser() : impl_ (new Impl()) {} @@ -223,8 +244,20 @@ prefix_ senf::console::CommandParser::~CommandParser() prefix_ bool senf::console::CommandParser::parse(std::string command, Callback cb) { detail::ParseDispatcher::BindInfo bind (impl().dispatcher, cb); -# warning don't use c_str() in parse and add istream parser. Implement error checking in parser. - return boost::spirit::parse( command.c_str(), + return boost::spirit::parse( command.begin(), command.end(), + impl().grammar.use_parser(), + impl().grammar.use_parser() + ).full; +} + +prefix_ bool senf::console::CommandParser::parseFile(std::string filename, Callback cb) +{ + detail::ParseDispatcher::BindInfo bind (impl().dispatcher, cb); + boost::spirit::file_iterator<> i (filename); + if (!i) throw SystemException(ENOENT SENF_EXC_DEBUGINFO); + boost::spirit::file_iterator<> const i_end (i.make_end()); + + return boost::spirit::parse( i, i_end, impl().grammar.use_parser(), impl().grammar.use_parser() ).full;