]> Pileus Git - ~andy/ct/blobdiff - scan.l
Add C/Bison/Lex ct parser
[~andy/ct] / scan.l
diff --git a/scan.l b/scan.l
new file mode 100644 (file)
index 0000000..19f6777
--- /dev/null
+++ b/scan.l
@@ -0,0 +1,23 @@
+%{
+#define YYSTYPE char *
+#include <glib.h>
+#include "parse.h"
+#define debug(arg) // g_message("scan: " arg, yytext);
+%}
+%option noyywrap
+%option nounput
+%option noinput
+/* %option nodebug */
+START [ \t]*<%
+END   [ \t]*%>[ \t]*
+DATA  ([^<\n]|<[^%])*
+CODE  [ \t\n]([^%\n]|%[^>])*
+%s IN FMT
+%%
+<INITIAL>{START} { debug("START [%s]"); yylval = g_strdup(yytext); BEGIN(IN);      return START; }
+<INITIAL>{DATA}  { debug("DATA  [%s]"); yylval = g_strdup(yytext);                 return DATA;  }
+<IN>{END}        { debug("END   [%s]"); yylval = g_strdup(yytext); BEGIN(INITIAL); return END;   }
+<IN>=            { debug("OUT   [%s]"); yylval = g_strdup(yytext);                 return OUT;   }
+<IN>{CODE}       { debug("CODE  [%s]"); yylval = g_strdup(yytext);                 return DATA;  }
+[\n]             { debug("NL    [%s]"); }
+%%