summaryrefslogtreecommitdiff
path: root/lib/jsonParse.h
blob: c7766433050a86958c043d9b8fa6876a01e7da9b (plain)
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
#pragma once

#ifndef FLEX_SCANNER
#	define yyFlexLexer jsonBaseFlexLexer
#	include <FlexLexer.h>
#endif
#include <cassert>
#include <filesystem>
#include <fstream>
#include <memory>
#include <stdexcept>
#include <string>

namespace json {
	class jsonParser : public yyFlexLexer {
	public:
		using yyFlexLexer::yyFlexLexer;
		int yylex() override;

		static void appendEscape(const char *, std::string &);
		static void appendEscape(unsigned long, std::string &);

	protected:
		virtual void beginObject() = 0;
		virtual void beginArray() = 0;

		virtual void pushBoolean(bool) = 0;
		virtual void pushNumber(std::string_view) = 0;
		virtual void pushNull() = 0;
		virtual void pushText(std::string &&) = 0;
		virtual void pushKey(std::string &&) = 0;

		virtual void endArray() = 0;
		virtual void endObject() = 0;

		void LexerError(const char * msg) override;

		std::string buf;
	};
}