Removed last dependency of Lexer on EvalOpt.

This commit is contained in:
Christian Rinderknecht 2019-04-13 19:19:36 +02:00
parent fd5bee397b
commit d8d2d79e9d
No known key found for this signature in database
GPG Key ID: 9446816CFD267040
4 changed files with 84 additions and 85 deletions

View File

@ -615,7 +615,7 @@ and field_assign = {
} }
and projection = { and projection = {
record_name : variable; struct_name : variable;
selector : dot; selector : dot;
field_path : (selection, dot) nsepseq field_path : (selection, dot) nsepseq
} }
@ -1344,8 +1344,8 @@ and print_field_assign {value; _} =
print_expr field_expr print_expr field_expr
and print_projection {value; _} = and print_projection {value; _} =
let {record_name; selector; field_path} = value in let {struct_name; selector; field_path} = value in
print_var record_name; print_var struct_name;
print_token selector "."; print_token selector ".";
print_field_path field_path print_field_path field_path

View File

@ -599,7 +599,7 @@ and field_assign = {
} }
and projection = { and projection = {
record_name : variable; struct_name : variable;
selector : dot; selector : dot;
field_path : (selection, dot) nsepseq field_path : (selection, dot) nsepseq
} }

View File

@ -733,49 +733,49 @@ type instance = {
close : unit -> unit close : unit -> unit
} }
let file_path = match EvalOpt.input with let open_token_stream file_path_opt =
let file_path = match file_path_opt with
None | Some "-" -> "" None | Some "-" -> ""
| Some file_path -> file_path | Some file_path -> file_path in
let pos = Pos.min#set_file file_path let pos = Pos.min#set_file file_path in
let buf_reg = ref (pos#byte, pos#byte) let buf_reg = ref (pos#byte, pos#byte)
and first_call = ref true and first_call = ref true
and decoder = Uutf.decoder ~encoding:`UTF_8 `Manual and decoder = Uutf.decoder ~encoding:`UTF_8 `Manual in
let supply = Uutf.Manual.src decoder let supply = Uutf.Manual.src decoder in
let state = ref {units = FQueue.empty; let state = ref {units = FQueue.empty;
last = Region.ghost; last = Region.ghost;
pos; pos;
markup = []; markup = [];
decoder; decoder;
supply} supply} in
let get_pos () = !state.pos let get_pos () = !state.pos
and get_last () = !state.last in
let get_last () = !state.last let patch_buffer (start, stop) buffer =
let patch_buffer (start, stop) buffer =
let open Lexing in let open Lexing in
let file_path = buffer.lex_curr_p.pos_fname in let file_path = buffer.lex_curr_p.pos_fname in
buffer.lex_start_p <- {start with pos_fname = file_path}; buffer.lex_start_p <- {start with pos_fname = file_path};
buffer.lex_curr_p <- {stop with pos_fname = file_path} buffer.lex_curr_p <- {stop with pos_fname = file_path}
and save_region buffer = and save_region buffer =
buf_reg := Lexing.(buffer.lex_start_p, buffer.lex_curr_p) buf_reg := Lexing.(buffer.lex_start_p, buffer.lex_curr_p) in
let scan buffer = let scan buffer =
patch_buffer !buf_reg buffer; patch_buffer !buf_reg buffer;
(if !first_call (if !first_call
then (state := init !state buffer; first_call := false) then (state := init !state buffer; first_call := false)
else state := scan !state buffer); else state := scan !state buffer);
save_region buffer save_region buffer in
let next_token buffer = let next_token buffer =
scan buffer; scan buffer;
match FQueue.peek !state.units with match FQueue.peek !state.units with
None -> assert false None -> assert false
| Some (units, ext_token) -> | Some (units, ext_token) ->
state := {!state with units}; Some ext_token state := {!state with units}; Some ext_token in
let check_right_context token buffer = let check_right_context token buffer =
let open Token in let open Token in
if is_int token || is_bytes token then if is_int token || is_bytes token then
match next_token buffer with match next_token buffer with
@ -799,9 +799,9 @@ let check_right_context token buffer =
let pos = (Token.to_region token)#stop in let pos = (Token.to_region token)#stop in
let region = Region.make ~start:pos ~stop:pos let region = Region.make ~start:pos ~stop:pos
in fail region Missing_break in fail region Missing_break
| _ -> () | _ -> () in
let rec read_token ?(log=fun _ _ -> ()) buffer = let rec read_token ?(log=fun _ _ -> ()) buffer =
match FQueue.deq !state.units with match FQueue.deq !state.units with
None -> None ->
scan buffer; scan buffer;
@ -811,9 +811,8 @@ let rec read_token ?(log=fun _ _ -> ()) buffer =
state := {!state with units; last = Token.to_region token}; state := {!state with units; last = Token.to_region token};
check_right_context token buffer; check_right_context token buffer;
patch_buffer (Token.to_region token)#byte_pos buffer; patch_buffer (Token.to_region token)#byte_pos buffer;
token token in
let open_token_stream file_path_opt =
let cin = match file_path_opt with let cin = match file_path_opt with
None | Some "-" -> stdin None | Some "-" -> stdin
| Some file_path -> open_in file_path in | Some file_path -> open_in file_path in

View File

@ -85,7 +85,7 @@ let rec simpl_expression (t:Raw.expr) : ae result =
let return x = ok @@ ae x in let return x = ok @@ ae x in
let simpl_projection = fun (p:Raw.projection) -> let simpl_projection = fun (p:Raw.projection) ->
let var = let var =
let name = p.record_name.value in let name = p.struct_name.value in
ae @@ E_variable name in ae @@ E_variable name in
let path = p.field_path in let path = p.field_path in
let path' = let path' =