-
Notifications
You must be signed in to change notification settings - Fork 1
/
clauparse.h
84 lines (72 loc) · 1.59 KB
/
clauparse.h
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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
/* `clauparse.h`
* By: Ivan Rubinson (c) 2016
* Licensed under the Lesser GNU Public License v3.
*/
#ifndef CLAUPARSE_CLAUPARSE_H_INCLUDED
#define CLAUPARSE_CLAUPARSE_H_INCLUDED
#include <vector>
#include <exception>
#include <string>
namespace ClauParse
{
class Data
{
public:
/* `Node`
* is a node in an n-element tree.
*/
struct Node
{
std::wstring name;
std::vector<Node> children;
Node* parent;
Node(Node* parent, std::wstring name = L"") :
parent(parent),
name(name)
{
}
Node() :
parent(nullptr)
{
}
};
private:
Node data_start;
public:
Node* begin() { return &data_start; }
Data()
{
}
Data(Node node) :
data_start(node)
{
}
};
/* `parseFile`
* Parses a file at given `path`, and returns `Data`.
* May throw `std::runtime_error` if it fails to read from the file.
* Possible causes:
* - File does not exist
* - File is locked by another process
* May also throw `ParsingException` if the file is malformed.
*/
Data parseFile(const char* path);
/* `ParsingException`
* Is thrown when a file is malformed.
* Make sure that you're parsing the right file.
* If it's the right file but it's still misformed,
* it can be caused by a mistake in the file.
* A file might have a mistake for many reasons, including:
* - A mistake when editing by hand
* - A system failure during a write operation
*/
class ParsingException : public std::exception
{
private:
const char* error;
public:
const char* what() const throw() { return error; }
ParsingException(const char* error) : error(error) {}
};
}
#endif