added Parser class and a parameter for it to parse_input()

This commit is contained in:
Josh Holtrop 2010-04-08 16:15:17 -04:00
parent 269eddf81d
commit 5a220b91d0
5 changed files with 41 additions and 5 deletions

8
Parser.cc Normal file
View File

@ -0,0 +1,8 @@
#include "Parser.h"
using namespace std;
Parser::Parser()
{
}

23
Parser.h Normal file
View File

@ -0,0 +1,23 @@
#ifndef PARSER_H
#define PARSER_H
#include <vector>
#include "refptr/refptr.h"
#include "TokenDefinition.h"
class Parser
{
public:
Parser();
void addTokenDefinition(refptr<TokenDefinition> td)
{
m_tokens.push_back(td);
}
protected:
std::vector< refptr< TokenDefinition > > m_tokens;
};
#endif

View File

@ -42,7 +42,9 @@ int main(int argc, char * argv[])
char * buff = new char[size];
ifs.read(buff, size);
parse_input(buff, size);
Parser p;
parse_input(buff, size, p);
ifs.close();
delete[] buff;

View File

@ -9,12 +9,13 @@
#include "parse-input.h"
#include "TokenDefinition.h"
#include "Parser.h"
using namespace std;
enum Section{ none, tokens, rules };
bool parse_input(char * buff, int size)
bool parse_input(char * buff, int size, Parser & parser)
{
pcre * empty;
pcre * comment;
@ -130,7 +131,7 @@ bool parse_input(char * buff, int size)
refptr<TokenDefinition> td = new TokenDefinition();
if (td->create(name, definition, flags))
{
/* TODO: do something with td */
parser.addTokenDefinition(td);
}
else
{

View File

@ -3,8 +3,10 @@
#define PARSE_INPUT_H
#include <vector>
#include "refptr/refptr.h"
bool parse_input(char * buff, int size);
#include "refptr/refptr.h"
#include "Parser.h"
bool parse_input(char * buff, int size, Parser & parser);
#endif