diff --git a/lex.ml b/lex.ml index d155eaa..0d8fed7 100644 --- a/lex.ml +++ b/lex.ml @@ -9,6 +9,8 @@ let expected col c = raise @@ Expected (col, c) let either f g c = f c || g c +(* test functions *) + let is_digit c = '0' <= c && c <= '9' @@ -30,10 +32,11 @@ let is_ident_start = let is_ident = either is_ident_start is_digit +(* expect_char expects c at col of seq. If not, raise Expected. *) let expect_char col c seq = match seq () with | Seq.Nil -> expected col c - | Seq.Cons ((_, x), seq) -> + | Seq.Cons ((col, x), seq) -> if x = c then seq else expected col c let expect_token str tok seq =