expression parsing has begun
authorDerek Foreman <foremande@gmail.com>
Fri, 14 May 2010 21:50:02 +0000 (17:50 -0400)
committerDerek Foreman <foremande@gmail.com>
Fri, 14 May 2010 21:51:19 +0000 (17:51 -0400)
main.c
obtheme.h
obtheme.l
obtheme.y
theme.obtheme

diff --git a/main.c b/main.c
index 0e54d18..9f19e52 100644 (file)
--- a/main.c
+++ b/main.c
@@ -1,14 +1,48 @@
+#include <assert.h>
 #include <stdio.h>
 #include <string.h>
 #include <glib.h>
 #include "obtheme.h"
 
+double variable_lookup(struct variable *in)
+{
+       return 0.0;
+}
+
+double expression_eval(struct expression *in)
+{
+       switch (in->op) {
+               case OB_THEME_MUL:
+                       return expression_eval(in->a) * expression_eval(in->b);
+                       break;
+               case OB_THEME_DIV:
+                       return expression_eval(in->a) / expression_eval(in->b);
+                       break;
+               case OB_THEME_ADD:
+                       return expression_eval(in->a) + expression_eval(in->b);
+                       break;
+               case OB_THEME_SUB:
+                       return expression_eval(in->a) - expression_eval(in->b);
+                       break;
+               case OB_THEME_EQL:
+                       if (in->v.base == NULL) {
+                               return in->v.number;
+                       } else return variable_lookup(&in->v);
+                       break;
+               default:
+                       assert(!!!"OH NOES!!!");
+       }
+       return 0;
+}
+
 static void decor_print(gpointer data, gpointer user_data)
 {
+       double out;
        struct decor *decor = data;
        printf("    decor id %s\n", decor->name);
-       printf("      anchor (%d %d %d)\n", decor->space.anchor.x, decor->space.anchor.y, decor->space.anchor.z);
-       printf("      up     (%d %d %d)\n", decor->space.up.x, decor->space.up.y, decor->space.up.z);
+printf("   anchor.x = %f\n", expression_eval(&decor->space.anchor.x));
+//     printf("      anchor (%d %d %d)\n", decor->space.anchor.x, decor->space.anchor.y, decor->space.anchor.z);
+//     printf("      up     (%d %d %d)\n", decor->space.up.x, decor->space.up.y, decor->space.up.z);
        if (decor->children)
                g_slist_foreach(decor->children, decor_print, NULL);
 }
index d98d335..9a4faf7 100644 (file)
--- a/obtheme.h
+++ b/obtheme.h
 
 extern int themedebug;
 
+typedef enum {
+       OB_THEME_ADD,
+       OB_THEME_SUB,
+       OB_THEME_MUL,
+       OB_THEME_DIV,
+       OB_THEME_EQL
+} ObThemeOp;
+
+struct variable {
+       char *base;
+       char *member;
+       double number;
+};
+
+struct expression {
+       ObThemeOp op;
+       struct expression *a;
+       struct expression *b;
+       struct variable v;
+};
+
 struct material {
        float opacity;
 };
@@ -36,9 +57,9 @@ struct theme {
 };
 
 struct vector {
-       int x;
-       int y;
-       int z;
+       struct expression x;
+       struct expression y;
+       struct expression z;
 };
 
 struct space {
index 889e6ad..364fb3f 100644 (file)
--- a/obtheme.l
+++ b/obtheme.l
@@ -163,6 +163,10 @@ UNCHANGED          return UNCHANGED;
 "<-"                   return LEFT_ARROW;
 "->"                   return RIGHT_ARROW;
 "<->"                  return DOUBLE_ARROW;
+"."                    return DOT;
+"*"                    return STAR;
+"/"                    return SLASH;
+","                    return COMMA;
 \n                     LINE++; /* zap EOL */
 [ \t]+                 ; /* and whitespace */
 .                      return 0;
index 4ebd13d..ffcf862 100644 (file)
--- a/obtheme.y
+++ b/obtheme.y
@@ -100,6 +100,14 @@ void parser_finish(struct parser_control *c)
        free(c);
 }
 
+struct expression *exdup(struct expression in)
+{
+       struct expression *out;
+       out = malloc(sizeof(struct expression));
+       *out = in;
+       return out;
+}
+
 %}
 %start theme_objects
 
@@ -118,6 +126,8 @@ void parser_finish(struct parser_control *c)
        ObCursor dir;
        ObFrameContext context;
        RrSurfaceColorType gradient;
+       struct expression expr;
+       struct variable var;
 }
 
 %token NORTH NORTHEAST EAST SOUTHEAST SOUTH SOUTHWEST
@@ -125,12 +135,12 @@ void parser_finish(struct parser_control *c)
 %token LCB RCB LB RB
 %token LEFT_ARROW RIGHT_ARROW DOUBLE_ARROW
 %token SEMICOLON AT COLON DEFAULT NOT
-%token PLUS MINUS
+%token PLUS MINUS STAR SLASH COMMA
 %token <string> STRING ID
 %token <integer> NUMBER SUBST BULK BIG LITTLE
 %token THEME FRAME SPACE GEOMETRY MATERIAL GRADIENT
 %token CONTEXT CURSOR UP ANCHOR STYLE TEXTURE OPACITY
-%token SHAPEOF DECOR
+%token SHAPEOF DECOR DOT
 %type <decor> decor
 %type <decor> decoritems styleitem
 %type <space> space
@@ -143,6 +153,12 @@ void parser_finish(struct parser_control *c)
 %type <dir> cursor
 %type <context> context
 %type <gradient> gradient
+%type <expr> expression
+%type <var> variable
+
+%left PLUS MINUS
+%left STAR SLASH
+%left LB
 %%
 
 theme_object   : material_decl
@@ -178,21 +194,34 @@ material_decl     : MATERIAL ID LCB material_props RCB {
                }
                ;
 
-anchor         : ANCHOR LB NUMBER NUMBER NUMBER RB {
+anchor         : ANCHOR LB expression COMMA expression COMMA expression RB {
                        $$.x = $3;
-                       $$.y = $4;
-                       $$.z = $5;
+                       $$.y = $5;
+                       $$.z = $7;
                }
                ;
 
-up             : UP LB NUMBER NUMBER NUMBER RB {
+up             : UP LB expression COMMA expression COMMA expression RB {
                        $$.x = $3;
-                       $$.y = $4;
-                       $$.z = $5;
+                       $$.y = $5;
+                       $$.z = $7;
                }
                ;
 
-spaceconstraints: /* empty */ { memset(&$$, 0, sizeof($$)); }
+spaceconstraints: /* empty */ { memset(&$$, 0, sizeof($$));
+                       $$.anchor.x.op = OB_THEME_EQL;
+                       $$.anchor.x.v.number = 1;
+                       $$.anchor.y.op = OB_THEME_EQL;
+                       $$.anchor.y.v.number = 1;
+                       $$.anchor.z.op = OB_THEME_EQL;
+                       $$.anchor.z.v.number = 1;
+                       $$.up.x.op = OB_THEME_EQL;
+                       $$.up.x.v.number = 1;
+                       $$.up.y.op = OB_THEME_EQL;
+                       $$.up.y.v.number = 1;
+                       $$.up.z.op = OB_THEME_EQL;
+                       $$.up.z.v.number = 1;
+               }
                | spaceconstraints anchor { $1.anchor = $2; $$ = $1; }
                | spaceconstraints up     { $1.up = $2; $$ = $1; }
                ;
@@ -250,8 +279,20 @@ style              : STYLE ID LCB styleitems RCB {
 
 decoritems     : /* empty */ {
                        memset(&$$, 0, sizeof($$));
-                       $$.space.up.y = -1;
+//                     $$.space.up.y = -1;  XXX need a sane default!
                        $$.cursor = OB_CURSOR_NONE;
+                       $$.space.anchor.x.op = OB_THEME_EQL;
+                       $$.space.anchor.x.v.number = 1;
+                       $$.space.anchor.y.op = OB_THEME_EQL;
+                       $$.space.anchor.y.v.number = 1;
+                       $$.space.anchor.z.op = OB_THEME_EQL;
+                       $$.space.anchor.z.v.number = 1;
+                       $$.space.up.x.op = OB_THEME_EQL;
+                       $$.space.up.x.v.number = 1;
+                       $$.space.up.y.op = OB_THEME_EQL;
+                       $$.space.up.y.v.number = 1;
+                       $$.space.up.z.op = OB_THEME_EQL;
+                       $$.space.up.z.v.number = 1;
                }
                | decoritems decor {
                        struct decor *out = malloc(sizeof(struct decor));
@@ -310,4 +351,36 @@ gradient   : GRADIENT LB ID RB {
                }
                ;
 
+variable       : ID DOT ID { $$.base = $1; $$.member = $3; }
+               | ID        { $$.base = $1; $$.member = NULL; }
+               | NUMBER    { $$.base = NULL; $$.number = $1; }
+               ;
+
+expression     : expression STAR expression {
+                       $$.op = OB_THEME_MUL;
+                       $$.a = exdup($1);
+                       $$.b = exdup($3);
+               }
+               | expression SLASH expression {
+                       $$.op = OB_THEME_DIV;
+                       $$.a = exdup($1);
+                       $$.b = exdup($3);
+               }
+               | expression PLUS expression {
+                       $$.op = OB_THEME_ADD;
+                       $$.a = exdup($1);
+                       $$.b = exdup($3);
+               }
+               | expression MINUS expression {
+                       $$.op = OB_THEME_SUB;
+                       $$.a = exdup($1);
+                       $$.b = exdup($3);
+               }
+               | variable {
+                       $$.op = OB_THEME_EQL;
+                       $$.v = $1;
+               }
+               | LB expression RB { $$ = $2; }
+               ;
+
 %%
index af8d033..ced4738 100644 (file)
@@ -18,8 +18,8 @@ theme awesome {
        style regular_window {
                decor clientwindow {
                        space {
-                               anchor(0 0 0)
-                               up(1 0 0)
+                               anchor(1 + client.width + 1/3* 9/2, 0, 0)
+                               up(0, 0, 0)
                        }
                        geometry {
                                shapeof(client)
@@ -31,7 +31,7 @@ theme awesome {
                        decor titlebar {
                                context(titlebar)
                                geometry {
-                               //      box (0, 0, 0) to (100% of $CLIENT, 100%, 0)
+                               //      box (0, 0, 0) to (.1 * client.width / (4/client.width), 100%, 0)
                                }
                                material(flat)
 //texture {
@@ -52,8 +52,8 @@ theme awesome {
                        }
                        decor handle {
                                space {
-                                       anchor(0 0 0)
-                                       up(0 0 0)
+                                       anchor(0, 0, 0)
+                                       up(0, 0, 0)
                                }
                                decor leftgrip {
                                        context(blcorner)