ocaml: +let bindings
This commit is contained in:
parent
2f23dc491d
commit
98b3f087f9
|
@ -1,3 +1,4 @@
|
|||
|
||||
(* unevaluated expressions with no runtime variables *)
|
||||
|
||||
open Tys
|
||||
|
@ -65,7 +66,23 @@ and parse_ty_annot ps = when_got DubColon (fun (_, ps) ->
|
|||
let span_start = ps.offset in
|
||||
let (ptyx, ps) = parse_expr ps in
|
||||
let span = loc_span_of_start_end span_start ps.offset in
|
||||
Some ((ps.file, span), ptyx, ps)
|
||||
((ps.file, span), ptyx, ps)
|
||||
) ps
|
||||
|
||||
and parse_letbinds ps acc = match ps.lt with
|
||||
| (Let, s)::lt ->
|
||||
let (pat, ps) = Pattern.parse { ps with lt; offset = loc_span_end s; } in
|
||||
let (pty, ps) = match parse_ty_annot ps with
|
||||
| Some (x, y, ps) -> (Some (x, y), ps)
|
||||
| None -> (None, ps)
|
||||
in
|
||||
let (_, ps) = require XLet (got Assign) ps in
|
||||
let value_start = ps.offset in
|
||||
let (value, ps) = parse_expr ps in
|
||||
let value_span = loc_span_of_start_end value_start ps.offset in
|
||||
let ps = { ps with names = Pattern.exports ps.names pat } in
|
||||
let (_, ps) = require XLet (got SemiColon) ps in
|
||||
parse_letbinds ps ((pat, pty, (value_span, value)) :: acc)
|
||||
| _ -> (acc, ps)
|
||||
|
||||
and parse_expr _ = failwith "unimplemented"
|
||||
|
|
|
@ -130,7 +130,7 @@ type parser_env =
|
|||
{ lt : token_ann list
|
||||
; file : string
|
||||
; offset : int
|
||||
; names : string list
|
||||
; names : tagged_ident list
|
||||
}
|
||||
|
||||
let zero_len = Unsigned.UInt32.zero
|
||||
|
@ -168,7 +168,7 @@ let require ctx parse_inner ps = match parse_inner ps with
|
|||
let env_lookup_opt name ps =
|
||||
let rec inner names count = match names with
|
||||
| [] -> None
|
||||
| x::xs -> if x == name then Some count else inner xs (count + 1)
|
||||
| x::xs -> if x.ident == name then Some count else inner xs (count + 1)
|
||||
in inner ps.names 0
|
||||
|
||||
let env_lookup name span ps = match env_lookup_opt name ps with
|
||||
|
|
Loading…
Reference in a new issue