diff options
author | Jason Kim <git@jasonk.me> | 2020-05-17 12:50:38 +0000 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-05-17 14:50:38 +0200 |
commit | a4c5a92199249369f1f312f83f6ac3995c6c64f9 (patch) | |
tree | 026d5f2c3a52a95eaf92d6417a6632a5a31a3a34 /lexer | |
parent | ec6549748b6ec76cc7c13b8a5b117a3556996cc1 (diff) |
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 `'<char>'` 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.
Diffstat (limited to 'lexer')
-rw-r--r-- | lexer/theme-lexer.l | 8 | ||||
-rw-r--r-- | lexer/theme-parser.y | 6 |
2 files changed, 11 insertions, 3 deletions
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. */ <DEFAULTS>. { 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. */ <NAMESTR>"\{" { 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. */ <SECTION>"\}" { g_queue_pop_head ( queue ); BEGIN(GPOINTER_TO_INT(g_queue_pop_head ( queue ))); @@ -441,6 +442,7 @@ if ( queue == NULL ){ <PROPERTIES,PROPERTIES_ENV,PROPERTIES_VAR_DEFAULT,MEDIA_CONTENT>{PNNUMBER}\.{NUMBER}+ { yylval->fval = g_ascii_strtod(yytext, NULL); return T_DOUBLE;} <PROPERTIES,PROPERTIES_ENV,PROPERTIES_VAR_DEFAULT,MEDIA_CONTENT>{PNNUMBER} { yylval->ival = (int)g_ascii_strtoll(yytext, NULL, 10); return T_INT;} <PROPERTIES,PROPERTIES_ENV,PROPERTIES_VAR_DEFAULT>{STRING} { yytext[yyleng-1] = '\0'; yylval->sval = g_strcompress(&yytext[1]); return T_STRING;} +<PROPERTIES,PROPERTIES_ENV,PROPERTIES_VAR_DEFAULT>{CHAR} { yytext[yyleng-1] = '\0'; yylval->cval = g_strcompress(&yytext[1])[0]; return T_CHAR;} <PROPERTIES,PROPERTIES_ENV,PROPERTIES_VAR_DEFAULT>@{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 <ival> T_INT "Integer number" %token <fval> T_DOUBLE "Floating-point number" %token <sval> T_STRING "UTF-8 encoded string" +%token <cval> T_CHAR "Character" %token <sval> T_PROP_NAME "property name" %token <colorval> T_COLOR_NAME "Color value by name" %token <sval> 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; |