2017-04-15 06:32:05 -04:00
|
|
|
/*
|
|
|
|
* rofi
|
|
|
|
*
|
|
|
|
* MIT/X11 License
|
|
|
|
* Copyright 2013-2017 Qball Cow <qball@gmpclient.org>
|
|
|
|
*
|
|
|
|
* Permission is hereby granted, free of charge, to any person obtaining
|
|
|
|
* a copy of this software and associated documentation files (the
|
|
|
|
* "Software"), to deal in the Software without restriction, including
|
|
|
|
* without limitation the rights to use, copy, modify, merge, publish,
|
|
|
|
* distribute, sublicense, and/or sell copies of the Software, and to
|
|
|
|
* permit persons to whom the Software is furnished to do so, subject to
|
|
|
|
* the following conditions:
|
|
|
|
*
|
|
|
|
* The above copyright notice and this permission notice shall be
|
|
|
|
* included in all copies or substantial portions of the Software.
|
|
|
|
*
|
|
|
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
|
|
|
|
* OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
|
|
|
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
|
|
|
|
* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
|
|
|
|
* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
|
|
|
|
* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
|
|
|
|
* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
2016-12-12 10:55:31 -05:00
|
|
|
%define api.pure
|
2017-03-13 03:54:55 -04:00
|
|
|
%define parse.error verbose
|
2017-01-09 16:29:31 -05:00
|
|
|
%locations
|
2016-12-12 17:40:43 -05:00
|
|
|
%glr-parser
|
2016-12-11 08:08:28 -05:00
|
|
|
%skeleton "glr.c"
|
2016-12-09 13:49:49 -05:00
|
|
|
%debug
|
2017-01-09 16:29:31 -05:00
|
|
|
%parse-param {const char *what}
|
2016-12-09 13:49:49 -05:00
|
|
|
%code requires {
|
|
|
|
#include "theme.h"
|
2017-03-28 03:02:39 -04:00
|
|
|
#include "xrmoptions.h"
|
2017-03-13 11:42:17 -04:00
|
|
|
|
|
|
|
typedef struct YYLTYPE {
|
|
|
|
int first_line;
|
|
|
|
int first_column;
|
|
|
|
int last_line;
|
|
|
|
int last_column;
|
|
|
|
char *filename;
|
|
|
|
} YYLTYPE;
|
|
|
|
# define YYLTYPE_IS_DECLARED 1 /* alert the parser that we have our own definition */
|
|
|
|
|
|
|
|
# define YYLLOC_DEFAULT(Current, Rhs, N) \
|
|
|
|
do \
|
|
|
|
if (N) \
|
|
|
|
{ \
|
|
|
|
(Current).first_line = YYRHSLOC (Rhs, 1).first_line; \
|
|
|
|
(Current).first_column = YYRHSLOC (Rhs, 1).first_column; \
|
|
|
|
(Current).last_line = YYRHSLOC (Rhs, N).last_line; \
|
|
|
|
(Current).last_column = YYRHSLOC (Rhs, N).last_column; \
|
|
|
|
(Current).filename = YYRHSLOC (Rhs, 1).filename; \
|
|
|
|
} \
|
|
|
|
else \
|
|
|
|
{ /* empty RHS */ \
|
|
|
|
(Current).first_line = (Current).last_line = \
|
|
|
|
YYRHSLOC (Rhs, 0).last_line; \
|
|
|
|
(Current).first_column = (Current).last_column = \
|
|
|
|
YYRHSLOC (Rhs, 0).last_column; \
|
|
|
|
(Current).filename = NULL; /* new */ \
|
|
|
|
} \
|
|
|
|
while (0)
|
2016-12-09 13:49:49 -05:00
|
|
|
}
|
|
|
|
%{
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdlib.h>
|
2016-12-31 15:37:19 -05:00
|
|
|
#include <glib.h>
|
2016-12-09 13:49:49 -05:00
|
|
|
|
2016-12-12 10:55:31 -05:00
|
|
|
#include "lexer/theme-parser.h"
|
2017-01-01 12:08:49 -05:00
|
|
|
ThemeWidget *rofi_theme = NULL;
|
2017-01-09 16:29:31 -05:00
|
|
|
void yyerror(YYLTYPE *yylloc, const char *what, const char* s);
|
2016-12-12 10:55:31 -05:00
|
|
|
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;
|
2017-03-13 03:54:55 -04:00
|
|
|
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
|
|
|
}
|
|
|
|
|
2017-01-09 16:29:31 -05:00
|
|
|
%token <ival> T_END 0 "end of file"
|
|
|
|
%token <ival> T_ERROR 1 "error from file parser"
|
|
|
|
%token <ival> T_ERROR_PROPERTY 2 "invalid property value"
|
2017-03-13 05:49:33 -04:00
|
|
|
%token <ival> T_ERROR_SECTION 3 "invalid property name"
|
2017-01-09 16:29:31 -05:00
|
|
|
%token <ival> T_ERROR_NAMESTRING 4 "invalid element name"
|
|
|
|
%token <ival> T_ERROR_DEFAULTS 5 "invalid defaults name"
|
2017-03-13 03:54:55 -04:00
|
|
|
%token <ival> T_ERROR_INCLUDE 6 "invalid import value"
|
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
|
2017-01-09 16:29:31 -05:00
|
|
|
%token <sval> N_STRING "property name"
|
2017-01-06 18:23:39 -05:00
|
|
|
%token <ival> T_POSITION;
|
2017-01-08 18:09:02 -05:00
|
|
|
%token <ival> T_HIGHLIGHT_STYLE
|
2017-01-08 10:09:24 -05:00
|
|
|
%token <sval> NAME_ELEMENT "Element name"
|
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
|
2016-12-12 17:40:43 -05:00
|
|
|
%token <sval> FIRST_NAME
|
2016-12-09 13:49:49 -05:00
|
|
|
|
2017-04-09 09:27:23 -04:00
|
|
|
%token BOPEN "bracket open ('{')"
|
|
|
|
%token BCLOSE "bracket close ('}')"
|
|
|
|
%token PSEP "property separator (':')"
|
|
|
|
%token PCLOSE "property close (';')"
|
|
|
|
%token NSEP "Name separator (' ' or '.')"
|
2017-03-13 03:54:55 -04:00
|
|
|
%token NAME_PREFIX "Element section ('# {name} { ... }')"
|
2017-01-09 12:32:26 -05:00
|
|
|
%token WHITESPACE "White space"
|
|
|
|
%token PDEFAULTS "Default settings section ( '* { ... }')"
|
2017-03-27 03:04:55 -04:00
|
|
|
%token CONFIGURATION "Configuration block"
|
2016-12-09 13:49:49 -05:00
|
|
|
|
2017-01-08 18:09:02 -05:00
|
|
|
%type <ival> highlight_styles
|
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
|
2016-12-09 13:49:49 -05:00
|
|
|
%type <name_path> name_path
|
|
|
|
%type <property> property
|
|
|
|
%type <property_list> property_list
|
|
|
|
%type <property_list> optional_properties
|
2017-01-06 18:23:39 -05:00
|
|
|
%start entries
|
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.
|
2017-01-08 10:09:24 -05:00
|
|
|
if (rofi_theme == NULL ){
|
2017-03-04 14:09:19 -05:00
|
|
|
$$ = rofi_theme = g_slice_new0 ( ThemeWidget );
|
2017-01-08 10:09:24 -05:00
|
|
|
rofi_theme->name = g_strdup ( "Root" );
|
|
|
|
}
|
2016-12-09 13:49:49 -05:00
|
|
|
}
|
2016-12-16 03:28:13 -05:00
|
|
|
| entries
|
|
|
|
entry {
|
|
|
|
}
|
2016-12-09 13:49:49 -05:00
|
|
|
;
|
|
|
|
|
|
|
|
entry:
|
2017-01-06 17:25:55 -05:00
|
|
|
NAME_PREFIX name_path BOPEN optional_properties BCLOSE
|
2016-12-12 15:14:57 -05:00
|
|
|
{
|
2017-01-01 12:08:49 -05:00
|
|
|
ThemeWidget *widget = rofi_theme;
|
2016-12-12 15:14:57 -05:00
|
|
|
for ( GList *iter = g_list_first ( $2 ); iter ; iter = g_list_next ( iter ) ) {
|
2017-01-04 09:05:39 -05:00
|
|
|
widget = rofi_theme_find_or_create_name ( widget, iter->data );
|
2016-12-12 15:14:57 -05:00
|
|
|
}
|
|
|
|
g_list_foreach ( $2, (GFunc)g_free , NULL );
|
|
|
|
g_list_free ( $2 );
|
2016-12-12 18:09:51 -05:00
|
|
|
widget->set = TRUE;
|
2017-01-06 17:25:55 -05:00
|
|
|
rofi_theme_widget_add_properties ( widget, $4);
|
2017-01-06 17:41:10 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
|
PDEFAULTS BOPEN optional_properties BCLOSE {
|
|
|
|
rofi_theme_widget_add_properties ( rofi_theme, $3);
|
|
|
|
}
|
2017-03-27 03:04:55 -04:00
|
|
|
| CONFIGURATION BOPEN optional_properties BCLOSE {
|
|
|
|
GHashTableIter iter;
|
|
|
|
g_hash_table_iter_init ( &iter, $3 );
|
|
|
|
gpointer key,value;
|
|
|
|
while ( g_hash_table_iter_next ( &iter, &key, &value ) ) {
|
|
|
|
Property *p = (Property *) value;
|
2017-03-28 11:33:43 -04:00
|
|
|
config_parse_set_property ( p );
|
2017-03-27 03:04:55 -04:00
|
|
|
}
|
2017-04-12 03:22:26 -04:00
|
|
|
g_hash_table_destroy ( $3 );
|
2017-03-27 03:04:55 -04:00
|
|
|
}
|
2017-01-06 17:41:10 -05:00
|
|
|
;
|
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
|
|
|
}
|
2016-12-31 15:37:19 -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 };
|
2016-12-31 15:37:19 -05:00
|
|
|
}
|
2016-12-31 19:31:25 -05:00
|
|
|
| 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 };
|
|
|
|
}
|
2016-12-31 15:37:19 -05:00
|
|
|
| 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 };
|
2016-12-31 15:37:19 -05:00
|
|
|
}
|
2017-01-06 13:04:25 -05:00
|
|
|
| pvalue PSEP T_POSITION PCLOSE{
|
|
|
|
$$ = rofi_theme_property_create ( P_POSITION );
|
|
|
|
$$->name = $1;
|
|
|
|
$$->value.i = $3;
|
|
|
|
}
|
2017-01-08 18:09:02 -05:00
|
|
|
| pvalue PSEP highlight_styles T_COLOR PCLOSE {
|
|
|
|
$$ = rofi_theme_property_create ( P_HIGHLIGHT );
|
|
|
|
$$->name = $1;
|
|
|
|
$$->value.highlight.style = $3|HL_COLOR;
|
|
|
|
$$->value.highlight.color = $4;
|
|
|
|
}
|
|
|
|
| pvalue PSEP highlight_styles PCLOSE {
|
|
|
|
$$ = rofi_theme_property_create ( P_HIGHLIGHT );
|
|
|
|
$$->name = $1;
|
|
|
|
$$->value.highlight.style = $3;
|
|
|
|
}
|
2016-12-09 13:49:49 -05:00
|
|
|
;
|
|
|
|
|
2017-01-08 18:09:02 -05:00
|
|
|
highlight_styles:
|
|
|
|
T_HIGHLIGHT_STYLE { $$ = $1; }
|
|
|
|
| highlight_styles T_HIGHLIGHT_STYLE {
|
|
|
|
$$ = $1 | $2;
|
|
|
|
}
|
|
|
|
;
|
2016-12-09 13:49:49 -05:00
|
|
|
pvalue: N_STRING { $$ = $1; }
|
|
|
|
|
|
|
|
name_path:
|
2016-12-12 17:40:43 -05:00
|
|
|
NAME_ELEMENT { $$ = g_list_append ( NULL, $1 );}
|
|
|
|
| name_path NSEP NAME_ELEMENT { $$ = g_list_append ( $1, $3);}
|
2017-01-06 17:25:55 -05:00
|
|
|
| name_path NSEP { $$ = $1; }
|
2016-12-09 13:49:49 -05:00
|
|
|
;
|
|
|
|
|
|
|
|
%%
|
|
|
|
|