-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathparser.h
66 lines (53 loc) · 1.52 KB
/
parser.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
#ifndef UCIF_PARSER_H
#define UCIF_PARSER_H
#include <istream>
#include <string>
#include <ucif/cifLexer.h>
#include <ucif/cifParser.h>
#include <ucif/utils.h>
namespace ucif {
class parser
{
private: // emphasize the following members are private
parser(const parser&);
const parser& operator=(const parser&);
public:
parser() {}
parser(builder_base* builder,
std::string input_string,
std::string filename="memory", bool strict=true)
{
input = antlr3StringStreamNew(
pANTLR3_UINT8(input_string.c_str()),
ANTLR3_ENC_8BIT,
input_string.size(),
pANTLR3_UINT8(filename.c_str()));
lxr = cifLexerNew(input);
tstream = antlr3CommonTokenStreamSourceNew(
ANTLR3_SIZE_HINT, TOKENSOURCE(lxr));
psr = cifParserNew(tstream);
psr->pParser->rec->displayRecognitionError = parser_displayRecognitionError;
psr->errors = builder->new_array();
lxr->pLexer->rec->displayRecognitionError = lexer_displayRecognitionError;
lxr->errors = builder->new_array();
psr->parse(psr, builder, strict);
fflush(stderr);
}
~parser()
{
// Essential to clean up after ourselves (in reverse order)
delete psr->errors;
delete lxr->errors;
psr->free(psr);
tstream->free(tstream);
lxr->free(lxr);
input->close(input);
}
pcifLexer lxr;
pcifParser psr;
private:
pANTLR3_COMMON_TOKEN_STREAM tstream;
pANTLR3_INPUT_STREAM input;
};
} // namespace ucif
#endif //GUARD