///////////////////////////////////////////////////////////////////////////
// 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[] = {
"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<senf::console::detail::FilePositionWithIndex>
+ : public position_policy<file_position>
+ {
+ typedef position_policy<file_position> 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())
{}
prefix_ Iterator senf::console::CommandParser::parseLoop(Iterator npb, Iterator npe,
std::string const & source, Callback cb)
{
- typedef boost::spirit::position_iterator<Iterator> PositionIterator;
+ typedef boost::spirit::position_iterator<
+ Iterator, detail::FilePositionWithIndex> PositionIterator;
PositionIterator b (npb, npe, source);
PositionIterator e (npe, npe, source);
ParseCommandInfo info;
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;
}
prefix_ void senf::console::CommandParser::parseArguments(std::string const & arguments,
ParseCommandInfo & info)
{
- typedef boost::spirit::position_iterator<std::string::const_iterator> PositionIterator;
+ typedef boost::spirit::position_iterator<
+ std::string::const_iterator, detail::FilePositionWithIndex> PositionIterator;
PositionIterator b (arguments.begin(), arguments.end(), std::string("<unknown>"));
PositionIterator e (arguments.end(), arguments.end(), std::string("<unknown>"));
detail::ParseDispatcher::BindInfo bind (impl().dispatcher, info);
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;
}
prefix_ void senf::console::CommandParser::parsePath(std::string const & path,
ParseCommandInfo & info)
{
- typedef boost::spirit::position_iterator<std::string::const_iterator> PositionIterator;
+ typedef boost::spirit::position_iterator<
+ std::string::const_iterator, detail::FilePositionWithIndex> PositionIterator;
PositionIterator b (path.begin(), path.end(), std::string("<unknown>"));
PositionIterator e (path.end(), path.end(), std::string("<unknown>"));
detail::ParseDispatcher::BindInfo bind (impl().dispatcher, info);
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;
}
parseLoop(commands.begin(), commands.end(), "<unknown>", 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"