Commit 5c8f674c authored by bguillaum's avatar bguillaum

add syntax for new pattern items:

N.cat = NOUN
N.lemma = “être”
N.pos = 10

git-svn-id: svn+ssh://scm.gforge.inria.fr/svn/semagramme/libcaml-grew/trunk@9078 7838e531-6607-4d57-9587-6c381814729c
parent f873569b
......@@ -134,7 +134,13 @@ module Ast = struct
| Feature_diseq of feature_ident * feature_ident
| Feature_ineq of ineq * feature_ident * feature_ident
| Feature_ineq_cst of ineq * feature_ident * float
| Feature_float of feature_ident * float
| Feature_diff_float of feature_ident * float
| Feature_re of feature_ident * string
| Feature_cst of feature_ident * string
| Feature_diff_cst of feature_ident * string
| Prec of Id.name * Id.name
| Lprec of Id.name * Id.name
type const = u_const * Loc.t
......@@ -175,6 +181,10 @@ module Ast = struct
|> (add_implicit_node loc aux name1)
|> (add_implicit_node loc aux name2)
| Feature_ineq_cst (_, (name,_), _)
| Feature_cst ((name,_), _)
| Feature_diff_cst ((name,_), _)
| Feature_float ((name,_), _)
| Feature_diff_float ((name,_), _)
| Feature_re ((name,_), _) ->
acc
|> (add_implicit_node loc aux name)
......
......@@ -97,10 +97,15 @@ module Ast : sig
| Feature_diseq of feature_ident * feature_ident
| Feature_ineq of ineq * feature_ident * feature_ident
| Feature_ineq_cst of ineq * feature_ident * float
| Feature_float of feature_ident * float
| Feature_diff_float of feature_ident * float
| Feature_re of feature_ident * string
| Feature_cst of feature_ident * string
| Feature_diff_cst of feature_ident * string
| Prec of Id.name * Id.name
| Lprec of Id.name * Id.name
type const = u_const * Loc.t
type basic = {
......
......@@ -107,6 +107,17 @@ module Html_doc = struct
bprintf buff "%s %s %s" (Ast.dump_feature_ident feat_id_l) (Ast.string_of_ineq ineq) (Ast.dump_feature_ident feat_id_r)
| Ast.Feature_ineq_cst (ineq, feat_id_l, constant) ->
bprintf buff "%s %s %f" (Ast.dump_feature_ident feat_id_l) (Ast.string_of_ineq ineq) constant
| Ast.Feature_cst (feat_id_l, value) ->
bprintf buff "%s = \"%s\"" (Ast.dump_feature_ident feat_id_l) value;
| Ast.Feature_diff_cst (feat_id_l, value) ->
bprintf buff "%s ≠ \"%s\"" (Ast.dump_feature_ident feat_id_l) value;
| Ast.Feature_float (feat_id_l, value) ->
bprintf buff "%s = %g" (Ast.dump_feature_ident feat_id_l) value;
| Ast.Feature_diff_float (feat_id_l, value) ->
bprintf buff "%s ≠ %g" (Ast.dump_feature_ident feat_id_l) value;
| Ast.Feature_re (feat_id, regexp) ->
bprintf buff "%s == \"%s\"" (Ast.dump_feature_ident feat_id) regexp
| Ast.Prec (id1, id2) ->
......
......@@ -477,13 +477,40 @@ pat_edge_or_const:
| STAR labels=delimited(LTR_EDGE_LEFT_NEG,separated_nonempty_list(PIPE,pattern_label_ident),LTR_EDGE_RIGHT) n2_loc=simple_id_with_loc
{ let (n2,loc) = n2_loc in Pat_const (Ast.Cst_in (n2,Ast.Neg_list labels), loc) }
(* "X.cat = Y.cat" *)
| feat_id1_loc=feature_ident_with_loc EQUAL feat_id2=feature_ident
{ let (feat_id1,loc)=feat_id1_loc in Pat_const (Ast.Feature_eq (feat_id1, feat_id2), loc) }
(* X.cat = Y.cat *)
(* X.cat = value *)
| feat_id1_loc=feature_ident_with_loc EQUAL rhs=ID
{ let (feat_id1,loc)=feat_id1_loc in
match Ast.parse_simple_or_feature_ident rhs with
| (node_id, Some feat_name) -> Pat_const (Ast.Feature_eq (feat_id1, (node_id,feat_name)), loc)
| (value, None) -> Pat_const (Ast.Feature_cst (feat_id1, value), loc)
}
(* X.cat = "value" *)
| feat_id1_loc=feature_ident_with_loc EQUAL rhs=STRING
{ let (feat_id1,loc)=feat_id1_loc in Pat_const (Ast.Feature_cst (feat_id1, rhs), loc) }
(* X.cat = 12.34 *)
| feat_id1_loc=feature_ident_with_loc EQUAL rhs=FLOAT
{ let (feat_id1,loc)=feat_id1_loc in Pat_const (Ast.Feature_float (feat_id1, rhs), loc) }
(* X.cat <> Y.cat *)
(* X.cat <> value *)
| feat_id1_loc=feature_ident_with_loc DISEQUAL rhs=ID
{ let (feat_id1,loc)=feat_id1_loc in
match Ast.parse_simple_or_feature_ident rhs with
| (node_id, Some feat_name) -> Pat_const (Ast.Feature_diseq (feat_id1, (node_id,feat_name)), loc)
| (value, None) -> Pat_const (Ast.Feature_diff_cst (feat_id1, value), loc)
}
(* X.cat <> "value" *)
| feat_id1_loc=feature_ident_with_loc DISEQUAL rhs=STRING
{ let (feat_id1,loc)=feat_id1_loc in Pat_const (Ast.Feature_diff_cst (feat_id1, rhs), loc) }
(* X.cat <> 12.34 *)
| feat_id1_loc=feature_ident_with_loc DISEQUAL rhs=FLOAT
{ let (feat_id1,loc)=feat_id1_loc in Pat_const (Ast.Feature_diff_float (feat_id1, rhs), loc) }
(* "X.cat <> Y.cat" *)
| feat_id1_loc=feature_ident_with_loc DISEQUAL feat_id2=feature_ident
{ let (feat_id1,loc)=feat_id1_loc in Pat_const (Ast.Feature_diseq (feat_id1, feat_id2), loc) }
(* "X.cat = re"regexp" " *)
| feat_id_loc=feature_ident_with_loc EQUAL regexp=REGEXP
......
......@@ -97,6 +97,12 @@ module Rule = struct
| Feature_eq of Pid.t * string * Pid.t * string
| Feature_diseq of Pid.t * string * Pid.t * string
| Feature_cst of Pid.t * string * string
| Feature_diff_cst of Pid.t * string * string
| Feature_float of Pid.t * string * float
| Feature_diff_float of Pid.t * string * float
| Feature_re of Pid.t * string * string
| Feature_ineq of Ast.ineq * Pid.t * string * Pid.t * string
......@@ -138,6 +144,20 @@ module Rule = struct
Domain.check_feature_name ?domain ~loc feat_name;
Feature_re (pid_of_name loc node_name, feat_name, regexp)
| (Ast.Feature_cst ((node_name, feat_name), string), loc) ->
Domain.check_feature_name ?domain ~loc feat_name;
Feature_cst (pid_of_name loc node_name, feat_name, string)
| (Ast.Feature_diff_cst ((node_name, feat_name), string), loc) ->
Domain.check_feature_name ?domain ~loc feat_name;
Feature_diff_cst (pid_of_name loc node_name, feat_name, string)
| (Ast.Feature_float ((node_name, feat_name), float), loc) ->
Domain.check_feature_name ?domain ~loc feat_name;
Feature_float (pid_of_name loc node_name, feat_name, float)
| (Ast.Feature_diff_float ((node_name, feat_name), float), loc) ->
Domain.check_feature_name ?domain ~loc feat_name;
Feature_diff_float (pid_of_name loc node_name, feat_name, float)
| (Ast.Prec (id1, id2), loc) ->
Prec (pid_of_name loc id1, pid_of_name loc id2)
......@@ -203,6 +223,21 @@ module Rule = struct
Domain.check_feature_name ?domain ~loc feat_name;
Feature_re (pid_of_name loc node_name, feat_name, regexp)
| (Ast.Feature_cst ((node_name, feat_name), string), loc) ->
Domain.check_feature_name ?domain ~loc feat_name;
Feature_cst (pid_of_name loc node_name, feat_name, string)
| (Ast.Feature_diff_cst ((node_name, feat_name), string), loc) ->
Domain.check_feature_name ?domain ~loc feat_name;
Feature_diff_cst (pid_of_name loc node_name, feat_name, string)
| (Ast.Feature_float ((node_name, feat_name), float), loc) ->
Domain.check_feature_name ?domain ~loc feat_name;
Feature_float (pid_of_name loc node_name, feat_name, float)
| (Ast.Feature_diff_float ((node_name, feat_name), float), loc) ->
Domain.check_feature_name ?domain ~loc feat_name;
Feature_diff_float (pid_of_name loc node_name, feat_name, float)
| (Ast.Prec (id1, id2), loc) ->
Prec (pid_of_name loc id1, pid_of_name loc id2)
......@@ -543,6 +578,30 @@ module Rule = struct
| Some fv1, Some fv2 when fv1 = fv2 -> matching
| _ -> raise Fail
end
| Feature_cst (pid1, feat_name1, value) ->
begin
match get_string_feat pid1 feat_name1 with
| Some fv1 when fv1 = value -> matching
| _ -> raise Fail
end
| Feature_diff_cst (pid1, feat_name1, value) ->
begin
match get_string_feat pid1 feat_name1 with
| Some fv1 when fv1 <> value -> matching
| _ -> raise Fail
end
| Feature_float (pid1, feat_name1, float) ->
begin
match get_float_feat pid1 feat_name1 with
| Some fv1 when fv1 = float -> matching
| _ -> raise Fail
end
| Feature_diff_float (pid1, feat_name1, float) ->
begin
match get_float_feat pid1 feat_name1 with
| Some fv1 when fv1 <> float -> matching
| _ -> raise Fail
end
| Feature_diseq (pid1, feat_name1, pid2, feat_name2) ->
begin
match (get_string_feat pid1 feat_name1, get_string_feat pid2 feat_name2) with
......
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