
structure Tokens = Tokens

(* datatype lexresult =  COMMA | DOT | TOP | LPAREN | RPAREN | SEMI *)
(*  | EQUALS | PAR | LCOOP | RCOOP | MINUS | MULT | SUM | HIDE | HASH *)
(*  | PERC | EXP | NORM | UNIF | LSET | RSET | UNION | SETMINUS *)
(*  | PEOF | STRN of string | NUMB of real | INTNUMB of int; *)

 val intOfString = valOf o Int.fromString;
 val realOfString = valOf o Real.fromString;

 val linenum = ref 1;
 val error = fn x => TextIO.output(TextIO.stdOut,x ^ "\n");
 val eof = fn () => Tokens.PEOF(!linenum,!linenum);
 fun inc x = (x := (!x) + 1);

 exception LexicalError of string * int * int; (* (message, loc1, loc2) *)

(*  fun lexerError lexbuf s =  *)
(*      raise LexicalError (s, getLexemeStart lexbuf, getLexemeEnd lexbuf); *)

 type pos = int
 type svalue = Tokens.svalue
 type ('a,'b) token = ('a,'b) Tokens.token
 type lexresult  = (svalue,pos) token

 val commentStart = ref 0;  (* Start of outermost comment being scanned *)
 val commentDepth = ref 0;  (* Current comment nesting *)

(*  fun commentNotClosed lexbuf = *)
(*      raise LexicalError ("Comment not terminated",  *)
(*                          !commentStart, getLexemeEnd lexbuf); *)
     
%%
%header (functor PepaLexFun(structure Tokens: Pepa_TOKENS));

%%

\n        => (inc linenum; lex());
[\ \t]+   => (lex());
","       => (Tokens.COMMA(!linenum,!linenum));
"."       => (Tokens.DOT(!linenum,!linenum));
"reward"  => (Tokens.REWARD(!linenum,!linenum));
"attachment" => (Tokens.ATTACHMENT(!linenum,!linenum));
"tt"      => (Tokens.MTT(!linenum,!linenum));
"ff"      => (Tokens.MFF(!linenum,!linenum));
"|"       => (Tokens.LOR(!linenum,!linenum));
"&"       => (Tokens.LAND(!linenum,!linenum));
"~"       => (Tokens.LNOT(!linenum,!linenum));
"/\\{"     => (Tokens.DELTA(!linenum,!linenum));
"\\/{"     => (Tokens.NABLA(!linenum,!linenum));
"rate("   => (Tokens.RATE(!linenum,!linenum));
"infty"   => (Tokens.TOP(!linenum,!linenum));
"top"     => (Tokens.TOP(!linenum,!linenum));
"U"       => (Tokens.UNION(!linenum,!linenum));
"("       => (Tokens.LPAREN(!linenum,!linenum));
")"       => (Tokens.RPAREN(!linenum,!linenum));
";"       => (Tokens.SEMI(!linenum,!linenum));
"=>"      => (Tokens.ARROW(!linenum,!linenum));
"="       => (Tokens.EQUALS(!linenum,!linenum));
"||"      => (Tokens.PAR(!linenum,!linenum));
"<"       => (Tokens.LCOOP(!linenum,!linenum));
">"       => (Tokens.RCOOP(!linenum,!linenum));
"{"       => (Tokens.LSET(!linenum,!linenum));
"}"       => (Tokens.RSET(!linenum,!linenum));
"["       => (Tokens.LSQUARE(!linenum,!linenum));
"]"       => (Tokens.RSQUARE(!linenum,!linenum));
"*"       => (Tokens.MULT(!linenum,!linenum));
"-"       => (Tokens.MINUS(!linenum,!linenum));
"+"       => (Tokens.SUM(!linenum,!linenum));
"/"       => (Tokens.HIDE(!linenum,!linenum));
"\\"      => (Tokens.SETMINUS(!linenum,!linenum));
"#"       => (Tokens.HASH(!linenum,!linenum));
"%"       => (Tokens.PERC(!linenum,!linenum));
[0-9]+("."[0-9]*) => (Tokens.NUMB(realOfString (yytext),!linenum,!linenum));
[0-9]+    => (Tokens.INTNUMB(intOfString (yytext),!linenum,!linenum));
[A-Za-z]([A-Za-z0-9_'-]*) => (Tokens.STRN(yytext,!linenum,!linenum));


