Menu

[94f52a]: / parser / many.hpp  Maximize  Restore  History

Download this file

93 lines (73 with data), 2.4 kB

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
#ifndef CHILON_PARSER_MANY_HPP
#define CHILON_PARSER_MANY_HPP
#include <chilon/parser/detail/many.hpp>
#include <chilon/parser/parse.hpp>
#include <chilon/parser/skipped.hpp>
#include <chilon/parser/stored.hpp>
namespace chilon { namespace parser {
template <class H, bool SkipWhitespace, bool AtLeastOne = false>
struct many_base {
template <class Stream>
inline static bool skip(Stream& stream) {
if (AtLeastOne) {
if (! H::skip(stream)) return false;
if (SkipWhitespace) stream.skip_whitespace();
if (stream.empty()) return true;
}
while (H::skip(stream)) {
if (SkipWhitespace) stream.skip_whitespace();
if (stream.empty()) return true;
};
return true;
}
template <class Stream>
inline static bool match(Stream& stream) {
return ! AtLeastOne || H::match(stream);
}
};
/**
* H^*
* Equivalent to H* where each H cannot be separated by whitespace.
* Stores a range always.
*/
template <class... H>
struct many_range : many_base<sequence<H...>, false> {};
template <class... H>
struct many_plus_range : many_base<sequence<H...>, false, true> {};
/**
* H~*
* Equivalent to H* where each H can be separated by whitespace.
*/
template <class... H>
struct many_list : many_base<sequence<H...>, true> {};
template <class... H>
struct many_plus_list : many_base<sequence<H...>, true, true> {};
/**
* (...)*
* many<T...> -> many< sequence<T...> >
*/
template <class... T>
struct many : many< sequence<T...> > {};
template <class... T>
struct many_plus : many_plus< sequence<T...> > {};
/**
* Redirect character matches to no-whitespace version of many which stores
* a string, otherwise redirect to whitespace version which stores a vector
* of its results.
*/
template <class H>
struct many<H> :
detail::make_many<typename skipped_store<H>::type, H> {};
template <class H>
struct many_plus<H> :
detail::make_many_plus<typename skipped_store<H>::type, H> {};
template <class H>
struct parse<many_range<H>> : detail::parse_many_range<H, false> {};
template <class H>
struct parse<many_plus_range<H>> : detail::parse_many_range<H, true> {};
template <class H>
struct parse<many_list<H>> : detail::parse_many_list<H, false> {};
template <class H>
struct parse<many_plus_list<H>> : detail::parse_many_list<H, true> {};
} }
#endif
Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.