-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathparseLsysXML.cpp
40 lines (35 loc) · 1.11 KB
/
parseLsysXML.cpp
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
#include <cstring>
#include <sstream>
#include "parseLsysXML.h"
using std::string;
using std::cout;
using std::endl;
void ParseLsysXML::start(const char *el, const char *attr[]) {
ParseXML::start(el, attr);
for (int i = 0; attr[i]; i += 2) {
if ( string(el)=="rule" && attr[i]==string("nonterminal") ) {
lastNonTerminal = attr[i+1];
}
}
}
void ParseLsysXML::chars(const char *text, int textlen) {
ParseXML::chars(text, textlen);
// The text is not zero terminated; thus we need the length:
string str(text, textlen);
// The text is likely to have trailing white space, e.g. newline, etc
stripTrailWhiteSpace(str);
if ( str.size() ) {
if ( lastElementTag == "rule") {
grammar.insert(std::pair<char,string>(lastNonTerminal[0], str));
}
}
}
void ParseLsysXML::
wrapper4Start(void *data, const char *el, const char **attr) {
ParseLsysXML * parser = static_cast<ParseLsysXML*>(data);
parser->start(el, attr);
}
void ParseLsysXML::wrapper4Chars(void *data, const char *text, int textlen) {
ParseLsysXML * parser = static_cast<ParseLsysXML*>(data);
parser->chars(text, textlen);
}