forked from rescript-lang/rescript
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathnumber_lexer.mll
30 lines (26 loc) · 843 Bytes
/
number_lexer.mll
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
{
external log : string -> unit = "caml_alloc_dummy" [@@bs.val "console.log"]
let l =
#if BS then
log
#else output_string stdout
#end
}
rule token l = parse
[' ' '\t' '\r' '\n'] { l "new line" ; token l lexbuf}
| ['0'-'9']+ { l "number"; l (Lexing.lexeme lexbuf); token l lexbuf }
| ['a'-'z''A'-'Z']+ {l "ident"; l (Lexing.lexeme lexbuf); token l lexbuf}
| '+' { l "+" ; token l lexbuf }
| '-' { l "-" ; token l lexbuf}
| '*' { l "*" ; token l lexbuf}
| '/' { l "/" ; token l lexbuf}
| '(' { l "(" ; token l lexbuf }
| ')' { l ")"; token l lexbuf }
| eof { l "eof" }
{
(* token l (Lexing.from_string "32 + 32 ( ) * / ") *)
(* token (Lexing.from_string "32") *)
}
(* local variables: *)
(* compile-command: "ocamlbuild number_lexer.byte --" *)
(* end: *)