Elm  2
ELM is a library providing generic data structures, OS-independent interface, plugins and XML.
Parser.h
1 /*
2  * json::Parser class interface
3  *
4  * This file is part of OTAWA
5  * Copyright (c) 2016, IRIT UPS.
6  *
7  * OTAWA is free software; you can redistribute it and/or modify
8  * it under the terms of the GNU General Public License as published by
9  * the Free Software Foundation; either version 2 of the License, or
10  * (at your option) any later version.
11  *
12  * OTAWA is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15  * GNU General Public License for more details.
16  *
17  * You should have received a copy of the GNU General Public License
18  * along with OTAWA; if not, write to the Free Software
19  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
20  */
21 #ifndef ELM_JSON_PARSER_H_
22 #define ELM_JSON_PARSER_H_
23 
24 #include "common.h"
25 #include <elm/io.h>
26 #include <elm/sys/Path.h>
27 
28 namespace elm { namespace json {
29 
30 class Maker {
31 public:
32  virtual ~Maker(void);
33  virtual void beginObject(void);
34  virtual void endObject(void);
35  virtual void beginArray(void);
36  virtual void endArray(void);
37  virtual void onField(string name);
38  virtual void onNull(void);
39  virtual void onValue(bool value);
40  virtual void onValue(int value);
41  virtual void onValue(double value);
42  virtual void onValue(string value);
43 };
44 
45 class Parser {
46 public:
47  Parser(Maker& maker);
48  void parse(string s);
49  inline void parse(cstring s) { parse(string(s)); }
50  inline void parse(const char *s) { parse(string(s)); }
51  void parse(io::InStream& in);
52  void parse(sys::Path path);
53 
54 private:
55  typedef enum {
56  NONE = 0,
57  LBRACE,
58  RBRACE,
59  LBRACK,
60  RBRACK,
61  _NULL,
62  TRUE,
63  FALSE,
64  INT,
65  FLOAT,
66  STRING,
67  COMMA,
68  COLON
69  } token_t;
70 
71  void doParsing(io::InStream& in);
72  token_t parseNumber(io::InStream& in, char c, int base = 10);
73  void parseObject(io::InStream& in);
74  void parseArray(io::InStream& in);
75  void parseValue(io::InStream& in, token_t t);
76  void parseString(io::InStream& in, char c);
77  void parseLitt(io::InStream& in, cstring litt);
78  void parseComment(io::InStream& in);
79  token_t parseBasedNumber(io::InStream& in);
80 
81  void error(string message);
82  token_t next(io::InStream& in);
83  char nextChar(io::InStream& in);
84  void pushBack(char c);
85 
86  Maker& m;
87  int line, col;
88  String text;
89  char prev;
90 };
91 
92 } } // elm::json
93 
94 #endif /* ELM_JSON_PARSER_H_ */
elm::json::Maker::endObject
virtual void endObject(void)
Definition: json_Parser.cpp:60
elm::json::Maker::onValue
virtual void onValue(bool value)
Definition: json_Parser.cpp:103
elm::json::Parser::parse
void parse(string s)
Definition: json_Parser.cpp:164
elm::json::Maker
Definition: Parser.h:30
elm::sys::Path
Definition: Path.h:33
elm::json::Maker::onNull
virtual void onNull(void)
Definition: json_Parser.cpp:93
elm::io::base
IntFormat base(int base, IntFormat fmt)
Definition: Output.h:256
elm::json::Maker::onField
virtual void onField(string name)
Definition: json_Parser.cpp:85
elm::json::Parser::Parser
Parser(Maker &maker)
Definition: json_Parser.cpp:156
value
elm::CString
Definition: CString.h:17
elm::json::Maker::endArray
virtual void endArray(void)
Definition: json_Parser.cpp:75
elm::t::in
typename type_info< T >::in_t in
Definition: type_info.h:283
elm::json::Parser::parse
void parse(const char *s)
Definition: Parser.h:50
elm
Definition: adapter.h:26
elm::json::Maker::beginArray
virtual void beginArray(void)
Definition: json_Parser.cpp:67
elm::json::Maker::~Maker
virtual ~Maker(void)
Definition: json_Parser.cpp:45
elm::json::Parser::parse
void parse(cstring s)
Definition: Parser.h:49
elm::String
Definition: String.h:30
elm::json::Maker::beginObject
virtual void beginObject(void)
Definition: json_Parser.cpp:52
elm::json::Parser
Definition: Parser.h:45
elm::io::InStream
Definition: InStream.h:29