X-Git-Url: http://g0dil.de/git?a=blobdiff_plain;f=Utils%2FConsole%2FParse.cc;h=28fa61a0c972cca392358c5c69bef80d52624375;hb=c45c112ae88196ea8da9c5a9efb0e167196744d2;hp=e4e1e660f415b3b1ed425d4a02e938e63107f661;hpb=0461eef93912cb9d454d726b4a7b4ccf50ed31bd;p=senf.git diff --git a/Utils/Console/Parse.cc b/Utils/Console/Parse.cc index e4e1e66..28fa61a 100644 --- a/Utils/Console/Parse.cc +++ b/Utils/Console/Parse.cc @@ -76,10 +76,10 @@ namespace detail { info_->builtin(ParseCommandInfo::BuiltinLS); setBuiltinPathArg(path); } - void pushDirectory(std::vector & path) - { info_->clear(); - info_->builtin(ParseCommandInfo::BuiltinPUSHD); - setBuiltinPathArg(path); } + void pushDirectory() + { // Do NOT call clear since pushDirectory is set in ADDITION + // to an ordinary command (which may be only a directory name) + info_->builtin(ParseCommandInfo::BuiltinPUSHD); } void popDirectory() { info_->clear(); @@ -96,11 +96,12 @@ namespace detail { void setBuiltinPathArg(std::vector & path) { - pushToken(ArgumentGroupOpenToken()); - for (std::vector::const_iterator i (path.begin()); - i != path.end(); ++i) - pushToken(*i); - pushToken(ArgumentGroupCloseToken()); + info_->command(path); +// pushToken(ArgumentGroupOpenToken()); +// for (std::vector::const_iterator i (path.begin()); +// i != path.end(); ++i) +// pushToken(*i); +// pushToken(ArgumentGroupCloseToken()); } }; @@ -111,6 +112,12 @@ namespace detail { /////////////////////////////////////////////////////////////////////////// // senf::console::Token +prefix_ senf::console::Token::Token(TokenType type, std::string token, + detail::FilePositionWithIndex const & pos) + : type_(type), token_ (token), line_ (pos.line), column_ (pos.column), index_ (pos.index) +{} + + prefix_ std::ostream & senf::console::operator<<(std::ostream & os, Token const & token) { static char const * tokenTypeName[] = { @@ -249,16 +256,46 @@ namespace { void throwParserError(Error const & err) { static char const * msg [] = { "end of statement expected", - "'{' or arguments expected", "path expected", "')' expected", "'\"' expected" }; - boost::spirit::file_position pos (err.where.get_position()); + senf::console::detail::FilePositionWithIndex pos (err.where.get_position()); throw senf::console::CommandParser::ParserErrorException(msg[err.descriptor]) << "\nat " << pos.file << ":" << pos.line << ":" << pos.column; } + } +namespace boost { +namespace spirit { + + template <> + struct position_policy + : public position_policy + { + typedef position_policy Base; + + void next_line(senf::console::detail::FilePositionWithIndex & pos) + { + Base::next_line(pos); + pos.index ++; + } + + void next_char(senf::console::detail::FilePositionWithIndex & pos) + { + Base::next_char(pos); + pos.index ++; + } + + void tabulation(senf::console::detail::FilePositionWithIndex & pos) + { + Base::tabulation(pos); + pos.index ++; + } + }; + +}} + prefix_ senf::console::CommandParser::CommandParser() : impl_ (new Impl()) {} @@ -273,7 +310,8 @@ template prefix_ Iterator senf::console::CommandParser::parseLoop(Iterator npb, Iterator npe, std::string const & source, Callback cb) { - typedef boost::spirit::position_iterator PositionIterator; + typedef boost::spirit::position_iterator< + Iterator, detail::FilePositionWithIndex> PositionIterator; PositionIterator b (npb, npe, source); PositionIterator e (npe, npe, source); ParseCommandInfo info; @@ -305,7 +343,7 @@ prefix_ Iterator senf::console::CommandParser::parseLoop(Iterator npb, Iterator cb(info); } catch (senf::ExceptionMixin & ex) { - boost::spirit::file_position pos (result.stop.get_position()); + detail::FilePositionWithIndex pos (result.stop.get_position()); ex << "\nat " << pos.file << ":" << pos.line << ":" << pos.column; throw; } @@ -329,7 +367,8 @@ prefix_ void senf::console::CommandParser::parseFile(std::string const & filenam prefix_ void senf::console::CommandParser::parseArguments(std::string const & arguments, ParseCommandInfo & info) { - typedef boost::spirit::position_iterator PositionIterator; + typedef boost::spirit::position_iterator< + std::string::const_iterator, detail::FilePositionWithIndex> PositionIterator; PositionIterator b (arguments.begin(), arguments.end(), std::string("")); PositionIterator e (arguments.end(), arguments.end(), std::string("")); detail::ParseDispatcher::BindInfo bind (impl().dispatcher, info); @@ -343,7 +382,7 @@ prefix_ void senf::console::CommandParser::parseArguments(std::string const & ar throwParserError(ex); } if (! result.full) { - boost::spirit::file_position pos (result.stop.get_position()); + detail::FilePositionWithIndex pos (result.stop.get_position()); throw ParserErrorException("argument expected") << "\nat " << pos.file << ":" << pos.line << ":" << pos.column; } @@ -352,7 +391,8 @@ prefix_ void senf::console::CommandParser::parseArguments(std::string const & ar prefix_ void senf::console::CommandParser::parsePath(std::string const & path, ParseCommandInfo & info) { - typedef boost::spirit::position_iterator PositionIterator; + typedef boost::spirit::position_iterator< + std::string::const_iterator, detail::FilePositionWithIndex> PositionIterator; PositionIterator b (path.begin(), path.end(), std::string("")); PositionIterator e (path.end(), path.end(), std::string("")); detail::ParseDispatcher::BindInfo bind (impl().dispatcher, info); @@ -366,7 +406,7 @@ prefix_ void senf::console::CommandParser::parsePath(std::string const & path, throwParserError(ex); } if (! result.full) { - boost::spirit::file_position pos (result.stop.get_position()); + detail::FilePositionWithIndex pos (result.stop.get_position()); throw ParserErrorException("path expected") << "\nat " << pos.file << ":" << pos.line << ":" << pos.column; } @@ -393,7 +433,35 @@ senf::console::CommandParser::parseIncremental(std::string const & commands, Cal parseLoop(commands.begin(), commands.end(), "", cb) ); } -///////////////////////////////cc.e//////////////////////////////////////// +/////////////////////////////////////////////////////////////////////////// +// Character sets + +prefix_ bool senf::console::CommandParser::isSpecialChar(char ch) +{ + return Impl::Grammar::special_p.test(ch); +} + +prefix_ bool senf::console::CommandParser::isPunctuationChar(char ch) +{ + return Impl::Grammar::punctuation_p.test(ch); +} + +prefix_ bool senf::console::CommandParser::isSpaceChar(char ch) +{ + return Impl::Grammar::space_p.test(ch); +} + +prefix_ bool senf::console::CommandParser::isInvalidChar(char ch) +{ + return Impl::Grammar::invalid_p.test(ch); +} + +prefix_ bool senf::console::CommandParser::isWordChar(char ch) +{ + return Impl::Grammar::word_p.test(ch); +} + +/////////////////////////////cc.e//////////////////////////////////////// #undef prefix_ //#include "Parse.mpp"