-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathParserSingle.cpp
More file actions
49 lines (32 loc) · 1.26 KB
/
ParserSingle.cpp
File metadata and controls
49 lines (32 loc) · 1.26 KB
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
//
// Created by LE, Duc Anh on 8/18/15.
//
#include "ParserSingle.h"
#include "Exceptions/ParserException.h"
#include "Common/IDefines.h"
namespace CLDEParser {
SPtrSyntaxModel ParserSingle::Parse(SPtrTokenVector const &sptrTokens) const {
auto iterator = sptrTokens.cbegin();
try {
// Empty string returns a nullptr entity
if(iterator == sptrTokens.cend()){
return _sptrDerivative->SyntaxModel();
}
// Process
if (!_sptrDerivative->Derive(iterator)) {
int code = (int) Exceptions::ParserException::ParserExceptionCode::UnmatchedToken;
throw Exceptions::ParserException{code, iterator};
}
} catch (Exceptions::ParserException &ex) {
std::string _description;
_description.reserve(Common::BufferSize::EIGHTY);
auto exIter = sptrTokens.cbegin();
for (; exIter != ex.Iterator(); ++exIter) {
_description += (*exIter)->CopyToString();
}
_description += (*(ex.Iterator()))->CopyToString();
throw Exceptions::ParserException{(int) ex.Code(), iterator, _description};
}
return _sptrDerivative->SyntaxModel();
}
}