Commit 0b9fbfb8 authored by Bruno Guillaume's avatar Bruno Guillaume

Clean unused code (step 2)

parent 1a7e5282
......@@ -351,46 +351,6 @@ module Ast = struct
mod_dir: string; (* the directory where the module is defined (for lp file localisation) *)
}
type strat_def = (* /!\ The list must not be empty in the Seq constructor *)
| Ref of string (* reference to a module name or to another strategy *)
| Seq of strat_def list (* a sequence of strategies to apply one after the other *)
| Star of strat_def (* a strategy to apply iteratively *)
| Pick of strat_def (* pick one normal form a the given strategy; return 0 if nf *)
| Sequence of string list (* compatibility mode with old code *)
let rec strat_def_to_string = function
| Ref m -> m
| Seq l -> "(" ^ (String.concat "; " (List.map strat_def_to_string l)) ^ ")"
| Star s -> "(" ^ (strat_def_to_string s) ^")" ^ "*"
| Pick s -> "pick" ^ "(" ^(strat_def_to_string s)^")"
| Sequence names -> "{" ^ (String.concat ";" names) ^ "}"
(* invariant: Seq list and Plus list are not empty in the input and so not empty in the output *)
let rec strat_def_flatten = function
| Sequence l -> Sequence l
| Ref m -> Ref m
| Star s -> Star (strat_def_flatten s)
| Pick s -> Pick (strat_def_flatten s)
| Seq l ->
let fl = List.map strat_def_flatten l in
let rec loop = function
| [] -> []
| (Seq l) :: tail -> l @ (loop tail)
| x :: tail -> x :: (loop tail)
in Seq (loop fl)
type strategy = {
strat_name: string;
strat_def: strat_def;
strat_doc: string list;
strat_loc: Loc.t;
}
(** a GRS: graph rewriting system *)
type module_or_include =
| Modul of modul
| Includ of (string * Loc.t)
type feature_spec =
| Closed of feature_name * feature_atom list (* cat:V,N *)
| Open of feature_name (* phon, lemma, ... *)
......@@ -413,20 +373,6 @@ module Ast = struct
label_domain: (string * string list) list;
}
type domain_wi = Dom of domain | Dom_file of string
type grs_wi = {
domain_wi: domain_wi option;
modules_wi: module_or_include list;
strategies_wi: strategy list;
}
type grs = {
domain: domain option;
modules: modul list;
strategies: strategy list;
}
type gr = {
meta: string list;
nodes: node list;
......@@ -450,8 +396,6 @@ module Ast = struct
) gr.nodes gr.edges in
{ gr with nodes = new_nodes }
let empty_grs = { domain = None; modules = []; strategies= [] }
(* phrase structure tree *)
type pst =
| Leaf of (Loc.t * string) (* phon *)
......@@ -460,14 +404,9 @@ module Ast = struct
let rec word_list = function
| Leaf (_, p) -> [p]
| T (_,_,l) -> List.flatten (List.map word_list l)
end (* module Ast *)
(* ================================================================================================ *)
module New_ast = struct
type strat =
| Ref of Ast.node_ident (* reference to a rule name or to another strategy *)
| Ref of node_ident (* reference to a rule name or to another strategy *)
| Pick of strat (* pick one normal form a the given strategy; return 0 if nf *)
| Alt of strat list (* a set of strategies to apply in parallel *)
| Seq of strat list (* a sequence of strategies to apply one after the other *)
......@@ -478,11 +417,11 @@ module New_ast = struct
type decl =
| Conll_fields of string list
| Features of Ast.feature_spec list
| Features of feature_spec list
| Labels of (string * string list) list
| Package of (Loc.t * Ast.simple_ident * decl list)
| Rule of Ast.rule
| Strategy of (Loc.t * Ast.simple_ident * strat)
| Package of (Loc.t * simple_ident * decl list)
| Rule of rule
| Strategy of (Loc.t * simple_ident * strat)
| Import of string
| Include of string
......@@ -506,37 +445,7 @@ module New_ast = struct
| _ :: tail -> loop pref tail
in loop "" grs
(* conversion from old grs to new ones *)
let modul2package modul =
let decl_list = List.map (fun rule -> Rule rule) modul.Ast.rules in
Package (modul.Ast.mod_loc, modul.Ast.module_id, decl_list)
let convert_strat det_modules old_strat =
let new_strat_list =
match old_strat.Ast.strat_def with
| Ast.Sequence module_list ->
Seq (List.map
(fun name ->
if List.mem name det_modules
then Pick (Iter (Ref name))
else Iter (Ref name)
) module_list
)
| _ -> failwith "No translation of old strat ≠ Sequence" in
let strat_name = old_strat.Ast.strat_name in
let loc = old_strat.Ast.strat_loc in
Strategy (loc, strat_name, new_strat_list)
let convert old_grs =
let new_domain =
match old_grs.Ast.domain with
| None -> []
| Some { Ast.feature_domain; label_domain } -> [Features feature_domain; Labels label_domain] in
let packages = List.map modul2package old_grs.Ast.modules in
let det_modules = List.fold_left (fun acc modul -> if modul.Ast.deterministic then modul.Ast.module_id::acc else acc) [] old_grs.Ast.modules in
let new_strat_list = List.map (convert_strat det_modules) old_grs.Ast.strategies in
new_domain @ packages @ new_strat_list
end (* module New_ast *)
end (* module Ast *)
......
......@@ -188,19 +188,6 @@ module Ast : sig
rule_dir: string option; (* the real folder where the file is defined *)
}
type modul = {
module_id:Id.name;
rules: rule list;
deterministic: bool;
module_doc:string list;
mod_loc:Loc.t;
mod_dir: string; (* the directory where the module is defined (for lp file localisation) *)
}
type module_or_include =
| Modul of modul
| Includ of (string * Loc.t)
type feature_spec =
| Closed of feature_name * feature_atom list (* cat:V,N *)
| Open of feature_name (* phon, lemma, ... *)
......@@ -213,41 +200,6 @@ module Ast : sig
label_domain: (string * string list) list;
}
type domain_wi = Dom of domain | Dom_file of string
type strat_def = (* /!\ The list must not be empty in the Seq or Plus constructor *)
| Ref of string (* reference to a module name or to another strategy *)
| Seq of strat_def list (* a sequence of strategies to apply one after the other *)
| Star of strat_def (* a strategy to apply iteratively *)
| Pick of strat_def (* pick one normal form a the given strategy; return 0 if nf *)
| Sequence of string list (* compatibility mode with old code *)
val strat_def_to_string: strat_def -> string
val strat_def_flatten: strat_def -> strat_def
(* a strategy is given by its descrition in the grs file and the 4 fields: *)
type strategy = {
strat_name:string; (* a unique name of the stratgy *)
strat_def:strat_def; (* the definition itself *)
strat_doc:string list; (* lines of docs (if any in the GRS file) *)
strat_loc:Loc.t; (* the location of the [name] of the strategy *)
}
type grs_wi = {
domain_wi: domain_wi option;
modules_wi: module_or_include list;
strategies_wi: strategy list;
}
(* a GRS: graph rewriting system *)
type grs = {
domain: domain option;
modules: modul list;
strategies: strategy list;
}
val empty_grs: grs
type gr = {
meta: string list;
nodes: node list;
......@@ -260,13 +212,9 @@ module Ast : sig
| Leaf of (Loc.t * string) (* phon *)
| T of (Loc.t * string * pst list)
val word_list: pst -> string list
end (* module Ast *)
(* ================================================================================================ *)
module New_ast : sig
type strat =
| Ref of Ast.node_ident (* reference to a rule name or to another strategy *)
| Ref of node_ident (* reference to a rule name or to another strategy *)
| Pick of strat (* pick one normal form a the given strategy; return 0 if nf *)
| Alt of strat list (* a set of strategies to apply in parallel *)
| Seq of strat list (* a sequence of strategies to apply one after the other *)
......@@ -277,11 +225,11 @@ module New_ast : sig
type decl =
| Conll_fields of string list
| Features of Ast.feature_spec list
| Features of feature_spec list
| Labels of (string * string list) list
| Package of (Loc.t * Ast.simple_ident * decl list)
| Rule of Ast.rule
| Strategy of (Loc.t * Ast.simple_ident * strat)
| Package of (Loc.t * simple_ident * decl list)
| Rule of rule
| Strategy of (Loc.t * simple_ident * strat)
| Import of string
| Include of string
......@@ -291,5 +239,4 @@ module New_ast : sig
val strat_list: grs -> string list
val convert: Ast.grs -> grs
end (* module New_ast *)
end (* module Ast *)
This diff is collapsed.
......@@ -171,7 +171,6 @@ and standard target = parse
| "include" { INCL }
| "import" { IMPORT }
| "domain" { DOMAIN }
| "features" { FEATURES }
| "conll_fields" { Log.fwarning "\"conll_fields\" is deprecated, ignored"; DUMMY }
| "from" { FROM }
......@@ -193,14 +192,10 @@ and standard target = parse
| "add_node" { ADD_NODE }
| "del_feat" { DEL_FEAT }
| "module" { MODULE }
| "package" { PACKAGE }
| "confluent" { Log.fwarning "%s \"confluent\" is deprecated, please use \"deterministic\" instead" (Global.loc_string ()); DETERMINISTIC }
| "deterministic" { DETERMINISTIC }
| "rule" { RULE }
| "strat" { STRAT }
| "lex_rule" { Log.fwarning "%s \"lex_rule\" is deprecated, please use \"rule\" instead" (Global.loc_string ()); RULE }
| "sequences" { SEQUENCES }
| "Pick" { PICK }
| "Alt" { ALT }
......
......@@ -25,28 +25,6 @@ let parse_handle fct_name fct lexbuf =
module Loader = struct
(* ------------------------------------------------------------------------------------------*)
let parse_file_to_grs_wi file =
try
Global.new_file file;
let in_ch = open_in file in
let lexbuf = Lexing.from_channel in_ch in
let grs = parse_handle "[Grew_loader.Loader.parse_file_to_grs_wi]" (Grew_parser.grs_wi Grew_lexer.global) lexbuf in
close_in in_ch;
grs
with Sys_error msg -> Error.parse ~loc:(Loc.file file) "[Grew_loader.Loader.parse_file_to_grs_wi] %s" msg
(* ------------------------------------------------------------------------------------------*)
let parse_file_to_module_list file =
try
Global.new_file file;
let in_ch = open_in file in
let lexbuf = Lexing.from_channel in_ch in
let module_list = parse_handle "[Grew_loader.Loader.parse_file_to_module_list]" (Grew_parser.included Grew_lexer.global) lexbuf in
close_in in_ch;
module_list
with Sys_error msg -> Error.parse ~loc:(Loc.file file) "[Grew_loader.Loader.parse_file_to_module_list] %s" msg
(* ------------------------------------------------------------------------------------------*)
let domain file =
try
......@@ -58,65 +36,16 @@ module Loader = struct
gr
with Sys_error msg -> Error.parse ~loc:(Loc.file file) "[Grew_loader.Loader.domain] %s" msg
(* ------------------------------------------------------------------------------------------*)
(**
[parse_string file] where [file] is a file following the grew syntax
@param file the file to parse
@return a syntactic tree of the parsed file
*)
let grs main_file =
let real_dir =
match (Unix.lstat main_file).Unix.st_kind with
| Unix.S_LNK -> Filename.dirname (Unix.readlink main_file)
| _ -> Filename.dirname main_file in
let unlink file = Filename.concat real_dir (Filename.basename file) in
let grs_wi = parse_file_to_grs_wi (unlink main_file) in
let domain = match grs_wi.Ast.domain_wi with
| None -> None
| Some (Ast.Dom d) -> Some d
| Some (Ast.Dom_file file) -> Some (domain (unlink file)) in
let rec flatten_modules current_file = function
| [] -> []
| Ast.Modul m :: tail ->
let real_dir = Filename.dirname current_file in
{m with
Ast.mod_dir = real_dir;
rules = List.map (fun r -> {r with Ast.rule_dir = Some real_dir}) m.Ast.rules
}
:: (flatten_modules current_file tail)
| Ast.Includ (inc_file,loc) :: tail ->
let sub_file =
if Filename.is_relative inc_file
then Filename.concat (Filename.dirname current_file) inc_file
else inc_file in
(flatten_modules sub_file (parse_file_to_module_list sub_file))
@ (flatten_modules current_file tail) in
{
Ast.domain = domain;
Ast.modules = flatten_modules main_file grs_wi.Ast.modules_wi;
Ast.strategies = grs_wi.Ast.strategies_wi;
}
let rec check_duplicate_id id = function
| [] -> None
| New_ast.Rule r :: _ when r.Ast.rule_id = id -> Some r.Ast.rule_loc
| New_ast.Package (loc, name, _) :: _ when name = id -> Some loc
| New_ast.Strategy (loc, name, _) :: _ when name = id -> Some loc
| Ast.Rule r :: _ when r.Ast.rule_id = id -> Some r.Ast.rule_loc
| Ast.Package (loc, name, _) :: _ when name = id -> Some loc
| Ast.Strategy (loc, name, _) :: _ when name = id -> Some loc
| _ -> None
let rec check_grs = function
| [] -> ()
| New_ast.Rule r :: tail ->
| Ast.Rule r :: tail ->
begin
match check_duplicate_id r.Ast.rule_id tail with
| None -> ()
......@@ -124,7 +53,7 @@ module Loader = struct
r.Ast.rule_id (Loc.to_string r.Ast.rule_loc) (Loc.to_string loc)
end;
check_grs tail
| New_ast.Strategy (loc, name, _) :: tail ->
| Ast.Strategy (loc, name, _) :: tail ->
begin
match check_duplicate_id name tail with
| None -> ()
......@@ -132,7 +61,7 @@ module Loader = struct
name (Loc.to_string loc) (Loc.to_string loc2)
end;
check_grs tail
| New_ast.Package (loc, name, sub) :: tail ->
| Ast.Package (loc, name, sub) :: tail ->
begin
match check_duplicate_id name tail with
| None -> ()
......@@ -161,25 +90,25 @@ module Loader = struct
let rec unfold_new_grs dir top new_ast_grs =
List.fold_left
(fun acc decl -> match decl with
| New_ast.Import filename ->
| Ast.Import filename ->
let real_file = Filename.concat dir filename in
let pack_name = match CCString.chop_suffix ~suf:".grs" filename with
| Some x -> x
| None -> Error.build "Imported file must have the \".grs\" file extension" in
let sub = loc_new_grs real_file in
let unfolded_sub = unfold_new_grs (real_dir real_file) false sub in
New_ast.Package (Loc.file filename, pack_name, unfolded_sub) :: acc
| New_ast.Include filename ->
Ast.Package (Loc.file filename, pack_name, unfolded_sub) :: acc
| Ast.Include filename ->
let real_file = Filename.concat dir filename in
let sub = loc_new_grs real_file in
let unfolded_sub = unfold_new_grs (real_dir real_file) top sub in
unfolded_sub @ acc
| New_ast.Features _ when not top -> Error.build "Non top features declaration"
| New_ast.Labels _ when not top -> Error.build "Non top labels declaration"
| New_ast.Package (loc, name, decls) ->
New_ast.Package (loc, name, unfold_new_grs dir top decls) :: acc
| New_ast.Rule ast_rule ->
New_ast.Rule {ast_rule with Ast.rule_dir = Some dir} :: acc
| Ast.Features _ when not top -> Error.build "Non top features declaration"
| Ast.Labels _ when not top -> Error.build "Non top labels declaration"
| Ast.Package (loc, name, decls) ->
Ast.Package (loc, name, unfold_new_grs dir top decls) :: acc
| Ast.Rule ast_rule ->
Ast.Rule {ast_rule with Ast.rule_dir = Some dir} :: acc
| x -> x :: acc
) [] new_ast_grs
......
......@@ -16,9 +16,8 @@ open Grew_ast
module Loader: sig
val domain: string -> Ast.domain
val grs: string -> Ast.grs
val new_grs: string -> New_ast.grs
val new_grs: string -> Ast.grs
val gr: string -> Ast.gr
......@@ -34,5 +33,5 @@ module Parser : sig
val pattern: string -> Ast.pattern
val strategy: string -> New_ast.strat
val strategy: string -> Ast.strat
end
......@@ -72,7 +72,6 @@ let localize t = (t,get_loc ())
%token ARROW_LEFT_NEG /* =[^ */
%token ARROW_RIGHT /* ]=> */
%token DOMAIN /* domain */
%token INCL /* include */
%token IMPORT /* import */
%token FEATURES /* features */
......@@ -81,12 +80,9 @@ let localize t = (t,get_loc ())
%token PATTERN /* pattern */
%token WITHOUT /* without */
%token COMMANDS /* commands */
%token MODULE /* module */
%token STRAT /* strat */
%token PACKAGE /* package */
%token DETERMINISTIC /* deterministic (or deprecated confluent) */
%token RULE /* rule */
%token SEQUENCES /* sequences */
%token GRAPH /* graph */
%token DEL_EDGE /* del_edge */
......@@ -122,14 +118,12 @@ let localize t = (t,get_loc ())
%token EOF /* end of file */
%start <Grew_ast.Ast.grs_wi> grs_wi
%start <Grew_ast.Ast.gr> gr
%start <Grew_ast.Ast.module_or_include list> included
%start <Grew_ast.Ast.pattern> pattern
%start <Grew_ast.Ast.domain> domain
%start <Grew_ast.New_ast.grs> new_grs
%start <Grew_ast.New_ast.strat> strat_alone
%start <Grew_ast.Ast.grs> new_grs
%start <Grew_ast.Ast.strat> strat_alone
/* parsing of the string representation of the constituent representation of Sequoia */
/* EX: "( (SENT (NP (NC Amélioration) (PP (P de) (NP (DET la) (NC sécurité))))))" */
......@@ -237,35 +231,6 @@ domain:
}
}
/*=============================================================================================*/
/* GREW GRAPH REWRITING SYSTEM */
/*=============================================================================================*/
grs_wi:
| d=option(domain) m=module_or_include_list s=option(sequences) EOF
{
{ Ast.domain_wi=(match d with Some dom -> Some (Ast.Dom dom) | None -> None);
modules_wi=m;
strategies_wi=match s with Some seq -> seq | None -> [];
}
}
| DOMAIN file=STRING m=module_or_include_list s=option(sequences) EOF
{
{ Ast.domain_wi= Some (Ast.Dom_file file);
modules_wi=m;
strategies_wi=match s with Some seq -> seq | None -> [];
}
}
module_or_include_list:
| x=list(module_or_include) { x }
module_or_include:
| m=grew_module { Ast.Modul m }
| INCL sub=subfile SEMIC { Ast.Includ sub }
subfile:
| f=STRING { localize f }
/*=============================================================================================*/
/* FEATURES DOMAIN DEFINITION */
/*=============================================================================================*/
......@@ -311,30 +276,9 @@ display:
| dis=AROBAS_ID { dis }
| col=COLOR { col }
/*=============================================================================================*/
/* MODULE DEFINITION */
/*=============================================================================================*/
included:
| x=list(module_or_include) EOF { x }
grew_module:
| doc=option(COMMENT) MODULE det=boption(DETERMINISTIC) id_loc=simple_id_with_loc LACC l=option(labels) r=rules RACC
{
{ Ast.module_id = fst id_loc;
rules = r;
deterministic = det;
module_doc = (match doc with Some d -> d | None -> []);
mod_loc = snd id_loc;
mod_dir = "";
}
}
/*=============================================================================================*/
/* RULES DEFINITION */
/*=============================================================================================*/
rules:
| r = list(rule) { r }
rule:
| doc=option(COMMENT) RULE id_loc=simple_id_with_loc file_lexicons = option(external_lexicons) LACC p=pos_item n=list(neg_item) cmds=commands RACC final_lexicons=list(final_lexicon)
{
......@@ -724,23 +668,6 @@ concat_item:
| f=FLOAT { Ast.String_item (Printf.sprintf "%g" f) }
/*=============================================================================================*/
/* SEQUENCE DEFINITION */
/*=============================================================================================*/
sequences:
| SEQUENCES seq=delimited(LACC,list(sequence),RACC) { seq }
sequence:
/* seq_name { ant; p7_to_p7p-mc} */
| doc = option(COMMENT) id_loc=simple_id_with_loc mod_names=delimited(LACC,separated_list_final_opt(SEMIC,simple_id),RACC)
{ let (strat_name,strat_loc) = id_loc in
{
Ast.strat_name;
strat_def = Ast.Sequence mod_names;
strat_doc = begin match doc with Some d -> d | None -> [] end;
strat_loc;
}
}
/*=============================================================================================*/
/* ISOLATED PATTERN (grep mode) */
......@@ -776,24 +703,24 @@ new_grs:
| decls = list(decl) EOF { decls }
decl:
| f=feature_group { New_ast.Features f }
| l=labels { New_ast.Labels l }
| r=rule { New_ast.Rule r }
| IMPORT f=STRING { New_ast.Import f }
| INCL f=STRING { New_ast.Include f }
| PACKAGE id_loc=simple_id_with_loc LACC l=list(decl) RACC { New_ast.Package (snd id_loc, fst id_loc, l) }
| STRAT id_loc=simple_id_with_loc LACC d = strat_desc RACC { New_ast.Strategy (snd id_loc, fst id_loc, d) }
| f=feature_group { Ast.Features f }
| l=labels { Ast.Labels l }
| r=rule { Ast.Rule r }
| IMPORT f=STRING { Ast.Import f }
| INCL f=STRING { Ast.Include f }
| PACKAGE id_loc=simple_id_with_loc LACC l=list(decl) RACC { Ast.Package (snd id_loc, fst id_loc, l) }
| STRAT id_loc=simple_id_with_loc LACC d = strat_desc RACC { Ast.Strategy (snd id_loc, fst id_loc, d) }
strat_desc:
| id = node_id { New_ast.Ref id }
| PICK LPAREN s=strat_desc RPAREN { New_ast.Pick s }
| ALT LPAREN sl=separated_list_final_opt(COMA,strat_desc) RPAREN { New_ast.Alt sl }
| SEQ LPAREN sl=separated_list_final_opt(COMA,strat_desc) RPAREN { New_ast.Seq sl }
| ITER LPAREN s=strat_desc RPAREN { New_ast.Iter s }
| IF LPAREN s1=strat_desc COMA s2=strat_desc COMA s3=strat_desc RPAREN { New_ast.If (s1,s2,s3) }
| TRY LPAREN s=strat_desc RPAREN { New_ast.Try s }
| ONF LPAREN s=strat_desc RPAREN { New_ast.Onf s }
| EMPTY { New_ast.Seq [] }
| id = node_id { Ast.Ref id }
| PICK LPAREN s=strat_desc RPAREN { Ast.Pick s }
| ALT LPAREN sl=separated_list_final_opt(COMA,strat_desc) RPAREN { Ast.Alt sl }
| SEQ LPAREN sl=separated_list_final_opt(COMA,strat_desc) RPAREN { Ast.Seq sl }
| ITER LPAREN s=strat_desc RPAREN { Ast.Iter s }
| IF LPAREN s1=strat_desc COMA s2=strat_desc COMA s3=strat_desc RPAREN { Ast.If (s1,s2,s3) }
| TRY LPAREN s=strat_desc RPAREN { Ast.Try s }
| ONF LPAREN s=strat_desc RPAREN { Ast.Onf s }
| EMPTY { Ast.Seq [] }
strat_alone:
| s = strat_desc EOF { s }
......
......@@ -239,7 +239,7 @@ module Graph = struct
end
(* ==================================================================================================== *)
(** {2 New Graph Rewriting System} *)
(** {2 Graph Rewriting System} *)
(* ==================================================================================================== *)
module Grs = struct
type t = Grew_grs.Grs.t
......
......@@ -114,7 +114,7 @@ module Graph : sig
end
(* ==================================================================================================== *)
(** {2 New Graph Rewriting System} *)
(** {2 Graph Rewriting System} *)
(* ==================================================================================================== *)
module Grs : sig
type t
......
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