1
0
Fork 0
mirror of https://github.com/davatorium/rofi.git synced 2025-07-31 21:59:25 -04:00

Improve theme parser on error.

This commit is contained in:
Dave Davenport 2016-12-17 16:16:28 +01:00
parent b8e58b0342
commit a8a8906adc

View file

@ -6,6 +6,8 @@
#include "lexer/theme-parser.h" #include "lexer/theme-parser.h"
int last_state = 0;
GQueue *queue = NULL;
%} %}
%{ %{
@ -25,13 +27,19 @@ NUMBER [0-9]
%x PROPERTIES %x PROPERTIES
%x NAMESTR %x NAMESTR
%x ENTRY
%% %%
%{ %{
YY_LLOC_START YY_LLOC_START
%} %}
%{
"//" { if ( queue == NULL ){
printf("queue create\n");
queue = g_queue_new ( );
}
%}
<*>"//" {
int c; int c;
while ((c = input()) != EOF){ while ((c = input()) != EOF){
if (c == '\n') { if (c == '\n') {
@ -43,7 +51,7 @@ YY_LLOC_START
} }
YY_LLOC_START YY_LLOC_START
} }
"/*" { <*>"/*" {
int c = 0, p; int c = 0, p;
int nesting_depth = 1; int nesting_depth = 1;
while (nesting_depth) { while (nesting_depth) {
@ -66,20 +74,31 @@ YY_LLOC_START
YY_LLOC_START YY_LLOC_START
} }
"\{" { return BOPEN;} /* Go into parsing an entry */
"@" { BEGIN(NAMESTR);return CLASS_PREFIX;} <INITIAL>"\{" {
"#" { BEGIN(NAMESTR);return NAME_PREFIX;} g_queue_push_head ( queue, GINT_TO_POINTER (YY_START) );
"\}" { return BCLOSE;} BEGIN(ENTRY);
<INITIAL,NAMESTR>"." { return NSEP; } return BOPEN;
{WORD} { yylval->sval = g_strdup(yytext); return N_STRING;} }
<NAMESTR>{WORD} { yylval->sval = g_strdup(yytext); return NAME_ELEMENT;} /* Pop out of parsing an entry. */
<ENTRY>"\}" {
BEGIN(GPOINTER_TO_INT(g_queue_pop_head ( queue )));
return BCLOSE;
}
<NAMESTR>{WHITESPACE} { BEGIN(INITIAL);} <INITIAL>"@" { g_queue_push_head ( queue, GINT_TO_POINTER (YY_START) ); BEGIN(NAMESTR);return CLASS_PREFIX;}
<INITIAL>{WHITESPACE}+ ; // ignore all whitespace <INITIAL>"#" { g_queue_push_head ( queue, GINT_TO_POINTER (YY_START) ); BEGIN(NAMESTR);return NAME_PREFIX;}
<INITIAL,NAMESTR>"." { return NSEP; }
<INITIAL,ENTRY>{WORD} { yylval->sval = g_strdup(yytext); return N_STRING;}
<NAMESTR>{WORD} { yylval->sval = g_strdup(yytext); return NAME_ELEMENT;}
/* After Namestr/Classstr we want to go to state str, then to { */
<NAMESTR>{WHITESPACE} { BEGIN(GPOINTER_TO_INT (g_queue_pop_head ( queue )));}
<INITIAL,ENTRY>{WHITESPACE}+ ; // ignore all whitespace
<PROPERTIES>{WHITESPACE}+ ; // ignore all whitespace <PROPERTIES>{WHITESPACE}+ ; // ignore all whitespace
":" { BEGIN(PROPERTIES); return PSEP; } <INITIAL,ENTRY>":" { g_queue_push_head ( queue, GINT_TO_POINTER (YY_START) ); BEGIN(PROPERTIES); return PSEP; }
<PROPERTIES>";" { BEGIN(0); return PCLOSE;} <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;} <PROPERTIES>(true|false) { yylval->bval= g_strcmp0(yytext, "true") == 0; return T_BOOLEAN;}
<PROPERTIES>{NUMBER}+ { yylval->ival = (int)g_ascii_strtoll(yytext, NULL, 10); return T_INT;} <PROPERTIES>{NUMBER}+ { yylval->ival = (int)g_ascii_strtoll(yytext, NULL, 10); return T_INT;}
<PROPERTIES>{NUMBER}+\.{NUMBER}+ { yylval->fval = g_ascii_strtod(yytext, NULL); return T_DOUBLE;} <PROPERTIES>{NUMBER}+\.{NUMBER}+ { yylval->fval = g_ascii_strtod(yytext, NULL); return T_DOUBLE;}
@ -133,7 +152,14 @@ YY_LLOC_START
yylloc->last_line ++; yylloc->last_line ++;
}; };
<*><<EOF>> { <INITIAL><<EOF>> {
yyterminate();
printf("Queue free: %d\n", g_queue_get_length(queue));;
g_queue_free ( queue );
}
<*>. {
fprintf(stderr, "Invalid character: '%c'\n", *yytext);
yyterminate(); yyterminate();
} }
%% %%