From c41af88a8a3dcd3e9e0ea6dcbe7df9e71eb4eedd Mon Sep 17 00:00:00 2001 From: Mike Buland Date: Mon, 28 Aug 2006 18:51:25 +0000 Subject: Finished getting everything to build with the new changes. Parser is now the generic base class for anything that could create a build object. --- src/buildparser.cpp | 16 ---------------- src/buildparser.h | 7 ++----- src/parser.cpp | 27 +++++++++++++++++++++++++++ src/parser.h | 40 ++++++++++++++++++++++++++++++++++++++++ 4 files changed, 69 insertions(+), 21 deletions(-) create mode 100644 src/parser.cpp create mode 100644 src/parser.h diff --git a/src/buildparser.cpp b/src/buildparser.cpp index cb285d4..7903e04 100644 --- a/src/buildparser.cpp +++ b/src/buildparser.cpp @@ -31,22 +31,6 @@ Build *BuildParser::load( const std::string &sFile ) return genBuild(); } -void BuildParser::error( YYLTYPE *locp, const char *msg ) -{ - fflush( stdout ); - throw BuildException("%s: %d.%d-%d.%d: %s", - file.c_str(), - locp->first_line, locp->first_column, - locp->last_line, locp->last_column, - msg ); -} - -void BuildParser::error( const std::string &msg ) -{ - fflush( stdout ); - throw BuildException("%s", msg.c_str() ); -} - // // Target functions // diff --git a/src/buildparser.h b/src/buildparser.h index 642cc73..2e1924c 100644 --- a/src/buildparser.h +++ b/src/buildparser.h @@ -6,6 +6,7 @@ #include #include #include "build.tab.h" +#include "parser.h" class Build; class BuildParser; @@ -46,7 +47,7 @@ enum eSetHow setAdd }; -class BuildParser +class BuildParser : public Parser { typedef std::pair BuildListItem; typedef std::list BuildList; @@ -56,13 +57,9 @@ public: BuildParser(); virtual ~BuildParser(); - void error( YYLTYPE *locp, const char *msg ); - void error( const std::string &msg ); - Build *load( const std::string &sFile ); private: - std::string file; void scanBegin(); void scanEnd(); diff --git a/src/parser.cpp b/src/parser.cpp new file mode 100644 index 0000000..d9fd2d0 --- /dev/null +++ b/src/parser.cpp @@ -0,0 +1,27 @@ +#include "parser.h" +#include "build.h" + +Parser::Parser() +{ +} + +Parser::~Parser() +{ +} + +void Parser::error( YYLTYPE *locp, const char *msg ) +{ + fflush( stdout ); + throw BuildException("%s: %d.%d-%d.%d: %s", + file.c_str(), + locp->first_line, locp->first_column, + locp->last_line, locp->last_column, + msg ); +} + +void Parser::error( const std::string &msg ) +{ + fflush( stdout ); + throw BuildException("%s", msg.c_str() ); +} + diff --git a/src/parser.h b/src/parser.h new file mode 100644 index 0000000..675e28b --- /dev/null +++ b/src/parser.h @@ -0,0 +1,40 @@ +#ifndef PARSER_H +#define PARSER_H + +#include +#include + +class Build; + +#if ! defined (YYLTYPE) && ! defined (YYLTYPE_IS_DECLARED) +typedef struct YYLTYPE +{ + int first_line; + int first_column; + int last_line; + int last_column; +} YYLTYPE; +# define yyltype YYLTYPE /* obsolescent; will be withdrawn */ +# define YYLTYPE_IS_DECLARED 1 +# define YYLTYPE_IS_TRIVIAL 1 +#endif + +class Parser +{ +public: + Parser(); + virtual ~Parser(); + + virtual void error( YYLTYPE *locp, const char *msg ); + virtual void error( const std::string &msg ); + + virtual Build *load( const std::string &sFile ) = 0; + +protected: + std::string file; + +private: + +}; + +#endif -- cgit v1.2.3