X-Git-Url: https://git.dogcows.com/gitweb?a=blobdiff_plain;f=openbox%2Fparse.y;h=125f18038dc02bee22cf9d1f9929232e10421a14;hb=63b0c5616ffe67aa021234abe6635adb9c91879b;hp=e9b469e029628ef7f7dbf9ac0c0334c33434ad5f;hpb=67bbd6970ce0b807397e5ecb3255982d7b1cc617;p=chaz%2Fopenbox diff --git a/openbox/parse.y b/openbox/parse.y index e9b469e0..125f1803 100644 --- a/openbox/parse.y +++ b/openbox/parse.y @@ -1,31 +1,40 @@ %{ -#include "parse.h" +#include #ifdef HAVE_STDIO_H # include #endif +%} + +%union ParseTokenData { + float real; + int integer; + char *string; + char *identifier; + gboolean bool; + char character; + GList *list; +} + +%{ +#include "parse.h" + extern int yylex(); +extern int yyparse(); +void yyerror(char *err); extern int yylineno; 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); %} -%union ParseToken { - float real; - int integer; - char *string; - char *identifier; - gboolean bool; - char character; -} - %token REAL %token INTEGER %token STRING @@ -40,35 +49,70 @@ void parse_set_section(char *section); %token '\n' %token INVALID +%type list +%type listtokens + %% sections: - | sections '[' IDENTIFIER ']' { parse_set_section($3); } '\n' lines + | sections '[' IDENTIFIER ']' { parse_set_section($3); } '\n' + { ++yylineno; } lines ; lines: - | lines tokens '\n' { t.character = $3; parse_token(TOKEN_NEWLINE, t); } + | lines tokens { t.type='\n'; t.data.character='\n'; parse_token(&t); } '\n' + { ++yylineno; } + | lines IDENTIFIER '=' listtoken { parse_assign($2, &t); } '\n' + { ++yylineno; } ; tokens: - tokens token - | token + tokens token { parse_token(&t); } + | token { parse_token(&t); } ; token: - REAL { t.real = $1; parse_token(TOKEN_REAL, t); } - | INTEGER { t.integer = $1; parse_token(TOKEN_INTEGER, t); } - | STRING { t.string = $1; parse_token(TOKEN_STRING, t); } - | IDENTIFIER { t.identifier = $1; parse_token(TOKEN_IDENTIFIER, t); } - | BOOL { t.bool = $1; parse_token(TOKEN_BOOL, t); } - | '(' { t.character = $1; parse_token(TOKEN_LBRACKET, t); } - | ')' { t.character = $1; parse_token(TOKEN_RBRACKET, t); } - | '{' { t.character = $1; parse_token(TOKEN_LBRACE, t); } - | '}' { t.character = $1; parse_token(TOKEN_RBRACE, t); } - | '=' { t.character = $1; parse_token(TOKEN_EQUALS, t); } - | ',' { t.character = $1; parse_token(TOKEN_COMMA, 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; } + | BOOL { 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; } + | BOOL { 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; } + ; + + %% void yyerror(char *err) {