Commit fc2e3441 authored by bguillaum's avatar bguillaum
Browse files

modify the lexer and parser to handle edge labels with dots "obj.p"

git-svn-id: svn+ssh://scm.gforge.inria.fr/svn/semagramme/libcaml-grew/trunk@7845 7838e531-6607-4d57-9587-6c381814729c
parent a1becc1e
......@@ -78,7 +78,7 @@ let localize t = (t,get_loc ())
%token <string> COLOR /* @#89abCD */
%token <string> IDENT /* indentifier */
%token <Grew_ast.Ast.qfn> QFN /* ident.ident */
%token <string * string> PAIR /* ident.ident */
%token <string> STRING
%token <int> INT
%token <string list> COMMENT
......@@ -142,9 +142,11 @@ num:
| INT { $1 }
label_ident:
| x = separated_nonempty_list(DDOT,IDENT) { String.concat ":" x }
| x = separated_nonempty_list(DDOT,label_item) { String.concat ":" x }
label_item:
| x = IDENT { x }
| p = PAIR { (fst p)^"."^(snd p) }
......@@ -461,23 +463,23 @@ pat_const:
{ localize (Ast.Cst_in n2) }
(* X.cat = Y.cat *)
| qfn1 = QFN EQUAL qfn2 = QFN
| qfn1 = PAIR EQUAL qfn2 = PAIR
{ localize (Ast.Feature_eq (qfn1, qfn2)) }
(* X.position < Y.position *)
| qfn1 = QFN LT qfn2 = QFN
| qfn1 = PAIR LT qfn2 = PAIR
{ localize (Ast.Feature_ineq (Ast.Lt, qfn1, qfn2)) }
(* X.position > Y.position *)
| qfn1 = QFN GT qfn2 = QFN
| qfn1 = PAIR GT qfn2 = PAIR
{ localize (Ast.Feature_ineq (Ast.Gt, qfn1, qfn2)) }
(* X.position <= Y.position *)
| qfn1 = QFN LE qfn2 = QFN
| qfn1 = PAIR LE qfn2 = PAIR
{ localize (Ast.Feature_ineq (Ast.Le, qfn1, qfn2)) }
(* X.position >= Y.position *)
| qfn1 = QFN GE qfn2 = QFN
| qfn1 = PAIR GE qfn2 = PAIR
{ localize (Ast.Feature_ineq (Ast.Ge, qfn1, qfn2)) }
/*=============================================================================================*/
......@@ -528,13 +530,13 @@ command:
{ localize (Ast.Del_node n) }
| ADD_NODE n1 = IDENT DDOT label = delimited(RTL_EDGE_LEFT,label_ident,RTL_EDGE_RIGHT) n2 = IDENT
{ localize (Ast.New_neighbour (n1,n2,label)) }
| DEL_FEAT qfn = QFN
| DEL_FEAT qfn = PAIR
{ localize (Ast.Del_feat qfn) }
| qfn = QFN EQUAL items = separated_nonempty_list (PLUS, concat_item)
| qfn = PAIR EQUAL items = separated_nonempty_list (PLUS, concat_item)
{ localize (Ast.Update_feat (qfn, items)) }
concat_item:
| qfn = QFN { Ast.Qfn_item qfn }
| qfn = PAIR { Ast.Qfn_item qfn }
| s = IDENT { Ast.String_item s }
| s = STRING { Ast.String_item s }
| p = AROBAS_ID { Ast.Param_item p }
......
......@@ -10,10 +10,10 @@
let tmp_string = ref ""
let escaped = ref false
let parse_qfn string_feat =
match Str.split (Str.regexp "\\.") string_feat with
| [node; feat_name] -> (node, feat_name)
| _ -> Log.fcritical "[BUG] \"%s\" is not a feature" string_feat
let parse_couple string =
match Str.split (Str.regexp "\\.") string with
| [s1; s2] -> (s1, s2)
| _ -> Log.fcritical "[BUG] \"%s\" is not a couple" string
let split_comment com =
let raw = Str.split (Str.regexp "\n") com in
......@@ -24,10 +24,10 @@
let digit = ['0'-'9']
let letter = ['a'-'z' 'A'-'Z']
let hex = ['0'-'9' 'a'-'f' 'A'-'F']
(* an identifier is either a single letter or its lenght is >=2 and it doesn't end with a '-' *)
let ident = letter | (letter | '_') (letter | digit | '_' | '\'' | '-')* (letter | digit | '_' | '\'')
(* an identifier is either a single letter, "_", or its lenght is >=2 and it doesn't end with a '-' *)
let ident = (letter | '_') | (letter | '_') (letter | digit | '_' | '\'' | '-')* (letter | digit | '_' | '\'')
let hex = ['0'-'9' 'a'-'f' 'A'-'F']
let color = hex hex hex hex hex hex
rule comment target = parse
......@@ -103,13 +103,12 @@ and global = parse
| "graph" { GRAPH }
| digit+ as number { INT (int_of_string number) }
| ident ['.'] ident as qfn { QFN (parse_qfn qfn) }
| ident ['.'] ident as c { PAIR (parse_couple c) }
| ident as id { IDENT id }
| '$' ident as pat_var { DOLLAR_ID pat_var}
| '@' ident as cmd_var { AROBAS_ID cmd_var }
| "@#" color as col { COLOR col }
| '{' { LACC }
| '}' { RACC }
| '[' { LBRACKET }
......
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