From ff81184c4c39a001e354f0b609aff6ff0cb34eaa Mon Sep 17 00:00:00 2001 From: Christian Rinderknecht Date: Sat, 13 Apr 2019 19:19:36 +0200 Subject: [PATCH] Removed last dependency of Lexer on EvalOpt. Renamed field "record_name" into "struct_name" in AST. --- src/ligo/ligo_parser/AST.ml | 6 +- src/ligo/ligo_parser/AST.mli | 2 +- src/ligo/ligo_parser/Lexer.mll | 159 ++++++++++++++++----------------- src/ligo/simplify.ml | 2 +- 4 files changed, 84 insertions(+), 85 deletions(-) diff --git a/src/ligo/ligo_parser/AST.ml b/src/ligo/ligo_parser/AST.ml index 2e0659610..5362beabc 100644 --- a/src/ligo/ligo_parser/AST.ml +++ b/src/ligo/ligo_parser/AST.ml @@ -615,7 +615,7 @@ and field_assign = { } and projection = { - record_name : variable; + struct_name : variable; selector : dot; field_path : (selection, dot) nsepseq } @@ -1344,8 +1344,8 @@ and print_field_assign {value; _} = print_expr field_expr and print_projection {value; _} = - let {record_name; selector; field_path} = value in - print_var record_name; + let {struct_name; selector; field_path} = value in + print_var struct_name; print_token selector "."; print_field_path field_path diff --git a/src/ligo/ligo_parser/AST.mli b/src/ligo/ligo_parser/AST.mli index 46905ddde..d7567501b 100644 --- a/src/ligo/ligo_parser/AST.mli +++ b/src/ligo/ligo_parser/AST.mli @@ -599,7 +599,7 @@ and field_assign = { } and projection = { - record_name : variable; + struct_name : variable; selector : dot; field_path : (selection, dot) nsepseq } diff --git a/src/ligo/ligo_parser/Lexer.mll b/src/ligo/ligo_parser/Lexer.mll index d5c7b5d5f..9ae4dd065 100644 --- a/src/ligo/ligo_parser/Lexer.mll +++ b/src/ligo/ligo_parser/Lexer.mll @@ -733,87 +733,86 @@ type instance = { close : unit -> unit } -let file_path = match EvalOpt.input with - None | Some "-" -> "" - | Some file_path -> file_path -let pos = Pos.min#set_file file_path -let buf_reg = ref (pos#byte, pos#byte) -and first_call = ref true -and decoder = Uutf.decoder ~encoding:`UTF_8 `Manual -let supply = Uutf.Manual.src decoder -let state = ref {units = FQueue.empty; - last = Region.ghost; - pos; - markup = []; - decoder; - supply} - -let get_pos () = !state.pos - -let get_last () = !state.last - -let patch_buffer (start, stop) buffer = - let open Lexing in - let file_path = buffer.lex_curr_p.pos_fname in - buffer.lex_start_p <- {start with pos_fname = file_path}; - buffer.lex_curr_p <- {stop with pos_fname = file_path} - -and save_region buffer = - buf_reg := Lexing.(buffer.lex_start_p, buffer.lex_curr_p) - -let scan buffer = - patch_buffer !buf_reg buffer; - (if !first_call - then (state := init !state buffer; first_call := false) - else state := scan !state buffer); - save_region buffer - -let next_token buffer = - scan buffer; - match FQueue.peek !state.units with - None -> assert false - | Some (units, ext_token) -> - state := {!state with units}; Some ext_token - -let check_right_context token buffer = - let open Token in - if is_int token || is_bytes token then - match next_token buffer with - Some ([], next) -> - let pos = (Token.to_region token)#stop in - let region = Region.make ~start:pos ~stop:pos in - if is_bytes token && is_int next then - fail region Odd_lengthed_bytes - else - if is_ident next || is_string next - || is_bytes next || is_int next then - fail region Missing_break - | _ -> () - else - if Token.is_ident token || Token.is_string token then - match next_token buffer with - Some ([], next) -> - if Token.is_ident next || Token.is_string next - || Token.is_bytes next || Token.is_int next - then - let pos = (Token.to_region token)#stop in - let region = Region.make ~start:pos ~stop:pos - in fail region Missing_break - | _ -> () - -let rec read_token ?(log=fun _ _ -> ()) buffer = - match FQueue.deq !state.units with - None -> - scan buffer; - read_token ~log buffer - | Some (units, (left_mark, token)) -> - log left_mark token; - state := {!state with units; last = Token.to_region token}; - check_right_context token buffer; - patch_buffer (Token.to_region token)#byte_pos buffer; - token - let open_token_stream file_path_opt = + let file_path = match file_path_opt with + None | Some "-" -> "" + | Some file_path -> file_path in + let pos = Pos.min#set_file file_path in + let buf_reg = ref (pos#byte, pos#byte) + and first_call = ref true + and decoder = Uutf.decoder ~encoding:`UTF_8 `Manual in + let supply = Uutf.Manual.src decoder in + let state = ref {units = FQueue.empty; + last = Region.ghost; + pos; + markup = []; + decoder; + supply} in + + let get_pos () = !state.pos + and get_last () = !state.last in + + let patch_buffer (start, stop) buffer = + let open Lexing in + let file_path = buffer.lex_curr_p.pos_fname in + buffer.lex_start_p <- {start with pos_fname = file_path}; + buffer.lex_curr_p <- {stop with pos_fname = file_path} + + and save_region buffer = + buf_reg := Lexing.(buffer.lex_start_p, buffer.lex_curr_p) in + + let scan buffer = + patch_buffer !buf_reg buffer; + (if !first_call + then (state := init !state buffer; first_call := false) + else state := scan !state buffer); + save_region buffer in + + let next_token buffer = + scan buffer; + match FQueue.peek !state.units with + None -> assert false + | Some (units, ext_token) -> + state := {!state with units}; Some ext_token in + + let check_right_context token buffer = + let open Token in + if is_int token || is_bytes token then + match next_token buffer with + Some ([], next) -> + let pos = (Token.to_region token)#stop in + let region = Region.make ~start:pos ~stop:pos in + if is_bytes token && is_int next then + fail region Odd_lengthed_bytes + else + if is_ident next || is_string next + || is_bytes next || is_int next then + fail region Missing_break + | _ -> () + else + if Token.is_ident token || Token.is_string token then + match next_token buffer with + Some ([], next) -> + if Token.is_ident next || Token.is_string next + || Token.is_bytes next || Token.is_int next + then + let pos = (Token.to_region token)#stop in + let region = Region.make ~start:pos ~stop:pos + in fail region Missing_break + | _ -> () in + + let rec read_token ?(log=fun _ _ -> ()) buffer = + match FQueue.deq !state.units with + None -> + scan buffer; + read_token ~log buffer + | Some (units, (left_mark, token)) -> + log left_mark token; + state := {!state with units; last = Token.to_region token}; + check_right_context token buffer; + patch_buffer (Token.to_region token)#byte_pos buffer; + token in + let cin = match file_path_opt with None | Some "-" -> stdin | Some file_path -> open_in file_path in diff --git a/src/ligo/simplify.ml b/src/ligo/simplify.ml index 5e5467720..a81c322f5 100644 --- a/src/ligo/simplify.ml +++ b/src/ligo/simplify.ml @@ -85,7 +85,7 @@ let rec simpl_expression (t:Raw.expr) : ae result = let return x = ok @@ ae x in let simpl_projection = fun (p:Raw.projection) -> let var = - let name = p.record_name.value in + let name = p.struct_name.value in ae @@ E_variable name in let path = p.field_path in let path' =