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

Fix parsing of “lexicon.field” in patterns

parent fdcd70a4
......@@ -96,6 +96,8 @@ module Ast = struct
type feature_kind =
| Equality of feature_value list
| Disequality of feature_value list
| Equal_lex of string * string
| Disequal_lex of string * string
| Equal_param of string (* $ident *)
| Absent
......@@ -103,6 +105,8 @@ module Ast = struct
| Equality fv_list -> sprintf " = %s" (String.concat "|" fv_list)
| Disequality [] -> ""
| Disequality fv_list -> sprintf " <> %s" (String.concat "|" fv_list)
| Equal_lex (lex,fn) -> sprintf " = %s.%s" lex fn
| Disequal_lex (lex,fn) -> sprintf " <> %s.%s" lex fn
| Equal_param param -> sprintf " = $%s" param
| Absent -> " <> *"
......@@ -162,7 +166,6 @@ module Ast = struct
| Feature_ineq_cst of ineq * feature_ident * float
| Feature_eq_float of feature_ident * float
| Feature_diff_float of feature_ident * float
(* ambiguous case, context needed to make difference "N.cat = M.cat" VS "N.cat = lex.cat" *)
| Feature_eq_lex_or_fs of feature_ident * (string * string)
| Feature_diff_lex_or_fs of feature_ident * (string * string)
......
......@@ -60,6 +60,8 @@ module Ast : sig
type feature_kind =
| Equality of feature_value list
| Disequality of feature_value list
| Equal_lex of string * string
| Disequal_lex of string * string
| Equal_param of string (* $ident *)
| Absent
......
......@@ -78,6 +78,8 @@ module P_feature = struct
| Absent
| Equal of value list (* with Equal constr, the list MUST never be empty *)
| Different of value list
| Equal_lex of string * string
| Different_lex of string * string
(* NB: in the current version, |in_param| ≤ 1 *)
type v = {
......@@ -94,6 +96,8 @@ module P_feature = struct
| Different [] -> "=*"
| Different l -> "≠" ^ (String.concat "|" (List.map string_of_value l))
| Equal l -> "=" ^ (String.concat "|" (List.map string_of_value l))
| Equal_lex (lex,fn) -> sprintf "= %s.%s" lex fn
| Different_lex (lex,fn) -> sprintf "≠ %s.%s" lex fn
| Absent -> " must be Absent!");
printf "in_param=[%s]\n" (String.concat "," (List.map string_of_int in_param));
printf "%!"
......@@ -105,6 +109,8 @@ module P_feature = struct
| Absent -> ("absent", `Null)
| Equal val_list -> ("equal", `List (List.map (fun x -> `String (string_of_value x)) val_list))
| Different val_list -> ("different", `List (List.map (fun x -> `String (string_of_value x)) val_list))
| Equal_lex (lex,fn) -> ("equal_lex", `String (sprintf "%s.%s" lex fn))
| Different_lex (lex,fn) -> ("different_lex", `String (sprintf "%s.%s" lex fn))
)
]
......@@ -164,6 +170,8 @@ module P_feature = struct
let values = Feature_value.build_disj ~loc ?domain name unsorted_values in (name, {cst=Equal values;in_param=[];})
| ({Ast.kind=Ast.Disequality unsorted_values; name=name}, loc) ->
let values = Feature_value.build_disj ~loc ?domain name unsorted_values in (name, {cst=Different values;in_param=[];})
| ({Ast.kind=Ast.Equal_lex (lex,fn); name=name}, loc) -> (name, {cst=Equal_lex (lex,fn); in_param=[];})
| ({Ast.kind=Ast.Disequal_lex (lex,fn); name=name}, loc) -> (name, {cst=Different_lex (lex,fn); in_param=[];})
| ({Ast.kind=Ast.Equal_param var; name=name}, loc) ->
begin
match pat_vars with
......
......@@ -177,10 +177,15 @@ feature_ident_with_loc :
| id=ID { localize (Ast.parse_feature_ident id) }
feature_value:
| v=ID { v }
| v=ID { Ast.parse_simple_ident v }
| v=STRING { v }
| v=FLOAT { Printf.sprintf "%g" v }
pattern_feature_value:
| v=ID { Ast.parse_simple_or_pointed v }
| v=STRING { Ast.Simple v }
| v=FLOAT { Ast.Simple (Printf.sprintf "%g" v) }
ineq_value:
| v=ID { Ineq_sofi (Ast.parse_simple_or_pointed v) }
| v=FLOAT { Ineq_float v }
......@@ -226,7 +231,7 @@ gr_item:
/* DOMAIN DEFINITION */
/*=============================================================================================*/
domain:
| c=option(DUMMY) f=features_group g=labels EOF
| c=option(DUMMY) f=feature_group g=labels EOF
{
{ Ast.feature_domain = f;
label_domain = g;
......@@ -265,7 +270,7 @@ subfile:
/*=============================================================================================*/
/* FEATURES DOMAIN DEFINITION */
/*=============================================================================================*/
features_group:
feature_group:
| FEATURES x=features { x }
features:
......@@ -274,7 +279,7 @@ features:
feature:
/* pos=# */
/* m: ind,inf,part,subj,imp */
| feature_name=feature_name DDOT feature_values=features_values
| feature_name=feature_name DDOT feature_values=feature_values
{
match feature_values with
| ["#"] -> Ast.Num feature_name
......@@ -288,7 +293,7 @@ feature:
feature_name:
| ci=ID { Ast.to_uname ci }
features_values:
feature_values:
| SHARP { ["#"] }
| x=separated_nonempty_list(COMA,feature_value) { x }
......@@ -461,6 +466,7 @@ pat_item:
| Ast.Simple value ->
Pat_const (Ast.Feature_eq_cst (feat_id1, value), loc)
| Ast.Pointed (s1, s2) ->
Printf.printf "###%s--%s###\n%!" s1 s2;
Pat_const (Ast.Feature_eq_lex_or_fs (feat_id1, (s1,s2)), loc)
}
......@@ -579,32 +585,65 @@ pat_item:
node_features:
/* cat = n|v|adj */
| name_loc=simple_id_with_loc EQUAL values=separated_nonempty_list(PIPE,feature_value)
{ let (name,loc) = name_loc in
| name_loc=simple_id_with_loc EQUAL values=separated_nonempty_list(PIPE,pattern_feature_value)
{
let (name,loc) = name_loc in
let uname = Ast.to_uname name in
match values with
| ["*"] -> ({Ast.kind = Ast.Disequality []; name=uname},loc)
| _ -> ({Ast.kind = Ast.Equality values; name=uname }, loc) }
| [Ast.Simple "*"] ->
Printf.printf "###node_features[1.1] --> %s\n%!" name;
({Ast.kind = Ast.Disequality []; name=uname},loc)
| [Ast.Pointed (lex,fn)] ->
Printf.printf "###node_features[1.2] --> %s\n%!" name;
({Ast.kind = Ast.Equal_lex (lex,fn); name=uname }, loc)
| l ->
Printf.printf "###node_features[1.3] --> %s\n%!" name;
let value_list = List.map (function
| Ast.Simple x -> x
| Ast.Pointed (lex,fn) -> Error.build "Lexical reference '%s.%s' cannot be used in a disjunction" lex fn
) l in ({Ast.kind = Ast.Equality value_list; name=uname }, loc)
}
/* cat = * */
| name_loc=simple_id_with_loc EQUAL STAR
{ let (name,loc) = name_loc in ({Ast.kind = Ast.Disequality []; name=Ast.to_uname name},loc) }
{ let (name,loc) = name_loc in
Printf.printf "###node_features[2] --> %s\n%!" name;
({Ast.kind = Ast.Disequality []; name=Ast.to_uname name},loc) }
/* cat */
| name_loc=simple_id_with_loc
{ let (name,loc) = name_loc in ({Ast.kind = Ast.Disequality []; name=Ast.to_uname name},loc) }
{ let (name,loc) = name_loc in
Printf.printf "###node_features[3] --> %s\n%!" name;
({Ast.kind = Ast.Disequality []; name=Ast.to_uname name},loc) }
/* cat<>n|v|adj */
| name_loc=simple_id_with_loc DISEQUAL values=separated_nonempty_list(PIPE,feature_value)
{ let (name,loc) = name_loc in ( {Ast.kind = Ast.Disequality values; name=Ast.to_uname name}, loc) }
| name_loc=simple_id_with_loc DISEQUAL values=separated_nonempty_list(PIPE,pattern_feature_value)
{
let (name,loc) = name_loc in
let uname = Ast.to_uname name in
match values with
| [Ast.Pointed (lex,fn)] ->
Printf.printf "###node_features[4.2] --> %s\n%!" name;
({Ast.kind = Ast.Disequal_lex (lex,fn); name=uname }, loc)
| l ->
Printf.printf "###node_features[4.3] --> %s\n%!" name;
let value_list = List.map (function
| Ast.Simple x -> x
| Ast.Pointed (lex,fn) -> Error.build "Lexical reference '%s.%s' cannot be used in a disjunction" lex fn
) l in ({Ast.kind = Ast.Disequality value_list; name=uname }, loc)
}
/* lemma=$lem */
| name_loc=simple_id_with_loc EQUAL p=DOLLAR_ID
{ let (name,loc) = name_loc in ( {Ast.kind = Ast.Equal_param p; name=Ast.to_uname name }, loc) }
{ let (name,loc) = name_loc in
Printf.printf "###node_features[5] --> %s\n%!" name;
( {Ast.kind = Ast.Equal_param p; name=Ast.to_uname name }, loc) }
/* !lemma */
| BANG name_loc=simple_id_with_loc
{ let (name,loc) = name_loc in ({Ast.kind = Ast.Absent; name=Ast.to_uname name}, loc) }
{ let (name,loc) = name_loc in
Printf.printf "###node_features[6] --> %s\n%!" name;
({Ast.kind = Ast.Absent; name=Ast.to_uname name}, loc) }
/*=============================================================================================*/
/* COMMANDS DEFINITION */
......@@ -766,7 +805,7 @@ new_grs:
| decls = list(decl) EOF { decls }
decl:
| f=features_group { New_ast.Features f }
| 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 }
......
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