2017-04-15 06:32:05 -04:00
|
|
|
/*
|
|
|
|
* rofi
|
|
|
|
*
|
|
|
|
* MIT/X11 License
|
|
|
|
* Copyright 2013-2017 Qball Cow <qball@gmpclient.org>
|
|
|
|
*
|
|
|
|
* Permission is hereby granted, free of charge, to any person obtaining
|
|
|
|
* a copy of this software and associated documentation files (the
|
|
|
|
* "Software"), to deal in the Software without restriction, including
|
|
|
|
* without limitation the rights to use, copy, modify, merge, publish,
|
|
|
|
* distribute, sublicense, and/or sell copies of the Software, and to
|
|
|
|
* permit persons to whom the Software is furnished to do so, subject to
|
|
|
|
* the following conditions:
|
|
|
|
*
|
|
|
|
* The above copyright notice and this permission notice shall be
|
|
|
|
* included in all copies or substantial portions of the Software.
|
|
|
|
*
|
|
|
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
|
|
|
|
* OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
|
|
|
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
|
|
|
|
* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
|
|
|
|
* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
|
|
|
|
* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
|
|
|
|
* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
2017-04-05 02:26:11 -04:00
|
|
|
%option nodefault noyywrap
|
|
|
|
%option nostdinit
|
2017-03-28 03:02:39 -04:00
|
|
|
%option nounput
|
|
|
|
%option never-interactive
|
2016-12-12 10:55:31 -05:00
|
|
|
%option bison-locations
|
2018-06-09 13:13:57 -04:00
|
|
|
%option bison-bridge
|
2016-12-09 13:49:49 -05:00
|
|
|
|
|
|
|
%{
|
2019-04-19 03:59:53 -04:00
|
|
|
#include "config.h"
|
2016-12-09 13:49:49 -05:00
|
|
|
#include <stdio.h>
|
2017-03-11 11:06:06 -05:00
|
|
|
#include <glib.h>
|
|
|
|
#include <helper.h>
|
2017-05-06 10:10:20 -04:00
|
|
|
#include <math.h>
|
2017-05-28 11:06:41 -04:00
|
|
|
#include <strings.h>
|
2017-03-11 11:06:06 -05:00
|
|
|
#include "rofi.h"
|
2017-05-04 01:56:40 -04:00
|
|
|
#include "theme.h"
|
2016-12-09 13:49:49 -05:00
|
|
|
|
2017-05-04 07:29:11 -04:00
|
|
|
#include "theme-parser.h"
|
2017-05-15 16:46:33 -04:00
|
|
|
#include "css-colors.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 */
|
2018-07-10 07:53:40 -04:00
|
|
|
PT_STRING,
|
|
|
|
/** Parse environment */
|
|
|
|
PT_ENV
|
2017-03-11 11:06:06 -05:00
|
|
|
} 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-05-16 15:55:52 -04:00
|
|
|
|
|
|
|
|
|
|
|
static double rofi_theme_parse_convert_hex ( char high, char low)
|
|
|
|
{
|
|
|
|
uint8_t retv = 0;
|
|
|
|
|
2017-06-02 16:33:55 -04:00
|
|
|
int t = g_ascii_toupper ( high );
|
2017-05-16 15:55:52 -04:00
|
|
|
t = ( t > '9')? (t-'A'+10):(t-'0');
|
|
|
|
retv = t<<4;
|
2017-06-02 16:33:55 -04:00
|
|
|
t = g_ascii_toupper ( low );
|
2017-05-16 15:55:52 -04:00
|
|
|
t = ( t > '9')? (t-'A'+10):(t-'0');
|
|
|
|
retv +=t;
|
|
|
|
return retv/255.0;
|
|
|
|
}
|
|
|
|
|
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 ) {\
|
2017-04-05 02:26:11 -04:00
|
|
|
result = 0;\
|
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;\
|
|
|
|
}\
|
2018-07-10 07:53:40 -04:00
|
|
|
case PT_ENV:\
|
2017-03-11 11:06:06 -05:00
|
|
|
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 {\
|
2017-04-05 02:26:11 -04:00
|
|
|
result = 0;\
|
|
|
|
}\
|
2017-03-11 11:06:06 -05:00
|
|
|
}\
|
|
|
|
}\
|
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:]]
|
2017-05-08 16:21:01 -04:00
|
|
|
WSO [[:blank:]]*
|
2016-12-19 11:48:20 -05:00
|
|
|
WORD [[:alnum:]-]+
|
2017-05-15 16:46:33 -04:00
|
|
|
COLOR_NAME [[:alpha:]]+
|
2017-06-07 07:28:43 -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:]]+
|
2016-12-31 15:37:19 -05:00
|
|
|
PX (px)
|
2016-12-31 16:47:22 -05:00
|
|
|
EM (em)
|
2017-09-05 07:52:21 -04:00
|
|
|
CH (ch)
|
2017-01-03 13:23:09 -05:00
|
|
|
PERCENT (\%)
|
2016-12-12 17:40:43 -05:00
|
|
|
|
2017-09-06 04:03:44 -04:00
|
|
|
INHERIT (inherit)
|
|
|
|
|
2017-01-06 17:41:10 -05:00
|
|
|
ASTERIX \*
|
|
|
|
|
2018-07-09 05:57:21 -04:00
|
|
|
ENV $\{[[:alnum:]]*\}
|
2018-07-09 05:48:32 -04:00
|
|
|
|
2017-05-10 06:41:06 -04:00
|
|
|
/* Position */
|
2017-06-02 16:12:00 -04:00
|
|
|
CENTER (?i:center)
|
|
|
|
NORTH (?i:north)
|
|
|
|
SOUTH (?i:south)
|
|
|
|
EAST (?i:east)
|
|
|
|
WEST (?i:west)
|
2017-01-06 13:04:25 -05:00
|
|
|
|
2017-05-10 06:41:06 -04:00
|
|
|
/* Line Style */
|
2017-06-02 16:12:00 -04:00
|
|
|
NONE (?i:none)
|
|
|
|
BOLD (?i:bold)
|
|
|
|
UNDERLINE (?i:underline)
|
|
|
|
ITALIC (?i:italic)
|
|
|
|
STRIKETHROUGH (?i:strikethrough)
|
|
|
|
SMALLCAPS (?i:small\ caps)
|
2017-05-10 06:41:06 -04:00
|
|
|
|
2017-05-15 09:05:40 -04:00
|
|
|
/* ANGLES */
|
|
|
|
|
2017-06-02 16:12:00 -04:00
|
|
|
ANGLE_DEG (?i:deg)
|
|
|
|
ANGLE_GRAD (?i:grad)
|
|
|
|
ANGLE_RAD (?i:rad)
|
|
|
|
ANGLE_TURN (?i:turn)
|
2017-05-15 09:05:40 -04:00
|
|
|
|
2017-06-02 16:12:00 -04:00
|
|
|
/* LINE STYLE */
|
|
|
|
LS_DASH (?i:dash)
|
|
|
|
LS_SOLID (?i:solid)
|
2017-06-02 08:05:19 -04:00
|
|
|
|
|
|
|
/* Orientation */
|
|
|
|
|
2017-06-02 16:12:00 -04:00
|
|
|
ORIENTATION_HORI (?i:horizontal)
|
|
|
|
ORIENTATION_VERT (?i:vertical)
|
2017-06-02 08:05:19 -04:00
|
|
|
|
2017-05-10 06:41:06 -04:00
|
|
|
/* Color schema */
|
2017-06-02 16:12:00 -04:00
|
|
|
RGBA (?i:rgb[a]?)
|
|
|
|
HWB (?i:hwb)
|
|
|
|
CMYK (?i:cmyk)
|
|
|
|
HSL (?i:hsl[a]?)
|
2017-05-10 06:41:06 -04:00
|
|
|
|
2017-06-02 16:12:00 -04:00
|
|
|
COLOR_TRANSPARENT (?i:transparent)
|
2017-05-15 16:46:33 -04:00
|
|
|
|
2017-05-11 12:23:36 -04:00
|
|
|
S_T_PARENT_LEFT \(
|
|
|
|
S_T_PARENT_RIGHT \)
|
2017-05-15 09:05:40 -04:00
|
|
|
COMMA ,
|
|
|
|
FORWARD_SLASH \/
|
2017-01-08 18:09:02 -05:00
|
|
|
|
2017-05-25 17:41:15 -04:00
|
|
|
LIST_OPEN \[
|
|
|
|
LIST_CLOSE \]
|
|
|
|
|
2019-01-29 11:56:45 -05:00
|
|
|
VAR_START "var"
|
|
|
|
|
2017-06-02 16:12:00 -04:00
|
|
|
CPP_COMMENT "//"
|
|
|
|
C_COMMENT_OPEN "/*"
|
|
|
|
|
2017-01-04 16:27:27 -05:00
|
|
|
|
2017-03-11 11:06:06 -05:00
|
|
|
INCLUDE "@import"
|
2017-09-18 11:48:13 -04:00
|
|
|
THEME "@theme"
|
2017-03-11 11:06:06 -05:00
|
|
|
|
2019-09-20 09:05:36 -04:00
|
|
|
MEDIA "@media"
|
|
|
|
|
2017-06-02 16:12:00 -04:00
|
|
|
CONFIGURATION (?i: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
|
2018-07-09 05:48:32 -04:00
|
|
|
%x PROPERTIES_ENV
|
2019-01-29 11:56:45 -05:00
|
|
|
%x PROPERTIES_VAR
|
|
|
|
%x PROPERTIES_VAR_DEFAULT
|
2017-05-25 17:41:15 -04:00
|
|
|
%x PROPERTIES_LIST
|
2016-12-12 17:40:43 -05:00
|
|
|
%x NAMESTR
|
2017-03-13 05:49:33 -04:00
|
|
|
%x SECTION
|
2017-01-06 17:41:10 -05:00
|
|
|
%x DEFAULTS
|
2019-09-20 09:05:36 -04:00
|
|
|
%x MEDIA
|
|
|
|
%x MEDIA_CONTENT
|
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.
|
|
|
|
*/
|
|
|
|
|
2017-06-02 16:12:00 -04:00
|
|
|
<*>{CPP_COMMENT} {
|
2017-04-05 02:26:11 -04:00
|
|
|
int c = input();
|
|
|
|
while ( c != 0 && c != EOF){
|
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++;
|
2017-04-05 02:26:11 -04:00
|
|
|
c = input();
|
2016-12-12 10:55:31 -05:00
|
|
|
}
|
|
|
|
YY_LLOC_START
|
2016-12-11 12:25:47 -05:00
|
|
|
}
|
2017-06-02 16:12:00 -04:00
|
|
|
<*>{C_COMMENT_OPEN} {
|
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;
|
2017-04-05 02:26:11 -04:00
|
|
|
case EOF: 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-09-18 11:48:13 -04:00
|
|
|
}
|
|
|
|
<INITIAL>{THEME} {
|
|
|
|
rofi_theme_reset();
|
|
|
|
g_queue_push_head ( queue, GINT_TO_POINTER (YY_START) );
|
|
|
|
BEGIN(INCLUDE);
|
2017-03-11 11:06:06 -05:00
|
|
|
}
|
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-06-02 16:12:00 -04:00
|
|
|
<INCLUDE>{STRING} {
|
2017-03-11 11:06:06 -05:00
|
|
|
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-06-20 03:16:12 -04:00
|
|
|
char *file2 = helper_get_theme_path ( &yytext[1] );
|
|
|
|
char *filename = rofi_theme_parse_prepare_file ( file2, top->filename );
|
|
|
|
g_free ( file2 );
|
2017-03-13 09:16:38 -04:00
|
|
|
if ( g_list_find_custom ( imported_files, filename, (GCompareFunc)g_strcmp0 ) != NULL ) {
|
2017-06-02 16:39:20 -04:00
|
|
|
g_debug ( "Skipping file: '%s' already parsed.", filename );
|
2017-03-11 11:06:06 -05:00
|
|
|
} else {
|
2017-06-02 16:39:20 -04:00
|
|
|
g_debug ( "Parsing file: '%s'", filename );
|
2017-03-13 09:16:38 -04:00
|
|
|
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
|
|
|
|
2017-03-27 03:04:55 -04:00
|
|
|
<INITIAL>{CONFIGURATION} {
|
|
|
|
g_queue_push_head ( queue, GINT_TO_POINTER (YY_START) );
|
|
|
|
BEGIN(DEFAULTS);
|
2017-05-11 12:23:36 -04:00
|
|
|
return T_CONFIGURATION;
|
2017-03-27 03:04:55 -04:00
|
|
|
|
|
|
|
}
|
2017-10-22 06:41:51 -04:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Handle defaults: * { ... }
|
|
|
|
*/
|
2017-01-06 17:41:10 -05:00
|
|
|
<INITIAL>{ASTERIX} {
|
|
|
|
g_queue_push_head ( queue, GINT_TO_POINTER (YY_START) );
|
|
|
|
BEGIN(DEFAULTS);
|
2017-05-11 12:23:36 -04:00
|
|
|
return T_PDEFAULTS;
|
2017-01-06 17:41:10 -05:00
|
|
|
}
|
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-05-11 12:23:36 -04:00
|
|
|
return T_BOPEN;
|
2017-01-06 17:41:10 -05:00
|
|
|
}
|
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-10-22 06:41:51 -04:00
|
|
|
<INITIAL>"#" {
|
|
|
|
g_queue_push_head ( queue, GINT_TO_POINTER (YY_START) );
|
|
|
|
BEGIN(NAMESTR);
|
|
|
|
return T_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);
|
2017-05-11 12:23:36 -04:00
|
|
|
return T_BOPEN;
|
2016-12-17 10:16:28 -05:00
|
|
|
}
|
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 )));
|
2017-05-11 12:23:36 -04:00
|
|
|
return T_BCLOSE;
|
2016-12-17 10:16:28 -05:00
|
|
|
}
|
|
|
|
|
2017-05-11 12:23:36 -04:00
|
|
|
<NAMESTR>\.|{WHITESPACE} { return T_NSEP; }
|
2017-09-06 17:11:03 -04:00
|
|
|
<NAMESTR>,{WHITESPACE}* { return T_SSEP; }
|
2017-09-07 02:35:09 -04:00
|
|
|
/* Alias color to text-color */
|
|
|
|
<SECTION>"color" { yylval->sval = g_strdup("text-color"); return T_PROP_NAME;}
|
2017-05-11 12:23:36 -04:00
|
|
|
<SECTION>{WORD} { yylval->sval = g_strdup(yytext); return T_PROP_NAME;}
|
|
|
|
<NAMESTR>{WORD} { yylval->sval = g_strdup(yytext); return T_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
|
2019-09-20 09:05:36 -04:00
|
|
|
<PROPERTIES,PROPERTIES_ENV,PROPERTIES_VAR_DEFAULT,PROPERTIES_LIST,PROPERTIES_VAR,MEDIA_CONTENT>{WHITESPACE}+ ; // ignore all whitespace
|
2016-12-11 11:50:03 -05:00
|
|
|
|
2017-05-11 12:23:36 -04:00
|
|
|
<SECTION>":" { g_queue_push_head ( queue, GINT_TO_POINTER (YY_START) ); BEGIN(PROPERTIES); return T_PSEP; }
|
|
|
|
<PROPERTIES>";" { BEGIN(GPOINTER_TO_INT ( g_queue_pop_head ( queue ))); return T_PCLOSE;}
|
2019-01-29 11:56:45 -05:00
|
|
|
<PROPERTIES,PROPERTIES_ENV,PROPERTIES_VAR_DEFAULT>(true|false) { yylval->bval= g_strcmp0(yytext, "true") == 0; return T_BOOLEAN;}
|
2019-09-20 09:05:36 -04:00
|
|
|
<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;}
|
2019-01-29 11:56:45 -05:00
|
|
|
<PROPERTIES,PROPERTIES_ENV,PROPERTIES_VAR_DEFAULT>{STRING} { yytext[yyleng-1] = '\0'; yylval->sval = g_strcompress(&yytext[1]); return T_STRING;}
|
2017-05-28 12:05:02 -04:00
|
|
|
|
2019-01-29 11:56:45 -05:00
|
|
|
<PROPERTIES,PROPERTIES_ENV,PROPERTIES_VAR_DEFAULT>@{WORD} {
|
|
|
|
yylval->sval = g_strdup(yytext+1);
|
2017-01-05 12:22:34 -05:00
|
|
|
return T_LINK;
|
|
|
|
}
|
2016-12-31 15:37:19 -05:00
|
|
|
|
2019-01-29 11:56:45 -05:00
|
|
|
<PROPERTIES,PROPERTIES_ENV,PROPERTIES_VAR_DEFAULT>{EM} { return T_UNIT_EM; }
|
|
|
|
<PROPERTIES,PROPERTIES_ENV,PROPERTIES_VAR_DEFAULT>{CH} { return T_UNIT_CH; }
|
2019-09-20 09:05:36 -04:00
|
|
|
<PROPERTIES,PROPERTIES_ENV,PROPERTIES_VAR_DEFAULT,MEDIA_CONTENT>{PX} { return T_UNIT_PX; }
|
2019-01-29 11:56:45 -05:00
|
|
|
<PROPERTIES,PROPERTIES_ENV,PROPERTIES_VAR_DEFAULT>{PERCENT} { return T_PERCENT; }
|
|
|
|
<PROPERTIES,PROPERTIES_ENV,PROPERTIES_VAR_DEFAULT>{LS_SOLID} { return T_SOLID; }
|
|
|
|
<PROPERTIES,PROPERTIES_ENV,PROPERTIES_VAR_DEFAULT>{LS_DASH} { return T_DASH; }
|
2018-07-09 05:48:32 -04:00
|
|
|
|
2019-01-29 11:56:45 -05:00
|
|
|
<PROPERTIES,PROPERTIES_ENV,PROPERTIES_VAR_DEFAULT>{INHERIT} { return T_INHERIT; }
|
2017-09-06 04:03:44 -04:00
|
|
|
|
2019-01-29 11:56:45 -05:00
|
|
|
<PROPERTIES,PROPERTIES_ENV,PROPERTIES_VAR_DEFAULT>{ENV} {
|
2018-07-09 05:48:32 -04:00
|
|
|
yytext[yyleng-1] = '\0';
|
|
|
|
const char *val = g_getenv(yytext+2);
|
|
|
|
if ( val ) {
|
|
|
|
ParseObject *top = g_queue_peek_head ( file_queue );
|
|
|
|
top->location = *yylloc;
|
|
|
|
ParseObject *po = g_malloc0(sizeof(ParseObject));
|
2018-07-10 07:53:40 -04:00
|
|
|
po->type = PT_ENV;
|
2018-07-09 05:48:32 -04:00
|
|
|
po->input_str = val;
|
|
|
|
po->str_len = strlen(val);
|
|
|
|
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;
|
|
|
|
yylloc->filename = current->filename;
|
|
|
|
g_queue_push_head ( queue, GINT_TO_POINTER (YY_START) ); BEGIN(PROPERTIES_ENV);
|
|
|
|
}
|
|
|
|
}
|
2017-05-10 06:41:06 -04:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Color parsing. It is easier to do this at lexer level.
|
|
|
|
* Other schemes are done at yacc level.
|
|
|
|
*/
|
2019-01-29 11:56:45 -05:00
|
|
|
<PROPERTIES,PROPERTIES_ENV,PROPERTIES_VAR_DEFAULT>#{HEX}{8} {
|
2017-05-16 15:55:52 -04:00
|
|
|
yylval->colorval.red = rofi_theme_parse_convert_hex(yytext[1],yytext[2]);
|
|
|
|
yylval->colorval.green = rofi_theme_parse_convert_hex(yytext[3],yytext[4]);
|
|
|
|
yylval->colorval.blue = rofi_theme_parse_convert_hex(yytext[5],yytext[6]);
|
|
|
|
yylval->colorval.alpha = rofi_theme_parse_convert_hex(yytext[7],yytext[8]);
|
2016-12-11 06:19:46 -05:00
|
|
|
return T_COLOR;
|
|
|
|
}
|
2019-01-29 11:56:45 -05:00
|
|
|
<PROPERTIES,PROPERTIES_ENV,PROPERTIES_VAR_DEFAULT>#{HEX}{6} {
|
2016-12-12 10:55:31 -05:00
|
|
|
yylval->colorval.alpha = 1.0;
|
2017-05-16 15:55:52 -04:00
|
|
|
yylval->colorval.red = rofi_theme_parse_convert_hex(yytext[1],yytext[2]);
|
|
|
|
yylval->colorval.green = rofi_theme_parse_convert_hex(yytext[3],yytext[4]);
|
|
|
|
yylval->colorval.blue = rofi_theme_parse_convert_hex(yytext[5],yytext[6]);
|
2016-12-10 13:48:44 -05:00
|
|
|
return T_COLOR;
|
2016-12-11 11:50:03 -05:00
|
|
|
}
|
2019-01-29 11:56:45 -05:00
|
|
|
<PROPERTIES,PROPERTIES_ENV,PROPERTIES_VAR_DEFAULT>#{HEX}{3} {
|
2017-04-02 06:47:53 -04:00
|
|
|
yylval->colorval.alpha = 1.0;
|
2017-05-16 15:55:52 -04:00
|
|
|
yylval->colorval.red = rofi_theme_parse_convert_hex(yytext[1],yytext[1]);
|
|
|
|
yylval->colorval.green = rofi_theme_parse_convert_hex(yytext[2],yytext[2]);
|
|
|
|
yylval->colorval.blue = rofi_theme_parse_convert_hex(yytext[3],yytext[3]);
|
|
|
|
return T_COLOR;
|
|
|
|
}
|
2019-01-29 11:56:45 -05:00
|
|
|
<PROPERTIES,PROPERTIES_ENV,PROPERTIES_VAR_DEFAULT>#{HEX}{4} {
|
2017-05-16 15:55:52 -04:00
|
|
|
yylval->colorval.alpha = rofi_theme_parse_convert_hex(yytext[4],yytext[4]);
|
|
|
|
yylval->colorval.red = rofi_theme_parse_convert_hex(yytext[1],yytext[1]);
|
|
|
|
yylval->colorval.green = rofi_theme_parse_convert_hex(yytext[2],yytext[2]);
|
|
|
|
yylval->colorval.blue = rofi_theme_parse_convert_hex(yytext[3],yytext[3]);
|
2017-04-02 06:47:53 -04:00
|
|
|
return T_COLOR;
|
|
|
|
}
|
2019-01-29 11:56:45 -05:00
|
|
|
<PROPERTIES,PROPERTIES_ENV,PROPERTIES_VAR_DEFAULT>argb:{HEX}{8} {
|
2017-05-16 15:55:52 -04:00
|
|
|
yylval->colorval.alpha = rofi_theme_parse_convert_hex(yytext[5],yytext[6]);
|
|
|
|
yylval->colorval.red = rofi_theme_parse_convert_hex(yytext[7],yytext[8]);
|
|
|
|
yylval->colorval.green = rofi_theme_parse_convert_hex(yytext[9],yytext[10]);
|
|
|
|
yylval->colorval.blue = rofi_theme_parse_convert_hex(yytext[11],yytext[12]);
|
2017-04-02 06:32:11 -04:00
|
|
|
return T_COLOR;
|
2017-10-30 12:06:11 -04:00
|
|
|
}
|
2019-01-29 11:56:45 -05:00
|
|
|
<PROPERTIES,PROPERTIES_ENV,PROPERTIES_VAR_DEFAULT>argb:{HEX}{7} {
|
2017-10-30 12:06:11 -04:00
|
|
|
return T_ERROR_ARGB_SPEC;
|
2017-04-02 06:32:11 -04:00
|
|
|
}
|
2017-05-10 06:41:06 -04:00
|
|
|
/* Color schemes */
|
2019-01-29 11:56:45 -05:00
|
|
|
<PROPERTIES,PROPERTIES_ENV,PROPERTIES_VAR_DEFAULT>{RGBA} { return T_COL_RGBA; }
|
|
|
|
<PROPERTIES,PROPERTIES_ENV,PROPERTIES_VAR_DEFAULT>{HSL} { return T_COL_HSL; }
|
|
|
|
<PROPERTIES,PROPERTIES_ENV,PROPERTIES_VAR_DEFAULT>{HWB} { return T_COL_HWB; }
|
|
|
|
<PROPERTIES,PROPERTIES_ENV,PROPERTIES_VAR_DEFAULT>{CMYK} { return T_COL_CMYK; }
|
2017-05-10 06:41:06 -04:00
|
|
|
/* Fluff */
|
2019-01-29 11:56:45 -05:00
|
|
|
<PROPERTIES,PROPERTIES_ENV,PROPERTIES_VAR_DEFAULT>{VAR_START}{S_T_PARENT_LEFT} {
|
|
|
|
g_queue_push_head ( queue, GINT_TO_POINTER (YY_START) );
|
|
|
|
BEGIN(PROPERTIES_VAR);
|
2019-03-21 05:33:50 -04:00
|
|
|
return T_PARENT_LEFT;
|
2019-01-29 11:56:45 -05:00
|
|
|
}
|
|
|
|
<PROPERTIES_VAR>{S_T_PARENT_RIGHT} {
|
|
|
|
BEGIN(GPOINTER_TO_INT(g_queue_pop_head ( queue )));
|
2019-03-21 05:33:50 -04:00
|
|
|
return T_PARENT_RIGHT;
|
2019-01-29 11:56:45 -05:00
|
|
|
}
|
|
|
|
<PROPERTIES_VAR>{COMMA} {
|
|
|
|
g_queue_push_head ( queue, GINT_TO_POINTER (YY_START) );
|
|
|
|
BEGIN(PROPERTIES_VAR_DEFAULT);
|
|
|
|
return T_COMMA;
|
|
|
|
}
|
|
|
|
<PROPERTIES_VAR_DEFAULT>{S_T_PARENT_RIGHT} {
|
|
|
|
// Pop 2.
|
|
|
|
g_queue_pop_head ( queue );
|
|
|
|
BEGIN(GPOINTER_TO_INT(g_queue_pop_head ( queue )));
|
2019-03-21 05:33:50 -04:00
|
|
|
return T_PARENT_RIGHT;
|
2019-01-29 11:56:45 -05:00
|
|
|
}
|
2019-03-21 05:33:50 -04:00
|
|
|
<PROPERTIES,PROPERTIES_ENV,PROPERTIES_VAR_DEFAULT>{S_T_PARENT_LEFT} { return T_PARENT_LEFT; }
|
|
|
|
<PROPERTIES,PROPERTIES_ENV,PROPERTIES_VAR_DEFAULT>{S_T_PARENT_RIGHT} { return T_PARENT_RIGHT; }
|
2019-01-29 11:56:45 -05:00
|
|
|
<PROPERTIES,PROPERTIES_ENV,PROPERTIES_VAR_DEFAULT,PROPERTIES_LIST>{COMMA} { return T_COMMA; }
|
|
|
|
<PROPERTIES,PROPERTIES_ENV,PROPERTIES_VAR_DEFAULT>{LIST_OPEN} {
|
2017-05-25 17:41:15 -04:00
|
|
|
g_queue_push_head ( queue, GINT_TO_POINTER (YY_START) );
|
|
|
|
BEGIN(PROPERTIES_LIST);
|
|
|
|
return T_LIST_OPEN;
|
|
|
|
}
|
|
|
|
<PROPERTIES_LIST>{LIST_CLOSE} {
|
|
|
|
BEGIN(GPOINTER_TO_INT(g_queue_pop_head ( queue )));
|
|
|
|
return T_LIST_CLOSE;
|
|
|
|
}
|
2019-01-29 11:56:45 -05:00
|
|
|
<PROPERTIES,PROPERTIES_ENV,PROPERTIES_VAR_DEFAULT>{FORWARD_SLASH} { return T_FORWARD_SLASH; }
|
2017-05-10 06:41:06 -04:00
|
|
|
/* Position */
|
2019-01-29 11:56:45 -05:00
|
|
|
<PROPERTIES,PROPERTIES_ENV,PROPERTIES_VAR_DEFAULT>{CENTER} { return T_POS_CENTER; }
|
|
|
|
<PROPERTIES,PROPERTIES_ENV,PROPERTIES_VAR_DEFAULT>{EAST} { return T_POS_EAST; }
|
|
|
|
<PROPERTIES,PROPERTIES_ENV,PROPERTIES_VAR_DEFAULT>{WEST} { return T_POS_WEST; }
|
|
|
|
<PROPERTIES,PROPERTIES_ENV,PROPERTIES_VAR_DEFAULT>{SOUTH} { return T_POS_SOUTH; }
|
|
|
|
<PROPERTIES,PROPERTIES_ENV,PROPERTIES_VAR_DEFAULT>{NORTH} { return T_POS_NORTH; }
|
2017-05-10 06:41:06 -04:00
|
|
|
/* Highlight style */
|
2019-01-29 11:56:45 -05:00
|
|
|
<PROPERTIES,PROPERTIES_ENV,PROPERTIES_VAR_DEFAULT>{NONE} { return T_NONE; }
|
|
|
|
<PROPERTIES,PROPERTIES_ENV,PROPERTIES_VAR_DEFAULT>{BOLD} { return T_BOLD; }
|
|
|
|
<PROPERTIES,PROPERTIES_ENV,PROPERTIES_VAR_DEFAULT>{ITALIC} { return T_ITALIC; }
|
|
|
|
<PROPERTIES,PROPERTIES_ENV,PROPERTIES_VAR_DEFAULT>{UNDERLINE} { return T_UNDERLINE; }
|
|
|
|
<PROPERTIES,PROPERTIES_ENV,PROPERTIES_VAR_DEFAULT>{STRIKETHROUGH} { return T_STRIKETHROUGH; }
|
|
|
|
<PROPERTIES,PROPERTIES_ENV,PROPERTIES_VAR_DEFAULT>{SMALLCAPS} { return T_SMALLCAPS; }
|
|
|
|
|
|
|
|
<PROPERTIES,PROPERTIES_ENV,PROPERTIES_VAR_DEFAULT>{ANGLE_DEG} { return T_ANGLE_DEG; }
|
|
|
|
<PROPERTIES,PROPERTIES_ENV,PROPERTIES_VAR_DEFAULT>{ANGLE_RAD} { return T_ANGLE_RAD; }
|
|
|
|
<PROPERTIES,PROPERTIES_ENV,PROPERTIES_VAR_DEFAULT>{ANGLE_GRAD} { return T_ANGLE_GRAD; }
|
|
|
|
<PROPERTIES,PROPERTIES_ENV,PROPERTIES_VAR_DEFAULT>{ANGLE_TURN} { return T_ANGLE_TURN; }
|
|
|
|
|
|
|
|
<PROPERTIES,PROPERTIES_ENV,PROPERTIES_VAR_DEFAULT>{ORIENTATION_HORI} { return ORIENTATION_HORI; }
|
|
|
|
<PROPERTIES,PROPERTIES_ENV,PROPERTIES_VAR_DEFAULT>{ORIENTATION_VERT} { return ORIENTATION_VERT; }
|
|
|
|
|
|
|
|
<PROPERTIES,PROPERTIES_ENV,PROPERTIES_VAR_DEFAULT>{COLOR_TRANSPARENT} {
|
2017-05-15 16:46:33 -04:00
|
|
|
return T_COLOR_TRANSPARENT;
|
|
|
|
}
|
2019-01-29 11:56:45 -05:00
|
|
|
<PROPERTIES,PROPERTIES_ENV,PROPERTIES_VAR_DEFAULT>{COLOR_NAME} {
|
2017-05-15 16:46:33 -04:00
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
2019-01-29 11:56:45 -05:00
|
|
|
<INITIAL,PROPERTIES_ENV,PROPERTIES_VAR_DEFAULT><<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-10-22 06:41:51 -04:00
|
|
|
|
2019-09-20 09:05:36 -04:00
|
|
|
|
|
|
|
<INITIAL>{MEDIA} {
|
|
|
|
g_queue_push_head ( queue, GINT_TO_POINTER (YY_START) );
|
|
|
|
BEGIN(MEDIA);
|
|
|
|
return T_MEDIA;
|
|
|
|
}
|
|
|
|
|
|
|
|
<MEDIA>{S_T_PARENT_LEFT} {
|
|
|
|
g_queue_push_head ( queue, GINT_TO_POINTER (YY_START) );
|
|
|
|
BEGIN(MEDIA_CONTENT);
|
|
|
|
return T_PARENT_LEFT;
|
|
|
|
}
|
|
|
|
<MEDIA_CONTENT>{WORD} {
|
|
|
|
yylval->sval = g_strdup(yytext);
|
|
|
|
return T_STRING;
|
|
|
|
}
|
|
|
|
<MEDIA_CONTENT>":" {
|
|
|
|
return T_PSEP;
|
|
|
|
}
|
|
|
|
<MEDIA_CONTENT>{S_T_PARENT_RIGHT} {
|
|
|
|
int id = GPOINTER_TO_INT(g_queue_pop_head ( queue ));
|
|
|
|
BEGIN(id);
|
|
|
|
return T_PARENT_RIGHT;
|
|
|
|
}
|
|
|
|
<MEDIA>"\{" {
|
|
|
|
g_queue_push_head ( queue, GINT_TO_POINTER (YY_START) );
|
|
|
|
BEGIN(INITIAL);
|
|
|
|
return T_BOPEN;
|
|
|
|
}
|
|
|
|
|
|
|
|
<INITIAL>"\}" {
|
|
|
|
g_queue_pop_head ( queue );
|
|
|
|
BEGIN(GPOINTER_TO_INT(g_queue_pop_head ( queue )));
|
|
|
|
return T_BCLOSE;
|
|
|
|
}
|
|
|
|
<MEDIA>{WHITESPACE}+ ; // ignore all whitespace
|
|
|
|
|
|
|
|
|
|
|
|
<MEDIA,MEDIA_CONTENT>. {
|
|
|
|
yytext[yyleng-1] = '\0';
|
|
|
|
fprintf(stderr,"found: |%s|\n", yytext);
|
|
|
|
return T_ERROR;
|
|
|
|
}
|
|
|
|
|
2017-10-22 06:41:51 -04:00
|
|
|
/**
|
|
|
|
* If we just encounter a word, we assume it is a Widget name.
|
|
|
|
* This makes include,theme, configuration a reserved keyword.
|
|
|
|
*/
|
|
|
|
<INITIAL>{WORD} {
|
|
|
|
g_queue_push_head ( queue, GINT_TO_POINTER (YY_START) );
|
|
|
|
BEGIN(NAMESTR);
|
|
|
|
yylval->sval = g_strdup(yytext);
|
|
|
|
return T_NAME_ELEMENT;
|
|
|
|
}
|
2017-01-08 10:09:24 -05:00
|
|
|
<INITIAL>. {
|
2019-09-20 09:05:36 -04:00
|
|
|
yytext[yyleng-1] = '\0';
|
|
|
|
fprintf(stderr,"initial found: |%s|\n", yytext);
|
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>. {
|
2019-09-20 09:05:36 -04:00
|
|
|
yytext[yyleng-1] = '\0';
|
|
|
|
fprintf(stderr,"section found: |%s|\n", yytext);
|
2017-03-13 05:49:33 -04:00
|
|
|
return T_ERROR_SECTION;
|
2017-01-09 16:29:31 -05:00
|
|
|
}
|
2019-01-29 11:56:45 -05:00
|
|
|
<PROPERTIES_LIST,PROPERTIES_VAR>{WORD} {
|
2017-05-25 17:41:15 -04:00
|
|
|
yylval->sval = g_strdup(yytext);
|
|
|
|
return T_ELEMENT;
|
|
|
|
}
|
2018-04-28 09:30:01 -04:00
|
|
|
<PROPERTIES_LIST>{STRING} {
|
|
|
|
yytext[yyleng-1] = '\0';
|
|
|
|
yylval->sval = g_strdup(yytext+1);
|
|
|
|
return T_ELEMENT;
|
|
|
|
}
|
2017-05-25 17:41:15 -04:00
|
|
|
|
2019-01-29 11:56:45 -05:00
|
|
|
<PROPERTIES,PROPERTIES_ENV,PROPERTIES_VAR_DEFAULT,PROPERTIES_LIST>. {
|
2019-09-20 09:05:36 -04:00
|
|
|
yytext[yyleng-1] = '\0';
|
|
|
|
fprintf(stderr,"prop found: |%s|\n", yytext);
|
2017-01-09 16:29:31 -05:00
|
|
|
return T_ERROR_PROPERTY;
|
|
|
|
}
|
|
|
|
<NAMESTR>. {
|
2019-09-20 09:05:36 -04:00
|
|
|
yytext[yyleng-1] = '\0';
|
|
|
|
fprintf(stderr,"namestr found: |%s|\n", yytext);
|
2017-01-09 16:29:31 -05:00
|
|
|
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
|
|
|
|
|
|
|
gboolean rofi_theme_parse_file ( const char *file )
|
|
|
|
{
|
2017-04-17 11:46:01 -04:00
|
|
|
char *file2 = helper_get_theme_path ( file );
|
|
|
|
char *filename = rofi_theme_parse_prepare_file ( file2, NULL );
|
|
|
|
g_free ( file2 );
|
|
|
|
|
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>",
|
2017-04-17 11:46:01 -04:00
|
|
|
filename, strerror ( errno ) );
|
2017-03-11 11:06:06 -05:00
|
|
|
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-06-02 16:39:20 -04:00
|
|
|
g_debug ( "Parsing top file: '%s'", filename );
|
2017-03-11 11:06:06 -05:00
|
|
|
|
|
|
|
int parser_retv = yyparse ( file );
|
|
|
|
yylex_destroy ();
|
|
|
|
yyin = NULL;
|
|
|
|
|
2017-04-06 03:12:03 -04:00
|
|
|
while ( (po = g_queue_pop_head ( file_queue ) )) {
|
|
|
|
if ( po ) {
|
|
|
|
if ( po->type == PT_FILE ){
|
|
|
|
fclose ( po->filein );
|
|
|
|
}
|
|
|
|
g_free ( po );
|
|
|
|
}
|
|
|
|
}
|
2017-03-11 11:06:06 -05:00
|
|
|
// Free up.
|
2019-04-19 04:00:58 -04:00
|
|
|
g_list_free_full ( imported_files, g_free );
|
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-06-02 16:39:20 -04:00
|
|
|
g_debug ( "Parsing string: '%s'", string );
|
2017-03-11 11:06:06 -05:00
|
|
|
|
|
|
|
int parser_retv = yyparse ( string );
|
|
|
|
yylex_destroy ();
|
|
|
|
|
2017-04-06 03:12:03 -04:00
|
|
|
while ( (po = g_queue_pop_head ( file_queue ) )) {
|
|
|
|
if ( po ) {
|
|
|
|
if ( po->type == PT_FILE ){
|
|
|
|
fclose ( po->filein );
|
|
|
|
}
|
|
|
|
g_free ( po );
|
|
|
|
}
|
|
|
|
}
|
2017-03-11 11:06:06 -05:00
|
|
|
// Free up.
|
2019-04-19 04:00:58 -04:00
|
|
|
g_list_free_full ( imported_files, g_free );
|
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;
|
|
|
|
}
|