Commit 2fece03f authored by POGODALLA Sylvain's avatar POGODALLA Sylvain

Bug fix: in interpreter, data are not lost after loading a script

parent e3c7ae50
......@@ -12,6 +12,25 @@ load d ../data/cvg.acg;
compose CVG_strings CVG_syntax as CVG_phonology;
compose RC_ty CVG_semantics as ty_sem;
# Let's look we we have as signatures and lexicons:
list ;
# Available data:
# Lexicon ty_sem (syntax --> ty_n)
# Signature ty_n
# Signature syntax
# Signature strings
# Signature simple_syntax
# Signature semantics
# Lexicon RC_ty (semantics --> ty_n)
# Lexicon CVG_syntax (syntax --> simple_syntax)
# Lexicon CVG_strings (simple_syntax --> strings)
# Lexicon CVG_semantics (syntax --> semantics)
# Lexicon CVG_phonology (syntax --> strings)
# we require to give the translation of the term:type pair occurring
# after the "analyse" by all the lexicons specified before the
# "analyse" command.
......
......@@ -483,7 +483,7 @@ sig_entries :
with
| Error.Error e ->
let () = Printf.fprintf stderr "Error: %s\n%!" (Error.error_msg e filename) in
env
env
let parse_term ?(offset="") ?(output=false) t sg =
let lexbuf = Lexing.from_string t in
......
......@@ -14,7 +14,6 @@
(* module Data_parser = Parser.Make(E)*)
module F = Functions.Make(E)
let echo s = Printf.printf "%s\n%!" s
}
......@@ -22,7 +21,10 @@
{
open Dyp
let local_data = (E.empty,fun _ -> failwith "Bug: Not yet defined")
let global_data = false
let global_data = false,true
let echo (_,b) s = if b then Printf.printf "%s\n%!" s else ()
}
......@@ -61,8 +63,6 @@ CREATE_HELP
zzcommands :
| EOII @{let e,f = dyp.last_local_data in
(* let () = Printf.printf "End of parsing, getting:\n%!" in
let () = F.list e in *)
(e,[Local_data (e,f)])}
| command[c] ...@{let e,f = (dyp.last_local_data) in
let e' =
......@@ -70,26 +70,26 @@ CREATE_HELP
c e
with
| F.Not_yet_implemented s-> raise (Scripting_errors.Error (Scripting_errors.Not_yet_implemented s,(Lexing.dummy_pos,Lexing.dummy_pos))) in
let () = if dyp.global_data then ignore(read_line()) else () in
let () = if fst dyp.global_data then ignore(read_line()) else () in
e',[Local_data (e',f)]}
zzcommands {fst dyp.last_local_data}
zzcommands @{let e,f = (dyp.last_local_data) in e,[Local_data (e,f)]}
command:
| WAIT SEMICOLONN[l] @{(fun e -> let () = echo l in let () = F.wait () in e),[Global_data true]}
| DONT WAIT SEMICOLONN[l] @{(fun e -> let () = echo l in let () = F.dont_wait () in e),[Global_data false]}
| LOAD_DATA[(s,loc,l)] {fun e -> let () = echo l in F.load F.Data s e}
| LOAD_SCRIPT[(s,loc,l)] {fun e -> let () = echo l in
| WAIT SEMICOLONN[l] @{let g_d1,g_d2 = dyp.global_data in (fun e -> let () = echo dyp.global_data l in let () = F.wait () in e),[Global_data (true,g_d2)]}
| DONT WAIT SEMICOLONN[l] @{let g_d1,g_d2 = dyp.global_data in (fun e -> let () = echo dyp.global_data l in let () = F.dont_wait () in e),[Global_data (false,g_d2)]}
| LOAD_DATA[(s,loc,l)] {fun e -> let () = echo dyp.global_data l in F.load F.Data s e}
| LOAD_SCRIPT[(s,loc,l)] {fun e -> let () = echo dyp.global_data l in
let new_env = F.load (F.Script (snd dyp.last_local_data)) s e in
let () = Printf.printf "load script performed, getting:\n%!" in
let () = F.list new_env in
(* let () = Printf.printf "load script performed, getting:\n%!" in
let () = F.list new_env in *)
new_env}
| LIST SEMICOLONN[l] {fun e -> let () = echo l in let () = F.list e in e}
| SELECT IDENTT[(name,loc)] SEMICOLONN[l] {fun e -> let () = echo l in F.select name loc e}
| UNSELECT SEMICOLONN[l] { let () = echo l in F.unselect}
| TRACE SEMICOLONN[l] { let () = echo l in fun e -> let () = F.trace () in e}
| DONT TRACE SEMICOLONN[l] { let () = echo l in fun e -> let () = F.dont_trace () in e}
| optional_ident[name] PRINT[p] SEMICOLONN[l] { let () = echo l in fun e ->
| LIST SEMICOLONN[l] {fun e -> let () = echo dyp.global_data l in let () = F.list e in e}
| SELECT IDENTT[(name,loc)] SEMICOLONN[l] {fun e -> let () = echo dyp.global_data l in F.select name loc e}
| UNSELECT SEMICOLONN[l] { let () = echo dyp.global_data l in F.unselect}
| TRACE SEMICOLONN[l] { let () = echo dyp.global_data l in fun e -> let () = F.trace () in e}
| DONT TRACE SEMICOLONN[l] { let () = echo dyp.global_data l in fun e -> let () = F.dont_trace () in e}
| optional_ident[name] PRINT[p] SEMICOLONN[l] { let () = echo dyp.global_data l in fun e ->
let loc =
match name with
| None -> p
......@@ -97,21 +97,21 @@ CREATE_HELP
match name with
| None -> let () = F.print e loc in e
| Some (n,l) -> let () = F.print ~name:n e loc in e}
| optional_idents[names] ANALYSE[(t,l,line)] { let () = echo line in fun e ->
| optional_idents[names] ANALYSE[(t,l,line)] { let () = echo dyp.global_data line in fun e ->
match names with
| [] -> let () = F.analyse e t l in e
| _ -> let () = F.analyse ~names e t l in e}
| optional_idents[names] ADD[(t,l,line)] { let () = echo line in fun e ->
| optional_idents[names] ADD[(t,l,line)] { let () = echo dyp.global_data line in fun e ->
match names with
| [] -> F.add e t l
| _ -> F.add ~names e t l}
| COMPOSE IDENTT[n1] IDENTT [n2] AS IDENTT[n3] SEMICOLONN[l] { let () = echo l in fun e -> F.compose n1 n2 n3 e}
| HELP SEMICOLONN[l] {let () = echo l in fun e -> let () = F.help (F.Help None) in e}
| all_commands[c] HELP SEMICOLONN[l] {let () = echo l in fun e -> let () = F.help (F.Help (Some c)) in e}
| LOAD_HELP SEMICOLONN[l] {let () = echo l in fun e -> let () = F.help (F.Help (Some F.Load)) in e}
| CREATE_SIG IDENTT[n] SEMICOLONN[l] {let () = echo l in fun e -> F.create_sig n e}
| CREATE_LEX IDENTT[n] IDENTT[n1] IDENTT[n2] SEMICOLONN[l] {let () = echo l in fun e -> F.create_lex ~abs:n1 ~obj:n2 n e}
| optional_idents[names] SAVE[(filename,l,line)] { let () = echo line in fun e ->
| COMPOSE IDENTT[n1] IDENTT [n2] AS IDENTT[n3] SEMICOLONN[l] { let () = echo dyp.global_data l in fun e -> F.compose n1 n2 n3 e}
| HELP SEMICOLONN[l] {let () = echo dyp.global_data l in fun e -> let () = F.help (F.Help None) in e}
| all_commands[c] HELP SEMICOLONN[l] {let () = echo dyp.global_data l in fun e -> let () = F.help (F.Help (Some c)) in e}
| LOAD_HELP SEMICOLONN[l] {let () = echo dyp.global_data l in fun e -> let () = F.help (F.Help (Some F.Load)) in e}
| CREATE_SIG IDENTT[n] SEMICOLONN[l] {let () = echo dyp.global_data l in fun e -> F.create_sig n e}
| CREATE_LEX IDENTT[n] IDENTT[n1] IDENTT[n2] SEMICOLONN[l] {let () = echo dyp.global_data l in fun e -> F.create_lex ~abs:n1 ~obj:n2 n e}
| optional_idents[names] SAVE[(filename,l,line)] { let () = echo dyp.global_data line in fun e ->
match names with
| [] -> let () = F.save filename e l in e
| _ -> let () = F.save ~names filename e l in e}
......@@ -144,13 +144,13 @@ CREATE_HELP
{
let rec parse_file filename env =
let rec parse_file ?(verbose=true) filename env =
let in_ch = try open_in filename with | Sys_error s -> raise (Error.Error (Error.System_error s)) in
let lexbuf = Lexing.from_channel in_ch in
let () = Printf.printf "Parsing script file \"%s\"...\n%!" filename in
try
let new_env=
try (fst (List.hd (zzcommands ~global_data:(F.should_wait ()) ~local_data:(env,parse_file) Script_lexer.lexer lexbuf))) with
try (fst (List.hd (zzcommands ~global_data:(F.should_wait (),verbose) ~local_data:(env,parse_file ~verbose) Script_lexer.lexer lexbuf))) with
| Dyp.Syntax_error -> raise (Error.dyp_error lexbuf filename) in
let () = Printf.printf "Done.\n%!" in
(* let () = Printf.printf "I parsed the script file and now:\n%!" in
......@@ -190,12 +190,12 @@ CREATE_HELP
let parse_entry env =
let parse_entry ?(verbose=true) env =
let in_str = bufferize () in
let lexbuf = Lexing.from_string in_str in
let new_env=
try
try (fst (List.hd (zzcommands ~global_data:false ~local_data:(env,parse_file) Script_lexer.lexer lexbuf))) with
try (fst (List.hd (zzcommands ~global_data:(false,verbose) ~local_data:(env,parse_file ~verbose) Script_lexer.lexer lexbuf))) with
| Dyp.Syntax_error -> raise (Error.dyp_error lexbuf "stdin")
with
| Failure "lexing: empty token" -> env
......@@ -224,9 +224,9 @@ end}
(* type token = Script_lexer.token*)
val parse_file : string -> E.t -> E.t
val parse_file : ?verbose:bool -> string -> E.t -> E.t
val parse_entry : E.t -> E.t
val parse_entry : ?verbose:bool -> E.t -> E.t
}
%mli{end}
......@@ -16,7 +16,7 @@ let welcome_msg =
let env = ref E.empty
let anon_fun s = env := P.parse_file s !env
let anon_fun s = env := P.parse_file ~verbose:false s !env
let _ =
let () = Arg.parse [] anon_fun "toto" in
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment