// $Id$
//
-// Copyright (C) 2008
+// Copyright (C) 2008
// Fraunhofer Institute for Open Communication Systems (FOKUS)
// Competence Center NETwork research (NET), St. Augustin, GERMANY
// Stefan Bund <g0dil@berlios.de>
#include <cerrno>
#include <sys/stat.h>
#include <boost/iterator/transform_iterator.hpp>
-#include <boost/spirit/iterator/file_iterator.hpp>
-#include <boost/spirit/iterator/position_iterator.hpp>
+#include <senf/config.hh>
+
+#if HAVE_BOOST_SPIRIT_INCLUDE_CLASSIC_HPP
+# include <boost/spirit/include/classic_file_iterator.hpp>
+# include <boost/spirit/include/classic_position_iterator.hpp>
+#else
+# include <boost/spirit/iterator/file_iterator.hpp>
+# include <boost/spirit/iterator/position_iterator.hpp>
+#endif
+
#include <senf/Utils/Exception.hh>
#include <senf/Utils/senfassert.hh>
void popDirectory()
{ info_->clear();
info_->builtin(ParseCommandInfo::BuiltinPOPD); }
-
+
void builtin_exit()
{ info_->clear();
info_->builtin(ParseCommandInfo::BuiltinEXIT); }
"Word" };
// The real table is:
// static const int bitPosition[32] = {
- // 0, 1, 28, 2, 29, 14, 24, 3, 30, 22, 20, 15, 25, 17, 4, 8,
+ // 0, 1, 28, 2, 29, 14, 24, 3, 30, 22, 20, 15, 25, 17, 4, 8,
// 31, 27, 13, 23, 21, 19, 16, 7, 26, 12, 18, 6, 11, 5, 10, 9 };
// However, we have replaced all values >= sizeof(tokenTypeName) with 0
// and have added 1 to all the remaining values
static const int bitPosition[32] = {
- 1, 2, 0, 3, 0, 0, 0, 4, 0, 0, 0, 0, 0, 0, 5, 9,
+ 1, 2, 0, 3, 0, 0, 0, 4, 0, 0, 0, 0, 0, 0, 5, 9,
0, 0, 0, 0, 0, 0, 0, 8, 0, 0, 0, 7, 0, 6, 0, 10 };
// We need to check token.type() against 0 explicitly since 0 and 1 will both be mapped to 0
- os << tokenTypeName[ token.type()
+ os << tokenTypeName[ token.type()
? bitPosition[(((token.type() & -token.type()) * 0x077CB531UL) >> 27) & 31]
: 0 ]
<< "('"
char const * builtins[] = { 0, "cd", "ls", "lr", "pushd", "popd", "exit", "help" };
stream << "builtin-" << builtins[info.builtin()];
}
-
+
ParseCommandInfo::ArgumentsRange args (info.arguments());
for (ParseCommandInfo::argument_iterator i (args.begin()); i != args.end(); ++i) {
ParseCommandInfo::token_iterator j (i->begin());
#endif
namespace {
-
+
template <class Error>
- void throwParserError(Error const & err)
+ void throwParserError(Error const & err)
{
static char const * msg [] = { "end of statement expected",
"path expected",
}
-namespace boost {
+namespace boost {
namespace spirit {
+#if HAVE_BOOST_SPIRIT_INCLUDE_CLASSIC_HPP
+namespace classic {
+#endif
template <>
struct position_policy<senf::console::detail::FilePositionWithIndex>
}
};
+#if HAVE_BOOST_SPIRIT_INCLUDE_CLASSIC_HPP
+}
+#endif
}}
prefix_ senf::console::CommandParser::CommandParser()
// we would need to expose the Impl member to the public, which we don't want to do.
template <class Iterator>
-prefix_ Iterator senf::console::CommandParser::parseLoop(Iterator npb, Iterator npe,
+prefix_ Iterator senf::console::CommandParser::parseLoop(Iterator npb, Iterator npe,
std::string const & source, Callback cb)
{
- typedef boost::spirit::position_iterator<
+ typedef detail::boost_spirit::position_iterator<
Iterator, detail::FilePositionWithIndex> PositionIterator;
PositionIterator b (npb, npe, source);
PositionIterator e (npe, npe, source);
ParseCommandInfo info;
detail::ParseDispatcher::BindInfo bind (impl().dispatcher, info);
- boost::spirit::parse_info<PositionIterator> result;
+ detail::boost_spirit::parse_info<PositionIterator> result;
for(;;) {
- result = boost::spirit::parse(
+ result = detail::boost_spirit::parse(
b, e, * impl().grammar.use_parser<Impl::Grammar::SkipParser>());
b = result.stop;
- if (b == e)
+ if (b == e)
return e.base();
info.clear();
try {
- result = boost::spirit::parse(b, e,
+ result = detail::boost_spirit::parse(b, e,
impl().grammar.use_parser<Impl::Grammar::CommandParser>(),
impl().grammar.use_parser<Impl::Grammar::SkipParser>());
}
- catch (boost::spirit::parser_error<Impl::Grammar::Errors, PositionIterator> & ex) {
+ catch (detail::boost_spirit::parser_error<Impl::Grammar::Errors, PositionIterator> & ex) {
if (impl().grammar.incremental && ex.where == e)
return b.base();
else
throwParserError(ex);
}
// Otherwise the error handling in the parser is broken
- SENF_ASSERT( result.hit );
- if (! info.empty())
+ SENF_ASSERT( result.hit, "Internal parser failure (error handling broken?)" );
+ if (! info.empty())
try {
cb(info);
}
prefix_ void senf::console::CommandParser::parseFile(std::string const & filename, Callback cb)
{
- // file_iterator sets errno to EINVAL and returns error when file size is 0
- // so we check the file size before
- struct stat statBuf;
+ // file_iterator sets errno to EINVAL and returns error when file size is 0
+ // so we check the file size before
+ struct stat statBuf;
if (stat( filename.c_str(), &statBuf) != 0)
throw SystemException(filename, errno SENF_EXC_DEBUGINFO);
if (statBuf.st_size == 0) return;
- boost::spirit::file_iterator<> i (filename);
+ detail::boost_spirit::file_iterator<> i (filename);
if (!i) {
if (errno == 0)
// hmm.. errno==0 but the file_iterator is false; something is wrong but we
- // do not know what exactly, so we throw a SystemeException with EINVAL
+ // do not know what exactly, so we throw a SystemeException with EINVAL
throw SystemException(filename, EINVAL SENF_EXC_DEBUGINFO);
else
throw SystemException(filename, errno SENF_EXC_DEBUGINFO);
}
- boost::spirit::file_iterator<> const i_end (i.make_end());
+ detail::boost_spirit::file_iterator<> const i_end (i.make_end());
parseLoop(i, i_end, filename, cb);
}
prefix_ void senf::console::CommandParser::parseArguments(std::string const & arguments,
ParseCommandInfo & info)
{
- typedef boost::spirit::position_iterator<
+ typedef detail::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);
- boost::spirit::parse_info<PositionIterator> result;
+ detail::boost_spirit::parse_info<PositionIterator> result;
try {
- result = boost::spirit::parse( b, e,
+ result = detail::boost_spirit::parse( b, e,
impl().grammar.use_parser<Impl::Grammar::ArgumentsParser>(),
impl().grammar.use_parser<Impl::Grammar::SkipParser>() );
}
- catch (boost::spirit::parser_error<Impl::Grammar::Errors, PositionIterator> & ex) {
+ catch (detail::boost_spirit::parser_error<Impl::Grammar::Errors, PositionIterator> & ex) {
throwParserError(ex);
}
if (! result.full) {
prefix_ void senf::console::CommandParser::parsePath(std::string const & path,
ParseCommandInfo & info)
{
- typedef boost::spirit::position_iterator<
+ typedef detail::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);
- boost::spirit::parse_info<PositionIterator> result;
+ detail::boost_spirit::parse_info<PositionIterator> result;
try {
- result = boost::spirit::parse( b, e,
+ result = detail::boost_spirit::parse( b, e,
impl().grammar.use_parser<Impl::Grammar::PathParser>(),
impl().grammar.use_parser<Impl::Grammar::SkipParser>() );
}
- catch (boost::spirit::parser_error<Impl::Grammar::Errors, PositionIterator> & ex) {
+ catch (detail::boost_spirit::parser_error<Impl::Grammar::Errors, PositionIterator> & ex) {
throwParserError(ex);
}
if (! result.full) {
senf::console::CommandParser::parseIncremental(std::string const & commands, Callback cb)
{
SetIncremental si (*this);
- return std::distance( commands.begin(),
+ return std::distance( commands.begin(),
parseLoop(commands.begin(), commands.end(), "<unknown>", cb) );
}