aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMike Buland <eichlan@xagasoft.com>2006-08-21 15:24:10 +0000
committerMike Buland <eichlan@xagasoft.com>2006-08-21 15:24:10 +0000
commite95c31f841b67fc69d93ec650fe285d34f996a1e (patch)
treebb0153ba0ee01958743d31be70a73b032b3ea2fc
parent4887f62bea708f24e03b3f926f2698c60a94c807 (diff)
downloadbuild-e95c31f841b67fc69d93ec650fe285d34f996a1e.tar.gz
build-e95c31f841b67fc69d93ec650fe285d34f996a1e.tar.bz2
build-e95c31f841b67fc69d93ec650fe285d34f996a1e.tar.xz
build-e95c31f841b67fc69d93ec650fe285d34f996a1e.zip
Alright, the grammer is almost there, just debugging, in what I call extreme-
debugging mode. If you wanted something intelligable, don't use this one.
Diffstat (limited to '')
-rw-r--r--build.conf2
-rw-r--r--src/build.l28
-rw-r--r--src/build.y59
-rw-r--r--src/builder.cpp26
-rw-r--r--src/builder.h6
5 files changed, 90 insertions, 31 deletions
diff --git a/build.conf b/build.conf
index 8bbe679..2115fb0 100644
--- a/build.conf
+++ b/build.conf
@@ -4,7 +4,7 @@ default action: check "build", check "cleanup"
4 rule "exe", 4 rule "exe",
5 target file, 5 target file,
6 set "CXXFLAGS" = "-lBob", 6 set "CXXFLAGS" = "-lBob",
7 input [files("src/{target}"), files("src/shared")] 7 input [files("src/{target}" ), files("src/shared")]
8 8
9[directoryName("src/tests")] filter /src\/tests/(.*)/tests\/{re:1}/: 9[directoryName("src/tests")] filter /src\/tests/(.*)/tests\/{re:1}/:
10 rule "exe", 10 rule "exe",
diff --git a/src/build.l b/src/build.l
index 9a15719..8189f9d 100644
--- a/src/build.l
+++ b/src/build.l
@@ -18,7 +18,7 @@ std::string strbuf;
18%} 18%}
19%% 19%%
20 20
21[,:=[\]] return yytext[0]; 21[,:=[\]()] return yytext[0];
22"+=" return TOK_ADDSET; 22"+=" return TOK_ADDSET;
23 23
24"default" return TOK_DEFAULT; 24"default" return TOK_DEFAULT;
@@ -32,6 +32,7 @@ std::string strbuf;
32"check" return TOK_CHECK; 32"check" return TOK_CHECK;
33"clean" return TOK_CLEAN; 33"clean" return TOK_CLEAN;
34"target" return TOK_TARGET; 34"target" return TOK_TARGET;
35"input" return TOK_INPUT;
35 36
36\n+ { 37\n+ {
37 yylloc->last_line += yyleng; 38 yylloc->last_line += yyleng;
@@ -59,6 +60,27 @@ std::string strbuf;
59 60
60"#".* /* single line comment */ 61"#".* /* single line comment */
61 62
63[a-zA-Z][a-zA-Z0-9]* {
64 {
65 yylval->tval = bld.getTargetType( yytext );
66 if( yylval->tval >= 0 )
67 {
68 return TARGETTYPE;
69 }
70 else if( bld.isFunction( yytext ) )
71 {
72 yylval->strval = stringdup( yytext );
73 return FUNCTION;
74 }
75 bld.error( yylloc, "Invalid token" );
76 }
77}
78
79[^ \t\r\n\'\":=,/][^ \t\r\n\'\"=,]+[^ \t\r\n\'\":=,] {
80 yylval->strval = stringdup( yytext );
81 return STRING;
82}
83
62\" { 84\" {
63 BEGIN( strdq ); 85 BEGIN( strdq );
64 strbuf = ""; 86 strbuf = "";
@@ -94,6 +116,10 @@ std::string strbuf;
94 return STRING; 116 return STRING;
95} 117}
96 118
119. {
120 bld.error( yylloc, "Invalid character found!" );
121}
122
97%% 123%%
98 124
99void Builder::scanBegin() 125void Builder::scanBegin()
diff --git a/src/build.y b/src/build.y
index d852c4c..5580299 100644
--- a/src/build.y
+++ b/src/build.y
@@ -40,9 +40,9 @@ void yyerror( YYLTYPE *locp, Builder &bld, char const *msg );
40%token TOK_PERFORM "perform" 40%token TOK_PERFORM "perform"
41%token TOK_PRODUCES "produces" 41%token TOK_PRODUCES "produces"
42 42
43%token ',' ':' '=' 43%token ',' ':' '=' '(' ')'
44 44
45%destructor { delete[] $$; } STRING 45%destructor { delete[] $$; } STRING FUNCTION
46 46
47%% 47%%
48 48
@@ -54,57 +54,61 @@ input:
54 ; 54 ;
55 55
56// Rule interpretation 56// Rule interpretation
57rule: TOK_RULE STRING ':' rulecmds 57rule: TOK_RULE STRING {printf("Rule %s:\n", $2 ); } ':' rulecmds
58 ; 58 ;
59 59
60rulecmds: rulecmd 60rulecmds: rulecmd
61 | rulecmds ',' rulecmd 61 | rulecmds ',' rulecmd
62 ; 62 ;
63 63
64rulecmd: TOK_MATCHES REGEXP 64rulecmd: TOK_MATCHES REGEXP { printf(" Matches: %s\n", $2 ); }
65 | TOK_PRODUCES STRING 65 | TOK_PRODUCES STRING { printf(" Produces: %s\n", $2 ); }
66 | TOK_REQUIRES list 66 | TOK_REQUIRES { printf(" Requires:\n"); } list {printf("\n");}
67 | TOK_INPUT TOK_FILTER REGEXP 67 | TOK_INPUT TOK_FILTER REGEXP { printf(" Input Filter: %s\n", $3 ); }
68 | TOK_INPUT TOK_FILTER func 68 | TOK_INPUT TOK_FILTER { printf(" Input Filter: "); } func {printf("\n");}
69 | TOK_PERFORM func 69 | TOK_PERFORM { printf(" Perform: "); } func {printf("\n");}
70 ; 70 ;
71 71
72// Action interpretation 72// Action interpretation
73action: TOK_DEFAULT TOK_ACTION ':' actioncmds 73action: TOK_DEFAULT TOK_ACTION ':' { printf("Default action:\n"); } actioncmds
74 | STRING TOK_ACTION ':' actioncmds 74 | STRING TOK_ACTION ':' { printf("\"%s\" action:\n", $1 ); } actioncmds
75 ; 75 ;
76 76
77actioncmds: actioncmd 77actioncmds: actioncmd
78 | actioncmds ',' actioncmd 78 | actioncmds ',' actioncmd
79 ; 79 ;
80 80
81actioncmd: actioncmdtype list 81actioncmd: { printf("\t"); } actioncmdtype list {printf("\n");}
82 ; 82 ;
83 83
84actioncmdtype: TOK_CHECK 84actioncmdtype: TOK_CHECK { printf("check "); }
85 | TOK_CLEAN 85 | TOK_CLEAN { printf("clean "); }
86 ; 86 ;
87 87
88// Target interpretation 88// Target interpretation
89 89target: list ':' { printf(" are targets:\n"); } targetcmds
90target: list ':' targetcmds
91 ; 90 ;
92 91
93targetcmds: targetcmd 92targetcmds: targetcmd
94 | targetcmds ',' targetcmd 93 | targetcmds ',' targetcmd
95 ; 94 ;
96 95
97targetcmd: TOK_RULE STRING 96targetcmd: TOK_RULE STRING { printf(" Rule %s\n", $2 ); }
98 | TOK_TARGET TOK_PREFIX STRING 97 | TOK_TARGET TOK_PREFIX STRING { printf(" Target prefix: %s\n", $3 ); }
99 | TOK_TARGET TARGETTYPE 98 | TOK_TARGET TARGETTYPE { printf(" Target Type: %d\n", $2 ); }
100 | TOK_INPUT list 99 | TOK_INPUT { printf(" Input: "); } list { printf("\n"); }
101 | TOK_REQUIRES list 100 | TOK_REQUIRES { printf(" Requires: "); } list { printf("\n"); }
101 | TOK_SET { printf(" Set: "); } targetset
102 ;
103
104targetset: STRING '=' STRING { printf("%s = %s\n", $1, $3 ); }
105 | STRING TOK_ADDSET STRING { printf("%s += %s\n", $1, $3 ); }
102 ; 106 ;
103 107
104// list goo 108// list goo
105 109
106list: listitem listfilter 110list: listitem listfilter
107 | '[' listitems ']' listfilter 111 | '[' { printf("["); } listitems ']' { printf("]"); } listfilter
108 ; 112 ;
109 113
110listfilter: 114listfilter:
@@ -113,21 +117,21 @@ listfilter:
113 ; 117 ;
114 118
115listitems: listitem 119listitems: listitem
116 | listitems ',' listitem 120 | listitems ',' {printf(", "); } listitem
117 ; 121 ;
118 122
119listitem: STRING 123listitem: STRING {printf("%s", $1 ); }
120 | func 124 | func
121 ; 125 ;
122 126
123// Function 127// Function
124 128
125func: FUNCTION '(' funcparams ')' 129func: FUNCTION { printf("%s(", $1 ); } '(' funcparams ')' { printf(")"); }
126 ; 130 ;
127 131
128funcparams: 132funcparams:
129 | STRING 133 | STRING { printf("%s", $1 ); }
130 | funcparams ',' STRING 134 | funcparams ',' STRING { printf(", %s", $3 ); }
131 ; 135 ;
132 136
133%% 137%%
@@ -136,3 +140,4 @@ void yyerror( YYLTYPE *locp, Builder &bld, char const *msg )
136{ 140{
137 bld.error( locp, msg ); 141 bld.error( locp, msg );
138} 142}
143
diff --git a/src/builder.cpp b/src/builder.cpp
index 1ecbf05..b6ae887 100644
--- a/src/builder.cpp
+++ b/src/builder.cpp
@@ -1,5 +1,7 @@
1#include "builder.h" 1#include "builder.h"
2 2
3subExceptionDef( BuildException );
4
3Builder::Builder() 5Builder::Builder()
4{ 6{
5} 7}
@@ -9,22 +11,42 @@ Builder::~Builder()
9} 11}
10 12
11void yyparse( Builder &bld ); 13void yyparse( Builder &bld );
14extern int yydebug;
12 15
13void Builder::load( const std::string &sFile ) 16void Builder::load( const std::string &sFile )
14{ 17{
15 file = sFile; 18 file = sFile;
16 scanBegin(); 19 scanBegin();
20 yydebug = 1;
17 yyparse( *this ); 21 yyparse( *this );
18 scanEnd(); 22 scanEnd();
19} 23}
20 24
21void Builder::error( YYLTYPE *locp, const char *msg ) 25void Builder::error( YYLTYPE *locp, const char *msg )
22{ 26{
23 printf("%s\n", msg ); 27 fflush( stdout );
28 throw BuildException("%s: %d.%d-%d.%d: %s",
29 file.c_str(),
30 locp->first_line, locp->first_column,
31 locp->last_line, locp->last_column,
32 msg );
24} 33}
25 34
26void Builder::error( const std::string &msg ) 35void Builder::error( const std::string &msg )
27{ 36{
28 printf("%s\n", msg.c_str() ); 37 fflush( stdout );
38 throw BuildException("%s", msg.c_str() );
39}
40
41int Builder::getTargetType( const char *sType )
42{
43 if( !strcmp( sType, "file" ) )
44 return 0;
45 return -1;
46}
47
48bool Builder::isFunction( const char *sFunc )
49{
50 return true;
29} 51}
30 52
diff --git a/src/builder.h b/src/builder.h
index 9c146ea..3293108 100644
--- a/src/builder.h
+++ b/src/builder.h
@@ -4,12 +4,15 @@
4#include <stdint.h> 4#include <stdint.h>
5#include <string> 5#include <string>
6#include "build.tab.h" 6#include "build.tab.h"
7#include "exceptions.h"
7 8
8class Builder; 9class Builder;
9 10
10#define YY_DECL int yylex( YYSTYPE *yylval_param, YYLTYPE *yylloc_param, Builder &bld ) 11#define YY_DECL int yylex( YYSTYPE *yylval_param, YYLTYPE *yylloc_param, Builder &bld )
11YY_DECL; 12YY_DECL;
12 13
14subExceptionDecl( BuildException );
15
13class Builder 16class Builder
14{ 17{
15public: 18public:
@@ -21,6 +24,9 @@ public:
21 24
22 void load( const std::string &sFile ); 25 void load( const std::string &sFile );
23 26
27 int getTargetType( const char *sType );
28 bool isFunction( const char *sFunc );
29
24private: 30private:
25 std::string file; 31 std::string file;
26 void scanBegin(); 32 void scanBegin();