]> Dogcows Code - chaz/openbox/blobdiff - openbox/parse.y
all my changes while i was offline.
[chaz/openbox] / openbox / parse.y
index 71cc5ba92288bd7cd2b861570c1add04083c293a..7e92efd6767dc8e6e703fab08ceee9b8b1066b2c 100644 (file)
@@ -6,30 +6,34 @@
 
 %}
 
-%union ParseToken {
+%union ParseTokenData {
     float real;
     int integer;
     char *string;
     char *identifier;
     gboolean bool;
     char character;
+    GList *list;
 }
 
 %{
+#define NO_TAB_H
 #include "parse.h"
+#undef NO_TAB_H
 
 extern int yylex();
 extern int yyparse();
 void yyerror(char *err);
 
-extern int yylineno;
+extern int lineno;
 extern FILE *yyin;
 
 static char *path;
-static union ParseToken t;
+static ParseToken t;
 
 /* in parse.c */
-void parse_token(ParseTokenType type, union ParseToken token);
+void parse_token(ParseToken *token);
+void parse_assign(char *name, ParseToken *token);
 void parse_set_section(char *section);
 %}
 
@@ -37,7 +41,7 @@ void parse_set_section(char *section);
 %token <integer> INTEGER
 %token <string> STRING
 %token <identifier> IDENTIFIER
-%token <bool> BOOL
+%token <bool> BOOLEAN
 %token <character> '('
 %token <character> ')'
 %token <character> '{'
@@ -47,39 +51,76 @@ void parse_set_section(char *section);
 %token <character> '\n'
 %token INVALID
 
+%type <list> list
+%type <list> listtokens
+
 %%
 
 sections:
-  | sections '[' IDENTIFIER ']' { parse_set_section($3); } '\n' lines
+  | sections '[' IDENTIFIER ']' { parse_set_section($3); } '\n'
+    { ++lineno; } lines
   ;
 
 lines:
-  | lines tokens '\n' { t.character = $3; parse_token($3, t); }
+  | lines tokens { t.type='\n'; t.data.character='\n'; parse_token(&t); } '\n'
+    { ++lineno; }
+  | lines IDENTIFIER '=' listtoken { parse_assign($2, &t); } '\n'
+    { ++lineno; }
   ;
 
 tokens:
-    tokens token
-  | token
+    tokens token { parse_token(&t); }
+  | token        { parse_token(&t); }
   ;
 
 token:
-    REAL       { t.real = $1; parse_token(REAL, t); }
-  | INTEGER    { t.integer = $1; parse_token(INTEGER, t); }
-  | STRING     { t.string = $1; parse_token(STRING, t); }
-  | IDENTIFIER { t.identifier = $1; parse_token(IDENTIFIER, t); }
-  | BOOL       { t.bool = $1; parse_token(BOOL, t); }
-  | '('        { t.character = $1; parse_token($1, t); }
-  | ')'        { t.character = $1; parse_token($1, t); }
-  | '{'        { t.character = $1; parse_token($1, t); }
-  | '}'        { t.character = $1; parse_token($1, t); }
-  | '='        { t.character = $1; parse_token($1, t); }
-  | ','        { t.character = $1; parse_token($1, t); }
+    REAL       { t.type = TOKEN_REAL; t.data.real = $1; }
+  | INTEGER    { t.type = TOKEN_INTEGER; t.data.integer = $1; }
+  | STRING     { t.type = TOKEN_STRING; t.data.string = $1; }
+  | IDENTIFIER { t.type = TOKEN_IDENTIFIER; t.data.identifier = $1; }
+  | BOOLEAN    { t.type = TOKEN_BOOL; t.data.bool = $1; }
+  | list       { t.type = TOKEN_LIST; t.data.list = $1; }
+  | '{'        { t.type = $1; t.data.character = $1; }
+  | '}'        { t.type = $1; t.data.character = $1; }
+  | ','        { t.type = $1; t.data.character = $1; }
+  ;
+
+list:
+    '(' listtokens ')' { $$ = $2; }
+  ;
+
+listtokens:
+    listtokens listtoken { ParseToken *nt = g_new(ParseToken, 1);
+                           nt->type = t.type;
+                           nt->data = t.data;
+                           $$ = g_list_append($1, nt);
+                         }
+  | listtoken            { ParseToken *nt = g_new(ParseToken, 1);
+                           nt->type = t.type;
+                           nt->data = t.data;
+                           $$ = g_list_append(NULL, nt);
+                         }
   ;
 
+listtoken:
+    REAL       { t.type = TOKEN_REAL; t.data.real = $1; }
+  | INTEGER    { t.type = TOKEN_INTEGER; t.data.integer = $1; }
+  | STRING     { t.type = TOKEN_STRING; t.data.string = $1; }
+  | IDENTIFIER { t.type = TOKEN_IDENTIFIER; t.data.identifier = $1; }
+  | BOOLEAN    { t.type = TOKEN_BOOL; t.data.bool = $1; }
+  | list       { t.type = TOKEN_LIST; t.data.list = $1; }
+  | '{'        { t.type = $1; t.data.character = $1; }
+  | '}'        { t.type = $1; t.data.character = $1; }
+  | ','        { t.type = $1; t.data.character = $1; }
+  ;
+
+
 %%
 
+int lineno;
+
 void yyerror(char *err) {
-    g_message("%s:%d: %s", path, yylineno, err);
+    g_message("%s:%d: %s", path, lineno, err);
 }
 
 void parse_rc()
@@ -97,7 +138,7 @@ void parse_rc()
         }
     }
 
-    yylineno = 1;
+    lineno = 1;
 
     yyparse();
 
This page took 0.028506 seconds and 4 git commands to generate.