]>
Commit | Line | Data |
---|---|---|
7c673cae FG |
1 | // tokeniser_state.hpp |
2 | // Copyright (c) 2007-2009 Ben Hanson (http://www.benhanson.net/) | |
3 | // | |
4 | // Distributed under the Boost Software License, Version 1.0. (See accompanying | |
5 | // file licence_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) | |
6 | #ifndef BOOST_LEXER_RE_TOKENISER_STATE_HPP | |
7 | #define BOOST_LEXER_RE_TOKENISER_STATE_HPP | |
8 | ||
9 | #include "../../consts.hpp" | |
10 | #include <locale> | |
11 | #include "../../size_t.hpp" | |
12 | #include <stack> | |
13 | ||
14 | namespace boost | |
15 | { | |
16 | namespace lexer | |
17 | { | |
18 | namespace detail | |
19 | { | |
20 | template<typename CharT> | |
21 | struct basic_re_tokeniser_state | |
22 | { | |
23 | const CharT * const _start; | |
24 | const CharT * const _end; | |
25 | const CharT *_curr; | |
26 | regex_flags _flags; | |
27 | std::stack<regex_flags> _flags_stack; | |
28 | std::locale _locale; | |
29 | long _paren_count; | |
30 | bool _in_string; | |
31 | bool _seen_BOL_assertion; | |
32 | bool _seen_EOL_assertion; | |
33 | ||
34 | basic_re_tokeniser_state (const CharT *start_, const CharT * const end_, | |
35 | const regex_flags flags_, const std::locale locale_) : | |
36 | _start (start_), | |
37 | _end (end_), | |
38 | _curr (start_), | |
39 | _flags (flags_), | |
40 | _locale (locale_), | |
41 | _paren_count (0), | |
42 | _in_string (false), | |
43 | _seen_BOL_assertion (false), | |
44 | _seen_EOL_assertion (false) | |
45 | { | |
46 | } | |
47 | ||
48 | // prevent VC++ 7.1 warning: | |
49 | const basic_re_tokeniser_state &operator = | |
50 | (const basic_re_tokeniser_state &rhs_) | |
51 | { | |
52 | _start = rhs_._start; | |
53 | _end = rhs_._end; | |
54 | _curr = rhs_._curr; | |
55 | _flags = rhs_._flags; | |
56 | _locale = rhs_._locale; | |
57 | _paren_count = rhs_._paren_count; | |
58 | _in_string = rhs_._in_string; | |
59 | _seen_BOL_assertion = rhs_._seen_BOL_assertion; | |
60 | _seen_EOL_assertion = rhs_._seen_EOL_assertion; | |
61 | return this; | |
62 | } | |
63 | ||
64 | inline bool next (CharT &ch_) | |
65 | { | |
66 | if (_curr >= _end) | |
67 | { | |
68 | ch_ = 0; | |
69 | return true; | |
70 | } | |
71 | else | |
72 | { | |
73 | ch_ = *_curr; | |
74 | increment (); | |
75 | return false; | |
76 | } | |
77 | } | |
78 | ||
79 | inline void increment () | |
80 | { | |
81 | ++_curr; | |
82 | } | |
83 | ||
84 | inline std::size_t index () | |
85 | { | |
86 | return _curr - _start; | |
87 | } | |
88 | ||
89 | inline bool eos () | |
90 | { | |
91 | return _curr >= _end; | |
92 | } | |
93 | }; | |
94 | } | |
95 | } | |
96 | } | |
97 | ||
98 | #endif |