diff options
author | Dave Davenport <qball@gmpclient.org> | 2016-12-12 21:14:57 +0100 |
---|---|---|
committer | Dave Davenport <qball@gmpclient.org> | 2016-12-12 21:14:57 +0100 |
commit | be0677cf498aa885a6203fcd0c21c315ad1face3 (patch) | |
tree | 2a61753ec3644ef9c74044f06c91eee7ca56bad3 /lexer | |
parent | c6030063c6eeee267eca07d06dbe69a2657181c6 (diff) |
Update theme to new format.
- @class state {
}
- #name state {
}
Diffstat (limited to 'lexer')
-rw-r--r-- | lexer/theme-lexer.l | 27 | ||||
-rw-r--r-- | lexer/theme-parser.y | 43 |
2 files changed, 52 insertions, 18 deletions
diff --git a/lexer/theme-lexer.l b/lexer/theme-lexer.l index 7f82e759..a540c229 100644 --- a/lexer/theme-lexer.l +++ b/lexer/theme-lexer.l @@ -17,7 +17,11 @@ yylloc->first_line = yylloc->last_line; yylloc->first_column = yylloc->last_column;\ } %} - +WHITESPACE [ \t] +WORD [_\-a-zA-Z0-9]+ +STRING [ \t_\-a-zA-Z0-9]+ +HEX [0-9a-fA-F] +NUMBER [0-9] %% %{ @@ -58,19 +62,22 @@ YY_LLOC_START } YY_LLOC_START } + "\{" { return BOPEN;} "\}" { return BCLOSE;} ":" { return PSEP; } ";" { return PCLOSE;} "." { return NSEP; } -[ \t] ; // ignore all whitespace -[0-9]+\.[0-9]+ { yylval->fval = g_ascii_strtod(yytext, NULL); return T_DOUBLE;} -[0-9]+ { yylval->ival = (int)g_ascii_strtoll(yytext, NULL, 10); return T_INT;} +"#" { return NAME_PREFIX;} (true|false) { yylval->bval= g_strcmp0(yytext, "true") == 0; return T_BOOLEAN;} -[_\-a-zA-Z0-9]+ { yylval->sval = g_strdup(yytext); return N_STRING;} -\"[_\-a-zA-Z0-9 \t]+\" { yytext[yyleng-1] = '\0'; yylval->sval = g_strdup(&yytext[1]); return T_STRING;} +{NUMBER}+ { yylval->ival = (int)g_ascii_strtoll(yytext, NULL, 10); return T_INT;} +{NUMBER}+\.{NUMBER}+ { yylval->fval = g_ascii_strtod(yytext, NULL); return T_DOUBLE;} +@{WORD} { yylval->sval = g_strdup(yytext); return CLASS_NAME; } +{WORD} { yylval->sval = g_strdup(yytext); return N_STRING;} +{WHITESPACE} ; // ignore all whitespace +\"{STRING}\" { yytext[yyleng-1] = '\0'; yylval->sval = g_strdup(&yytext[1]); return T_STRING;} -#[0-9A-Fa-f]{8} { +#{HEX}{8} { union { unsigned int val; struct { unsigned char b,g,r,a;};} val; val.val = (unsigned int)strtoull ( &yytext[1], NULL, 16); yylval->colorval.alpha = val.a/255.0; @@ -79,7 +86,7 @@ YY_LLOC_START yylval->colorval.blue = val.b/255.0; return T_COLOR; } -#[0-9A-Fa-f]{6} { +#{HEX}{6} { union { unsigned int val; struct { unsigned char b,g,r,a;};} val; val.val = (unsigned int)g_ascii_strtoull ( &yytext[1], NULL, 16); yylval->colorval.alpha = 1.0; @@ -88,7 +95,7 @@ YY_LLOC_START yylval->colorval.blue = val.b/255.0; return T_COLOR; } -rgba\([0-9]{1,3},[0-9]{1,3},[0-9]{1,3},[01](\.[0-9]+)?\) { +rgba\({NUMBER}{1,3},{NUMBER}{1,3},{NUMBER}{1,3},[01](\.{NUMBER}+)?\) { char *endptr = &yytext[5]; yylval->colorval.red = g_ascii_strtoull ( endptr, &endptr, 10); yylval->colorval.green= g_ascii_strtoull ( endptr+1, &endptr, 10); @@ -96,7 +103,7 @@ rgba\([0-9]{1,3},[0-9]{1,3},[0-9]{1,3},[01](\.[0-9]+)?\) { yylval->colorval.alpha= g_ascii_strtod ( endptr+1, NULL); return T_COLOR; } -rgb\([0-9]{1,3},[0-9]{1,3},[0-9]{1,3}\) { +rgb\({NUMBER}{1,3},{NUMBER}{1,3},{NUMBER}{1,3}\) { char *endptr = &yytext[4]; yylval->colorval.red = g_ascii_strtoull ( endptr, &endptr, 10); yylval->colorval.green = g_ascii_strtoull ( endptr+1, &endptr, 10); diff --git a/lexer/theme-parser.y b/lexer/theme-parser.y index 2ad71627..aa82cdcf 100644 --- a/lexer/theme-parser.y +++ b/lexer/theme-parser.y @@ -38,18 +38,22 @@ int yylex (YYSTYPE *, YYLTYPE *); %token <sval> N_STRING %token <bval> T_BOOLEAN %token <colorval> T_COLOR +%token <sval> CLASS_NAME %token BOPEN "bracket open"; %token BCLOSE "bracket close"; %token PSEP "property separator"; %token PCLOSE "property close"; %token NSEP "Name separator"; +%token CLASS_PREFIX "Class prefix"; +%token NAME_PREFIX "Name prefix"; %type <sval> entry %type <sval> pvalue %type <theme> entries %type <theme> start %type <name_path> name_path +%type <name_path> state_path %type <property> property %type <property_list> property_list %type <property_list> optional_properties @@ -76,20 +80,38 @@ entries: ; entry: - name_path BOPEN optional_properties BCLOSE +CLASS_NAME state_path BOPEN optional_properties BCLOSE { - Widget *widget = rofi_theme;//rofi_theme_find_or_create_class ( rofi_theme , $1 ); - for ( GList *iter = g_list_first ( $1 ); iter ; iter = g_list_next ( iter ) ) { + Widget *widget = rofi_theme_find_or_create_class ( rofi_theme , $1 ); + for ( GList *iter = g_list_first ( $2 ); iter ; iter = g_list_next ( iter ) ) { widget = rofi_theme_find_or_create_class ( widget, iter->data ); } - g_list_foreach ( $1, (GFunc)g_free , NULL ); - g_list_free ( $1 ); + g_list_foreach ( $2, (GFunc)g_free , NULL ); + g_list_free ( $2 ); if ( widget->properties != NULL ) { fprintf(stderr, "Properties already set on this widget.\n"); exit ( EXIT_FAILURE ); } - widget->properties = $3; - + widget->properties = $4; +} +| NAME_PREFIX name_path state_path BOPEN optional_properties BCLOSE +{ + Widget *widget = rofi_theme; + for ( GList *iter = g_list_first ( $2 ); iter ; iter = g_list_next ( iter ) ) { + widget = rofi_theme_find_or_create_class ( widget, iter->data ); + } + g_list_foreach ( $2, (GFunc)g_free , NULL ); + g_list_free ( $2 ); + for ( GList *iter = g_list_first ( $3 ); iter ; iter = g_list_next ( iter ) ) { + widget = rofi_theme_find_or_create_class ( widget, iter->data ); + } + g_list_foreach ( $3, (GFunc)g_free , NULL ); + g_list_free ( $3 ); + if ( widget->properties != NULL ) { + fprintf(stderr, "Properties already set on this widget.\n"); + exit ( EXIT_FAILURE ); + } + widget->properties = $5; }; /** @@ -141,13 +163,18 @@ property pvalue: N_STRING { $$ = $1; } - name_path: %empty { $$ = NULL; } | N_STRING { $$ = g_list_append ( NULL, $1 );} | name_path NSEP N_STRING { $$ = g_list_append ( $1, $3);} ; +state_path: + %empty { $$ = NULL; } +| N_STRING { $$ = g_list_append ( NULL, $1 );} +| state_path NSEP N_STRING { $$ = g_list_append ( $1, $3);} +; + %% |