cpp-hocon  0.3.0
tokens.hpp
1 #pragma once
2 
3 #include "token.hpp"
4 #include <hocon/config_value.hpp>
5 
6 namespace hocon {
7 
8  class value : public token {
9  public:
10  value(shared_value value);
11  value(shared_value value, std::string original_text);
12 
13  std::string to_string() const override;
14  shared_origin const& origin() const override;
15 
16  shared_value get_value() const;
17 
18  bool operator==(const token& other) const override;
19 
20  private:
21  shared_value _value;
22  };
23 
24  class line : public token {
25  public:
26  line(shared_origin origin);
27 
28  std::string to_string() const override;
29 
30  bool operator==(token const& other) const override;
31  };
32 
33  class unquoted_text : public token {
34  public:
35  unquoted_text(shared_origin origin, std::string text);
36 
37  std::string to_string() const override;
38 
39  bool operator==(const token& other) const override;
40  };
41 
42  class ignored_whitespace : public token {
43  public:
44  ignored_whitespace(shared_origin origin, std::string whitespace);
45 
46  std::string to_string() const override;
47 
48  bool operator==(const token& other) const override;
49  };
50 
51  class problem : public token {
52  public:
53  problem(shared_origin origin, std::string what, std::string message, bool suggest_quotes);
54 
55  std::string what() const;
56  std::string message() const;
57  bool suggest_quotes() const;
58 
59  std::string to_string() const override;
60 
61  bool operator==(const token& other) const override;
62 
63  private:
64  std::string _what;
65  std::string _message;
66  bool _suggest_quotes;
67  };
68 
69  class comment : public token {
70  public:
71  comment(shared_origin origin, std::string text);
72 
73  std::string text() const;
74 
75  std::string to_string() const override;
76  bool operator==(const token& other) const override;
77 
78  private:
79  std::string _text;
80  };
81 
82  class double_slash_comment : public comment {
83  public:
84  double_slash_comment(shared_origin origin, std::string text);
85 
86  std::string token_text() const override;
87  };
88 
89  class hash_comment : public comment {
90  public:
91  hash_comment(shared_origin origin, std::string text);
92 
93  std::string token_text() const override;
94  };
95 
96  class substitution : public token {
97  public:
98  substitution(shared_origin origin, bool optional, token_list expression);
99 
100  bool optional() const;
101  token_list const& expression() const;
102 
103  std::string token_text() const override;
104  std::string to_string() const override;
105 
106  bool operator==(const token& other) const override;
107 
108  private:
109  bool _optional;
110  token_list _expression;
111  };
112 
113  class tokens {
114  public:
116  static shared_token const& start_token();
117  static shared_token const& end_token();
118  static shared_token const& comma_token();
119  static shared_token const& equals_token();
120  static shared_token const& colon_token();
121  static shared_token const& open_curly_token();
122  static shared_token const& close_curly_token();
123  static shared_token const& open_square_token();
124  static shared_token const& close_square_token();
125  static shared_token const& plus_equals_token();
126 
127  static bool is_newline(shared_token);
128  static bool is_ignored_whitespace(shared_token);
129 
130  static bool is_value_with_type(shared_token t, config_value::type type);
131 
132  static shared_value get_value(shared_token t);
133  };
134 
135 } // namespace hocon
hocon::line
Definition: tokens.hpp:24
hocon::token
Definition: token.hpp:18
hocon::double_slash_comment
Definition: tokens.hpp:82
hocon::config_value::type
type
The type of a configuration value (following the JSON type schema).
Definition: config_value.hpp:56
hocon::comment
Definition: tokens.hpp:69
hocon
Factory for creating config_document instances.
Definition: config.hpp:18
hocon::substitution
Definition: tokens.hpp:96
hocon::hash_comment
Definition: tokens.hpp:89
hocon::tokens
Definition: tokens.hpp:113
hocon::value
Definition: tokens.hpp:8
hocon::unquoted_text
Definition: tokens.hpp:33
hocon::tokens::start_token
static shared_token const & start_token()
Singleton tokens.
hocon::problem
Definition: tokens.hpp:51
hocon::ignored_whitespace
Definition: tokens.hpp:42