Commit b2d6a671 authored by bguillaum's avatar bguillaum

syntactic sugar: "A < B" is interpreted as "A.position < B.position"

git-svn-id: svn+ssh://scm.gforge.inria.fr/svn/semagramme/libcaml-grew/trunk@8893 7838e531-6607-4d57-9587-6c381814729c
parent f55f8b7c
......@@ -55,13 +55,20 @@ module Ast = struct
(* ---------------------------------------------------------------------- *)
(* feature_ident: V.cat *)
type feature_ident = Id.name * feature_name
let dump_feature_ident (name, feat_name) = sprintf "%s.%s" name feat_name
let parse_feature_ident s =
check_special "feature ident" ["."] s;
match Str.full_split (Str.regexp "\\.") s with
| [Str.Text base; Str.Delim "."; Str.Text fn] -> (base, fn)
| _ -> Error.build "The identifier '%s' must be a feature identifier (with exactly one '.' symbol, like \"V.cat\" for instance)" s
let dump_feature_ident (name, feat_name) = sprintf "%s.%s" name feat_name
let parse_ineq_ident s =
check_special "feature ident" ["."] s;
match Str.full_split (Str.regexp "\\.") s with
| [Str.Text base; ] -> (base, "position")
| [Str.Text base; Str.Delim "."; Str.Text fn] -> (base, fn)
| _ -> Error.build "The identifier '%s' must be a feature identifier (with exactly one '.' symbol, like \"V.cat\" for instance)" s
(* ---------------------------------------------------------------------- *)
(* command_node_id: V, V#alpha *)
......
......@@ -36,6 +36,7 @@ module Ast : sig
(* feature_ident: V.cat *)
type feature_ident = Id.name * feature_name
val parse_feature_ident: string -> feature_ident
val parse_ineq_ident: string -> feature_ident
val dump_feature_ident: feature_ident -> string
(* -------------------------------------------------------------------------------- *)
......
......@@ -157,6 +157,12 @@ feature_ident :
feature_ident_with_loc :
| id=ID { localize (Ast.parse_feature_ident id) }
ineq_ident :
| id=ID { Ast.parse_ineq_ident id }
ineq_ident_with_loc :
| id=ID { localize (Ast.parse_ineq_ident id) }
command_feature_ident_with_loc :
| id=ID { localize (Ast.parse_command_feature_ident id) }
......@@ -478,39 +484,39 @@ pat_edge_or_const:
{ let (feat_id1,loc)=feat_id1_loc in Pat_const (Ast.Feature_diseq (feat_id1, feat_id2), loc) }
(* "X.position < Y.position" *)
| feat_id1_loc=feature_ident_with_loc LT feat_id2=feature_ident
| feat_id1_loc=ineq_ident_with_loc LT feat_id2=ineq_ident
{ let (feat_id1,loc)=feat_id1_loc in Pat_const (Ast.Feature_ineq (Ast.Lt, feat_id1, feat_id2), loc) }
(* "X.position > Y.position" *)
| feat_id1_loc=feature_ident_with_loc GT feat_id2=feature_ident
| feat_id1_loc=ineq_ident_with_loc GT feat_id2=ineq_ident
{ let (feat_id1,loc)=feat_id1_loc in Pat_const (Ast.Feature_ineq (Ast.Gt, feat_id1, feat_id2), loc) }
(* "X.position <= Y.position" *)
| feat_id1_loc=feature_ident_with_loc LE feat_id2=feature_ident
| feat_id1_loc=ineq_ident_with_loc LE feat_id2=ineq_ident
{ let (feat_id1,loc)=feat_id1_loc in Pat_const (Ast.Feature_ineq (Ast.Le, feat_id1, feat_id2), loc) }
(* "X.position >= Y.position" *)
| feat_id1_loc=feature_ident_with_loc GE feat_id2=feature_ident
| feat_id1_loc=ineq_ident_with_loc GE feat_id2=ineq_ident
{ let (feat_id1,loc)=feat_id1_loc in Pat_const (Ast.Feature_ineq (Ast.Ge, feat_id1, feat_id2), loc) }
(* "X.feat >= 12.34" *)
| feat_id1_loc=feature_ident_with_loc GE num=FLOAT
| num=FLOAT LE feat_id1_loc=feature_ident_with_loc
| feat_id1_loc=ineq_ident_with_loc GE num=FLOAT
| num=FLOAT LE feat_id1_loc=ineq_ident_with_loc
{ let (feat_id1,loc)=feat_id1_loc in Pat_const (Ast.Feature_ineq_cst (Ast.Ge, feat_id1, num), loc) }
(* "X.feat > 12.34" *)
| feat_id1_loc=feature_ident_with_loc GT num=FLOAT
| num=FLOAT LT feat_id1_loc=feature_ident_with_loc
| feat_id1_loc=ineq_ident_with_loc GT num=FLOAT
| num=FLOAT LT feat_id1_loc=ineq_ident_with_loc
{ let (feat_id1,loc)=feat_id1_loc in Pat_const (Ast.Feature_ineq_cst (Ast.Gt, feat_id1, num), loc) }
(* "X.feat <= 12.34" *)
| feat_id1_loc=feature_ident_with_loc LE num=FLOAT
| num=FLOAT GE feat_id1_loc=feature_ident_with_loc
| feat_id1_loc=ineq_ident_with_loc LE num=FLOAT
| num=FLOAT GE feat_id1_loc=ineq_ident_with_loc
{ let (feat_id1,loc)=feat_id1_loc in Pat_const (Ast.Feature_ineq_cst (Ast.Le, feat_id1, num), loc) }
(* "X.feat < 12.34" *)
| feat_id1_loc=feature_ident_with_loc LT num=FLOAT
| num=FLOAT GT feat_id1_loc=feature_ident_with_loc
| feat_id1_loc=ineq_ident_with_loc LT num=FLOAT
| num=FLOAT GT feat_id1_loc=ineq_ident_with_loc
{ let (feat_id1,loc)=feat_id1_loc in Pat_const (Ast.Feature_ineq_cst (Ast.Lt, feat_id1, num), loc) }
......
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