From bacfd64bae3f135ca81010ca4d179ed8badff03e Mon Sep 17 00:00:00 2001 From: Hyeonung Baek Date: Tue, 15 Feb 2022 00:08:24 +0900 Subject: [PATCH] Pass column info on lex --- lex.ml | 8 ++++---- parser.ml | 1 + 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/lex.ml b/lex.ml index d058499..d155eaa 100644 --- a/lex.ml +++ b/lex.ml @@ -81,7 +81,7 @@ let tokenize str = let str, seq = partition_while (fun (_, c) -> c <> '"') seq in let str = String.of_seq @@ Seq.map snd str in let seq = expect_char (col + String.length str + 1) '"' seq in - cons (String str) (aux seq) + cons (col, String str) (aux seq) (* number (int, float) *) else if is_digit x then @@ -92,18 +92,18 @@ let tokenize str = then Float (float_of_string n) else Int (int_of_string n) in - cons n (aux seq) + cons (col, n) (aux seq) (* idents *) else if is_ident_start x then let id, seq = partition_while (snds is_ident) seq in let id = String.of_seq @@ cons x @@ Seq.map snd id in - cons (Ident id) (aux seq) + cons (col, Ident id) (aux seq) (* tokens *) else match find_token @@ cons (col, x) seq with | None -> invalid_char col x - | Some (t, seq) -> cons t (aux seq) + | Some (t, seq) -> cons (col, t) (aux seq) in aux seq diff --git a/parser.ml b/parser.ml index 5f50188..2ffedac 100644 --- a/parser.ml +++ b/parser.ml @@ -317,6 +317,7 @@ and binop pre left seq = (* parse tokens *) let parse ts = + let ts = Seq.map snd ts in let ast, rest = decl ts in if rest () <> Seq.Nil then failwith "Parser.parse"; ast