summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDave Davenport <qball@gmpclient.org>2016-12-11 18:25:47 +0100
committerDave Davenport <qball@gmpclient.org>2016-12-11 18:25:47 +0100
commit8f8d296029184a53b6f14d50d061a0b943ce2d1a (patch)
tree06607d466ff8a99f553e27febf52a11ab6b80e2d
parent95667e60d9024fcaa122ed6096d53f701df11165 (diff)
Add support for // and /* */ comments
-rw-r--r--lexer/theme-lexer.l27
1 files changed, 24 insertions, 3 deletions
diff --git a/lexer/theme-lexer.l b/lexer/theme-lexer.l
index f0ce33cf..e6aeeb60 100644
--- a/lexer/theme-lexer.l
+++ b/lexer/theme-lexer.l
@@ -1,4 +1,4 @@
-%option noyywrap
+%option noyywrap nounput batch debug
%{
#include <stdio.h>
@@ -11,7 +11,28 @@ int yylex(void);
%}
%%
-
+"//" {
+ 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: ;
+ }
+ }
+}
"\{" { return BOPEN;}
"\}" { return BCLOSE;}
":" { return PSEP; }
@@ -36,7 +57,7 @@ int yylex(void);
#[0-9A-Fa-f]{6} {
union { unsigned int val; struct { unsigned char b,g,r,a;};} val;
val.val = (unsigned int)g_ascii_strtoull ( &yytext[1], NULL, 16);
- yylval.colorval.alpha = 1.0;
+ 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;