Make parser more flexible, allow global properties to be anywhere in file and allow multiple similar entries.

This commit is contained in:
Dave Davenport 2016-12-16 09:28:13 +01:00
parent efd1e07755
commit b8e58b0342
8 changed files with 61 additions and 30 deletions

View file

@ -9,6 +9,8 @@
* autoconf
* automake (1.11.3 or up)
* pkg-config
* flex
* bison
* Developer packages of the external libraries
### External libraries

View file

@ -273,6 +273,10 @@ box_test_CFLAGS=$(textbox_test_CFLAGS)
box_test_SOURCES=\
source/widgets/widget.c\
source/widgets/box.c\
lexer/theme-parser.y\
lexer/theme-lexer.l\
source/theme.c\
inlucde/theme.h\
test/box-test.c
scrollbar_test_LDADD=$(textbox_test_LDADD)
@ -280,11 +284,18 @@ scrollbar_test_CFLAGS=$(textbox_test_CFLAGS)
scrollbar_test_SOURCES=\
source/widgets/widget.c\
source/widgets/scrollbar.c\
lexer/theme-parser.y\
lexer/theme-lexer.l\
source/theme.c\
inlucde/theme.h\
test/scrollbar-test.c
textbox_test_SOURCES=\
source/widgets/widget.c\
source/widgets/textbox.c\
lexer/theme-parser.y\
lexer/theme-lexer.l\
source/theme.c\
config/config.c\
include/keyb.h\
include/rofi.h\

View file

@ -106,7 +106,7 @@ The file is structured as follows
}
```
The global properties has to be at the top of the file, the rest can freeĺy be mixed.
The global properties an freeĺy be mixed between entries.
Each property is constructed like:
```

View file

@ -58,6 +58,7 @@ Property *rofi_theme_property_create ( PropertyType type );
void rofi_theme_property_free ( Property *p );
void rofi_theme_free ( Widget * );
void rofi_theme_parse_file ( const char *file );
void rofi_theme_widget_add_properties ( Widget *widget, GHashTable *table );
/**
* Public API

View file

@ -66,12 +66,11 @@ int yylex (YYSTYPE *, YYLTYPE *);
%%
start:
entries
optional_properties
entries {
$$ = $2;
if ( $1 != NULL ) {
$$->properties = $1;
}
{
$$ = $1;
rofi_theme_widget_add_properties ( $$, $2 );
}
;
entries:
@ -80,7 +79,12 @@ entries:
$$ = rofi_theme = (Widget*)g_malloc0 (sizeof(Widget));
rofi_theme->name = g_strdup ( "Window" );
}
| entries entry { $$ = $1; }
| entries
optional_properties
entry {
$$ = $1;
rofi_theme_widget_add_properties ( $$, $2);
}
;
entry:
@ -96,11 +100,7 @@ CLASS_PREFIX class_name state_path BOPEN optional_properties BCLOSE
g_list_foreach ( $3, (GFunc)g_free , NULL );
g_list_free ( $3 );
widget->set = TRUE;
if ( widget->properties != NULL ) {
fprintf(stderr, "Properties already set on this widget.\n");
exit ( EXIT_FAILURE );
}
widget->properties = $5;
rofi_theme_widget_add_properties ( widget, $5);
}
| NAME_PREFIX name_path state_path BOPEN optional_properties BCLOSE
{
@ -117,11 +117,7 @@ CLASS_PREFIX class_name state_path BOPEN optional_properties BCLOSE
g_list_foreach ( $3, (GFunc)g_free , NULL );
g_list_free ( $3 );
widget->set = TRUE;
if ( widget->properties != NULL ) {
fprintf(stderr, "Properties already set on this widget.\n");
exit ( EXIT_FAILURE );
}
widget->properties = $5;
rofi_theme_widget_add_properties ( widget, $5);
};
/**

View file

@ -52,7 +52,7 @@ void rofi_theme_free ( Widget *widget )
g_hash_table_destroy ( widget->properties );
}
for ( unsigned int i = 0; i < widget->num_widgets; i++ ){
rofi_theme_free ( widget->widgets[i] );
rofi_theme_free ( widget->widgets[i] );
}
g_free ( widget->widgets );
g_free ( widget->name );
@ -68,10 +68,10 @@ static void rofi_theme_print_property_index ( int depth, Property *p )
switch ( p->type )
{
case P_STRING:
printf("\"%s\"", p->value.s);
printf("\"%s\"", p->value.s);
break;
case P_INTEGER:
printf("%d", p->value.i);
printf("%d", p->value.i);
break;
case P_DOUBLE:
printf("%.2f", p->value.f);
@ -122,6 +122,27 @@ void yyerror(YYLTYPE *yylloc, const char* s) {
fprintf(stderr, "From line %d column %d to line %d column %d\n", yylloc->first_line, yylloc->first_column, yylloc->last_line, yylloc->last_column);
exit(EXIT_FAILURE);
}
static gboolean rofi_theme_steal_property_int ( gpointer key, gpointer value, gpointer user_data)
{
GHashTable *table = (GHashTable*)user_data;
g_hash_table_replace ( table, key, value);
return TRUE;
}
void rofi_theme_widget_add_properties ( Widget *widget, GHashTable *table )
{
if ( table == NULL ) {
return;
}
if ( widget->properties == NULL ){
widget->properties = table;
return;
}
g_hash_table_foreach_steal ( table, rofi_theme_steal_property_int, widget->properties );
g_hash_table_destroy ( table );
}
/**
* Public API
*/
@ -159,7 +180,7 @@ static Widget *rofi_theme_find ( Widget *widget , const char *name )
widget = f;
found = TRUE;
}
}
}
g_strfreev(names);
return widget;
}
@ -172,7 +193,7 @@ static Property *rofi_theme_find_property ( Widget *widget, PropertyType type, c
if ( p->type == type ){
return p;
}
}
}
widget = widget->parent;
}
return NULL;
@ -260,7 +281,7 @@ double rofi_theme_get_double ( const char *wclass, const char *name, const char
}
return def;
}
void rofi_theme_get_color ( const char *wclass, const char *name, const char *state, const char *property, cairo_t *d)
void rofi_theme_get_color ( const char *wclass, const char *name, const char *state, const char *property, cairo_t *d)
{
if ( rofi_theme == NULL ) {
return ;

View file

@ -31,8 +31,8 @@ static gboolean test_widget_clicked ( G_GNUC_UNUSED widget *wid, G_GNUC_UNUSED x
int main ( G_GNUC_UNUSED int argc, G_GNUC_UNUSED char **argv )
{
{
box *b = box_create ( BOX_HORIZONTAL, 0, 0, 100, 20 );
box_set_padding ( b, 5 );
box *b = box_create ( "box", BOX_HORIZONTAL, 0, 0, 100, 20 );
//box_set_padding ( b, 5 );
widget *wid1 = g_malloc0(sizeof(widget));
box_add ( b , WIDGET( wid1 ), TRUE, FALSE );
@ -92,8 +92,8 @@ int main ( G_GNUC_UNUSED int argc, G_GNUC_UNUSED char **argv )
widget_free ( WIDGET ( b ) );
}
{
box *b = box_create ( BOX_VERTICAL, 0, 0, 20, 100 );
box_set_padding ( b, 5 );
box *b = box_create ( "box", BOX_VERTICAL, 0, 0, 20, 100 );
//box_set_padding ( b, 5 );
widget *wid1 = g_malloc0(sizeof(widget));
box_add ( b , WIDGET( wid1 ), TRUE, FALSE );
@ -152,8 +152,8 @@ int main ( G_GNUC_UNUSED int argc, G_GNUC_UNUSED char **argv )
widget_free ( WIDGET ( b ) );
}
{
box *b = box_create ( BOX_VERTICAL, 0, 0, 20, 100 );
box_set_padding ( b, 5 );
box *b = box_create ( "box", BOX_VERTICAL, 0, 0, 20, 100 );
//box_set_padding ( b, 5 );
widget *wid1 = g_malloc0(sizeof(widget));
widget_enable(wid1);
wid1->clicked = test_widget_clicked;

View file

@ -53,7 +53,7 @@ int main ( G_GNUC_UNUSED int argc, G_GNUC_UNUSED char **argv )
PangoContext *p = pango_cairo_create_context ( draw );
textbox_set_pango_context ( p );
textbox *box = textbox_create ( TB_EDITABLE | TB_AUTOWIDTH | TB_AUTOHEIGHT, 0, 0, -1, -1,
textbox *box = textbox_create ( "textbox", TB_EDITABLE | TB_AUTOWIDTH | TB_AUTOHEIGHT, 0, 0, -1, -1,
NORMAL, "test" );
TASSERT ( box != NULL );