alec

Abstraction Layer for Escape Codes
git clone git://git.dimitrijedobrota.com/alec.git
Log | Files | Refs | README | LICENSE

lexer.l (863B)


      1 %option noyywrap nodefault yylineno
      2 
      3 %{
      4     #include "generator.h"
      5     #include "parser.h"
      6     #include <ctype.h>
      7 %}
      8 
      9 LINE_END (\n|\r|\r\n)
     10 
     11 %x GEN
     12 %x LAST
     13 
     14 %%
     15 
     16 
     17 "%%"{LINE_END}     { BEGIN GEN; return SWITCH; }
     18 .*{LINE_END}       { yylval.n = strdup(yytext); return PROLOGUE; }
     19 
     20 <GEN>{LINE_END}                  { return EOL; }
     21 <GEN>^[\t ]*{LINE_END}           { return EOL; }
     22 <GEN>^[\t ]*\|*[\t ]*{LINE_END}  { return EMPTY; }
     23 
     24 <GEN>^[\t ]*"//".* { yylval.n = strdup(yytext); return COMMENT; }
     25 
     26 <GEN>, { return COMMA; }
     27 
     28 <GEN>[^,\n]*                  {
     29     char *p = yytext + strlen(yytext) - 1;
     30     while(isspace(*p)) *p-- = '\0';
     31 	while(*yytext && isspace(*yytext)) yytext++;
     32 	yylval.n = strdup(yytext); return LITERAL;
     33 }
     34 
     35 <GEN>"%%"{LINE_END}        { BEGIN LAST; return SWITCH; }
     36 
     37 <LAST>.*{LINE_END}       { yylval.n = strdup(yytext); return EPILOGUE; }
     38 
     39 %%
     40