Source

blub / blub_lexer.mll

{
  open Blub_parse
  open Blub_types
}

let digit = ['0' - '9']
let special_initial = ['!' '$' '%' '&' '*' '/' ':' '<' '=' '>' '?' '^' '_' '~'] 
let initial = ['a'-'z'] | ['A'-'Z'] | special_initial
let subsequent = initial | digit | ['+' '-' '.' '@']
let peculiar_id = ['+' '-'] | "..."

rule read_string sbuf = parse
  | '"' { }
  | "\\\"" { Buffer.add_char sbuf '"'; read_string sbuf lexbuf }
  | _ as c { Buffer.add_char sbuf c; read_string sbuf lexbuf }
    
and token = parse
    digit+ as num { INTEGER (int_of_string num) }
  | digit+ '.' digit* as num { FLOAT (float_of_string num) }
  | "#f" { BOOLEAN false }
  | "#t" { BOOLEAN true }
  | '(' { LPAREN }
  | ')' { RPAREN }
  | "if" { IF } 
  | "quote" { QUOTE }
  | '\'' { TINYQUOTE }
  | "begin" { BEGIN }
  | "lambda" { LAMBDA }
  | "let" { LET }
  | "letrec" { LETREC }
  | "let*" { LETSTAR }
  | "define" { DEFINE }
  | "." { DOT }
  | "set!" { SET }
  | "call-with-current-continuation" | "call/cc" { CALLCC }
  | "cond" { COND }
  | "else" { ELSE }
  | "=>" { ARROW }
  | "shift" { SHIFT }
  | "reset" { RESET }

  | ';' [^'\n']* '\n' { token lexbuf }   (* eat up comments *)

  | '"' 
      { 
	let buf = Buffer.create 1000 in
	read_string buf lexbuf;
	let s = Buffer.contents buf in
	STRING s
      }
  | (initial subsequent*) | peculiar_id as id { IDENTIFIER id }
      

  | [' ' '\t' '\n' '\r' '\012'] { token lexbuf }   (* eat up whitespace *)
  | eof { raise End_of_file }

{
}