⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 primitives.ipp

📁 著名的Parser库Spirit在VC6上的Port
💻 IPP
📖 第 1 页 / 共 2 页
字号:

//////////////////////////////////
template <typename StringT>
template <typename IteratorT, typename MatchTraitsT>
inline typename MatchTraitsT::match_t
strlit<StringT>::ast_parse(IteratorT& first, IteratorT const& last, 
        MatchTraitsT const& /*mt*/) const
{
    typedef typename impl::strip_scanner<IteratorT>
        ::iterator_type plain_iter;
    plain_iter  i1 = impl::strip_scanner<IteratorT>::get(first);
    plain_iter  i2 = impl::strip_scanner<IteratorT>::get(last);

    actual_type s = str;
    raw_string_type strEnd = s.end();

    for (raw_string_type strFirst = s.begin();
        strFirst != strEnd; ++strFirst, ++i1)
        if ((i1 == i2) || (*strFirst != *i1))
            return MatchTraitsT::no_match;
    IteratorT saved = first;
    first = i1;
    return MatchTraitsT::create_match(s.length(), saved, first);
}

///////////////////////////////////////////////////////////////////////////////
//
//  Convenience functions
//
///////////////////////////////////////////////////////////////////////////////
//
//  On some systems the is* functions are defined as macros

#if defined(_MSC_VER) || _STLPORT_VERSION >= 0x450
// is* functions already setup
#else
#ifndef isalnum
inline bool isalnum(int c)     { return std::isalnum(c); }
#endif
#ifndef isalpha
inline bool isalpha(int c)     { return std::isalpha(c); }
#endif
#ifndef iscntrl
inline bool iscntrl(int c)     { return std::iscntrl(c); }
#endif
#ifndef isdigit
inline bool isdigit(int c)     { return std::isdigit(c); }
#endif
#ifndef isgraph
inline bool isgraph(int c)     { return std::isgraph(c); }
#endif
#ifndef islower
inline bool islower(int c)     { return std::islower(c); }
#endif
#ifndef isprint
inline bool isprint(int c)     { return std::isprint(c); }
#endif
#ifndef ispunct
inline bool ispunct(int c)     { return std::ispunct(c); }
#endif
#ifndef isspace
inline bool isspace(int c)     { return std::isspace(c); }
#endif
#ifndef isupper
inline bool isupper(int c)     { return std::isupper(c); }
#endif
#ifndef isxdigit
inline bool isxdigit(int c)    { return std::isxdigit(c); }
#endif
#ifndef isalnum
inline bool isalnum(wchar_t c)  { return std::iswalnum(c); }
#endif
#ifndef isalpha
inline bool isalpha(wchar_t c)  { return std::iswalpha(c); }
#endif
#ifndef iscntrl
inline bool iscntrl(wchar_t c)  { return std::iswcntrl(c); }
#endif
#ifndef isdigit
inline bool isdigit(wchar_t c)  { return std::iswdigit(c); }
#endif
#ifndef isgraph
inline bool isgraph(wchar_t c)  { return std::iswgraph(c); }
#endif
#ifndef islower
inline bool islower(wchar_t c)  { return std::iswlower(c); }
#endif
#ifndef isprint
inline bool isprint(wchar_t c)  { return std::iswprint(c); }
#endif
#ifndef ispunct
inline bool ispunct(wchar_t c)  { return std::iswpunct(c); }
#endif
#ifndef isspace
inline bool isspace(wchar_t c)  { return std::iswspace(c); }
#endif
#ifndef isupper
inline bool isupper(wchar_t c)  { return std::iswupper(c); }
#endif
#ifndef isxdigit
inline bool isxdigit(wchar_t c) { return std::iswxdigit(c); }
#endif
#endif // !defined(_MSC_VER)

///////////////////////////////////////////////////////////////////////////////
//
//  Predefined parser primitives implementation
//
///////////////////////////////////////////////////////////////////////////////
template <typename CharT>
inline bool
anychar_::test(CharT) const
{
    return true;
}

//////////////////////////////////
template <typename IteratorT>
inline match
nothing_::parse(IteratorT& /*first*/, IteratorT const& /*last*/) const
{
    return match();
}

//////////////////////////////////
template <typename IteratorT, typename MatchTraitsT>
inline typename MatchTraitsT::match_t
nothing_::ast_parse(IteratorT& /*first*/, IteratorT const& /*last*/, 
        MatchTraitsT const& /*mt*/) const
{
    return MatchTraitsT::no_match;
}

//////////////////////////////////
template <typename IteratorT>
inline match
epsilon_::parse(IteratorT&, IteratorT const&) const
{
    return match(0);
}

//////////////////////////////////
template <typename IteratorT, typename MatchTraitsT>
inline typename MatchTraitsT::match_t
epsilon_::ast_parse(IteratorT& first, IteratorT const& last, 
        MatchTraitsT const& /*mt*/) const
{
    return MatchTraitsT::empty_match;
}

//////////////////////////////////
template <typename CharT>
inline bool
alnum_::test(CharT ch) const
{
    return isalnum(ch);
}

//////////////////////////////////
template <typename CharT>
inline bool
alpha_::test(CharT ch) const
{
    return isalpha(ch);
}

//////////////////////////////////
template <typename CharT>
inline bool
cntrl_::test(CharT ch) const
{
    return iscntrl(ch);
}

//////////////////////////////////
template <typename CharT>
inline bool
digit_::test(CharT ch) const
{
    return isdigit(ch);
}

//////////////////////////////////
template <typename CharT>
inline bool
graph_::test(CharT ch) const
{
    return isgraph(ch);
}

//////////////////////////////////
template <typename CharT>
inline bool
lower_::test(CharT ch) const
{
    return islower(ch);
}

//////////////////////////////////
template <typename CharT>
inline bool
print_::test(CharT ch) const
{
    return isprint(ch);
}

//////////////////////////////////
template <typename CharT>
inline bool
punct_::test(CharT ch) const
{
    return ispunct(ch);
}

//////////////////////////////////
template <typename CharT>
inline bool
blank_::test(CharT ch) const
{
    // some systems have isblank(), but some don't, so just do it manually.
    return ch == ' ' || ch == '\t';
}

//////////////////////////////////
template <typename CharT>
inline bool
space_::test(CharT ch) const
{
    return isspace(ch);
}

//////////////////////////////////
template <typename CharT>
inline bool
upper_::test(CharT ch) const
{
    return isupper(ch);
}

//////////////////////////////////
template <typename CharT>
inline bool
xdigit_::test(CharT ch) const
{
    return isxdigit(ch);
}

///////////////////////////////////////////////////////////////////////////////
//
//  Generator functions implementation
//
///////////////////////////////////////////////////////////////////////////////
template <typename ParamT>
inline chlit<ParamT>
ch_p(ParamT param)
{
    return chlit<ParamT>(param);
}

template <typename ParamAT, typename ParamBT>
inline range<ParamAT, ParamBT>
range_p(ParamAT first, ParamBT last)
{
    return range<ParamAT, ParamBT>(first, last);
}

template <typename CharT>
inline strlit<cstring<CharT> >
str_p(CharT const* str)
{
    return strlit<cstring<CharT> >(str);
}

template <typename StringT>
inline strlit<StringT&>
str_p(reference_wrapper<StringT> const& ref)
{
    return strlit<StringT&>(ref);
}

///////////////////////////////////////////////////////////////////////////////
}   //  namespace Spirit

#endif

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -