Blame view

3rdparty/boost_1_81_0/libs/metaparse/doc/token.qbk 1.63 KB
73ef4ff3   Hu Chunming   提交三方库
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
  [#token]
  [section token]
  
  [h1 Synopsis]
  
    template <class P>
    struct token;
  
  This is a [link parser_combinator parser combinator].
  
  [table Arguments
    [[Name] [Type]]
    [[`P`]  [[link parser parser]]]
  ]
  
  [h1 Description]
  
  `token` parses the input using `P` when it succeeds, `token` consumes all
  whitespaces afterwards. The result of parsing is the result of `P`.
  
  [h1 Header]
  
    #include <boost/metaparse/token.hpp>
  
  [h1 Expression semantics]
  
  For any `p` parser the following are equivalent:
  
    token<p>
    
    first_of<p, spaces>
  
  [h1 Example]
  
    #include <boost/metaparse/token.hpp>
    #include <boost/metaparse/int_.hpp>
    #include <boost/metaparse/start.hpp>
    #include <boost/metaparse/get_result.hpp>
    #include <boost/metaparse/get_remaining.hpp>
    #include <boost/metaparse/is_error.hpp>
    #include <boost/metaparse/string.hpp>
    
    #include <type_traits>
    
    using namespace boost::metaparse;
    
    using int_token = token<int_>;
    
    static_assert(
      get_result<
        int_token::apply<BOOST_METAPARSE_STRING("13 "), start>
      >::type::value,
      "the result of int_token is the number"
    );
    
    static_assert(
      std::is_same<
        BOOST_METAPARSE_STRING(""),
        get_remaining<int_token::apply<BOOST_METAPARSE_STRING("13 "), start>>::type
      >::type::value,
      "token consumes whitespaces after the number"
    );
    
    static_assert(
      get_result<
        int_token::apply<BOOST_METAPARSE_STRING("13"), start>
      >::type::value,
      "whitespaces after the number are optional"
    );
    
    static_assert(
      is_error<int_token::apply<BOOST_METAPARSE_STRING("foo"), start>>::type::value,
      "when there is no number, token fails"
    );
  
  [endsect]