From b78ea37a6f8d289b9adb2b5bc565716168a00060 Mon Sep 17 00:00:00 2001 From: Mike Buland Date: Tue, 22 Aug 2006 05:04:16 +0000 Subject: The basic outline for all of the initial functions and rules has been set. The parser and scanner are using the new system so they actually match functions and whatnot and pass that data to the parser, it's very cool. --- src/build.l | 33 +++++++++++++-------------------- src/build.y | 27 ++++++++++++++++----------- src/builder.cpp | 38 +++++++++++++++++++++++++++++++++++--- src/builder.h | 32 +++++++++++++++++++++++++++++++- src/function.cpp | 9 +++++++++ src/function.h | 17 +++++++++++++++++ src/functioncommandtolist.cpp | 12 ++++++++++++ src/functioncommandtolist.h | 18 ++++++++++++++++++ src/functiondirectoriesin.cpp | 12 ++++++++++++ src/functiondirectoriesin.h | 18 ++++++++++++++++++ src/functionfactory.cpp | 20 ++++++++++++++++++++ src/functionfactory.h | 20 ++++++++++++++++++++ src/functionfilesin.cpp | 12 ++++++++++++ src/functionfilesin.h | 18 ++++++++++++++++++ src/functionregexp.cpp | 12 ++++++++++++ src/functionregexp.h | 18 ++++++++++++++++++ src/functiontostring.cpp | 12 ++++++++++++ src/functiontostring.h | 18 ++++++++++++++++++ src/perform.cpp | 9 +++++++++ src/perform.h | 17 +++++++++++++++++ src/performcommand.cpp | 12 ++++++++++++ src/performcommand.h | 18 ++++++++++++++++++ src/performfactory.cpp | 12 ++++++++++++ src/performfactory.h | 20 ++++++++++++++++++++ 24 files changed, 399 insertions(+), 35 deletions(-) create mode 100644 src/function.cpp create mode 100644 src/function.h create mode 100644 src/functioncommandtolist.cpp create mode 100644 src/functioncommandtolist.h create mode 100644 src/functiondirectoriesin.cpp create mode 100644 src/functiondirectoriesin.h create mode 100644 src/functionfactory.cpp create mode 100644 src/functionfactory.h create mode 100644 src/functionfilesin.cpp create mode 100644 src/functionfilesin.h create mode 100644 src/functionregexp.cpp create mode 100644 src/functionregexp.h create mode 100644 src/functiontostring.cpp create mode 100644 src/functiontostring.h create mode 100644 src/perform.cpp create mode 100644 src/perform.h create mode 100644 src/performcommand.cpp create mode 100644 src/performcommand.h create mode 100644 src/performfactory.cpp create mode 100644 src/performfactory.h (limited to 'src') diff --git a/src/build.l b/src/build.l index 8189f9d..aab7de1 100644 --- a/src/build.l +++ b/src/build.l @@ -7,7 +7,6 @@ std::string strbuf; %} -%x regexp %x strsq %x strdq %x comment @@ -33,6 +32,8 @@ std::string strbuf; "clean" return TOK_CLEAN; "target" return TOK_TARGET; "input" return TOK_INPUT; +"filter" return TOK_FILTER; +"prefix" return TOK_PREFIX; \n+ { yylloc->last_line += yyleng; @@ -45,19 +46,6 @@ std::string strbuf; yylloc->first_column = yylloc->last_column+1; } -"/" { - BEGIN( regexp ); - strbuf = ""; -} -[^\n/\\]* strbuf += yytext; -"\\/" strbuf += "/"; -"\\" strbuf += "\\"; -"/" { - BEGIN( INITIAL ); - yylval->strval = stringdup( strbuf.c_str() ); - return REGEXP; -} - "#".* /* single line comment */ [a-zA-Z][a-zA-Z0-9]* { @@ -67,6 +55,11 @@ std::string strbuf; { return TARGETTYPE; } + else if( bld.isPerform( yytext ) ) + { + yylval->strval = stringdup( yytext ); + return PERFORM; + } else if( bld.isFunction( yytext ) ) { yylval->strval = stringdup( yytext ); @@ -76,11 +69,6 @@ std::string strbuf; } } -[^ \t\r\n\'\":=,/][^ \t\r\n\'\"=,]+[^ \t\r\n\'\":=,] { - yylval->strval = stringdup( yytext ); - return STRING; -} - \" { BEGIN( strdq ); strbuf = ""; @@ -103,6 +91,9 @@ std::string strbuf; \\r strbuf += "\r"; \\b strbuf += "\b"; \\f strbuf += "\f"; +\\\\ strbuf += "\\"; +\\\" strbuf += "\""; +\\\' strbuf += "\'"; \" { BEGIN( INITIAL ); @@ -117,7 +108,9 @@ std::string strbuf; } . { - bld.error( yylloc, "Invalid character found!" ); + char buf[] = {"Character x is out of place"}; + buf[10] = yytext[0]; + bld.error( yylloc, "Character !" ); } %% diff --git a/src/build.y b/src/build.y index 5580299..1621dbc 100644 --- a/src/build.y +++ b/src/build.y @@ -20,9 +20,9 @@ void yyerror( YYLTYPE *locp, Builder &bld, char const *msg ); } %token STRING "string literal" -%token REGEXP "regular expression" %token TARGETTYPE "target type" %token FUNCTION "function name" +%token PERFORM "perform name" %token TOK_ADDSET "+=" %token TOK_DEFAULT "default" @@ -61,12 +61,11 @@ rulecmds: rulecmd | rulecmds ',' rulecmd ; -rulecmd: TOK_MATCHES REGEXP { printf(" Matches: %s\n", $2 ); } +rulecmd: TOK_MATCHES { printf(" Matches: " ); } func | TOK_PRODUCES STRING { printf(" Produces: %s\n", $2 ); } | TOK_REQUIRES { printf(" Requires:\n"); } list {printf("\n");} - | TOK_INPUT TOK_FILTER REGEXP { printf(" Input Filter: %s\n", $3 ); } | TOK_INPUT TOK_FILTER { printf(" Input Filter: "); } func {printf("\n");} - | TOK_PERFORM { printf(" Perform: "); } func {printf("\n");} + | TOK_PERFORM { printf(" Perform: "); } perf {printf("\n");} ; // Action interpretation @@ -78,7 +77,7 @@ actioncmds: actioncmd | actioncmds ',' actioncmd ; -actioncmd: { printf("\t"); } actioncmdtype list {printf("\n");} +actioncmd: { printf(" "); } actioncmdtype list {printf("\n");} ; actioncmdtype: TOK_CHECK { printf("check "); } @@ -97,6 +96,7 @@ targetcmd: TOK_RULE STRING { printf(" Rule %s\n", $2 ); } | TOK_TARGET TOK_PREFIX STRING { printf(" Target prefix: %s\n", $3 ); } | TOK_TARGET TARGETTYPE { printf(" Target Type: %d\n", $2 ); } | TOK_INPUT { printf(" Input: "); } list { printf("\n"); } + | TOK_INPUT TOK_FILTER { printf(" Input filter: "); } func | TOK_REQUIRES { printf(" Requires: "); } list { printf("\n"); } | TOK_SET { printf(" Set: "); } targetset ; @@ -106,26 +106,23 @@ targetset: STRING '=' STRING { printf("%s = %s\n", $1, $3 ); } ; // list goo - list: listitem listfilter | '[' { printf("["); } listitems ']' { printf("]"); } listfilter ; listfilter: - | TOK_FILTER REGEXP - | TOK_FILTER func + | TOK_FILTER { printf(" filtered by "); } func ; listitems: listitem - | listitems ',' {printf(", "); } listitem + | listitems ',' { printf(", "); } listitem ; -listitem: STRING {printf("%s", $1 ); } +listitem: STRING { printf("%s", $1 ); } | func ; // Function - func: FUNCTION { printf("%s(", $1 ); } '(' funcparams ')' { printf(")"); } ; @@ -134,6 +131,14 @@ funcparams: | funcparams ',' STRING { printf(", %s", $3 ); } ; +// Perform +perf: PERFORM { printf("%s(", $1 ); } '(' perfparams ')' { printf(")"); } + ; + +perfparams: + | STRING { printf("%s", $1 ); } + | perfparams ',' STRING { printf(", %s", $3 ); } + ; %% void yyerror( YYLTYPE *locp, Builder &bld, char const *msg ) diff --git a/src/builder.cpp b/src/builder.cpp index b6ae887..24e4536 100644 --- a/src/builder.cpp +++ b/src/builder.cpp @@ -1,8 +1,12 @@ #include "builder.h" +#include "functionfactory.h" +#include "performfactory.h" subExceptionDef( BuildException ); -Builder::Builder() +Builder::Builder() : + fFunction( FunctionFactory::getInstance() ), + fPerform( PerformFactory::getInstance() ) { } @@ -17,7 +21,7 @@ void Builder::load( const std::string &sFile ) { file = sFile; scanBegin(); - yydebug = 1; + //yydebug = 1; yyparse( *this ); scanEnd(); } @@ -45,8 +49,36 @@ int Builder::getTargetType( const char *sType ) return -1; } +// +// Function functions +// bool Builder::isFunction( const char *sFunc ) { - return true; + return fFunction.hasPlugin( sFunc ); +} + +void Builder::newFunctionCall( const char *sName ) +{ + +} + +void Builder::addFunctionParam( const char *sParam ) +{ +} + +// +// Perform functions +// +bool Builder::isPerform( const char *sPerf ) +{ + return fPerform.hasPlugin( sPerf ); +} + +void Builder::newPerform( const char *sName ) +{ +} + +void Builder::addPerformParam( const char *sParam ) +{ } diff --git a/src/builder.h b/src/builder.h index 3293108..529edc6 100644 --- a/src/builder.h +++ b/src/builder.h @@ -7,6 +7,10 @@ #include "exceptions.h" class Builder; +class Function; +class FunctionFactory; +class Perform; +class PerformFactory; #define YY_DECL int yylex( YYSTYPE *yylval_param, YYLTYPE *yylloc_param, Builder &bld ) YY_DECL; @@ -25,13 +29,39 @@ public: void load( const std::string &sFile ); int getTargetType( const char *sType ); - bool isFunction( const char *sFunc ); private: std::string file; void scanBegin(); void scanEnd(); +public: // Function functions + bool isFunction( const char *sFunc ); + void newFunctionCall( const char *sName ); + void addFunctionParam( const char *sParam ); + +private: // Function variables + Function *pTmpFunc; + FunctionFactory &fFunction; + +public: // Perform functions + bool isPerform( const char *sPerf ); + void newPerform( const char *sName ); + void addPerformParam( const char *sParam ); + +private: // Perform variables + Perform *pTmpPerform; + PerformFactory &fPerform; + +public: // List functions + void newList(); + void addListString( const char *str ); + void addListFunc(); + +public: // Functions for dealing with rules + void addAction(); + void addAction( const char *sName ); + void addCommand( int nType ); }; #endif diff --git a/src/function.cpp b/src/function.cpp new file mode 100644 index 0000000..5eeac97 --- /dev/null +++ b/src/function.cpp @@ -0,0 +1,9 @@ +#include "function.h" + +Function::Function() +{ +} + +Function::~Function() +{ +} diff --git a/src/function.h b/src/function.h new file mode 100644 index 0000000..44a894d --- /dev/null +++ b/src/function.h @@ -0,0 +1,17 @@ +#ifndef FUNCTION_H +#define FUNCTION_H + +#include + + +class Function +{ +public: + Function(); + virtual ~Function(); + +private: + +}; + +#endif diff --git a/src/functioncommandtolist.cpp b/src/functioncommandtolist.cpp new file mode 100644 index 0000000..8d18870 --- /dev/null +++ b/src/functioncommandtolist.cpp @@ -0,0 +1,12 @@ +#include "functioncommandtolist.h" +#include "plugger.h" + +PluginInterface2(commandToList, FunctionCommandToList, Function, "Mike Buland", 0, 1 ); + +FunctionCommandToList::FunctionCommandToList() +{ +} + +FunctionCommandToList::~FunctionCommandToList() +{ +} diff --git a/src/functioncommandtolist.h b/src/functioncommandtolist.h new file mode 100644 index 0000000..90b4bf3 --- /dev/null +++ b/src/functioncommandtolist.h @@ -0,0 +1,18 @@ +#ifndef FUNCTION_COMMAND_TO_LIST_H +#define FUNCTION__H + +#include + +#include "function.h" + +class FunctionCommandToList : public Function +{ +public: + FunctionCommandToList(); + virtual ~FunctionCommandToList(); + +private: + +}; + +#endif diff --git a/src/functiondirectoriesin.cpp b/src/functiondirectoriesin.cpp new file mode 100644 index 0000000..f847e13 --- /dev/null +++ b/src/functiondirectoriesin.cpp @@ -0,0 +1,12 @@ +#include "functiondirectoriesin.h" +#include "plugger.h" + +PluginInterface2(directoriesIn, FunctionDirectoriesIn, Function, "Mike Buland", 0, 1 ); + +FunctionDirectoriesIn::FunctionDirectoriesIn() +{ +} + +FunctionDirectoriesIn::~FunctionDirectoriesIn() +{ +} diff --git a/src/functiondirectoriesin.h b/src/functiondirectoriesin.h new file mode 100644 index 0000000..5f6ee42 --- /dev/null +++ b/src/functiondirectoriesin.h @@ -0,0 +1,18 @@ +#ifndef FUNCTION_DIRECTORIES_IN_H +#define FUNCTION_DIRECTORIES_IN_H + +#include + +#include "function.h" + +class FunctionDirectoriesIn : public Function +{ +public: + FunctionDirectoriesIn(); + virtual ~FunctionDirectoriesIn(); + +private: + +}; + +#endif diff --git a/src/functionfactory.cpp b/src/functionfactory.cpp new file mode 100644 index 0000000..b78cfcb --- /dev/null +++ b/src/functionfactory.cpp @@ -0,0 +1,20 @@ +#include "functionfactory.h" + +extern struct PluginInfo directoriesIn; +extern struct PluginInfo filesIn; +extern struct PluginInfo regexp; +extern struct PluginInfo toString; +extern struct PluginInfo commandToList; + +FunctionFactory::FunctionFactory() +{ + registerBuiltinPlugin( &directoriesIn ); + registerBuiltinPlugin( &filesIn ); + registerBuiltinPlugin( ®exp ); + registerBuiltinPlugin( &toString ); + registerBuiltinPlugin( &commandToList ); +} + +FunctionFactory::~FunctionFactory() +{ +} diff --git a/src/functionfactory.h b/src/functionfactory.h new file mode 100644 index 0000000..0541143 --- /dev/null +++ b/src/functionfactory.h @@ -0,0 +1,20 @@ +#ifndef FUNCTION_FACTORY_H +#define FUNCTION_FACTORY_H + +#include + +#include "plugger.h" +#include "singleton.h" +#include "function.h" + +class FunctionFactory : public Plugger, public Singleton +{ +public: + FunctionFactory(); + virtual ~FunctionFactory(); + +private: + +}; + +#endif diff --git a/src/functionfilesin.cpp b/src/functionfilesin.cpp new file mode 100644 index 0000000..3a9d163 --- /dev/null +++ b/src/functionfilesin.cpp @@ -0,0 +1,12 @@ +#include "functionfilesin.h" +#include "plugger.h" + +PluginInterface2(filesIn, FunctionFilesIn, Function, "Mike Buland", 0, 1 ); + +FunctionFilesIn::FunctionFilesIn() +{ +} + +FunctionFilesIn::~FunctionFilesIn() +{ +} diff --git a/src/functionfilesin.h b/src/functionfilesin.h new file mode 100644 index 0000000..070f508 --- /dev/null +++ b/src/functionfilesin.h @@ -0,0 +1,18 @@ +#ifndef FUNCTION_FILES_IN_H +#define FUNCTION_FILES_IN_H + +#include + +#include "function.h" + +class FunctionFilesIn : public Function +{ +public: + FunctionFilesIn(); + virtual ~FunctionFilesIn(); + +private: + +}; + +#endif diff --git a/src/functionregexp.cpp b/src/functionregexp.cpp new file mode 100644 index 0000000..fd632ae --- /dev/null +++ b/src/functionregexp.cpp @@ -0,0 +1,12 @@ +#include "functionregexp.h" +#include "plugger.h" + +PluginInterface2(regexp, FunctionRegexp, Function, "Mike Buland", 0, 1 ); + +FunctionRegexp::FunctionRegexp() +{ +} + +FunctionRegexp::~FunctionRegexp() +{ +} diff --git a/src/functionregexp.h b/src/functionregexp.h new file mode 100644 index 0000000..0adaf97 --- /dev/null +++ b/src/functionregexp.h @@ -0,0 +1,18 @@ +#ifndef FUNCTION_REGEXP_H +#define FUNCTION_REGEXP_H + +#include + +#include "function.h" + +class FunctionRegexp : public Function +{ +public: + FunctionRegexp(); + virtual ~FunctionRegexp(); + +private: + +}; + +#endif diff --git a/src/functiontostring.cpp b/src/functiontostring.cpp new file mode 100644 index 0000000..93a8b56 --- /dev/null +++ b/src/functiontostring.cpp @@ -0,0 +1,12 @@ +#include "functiontostring.h" +#include "plugger.h" + +PluginInterface2(toString, FunctionToString, Function, "Mike Buland", 0, 1 ); + +FunctionToString::FunctionToString() +{ +} + +FunctionToString::~FunctionToString() +{ +} diff --git a/src/functiontostring.h b/src/functiontostring.h new file mode 100644 index 0000000..08baadd --- /dev/null +++ b/src/functiontostring.h @@ -0,0 +1,18 @@ +#ifndef FUNCTION_TO_STRING_H +#define FUNCTION_TO_STRING_H + +#include + +#include "function.h" + +class FunctionToString : public Function +{ +public: + FunctionToString(); + virtual ~FunctionToString(); + +private: + +}; + +#endif diff --git a/src/perform.cpp b/src/perform.cpp new file mode 100644 index 0000000..937a76c --- /dev/null +++ b/src/perform.cpp @@ -0,0 +1,9 @@ +#include "perform.h" + +Perform::Perform() +{ +} + +Perform::~Perform() +{ +} diff --git a/src/perform.h b/src/perform.h new file mode 100644 index 0000000..0b6a16d --- /dev/null +++ b/src/perform.h @@ -0,0 +1,17 @@ +#ifndef PERFORM_H +#define PERFORM_H + +#include + + +class Perform +{ +public: + Perform(); + virtual ~Perform(); + +private: + +}; + +#endif diff --git a/src/performcommand.cpp b/src/performcommand.cpp new file mode 100644 index 0000000..7c7dd42 --- /dev/null +++ b/src/performcommand.cpp @@ -0,0 +1,12 @@ +#include "performcommand.h" +#include "plugger.h" + +PluginInterface2(command, PerformCommand, Perform, "Mike Buland", 0, 1 ); + +PerformCommand::PerformCommand() +{ +} + +PerformCommand::~PerformCommand() +{ +} diff --git a/src/performcommand.h b/src/performcommand.h new file mode 100644 index 0000000..219ae28 --- /dev/null +++ b/src/performcommand.h @@ -0,0 +1,18 @@ +#ifndef PERFORM_COMMAND_H +#define PERFORM_COMMAND_H + +#include + +#include "perform.h" + +class PerformCommand : public Perform +{ +public: + PerformCommand(); + virtual ~PerformCommand(); + +private: + +}; + +#endif diff --git a/src/performfactory.cpp b/src/performfactory.cpp new file mode 100644 index 0000000..6c7d57a --- /dev/null +++ b/src/performfactory.cpp @@ -0,0 +1,12 @@ +#include "performfactory.h" + +extern struct PluginInfo command; + +PerformFactory::PerformFactory() +{ + registerBuiltinPlugin( &command ); +} + +PerformFactory::~PerformFactory() +{ +} diff --git a/src/performfactory.h b/src/performfactory.h new file mode 100644 index 0000000..f5ce5c0 --- /dev/null +++ b/src/performfactory.h @@ -0,0 +1,20 @@ +#ifndef PERFORM_FACTORY_H +#define PERFORM_FACTORY_H + +#include + +#include "perform.h" +#include "plugger.h" +#include "singleton.h" + +class PerformFactory : public Plugger, public Singleton +{ +public: + PerformFactory(); + virtual ~PerformFactory(); + +private: + +}; + +#endif -- cgit v1.2.3