[project @ 1996-11-21 16:45:53 by simonm]
[ghc-hetmet.git] / ghc / utils / ugen / lex.flex
1 %{
2 #define YYSTYPE long
3
4 #ifdef __STDC__
5 #define PROTO(x)        x
6 #else
7 #define PROTO(x)        ()
8 #endif
9
10 # include "syntax.tab.h"
11 # include <stdio.h>
12 # include "id.h"
13 # include "tree.h"
14 # include "funs.h"
15 extern  YYSTYPE yylval;
16 extern  FILE *fc, *fhs;
17 int lineno;
18
19 void countNewlines (char *s)
20 {
21   while (*s) if (*s++ == '\n') lineno += 1;
22 }
23
24 %}
25
26 %%
27 ";"                     { return(SEMICOL); }
28 ":"                     { return(COLON); }
29 "<"                     { return(STDEF); }
30 ">"                     { return(ENDDEF); }
31 "type"                  { return(TYPE); }
32 "end"                   { return(END); }
33 [A-Za-z][A-Za-z0-9_]*   { yylval = (YYSTYPE) installid(yytext); return(ID); }
34 "\n"                    { lineno += 1; }
35 .                       { }
36 "/*"([^*]|"*"[^/]|\n)*"*/" { countNewlines(yytext); }
37 "%{{"([^%]|"%"[^}]|\n)*"%}}" {
38                                 /* For Haskell includes */
39                                 countNewlines(yytext);
40                                 yytext[yyleng-3] = '\0';
41                                 fprintf(fhs, "\n%s", yytext+3);
42                               }
43 "%{"([^%]|"%"[^}]|\n)*"%}"  {
44                               countNewlines(yytext);
45                               yytext[yyleng-2] = '\0';
46                               fprintf(fc, "\n%s",  &yytext[2]);
47                             }
48 %%
49 int
50 yywrap()
51 {
52         return(1);
53 }