Hasty Badger
Small UI library (a branch of Turbo Badger)
 All Classes Namespaces Functions Variables Enumerations Enumerator Friends Groups Pages
tb_parser.h
1 // ================================================================================
2 // == This file is a part of Turbo Badger. (C) 2011-2014, Emil SegerÃ¥s ==
3 // == See tb_core.h for more information. ==
4 // ================================================================================
5 
6 #ifndef TB_PARSER_H
7 #define TB_PARSER_H
8 
9 #include "tb_value.h"
10 #include "tb_tempbuffer.h"
11 #include "tb_str.h"
12 
13 namespace tb {
14 
17 void UnescapeString(char *str);
18 
22 bool IsEndQuote(const char *buf_start, const char *buf, const char quote_type);
23 
25 {
26 public:
27  virtual ~TBParserTarget() {}
28  virtual void OnError(int line_nr, const TBStr & error) = 0;
29  virtual void OnComment(int line_nr, const TBStr & comment) = 0;
30  virtual void OnToken(int line_nr, const char *name, TBValue &value) = 0;
31  virtual void Enter() = 0;
32  virtual void Leave() = 0;
33 };
34 
36 {
37 public:
38  virtual ~TBParserStream() {}
39  virtual int GetMoreData(char *buf, int buf_len) = 0;
40 };
41 
42 class TBParser
43 {
44 public:
45  enum STATUS {
46  STATUS_OK,
47  STATUS_OUT_OF_MEMORY,
48  STATUS_PARSE_ERROR
49  };
50  TBParser() {}
51  STATUS Read(TBParserStream *stream, TBParserTarget *target);
52 private:
53  int current_indent;
54  int current_line_nr;
55  TBStr multi_line_token;
56  TBTempBuffer multi_line_value;
57  int multi_line_sub_level;
58  bool pending_multiline;
59  void OnLine(char *line, TBParserTarget *target);
60  void OnCompactLine(char *line, TBParserTarget *target);
61  void OnMultiline(char *line, TBParserTarget *target);
62  void ConsumeValue(TBValue &dst_value, char *&line);
63 };
64 
65 } // namespace tb
66 
67 #endif // TB_PARSER_H
Definition: tb_parser.h:24
bool IsEndQuote(const char *buf_start, const char *buf, const char quote_type)
Check if buf is pointing at an end quote.
Definition: tb_parser.cpp:153
void UnescapeString(char *str)
Unescape backslash codes.
Definition: tb_parser.cpp:36
TBStr is a simple string class.
Definition: tb_str.h:62
TBValue holds value of a specific type.
Definition: tb_value.h:59
Definition: tb_parser.h:35
Definition: tb_parser.h:42
TBTempBuffer manages a buffer that will be deleted on destruction.
Definition: tb_tempbuffer.h:18