aboutsummaryrefslogtreecommitdiff
path: root/Parser.h
blob: 3a86eec3626e5d3b4f0a2c1c0c899d8267e61c9b (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
41
42
43
44
45
#pragma once

#include <iostream>
#include <istream>
#include <exception>

#include "Circuit.h"

using std::istream;
using std::string;

class ParserException : public std::exception {
public:
	ParserException(const char * fmt, ...);
	virtual ~ParserException();
	virtual const char * what();

private:
	char * error = NULL;
};

class Parser {
public:
	Parser() = default;
	virtual ~Parser() = default;

	void parse(string input);
	void parse(istream & input);

	/**
	 * \brief preprocess (filter) line of input
	 *
	 * normalize whitespace and remove comments
	 */
	static size_t filter(char * input);

	void set_circuit(Circuit & circuit);

private:
	friend istream & operator << (Parser & parser, istream & s);
	friend istream & operator >> (istream & s, Parser & parser);

	Circuit * circuit;
};