From 28e92029752693ffe33de12c10de3e7bd39a3c94 Mon Sep 17 00:00:00 2001 From: Mike Buland Date: Sun, 30 Jul 2006 03:28:46 +0000 Subject: Figured out a format I like, we'll see what happens. --- congo | 26 +++++++++++++------------- regexptest.cpp | 47 +++++++++++++++++++++++++++++++++++++++++++++++ src/build.l | 31 +++++++++++++++++++++++++++++++ src/build.y | 0 src/lexer.flex | 13 ------------- 5 files changed, 91 insertions(+), 26 deletions(-) create mode 100644 regexptest.cpp create mode 100644 src/build.l create mode 100644 src/build.y delete mode 100644 src/lexer.flex diff --git a/congo b/congo index 336a196..ddf7e7b 100644 --- a/congo +++ b/congo @@ -1,16 +1,16 @@ -target( all ) -{ - build( congo ); - build( congod ); -} +default action: create congo, congod -target( congo ) -{ - type = executable; - linker = c++; - - uses( src/congo ); - uses( src/congod ); -} +create file congod from files in src/congod using rule exe +create file congo from files in src/congo using rule exe +congod requires libcongo.a +congo requires libcongo.a + +set CXXFLAGS += "-Ilibbu++/src" +set LDFLAGS += "-Llibbu++ -lbu++" + +for congo set LDFLAGS += "-lreadline" + +rule exe matches all /(.*)\.o/ perform command "g++ {matches} {LDFLAGS} -o {target}" +rule cpp matches one /(.*)\.cpp/ produces {1}.o perform command "g++ {CXXFLAGS} -o {target} {match}" diff --git a/regexptest.cpp b/regexptest.cpp new file mode 100644 index 0000000..01597be --- /dev/null +++ b/regexptest.cpp @@ -0,0 +1,47 @@ +#include +#include +#include + +int test( const char *str, const char *sRegExp ) +{ + printf("Compiling: %s\n", sRegExp ); + regex_t r; + if( regcomp( &r, sRegExp, REG_EXTENDED|REG_NEWLINE ) ) + { + printf("Error compiling regular expression.\n"); + return 0; + } + + printf("Compiled, %d sub expressions.\n", r.re_nsub ); + + int nMatch = r.re_nsub+1; + regmatch_t *match = new regmatch_t[nMatch]; + if( regexec( &r, str, nMatch, match, 0 ) ) + { + printf("Regular expression did not match.\n"); + return 0; + } + + printf("Match!\nSubstrings:\n"); + for( int j = 0; j < nMatch; j++ ) + { + printf(" %d: (%d-%d) %s\n", + j, + match[j].rm_so, match[j].rm_eo, + std::string(str+match[j].rm_so, match[j].rm_eo-match[j].rm_so ).c_str() + ); + } + + delete[] match; + regfree( &r ); +} + +int main( int argc, char *argv[] ) +{ + printf("Regular expression test:\n\n"); + + test( argv[1], argv[2] ); + + return 0; +} + diff --git a/src/build.l b/src/build.l new file mode 100644 index 0000000..6daaa94 --- /dev/null +++ b/src/build.l @@ -0,0 +1,31 @@ + int lineNum = 1; +%% + +[,:=] return yytext[0]; +"+=" return TOK_ADDSET; + +"default" return TOK_DEFAULT; +"action" return TOK_ACTION; +"create" return TOK_CREATE; +"file" return TOK_FILE; +"from" return TOK_FROM; +"files" return TOK_FILES; +"in" return TOK_IN; +"using" return TOK_USING; +"rule" return TOK_RULE; +"requires" return TOK_REQUIRES; +"for" return TOK_FOR; +"set" return TOK_SET; +"matches" return TOK_MATCHES; +"all" return TOK_ALL; +"one" return TOK_ONE; +"perform" return TOK_PERFORM; +"produces" return TOK_PRODUCES; +"command" return TOK_COMMAND; + +\n+ return TOX_EOL; +[ \t\r]* + +\/\/.* +"#".* + diff --git a/src/build.y b/src/build.y new file mode 100644 index 0000000..e69de29 diff --git a/src/lexer.flex b/src/lexer.flex deleted file mode 100644 index 508a50c..0000000 --- a/src/lexer.flex +++ /dev/null @@ -1,13 +0,0 @@ - int lineNum = 1; -%% - -"="|"("|")"|"{"|"}"|";"|"," return yytext[0]; -"==" return TOK_COMPARE; -"target" return TOK_TARGET; - -\n ++lineNum; -[ \t\r]* - -\/\/.* -"#".* - -- cgit v1.2.3