[Lexer/Parser] Make the '#' before element optional.

This commit is contained in:
Dave Davenport 2017-10-22 12:41:51 +02:00
parent 814fad8191
commit 847d2e82a0
2 changed files with 31 additions and 6 deletions

View file

@ -359,15 +359,16 @@ if ( queue == NULL ){
*/ */
/**
* Handle defaults: * { ... }
*/
<INITIAL>{CONFIGURATION} { <INITIAL>{CONFIGURATION} {
g_queue_push_head ( queue, GINT_TO_POINTER (YY_START) ); g_queue_push_head ( queue, GINT_TO_POINTER (YY_START) );
BEGIN(DEFAULTS); BEGIN(DEFAULTS);
return T_CONFIGURATION; return T_CONFIGURATION;
} }
/**
* Handle defaults: * { ... }
*/
<INITIAL>{ASTERIX} { <INITIAL>{ASTERIX} {
g_queue_push_head ( queue, GINT_TO_POINTER (YY_START) ); g_queue_push_head ( queue, GINT_TO_POINTER (YY_START) );
BEGIN(DEFAULTS); BEGIN(DEFAULTS);
@ -385,7 +386,11 @@ if ( queue == NULL ){
return T_ERROR_DEFAULTS; return T_ERROR_DEFAULTS;
} }
<INITIAL>"#" { g_queue_push_head ( queue, GINT_TO_POINTER (YY_START) ); BEGIN(NAMESTR);return T_NAME_PREFIX;} <INITIAL>"#" {
g_queue_push_head ( queue, GINT_TO_POINTER (YY_START) );
BEGIN(NAMESTR);
return T_NAME_PREFIX;
}
/* Go into parsing an section*/ /* Go into parsing an section*/
<NAMESTR>"\{" { <NAMESTR>"\{" {
g_queue_push_head ( queue, GINT_TO_POINTER (YY_START) ); g_queue_push_head ( queue, GINT_TO_POINTER (YY_START) );
@ -557,6 +562,17 @@ if ( queue == NULL ){
yylloc->last_column = 1; yylloc->last_column = 1;
yylloc->last_line ++; yylloc->last_line ++;
}; };
/**
* If we just encounter a word, we assume it is a Widget name.
* This makes include,theme, configuration a reserved keyword.
*/
<INITIAL>{WORD} {
g_queue_push_head ( queue, GINT_TO_POINTER (YY_START) );
BEGIN(NAMESTR);
yylval->sval = g_strdup(yytext);
return T_NAME_ELEMENT;
}
<INITIAL>. { <INITIAL>. {
return T_ERROR; return T_ERROR;
} }

View file

@ -248,6 +248,7 @@ static ThemeColor hwb_to_rgb ( double h, double w, double b)
%type <list> t_property_element_list %type <list> t_property_element_list
%type <list> t_property_element_list_optional %type <list> t_property_element_list_optional
%type <ival> t_property_orientation %type <ival> t_property_orientation
%type <ival> t_name_prefix_optional
%start t_entry_list %start t_entry_list
%% %%
@ -265,8 +266,16 @@ t_entry_list:
} }
; ;
/**
* Small dummy object to make the prefix optional.
*/
t_name_prefix_optional
: T_NAME_PREFIX {}
| %empty {}
;
t_entry: t_entry:
T_NAME_PREFIX t_entry_name_path_selectors T_BOPEN t_property_list_optional T_BCLOSE t_name_prefix_optional t_entry_name_path_selectors T_BOPEN t_property_list_optional T_BCLOSE
{ {
for ( GList *liter = g_list_first ( $2); liter; liter = g_list_next ( liter ) ) { for ( GList *liter = g_list_first ( $2); liter; liter = g_list_next ( liter ) ) {
ThemeWidget *widget = rofi_theme; ThemeWidget *widget = rofi_theme;