// Copyright (c) 2001-2010 Hartmut Kaiser // Copyright (c) 2001-2010 Joel de Guzman // // Distributed under the Boost Software License, Version 1.0. (See accompanying // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) #if !defined(BOOST_SPIRIT_PARSE_SEXPR_IMPL) #define BOOST_SPIRIT_PARSE_SEXPR_IMPL #include #include #include #include #include #include #include namespace scheme { namespace input { /////////////////////////////////////////////////////////////////////////// template bool parse_sexpr( std::basic_istream& is, utree& result, std::string const& source_file) { // no white space skipping in the stream! is.unsetf(std::ios::skipws); typedef boost::spirit::basic_istream_iterator stream_iterator_type; stream_iterator_type sfirst(is); stream_iterator_type slast; typedef line_pos_iterator iterator_type; iterator_type first(sfirst); iterator_type last(slast); scheme::input::sexpr p(source_file); scheme::input::sexpr_white_space ws; using boost::spirit::qi::phrase_parse; return phrase_parse(first, last, p, ws, result); } /////////////////////////////////////////////////////////////////////////// template bool parse_sexpr_list( std::basic_istream& is, utree& result, std::string const& source_file) { // no white space skipping in the stream! is.unsetf(std::ios::skipws); typedef boost::spirit::basic_istream_iterator stream_iterator_type; stream_iterator_type sfirst(is); stream_iterator_type slast; typedef line_pos_iterator iterator_type; iterator_type first(sfirst); iterator_type last(slast); scheme::input::sexpr p(source_file); scheme::input::sexpr_white_space ws; using boost::spirit::qi::phrase_parse; bool ok = phrase_parse(first, last, +p, ws, result); result.tag(1); // line return ok; } /////////////////////////////////////////////////////////////////////////// template typename boost::disable_if, bool>::type parse_sexpr( Range const& rng, utree& result, std::string const& source_file) { typedef line_pos_iterator iterator_type; scheme::input::sexpr p(source_file); scheme::input::sexpr_white_space ws; iterator_type first(rng.begin()); iterator_type last(rng.end()); using boost::spirit::qi::phrase_parse; return phrase_parse(first, last, p, ws, result); } template typename boost::disable_if, bool>::type parse_sexpr_list( Range const& rng, utree& result, std::string const& source_file) { typedef line_pos_iterator iterator_type; scheme::input::sexpr p(source_file); scheme::input::sexpr_white_space ws; iterator_type first(rng.begin()); iterator_type last(rng.end()); using boost::spirit::qi::phrase_parse; bool ok = phrase_parse(first, last, +p, ws, result); result.tag(1); // line return ok; } /////////////////////////////////////////////////////////////////////////// bool parse_sexpr( utree const& in, utree& result, std::string const& source_file) { return parse_sexpr(in.get(), result, source_file); } bool parse_sexpr_list( utree const& in, utree& result, std::string const& source_file) { return parse_sexpr_list(in.get(), result, source_file); } }} #endif