annotate DEPENDENCIES/generic/include/boost/spirit/home/qi/char/char_parser.hpp @ 133:4acb5d8d80b6 tip

Don't fail environmental check if README.md exists (but .txt and no-suffix don't)
author Chris Cannam
date Tue, 30 Jul 2019 12:25:44 +0100
parents 2665513ce2d3
children
rev   line source
Chris@16 1 /*=============================================================================
Chris@16 2 Copyright (c) 2001-2011 Joel de Guzman
Chris@16 3
Chris@16 4 Distributed under the Boost Software License, Version 1.0. (See accompanying
Chris@16 5 file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
Chris@16 6 ==============================================================================*/
Chris@16 7 #if !defined(BOOST_SPIRIT_CHAR_PARSER_APR_16_2006_0906AM)
Chris@16 8 #define BOOST_SPIRIT_CHAR_PARSER_APR_16_2006_0906AM
Chris@16 9
Chris@16 10 #if defined(_MSC_VER)
Chris@16 11 #pragma once
Chris@16 12 #endif
Chris@16 13
Chris@16 14 #include <boost/spirit/home/qi/domain.hpp>
Chris@16 15 #include <boost/spirit/home/qi/parser.hpp>
Chris@16 16 #include <boost/spirit/home/qi/detail/assign_to.hpp>
Chris@16 17 #include <boost/spirit/home/qi/meta_compiler.hpp>
Chris@16 18 #include <boost/spirit/home/qi/skip_over.hpp>
Chris@16 19 #include <boost/spirit/home/support/unused.hpp>
Chris@16 20 #include <boost/spirit/home/support/info.hpp>
Chris@16 21
Chris@16 22 namespace boost { namespace spirit
Chris@16 23 {
Chris@16 24 ///////////////////////////////////////////////////////////////////////////
Chris@16 25 // Enablers
Chris@16 26 ///////////////////////////////////////////////////////////////////////////
Chris@16 27 template <>
Chris@16 28 struct use_operator<qi::domain, proto::tag::complement> // enables ~
Chris@16 29 : mpl::true_ {};
Chris@16 30 }}
Chris@16 31
Chris@16 32 namespace boost { namespace spirit { namespace traits // classification
Chris@16 33 {
Chris@16 34 namespace detail
Chris@16 35 {
Chris@16 36 BOOST_MPL_HAS_XXX_TRAIT_DEF(char_parser_id)
Chris@16 37 }
Chris@16 38
Chris@16 39 template <typename T>
Chris@16 40 struct is_char_parser : detail::has_char_parser_id<T> {};
Chris@16 41 }}}
Chris@16 42
Chris@16 43 namespace boost { namespace spirit { namespace qi
Chris@16 44 {
Chris@16 45 ///////////////////////////////////////////////////////////////////////////
Chris@16 46 // The base char_parser
Chris@16 47 ///////////////////////////////////////////////////////////////////////////
Chris@16 48 template <typename Derived, typename Char, typename Attr = Char>
Chris@16 49 struct char_parser : primitive_parser<Derived>
Chris@16 50 {
Chris@16 51 typedef Char char_type;
Chris@16 52 struct char_parser_id;
Chris@16 53
Chris@16 54 // if Attr is unused_type, Derived must supply its own attribute
Chris@16 55 // metafunction
Chris@16 56 template <typename Context, typename Iterator>
Chris@16 57 struct attribute
Chris@16 58 {
Chris@16 59 typedef Attr type;
Chris@16 60 };
Chris@16 61
Chris@16 62 template <typename Iterator, typename Context, typename Skipper, typename Attribute>
Chris@16 63 bool parse(Iterator& first, Iterator const& last
Chris@16 64 , Context& context, Skipper const& skipper, Attribute& attr_) const
Chris@16 65 {
Chris@16 66 qi::skip_over(first, last, skipper);
Chris@16 67
Chris@16 68 if (first != last && this->derived().test(*first, context))
Chris@16 69 {
Chris@16 70 spirit::traits::assign_to(*first, attr_);
Chris@16 71 ++first;
Chris@16 72 return true;
Chris@16 73 }
Chris@16 74 return false;
Chris@16 75 }
Chris@16 76
Chris@16 77 // Requirement: p.test(ch, context) -> bool
Chris@16 78 //
Chris@16 79 // ch: character being parsed
Chris@16 80 // context: enclosing rule context
Chris@16 81 };
Chris@16 82
Chris@16 83 ///////////////////////////////////////////////////////////////////////////
Chris@16 84 // negated_char_parser handles ~cp expressions (cp is a char_parser)
Chris@16 85 ///////////////////////////////////////////////////////////////////////////
Chris@16 86 template <typename Positive>
Chris@16 87 struct negated_char_parser :
Chris@16 88 char_parser<negated_char_parser<Positive>, typename Positive::char_type>
Chris@16 89 {
Chris@16 90 negated_char_parser(Positive const& positive_)
Chris@16 91 : positive(positive_) {}
Chris@16 92
Chris@16 93 template <typename CharParam, typename Context>
Chris@16 94 bool test(CharParam ch, Context& context) const
Chris@16 95 {
Chris@16 96 return !positive.test(ch, context);
Chris@16 97 }
Chris@16 98
Chris@16 99 template <typename Context>
Chris@16 100 info what(Context& context) const
Chris@16 101 {
Chris@16 102 return info("not", positive.what(context));
Chris@16 103 }
Chris@16 104
Chris@16 105 Positive positive;
Chris@16 106 };
Chris@16 107
Chris@16 108 ///////////////////////////////////////////////////////////////////////////
Chris@16 109 // Parser generators: make_xxx function (objects)
Chris@16 110 ///////////////////////////////////////////////////////////////////////////
Chris@16 111 namespace detail
Chris@16 112 {
Chris@16 113 template <typename Positive>
Chris@16 114 struct make_negated_char_parser
Chris@16 115 {
Chris@16 116 typedef negated_char_parser<Positive> result_type;
Chris@16 117 result_type operator()(Positive const& positive) const
Chris@16 118 {
Chris@16 119 return result_type(positive);
Chris@16 120 }
Chris@16 121 };
Chris@16 122
Chris@16 123 template <typename Positive>
Chris@16 124 struct make_negated_char_parser<negated_char_parser<Positive> >
Chris@16 125 {
Chris@16 126 typedef Positive result_type;
Chris@16 127 result_type operator()(negated_char_parser<Positive> const& ncp) const
Chris@16 128 {
Chris@16 129 return ncp.positive;
Chris@16 130 }
Chris@16 131 };
Chris@16 132 }
Chris@16 133
Chris@16 134 template <typename Elements, typename Modifiers>
Chris@16 135 struct make_composite<proto::tag::complement, Elements, Modifiers>
Chris@16 136 {
Chris@16 137 typedef typename
Chris@16 138 fusion::result_of::value_at_c<Elements, 0>::type
Chris@16 139 subject;
Chris@16 140
Chris@16 141 BOOST_SPIRIT_ASSERT_MSG((
Chris@16 142 traits::is_char_parser<subject>::value
Chris@16 143 ), subject_is_not_negatable, (subject));
Chris@16 144
Chris@16 145 typedef typename
Chris@16 146 detail::make_negated_char_parser<subject>::result_type
Chris@16 147 result_type;
Chris@16 148
Chris@16 149 result_type operator()(Elements const& elements, unused_type) const
Chris@16 150 {
Chris@16 151 return detail::make_negated_char_parser<subject>()(
Chris@16 152 fusion::at_c<0>(elements));
Chris@16 153 }
Chris@16 154 };
Chris@16 155 }}}
Chris@16 156
Chris@16 157 #endif