added Token::m_type/setType()/getType(); changed Token::process() to accept a const reference to a Matches; updated build test

This commit is contained in:
Josh Holtrop committed 2010-05-21 10:22:37 -04:00
1 parent 5219989f2a
commit 3a3dc4074b
5 files changed
+35 -21

No files matched your search

+18 -11
View File
@@ -25,6 +25,10 @@ static TokenRef buildToken(int typeindex)
{
{%buildToken%}
}
if (!token.isNull())
{
token->setType(typeindex);
}
return token;
}
@@ -119,19 +123,22 @@ bool I_CLASSNAME::parse(istream & i)
}
}
}
if (longest_match_index >= 0)
{
Matches matches(tokens[longest_match_index].re,
&buff[0], ovector, ovector_size);
TokenRef token = buildToken(longest_match_index);
buff_pos += longest_match_length;
}
else
if (longest_match_index < 0)
{
/* no pattern matched the input at the current position */
cerr << "Parse error" << endl;
return false;
}
Matches matches(tokens[longest_match_index].re,
&buff[0], ovector, ovector_size);
TokenRef token = buildToken(longest_match_index);
if (token.isNull())
{
cerr << "Internal Error: null token" << endl;
return false;
}
token->process(matches);
buff_pos += longest_match_length;
}
}
@@ -149,7 +156,7 @@ refptr<Node> Node::operator[](const std::string & index)
: NULL;
}
void Token::process(Matches matches)
void Token::process(const Matches & matches)
{
{%token_code%}
}
@@ -159,7 +166,7 @@ Matches::Matches(pcre * re, const char * data, int * ovector, int ovec_size)
{
}
std::string Matches::operator[](int index)
std::string Matches::operator[](int index) const
{
if (0 <= index && index < (m_ovec_size / 3))
{
@@ -173,7 +180,7 @@ std::string Matches::operator[](int index)
return "";
}
std::string Matches::operator[](const std::string & index)
std::string Matches::operator[](const std::string & index) const
{
int idx = pcre_get_stringnumber(m_re, index.c_str());
if (idx > 0 && idx < (m_ovec_size / 3))
+6 -3
View File
@@ -134,8 +134,8 @@ class Matches
{
public:
Matches(pcre * re, const char * data, int * ovector, int ovec_size);
std::string operator[](int index);
std::string operator[](const std::string & index);
std::string operator[](int index) const;
std::string operator[](const std::string & index) const;
protected:
pcre * m_re;
@@ -159,9 +159,12 @@ typedef refptr<Node> NodeRef;
class Token : public Node
{
public:
virtual void process(Matches matches);
virtual void process(const Matches & matches);
void setType(int type) { m_type = type; }
int getType() const { return m_type; }
protected:
int m_type;
{%token_data%}
};
typedef refptr<Token> TokenRef;