From 847d2e82a045fbafbe42da9013f3623542cd42e4 Mon Sep 17 00:00:00 2001 From: Dave Davenport Date: Sun, 22 Oct 2017 12:41:51 +0200 Subject: [PATCH] [Lexer/Parser] Make the '#' before element optional. --- lexer/theme-lexer.l | 26 +++++++++++++++++++++----- lexer/theme-parser.y | 11 ++++++++++- 2 files changed, 31 insertions(+), 6 deletions(-) diff --git a/lexer/theme-lexer.l b/lexer/theme-lexer.l index a576e266..b906b59c 100644 --- a/lexer/theme-lexer.l +++ b/lexer/theme-lexer.l @@ -359,15 +359,16 @@ if ( queue == NULL ){ */ - /** - * Handle defaults: * { ... } - */ {CONFIGURATION} { g_queue_push_head ( queue, GINT_TO_POINTER (YY_START) ); BEGIN(DEFAULTS); return T_CONFIGURATION; } + + /** + * Handle defaults: * { ... } + */ {ASTERIX} { g_queue_push_head ( queue, GINT_TO_POINTER (YY_START) ); BEGIN(DEFAULTS); @@ -385,8 +386,12 @@ if ( queue == NULL ){ return T_ERROR_DEFAULTS; } -"#" { g_queue_push_head ( queue, GINT_TO_POINTER (YY_START) ); BEGIN(NAMESTR);return T_NAME_PREFIX;} - /* Go into parsing an section*/ +"#" { + g_queue_push_head ( queue, GINT_TO_POINTER (YY_START) ); + BEGIN(NAMESTR); + return T_NAME_PREFIX; +} + /* Go into parsing an section*/ "\{" { g_queue_push_head ( queue, GINT_TO_POINTER (YY_START) ); BEGIN(SECTION); @@ -557,6 +562,17 @@ if ( queue == NULL ){ yylloc->last_column = 1; yylloc->last_line ++; }; + + /** + * If we just encounter a word, we assume it is a Widget name. + * This makes include,theme, configuration a reserved keyword. + */ +{WORD} { + g_queue_push_head ( queue, GINT_TO_POINTER (YY_START) ); + BEGIN(NAMESTR); + yylval->sval = g_strdup(yytext); + return T_NAME_ELEMENT; +} . { return T_ERROR; } diff --git a/lexer/theme-parser.y b/lexer/theme-parser.y index b97bae22..de2acf6f 100644 --- a/lexer/theme-parser.y +++ b/lexer/theme-parser.y @@ -248,6 +248,7 @@ static ThemeColor hwb_to_rgb ( double h, double w, double b) %type t_property_element_list %type t_property_element_list_optional %type t_property_orientation +%type t_name_prefix_optional %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_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 ) ) { ThemeWidget *widget = rofi_theme;