Commit bbf18747 authored by bguillaum's avatar bguillaum

- Param value are items and can be used in concatenation with string or features

- ambiguity is handled when there is only one "output" variable




git-svn-id: svn+ssh://scm.gforge.inria.fr/svn/semagramme/libcaml-grew/trunk@6765 7838e531-6607-4d57-9587-6c381814729c
parent 0de7ad1e
......@@ -28,7 +28,7 @@ INFO = @INFO@
OCAMLFIND_DIR=`ocamlfind printconf destdir`
VERSION = 0.9.6
VERSION = 0.9.7
cleanup:
rm -rf *.cmo *.cmx *.cmi *.annot *.o *.*~
......
......@@ -65,6 +65,7 @@ module Ast = struct
type concat_item =
| Qfn_item of (string * string)
| String_item of string
| Param_item of string
type u_command =
| Del_edge_expl of (Id.name * Id.name * string)
......@@ -79,7 +80,6 @@ module Ast = struct
| Del_feat of qfn
| Update_feat of qfn * concat_item list
| Param_feat of qfn * string
type command = u_command * Loc.t
......@@ -145,6 +145,7 @@ module AST_HTML = struct
let string_of_concat_item = function
| Ast.Qfn_item (n,f) -> sprintf "%s.%s" n f
| Ast.String_item s -> sprintf "\"%s\"" s
| Ast.Param_item var -> sprintf "@%s" var
let string_of_qfn (node, feat_name) = sprintf "%s.%s" node feat_name
......@@ -163,8 +164,7 @@ module AST_HTML = struct
| Ast.Del_node n -> bprintf buff "del_node %s" n
| Ast.Update_feat (qfn,item_list) -> bprintf buff "%s = %s" (string_of_qfn qfn) (List_.to_string string_of_concat_item " + " item_list)
| Ast.Del_feat qfn -> bprintf buff "del_feat %s" (string_of_qfn qfn)
| Ast.Param_feat (qfn, var) -> bprintf buff "param_feat %s = %s" (string_of_qfn qfn) var)
;
);
if li_html then bprintf buff "</li>\n" else bprintf buff ";\n"
let to_html_commands_pretty = function
......
......@@ -59,6 +59,7 @@ module Ast : sig
type concat_item =
| Qfn_item of (string * string)
| String_item of string
| Param_item of string
type u_command =
| Del_edge_expl of (Id.name * Id.name * string)
......@@ -73,7 +74,6 @@ module Ast : sig
| Del_feat of qfn
| Update_feat of qfn * concat_item list
| Param_feat of qfn * string
type command = u_command * Loc.t
type rule = {
......
......@@ -17,6 +17,7 @@ module Command = struct
type item =
| Feat of (cnode * string)
| String of string
| Param of int
(* the command in pattern *)
type p =
......@@ -26,7 +27,6 @@ module Command = struct
| ADD_EDGE of (cnode * cnode * G_edge.t)
| DEL_FEAT of (cnode * string)
| UPDATE_FEAT of (cnode * string * item list)
| PARAM_FEAT of (cnode * string * int)
| NEW_NEIGHBOUR of (string * G_edge.t * pid)
| SHIFT_EDGE of (cnode * cnode)
| SHIFT_IN of (cnode * cnode)
......@@ -121,19 +121,14 @@ module Command = struct
let items = List.map
(function
| Ast.Qfn_item (node,feat_name) -> check_node loc node kni; Feat (get_pid node, feat_name)
| Ast.String_item s -> String s)
ast_items in
| Ast.String_item s -> String s
| Ast.Param_item var ->
match cmd_vars with
| None -> Error.build "Unknown command variable '%s'" var
| Some l ->
match List_.pos var l with
| Some index -> Param index
| None -> Error.build "Unknown command variable '%s'" var
) ast_items in
((UPDATE_FEAT (get_pid tar_node, tar_feat_name, items), loc), (kni, kei))
| (Ast.Param_feat ((node,feat_name), var), loc) ->
match cmd_vars with
| None -> Error.build "Unknown command variable '%s'" var
| Some l ->
match List_.pos var l with
| Some index -> ((PARAM_FEAT (get_pid node, feat_name, index), loc), (kni, kei))
| None -> Error.build "Unknown command variable '%s'" var
end
......@@ -13,6 +13,7 @@ module Command : sig
type item =
| Feat of (cnode * string)
| String of string
| Param of int
type p =
| DEL_NODE of cnode
......@@ -21,7 +22,6 @@ module Command : sig
| ADD_EDGE of (cnode * cnode * G_edge.t)
| DEL_FEAT of (cnode * string)
| UPDATE_FEAT of (cnode * string * item list)
| PARAM_FEAT of (cnode * string * int)
| NEW_NEIGHBOUR of (string * G_edge.t * pid)
| SHIFT_EDGE of (cnode * cnode)
| SHIFT_IN of (cnode * cnode)
......
......@@ -193,7 +193,7 @@ module P_fs = struct
| None -> Log.bug "[P_fs.compatible] Illegal parametrized pattern feature"; exit 2
| Some param ->
(match Lex_par.filter index atom param with
| None -> None
| None -> raise Fail
| Some new_param -> loop (Some new_param) (t_pat,t)
)
)
......
......@@ -412,9 +412,7 @@ module G_graph = struct
Some {se_graph with map = new_map}
| None -> None
(* FIXME: check consistency wrt the domain *)
let set_feat ?loc graph node_id feat_name new_value =
printf "===DEBUG=== loc:%s\n%!" (match loc with None -> "None" | Some l -> Loc.to_string l);
let node = Gid_map.find node_id graph.map in
let new_fs = G_fs.set_feat ?loc feat_name new_value (G_node.get_fs node) in
{graph with map = Gid_map.add node_id (G_node.set_fs node new_fs) graph.map}
......
......@@ -477,6 +477,10 @@ module Rule = struct
(function
| Command.Feat (cnode, feat_name) -> G_graph.Feat (node_find cnode, feat_name)
| Command.String s -> G_graph.String s
| Command.Param index ->
match matching.m_param with
| None -> Error.bug "Cannot apply a UPDATE_FEAT command without parameter"
| Some param -> G_graph.String (Lex_par.get_command_value index param)
) item_list in
let (new_graph, new_feature_value) =
......@@ -545,25 +549,6 @@ module Rule = struct
created_nodes
)
| Command.PARAM_FEAT (tar_cn, tar_feat_name, index) ->
match matching.m_param with
| None -> Error.bug "Cannot apply a PARAM_FEAT command without parameter"
| Some param ->
let feature_value = Lex_par.get_command_value index param in
let tar_gid = node_find tar_cn in
let new_graph =
G_graph.set_feat ~loc instance.Instance.graph tar_gid tar_feat_name feature_value in
(
{instance with
Instance.graph = new_graph;
commands = List_.sort_insert
(Command.H_UPDATE_FEAT (tar_gid,tar_feat_name,feature_value))
instance.Instance.commands
},
created_nodes
)
(** [apply_rule instance matching rule] returns a new instance after the application of the rule
[Command_execution_fail] is raised if some merge unification fails
*)
......@@ -691,7 +676,7 @@ module Rule = struct
(** normalize [t] according to the [rules]
* [t] is a raw graph
* info about the commands applied on [t] are kept
* Info about the commands applied on [t] are kept
*)
(* type: Instance.t -> t list -> Instance_set.t *)
......
......@@ -530,7 +530,11 @@ module Lex_par = struct
let get_command_value index = function
| [(_,one)] -> List.nth one index
| [] -> Error.bug "[Lex_par.get_command_value] empty parameter"
| l -> Error.run "Lexcial parameter are not functionnal"
| (_,[sing])::tail when index=0 ->
Printf.sprintf "%s/%s"
sing
(List_.to_string (function (_,[s]) -> s | _ -> Error.bug "[Lex_par.get_command_value] inconsistent param") "/" tail)
| l -> Error.run "Lexical parameter are not functionnal"
end
......
......@@ -472,15 +472,14 @@ command:
{ localize (Ast.New_neighbour (n1,n2,label)) }
| DEL_FEAT qfn = QFN
{ localize (Ast.Del_feat qfn) }
| qfn = QFN EQUAL p = CMD
{ localize (Ast.Param_feat (qfn, p)) }
| qfn = QFN EQUAL items = separated_nonempty_list (PLUS, concat_item)
{ localize (Ast.Update_feat (qfn, items)) }
concat_item:
| qfn = QFN { Ast.Qfn_item qfn }
| s = IDENT { Ast.String_item s }
| qfn = QFN { Ast.Qfn_item qfn }
| s = IDENT { Ast.String_item s }
| s = STRING { Ast.String_item s }
| p = CMD { Ast.Param_item p }
/*=============================================================================================*/
/* */
......
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