diff options
| -rw-r--r-- | congo | 26 | ||||
| -rw-r--r-- | regexptest.cpp | 47 | ||||
| -rw-r--r-- | src/build.l | 31 | ||||
| -rw-r--r-- | src/build.y | 0 | ||||
| -rw-r--r-- | src/lexer.flex | 13 |
5 files changed, 91 insertions, 26 deletions
| @@ -1,16 +1,16 @@ | |||
| 1 | 1 | ||
| 2 | target( all ) | 2 | default action: create congo, congod |
| 3 | { | ||
| 4 | build( congo ); | ||
| 5 | build( congod ); | ||
| 6 | } | ||
| 7 | 3 | ||
| 8 | target( congo ) | 4 | create file congod from files in src/congod using rule exe |
| 9 | { | 5 | create file congo from files in src/congo using rule exe |
| 10 | type = executable; | ||
| 11 | linker = c++; | ||
| 12 | |||
| 13 | uses( src/congo ); | ||
| 14 | uses( src/congod ); | ||
| 15 | } | ||
| 16 | 6 | ||
| 7 | congod requires libcongo.a | ||
| 8 | congo requires libcongo.a | ||
| 9 | |||
| 10 | set CXXFLAGS += "-Ilibbu++/src" | ||
| 11 | set LDFLAGS += "-Llibbu++ -lbu++" | ||
| 12 | |||
| 13 | for congo set LDFLAGS += "-lreadline" | ||
| 14 | |||
| 15 | rule exe matches all /(.*)\.o/ perform command "g++ {matches} {LDFLAGS} -o {target}" | ||
| 16 | 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 @@ | |||
| 1 | #include <stdio.h> | ||
| 2 | #include <regex.h> | ||
| 3 | #include <string> | ||
| 4 | |||
| 5 | int test( const char *str, const char *sRegExp ) | ||
| 6 | { | ||
| 7 | printf("Compiling: %s\n", sRegExp ); | ||
| 8 | regex_t r; | ||
| 9 | if( regcomp( &r, sRegExp, REG_EXTENDED|REG_NEWLINE ) ) | ||
| 10 | { | ||
| 11 | printf("Error compiling regular expression.\n"); | ||
| 12 | return 0; | ||
| 13 | } | ||
| 14 | |||
| 15 | printf("Compiled, %d sub expressions.\n", r.re_nsub ); | ||
| 16 | |||
| 17 | int nMatch = r.re_nsub+1; | ||
| 18 | regmatch_t *match = new regmatch_t[nMatch]; | ||
| 19 | if( regexec( &r, str, nMatch, match, 0 ) ) | ||
| 20 | { | ||
| 21 | printf("Regular expression did not match.\n"); | ||
| 22 | return 0; | ||
| 23 | } | ||
| 24 | |||
| 25 | printf("Match!\nSubstrings:\n"); | ||
| 26 | for( int j = 0; j < nMatch; j++ ) | ||
| 27 | { | ||
| 28 | printf(" %d: (%d-%d) %s\n", | ||
| 29 | j, | ||
| 30 | match[j].rm_so, match[j].rm_eo, | ||
| 31 | std::string(str+match[j].rm_so, match[j].rm_eo-match[j].rm_so ).c_str() | ||
| 32 | ); | ||
| 33 | } | ||
| 34 | |||
| 35 | delete[] match; | ||
| 36 | regfree( &r ); | ||
| 37 | } | ||
| 38 | |||
| 39 | int main( int argc, char *argv[] ) | ||
| 40 | { | ||
| 41 | printf("Regular expression test:\n\n"); | ||
| 42 | |||
| 43 | test( argv[1], argv[2] ); | ||
| 44 | |||
| 45 | return 0; | ||
| 46 | } | ||
| 47 | |||
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 @@ | |||
| 1 | int lineNum = 1; | ||
| 2 | %% | ||
| 3 | |||
| 4 | [,:=] return yytext[0]; | ||
| 5 | "+=" return TOK_ADDSET; | ||
| 6 | |||
| 7 | "default" return TOK_DEFAULT; | ||
| 8 | "action" return TOK_ACTION; | ||
| 9 | "create" return TOK_CREATE; | ||
| 10 | "file" return TOK_FILE; | ||
| 11 | "from" return TOK_FROM; | ||
| 12 | "files" return TOK_FILES; | ||
| 13 | "in" return TOK_IN; | ||
| 14 | "using" return TOK_USING; | ||
| 15 | "rule" return TOK_RULE; | ||
| 16 | "requires" return TOK_REQUIRES; | ||
| 17 | "for" return TOK_FOR; | ||
| 18 | "set" return TOK_SET; | ||
| 19 | "matches" return TOK_MATCHES; | ||
| 20 | "all" return TOK_ALL; | ||
| 21 | "one" return TOK_ONE; | ||
| 22 | "perform" return TOK_PERFORM; | ||
| 23 | "produces" return TOK_PRODUCES; | ||
| 24 | "command" return TOK_COMMAND; | ||
| 25 | |||
| 26 | \n+ return TOX_EOL; | ||
| 27 | [ \t\r]* | ||
| 28 | |||
| 29 | \/\/.* | ||
| 30 | "#".* | ||
| 31 | |||
diff --git a/src/build.y b/src/build.y new file mode 100644 index 0000000..e69de29 --- /dev/null +++ b/src/build.y | |||
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 @@ | |||
| 1 | int lineNum = 1; | ||
| 2 | %% | ||
| 3 | |||
| 4 | "="|"("|")"|"{"|"}"|";"|"," return yytext[0]; | ||
| 5 | "==" return TOK_COMPARE; | ||
| 6 | "target" return TOK_TARGET; | ||
| 7 | |||
| 8 | \n ++lineNum; | ||
| 9 | [ \t\r]* | ||
| 10 | |||
| 11 | \/\/.* | ||
| 12 | "#".* | ||
| 13 | |||
