2016-12-11 15:58:55 -05:00
|
|
|
%option noyywrap nounput batch
|
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-09 13:49:49 -05:00
|
|
|
int yylex(void);
|
|
|
|
#define YY_DECL int yylex()
|
|
|
|
|
|
|
|
%}
|
|
|
|
|
|
|
|
%%
|
2016-12-11 12:25:47 -05:00
|
|
|
"//" {
|
|
|
|
int c;
|
|
|
|
while ((c = input()) != EOF)
|
|
|
|
if (c == '\n') {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
"/*" {
|
|
|
|
int c = 0, p;
|
|
|
|
int nesting_depth = 1;
|
|
|
|
while (nesting_depth) {
|
|
|
|
p = c;
|
|
|
|
c = input();
|
|
|
|
switch (c) {
|
|
|
|
case '*': if (p == '/') { c = 0; nesting_depth++; } break;
|
|
|
|
case '/': if (p == '*') { c = 0; nesting_depth--; } break;
|
|
|
|
case '\n': break;
|
|
|
|
case EOF: nesting_depth = 0; break;
|
|
|
|
default: ;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2016-12-09 13:49:49 -05:00
|
|
|
"\{" { return BOPEN;}
|
|
|
|
"\}" { return BCLOSE;}
|
|
|
|
":" { return PSEP; }
|
|
|
|
";" { return PCLOSE;}
|
|
|
|
"." { return NSEP; }
|
|
|
|
[ \t] ; // ignore all whitespace
|
2016-12-09 16:16:31 -05:00
|
|
|
[0-9]+\.[0-9]+ { yylval.fval = g_ascii_strtod(yytext, NULL); return T_DOUBLE;}
|
2016-12-09 13:49:49 -05:00
|
|
|
[0-9]+ { yylval.ival = (int)g_ascii_strtoll(yytext, NULL, 10); return T_INT;}
|
|
|
|
(true|false) { yylval.bval= g_strcmp0(yytext, "true") == 0; return T_BOOLEAN;}
|
2016-12-09 16:16:31 -05:00
|
|
|
[_\-a-zA-Z0-9]+ { yylval.sval = g_strdup(yytext); return N_STRING;}
|
|
|
|
\"[_\-a-zA-Z0-9 \t]+\" { yytext[yyleng-1] = '\0'; yylval.sval = g_strdup(&yytext[1]); return T_STRING;}
|
2016-12-11 11:50:03 -05:00
|
|
|
|
2016-12-11 06:19:46 -05:00
|
|
|
#[0-9A-Fa-f]{8} {
|
|
|
|
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);
|
|
|
|
yylval.colorval.alpha = val.a/255.0;
|
2016-12-11 06:19:46 -05:00
|
|
|
yylval.colorval.red = val.r/255.0;
|
2016-12-10 13:48:44 -05:00
|
|
|
yylval.colorval.green = val.g/255.0;
|
2016-12-11 06:19:46 -05:00
|
|
|
yylval.colorval.blue = val.b/255.0;
|
|
|
|
return T_COLOR;
|
|
|
|
}
|
|
|
|
#[0-9A-Fa-f]{6} {
|
|
|
|
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-11 12:25:47 -05:00
|
|
|
yylval.colorval.alpha = 1.0;
|
2016-12-11 06:19:46 -05:00
|
|
|
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
|
|
|
}
|
|
|
|
rgba\([0-9]{1,3},[0-9]{1,3},[0-9]{1,3},[01](\.[0-9]+)?\) {
|
|
|
|
char *endptr = &yytext[5];
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
rgb\([0-9]{1,3},[0-9]{1,3},[0-9]{1,3}\) {
|
|
|
|
char *endptr = &yytext[4];
|
|
|
|
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
|
|
|
}
|
|
|
|
[\r\n]+ ;
|
2016-12-09 13:49:49 -05:00
|
|
|
|
|
|
|
<*><<EOF>> {
|
|
|
|
yyterminate();
|
|
|
|
}
|
|
|
|
%%
|