1
0
Fork 0
mirror of https://github.com/davatorium/rofi.git synced 2024-11-18 13:54:36 -05:00

Move position parsing to bison file.

This commit is contained in:
Dave Davenport 2017-05-09 13:53:45 +02:00
parent 2a381856aa
commit cf8796ccd3
4 changed files with 73 additions and 50 deletions

View file

@ -56,22 +56,22 @@ typedef enum
{
/** Center */
WL_CENTER = 0,
/** Left top corner. */
WL_NORTH_WEST = 1,
/** Top middle */
WL_NORTH = 2,
/** Top right */
WL_NORTH_EAST = 3,
WL_NORTH = 1,
/** Middle right */
WL_EAST = 4,
/** Bottom right */
WL_SOUTH_EAST = 5,
WL_EAST = 2,
/** Bottom middle */
WL_SOUTH = 6,
/** Bottom left */
WL_SOUTH_WEST = 7,
WL_SOUTH = 4,
/** Middle left */
WL_WEST = 8
WL_WEST = 8,
/** Left top corner. */
WL_NORTH_WEST = WL_NORTH|WL_WEST,
/** Top right */
WL_NORTH_EAST = WL_NORTH|WL_EAST,
/** Bottom right */
WL_SOUTH_EAST = WL_SOUTH|WL_EAST,
/** Bottom left */
WL_SOUTH_WEST = WL_SOUTH|WL_WEST,
} WindowLocation;
/**

View file

@ -539,42 +539,11 @@ if ( queue == NULL ){
return T_COLOR;
}
<PROPERTIES>{CENTER} {
yylval->ival = WL_CENTER;
return T_POSITION;
}
<PROPERTIES>{EAST} {
yylval->ival = WL_EAST;
return T_POSITION;
}
<PROPERTIES>{WEST} {
yylval->ival = WL_WEST;
return T_POSITION;
}
<PROPERTIES>{SOUTH}{EAST} {
yylval->ival = WL_SOUTH_EAST;
return T_POSITION;
}
<PROPERTIES>{SOUTH}{WEST} {
yylval->ival = WL_SOUTH_WEST;
return T_POSITION;
}
<PROPERTIES>{SOUTH} {
yylval->ival = WL_SOUTH;
return T_POSITION;
}
<PROPERTIES>{NORTH}{EAST} {
yylval->ival = WL_NORTH_EAST;
return T_POSITION;
}
<PROPERTIES>{NORTH}{WEST} {
yylval->ival = WL_NORTH_WEST;
return T_POSITION;
}
<PROPERTIES>{NORTH} {
yylval->ival = WL_NORTH;
return T_POSITION;
}
<PROPERTIES>{CENTER} { return T_POS_CENTER; }
<PROPERTIES>{EAST} { return T_POS_EAST; }
<PROPERTIES>{WEST} { return T_POS_WEST; }
<PROPERTIES>{SOUTH} { return T_POS_SOUTH; }
<PROPERTIES>{NORTH} { return T_POS_NORTH; }
<PROPERTIES>{NONE} {
yylval->ival = HL_NONE;
return T_HIGHLIGHT_STYLE;

View file

@ -81,6 +81,7 @@ int yylex (YYSTYPE *, YYLTYPE *);
double fval;
char *sval;
int bval;
WindowLocation wloc;
ThemeColor colorval;
ThemeWidget *theme;
GList *name_path;
@ -100,7 +101,6 @@ int yylex (YYSTYPE *, YYLTYPE *);
%token <fval> T_DOUBLE
%token <sval> T_STRING
%token <sval> N_STRING "property name"
%token <ival> T_POSITION;
%token <ival> T_HIGHLIGHT_STYLE
%token <sval> NAME_ELEMENT "Element name"
%token <bval> T_BOOLEAN
@ -108,6 +108,12 @@ int yylex (YYSTYPE *, YYLTYPE *);
%token <distance> T_PIXEL
%token <sval> T_LINK
%token <sval> FIRST_NAME
%token T_POS_CENTER "Center"
%token T_POS_EAST "East"
%token T_POS_WEST "West"
%token T_POS_NORTH "North"
%token T_POS_SOUTH "South"
%token BOPEN "bracket open ('{')"
%token BCLOSE "bracket close ('}')"
@ -120,6 +126,9 @@ int yylex (YYSTYPE *, YYLTYPE *);
%token CONFIGURATION "Configuration block"
%type <ival> highlight_styles
%type <wloc> t_position
%type <wloc> t_position_ew
%type <wloc> t_position_sn
%type <sval> entry
%type <sval> pvalue
%type <theme> entries
@ -242,7 +251,7 @@ property
$$->name = $1;
$$->value.padding = (Padding){ $3, $4, $5, $6 };
}
| pvalue PSEP T_POSITION PCLOSE{
| pvalue PSEP t_position PCLOSE{
$$ = rofi_theme_property_create ( P_POSITION );
$$->name = $1;
$$->value.i = $3;
@ -260,6 +269,30 @@ property
}
;
/**
* Position can be either center,
* East or West, North Or South
* Or combi of East or West and North or South
*/
t_position
: T_POS_CENTER { $$ =WL_CENTER;}
| t_position_ew
| t_position_sn
| t_position_ew t_position_sn { $$ = $1|$2;}
| t_position_sn t_position_ew { $$ = $1|$2;}
;
t_position_ew
: T_POS_EAST { $$ = WL_EAST;}
| T_POS_WEST { $$ = WL_WEST;}
;
t_position_sn
: T_POS_NORTH { $$ = WL_NORTH;}
| T_POS_SOUTH { $$ = WL_SOUTH;}
;
/**
* Highlight style, allow mulitple styles to be combined.
*/
highlight_styles:
T_HIGHLIGHT_STYLE { $$ = $1; }
| highlight_styles T_HIGHLIGHT_STYLE {

View file

@ -332,6 +332,27 @@ START_TEST ( test_properties_position)
ck_assert_int_eq ( rofi_theme_get_position ( &wid, "southeast", WL_WEST) , WL_SOUTH_EAST);
ck_assert_int_eq ( rofi_theme_get_position ( &wid, "northwest", WL_NORTH) , WL_NORTH_WEST);
ck_assert_int_eq ( rofi_theme_get_position ( &wid, "northeast", WL_CENTER) , WL_NORTH_EAST);
rofi_theme_parse_string ( "* { southwest: south west; southeast: south east; northwest: north west; northeast:north east;}" );
ck_assert_int_eq ( rofi_theme_get_position ( &wid, "southwest", WL_EAST) , WL_SOUTH_WEST);
ck_assert_int_eq ( rofi_theme_get_position ( &wid, "southeast", WL_WEST) , WL_SOUTH_EAST);
ck_assert_int_eq ( rofi_theme_get_position ( &wid, "northwest", WL_NORTH) , WL_NORTH_WEST);
ck_assert_int_eq ( rofi_theme_get_position ( &wid, "northeast", WL_CENTER) , WL_NORTH_EAST);
rofi_theme_parse_string ( "* { westsouth: westsouth; eastsouth: eastsouth; westnorth: westnorth; eastnorth:eastnorth;}" );
ck_assert_int_eq ( rofi_theme_get_position ( &wid, "westsouth", WL_EAST) , WL_SOUTH_WEST);
ck_assert_int_eq ( rofi_theme_get_position ( &wid, "eastsouth", WL_WEST) , WL_SOUTH_EAST);
ck_assert_int_eq ( rofi_theme_get_position ( &wid, "westnorth", WL_NORTH) , WL_NORTH_WEST);
ck_assert_int_eq ( rofi_theme_get_position ( &wid, "eastnorth", WL_CENTER) , WL_NORTH_EAST);
rofi_theme_parse_string ( "* { westsouth: west south; eastsouth: east south; westnorth: west north; eastnorth:east north;}" );
ck_assert_int_eq ( rofi_theme_get_position ( &wid, "westsouth", WL_EAST) , WL_SOUTH_WEST);
ck_assert_int_eq ( rofi_theme_get_position ( &wid, "eastsouth", WL_WEST) , WL_SOUTH_EAST);
ck_assert_int_eq ( rofi_theme_get_position ( &wid, "westnorth", WL_NORTH) , WL_NORTH_WEST);
ck_assert_int_eq ( rofi_theme_get_position ( &wid, "eastnorth", WL_CENTER) , WL_NORTH_EAST);
rofi_theme_parse_string ( "* { westeast: west east;}" );
// Should return error.
// TODO: check error message.
g_string_free ( error_msg, TRUE);
error_msg = NULL;
error = 0;
}
END_TEST