1 // Copyright (c) 2001-2010 Hartmut Kaiser
2 // Copyright (c) 2001-2010 Joel de Guzman
4 // Distributed under the Boost Software License, Version 1.0. (See accompanying
5 // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
7 #if !defined(BOOST_SPIRIT_PARSE_SEXPR_IMPL)
8 #define BOOST_SPIRIT_PARSE_SEXPR_IMPL
12 #include <boost/spirit/include/support_istream_iterator.hpp>
13 #include <boost/spirit/include/support_line_pos_iterator.hpp>
14 #include <boost/spirit/include/qi_parse.hpp>
16 #include <input/sexpr.hpp>
17 #include <input/parse_sexpr.hpp>
19 namespace scheme { namespace input
21 ///////////////////////////////////////////////////////////////////////////
22 template <typename Char>
24 std::basic_istream<Char>& is,
26 std::string const& source_file)
28 // no white space skipping in the stream!
29 is.unsetf(std::ios::skipws);
32 boost::spirit::basic_istream_iterator<Char>
34 stream_iterator_type sfirst(is);
35 stream_iterator_type slast;
37 typedef boost::spirit::line_pos_iterator<stream_iterator_type>
39 iterator_type first(sfirst);
40 iterator_type last(slast);
42 scheme::input::sexpr<iterator_type> p(source_file);
43 scheme::input::sexpr_white_space<iterator_type> ws;
45 using boost::spirit::qi::phrase_parse;
46 return phrase_parse(first, last, p, ws, result);
49 ///////////////////////////////////////////////////////////////////////////
50 template <typename Char>
51 bool parse_sexpr_list(
52 std::basic_istream<Char>& is,
54 std::string const& source_file)
56 // no white space skipping in the stream!
57 is.unsetf(std::ios::skipws);
60 boost::spirit::basic_istream_iterator<Char>
62 stream_iterator_type sfirst(is);
63 stream_iterator_type slast;
65 typedef boost::spirit::line_pos_iterator<stream_iterator_type>
67 iterator_type first(sfirst);
68 iterator_type last(slast);
70 scheme::input::sexpr<iterator_type> p(source_file);
71 scheme::input::sexpr_white_space<iterator_type> ws;
73 using boost::spirit::qi::phrase_parse;
74 bool ok = phrase_parse(first, last, +p, ws, result);
75 result.tag(1); // line
79 ///////////////////////////////////////////////////////////////////////////
80 template <typename Range>
81 typename boost::disable_if<boost::is_base_of<std::ios_base, Range>, bool>::type
85 std::string const& source_file)
87 typedef boost::spirit::line_pos_iterator<typename Range::const_iterator>
90 scheme::input::sexpr<iterator_type> p(source_file);
91 scheme::input::sexpr_white_space<iterator_type> ws;
93 iterator_type first(rng.begin());
94 iterator_type last(rng.end());
96 using boost::spirit::qi::phrase_parse;
97 return phrase_parse(first, last, p, ws, result);
100 template <typename Range>
101 typename boost::disable_if<boost::is_base_of<std::ios_base, Range>, bool>::type
105 std::string const& source_file)
107 typedef boost::spirit::line_pos_iterator<typename Range::const_iterator>
110 scheme::input::sexpr<iterator_type> p(source_file);
111 scheme::input::sexpr_white_space<iterator_type> ws;
113 iterator_type first(rng.begin());
114 iterator_type last(rng.end());
116 using boost::spirit::qi::phrase_parse;
117 bool ok = phrase_parse(first, last, +p, ws, result);
118 result.tag(1); // line
122 ///////////////////////////////////////////////////////////////////////////
126 std::string const& source_file)
128 return parse_sexpr(in.get<utf8_string_range_type>(), result, source_file);
131 bool parse_sexpr_list(
134 std::string const& source_file)
136 return parse_sexpr_list(in.get<utf8_string_range_type>(), result, source_file);