From a4c5a92199249369f1f312f83f6ac3995c6c64f9 Mon Sep 17 00:00:00 2001 From: Jason Kim Date: Sun, 17 May 2020 12:50:38 +0000 Subject: Support rasi config character type options (#1131) * style: remove extra space * feat: handle xrm_Char in config parser Handle the `xrm_Char` case in the (rasi theme) config file parser. This should properly handle configuration like ``` matching-negate-char: "\0"; ``` and ``` matching-negate-char: "-"; ``` * refactor: don't handle mem in xrm_Char case `mem` shouldn't ever be set when `XrmOption` is `type` `xrm_Char`. Therefore, there is no need to check it and free it. Remove that logic. * refactor: further condense logic * style: s/Everythin/Everything/ * style: s/parsing an section/parsing a section/ ...and missing period. * feat(lexer): add CHAR token Add a `CHAR` token that takes things of the form `''` or some specific backslash escape sequences like `'\''` and `'\0'`. For now, save it as a `T_STRING`. * refactor: define char property type * feat(parser): add cval and T_CHAR * refactor: use char property for xrm_Char Instead of using strings for property elements of type char, use characters, which were recently added to the grammar. --- lexer/theme-lexer.l | 8 +++++--- lexer/theme-parser.y | 6 ++++++ 2 files changed, 11 insertions(+), 3 deletions(-) (limited to 'lexer') diff --git a/lexer/theme-lexer.l b/lexer/theme-lexer.l index 61b099f2..e8ca45ba 100644 --- a/lexer/theme-lexer.l +++ b/lexer/theme-lexer.l @@ -169,6 +169,7 @@ WSO [[:blank:]]* WORD [[:alnum:]-]+ COLOR_NAME [[:alpha:]]+ STRING \"{UANYN}*\" +CHAR \'({ASCN}|\\\\|\\\'|\\0)\' HEX [[:xdigit:]] NUMBER [[:digit:]] PNNUMBER [-+]?[[:digit:]]+ @@ -401,7 +402,7 @@ if ( queue == NULL ){ BEGIN(SECTION); return T_BOPEN; } - /** Everythin not yet parsed is an error. */ + /** Everything not yet parsed is an error. */ . { return T_ERROR_DEFAULTS; } @@ -411,13 +412,13 @@ if ( queue == NULL ){ BEGIN(NAMESTR); return T_NAME_PREFIX; } - /* Go into parsing an section*/ + /* Go into parsing a section. */ "\{" { g_queue_push_head ( queue, GINT_TO_POINTER (YY_START) ); BEGIN(SECTION); return T_BOPEN; } - /* Pop out of parsing an section. */ + /* Pop out of parsing a section. */
"\}" { g_queue_pop_head ( queue ); BEGIN(GPOINTER_TO_INT(g_queue_pop_head ( queue ))); @@ -441,6 +442,7 @@ if ( queue == NULL ){ {PNNUMBER}\.{NUMBER}+ { yylval->fval = g_ascii_strtod(yytext, NULL); return T_DOUBLE;} {PNNUMBER} { yylval->ival = (int)g_ascii_strtoll(yytext, NULL, 10); return T_INT;} {STRING} { yytext[yyleng-1] = '\0'; yylval->sval = g_strcompress(&yytext[1]); return T_STRING;} +{CHAR} { yytext[yyleng-1] = '\0'; yylval->cval = g_strcompress(&yytext[1])[0]; return T_CHAR;} @{WORD} { yylval->sval = g_strdup(yytext+1); diff --git a/lexer/theme-parser.y b/lexer/theme-parser.y index 8bc0b5fa..ed3fdb1c 100644 --- a/lexer/theme-parser.y +++ b/lexer/theme-parser.y @@ -138,6 +138,7 @@ static ThemeColor hwb_to_rgb ( double h, double w, double b) int ival; double fval; char *sval; + char cval; int bval; WindowLocation wloc; ThemeColor colorval; @@ -160,6 +161,7 @@ static ThemeColor hwb_to_rgb ( double h, double w, double b) %token T_INT "Integer number" %token T_DOUBLE "Floating-point number" %token T_STRING "UTF-8 encoded string" +%token T_CHAR "Character" %token T_PROP_NAME "property name" %token T_COLOR_NAME "Color value by name" %token T_NAME_ELEMENT "Element name" @@ -503,6 +505,10 @@ t_property_element $$ = rofi_theme_property_create ( P_STRING ); $$->value.s = $1; } +| T_CHAR { + $$ = rofi_theme_property_create ( P_CHAR ); + $$->value.c = $1; + } | T_LINK { $$ = rofi_theme_property_create ( P_LINK ); $$->value.link.name = $1; -- cgit v1.2.3