2017-03-28 03:02:39 -04:00
|
|
|
%option noyywrap
|
|
|
|
%option nounput
|
|
|
|
%option never-interactive
|
2016-12-12 10:55:31 -05:00
|
|
|
%option bison-locations
|
2016-12-09 13:49:49 -05:00
|
|
|
|
|
|
|
%{
|
|
|
|
#include <stdio.h>
|
2017-03-11 11:06:06 -05:00
|
|
|
#include <glib.h>
|
2017-03-13 11:17:11 -04:00
|
|
|
#include <gio/gio.h>
|
2017-03-11 11:06:06 -05:00
|
|
|
#include <helper.h>
|
|
|
|
#include "rofi.h"
|
2016-12-09 13:49:49 -05:00
|
|
|
|
2016-12-09 14:04:50 -05:00
|
|
|
#include "lexer/theme-parser.h"
|
2017-03-13 05:49:33 -04:00
|
|
|
|
|
|
|
#define LOG_DOMAIN "Parser"
|
2016-12-17 10:16:28 -05:00
|
|
|
int last_state = 0;
|
2017-03-11 11:06:06 -05:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Type of Object to parse.
|
|
|
|
*/
|
|
|
|
typedef enum {
|
|
|
|
/** Parse a file */
|
|
|
|
PT_FILE,
|
|
|
|
/** Parse a string */
|
|
|
|
PT_STRING
|
|
|
|
} ParseType;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Parse object
|
|
|
|
*/
|
|
|
|
typedef struct _ParseObject {
|
|
|
|
/** Type */
|
|
|
|
ParseType type;
|
|
|
|
|
|
|
|
/** File pointer */
|
|
|
|
FILE *filein;
|
2017-03-13 03:54:55 -04:00
|
|
|
char *filename;
|
2017-03-11 11:06:06 -05:00
|
|
|
|
|
|
|
/** Length of string */
|
2017-04-04 02:58:20 -04:00
|
|
|
int str_len;
|
2017-03-11 11:06:06 -05:00
|
|
|
/** String */
|
|
|
|
const char *input_str;
|
2017-03-13 03:54:55 -04:00
|
|
|
/** Position in file */
|
|
|
|
YYLTYPE location;
|
2017-03-11 11:06:06 -05:00
|
|
|
} ParseObject;
|
|
|
|
|
2017-03-13 05:49:33 -04:00
|
|
|
|
2017-03-13 09:16:38 -04:00
|
|
|
GList *imported_files = NULL;
|
2017-03-13 05:49:33 -04:00
|
|
|
GList *prev_imported_files = NULL;
|
2017-03-11 11:06:06 -05:00
|
|
|
GQueue *file_queue = NULL;
|
2016-12-17 10:16:28 -05:00
|
|
|
GQueue *queue = NULL;
|
2016-12-09 13:49:49 -05:00
|
|
|
|
2017-03-11 11:06:06 -05:00
|
|
|
ParseObject *current = NULL;
|
|
|
|
|
2017-03-13 11:17:11 -04:00
|
|
|
static char * rofi_theme_parse_prepare_file ( const char *file, const char *parent_file );
|
2016-12-12 10:55:31 -05:00
|
|
|
%}
|
|
|
|
%{
|
|
|
|
|
2017-01-08 10:09:24 -05:00
|
|
|
#define YY_INPUT(buf,result,max_size) \
|
|
|
|
{\
|
2017-03-11 11:06:06 -05:00
|
|
|
if ( current == NULL ) {\
|
|
|
|
result = YY_NULL;\
|
2017-01-08 10:09:24 -05:00
|
|
|
} else {\
|
2017-03-11 11:06:06 -05:00
|
|
|
switch ( current->type ) { \
|
|
|
|
case PT_FILE:\
|
|
|
|
{\
|
|
|
|
errno =0; \
|
|
|
|
while ( (result = (int) fread(buf, 1, max_size, current->filein))==0 && ferror(current->filein)) \
|
|
|
|
{ \
|
|
|
|
if( errno != EINTR) \
|
|
|
|
{ \
|
|
|
|
YY_FATAL_ERROR( "input in flex scanner failed" ); \
|
|
|
|
break; \
|
|
|
|
} \
|
|
|
|
errno=0; \
|
|
|
|
clearerr(current->filein); \
|
|
|
|
} \
|
|
|
|
break;\
|
|
|
|
}\
|
|
|
|
case PT_STRING:\
|
|
|
|
{\
|
|
|
|
yy_size_t len = MIN (max_size, current->str_len);\
|
|
|
|
if ( len > 0 ){\
|
|
|
|
memcpy (buf, current->input_str, len);\
|
|
|
|
current->input_str+=len;\
|
|
|
|
current->str_len-=len;\
|
|
|
|
result = len;\
|
|
|
|
} else {\
|
|
|
|
result = YY_NULL;\
|
|
|
|
} \
|
|
|
|
}\
|
|
|
|
}\
|
2017-01-08 10:09:24 -05:00
|
|
|
}\
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2016-12-12 10:55:31 -05:00
|
|
|
#define YY_USER_ACTION {\
|
|
|
|
yylloc->last_column+= yyleng;\
|
|
|
|
}
|
|
|
|
#define YY_LLOC_START {\
|
2017-01-05 16:04:39 -05:00
|
|
|
yylloc->first_line = yylloc->last_line;\
|
|
|
|
yylloc->first_column = yylloc->last_column;\
|
2016-12-12 10:55:31 -05:00
|
|
|
}
|
2016-12-09 13:49:49 -05:00
|
|
|
%}
|
2017-03-26 16:54:53 -04:00
|
|
|
|
|
|
|
ASC [\x00-\x7f]
|
|
|
|
ASCN [\x00-\t\v-\x7f]
|
|
|
|
U [\x80-\xbf]
|
|
|
|
U2 [\xc2-\xdf]
|
|
|
|
U3 [\xe0-\xef]
|
|
|
|
U4 [\xf0-\xf4]
|
|
|
|
|
|
|
|
// UANY {ASC}|{U2}{U}|{U3}{U}{U}|{U4}{U}{U}{U}
|
|
|
|
UANYN {ASCN}|{U2}{U}|{U3}{U}{U}|{U4}{U}{U}{U}
|
|
|
|
// UONLY {U2}{U}|{U3}{U}{U}|{U4}{U}{U}{U}
|
|
|
|
|
2017-01-05 16:04:39 -05:00
|
|
|
WHITESPACE [[:blank:]]
|
2016-12-19 11:48:20 -05:00
|
|
|
WORD [[:alnum:]-]+
|
2017-03-26 16:54:53 -04:00
|
|
|
STRING {UANYN}+
|
2016-12-19 11:48:20 -05:00
|
|
|
HEX [[:xdigit:]]
|
2016-12-31 15:37:19 -05:00
|
|
|
NUMBER [[:digit:]]
|
2017-01-11 17:19:29 -05:00
|
|
|
PNNUMBER [-+]?[[:digit:]]+
|
|
|
|
REAL [-+]?[[:digit:]]+(\.[[:digit:]]+)?
|
2016-12-31 15:37:19 -05:00
|
|
|
PX (px)
|
2016-12-31 16:47:22 -05:00
|
|
|
EM (em)
|
2017-01-03 13:23:09 -05:00
|
|
|
PERCENT (\%)
|
2016-12-12 17:40:43 -05:00
|
|
|
|
2017-01-06 17:41:10 -05:00
|
|
|
ASTERIX \*
|
|
|
|
|
2017-01-06 13:04:25 -05:00
|
|
|
CENTER "center"
|
|
|
|
NORTH "north"
|
|
|
|
SOUTH "south"
|
|
|
|
EAST "east"
|
|
|
|
WEST "west"
|
|
|
|
|
2017-01-08 18:09:02 -05:00
|
|
|
NONE "none"
|
|
|
|
BOLD "bold"
|
|
|
|
UNDERLINE "underline"
|
|
|
|
ITALIC "italic"
|
|
|
|
|
2017-01-04 16:27:27 -05:00
|
|
|
LS_DASH "dash"
|
|
|
|
LS_SOLID "solid"
|
|
|
|
|
2017-03-11 11:06:06 -05:00
|
|
|
INCLUDE "@import"
|
|
|
|
|
2017-03-29 13:54:13 -04:00
|
|
|
CONFIGURATION "configuration"
|
2017-03-27 03:04:55 -04:00
|
|
|
|
2017-03-11 11:06:06 -05:00
|
|
|
%x INCLUDE
|
2016-12-12 17:40:43 -05:00
|
|
|
%x PROPERTIES
|
|
|
|
%x NAMESTR
|
2017-03-13 05:49:33 -04:00
|
|
|
%x SECTION
|
2017-01-06 17:41:10 -05:00
|
|
|
%x DEFAULTS
|
2016-12-09 13:49:49 -05:00
|
|
|
%%
|
2016-12-12 10:55:31 -05:00
|
|
|
|
|
|
|
%{
|
|
|
|
YY_LLOC_START
|
|
|
|
%}
|
2016-12-17 10:16:28 -05:00
|
|
|
%{
|
|
|
|
if ( queue == NULL ){
|
|
|
|
queue = g_queue_new ( );
|
2017-03-13 11:42:17 -04:00
|
|
|
yylloc->filename = current->filename;
|
2017-03-28 03:19:04 -04:00
|
|
|
// unsure why todo this.
|
|
|
|
yylloc->first_line = yylloc->last_line = 1;
|
|
|
|
yylloc->first_column = yylloc->last_column = 1;
|
2016-12-17 10:16:28 -05:00
|
|
|
}
|
|
|
|
%}
|
2017-01-05 16:04:39 -05:00
|
|
|
|
2017-03-13 05:49:33 -04:00
|
|
|
/**
|
|
|
|
* General code for handling comments.
|
|
|
|
* Both C and C++ style comments, including nexting.
|
|
|
|
*/
|
|
|
|
|
2016-12-17 10:16:28 -05:00
|
|
|
<*>"//" {
|
2016-12-11 12:25:47 -05:00
|
|
|
int c;
|
2017-03-11 11:06:06 -05:00
|
|
|
while ((c = input()) != 0){
|
2016-12-11 12:25:47 -05:00
|
|
|
if (c == '\n') {
|
2016-12-12 10:55:31 -05:00
|
|
|
yylloc->last_column = 1;
|
|
|
|
yylloc->last_line ++;
|
2016-12-11 12:25:47 -05:00
|
|
|
break;
|
|
|
|
}
|
2016-12-12 10:55:31 -05:00
|
|
|
yylloc->last_column++;
|
|
|
|
}
|
|
|
|
YY_LLOC_START
|
2016-12-11 12:25:47 -05:00
|
|
|
}
|
2016-12-17 10:16:28 -05:00
|
|
|
<*>"/*" {
|
2016-12-11 12:25:47 -05:00
|
|
|
int c = 0, p;
|
|
|
|
int nesting_depth = 1;
|
|
|
|
while (nesting_depth) {
|
|
|
|
p = c;
|
|
|
|
c = input();
|
|
|
|
switch (c) {
|
2016-12-12 10:55:31 -05:00
|
|
|
case '*': yylloc->last_column++; if (p == '/') { c = 0; nesting_depth++; } break;
|
|
|
|
case '/': yylloc->last_column++; if (p == '*') { c = 0; nesting_depth--; } break;
|
|
|
|
case '\n': {
|
|
|
|
yylloc->last_column = 1;
|
|
|
|
yylloc->last_line ++;
|
|
|
|
break;
|
|
|
|
}
|
2017-03-11 11:06:06 -05:00
|
|
|
case 0: nesting_depth = 0; break;
|
2016-12-12 10:55:31 -05:00
|
|
|
default:
|
|
|
|
yylloc->last_column++;
|
|
|
|
;
|
2016-12-11 12:25:47 -05:00
|
|
|
}
|
|
|
|
}
|
2016-12-12 10:55:31 -05:00
|
|
|
YY_LLOC_START
|
2016-12-11 12:25:47 -05:00
|
|
|
}
|
2016-12-12 15:14:57 -05:00
|
|
|
|
2017-03-11 11:06:06 -05:00
|
|
|
/**
|
|
|
|
* HANDLE INCLUDES
|
|
|
|
*/
|
|
|
|
<INITIAL>{INCLUDE} {
|
|
|
|
g_queue_push_head ( queue, GINT_TO_POINTER (YY_START) );
|
|
|
|
BEGIN(INCLUDE);
|
|
|
|
}
|
2017-03-13 05:49:33 -04:00
|
|
|
/** Skip all whitespace */
|
2017-03-11 11:06:06 -05:00
|
|
|
<INCLUDE>{WHITESPACE} {}
|
|
|
|
|
2017-03-13 05:49:33 -04:00
|
|
|
/** Parse path. Last element in this INCLUDE */
|
2017-03-11 11:06:06 -05:00
|
|
|
<INCLUDE>\"{STRING}\" {
|
|
|
|
yytext[yyleng-1] = '\0';
|
2017-03-13 03:54:55 -04:00
|
|
|
ParseObject *top = g_queue_peek_head ( file_queue );
|
|
|
|
g_assert ( top != NULL );
|
2017-03-13 11:17:11 -04:00
|
|
|
char *filename = rofi_theme_parse_prepare_file ( &yytext[1], top->filename );
|
2017-03-13 09:16:38 -04:00
|
|
|
if ( g_list_find_custom ( imported_files, filename, (GCompareFunc)g_strcmp0 ) != NULL ) {
|
|
|
|
g_log ( LOG_DOMAIN, G_LOG_LEVEL_DEBUG, "Skipping file: '%s' already parsed.", filename );
|
2017-03-11 11:06:06 -05:00
|
|
|
} else {
|
2017-03-13 09:16:38 -04:00
|
|
|
g_log ( LOG_DOMAIN, G_LOG_LEVEL_DEBUG, "Parsing file: '%s'", filename );
|
|
|
|
FILE *f = fopen ( filename, "rb" );
|
|
|
|
if ( f ) {
|
|
|
|
top->location = *yylloc;
|
|
|
|
ParseObject *po = g_malloc0(sizeof(ParseObject));
|
|
|
|
po->type = PT_FILE;
|
|
|
|
po->filename = filename;
|
|
|
|
po->filein = f;
|
|
|
|
current = po;
|
|
|
|
g_queue_push_head ( file_queue, po );
|
|
|
|
imported_files = g_list_append ( imported_files, po->filename );
|
|
|
|
|
|
|
|
yypush_buffer_state (yy_create_buffer ( 0, YY_BUF_SIZE ));
|
|
|
|
yylloc->first_line = yylloc->last_line = 1;
|
|
|
|
yylloc->first_column = yylloc->last_column = 1;
|
2017-03-13 11:42:17 -04:00
|
|
|
yylloc->filename = current->filename;
|
2017-03-13 09:16:38 -04:00
|
|
|
} else {
|
|
|
|
char *str = g_markup_printf_escaped ( "Failed to open theme: <i>%s</i>\nError: <b>%s</b>",
|
|
|
|
filename, strerror ( errno ) );
|
|
|
|
rofi_add_error_message ( g_string_new ( str ) );
|
|
|
|
g_free ( str );
|
|
|
|
g_free(filename);
|
|
|
|
}
|
2017-03-11 11:06:06 -05:00
|
|
|
}
|
|
|
|
// Pop out of include. */
|
|
|
|
BEGIN(GPOINTER_TO_INT(g_queue_pop_head ( queue )));
|
|
|
|
}
|
2017-03-13 05:49:33 -04:00
|
|
|
/** Everythin not yet parsed is an error. */
|
|
|
|
<INCLUDE>. {
|
|
|
|
return T_ERROR_INCLUDE;
|
|
|
|
}
|
2017-03-11 11:06:06 -05:00
|
|
|
|
|
|
|
/**
|
|
|
|
* END INCLUDES
|
|
|
|
*/
|
|
|
|
|
2017-03-13 05:49:33 -04:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Handle defaults: * { ... }
|
|
|
|
*/
|
2017-03-27 03:04:55 -04:00
|
|
|
<INITIAL>{CONFIGURATION} {
|
|
|
|
g_queue_push_head ( queue, GINT_TO_POINTER (YY_START) );
|
|
|
|
BEGIN(DEFAULTS);
|
|
|
|
return CONFIGURATION;
|
|
|
|
|
|
|
|
}
|
2017-01-06 17:41:10 -05:00
|
|
|
<INITIAL>{ASTERIX} {
|
|
|
|
g_queue_push_head ( queue, GINT_TO_POINTER (YY_START) );
|
|
|
|
BEGIN(DEFAULTS);
|
|
|
|
return PDEFAULTS;
|
|
|
|
}
|
2017-03-13 05:49:33 -04:00
|
|
|
/** Skip all whitespace */
|
2017-01-06 17:41:10 -05:00
|
|
|
<DEFAULTS>{WHITESPACE} {}
|
|
|
|
<DEFAULTS>"\{" {
|
|
|
|
g_queue_push_head ( queue, GINT_TO_POINTER (YY_START) );
|
2017-03-13 05:49:33 -04:00
|
|
|
BEGIN(SECTION);
|
2017-01-06 17:41:10 -05:00
|
|
|
return BOPEN;
|
|
|
|
}
|
2017-03-13 05:49:33 -04:00
|
|
|
/** Everythin not yet parsed is an error. */
|
|
|
|
<DEFAULTS>. {
|
|
|
|
return T_ERROR_DEFAULTS;
|
|
|
|
}
|
2017-01-06 17:41:10 -05:00
|
|
|
|
2017-03-13 05:49:33 -04:00
|
|
|
<INITIAL>"#" { g_queue_push_head ( queue, GINT_TO_POINTER (YY_START) ); BEGIN(NAMESTR);return NAME_PREFIX;}
|
|
|
|
/* Go into parsing an section*/
|
2017-01-06 17:25:55 -05:00
|
|
|
<NAMESTR>"\{" {
|
2016-12-17 10:16:28 -05:00
|
|
|
g_queue_push_head ( queue, GINT_TO_POINTER (YY_START) );
|
2017-03-13 05:49:33 -04:00
|
|
|
BEGIN(SECTION);
|
2016-12-17 10:16:28 -05:00
|
|
|
return BOPEN;
|
|
|
|
}
|
2017-03-13 05:49:33 -04:00
|
|
|
/* Pop out of parsing an section. */
|
|
|
|
<SECTION>"\}" {
|
2017-01-06 17:25:55 -05:00
|
|
|
g_queue_pop_head ( queue );
|
2016-12-17 10:16:28 -05:00
|
|
|
BEGIN(GPOINTER_TO_INT(g_queue_pop_head ( queue )));
|
|
|
|
return BCLOSE;
|
|
|
|
}
|
|
|
|
|
2017-01-06 17:25:55 -05:00
|
|
|
<NAMESTR>\.|{WHITESPACE} { return NSEP; }
|
2017-03-13 05:49:33 -04:00
|
|
|
<SECTION>{WORD} { yylval->sval = g_strdup(yytext); return N_STRING;}
|
2016-12-17 10:16:28 -05:00
|
|
|
<NAMESTR>{WORD} { yylval->sval = g_strdup(yytext); return NAME_ELEMENT;}
|
2016-12-12 17:40:43 -05:00
|
|
|
|
2017-03-13 05:49:33 -04:00
|
|
|
/* After Namestr/Classstr we want to go to state str, then to { */
|
|
|
|
<INITIAL,SECTION>{WHITESPACE}+ ; // ignore all whitespace
|
2016-12-12 17:40:43 -05:00
|
|
|
<PROPERTIES>{WHITESPACE}+ ; // ignore all whitespace
|
2016-12-11 11:50:03 -05:00
|
|
|
|
2017-03-13 05:49:33 -04:00
|
|
|
<SECTION>":" { g_queue_push_head ( queue, GINT_TO_POINTER (YY_START) ); BEGIN(PROPERTIES); return PSEP; }
|
2016-12-17 10:16:28 -05:00
|
|
|
<PROPERTIES>";" { BEGIN(GPOINTER_TO_INT ( g_queue_pop_head ( queue ))); return PCLOSE;}
|
2016-12-12 17:40:43 -05:00
|
|
|
<PROPERTIES>(true|false) { yylval->bval= g_strcmp0(yytext, "true") == 0; return T_BOOLEAN;}
|
2017-01-11 17:19:29 -05:00
|
|
|
<PROPERTIES>{PNNUMBER}+ { yylval->ival = (int)g_ascii_strtoll(yytext, NULL, 10); return T_INT;}
|
|
|
|
<PROPERTIES>{PNNUMBER}+\.{NUMBER}+ { yylval->fval = g_ascii_strtod(yytext, NULL); return T_DOUBLE;}
|
2016-12-12 17:40:43 -05:00
|
|
|
<PROPERTIES>\"{STRING}\" { yytext[yyleng-1] = '\0'; yylval->sval = g_strdup(&yytext[1]); return T_STRING;}
|
2017-01-05 12:22:34 -05:00
|
|
|
<PROPERTIES>@{WORD} {
|
|
|
|
yylval->sval = g_strdup(yytext);
|
|
|
|
return T_LINK;
|
|
|
|
}
|
2016-12-31 15:37:19 -05:00
|
|
|
|
2016-12-31 17:27:17 -05:00
|
|
|
<PROPERTIES>{REAL}{EM} {
|
|
|
|
yylval->distance.distance = (double)g_ascii_strtod(yytext, NULL);
|
|
|
|
yylval->distance.type = PW_EM;
|
2017-01-04 16:27:27 -05:00
|
|
|
yylval->distance.style = SOLID;
|
2016-12-31 16:47:22 -05:00
|
|
|
return T_PIXEL;
|
|
|
|
}
|
2017-01-11 17:19:29 -05:00
|
|
|
<PROPERTIES>{PNNUMBER}{PX} {
|
2016-12-31 17:27:17 -05:00
|
|
|
yylval->distance.distance = (double)g_ascii_strtoll(yytext, NULL, 10);
|
|
|
|
yylval->distance.type = PW_PX;
|
2017-01-04 16:27:27 -05:00
|
|
|
yylval->distance.style = SOLID;
|
|
|
|
return T_PIXEL;
|
|
|
|
}
|
2017-01-11 17:19:29 -05:00
|
|
|
<PROPERTIES>{PNNUMBER}+{PX}{WHITESPACE}{LS_DASH} {
|
2017-01-04 16:27:27 -05:00
|
|
|
yylval->distance.distance = (double)g_ascii_strtoll(yytext, NULL, 10);
|
|
|
|
yylval->distance.type = PW_PX;
|
|
|
|
yylval->distance.style = DASH;
|
|
|
|
return T_PIXEL;
|
|
|
|
}
|
2017-01-11 17:19:29 -05:00
|
|
|
<PROPERTIES>{PNNUMBER}+{EM}{WHITESPACE}{LS_DASH} {
|
2017-01-04 16:27:27 -05:00
|
|
|
yylval->distance.distance = (double)g_ascii_strtoll(yytext, NULL, 10);
|
|
|
|
yylval->distance.type = PW_PX;
|
|
|
|
yylval->distance.style = DASH;
|
|
|
|
return T_PIXEL;
|
|
|
|
}
|
2017-01-11 17:19:29 -05:00
|
|
|
<PROPERTIES>{PNNUMBER}+{PX}{WHITESPACE}{LS_SOLID} {
|
2017-01-04 16:27:27 -05:00
|
|
|
yylval->distance.distance = (double)g_ascii_strtoll(yytext, NULL, 10);
|
|
|
|
yylval->distance.type = PW_PX;
|
|
|
|
yylval->distance.style = SOLID;
|
|
|
|
return T_PIXEL;
|
|
|
|
}
|
2017-01-11 17:19:29 -05:00
|
|
|
<PROPERTIES>{PNNUMBER}+{EM}{WHITESPACE}{LS_SOLID} {
|
2017-01-04 16:27:27 -05:00
|
|
|
yylval->distance.distance = (double)g_ascii_strtoll(yytext, NULL, 10);
|
|
|
|
yylval->distance.type = PW_PX;
|
|
|
|
yylval->distance.style = SOLID;
|
2016-12-31 15:37:19 -05:00
|
|
|
return T_PIXEL;
|
|
|
|
}
|
2017-01-03 13:23:09 -05:00
|
|
|
<PROPERTIES>{REAL}{PERCENT} {
|
|
|
|
yylval->distance.distance = (double)g_ascii_strtod(yytext, NULL);
|
|
|
|
yylval->distance.type = PW_PERCENT;
|
2017-01-04 16:27:27 -05:00
|
|
|
yylval->distance.style = SOLID;
|
|
|
|
return T_PIXEL;
|
|
|
|
}
|
|
|
|
<PROPERTIES>{REAL}{PERCENT}{WHITESPACE}{LS_SOLID} {
|
|
|
|
yylval->distance.distance = (double)g_ascii_strtod(yytext, NULL);
|
|
|
|
yylval->distance.type = PW_PERCENT;
|
|
|
|
yylval->distance.style = SOLID;
|
|
|
|
return T_PIXEL;
|
|
|
|
}
|
|
|
|
<PROPERTIES>{REAL}{PERCENT}{WHITESPACE}{LS_DASH} {
|
|
|
|
yylval->distance.distance = (double)g_ascii_strtod(yytext, NULL);
|
|
|
|
yylval->distance.type = PW_PERCENT;
|
|
|
|
yylval->distance.style = DASH;
|
2017-01-03 13:23:09 -05:00
|
|
|
return T_PIXEL;
|
|
|
|
}
|
2016-12-12 17:40:43 -05:00
|
|
|
<PROPERTIES>#{HEX}{8} {
|
2016-12-11 06:19:46 -05:00
|
|
|
union { unsigned int val; struct { unsigned char b,g,r,a;};} val;
|
2016-12-10 13:48:44 -05:00
|
|
|
val.val = (unsigned int)strtoull ( &yytext[1], NULL, 16);
|
2016-12-12 10:55:31 -05:00
|
|
|
yylval->colorval.alpha = val.a/255.0;
|
|
|
|
yylval->colorval.red = val.r/255.0;
|
|
|
|
yylval->colorval.green = val.g/255.0;
|
|
|
|
yylval->colorval.blue = val.b/255.0;
|
2016-12-11 06:19:46 -05:00
|
|
|
return T_COLOR;
|
|
|
|
}
|
2016-12-12 17:40:43 -05:00
|
|
|
<PROPERTIES>#{HEX}{6} {
|
2016-12-11 06:19:46 -05:00
|
|
|
union { unsigned int val; struct { unsigned char b,g,r,a;};} val;
|
2016-12-11 11:50:03 -05:00
|
|
|
val.val = (unsigned int)g_ascii_strtoull ( &yytext[1], NULL, 16);
|
2016-12-12 10:55:31 -05:00
|
|
|
yylval->colorval.alpha = 1.0;
|
|
|
|
yylval->colorval.red = val.r/255.0;
|
|
|
|
yylval->colorval.green = val.g/255.0;
|
|
|
|
yylval->colorval.blue = val.b/255.0;
|
2016-12-10 13:48:44 -05:00
|
|
|
return T_COLOR;
|
2016-12-11 11:50:03 -05:00
|
|
|
}
|
2017-04-02 06:47:53 -04:00
|
|
|
<PROPERTIES>#{HEX}{3} {
|
|
|
|
union { uint16_t val; struct { unsigned char b:4,g:4,r:4,a :4;};} val;
|
|
|
|
val.val = (uint16_t )g_ascii_strtoull ( &yytext[1], NULL, 16);
|
|
|
|
yylval->colorval.alpha = 1.0;
|
|
|
|
yylval->colorval.red = val.r/16.0;
|
|
|
|
yylval->colorval.green = val.g/16.0;
|
|
|
|
yylval->colorval.blue = val.b/16.0;
|
|
|
|
return T_COLOR;
|
|
|
|
}
|
2016-12-12 17:40:43 -05:00
|
|
|
<PROPERTIES>rgba\({NUMBER}{1,3},{NUMBER}{1,3},{NUMBER}{1,3},[01](\.{NUMBER}+)?\) {
|
2016-12-11 11:50:03 -05:00
|
|
|
char *endptr = &yytext[5];
|
2016-12-12 10:55:31 -05:00
|
|
|
yylval->colorval.red = g_ascii_strtoull ( endptr, &endptr, 10);
|
|
|
|
yylval->colorval.green= g_ascii_strtoull ( endptr+1, &endptr, 10);
|
|
|
|
yylval->colorval.blue= g_ascii_strtoull ( endptr+1, &endptr, 10);
|
|
|
|
yylval->colorval.alpha= g_ascii_strtod ( endptr+1, NULL);
|
2016-12-11 11:50:03 -05:00
|
|
|
return T_COLOR;
|
|
|
|
}
|
2016-12-12 17:40:43 -05:00
|
|
|
<PROPERTIES>rgb\({NUMBER}{1,3},{NUMBER}{1,3},{NUMBER}{1,3}\) {
|
2016-12-11 11:50:03 -05:00
|
|
|
char *endptr = &yytext[4];
|
2016-12-12 10:55:31 -05:00
|
|
|
yylval->colorval.red = g_ascii_strtoull ( endptr, &endptr, 10);
|
|
|
|
yylval->colorval.green = g_ascii_strtoull ( endptr+1, &endptr, 10);
|
|
|
|
yylval->colorval.blue = g_ascii_strtoull ( endptr+1, &endptr, 10);
|
|
|
|
yylval->colorval.alpha = 1.0;
|
2016-12-11 11:50:03 -05:00
|
|
|
return T_COLOR;
|
2016-12-10 13:48:44 -05:00
|
|
|
}
|
2017-04-02 06:32:11 -04:00
|
|
|
<PROPERTIES>argb:{HEX}{1,8} {
|
|
|
|
union { unsigned int val; struct { unsigned char b,g,r,a;};} val;
|
|
|
|
val.val = (unsigned int)strtoull ( &yytext[5], NULL, 16);
|
|
|
|
yylval->colorval.alpha = val.a/255.0;
|
|
|
|
yylval->colorval.red = val.r/255.0;
|
|
|
|
yylval->colorval.green = val.g/255.0;
|
|
|
|
yylval->colorval.blue = val.b/255.0;
|
|
|
|
return T_COLOR;
|
|
|
|
}
|
2017-01-06 13:04:25 -05:00
|
|
|
|
|
|
|
<PROPERTIES>{CENTER} {
|
2017-01-06 18:23:39 -05:00
|
|
|
yylval->ival = WL_CENTER;
|
2017-01-06 13:04:25 -05:00
|
|
|
return T_POSITION;
|
|
|
|
}
|
|
|
|
<PROPERTIES>{EAST} {
|
2017-01-06 18:23:39 -05:00
|
|
|
yylval->ival = WL_EAST;
|
2017-01-06 13:04:25 -05:00
|
|
|
return T_POSITION;
|
|
|
|
}
|
|
|
|
<PROPERTIES>{WEST} {
|
2017-01-06 18:23:39 -05:00
|
|
|
yylval->ival = WL_WEST;
|
2017-01-06 13:04:25 -05:00
|
|
|
return T_POSITION;
|
|
|
|
}
|
|
|
|
<PROPERTIES>{SOUTH}{EAST} {
|
2017-01-06 18:23:39 -05:00
|
|
|
yylval->ival = WL_SOUTH_EAST;
|
2017-01-06 13:04:25 -05:00
|
|
|
return T_POSITION;
|
|
|
|
}
|
|
|
|
<PROPERTIES>{SOUTH}{WEST} {
|
2017-01-06 18:23:39 -05:00
|
|
|
yylval->ival = WL_SOUTH_WEST;
|
2017-01-06 13:04:25 -05:00
|
|
|
return T_POSITION;
|
|
|
|
}
|
|
|
|
<PROPERTIES>{SOUTH} {
|
2017-01-06 18:23:39 -05:00
|
|
|
yylval->ival = WL_SOUTH;
|
2017-01-06 13:04:25 -05:00
|
|
|
return T_POSITION;
|
|
|
|
}
|
|
|
|
<PROPERTIES>{NORTH}{EAST} {
|
2017-01-06 18:23:39 -05:00
|
|
|
yylval->ival = WL_NORTH_EAST;
|
2017-01-06 13:04:25 -05:00
|
|
|
return T_POSITION;
|
|
|
|
}
|
|
|
|
<PROPERTIES>{NORTH}{WEST} {
|
2017-01-06 18:23:39 -05:00
|
|
|
yylval->ival = WL_NORTH_WEST;
|
2017-01-06 13:04:25 -05:00
|
|
|
return T_POSITION;
|
|
|
|
}
|
|
|
|
<PROPERTIES>{NORTH} {
|
2017-01-06 18:23:39 -05:00
|
|
|
yylval->ival = WL_NORTH;
|
2017-01-06 13:04:25 -05:00
|
|
|
return T_POSITION;
|
|
|
|
}
|
2017-01-08 18:09:02 -05:00
|
|
|
<PROPERTIES>{NONE} {
|
|
|
|
yylval->ival = HL_NONE;
|
|
|
|
return T_HIGHLIGHT_STYLE;
|
|
|
|
}
|
|
|
|
<PROPERTIES>{BOLD} {
|
|
|
|
yylval->ival = HL_BOLD;
|
|
|
|
return T_HIGHLIGHT_STYLE;
|
|
|
|
}
|
|
|
|
<PROPERTIES>{ITALIC} {
|
|
|
|
yylval->ival = HL_ITALIC;
|
|
|
|
return T_HIGHLIGHT_STYLE;
|
|
|
|
}
|
|
|
|
<PROPERTIES>{UNDERLINE} {
|
|
|
|
yylval->ival = HL_UNDERLINE;
|
|
|
|
return T_HIGHLIGHT_STYLE;
|
|
|
|
}
|
2017-01-05 16:04:39 -05:00
|
|
|
<INITIAL><<EOF>> {
|
2017-03-11 11:06:06 -05:00
|
|
|
ParseObject *po = g_queue_pop_head ( file_queue );
|
|
|
|
if ( po ) {
|
|
|
|
if ( po->type == PT_FILE ){
|
|
|
|
fclose ( po->filein );
|
|
|
|
}
|
|
|
|
g_free ( po );
|
|
|
|
}
|
|
|
|
po = g_queue_peek_head ( file_queue );
|
|
|
|
if ( po == NULL ) {
|
|
|
|
g_queue_free ( queue );
|
|
|
|
// Reset pointer to NULL
|
|
|
|
queue = NULL;
|
|
|
|
yyterminate();
|
|
|
|
} else {
|
|
|
|
yypop_buffer_state();
|
|
|
|
current = po;
|
2017-03-13 03:54:55 -04:00
|
|
|
*yylloc = current->location;
|
2017-03-11 11:06:06 -05:00
|
|
|
BEGIN(GPOINTER_TO_INT ( g_queue_pop_head ( queue )));
|
|
|
|
}
|
2017-01-05 16:04:39 -05:00
|
|
|
}
|
2016-12-12 17:40:43 -05:00
|
|
|
|
2017-01-05 16:04:39 -05:00
|
|
|
<*>\n {
|
2017-01-05 12:22:34 -05:00
|
|
|
yylloc->last_column = 1;
|
|
|
|
yylloc->last_line ++;
|
|
|
|
};
|
2016-12-31 15:37:19 -05:00
|
|
|
<*>(\r\n) {
|
2016-12-12 10:55:31 -05:00
|
|
|
yylloc->last_column = 1;
|
|
|
|
yylloc->last_line ++;
|
|
|
|
};
|
2017-01-08 10:09:24 -05:00
|
|
|
<INITIAL>. {
|
2017-01-09 02:55:51 -05:00
|
|
|
return T_ERROR;
|
2017-01-08 10:09:24 -05:00
|
|
|
}
|
2017-03-13 05:49:33 -04:00
|
|
|
<SECTION>. {
|
|
|
|
return T_ERROR_SECTION;
|
2017-01-09 16:29:31 -05:00
|
|
|
}
|
|
|
|
<PROPERTIES>. {
|
|
|
|
return T_ERROR_PROPERTY;
|
|
|
|
}
|
|
|
|
<NAMESTR>. {
|
|
|
|
return T_ERROR_NAMESTRING;
|
|
|
|
}
|
2016-12-09 13:49:49 -05:00
|
|
|
%%
|
2017-03-11 11:06:06 -05:00
|
|
|
|
2017-03-13 11:17:11 -04:00
|
|
|
|
|
|
|
static char * rofi_theme_parse_prepare_file ( const char *file, const char *parent_file )
|
2017-03-11 11:06:06 -05:00
|
|
|
{
|
|
|
|
char *filename = rofi_expand_path ( file );
|
2017-03-13 11:17:11 -04:00
|
|
|
// If no absolute path specified, expand it.
|
|
|
|
if ( parent_file != NULL && ! g_path_is_absolute ( filename ) ) {
|
|
|
|
char *basedir = g_path_get_dirname ( parent_file );
|
|
|
|
char *path = g_build_filename ( basedir, filename, NULL );
|
|
|
|
g_free ( filename);
|
|
|
|
filename = path;
|
|
|
|
g_free ( basedir );
|
|
|
|
}
|
|
|
|
GFile *gf = g_file_new_for_path ( filename );
|
|
|
|
g_free(filename);
|
|
|
|
filename = g_file_get_path ( gf );
|
|
|
|
g_object_unref ( gf );
|
|
|
|
|
|
|
|
return filename;
|
|
|
|
}
|
|
|
|
gboolean rofi_theme_parse_file ( const char *file )
|
|
|
|
{
|
|
|
|
char *filename = rofi_theme_parse_prepare_file ( file, NULL );
|
2017-03-11 11:06:06 -05:00
|
|
|
yyin = fopen ( filename, "rb" );
|
|
|
|
if ( yyin == NULL ) {
|
|
|
|
char *str = g_markup_printf_escaped ( "Failed to open theme: <i>%s</i>\nError: <b>%s</b>",
|
|
|
|
filename, strerror ( errno ) );
|
|
|
|
rofi_add_error_message ( g_string_new ( str ) );
|
|
|
|
g_free ( str );
|
|
|
|
g_free ( filename );
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
/** Add Parse object */
|
|
|
|
file_queue = g_queue_new ();
|
|
|
|
ParseObject *po = g_malloc0(sizeof(ParseObject));
|
|
|
|
po->type = PT_FILE;
|
2017-03-13 03:54:55 -04:00
|
|
|
po->filename = filename;
|
2017-03-11 11:06:06 -05:00
|
|
|
po->filein = yyin;
|
|
|
|
current = po;
|
2017-03-13 09:16:38 -04:00
|
|
|
imported_files = g_list_append ( imported_files, po->filename );
|
2017-03-11 11:06:06 -05:00
|
|
|
g_queue_push_head ( file_queue, po );
|
2017-03-13 05:49:33 -04:00
|
|
|
g_log ( LOG_DOMAIN, G_LOG_LEVEL_DEBUG, "Parsing top file: '%s'", filename );
|
2017-03-11 11:06:06 -05:00
|
|
|
|
|
|
|
int parser_retv = yyparse ( file );
|
|
|
|
yylex_destroy ();
|
|
|
|
yyin = NULL;
|
|
|
|
|
|
|
|
// Free up.
|
2017-03-13 09:16:38 -04:00
|
|
|
g_list_foreach ( imported_files, (GFunc)g_free, NULL);
|
|
|
|
g_list_free ( imported_files );
|
2017-03-11 11:06:06 -05:00
|
|
|
g_queue_free ( file_queue );
|
2017-04-04 02:31:25 -04:00
|
|
|
imported_files = NULL;
|
2017-03-11 11:06:06 -05:00
|
|
|
file_queue = NULL;
|
|
|
|
if ( parser_retv != 0 ) {
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
gboolean rofi_theme_parse_string ( const char *string )
|
|
|
|
{
|
|
|
|
yyin = NULL;
|
|
|
|
|
|
|
|
/** Add Parse object */
|
|
|
|
file_queue = g_queue_new ();
|
|
|
|
ParseObject *po = g_malloc0(sizeof(ParseObject));
|
|
|
|
po->type = PT_STRING;
|
|
|
|
po->input_str = string;
|
|
|
|
po->str_len = strlen(string);
|
|
|
|
current = po;
|
|
|
|
g_queue_push_head ( file_queue, po );
|
2017-03-13 05:49:33 -04:00
|
|
|
g_log ( LOG_DOMAIN, G_LOG_LEVEL_DEBUG, "Parsing string: '%s'", string );
|
2017-03-11 11:06:06 -05:00
|
|
|
|
|
|
|
int parser_retv = yyparse ( string );
|
|
|
|
yylex_destroy ();
|
|
|
|
|
|
|
|
// Free up.
|
2017-03-13 09:16:38 -04:00
|
|
|
g_list_foreach ( imported_files, (GFunc)g_free, NULL);
|
|
|
|
g_list_free ( imported_files );
|
2017-04-04 02:31:25 -04:00
|
|
|
imported_files = NULL;
|
2017-03-11 11:06:06 -05:00
|
|
|
g_queue_free ( file_queue );
|
|
|
|
file_queue = NULL;
|
|
|
|
if ( parser_retv != 0 ) {
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
return FALSE;
|
|
|
|
}
|