Skip to content
Permalink
Browse files

Rename ComputeFunc -> ParseFunc

  • Loading branch information
nfomon committed May 26, 2015
1 parent ad57c17 commit 725bcfee917e954873aa88a845687a5508abf78a
@@ -26,8 +26,8 @@ using namespace statik;
/* public */

IncParser::IncParser(Rule& grammar, const string& name, const string& graphdir)
: m_rootRule(name, MakeComputeFunc_Root(name), MakeOutputFunc_Pass()),
m_root(*this, m_rootRule, NULL, MakeComputeFunc_Root(name), MakeOutputFunc_Pass()),
: m_rootRule(name, MakeParseFunc_Root(name), MakeOutputFunc_Pass()),
m_root(*this, m_rootRule, NULL, MakeParseFunc_Root(name), MakeOutputFunc_Pass()),
m_grammar(grammar),
m_name(name),
m_needsCleanup(false),
@@ -349,7 +349,7 @@ void IncParser::ProcessActions() {
}
a->node->StartNode(*a->inode);
} else {
a->node->ComputeNode(a->action, *a->inode, a->initiator);
a->node->ParseNode(a->action, *a->inode, a->initiator);
}
}
if (m_actions_by_depth.at(depth).empty()) {
@@ -57,7 +57,7 @@ class IncParser {
// Called from a node that's being restarted, to cancel all its listening
void UnlistenAll(STree& x);

// IncParser owns the STree nodes. This allows a ComputeFunc() to "unlink" a
// IncParser owns the STree nodes. This allows a ParseFunc() to "unlink" a
// node from the tree before it is actually deleted, so that an OutputFunc()
// can refer to its destruction safely.
STree* OwnNode(std::auto_ptr<STree> node);
@@ -71,7 +71,7 @@ class IncParser {
// Get the first node of the output list
const List* GetFirstONode() const;

// Indicate that a node has been computed. Called by STree::ComputeNode()
// Indicate that a node has been computed. Called by STree::ParseNode()
void TouchNode(const STree& node);

int INodeCompare(const List& a, const List& b) const;
@@ -104,8 +104,8 @@ class IncParser {
void CleanupIfNeeded();

Rule m_rootRule; // Rule for the Root node
STree m_root; // Root of the output tree
Rule& m_grammar; // Root of the Grammar
STree m_root; // Root of the parse tree
Rule& m_grammar; // Root of the grammar graph
std::string m_name;
bool m_needsCleanup;
std::auto_ptr<Grapher> m_grapher;
@@ -22,22 +22,22 @@ auto_ptr<Rule> statik::KEYWORD(const string& str) {

auto_ptr<Rule> statik::KEYWORD(const string& name, const string& str) {
return auto_ptr<Rule>(new Rule(name,
MakeComputeFunc_Keyword(str),
MakeParseFunc_Keyword(str),
MakeOutputFunc_Basic(name)));
}

auto_ptr<ComputeFunc> statik::MakeComputeFunc_Keyword(const string& str) {
return auto_ptr<ComputeFunc>(new ComputeFunc_Keyword(str));
auto_ptr<ParseFunc> statik::MakeParseFunc_Keyword(const string& str) {
return auto_ptr<ParseFunc>(new ParseFunc_Keyword(str));
}

ComputeFunc_Keyword::ComputeFunc_Keyword(const string& str)
ParseFunc_Keyword::ParseFunc_Keyword(const string& str)
: m_str(str) {
if (m_str.empty()) {
throw SError("Cannot create empty Keyword");
}
}

void ComputeFunc_Keyword::operator() (ParseAction::Action action, const List& inode, const STree* initiator) {
void ParseFunc_Keyword::operator() (ParseAction::Action action, const List& inode, const STree* initiator) {
g_log.info() << "Computing Keyword at " << *m_node << " with inode " << inode;
State& state = m_node->GetState();
state.Clear();
@@ -6,9 +6,9 @@

/* Keyword rule */

#include "ComputeFunc.h"
#include "List.h"
#include "ParseAction.h"
#include "ParseFunc.h"
#include "Rule.h"
#include "STree.h"

@@ -21,20 +21,20 @@ std::auto_ptr<Rule> KEYWORD(const std::string& str);
std::auto_ptr<Rule> KEYWORD(const std::string& name,
const std::string& str);

class ComputeFunc_Keyword : public ComputeFunc {
class ParseFunc_Keyword : public ParseFunc {
public:
ComputeFunc_Keyword(const std::string& str);
virtual ~ComputeFunc_Keyword() {}
ParseFunc_Keyword(const std::string& str);
virtual ~ParseFunc_Keyword() {}
virtual void operator() (ParseAction::Action action, const List& inode, const STree* initiator);
virtual std::auto_ptr<ComputeFunc> Clone() {
return std::auto_ptr<ComputeFunc>(new ComputeFunc_Keyword(m_str));
virtual std::auto_ptr<ParseFunc> Clone() {
return std::auto_ptr<ParseFunc>(new ParseFunc_Keyword(m_str));
}

private:
const std::string m_str;
};

std::auto_ptr<ComputeFunc> MakeComputeFunc_Keyword(const std::string& str);
std::auto_ptr<ParseFunc> MakeParseFunc_Keyword(const std::string& str);

}

@@ -21,15 +21,15 @@ auto_ptr<Rule> statik::META(const string& searchName) {

auto_ptr<Rule> statik::META(const string& name, const string& searchName) {
return auto_ptr<Rule>(new Rule(name,
MakeComputeFunc_Meta(searchName),
MakeParseFunc_Meta(searchName),
MakeOutputFunc_IValues(name)));
}

auto_ptr<ComputeFunc> statik::MakeComputeFunc_Meta(const string& searchName) {
return auto_ptr<ComputeFunc>(new ComputeFunc_Meta(searchName));
auto_ptr<ParseFunc> statik::MakeParseFunc_Meta(const string& searchName) {
return auto_ptr<ParseFunc>(new ParseFunc_Meta(searchName));
}

void ComputeFunc_Meta::operator() (ParseAction::Action action, const List& inode, const STree* initiator) {
void ParseFunc_Meta::operator() (ParseAction::Action action, const List& inode, const STree* initiator) {
g_log.info() << "Computing Meta at " << *m_node << " with inode "<< inode;
State& state = m_node->GetState();
state.Clear();
@@ -9,9 +9,9 @@
* Recognizes a node output by another rule, by its name.
*/

#include "ComputeFunc.h"
#include "List.h"
#include "ParseAction.h"
#include "ParseFunc.h"
#include "Rule.h"
#include "STree.h"

@@ -24,21 +24,21 @@ std::auto_ptr<Rule> META(const std::string& searchName);
std::auto_ptr<Rule> META(const std::string& name,
const std::string& searchName);

class ComputeFunc_Meta : public ComputeFunc {
class ParseFunc_Meta : public ParseFunc {
public:
ComputeFunc_Meta(const std::string& searchName)
ParseFunc_Meta(const std::string& searchName)
: m_searchName(searchName) {}
virtual ~ComputeFunc_Meta() {}
virtual ~ParseFunc_Meta() {}
virtual void operator() (ParseAction::Action action, const List& inode, const STree* initiator);
virtual std::auto_ptr<ComputeFunc> Clone() {
return std::auto_ptr<ComputeFunc>(new ComputeFunc_Meta(m_searchName));
virtual std::auto_ptr<ParseFunc> Clone() {
return std::auto_ptr<ParseFunc>(new ParseFunc_Meta(m_searchName));
}

private:
std::string m_searchName;
};

std::auto_ptr<ComputeFunc> MakeComputeFunc_Meta(const std::string& searchName);
std::auto_ptr<ParseFunc> MakeParseFunc_Meta(const std::string& searchName);

}

@@ -19,18 +19,18 @@ using namespace statik;

auto_ptr<Rule> statik::OR(const string& name) {
return auto_ptr<Rule>(new Rule(name,
MakeComputeFunc_Or(),
MakeParseFunc_Or(),
MakeOutputFunc_Winner()));
}

auto_ptr<ComputeFunc> statik::MakeComputeFunc_Or() {
return auto_ptr<ComputeFunc>(new ComputeFunc_Or());
auto_ptr<ParseFunc> statik::MakeParseFunc_Or() {
return auto_ptr<ParseFunc>(new ParseFunc_Or());
}

// TODO consider initiator, keep vectors as state that gets updated by each
// call to this function, and then we finally just update State from the vecs.
void ComputeFunc_Or::operator() (ParseAction::Action action, const List& inode, const STree* initiator) {
g_log.debug() << "Computing Or at " << *m_node;
void ParseFunc_Or::operator() (ParseAction::Action action, const List& inode, const STree* initiator) {
g_log.debug() << "Parsing Or at " << *m_node;

if (ParseAction::Restart == action) {
if (m_node->children.empty()) {
@@ -62,7 +62,7 @@ void ComputeFunc_Or::operator() (ParseAction::Action action, const List& inode,
const STree* lockedChild = NULL;

if (m_node->children.empty()) {
throw SError("Cannot compute Or at " + string(*m_node) + " that has no children");
throw SError("Cannot parse Or at " + string(*m_node) + " that has no children");
}
m_node->GetIConnection().SetEnd(m_node->IStart());

@@ -79,19 +79,19 @@ void ComputeFunc_Or::operator() (ParseAction::Action action, const List& inode,
bool thisChildLocked = false;
if (istate.IsLocked()) {
if (lockedChild) {
throw SError("Computing Or at " + string(*m_node) + " found more than one locked children");
throw SError("Parsing Or at " + string(*m_node) + " found more than one locked children");
}
g_log.info() << "Computing Or at " << *m_node << " found locked child " << **i << " in state " << istate;
g_log.info() << "Parsing Or at " << *m_node << " found locked child " << **i << " in state " << istate;
lockedChild = *i;
thisChildLocked = true;
state.Lock();
}
if (!istate.IsBad() && !haveSetEnd) {
if (&(*i)->IStart() != &m_node->IStart()) {
throw SError("Computing Or at " + string(*m_node) + " and a child disagree about istart");
throw SError("Parsing Or at " + string(*m_node) + " and a child disagree about istart");
}
m_node->GetIConnection().SetEnd((*i)->IEnd());
g_log.debug() << "Computing Or at " << *m_node << " assigning iend " << m_node->IEnd() << " from istate " << istate;
g_log.debug() << "Parsing Or at " << *m_node << " assigning iend " << m_node->IEnd() << " from istate " << istate;
haveSetEnd = true;
}
if (istate.IsOK()) {
@@ -135,15 +135,15 @@ void ComputeFunc_Or::operator() (ParseAction::Action action, const List& inode,
completes.push_back(*i);
}
} else {
throw SError("Computing Or at " + string(*m_node) + " found istate " + string(istate) + " in unknown station");
throw SError("Parsing Or at " + string(*m_node) + " found istate " + string(istate) + " in unknown station");
}
}
if (1 == completes.size()) {
m_node->GetIConnection().SetEnd(completes.at(0)->IEnd());
g_log.debug() << "Computing Or at " << *m_node << " declares complete winner " << *completes.at(0);
g_log.debug() << "Parsing Or at " << *m_node << " declares complete winner " << *completes.at(0);
} else if (1 == dones.size()) {
m_node->GetIConnection().SetEnd(dones.at(0)->IEnd());
g_log.debug() << "Computing Or at " << *m_node << " declares done winner " << *dones.at(0);
g_log.debug() << "Parsing Or at " << *m_node << " declares done winner " << *dones.at(0);
}
if (1 == completes.size()) {
state.GoComplete();
@@ -4,9 +4,9 @@
#ifndef _statik_Or_h_
#define _statik_Or_h_

#include "ComputeFunc.h"
#include "List.h"
#include "ParseAction.h"
#include "ParseFunc.h"
#include "Rule.h"
#include "STree.h"

@@ -17,15 +17,15 @@ namespace statik {

std::auto_ptr<Rule> OR(const std::string& name);

struct ComputeFunc_Or : public ComputeFunc {
virtual ~ComputeFunc_Or() {}
struct ParseFunc_Or : public ParseFunc {
virtual ~ParseFunc_Or() {}
virtual void operator() (ParseAction::Action action, const List& inode, const STree* initiator);
virtual std::auto_ptr<ComputeFunc> Clone() {
return std::auto_ptr<ComputeFunc>(new ComputeFunc_Or());
virtual std::auto_ptr<ParseFunc> Clone() {
return std::auto_ptr<ParseFunc>(new ParseFunc_Or());
}
};

std::auto_ptr<ComputeFunc> MakeComputeFunc_Or();
std::auto_ptr<ParseFunc> MakeParseFunc_Or();

}

@@ -1,8 +1,8 @@
// Copyright (C) 2014 Michael Biggs. See the COPYING file at the top-level
// directory of this distribution and at http://shok.io/code/copyright.html

#ifndef _statik_ComputeFunc_h_
#define _statik_ComputeFunc_h_
#ifndef _statik_ParseFunc_h_
#define _statik_ParseFunc_h_

#include "List.h"
#include "ParseAction.h"
@@ -11,16 +11,16 @@

namespace statik {

struct ComputeFunc {
struct ParseFunc {
public:
virtual ~ComputeFunc() {}
virtual ~ParseFunc() {}
void Init(STree& x) { m_node = &x; }
virtual void operator() (ParseAction::Action action, const List& inode, const STree* initiator) = 0;
virtual std::auto_ptr<ComputeFunc> Clone() = 0;
virtual std::auto_ptr<ParseFunc> Clone() = 0;
protected:
STree* m_node;
};

}

#endif // _statik_ComputeFunc_h_
#endif // _statik_ParseFunc_h_
@@ -18,22 +18,22 @@ using namespace statik;

auto_ptr<Rule> statik::REGEXP(const string& name, const boost::regex& regex) {
return auto_ptr<Rule>(new Rule(name,
MakeComputeFunc_Regexp(regex),
MakeParseFunc_Regexp(regex),
MakeOutputFunc_IValues(name)));
}

auto_ptr<ComputeFunc> statik::MakeComputeFunc_Regexp(const boost::regex& regex) {
return auto_ptr<ComputeFunc>(new ComputeFunc_Regexp(regex));
auto_ptr<ParseFunc> statik::MakeParseFunc_Regexp(const boost::regex& regex) {
return auto_ptr<ParseFunc>(new ParseFunc_Regexp(regex));
}

ComputeFunc_Regexp::ComputeFunc_Regexp(const boost::regex& regex)
ParseFunc_Regexp::ParseFunc_Regexp(const boost::regex& regex)
: m_regex(regex) {
if (m_regex.empty()) {
throw SError("Cannot create Regexp with empty regex");
}
}

void ComputeFunc_Regexp::operator() (ParseAction::Action action, const List& inode, const STree* initiator) {
void ParseFunc_Regexp::operator() (ParseAction::Action action, const List& inode, const STree* initiator) {
g_log.info() << "Computing Regexp at " << *m_node;
State& state = m_node->GetState();
state.Clear();
@@ -6,9 +6,9 @@

/* Regexp rule */

#include "ComputeFunc.h"
#include "List.h"
#include "ParseAction.h"
#include "ParseFunc.h"
#include "Rule.h"
#include "STree.h"

@@ -22,20 +22,20 @@ namespace statik {
std::auto_ptr<Rule> REGEXP(const std::string& name,
const boost::regex& regex);

class ComputeFunc_Regexp : public ComputeFunc {
class ParseFunc_Regexp : public ParseFunc {
public:
ComputeFunc_Regexp(const boost::regex& regex);
virtual ~ComputeFunc_Regexp() {}
ParseFunc_Regexp(const boost::regex& regex);
virtual ~ParseFunc_Regexp() {}
virtual void operator() (ParseAction::Action action, const List& inode, const STree* initiator);
virtual std::auto_ptr<ComputeFunc> Clone() {
return std::auto_ptr<ComputeFunc>(new ComputeFunc_Regexp(m_regex));
virtual std::auto_ptr<ParseFunc> Clone() {
return std::auto_ptr<ParseFunc>(new ParseFunc_Regexp(m_regex));
}

private:
const boost::regex m_regex;
};

std::auto_ptr<ComputeFunc> MakeComputeFunc_Regexp(const boost::regex& regex);
std::auto_ptr<ParseFunc> MakeParseFunc_Regexp(const boost::regex& regex);

}

0 comments on commit 725bcfe

Please sign in to comment.
You can’t perform that action at this time.