blob: 617163e7e7a18db68bc4ae0b1e86287c253b5d24 (
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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
|
{
open Lexing
open Syntax
let chan_out = ref stdout
let comment_depth = ref 0
let print s = output_string !chan_out s
exception Fin_fichier
}
let space = [' ' '\t' '\n']
let letter = ['a'-'z' 'A'-'Z']
let digit = ['0'-'9']
let identifier = letter (letter | digit | ['_' '\''])*
let number = digit+
let oper = ['-' '+' '/' '*' '|' '>' '<' '=' '%' '#' '$' ':' '\\' '?'
'.' '!' '@' ]+
rule token = parse
| "let" {LET}
| "in" {IN}
| "match" {MATCH}
| "with" {WITH}
| "end" {END}
| "and" {AND}
| "fun" {FUN}
| "if" {IF}
| "then" {THEN}
| "else" {ELSE}
| "eval" {EVAL}
| "for" {FOR}
| "Prop" {PROP}
| "Set" {SET}
| "Type" {TYPE}
| "fix" {FIX}
| "cofix" {COFIX}
| "struct" {STRUCT}
| "as" {AS}
| "Simpl" {SIMPL}
| "_" {WILDCARD}
| "(" {LPAR}
| ")" {RPAR}
| "{" {LBRACE}
| "}" {RBRACE}
| "!" {BANG}
| "@" {AT}
| ":" {COLON}
| ":=" {COLONEQ}
| "." {DOT}
| "," {COMMA}
| "->" {OPER "->"}
| "=>" {RARROW}
| "|" {BAR}
| "%" {PERCENT}
| '?' { META(ident lexbuf)}
| number { INT(Lexing.lexeme lexbuf) }
| oper { OPER(Lexing.lexeme lexbuf) }
| identifier { IDENT (Lexing.lexeme lexbuf) }
| "(*" (*"*)"*) { comment_depth := 1;
comment lexbuf;
token lexbuf }
| space+ { token lexbuf}
| eof { EOF }
and ident = parse
| identifier { Lexing.lexeme lexbuf }
and comment = parse
| "(*" (*"*)"*) { incr comment_depth; comment lexbuf }
| (*"(*"*) "*)"
{ decr comment_depth; if !comment_depth > 0 then comment lexbuf }
| eof { raise Fin_fichier }
| _ { comment lexbuf }
|