Pass column info on lex
This commit is contained in:
parent
8434ac98a0
commit
bacfd64bae
2 changed files with 5 additions and 4 deletions
8
lex.ml
8
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
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Add table
Reference in a new issue