cpp-hocon  0.3.0
config_document_parser.hpp
1 #pragma once
2 
3 #include <hocon/config_parse_options.hpp>
4 #include <internal/nodes/config_node_object.hpp>
5 #include <internal/nodes/config_node_root.hpp>
6 #include <internal/nodes/config_node_include.hpp>
7 #include <internal/simple_config_origin.hpp>
8 #include <internal/tokenizer.hpp>
9 
10 #include <stack>
11 
12 namespace hocon { namespace config_document_parser {
13 
14  std::shared_ptr<config_node_root> parse(token_iterator tokens,
15  shared_origin origin,
16  config_parse_options options);
17 
18  shared_node_value parse_value(token_iterator tokens,
19  shared_origin origin,
20  config_parse_options options);
21 
22  class parse_context {
23  public:
24  parse_context(config_syntax flavor, shared_origin origin, token_iterator tokens);
25 
26  std::shared_ptr<config_node_root> parse();
27 
31  shared_node_value parse_single_value();
32 
33  private:
34  parse_exception parse_error(std::string message);
35 
36  shared_token pop_token();
37  shared_token next_token();
38  shared_token next_token_collecting_whitespace(shared_node_list& nodes);
39  void put_back(shared_token token);
40 
49  bool check_element_separator(shared_node_list& nodes);
50 
52  shared_node_value consolidate_values(shared_node_list& nodes);
53 
54  std::string add_quote_suggestion(std::string bad_token, std::string message,
55  bool inside_equals, path* last_path);
56 
57  std::string add_quote_suggestion(std::string bad_token, std::string message);
58 
59  shared_node_value parse_value(shared_token t);
60  std::shared_ptr<config_node_path> parse_key(shared_token t);
61  bool is_key_value_separator(shared_token t);
62  std::shared_ptr<config_node_include> parse_include(shared_node_list& children);
63  std::shared_ptr<config_node_complex_value> parse_object(bool had_open_curly);
64  std::shared_ptr<config_node_complex_value> parse_array();
65 
66  static bool is_include_keyword(shared_token t);
67  static bool is_unquoted_whitespace(shared_token t);
68  static bool is_valid_array_element(shared_token t);
69 
70  int _line_number;
71  std::stack<shared_token> _buffer;
72  token_iterator _tokens;
73  config_syntax _flavor;
74  shared_origin _base_origin;
75 
76  // this is the number of "equals" we are inside,
77  // used to modify the error message to reflect that
78  // someone may think this is .properties format.
79  int _equals_count;
80  };
81 
82 
83 }} // namespace hocon::config_document_parser
hocon::config_document_parser::parse_context::parse_single_value
shared_node_value parse_single_value()
Parse a given input stream into a single value node.
hocon::token
Definition: token.hpp:18
hocon
Factory for creating config_document instances.
Definition: config.hpp:18
hocon::tokens
Definition: tokens.hpp:113
hocon::path
Definition: path.hpp:13
hocon::parse_exception
Exception indicating that there was a parse error.
Definition: config_exception.hpp:101
hocon::config_document_parser::parse_context
Definition: config_document_parser.hpp:22
hocon::token_iterator
Definition: tokenizer.hpp:49