1
0
Fork 0
mirror of https://github.com/davatorium/rofi.git synced 2024-11-11 13:50:48 -05:00
rofi/lexer/theme-parser.y

204 lines
5 KiB
Text
Raw Normal View History

2016-12-12 10:55:31 -05:00
%define api.pure
%glr-parser
%skeleton "glr.c"
2016-12-09 13:49:49 -05:00
%locations
%debug
%error-verbose
%code requires {
#include "theme.h"
}
%{
#include <stdio.h>
#include <stdlib.h>
#include <glib.h>
2016-12-09 13:49:49 -05:00
#include "theme.h"
2016-12-12 10:55:31 -05:00
#include "lexer/theme-parser.h"
ThemeWidget *rofi_theme = NULL;
2016-12-12 10:55:31 -05:00
void yyerror(YYLTYPE *yylloc, const char* s);
int yylex (YYSTYPE *, YYLTYPE *);
2016-12-09 13:49:49 -05:00
%}
%union {
int ival;
double fval;
char *sval;
int bval;
2016-12-10 13:48:44 -05:00
ThemeColor colorval;
ThemeWidget *theme;
2016-12-09 13:49:49 -05:00
GList *name_path;
Property *property;
GHashTable *property_list;
2016-12-31 16:47:22 -05:00
Distance distance;
2016-12-09 13:49:49 -05:00
}
%token <ival> T_INT
2016-12-09 16:16:31 -05:00
%token <fval> T_DOUBLE
2016-12-09 13:49:49 -05:00
%token <sval> T_STRING
%token <sval> N_STRING
%token <sval> T_POSITION;
%token <sval> NAME_ELEMENT
2016-12-09 13:49:49 -05:00
%token <bval> T_BOOLEAN
%token <colorval> T_COLOR
2016-12-31 16:47:22 -05:00
%token <distance> T_PIXEL
2017-01-05 12:22:34 -05:00
%token <sval> T_LINK
%token <sval> FIRST_NAME
2016-12-09 13:49:49 -05:00
%token BOPEN "bracket open";
%token BCLOSE "bracket close";
%token PSEP "property separator";
%token PCLOSE "property close";
%token NSEP "Name separator";
%token NAME_PREFIX "Name prefix";
%token WHITESPACE "White space";
2016-12-09 13:49:49 -05:00
2016-12-09 16:16:31 -05:00
%type <sval> entry
2016-12-09 13:49:49 -05:00
%type <sval> pvalue
2016-12-09 16:16:31 -05:00
%type <theme> entries
%type <theme> start
2016-12-09 13:49:49 -05:00
%type <name_path> name_path
%type <name_path> state_path
2016-12-09 13:49:49 -05:00
%type <property> property
%type <property_list> property_list
%type <property_list> optional_properties
2016-12-09 16:16:31 -05:00
%start start
2016-12-09 13:49:49 -05:00
%%
start:
entries
2016-12-09 13:49:49 -05:00
optional_properties
{
$$ = $1;
rofi_theme_widget_add_properties ( $$, $2 );
2016-12-09 13:49:49 -05:00
}
;
entries:
2016-12-09 16:16:31 -05:00
%empty {
2016-12-09 13:49:49 -05:00
// There is always a base widget.
$$ = rofi_theme = (ThemeWidget*)g_malloc0 (sizeof(ThemeWidget));
rofi_theme->name = g_strdup ( "Root" );
2016-12-09 13:49:49 -05:00
}
| entries
optional_properties
entry {
$$ = $1;
rofi_theme_widget_add_properties ( $$, $2);
}
2016-12-09 13:49:49 -05:00
;
entry:
NAME_PREFIX name_path state_path BOPEN optional_properties BCLOSE
{
ThemeWidget *widget = rofi_theme;
for ( GList *iter = g_list_first ( $2 ); iter ; iter = g_list_next ( iter ) ) {
widget = rofi_theme_find_or_create_name ( widget, iter->data );
}
g_list_foreach ( $2, (GFunc)g_free , NULL );
g_list_free ( $2 );
widget->set = TRUE;
for ( GList *iter = g_list_first ( $3 ); iter ; iter = g_list_next ( iter ) ) {
widget = rofi_theme_find_or_create_name ( widget, iter->data );
}
g_list_foreach ( $3, (GFunc)g_free , NULL );
g_list_free ( $3 );
widget->set = TRUE;
rofi_theme_widget_add_properties ( widget, $5);
2016-12-09 13:49:49 -05:00
};
/**
* properties
*/
optional_properties
: %empty { $$ = NULL; }
| property_list { $$ = $1; }
2016-12-09 16:16:31 -05:00
;
2016-12-09 13:49:49 -05:00
2016-12-09 16:16:31 -05:00
property_list:
2016-12-09 13:49:49 -05:00
property {
2016-12-09 16:16:31 -05:00
$$ = g_hash_table_new_full ( g_str_hash, g_str_equal, NULL, (GDestroyNotify)rofi_theme_property_free );
2016-12-09 13:49:49 -05:00
g_hash_table_replace ( $$, $1->name, $1 );
}
| property_list property {
// Old will be free'ed, and key/value will be replaced.
g_hash_table_replace ( $$, $2->name, $2 );
}
;
property
: pvalue PSEP T_INT PCLOSE {
$$ = rofi_theme_property_create ( P_INTEGER );
$$->name = $1;
2016-12-09 16:16:31 -05:00
$$->value.i = $3;
2016-12-09 13:49:49 -05:00
}
2016-12-09 16:16:31 -05:00
| pvalue PSEP T_DOUBLE PCLOSE {
$$ = rofi_theme_property_create ( P_DOUBLE );
2016-12-09 13:49:49 -05:00
$$->name = $1;
2016-12-09 16:16:31 -05:00
$$->value.f = $3;
2016-12-09 13:49:49 -05:00
}
2016-12-09 16:16:31 -05:00
| pvalue PSEP T_COLOR PCLOSE {
2016-12-09 13:49:49 -05:00
$$ = rofi_theme_property_create ( P_COLOR );
$$->name = $1;
2016-12-09 16:16:31 -05:00
$$->value.color = $3;
2016-12-09 13:49:49 -05:00
}
2016-12-09 16:16:31 -05:00
| pvalue PSEP T_STRING PCLOSE {
2016-12-09 13:49:49 -05:00
$$ = rofi_theme_property_create ( P_STRING );
$$->name = $1;
2016-12-09 16:16:31 -05:00
$$->value.s = $3;
2016-12-09 13:49:49 -05:00
}
2017-01-05 12:22:34 -05:00
| pvalue PSEP T_LINK PCLOSE {
$$ = rofi_theme_property_create ( P_LINK );
$$->name = $1;
$$->value.link.name = $3;
}
2016-12-09 13:49:49 -05:00
| pvalue PSEP T_BOOLEAN PCLOSE {
$$ = rofi_theme_property_create ( P_BOOLEAN );
$$->name = $1;
2016-12-09 16:16:31 -05:00
$$->value.b = $3;
2016-12-09 13:49:49 -05:00
}
| pvalue PSEP T_PIXEL PCLOSE {
$$ = rofi_theme_property_create ( P_PADDING );
$$->name = $1;
2016-12-31 16:47:22 -05:00
$$->value.padding = (Padding){ $3, $3, $3, $3 };
}
| pvalue PSEP T_PIXEL T_PIXEL PCLOSE {
$$ = rofi_theme_property_create ( P_PADDING );
$$->name = $1;
$$->value.padding = (Padding){ $3, $4, $3, $4 };
}
| pvalue PSEP T_PIXEL T_PIXEL T_PIXEL PCLOSE {
$$ = rofi_theme_property_create ( P_PADDING );
$$->name = $1;
$$->value.padding = (Padding){ $3, $4, $5, $4 };
}
| pvalue PSEP T_PIXEL T_PIXEL T_PIXEL T_PIXEL PCLOSE {
$$ = rofi_theme_property_create ( P_PADDING );
$$->name = $1;
2016-12-31 16:47:22 -05:00
$$->value.padding = (Padding){ $3, $4, $5, $6 };
}
| pvalue PSEP T_POSITION PCLOSE{
$$ = rofi_theme_property_create ( P_POSITION );
$$->name = $1;
$$->value.i = $3;
}
2016-12-09 13:49:49 -05:00
;
pvalue: N_STRING { $$ = $1; }
name_path:
NAME_ELEMENT { $$ = g_list_append ( NULL, $1 );}
| name_path NSEP NAME_ELEMENT { $$ = g_list_append ( $1, $3);}
2016-12-09 13:49:49 -05:00
;
state_path:
%empty { $$ = NULL; }
| N_STRING { $$ = g_list_append ( NULL, $1 );}
| state_path NSEP N_STRING { $$ = g_list_append ( $1, $3);}
;
2016-12-09 13:49:49 -05:00
%%