Commit 94d2f1b0 authored by bguillaum's avatar bguillaum

handle domain definition in a external file

git-svn-id: svn+ssh://scm.gforge.inria.fr/svn/semagramme/libcaml-grew/trunk@8958 7838e531-6607-4d57-9587-6c381814729c
parent a843ce53
......@@ -317,8 +317,10 @@ module Ast = struct
let empty_domain = { feature_domain=[]; label_domain=[] }
type grs_with_include = {
domain_wi: domain;
type domain_wi = Dom of domain | Dom_file of string
type grs_wi = {
domain_wi: domain_wi;
modules_wi: module_or_include list;
sequences_wi: sequence list;
}
......
......@@ -190,8 +190,10 @@ module Ast : sig
label_domain: (string * string list) list;
}
type grs_with_include = {
domain_wi: domain;
type domain_wi = Dom of domain | Dom_file of string
type grs_wi = {
domain_wi: domain_wi;
modules_wi: module_or_include list;
sequences_wi: sequence list;
}
......
......@@ -160,6 +160,7 @@ and standard target = parse
| '\n' { incr Global.current_line; Lexing.new_line lexbuf; global lexbuf}
| "include" { INCL }
| "domain" { DOMAIN }
| "features" { FEATURES }
| "feature" { FEATURE }
| "file" { FILE }
......
......@@ -37,12 +37,12 @@ module Loader = struct
raise (Error ("Unexpected error:"^(Printexc.to_string err), Some (Loc.file_line file cp)))
(* ------------------------------------------------------------------------------------------*)
let parse_file_to_grs_with_includes file =
let parse_file_to_grs_wi file =
try
Global.init file;
let in_ch = open_in file in
let lexbuf = Lexing.from_channel in_ch in
let grs = parse_handle file (Grew_parser.grs_with_include Grew_lexer.global) lexbuf in
let grs = parse_handle file (Grew_parser.grs_wi Grew_lexer.global) lexbuf in
close_in in_ch;
grs
with Sys_error msg -> raise (Error (msg, None))
......@@ -76,7 +76,10 @@ module Loader = struct
@return a syntactic tree of the parsed file
*)
let grs main_file =
let grs_with_includes = parse_file_to_grs_with_includes main_file in
let grs_wi = parse_file_to_grs_wi main_file in
let domain = match grs_wi.Ast.domain_wi with
| Ast.Dom d -> d
| Ast.Dom_file file -> domain file in
let rec flatten_modules current_file = function
| [] -> []
| Ast.Modul m :: tail ->
......@@ -90,9 +93,9 @@ module Loader = struct
(flatten_modules sub_file (parse_file_to_module_list loc sub_file))
@ (flatten_modules current_file tail) in
{
Ast.domain = grs_with_includes.Ast.domain_wi;
Ast.modules = flatten_modules main_file grs_with_includes.Ast.modules_wi;
Ast.sequences = grs_with_includes.Ast.sequences_wi;
Ast.domain = domain;
Ast.modules = flatten_modules main_file grs_wi.Ast.modules_wi;
Ast.sequences = grs_wi.Ast.sequences_wi;
}
(* ------------------------------------------------------------------------------------------*)
......
......@@ -63,6 +63,7 @@ let localize t = (t,get_loc ())
%token ARROW_LEFT_NEG /* =[^ */
%token ARROW_RIGHT /* ]=> */
%token DOMAIN /* domain */
%token INCL /* include */
%token FEATURES /* features */
%token FEATURE /* feature */
......@@ -105,8 +106,7 @@ let localize t = (t,get_loc ())
%token EOF /* end of file */
%start <Grew_ast.Ast.grs_with_include> grs_with_include
%start <Grew_ast.Ast.grs> grs
%start <Grew_ast.Ast.grs_wi> grs_wi
%start <Grew_ast.Ast.gr> gr
%start <Grew_ast.Ast.module_or_include list> included
%start <Grew_ast.Ast.pattern> pattern
......@@ -213,21 +213,19 @@ domain:
/*=============================================================================================*/
/* GREW GRAPH REWRITING SYSTEM */
/*=============================================================================================*/
grs_with_include:
grs_wi:
| d=domain m=module_or_include_list s=option(sequences) EOF
{
{ Ast.domain_wi=d;
{ Ast.domain_wi=Ast.Dom d;
modules_wi=m;
sequences_wi=match s with Some seq -> seq | None -> [];
}
}
grs:
| d=domain m=modules s=option(sequences) EOF
| DOMAIN file=STRING m=module_or_include_list s=option(sequences) EOF
{
{ Ast.domain=d;
modules=m;
sequences=match s with Some seq -> seq | None -> [];
{ Ast.domain_wi=Ast.Dom_file file;
modules_wi=m;
sequences_wi=match s with Some seq -> seq | None -> [];
}
}
......@@ -292,9 +290,6 @@ display:
included:
| x=list(module_or_include) EOF { x }
modules:
| x=list(grew_module) { x }
grew_module:
| doc=option(COMMENT) MODULE conf=boption(CONFLUENT) id_loc=simple_id_with_loc LACC l=option(labels) suff=option(suffixes) r=rules RACC
{
......
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