mirror of
https://github.com/lbonn/rofi
synced 2024-11-22 20:03:03 +00:00
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.
This commit is contained in:
parent
ec6549748b
commit
a4c5a92199
5 changed files with 26 additions and 4 deletions
|
@ -15,6 +15,8 @@ typedef enum
|
|||
P_DOUBLE,
|
||||
/** String */
|
||||
P_STRING,
|
||||
/** Character */
|
||||
P_CHAR,
|
||||
/** Boolean */
|
||||
P_BOOLEAN,
|
||||
/** Color */
|
||||
|
@ -211,6 +213,8 @@ typedef union _PropertyValue
|
|||
double f;
|
||||
/** String */
|
||||
char *s;
|
||||
/** Character */
|
||||
char c;
|
||||
/** boolean */
|
||||
gboolean b;
|
||||
/** Color */
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -10,6 +10,8 @@ const char * const PropertyTypeName[P_NUM_TYPES] = {
|
|||
"Double",
|
||||
/** String */
|
||||
"String",
|
||||
/** Character */
|
||||
"Character",
|
||||
/** Boolean */
|
||||
"Boolean",
|
||||
/** Color */
|
||||
|
|
|
@ -422,7 +422,7 @@ void config_parse_cmd_options ( void )
|
|||
|
||||
static gboolean __config_parser_set_property ( XrmOption *option, const Property *p, char **error )
|
||||
{
|
||||
if ( option->type == xrm_String ) {
|
||||
if ( option->type == xrm_String ) {
|
||||
if ( p->type != P_STRING && p->type != P_LIST ) {
|
||||
*error = g_strdup_printf ( "Option: %s needs to be set with a string not a %s.", option->name, PropertyTypeName[p->type] );
|
||||
return TRUE;
|
||||
|
@ -477,6 +477,14 @@ static gboolean __config_parser_set_property ( XrmOption *option, const Property
|
|||
*( option->value.num ) = ( p->value.b );
|
||||
option->source = CONFIG_FILE_THEME;
|
||||
}
|
||||
else if ( option->type == xrm_Char ) {
|
||||
if ( p->type != P_CHAR ) {
|
||||
*error = g_strdup_printf ( "Option: %s needs to be set with a character not a %s.", option->name, PropertyTypeName[p->type] );
|
||||
return TRUE;
|
||||
}
|
||||
*( option->value.charc ) = ( p->value.c );
|
||||
option->source = CONFIG_FILE_THEME;
|
||||
}
|
||||
else {
|
||||
// TODO add type
|
||||
*error = g_strdup_printf ( "Option: %s is not of a supported type: %s.", option->name, PropertyTypeName[p->type] );
|
||||
|
|
Loading…
Reference in a new issue