{ open Parser exception SyntaxError of string } let digit = ['0'-'9'] let frac = '.' digit* let exp = ['e' 'E'] ['-' '+']? digit+ let float = digit* frac? exp? let int = digit+ let white = [' ' '\t']+ let newline = '\r' | '\n' | "\r\n" let id = ['a'-'z' 'A'-'Z' '-' '_']* let newline = '\r' | '\n' | "\r\n" let many_newline = newline+ rule read = parse | "uuidv4" { UUIDV4 } | "email" { EMAIL } | "name" { NAME } | "increment" { INCREMENT } | "username" { USERNAME } | "past" { PAST } | "future" { FUTURE } | "now" { NOW } | "int" { INTSYMBOL } | id { IDENTIFIER (Lexing.lexeme lexbuf) } | "(" { LBRACE } | ")" { RBRACE } | '"' { read_string (Buffer.create 20) lexbuf } | int { INT (Lexing.lexeme lexbuf |> int_of_string) } | white { read lexbuf } | ":" { COLON } | ";" { SEMICOLON } | "," { COMMA } | many_newline { NEWLINE } | "." { DOT } | eof { EOF } | _ as c { failwith (Printf.sprintf "unexpected character: %C" c) } and read_string buf = parse | '"' { STRING (Buffer.contents buf) } | '\\' '/' { Buffer.add_char buf '/'; read_string buf lexbuf } | '\\' '\\' { Buffer.add_char buf '\\'; read_string buf lexbuf } | '\\' 'b' { Buffer.add_char buf '\b'; read_string buf lexbuf } | '\\' 'f' { Buffer.add_char buf '\012'; read_string buf lexbuf } | '\\' 'n' { Buffer.add_char buf '\n'; read_string buf lexbuf } | '\\' 'r' { Buffer.add_char buf '\r'; read_string buf lexbuf } | '\\' 't' { Buffer.add_char buf '\t'; read_string buf lexbuf } | [^ '"' '\\']+ { Buffer.add_string buf (Lexing.lexeme lexbuf); read_string buf lexbuf } | _ { raise (SyntaxError ("Illegal string character: " ^ Lexing.lexeme lexbuf)) } | eof { raise (SyntaxError ("String is not terminated")) }