added TokenDefinition class; creating TokenDefinition objects for each token in the input file
This commit is contained in:
parent
a6683fc37b
commit
269eddf81d
37
TokenDefinition.cc
Normal file
37
TokenDefinition.cc
Normal 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
21
TokenDefinition.h
Normal 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
|
@ -8,6 +8,7 @@
|
|||||||
#include <pcre.h>
|
#include <pcre.h>
|
||||||
|
|
||||||
#include "parse-input.h"
|
#include "parse-input.h"
|
||||||
|
#include "TokenDefinition.h"
|
||||||
|
|
||||||
using namespace std;
|
using namespace std;
|
||||||
|
|
||||||
@ -126,7 +127,17 @@ bool parse_input(char * buff, int size)
|
|||||||
flags = string(line,
|
flags = string(line,
|
||||||
ovector[6], ovector[7] - ovector[6]);
|
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
|
else
|
||||||
{
|
{
|
||||||
@ -155,5 +166,10 @@ bool parse_input(char * buff, int size)
|
|||||||
lineno++;
|
lineno++;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pcre_free(empty);
|
||||||
|
pcre_free(comment);
|
||||||
|
pcre_free(section_name);
|
||||||
|
pcre_free(token);
|
||||||
|
pcre_free(rule);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user