Commit 126a59b9 authored by bguillaum's avatar bguillaum

grs file can be splitted in several files

git-svn-id: svn+ssh://scm.gforge.inria.fr/svn/semagramme/libcaml-grew/trunk@6632 7838e531-6607-4d57-9587-6c381814729c
parent cf79ccf6
......@@ -100,11 +100,21 @@ type sequence = {
(**
a GRS: graph rewriting system
*)
type module_or_include =
| Modul of modul
| Includ of string
type grs_with_include = {
domain_wi: domain;
labels_wi: (string * string option) list; (* the list of global edge labels *)
modules_wi: module_or_include list;
sequences_wi: sequence list;
}
type grs = {
domain: domain;
labels: (string * string option) list; (* the list of global edge labels *)
modules: modul list; (* the ordered list of modules used from rewriting *)
labels: (string * string option) list;
modules: modul list;
sequences: sequence list;
}
......
......@@ -92,12 +92,23 @@ type sequence = {
(**
a GRS: graph rewriting system
*)
type module_or_include =
| Modul of modul
| Includ of string
type grs_with_include = {
domain_wi: domain;
labels_wi: (string * string option) list; (* the list of global edge labels *)
modules_wi: module_or_include list;
sequences_wi: sequence list;
}
type grs = {
domain: domain;
labels: (string * string option) list; (* the list of global edge labels *)
modules: modul list; (* the ordered list of modules used from rewriting *)
labels: (string * string option) list;
modules: modul list;
sequences: sequence list;
}
}
type gr = {
nodes: node list;
......
......@@ -29,10 +29,10 @@ lexer.cmo: gr_grs_parser.cmo lexer.mll ../ast.cmo
ocamlc -c $(BYTE_FLAGS) lexer.ml
grew_parser.cmx: gr_grs_parser.cmx lexer.cmx grew_parser.ml ../ast.cmx
ocamlopt -c $(OPT_FLAGS) grew_parser.ml
ocamlopt -c $(OPT_FLAGS) -I .. ast.cmx grew_parser.ml
grew_parser.cmo: gr_grs_parser.cmo lexer.cmo grew_parser.ml ../ast.cmo
ocamlc -c $(BYTE_FLAGS) grew_parser.ml
ocamlc -c $(BYTE_FLAGS) -I .. ast.cmo grew_parser.ml
clean:
rm -rf *.cmi *.cmx *.cmo lexer.ml gr_grs_parser.ml *.o *.mli *.annot
......
......@@ -38,6 +38,7 @@ let localize t = (t,get_loc ())
%token RTL_EDGE_RIGHT /* ]- */
%token LONGARROW /* ==> */
%token INCLUDE /* include */
%token FEATURES /* features */
%token LABELS /* labels */
%token BAD_LABELS /* bad_labels */
......@@ -66,9 +67,10 @@ let localize t = (t,get_loc ())
%token EOF /* end of file */
%start <Ast.grs_with_include> grs_with_include
%start <Ast.grs> grs
%start <Ast.gr> gr
%start <Ast.modul list> included
%%
/*=============================================================================================*/
......@@ -111,6 +113,16 @@ index:
/*=============================================================================================*/
grs_with_include:
| f = features_group g = global_labels m = module_or_include_list s = sequences EOF
{
{ Ast.domain_wi=List_.opt f;
labels_wi=g;
modules_wi=m;
sequences_wi=s;
}
}
grs:
| f = features_group g = global_labels m = modules s = sequences EOF
{
......@@ -120,7 +132,13 @@ grs:
sequences=s;
}
}
module_or_include_list:
| x = list(module_or_include) { x }
module_or_include:
| m = grew_module { Modul m }
| INCLUDE file = STRING { Includ file }
/*=============================================================================================*/
......@@ -188,6 +206,9 @@ global_labels:
/* */
/*=============================================================================================*/
included:
| x = list(grew_module) EOF { x }
modules:
| x = list(grew_module) { x }
......
module Grew_parser = struct
open Ast
exception Parse_error of string
module Grew_parser = struct
exception Parse_error of string
(**
[parse_string str] where [str] is a string following the grew syntax
@param str the string to parse
@return a syntactic tree of the parsed file
*)
let parse_string_to_grs str =
let to_parse = Lexing.from_string str in
begin
try Gr_grs_parser.grs Lexer.global to_parse
with
| Lexer.Error msg -> raise (Parse_error msg)
| Gr_grs_parser.Error ->
let cp = to_parse.Lexing.lex_curr_p in
raise (Parse_error (Printf.sprintf "Syntax error\nLine %d : %s\n%!" cp.Lexing.pos_lnum (Lexing.lexeme to_parse)))
| Failure msg ->
let cp = to_parse.Lexing.lex_curr_p in
raise (Parse_error (Printf.sprintf "Syntax error\nLine %d\n%s\n%!" cp.Lexing.pos_lnum msg))
| err -> raise (Parse_error (Printexc.to_string err))
end
let parse_file_to_grs_with_includes file =
try
let in_ch = open_in file in
let to_parse = Lexing.from_channel in_ch in
begin
try
Parser_global.current_file := file;
Parser_global.current_line := 0;
let res = Gr_grs_parser.grs_with_include Lexer.global to_parse in close_in in_ch; res
with
| Lexer.Error msg -> raise (Parse_error msg)
| Gr_grs_parser.Error ->
let cp = to_parse.Lexing.lex_curr_p in
raise (Parse_error (Printf.sprintf "Syntax error\nFile %s\nLine %d : %s\n%!" file cp.Lexing.pos_lnum (Lexing.lexeme to_parse)))
| Failure msg ->
let cp = to_parse.Lexing.lex_curr_p in
raise (Parse_error (Printf.sprintf "Syntax error\nFile %s\nLine %d\n%s\n%!" file cp.Lexing.pos_lnum msg))
| err -> raise (Parse_error (Printexc.to_string err))
end
with Sys_error msg-> raise (Parse_error msg)
(**
[parse_string str] where [str] is a string following the grew syntax
@param str the string to parse
@return a syntactic tree of the parsed file
*)
let parse_string_to_grs str =
let to_parse = Lexing.from_string str in
begin
try
Gr_grs_parser.grs Lexer.global to_parse
with
| Lexer.Error msg -> raise (Parse_error msg)
| Gr_grs_parser.Error ->
let cp = to_parse.Lexing.lex_curr_p in
raise (Parse_error (Printf.sprintf "Syntax error\nLine %d : %s\n%!" cp.Lexing.pos_lnum (Lexing.lexeme to_parse)))
| Failure msg ->
let cp = to_parse.Lexing.lex_curr_p in
raise (Parse_error (Printf.sprintf "Syntax error\nLine %d\n%s\n%!" cp.Lexing.pos_lnum msg))
| err -> raise (Parse_error (Printexc.to_string err))
end
(**
[parse_string file] where [file] is a file following the grew syntax
@param file the file to parse
@return a syntactic tree of the parsed file
*)
let parse_file_to_grs file =
try
let in_ch = open_in file in
let to_parse = Lexing.from_channel in_ch in
begin
try
Parser_global.current_file := file;
Parser_global.current_line := 0;
let res = Gr_grs_parser.grs Lexer.global to_parse in close_in in_ch; res
with
| Lexer.Error msg -> raise (Parse_error msg)
| Gr_grs_parser.Error ->
let cp = to_parse.Lexing.lex_curr_p in
raise (Parse_error (Printf.sprintf "Syntax error\nFile %s\nLine %d : %s\n%!" file cp.Lexing.pos_lnum (Lexing.lexeme to_parse)))
| Failure msg ->
let cp = to_parse.Lexing.lex_curr_p in
raise (Parse_error (Printf.sprintf "Syntax error\nFile %s\nLine %d\n%s\n%!" file cp.Lexing.pos_lnum msg))
| err -> raise (Parse_error (Printexc.to_string err))
end
with Sys_error msg-> raise (Parse_error msg)
let parse_file_to_module_list file =
try
let in_ch = open_in file in
let to_parse = Lexing.from_channel in_ch in
begin
try
Parser_global.current_file := file;
Parser_global.current_line := 0;
let res = Gr_grs_parser.included Lexer.global to_parse in close_in in_ch;
Printf.printf "=======================================================\n";
List.iter
(fun m -> Printf.printf "module %s --> %d rules\n" m.module_id (List.length m.rules)) res;
Printf.printf "=======================================================\n";
res
with
| Lexer.Error msg -> raise (Parse_error msg)
| Gr_grs_parser.Error ->
let cp = to_parse.Lexing.lex_curr_p in
raise (Parse_error (Printf.sprintf "Syntax error\nFile %s\nLine %d : %s\n%!" file cp.Lexing.pos_lnum (Lexing.lexeme to_parse)))
| Failure msg ->
let cp = to_parse.Lexing.lex_curr_p in
raise (Parse_error (Printf.sprintf "Syntax error\nFile %s\nLine %d\n%s\n%!" file cp.Lexing.pos_lnum msg))
| err -> raise (Parse_error (Printexc.to_string err))
end
with Sys_error msg-> raise (Parse_error msg)
(**
[parse_string file] where [file] is a file following the grew syntax
@param file the file to parse
@return a syntactic tree of the parsed file
*)
let parse_file_to_grs file =
let grs_with_includes = parse_file_to_grs_with_includes file in
let rec flatten_modules = function
| [] -> []
| Ast.Modul m :: tail -> m :: (flatten_modules tail)
| Ast.Includ file :: tail ->
(parse_file_to_module_list file)
@ (flatten_modules tail) in
{
Ast.domain = grs_with_includes.Ast.domain_wi;
Ast.labels = grs_with_includes.Ast.labels_wi;
Ast.modules = flatten_modules grs_with_includes.Ast.modules_wi;
Ast.sequences = grs_with_includes.Ast.sequences_wi;
}
let parse_string_to_gr str =
let to_parse = Lexing.from_string str in
begin
try
Gr_grs_parser.gr Lexer.global to_parse
with
| Lexer.Error msg -> raise (Parse_error msg)
| Gr_grs_parser.Error ->
let cp = to_parse.Lexing.lex_curr_p in
raise (Parse_error (Printf.sprintf "Syntax error\nLine %d : %s\n%!" cp.Lexing.pos_lnum (Lexing.lexeme to_parse)))
| Failure msg ->
let cp = to_parse.Lexing.lex_curr_p in
raise (Parse_error (Printf.sprintf "Syntax error\nLine %d\n%s\n%!" cp.Lexing.pos_lnum msg))
| err -> raise (Parse_error (Printexc.to_string err))
end
let parse_file_to_gr file =
try
let in_ch = open_in file in
let to_parse = Lexing.from_channel in_ch in
let parse_string_to_gr str =
let to_parse = Lexing.from_string str in
begin
try Gr_grs_parser.gr Lexer.global to_parse
with
| Lexer.Error msg -> raise (Parse_error msg)
| Gr_grs_parser.Error ->
let cp = to_parse.Lexing.lex_curr_p in
raise (Parse_error (Printf.sprintf "Syntax error\nLine %d : %s\n%!" cp.Lexing.pos_lnum (Lexing.lexeme to_parse)))
| Failure msg ->
let cp = to_parse.Lexing.lex_curr_p in
raise (Parse_error (Printf.sprintf "Syntax error\nLine %d\n%s\n%!" cp.Lexing.pos_lnum msg))
| err -> raise (Parse_error (Printexc.to_string err))
end
let parse_file_to_gr file =
try
let in_ch = open_in file in
let to_parse = Lexing.from_channel in_ch in
begin
try
Parser_global.current_file := file;
Parser_global.current_line := 0;
let res = Gr_grs_parser.gr Lexer.global to_parse in close_in in_ch; res
with
| Lexer.Error msg -> raise (Parse_error msg)
| Gr_grs_parser.Error ->
let cp = to_parse.Lexing.lex_curr_p in
raise (Parse_error (Printf.sprintf "Syntax error\nFile %s\nLine %d : %s\n%!" file cp.Lexing.pos_lnum (Lexing.lexeme to_parse)))
| Failure msg ->
let cp = to_parse.Lexing.lex_curr_p in
raise (Parse_error (Printf.sprintf "Syntax error\nFile %s\nLine %d\n%s\n%!" file cp.Lexing.pos_lnum msg))
| err -> raise (Parse_error (Printexc.to_string err))
end
with Sys_error msg -> raise (Parse_error msg)
begin
try
Parser_global.current_file := file;
Parser_global.current_line := 0;
let res = Gr_grs_parser.gr Lexer.global to_parse in close_in in_ch; res
with
| Lexer.Error msg -> raise (Parse_error msg)
| Gr_grs_parser.Error ->
let cp = to_parse.Lexing.lex_curr_p in
raise (Parse_error (Printf.sprintf "Syntax error\nFile %s\nLine %d : %s\n%!" file cp.Lexing.pos_lnum (Lexing.lexeme to_parse)))
| Failure msg ->
let cp = to_parse.Lexing.lex_curr_p in
raise (Parse_error (Printf.sprintf "Syntax error\nFile %s\nLine %d\n%s\n%!" file cp.Lexing.pos_lnum msg))
| err -> raise (Parse_error (Printexc.to_string err))
end
with Sys_error msg -> raise (Parse_error msg)
end
......@@ -50,6 +50,7 @@ and global = parse
| '\n' { incr Parser_global.current_line; Lexing.new_line lexbuf; global lexbuf}
| "include" { INCLUDE }
| "features" { FEATURES }
| "labels" { LABELS }
| "bad_labels" { BAD_LABELS }
......
......@@ -550,8 +550,6 @@ module Rule = struct
(pos_graph,Graph.empty)
instance.Instance.graph
(init rule.pos) in
(* Printf.printf "XXX -> | matching_list | = %d\n" (List.length matching_list); *)
let filtered_matching_list =
List.filter
......@@ -564,7 +562,6 @@ module Rule = struct
) rule.neg
) matching_list in
(* Printf.printf "XXX -> | filtered_matching_list | = %d\n" (List.length filtered_matching_list); *)
List.fold_left
(fun acc1 (matching,_) ->
try (apply_rule instance matching rule) :: acc1
......
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