From 448b26a7673b7d3b005d47f672d4b14d3aba1b0e Mon Sep 17 00:00:00 2001 From: Josh Holtrop Date: Fri, 9 Apr 2010 17:40:31 -0400 Subject: [PATCH] added RuleDefinition class --- Parser.h | 6 ++++++ RuleDefinition.cc | 9 +++++++++ RuleDefinition.h | 16 ++++++++++++++++ parse-input.cc | 12 +++++++++++- 4 files changed, 42 insertions(+), 1 deletion(-) create mode 100644 RuleDefinition.cc create mode 100644 RuleDefinition.h diff --git a/Parser.h b/Parser.h index 5687764..eee88d9 100644 --- a/Parser.h +++ b/Parser.h @@ -6,6 +6,7 @@ #include "refptr/refptr.h" #include "TokenDefinition.h" +#include "RuleDefinition.h" class Parser { @@ -15,9 +16,14 @@ class Parser { m_tokens.push_back(td); } + void addRuleDefinition(refptr rd) + { + m_rules.push_back(rd); + } protected: std::vector< refptr< TokenDefinition > > m_tokens; + std::vector< refptr< RuleDefinition > > m_rules; }; #endif diff --git a/RuleDefinition.cc b/RuleDefinition.cc new file mode 100644 index 0000000..aac4d2c --- /dev/null +++ b/RuleDefinition.cc @@ -0,0 +1,9 @@ + +#include "RuleDefinition.h" + +using namespace std; + +bool RuleDefinition::create(const string & name, const string & definition) +{ + m_name = name; +} diff --git a/RuleDefinition.h b/RuleDefinition.h new file mode 100644 index 0000000..b9c82c0 --- /dev/null +++ b/RuleDefinition.h @@ -0,0 +1,16 @@ + +#ifndef RULEDEFINITION_H +#define RULEDEFINITION_H + +#include + +class RuleDefinition +{ + public: + bool create(const std::string & name, const std::string & definition); + + protected: + std::string m_name; +}; + +#endif diff --git a/parse-input.cc b/parse-input.cc index 37ad7ed..67c136c 100644 --- a/parse-input.cc +++ b/parse-input.cc @@ -153,7 +153,17 @@ bool parse_input(char * buff, int size, Parser & parser) string name(line, ovector[2], ovector[3] - ovector[2]); string definition(line, ovector[4], ovector[5] - ovector[4]); - /* TODO: process rule */ + refptr rd = new RuleDefinition(); + if (rd->create(name, definition)) + { + parser.addRuleDefinition(rd); + } + else + { + cerr << "Error in rule definition ending on line " + << lineno << endl; + return false; + } } else {