summaryrefslogtreecommitdiffstats
path: root/lexer
diff options
context:
space:
mode:
authorDave Davenport <DaveDavenport@users.noreply.github.com>2017-05-15 22:46:33 +0200
committerGitHub <noreply@github.com>2017-05-15 22:46:33 +0200
commit494550d38d572801ba3924611b09c7ca2b20610a (patch)
treedf744a40f2bcaee4ba155faf4113b42089494500 /lexer
parente397c346da38f71c8b8f6e5e4cf57f7ee01b2404 (diff)
[ThemeParser] Add CSS color names support
* [ThemeParser] Add css color names * Add CSS color support (WIP) * Parse color names in the lexer. * Add test for css color names * Indent and fix ordering
Diffstat (limited to 'lexer')
-rw-r--r--lexer/theme-lexer.l24
-rw-r--r--lexer/theme-parser.y43
2 files changed, 38 insertions, 29 deletions
diff --git a/lexer/theme-lexer.l b/lexer/theme-lexer.l
index a35a5044..72d569c7 100644
--- a/lexer/theme-lexer.l
+++ b/lexer/theme-lexer.l
@@ -41,6 +41,7 @@
#include "theme.h"
#include "theme-parser.h"
+#include "css-colors.h"
#define LOG_DOMAIN "Parser"
int last_state = 0;
@@ -147,6 +148,7 @@ UANYN {ASCN}|{U2}{U}|{U3}{U}{U}|{U4}{U}{U}{U}
WHITESPACE [[:blank:]]
WSO [[:blank:]]*
WORD [[:alnum:]-]+
+COLOR_NAME [[:alpha:]]+
STRING {UANYN}+
HEX [[:xdigit:]]
NUMBER [[:digit:]]
@@ -179,12 +181,13 @@ ANGLE_RAD "rad"
ANGLE_TURN "turn"
/* Color schema */
-RGBA "rgba"
-RGB "rgb"
+RGBA rgb[a]?
HWB "hwb"
CMYK "cmyk"
HSL hsl[a]?
+COLOR_TRANSPARENT "transparent"
+
S_T_PARENT_LEFT \(
S_T_PARENT_RIGHT \)
COMMA ,
@@ -422,7 +425,6 @@ if ( queue == NULL ){
}
/* Color schemes */
<PROPERTIES>{RGBA} { return T_COL_RGBA; }
-<PROPERTIES>{RGB} { return T_COL_RGB; }
<PROPERTIES>{HSL} { return T_COL_HSL; }
<PROPERTIES>{HWB} { return T_COL_HWB; }
<PROPERTIES>{CMYK} { return T_COL_CMYK; }
@@ -448,6 +450,22 @@ if ( queue == NULL ){
<PROPERTIES>{ANGLE_GRAD} { return T_ANGLE_GRAD; }
<PROPERTIES>{ANGLE_TURN} { return T_ANGLE_TURN; }
+<PROPERTIES>{COLOR_TRANSPARENT} {
+ return T_COLOR_TRANSPARENT;
+}
+<PROPERTIES>{COLOR_NAME} {
+ for ( unsigned int iter = 0; iter < num_CSSColors; iter++){
+ if ( strcasecmp(yytext, CSSColors[iter].name )== 0 ) {
+ yylval->colorval.alpha = 1.0;
+ yylval->colorval.red = CSSColors[iter].r/255.0;
+ yylval->colorval.green = CSSColors[iter].g/255.0;
+ yylval->colorval.blue = CSSColors[iter].b/255.0;
+ return T_COLOR_NAME;
+ }
+ }
+ REJECT;
+}
+
<INITIAL><<EOF>> {
ParseObject *po = g_queue_pop_head ( file_queue );
if ( po ) {
diff --git a/lexer/theme-parser.y b/lexer/theme-parser.y
index 7ba81ae6..7e9c1da2 100644
--- a/lexer/theme-parser.y
+++ b/lexer/theme-parser.y
@@ -35,6 +35,7 @@
%code requires {
#include "theme.h"
#include "xrmoptions.h"
+#include "css-colors.h"
typedef struct YYLTYPE {
int first_line;
@@ -157,6 +158,7 @@ static ThemeColor hwb_to_rgb ( double h, double w, double b)
%token <fval> T_DOUBLE "Floating-point number"
%token <sval> T_STRING "UTF-8 encoded string"
%token <sval> T_PROP_NAME "property name"
+%token <colorval> T_COLOR_NAME "Color value by name"
%token <sval> T_NAME_ELEMENT "Element name"
%token <bval> T_BOOLEAN "Boolean value (true or false)"
%token <colorval> T_COLOR "Hexidecimal color value"
@@ -183,8 +185,7 @@ static ThemeColor hwb_to_rgb ( double h, double w, double b)
%token T_ANGLE_RAD "Radians"
%token T_ANGLE_TURN "Turns"
-%token T_COL_RGBA "rgba colorscheme"
-%token T_COL_RGB "rgb colorscheme"
+%token T_COL_RGBA "rgb[a] colorscheme"
%token T_COL_HSL "hsl colorscheme"
%token T_COL_HWB "hwb colorscheme"
%token T_COL_CMYK "cmyk colorscheme"
@@ -206,6 +207,8 @@ static ThemeColor hwb_to_rgb ( double h, double w, double b)
%token T_PDEFAULTS "Default settings section ( '* { ... }')"
%token T_CONFIGURATION "Configuration block"
+%token T_COLOR_TRANSPARENT "Transparent"
+
%type <sval> t_entry
%type <theme> t_entry_list
%type <name_path> t_entry_name_path
@@ -433,41 +436,21 @@ t_property_line_style
*/
t_property_color
/** rgba ( 0-255 , 0-255, 0-255, 0-1.0 ) */
-: T_COL_RGBA T_PARENT_LEFT T_INT T_COMMA T_INT T_COMMA T_INT T_COMMA t_property_color_value_unit T_PARENT_RIGHT {
+: T_COL_RGBA T_PARENT_LEFT T_INT T_COMMA T_INT T_COMMA T_INT t_property_color_opt_alpha_c T_PARENT_RIGHT {
if ( ! check_in_range($3,0,255, &(@$)) ) { YYABORT; }
if ( ! check_in_range($5,0,255, &(@$)) ) { YYABORT; }
if ( ! check_in_range($7,0,255, &(@$)) ) { YYABORT; }
- $$.alpha = $9;
+ $$.alpha = $8;
$$.red = $3/255.0;
$$.green = $5/255.0;
$$.blue = $7/255.0;
}
/** rgba ( 0-255 0-255 0-255 / 0-1.0 ) */
-| T_COL_RGBA T_PARENT_LEFT T_INT T_INT T_INT T_FORWARD_SLASH t_property_color_value_unit T_PARENT_RIGHT {
- if ( ! check_in_range($3,0,255, &(@$)) ) { YYABORT; }
- if ( ! check_in_range($4,0,255, &(@$)) ) { YYABORT; }
- if ( ! check_in_range($5,0,255, &(@$)) ) { YYABORT; }
- $$.alpha = $7;
- $$.red = $3/255.0;
- $$.green = $4/255.0;
- $$.blue = $5/255.0;
-}
- /** rgb ( 0-255 , 0-255, 0-255 ) */
-| T_COL_RGB T_PARENT_LEFT T_INT T_COMMA T_INT T_COMMA T_INT T_PARENT_RIGHT {
- if ( ! check_in_range($3,0,255, &(@$)) ) { YYABORT; }
- if ( ! check_in_range($5,0,255, &(@$)) ) { YYABORT; }
- if ( ! check_in_range($7,0,255, &(@$)) ) { YYABORT; }
- $$.alpha = 1.0;
- $$.red = $3/255.0;
- $$.green = $5/255.0;
- $$.blue = $7/255.0;
-}
- /** rgb ( 0-255 0-255 0-255 ) */
-| T_COL_RGB T_PARENT_LEFT T_INT T_INT T_INT T_PARENT_RIGHT {
+| T_COL_RGBA T_PARENT_LEFT T_INT T_INT T_INT t_property_color_opt_alpha_ws T_PARENT_RIGHT {
if ( ! check_in_range($3,0,255, &(@$)) ) { YYABORT; }
if ( ! check_in_range($4,0,255, &(@$)) ) { YYABORT; }
if ( ! check_in_range($5,0,255, &(@$)) ) { YYABORT; }
- $$.alpha = 1.0;
+ $$.alpha = $6;
$$.red = $3/255.0;
$$.green = $4/255.0;
$$.blue = $5/255.0;
@@ -516,6 +499,14 @@ t_property_color
| T_COLOR {
$$ = $1;
}
+| T_COLOR_TRANSPARENT {
+ $$.alpha = 0.0;
+ $$.red = $$.green = $$.blue = 0.0;
+}
+| T_COLOR_NAME t_property_color_opt_alpha_ws {
+ $$ = $1;
+ $$.alpha = $2;
+}
;
t_property_color_opt_alpha_c
: %empty { $$ = 1.0; }