2016-12-12 15:55:31 +00:00
|
|
|
%option noyywrap nounput
|
|
|
|
%option bison-locations
|
2016-12-09 18:49:49 +00:00
|
|
|
|
|
|
|
%{
|
|
|
|
#include <stdio.h>
|
|
|
|
|
|
|
|
|
2016-12-09 19:04:50 +00:00
|
|
|
#include "lexer/theme-parser.h"
|
2016-12-17 15:16:28 +00:00
|
|
|
int last_state = 0;
|
|
|
|
GQueue *queue = NULL;
|
2016-12-09 18:49:49 +00:00
|
|
|
|
2016-12-12 15:55:31 +00:00
|
|
|
%}
|
|
|
|
%{
|
|
|
|
|
|
|
|
#define YY_USER_ACTION {\
|
|
|
|
yylloc->last_column+= yyleng;\
|
|
|
|
}
|
|
|
|
#define YY_LLOC_START {\
|
|
|
|
yylloc->first_line = yylloc->last_line; yylloc->first_column = yylloc->last_column;\
|
|
|
|
}
|
2016-12-09 18:49:49 +00:00
|
|
|
%}
|
2016-12-12 20:14:57 +00:00
|
|
|
WHITESPACE [ \t]
|
|
|
|
WORD [_\-a-zA-Z0-9]+
|
|
|
|
STRING [ \t_\-a-zA-Z0-9]+
|
|
|
|
HEX [0-9a-fA-F]
|
|
|
|
NUMBER [0-9]
|
2016-12-12 22:40:43 +00:00
|
|
|
|
|
|
|
%x PROPERTIES
|
|
|
|
%x NAMESTR
|
2016-12-17 15:16:28 +00:00
|
|
|
%x ENTRY
|
2016-12-09 18:49:49 +00:00
|
|
|
%%
|
2016-12-12 15:55:31 +00:00
|
|
|
|
|
|
|
%{
|
|
|
|
YY_LLOC_START
|
|
|
|
%}
|
2016-12-17 15:16:28 +00:00
|
|
|
%{
|
|
|
|
if ( queue == NULL ){
|
|
|
|
printf("queue create\n");
|
|
|
|
queue = g_queue_new ( );
|
|
|
|
}
|
|
|
|
%}
|
|
|
|
<*>"//" {
|
2016-12-11 17:25:47 +00:00
|
|
|
int c;
|
2016-12-12 15:55:31 +00:00
|
|
|
while ((c = input()) != EOF){
|
2016-12-11 17:25:47 +00:00
|
|
|
if (c == '\n') {
|
2016-12-12 15:55:31 +00:00
|
|
|
yylloc->last_column = 1;
|
|
|
|
yylloc->last_line ++;
|
2016-12-11 17:25:47 +00:00
|
|
|
break;
|
|
|
|
}
|
2016-12-12 15:55:31 +00:00
|
|
|
yylloc->last_column++;
|
|
|
|
}
|
|
|
|
YY_LLOC_START
|
2016-12-11 17:25:47 +00:00
|
|
|
}
|
2016-12-17 15:16:28 +00:00
|
|
|
<*>"/*" {
|
2016-12-11 17:25:47 +00:00
|
|
|
int c = 0, p;
|
|
|
|
int nesting_depth = 1;
|
|
|
|
while (nesting_depth) {
|
|
|
|
p = c;
|
|
|
|
c = input();
|
|
|
|
switch (c) {
|
2016-12-12 15:55:31 +00: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 17:25:47 +00:00
|
|
|
case EOF: nesting_depth = 0; break;
|
2016-12-12 15:55:31 +00:00
|
|
|
default:
|
|
|
|
yylloc->last_column++;
|
|
|
|
;
|
2016-12-11 17:25:47 +00:00
|
|
|
}
|
|
|
|
}
|
2016-12-12 15:55:31 +00:00
|
|
|
YY_LLOC_START
|
2016-12-11 17:25:47 +00:00
|
|
|
}
|
2016-12-12 20:14:57 +00:00
|
|
|
|
2016-12-17 15:16:28 +00:00
|
|
|
/* Go into parsing an entry */
|
|
|
|
<INITIAL>"\{" {
|
|
|
|
g_queue_push_head ( queue, GINT_TO_POINTER (YY_START) );
|
|
|
|
BEGIN(ENTRY);
|
|
|
|
return BOPEN;
|
|
|
|
}
|
|
|
|
/* Pop out of parsing an entry. */
|
|
|
|
<ENTRY>"\}" {
|
|
|
|
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 CLASS_PREFIX;}
|
|
|
|
<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;}
|
2016-12-12 22:40:43 +00:00
|
|
|
|
2016-12-17 15:16:28 +00:00
|
|
|
/* 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
|
2016-12-12 22:40:43 +00:00
|
|
|
<PROPERTIES>{WHITESPACE}+ ; // ignore all whitespace
|
2016-12-11 16:50:03 +00:00
|
|
|
|
2016-12-17 15:16:28 +00: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;}
|
2016-12-12 22:40:43 +00:00
|
|
|
<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}+\.{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;}
|
|
|
|
<PROPERTIES>#{HEX}{8} {
|
2016-12-11 11:19:46 +00:00
|
|
|
union { unsigned int val; struct { unsigned char b,g,r,a;};} val;
|
2016-12-10 18:48:44 +00:00
|
|
|
val.val = (unsigned int)strtoull ( &yytext[1], NULL, 16);
|
2016-12-12 15:55:31 +00: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 11:19:46 +00:00
|
|
|
return T_COLOR;
|
|
|
|
}
|
2016-12-13 07:00:35 +00: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;
|
|
|
|
}
|
2016-12-12 22:40:43 +00:00
|
|
|
<PROPERTIES>#{HEX}{6} {
|
2016-12-11 11:19:46 +00:00
|
|
|
union { unsigned int val; struct { unsigned char b,g,r,a;};} val;
|
2016-12-11 16:50:03 +00:00
|
|
|
val.val = (unsigned int)g_ascii_strtoull ( &yytext[1], NULL, 16);
|
2016-12-12 15:55:31 +00: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 18:48:44 +00:00
|
|
|
return T_COLOR;
|
2016-12-11 16:50:03 +00:00
|
|
|
}
|
2016-12-12 22:40:43 +00:00
|
|
|
<PROPERTIES>rgba\({NUMBER}{1,3},{NUMBER}{1,3},{NUMBER}{1,3},[01](\.{NUMBER}+)?\) {
|
2016-12-11 16:50:03 +00:00
|
|
|
char *endptr = &yytext[5];
|
2016-12-12 15:55:31 +00: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 16:50:03 +00:00
|
|
|
return T_COLOR;
|
|
|
|
}
|
2016-12-12 22:40:43 +00:00
|
|
|
<PROPERTIES>rgb\({NUMBER}{1,3},{NUMBER}{1,3},{NUMBER}{1,3}\) {
|
2016-12-11 16:50:03 +00:00
|
|
|
char *endptr = &yytext[4];
|
2016-12-12 15:55:31 +00: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 16:50:03 +00:00
|
|
|
return T_COLOR;
|
2016-12-10 18:48:44 +00:00
|
|
|
}
|
2016-12-12 22:40:43 +00:00
|
|
|
|
|
|
|
<*>(\r\n|\n) {
|
2016-12-12 15:55:31 +00:00
|
|
|
yylloc->last_column = 1;
|
|
|
|
yylloc->last_line ++;
|
|
|
|
};
|
2016-12-09 18:49:49 +00:00
|
|
|
|
2016-12-17 15:16:28 +00:00
|
|
|
<INITIAL><<EOF>> {
|
2016-12-09 18:49:49 +00:00
|
|
|
yyterminate();
|
2016-12-17 15:16:28 +00:00
|
|
|
printf("Queue free: %d\n", g_queue_get_length(queue));;
|
|
|
|
g_queue_free ( queue );
|
2016-12-09 18:49:49 +00:00
|
|
|
}
|
2016-12-17 15:16:28 +00:00
|
|
|
<*>. {
|
|
|
|
fprintf(stderr, "Invalid character: '%c'\n", *yytext);
|
|
|
|
yyterminate();
|
|
|
|
}
|
|
|
|
|
2016-12-09 18:49:49 +00:00
|
|
|
%%
|