1
0
Fork 0
mirror of https://github.com/davatorium/rofi.git synced 2024-11-11 13:50:48 -05:00
rofi/lexer/theme-lexer.l

361 lines
9.7 KiB
Text
Raw Normal View History

%option noyywrap nounput never-interactive
2016-12-12 10:55:31 -05:00
%option bison-locations
2016-12-09 13:49:49 -05:00
%{
#include <stdio.h>
2016-12-09 14:04:50 -05:00
#include "lexer/theme-parser.h"
2016-12-17 10:16:28 -05:00
int last_state = 0;
GQueue *queue = NULL;
2016-12-09 13:49:49 -05:00
2016-12-12 10:55:31 -05:00
%}
%{
int str_len = 0;
char *input_str = NULL;
#define YY_INPUT(buf,result,max_size) \
{\
if ( input_str == NULL ) { \
errno =0; \
while ( (result = (int) fread(buf, 1, max_size, yyin))==0 && ferror(yyin)) \
{ \
if( errno != EINTR) \
{ \
YY_FATAL_ERROR( "input in flex scanner failed" ); \
break; \
} \
errno=0; \
clearerr(yyin); \
} \
} else {\
yy_size_t len = MIN (max_size, str_len);\
if ( len > 0 ){\
memcpy (buf, input_str, len);\
input_str+=len;\
str_len-=len;\
result = len;\
} else {\
result = YY_NULL;\
} \
}\
}
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-01-05 16:04:39 -05:00
WHITESPACE [[:blank:]]
WORD [[:alnum:]-]+
STRING [[:print:]]+
HEX [[:xdigit:]]
NUMBER [[:digit:]]
2017-01-11 17:19:29 -05:00
PNNUMBER [-+]?[[:digit:]]+
REAL [-+]?[[:digit:]]+(\.[[:digit:]]+)?
PX (px)
2016-12-31 16:47:22 -05:00
EM (em)
PERCENT (\%)
2017-01-06 17:41:10 -05:00
ASTERIX \*
CENTER "center"
NORTH "north"
SOUTH "south"
EAST "east"
WEST "west"
NONE "none"
BOLD "bold"
UNDERLINE "underline"
ITALIC "italic"
2017-01-04 16:27:27 -05:00
LS_DASH "dash"
LS_SOLID "solid"
%x PROPERTIES
%x NAMESTR
2016-12-17 10:16:28 -05:00
%x ENTRY
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-01-05 16:04:39 -05:00
2016-12-17 10:16:28 -05:00
<*>"//" {
2016-12-11 12:25:47 -05:00
int c;
2016-12-12 10:55:31 -05:00
while ((c = input()) != 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++;
}
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;
}
2016-12-11 12:25:47 -05: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
}
2017-01-06 17:41:10 -05:00
<INITIAL>{ASTERIX} {
g_queue_push_head ( queue, GINT_TO_POINTER (YY_START) );
BEGIN(DEFAULTS);
return PDEFAULTS;
}
<DEFAULTS>{WHITESPACE} {}
<DEFAULTS>"\{" {
g_queue_push_head ( queue, GINT_TO_POINTER (YY_START) );
BEGIN(ENTRY);
return BOPEN;
}
2016-12-17 10:16:28 -05:00
/* Go into parsing an entry */
<NAMESTR>"\{" {
2016-12-17 10:16:28 -05:00
g_queue_push_head ( queue, GINT_TO_POINTER (YY_START) );
BEGIN(ENTRY);
return BOPEN;
}
/* Pop out of parsing an entry. */
<ENTRY>"\}" {
g_queue_pop_head ( queue );
2016-12-17 10:16:28 -05:00
BEGIN(GPOINTER_TO_INT(g_queue_pop_head ( queue )));
return BCLOSE;
}
<INITIAL>"#" { g_queue_push_head ( queue, GINT_TO_POINTER (YY_START) ); BEGIN(NAMESTR);return NAME_PREFIX;}
<NAMESTR>\.|{WHITESPACE} { return NSEP; }
<ENTRY>{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-17 10:16:28 -05:00
/* After Namestr/Classstr we want to go to state str, then to { */
/*<NAMESTR>{WHITESPACE} { BEGIN(GPOINTER_TO_INT (g_queue_pop_head ( queue )));}*/
2016-12-17 10:16:28 -05:00
<INITIAL,ENTRY>{WHITESPACE}+ ; // ignore all whitespace
<PROPERTIES>{WHITESPACE}+ ; // ignore all whitespace
2016-12-17 10:16:28 -05:00
<INITIAL,ENTRY>":" { g_queue_push_head ( queue, GINT_TO_POINTER (YY_START) ); BEGIN(PROPERTIES); return PSEP; }
<PROPERTIES>";" { BEGIN(GPOINTER_TO_INT ( g_queue_pop_head ( queue ))); return PCLOSE;}
<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;}
<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 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;
return T_PIXEL;
}
<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;
return T_PIXEL;
}
<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-13 02:00:35 -05:00
<PROPERTIES>argb:{HEX}{8} {
union { unsigned int val; struct { unsigned char b,g,r,a;};} val;
val.val = (unsigned int)strtoull ( &yytext[1], 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;
}
<PROPERTIES>#{HEX}{6} {
2016-12-11 06:19:46 -05:00
union { unsigned int val; struct { unsigned char b,g,r,a;};} val;
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;
}
<PROPERTIES>rgba\({NUMBER}{1,3},{NUMBER}{1,3},{NUMBER}{1,3},[01](\.{NUMBER}+)?\) {
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);
return T_COLOR;
}
<PROPERTIES>rgb\({NUMBER}{1,3},{NUMBER}{1,3},{NUMBER}{1,3}\) {
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;
return T_COLOR;
2016-12-10 13:48:44 -05:00
}
<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>{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>> {
g_queue_free ( queue );
2017-01-08 10:16:09 -05:00
// Reset pointer to NULL
queue = NULL;
2017-01-05 16:04:39 -05:00
yyterminate();
}
2017-01-05 16:04:39 -05:00
<*>\n {
2017-01-05 12:22:34 -05:00
yylloc->last_column = 1;
yylloc->last_line ++;
};
<*>(\r\n) {
2016-12-12 10:55:31 -05:00
yylloc->last_column = 1;
yylloc->last_line ++;
};
<INITIAL>. {
return T_ERROR;
}
<ENTRY>. {
return T_ERROR_ENTRY;
}
<PROPERTIES>. {
return T_ERROR_PROPERTY;
}
<NAMESTR>. {
return T_ERROR_NAMESTRING;
}
<DEFAULTS>. {
return T_ERROR_DEFAULTS;
}
2016-12-17 10:16:28 -05:00
<*>. {
return T_ERROR;
2016-12-17 10:16:28 -05:00
}
2016-12-09 13:49:49 -05:00
%%