Source

ocaml-lib / lexer.mll

Full commit
{
open Token
} 

let skip_char = [' ' '\t']
let ident_char = ['A'-'Z' 'a'-'z' '0'-'9' '_']
let digit = ['0'-'9']

rule token = parse
| skip_char { token lexbuf }
| "\\\n" { token lexbuf }
| '\n' { EOL }
| '`' { BackQuote }
| '~' { Tilda }
| '!' { Exclam }
| '@' { At }
| '#' { Sharp }
| '$' { Dollar }
| '%' { Percent }
| '^' { Hat }
| '&' { Et }
| '*' { Star }
| '(' { LeftPar }
| ')' { RightPar }
| '-' { Minus }
| '+' { Plus }
| '=' { Equal }
| '{' { LeftAcc }
| '}' { RightAcc }
| '[' { LeftBra }
| ']' { RightBra }
| '|' { Pipe }
| '\\' { BackSlash }
| '/' { Slash }
| '?' { Interro }
| '<' { LT }
| '>' { GT }
| ',' { Comma }
| '.''.' { DotDot }
| '.' { Dot }
| ':' { Colon }
| ';' { SemiColon }
| '"' { DoubleQuote }
| '\'' { Quote }
| ['a'-'z' 'A'-'Z' '_'] ident_char *
    { Ident(Lexing.lexeme lexbuf) }
| ['+' '-']? digit+
    { Int(int_of_string(Lexing.lexeme lexbuf)) }
| ['+' '-']? digit+ '.' digit+ (['e' 'E'] ['+' '-']? digit+)?
    { Float(float_of_string(Lexing.lexeme lexbuf)) }
| '`' _ '`'
    { Char((Lexing.lexeme lexbuf).[1]) }
| '"' [^ '\\' '"']* ('\\' _ [^ '\\' '"']*)* '"'
  { let s = Lexing.lexeme lexbuf in String(String.sub s 1 (String.length s - 2)) }
| '\'' [^ '\\' '\'']* ('\\' _ [^ '\\' '\'']*)* '\''
  { let s = Lexing.lexeme lexbuf in Term(String.sub s 1 (String.length s - 2)) }
| eof { raise Eof }