Skip to content

Commit

Permalink
♻️ Use Core.Hashtbl in the lexer
Browse files Browse the repository at this point in the history
  • Loading branch information
Zeta611 committed Jun 1, 2024
1 parent feb4904 commit f562090
Showing 1 changed file with 5 additions and 6 deletions.
11 changes: 5 additions & 6 deletions lib/lexer.mll
Original file line number Diff line number Diff line change
@@ -1,14 +1,13 @@
{
open Core
open Lexing
open Parser

exception SyntaxError of string

let keyword_tbl = Hashtbl.create 31

let () =
List.iter
(fun (keyword, tok) -> Hashtbl.add keyword_tbl keyword tok)
let keywords =
Hashtbl.of_alist_exn
(module String)
[
("if", IF);
("then", THEN);
Expand Down Expand Up @@ -36,7 +35,7 @@ rule read =
| newline { new_line lexbuf; read lexbuf }
| int as i { INT (int_of_string i) }
| real as r { REAL (float_of_string r) }
| id as s { try Hashtbl.find keyword_tbl s with Not_found -> ID s }
| id as s { match Hashtbl.find keywords s with Some s -> s | None -> ID s }
| '#' { comment lexbuf }
| '+' { PLUS }
| "+." { RPLUS }
Expand Down

0 comments on commit f562090

Please sign in to comment.