~ubuntu-branches/ubuntu/warty/aqsis/warty

« back to all changes in this revision

Viewing changes to boost/boost/spirit/error_handling/impl/exceptions.ipp

  • Committer: Bazaar Package Importer
  • Author(s): LaMont Jones
  • Date: 2004-08-24 07:25:04 UTC
  • Revision ID: james.westby@ubuntu.com-20040824072504-zf993vnevvisdsvb
Tags: upstream-0.9.1
ImportĀ upstreamĀ versionĀ 0.9.1

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*=============================================================================
 
2
    Spirit v1.6.1
 
3
    Copyright (c) 2001-2003 Joel de Guzman
 
4
    http://spirit.sourceforge.net/
 
5
 
 
6
    Permission to copy, use, modify, sell and distribute this software is
 
7
    granted provided this copyright notice appears in all copies. This
 
8
    software is provided "as is" without express or implied warranty, and
 
9
    with no claim as to its suitability for any purpose.
 
10
=============================================================================*/
 
11
#ifndef BOOST_SPIRIT_EXCEPTIONS_IPP
 
12
#define BOOST_SPIRIT_EXCEPTIONS_IPP
 
13
 
 
14
namespace boost { namespace spirit { namespace impl {
 
15
 
 
16
#ifdef __BORLANDC__
 
17
    template <typename ParserT, typename ScannerT>
 
18
    typename parser_result<ParserT, ScannerT>::type
 
19
    fallback_parser_helper(ParserT const& subject, ScannerT const& scan);
 
20
#endif
 
21
 
 
22
    template <typename RT, typename ParserT, typename ScannerT>
 
23
    RT fallback_parser_parse(ParserT const& p, ScannerT const& scan)
 
24
    {
 
25
        typedef typename ScannerT::iterator_t iterator_t;
 
26
        typedef typename RT::attr_t attr_t;
 
27
        typedef error_status<attr_t> error_status_t;
 
28
        typedef typename ParserT::error_descr_t error_descr_t;
 
29
 
 
30
        iterator_t save = scan.first;
 
31
        error_status_t hr(error_status_t::retry);
 
32
 
 
33
        while (hr.result == error_status_t::retry)
 
34
        {
 
35
            try
 
36
            {
 
37
            #ifndef __BORLANDC__
 
38
                return p.subject().parse(scan);
 
39
            #else
 
40
                return impl::fallback_parser_helper(p, scan);
 
41
            #endif
 
42
            }
 
43
 
 
44
            catch (parser_error<error_descr_t, iterator_t> error)
 
45
            {
 
46
                scan.first = save;
 
47
                hr = p.handler(scan, error);
 
48
                switch (hr.result)
 
49
                {
 
50
                    case error_status_t::fail:
 
51
                        return scan.no_match();
 
52
                    case error_status_t::accept:
 
53
                        return scan.create_match
 
54
                            (hr.length, hr.value, save, scan.first);
 
55
                    case error_status_t::rethrow:
 
56
                         boost::throw_exception(error);
 
57
                    default:
 
58
                        continue;
 
59
                }
 
60
            }
 
61
        }
 
62
        return scan.no_match();
 
63
    }
 
64
 
 
65
///////////////////////////////////////////////////////////////////////////
 
66
//
 
67
//  Borland does not like calling the subject directly in the try block.
 
68
//  Removing the #ifdef __BORLANDC__ code makes Borland complain that
 
69
//  some variables and types cannot be found in the catch block. Weird!
 
70
//
 
71
///////////////////////////////////////////////////////////////////////////
 
72
#ifdef __BORLANDC__
 
73
 
 
74
    template <typename ParserT, typename ScannerT>
 
75
    typename parser_result<ParserT, ScannerT>::type
 
76
    fallback_parser_helper(ParserT const& p, ScannerT const& scan)
 
77
    { return p.subject().parse(scan); }
 
78
 
 
79
#endif
 
80
 
 
81
}}} // namespace boost::spirit::impl
 
82
 
 
83
///////////////////////////////////////////////////////////////////////////////
 
84
#endif
 
85