about summary refs log tree commit diff
path: root/src/parser/Lexer.mll
blob: 22ae387122a61b623e85e1e28020a9c920f9364f (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
{
open Grammar

exception IllegalCharacter of char
}

let whitespace = [' ' '\t' '\r' '\n']+
let letter = ['a'-'z' 'A'-'Z']
let ident = letter+

rule token =
  parse
  | whitespace { token lexbuf }

  | "(" { LPR }
  | ")" { RPR }
  | "[" { LBR }
  | "]" { RBR }
  | "->" { ARROW }
  | ":=" { ASSIGN }
  | "*" { ASTERISK }
  | "\\" { BACKSLASH }
  | "::" { DOUBLE_COLON }
  | ":" { COLON }
  | "," { COMMA }
  | "." { DOT }
  | "=>" { FATARROW }
  | "_" { UNDERSCORE }

  | "def" { DEF }

  | "fst" { FST }
  | "snd" { SND }

  | "type" { TYPE }

  | "bool" { BOOL }
  | "true" { TRUE }
  | "false" { FALSE }
  | "bool-elim" { BOOL_ELIM }
  | "at" { AT }

  | ident { IDENT (Lexing.lexeme lexbuf) }

  | eof { EOF }
  | (_ as illegal_char) { raise (IllegalCharacter illegal_char) }