added TokenDefinition class; creating TokenDefinition objects for each token in the input file

This commit is contained in:
Josh Holtrop 2010-04-08 15:10:11 -04:00
parent a6683fc37b
commit 269eddf81d
3 changed files with 75 additions and 1 deletions

37
TokenDefinition.cc Normal file
View File

@ -0,0 +1,37 @@
#include <pcre.h>
#include <iostream>
#include <string>
#include "TokenDefinition.h"
using namespace std;
TokenDefinition::TokenDefinition()
: m_re(NULL)
{
}
TokenDefinition::~TokenDefinition()
{
if (m_re != NULL)
{
pcre_free(m_re);
}
}
bool TokenDefinition::create(const string & name,
const string & definition, const string & flags)
{
const char * errptr;
int erroffset;
m_re = pcre_compile(definition.c_str(), 0, &errptr, &erroffset, NULL);
if (m_re == NULL)
{
cerr << "Error compiling regular expression '" << definition
<< "' at position " << erroffset << ": " << errptr << endl;
return false;
}
return true;
}

21
TokenDefinition.h Normal file
View File

@ -0,0 +1,21 @@
#ifndef TOKENDEFINITION_H
#define TOKENDEFINITION_H
#include <pcre.h>
#include <string>
class TokenDefinition
{
public:
TokenDefinition();
~TokenDefinition();
bool create(const std::string & name,
const std::string & definition, const std::string & flags);
protected:
pcre * m_re;
};
#endif

View File

@ -8,6 +8,7 @@
#include <pcre.h>
#include "parse-input.h"
#include "TokenDefinition.h"
using namespace std;
@ -126,7 +127,17 @@ bool parse_input(char * buff, int size)
flags = string(line,
ovector[6], ovector[7] - ovector[6]);
}
/* TODO: process token */
refptr<TokenDefinition> td = new TokenDefinition();
if (td->create(name, definition, flags))
{
/* TODO: do something with td */
}
else
{
cerr << "Error in token definition ending on line "
<< lineno << endl;
return false;
}
}
else
{
@ -155,5 +166,10 @@ bool parse_input(char * buff, int size)
lineno++;
}
pcre_free(empty);
pcre_free(comment);
pcre_free(section_name);
pcre_free(token);
pcre_free(rule);
return true;
}