Commit e6c8118c authored by bguillaum's avatar bguillaum

Make filename homogeneous

git-svn-id: svn+ssh://scm.gforge.inria.fr/svn/semagramme/libcaml-grew/trunk@8810 7838e531-6607-4d57-9587-6c381814729c
parent b51cd02c
......@@ -8,9 +8,9 @@
*.cmxa
# generated ml files
gr_grs_parser.ml
gr_grs_parser.mli
lexer.ml
grew_parser.ml
grew_parser.mli
grew_lexer.ml
.depend
......
......@@ -39,7 +39,6 @@ conf: config/configure.ac
clean:
@make -C src clean
@make -C src/parser clean
rm -f config.log confdefs.h config.status
purge: clean
......
......@@ -142,7 +142,6 @@ AC_CONFIG_FILES(\
config/Makefile \
Makefile \
src/Makefile \
src/parser/Makefile \
)
AC_PROG_MAKE_SET
......
......@@ -2642,7 +2642,7 @@ TRUNK=`pwd`
echo ""
ac_config_files="$ac_config_files config/Makefile Makefile src/Makefile src/parser/Makefile"
ac_config_files="$ac_config_files config/Makefile Makefile src/Makefile"
{ $as_echo "$as_me:${as_lineno-$LINENO}: checking whether ${MAKE-make} sets \$(MAKE)" >&5
......@@ -3388,7 +3388,6 @@ do
"config/Makefile") CONFIG_FILES="$CONFIG_FILES config/Makefile" ;;
"Makefile") CONFIG_FILES="$CONFIG_FILES Makefile" ;;
"src/Makefile") CONFIG_FILES="$CONFIG_FILES src/Makefile" ;;
"src/parser/Makefile") CONFIG_FILES="$CONFIG_FILES src/parser/Makefile" ;;
*) as_fn_error $? "invalid argument: \`$ac_config_target'" "$LINENO" 5;;
esac
......
......@@ -13,7 +13,7 @@ OCAMLOPTFLAGS= \
$(CAIRO_OPT) $(CAMOMILE_OPT) $(XML_LIGHT_OPT) $(ANSITERMINAL_OPT) $(LOG_OPT) $(DEP2PICT_OPT)
TARGET = libgrew_types.cmi libgrew.cmi libgrew.cma libgrew.cmxa
BASE = grew_base grew_types grew_ast parser_global gr_grs_parser lexer grew_parser grew_fs grew_edge grew_node grew_graph libgrew_types grew_command grew_rule grew_grs grew_html libgrew
BASE = grew_base grew_types grew_ast grew_parser grew_lexer grew_loader grew_fs grew_edge grew_node grew_graph libgrew_types grew_command grew_rule grew_grs grew_html libgrew
CMO = $(BASE:%=%.cmo)
CMX = $(BASE:%=%.cmx)
......@@ -30,20 +30,20 @@ include ../config/Makefile
# --------------------------------------------------------------------------
# Specific rules
SPECIFIC = gr_grs_parser.ml gr_grs_parser.mli lexer.ml
gr_grs_parser.ml: gr_grs_parser.mly
$(MENHIR) --infer --ocamlc "$(OCAMLC) -c -I ." gr_grs_parser.mly
@make gr_grs_parser.cmi # force the build NOW
gr_grs_parser.cmo: gr_grs_parser.ml
SPECIFIC = grew_parser.ml grew_parser.mli grew_lexer.ml
grew_parser.ml: grew_parser.mly
$(MENHIR) --infer --ocamlc "$(OCAMLC) -c -I ." grew_parser.mly
@make grew_parser.cmi # force the build NOW
grew_parser.cmo: grew_parser.ml
$(OCAMLC) $(OCAMLFLAGS) -c $<
gr_grs_parser.cmx: gr_grs_parser.ml
grew_parser.cmx: grew_parser.ml
$(OCAMLOPT) $(OCAMLOPTFLAGS) -c $<
lexer.ml: lexer.mll
$(OCAMLLEX) lexer.mll
lexer.cmo: lexer.ml
grew_lexer.ml: grew_lexer.mll
$(OCAMLLEX) grew_lexer.mll
grew_lexer.cmo: grew_lexer.ml
$(OCAMLC) $(OCAMLFLAGS) -c $<
lexer.cmx: lexer.ml
grew_lexer.cmx: grew_lexer.ml
$(OCAMLOPT) $(OCAMLOPTFLAGS) -c $<
# --------------------------------------------------------------------------
......
......@@ -591,3 +591,11 @@ module Timeout = struct
if Unix.time () -. !counter > delay
then raise Stop
end (* module Timeout *)
(* ================================================================================ *)
module Global = struct
let current_file = ref "Not a file"
let current_line = ref 0
let init file = current_file := file; current_line := 0
let label_flag = ref false
end
......@@ -261,3 +261,11 @@ module Timeout: sig
val check: unit -> unit
end
(* ================================================================================ *)
module Global: sig
val current_file: string ref
val current_line: int ref
val init: string -> unit
val label_flag: bool ref
end
......@@ -19,7 +19,7 @@ open Grew_edge
open Grew_command
open Grew_graph
open Grew_rule
open Grew_parser
open Grew_loader
(* ================================================================================ *)
module Rewrite_history = struct
......@@ -251,7 +251,7 @@ module Grs = struct
loop [] t.sequences
let build filename =
let ast = Grew_parser.grs_of_file filename in
let ast = Loader.grs filename in
Label.init ast.Ast.labels;
Domain.init ast.Ast.domain;
let modules = List.map Modul.build ast.Ast.modules in
......
......@@ -13,7 +13,7 @@
open Log
open Grew_base
open Grew_ast
open Gr_grs_parser
open Grew_parser
exception Error of string
......@@ -65,7 +65,7 @@ let color = hex hex hex hex hex hex | hex hex hex
(* ------------------------------------------------------------------------------- *)
rule comment target = parse
| '\n' { incr Parser_global.current_line; Lexing.new_line lexbuf; target lexbuf }
| '\n' { incr Global.current_line; Lexing.new_line lexbuf; target lexbuf }
| _ { comment target lexbuf }
and comment_multi_doc target = shortest
......@@ -73,7 +73,7 @@ and comment_multi_doc target = shortest
let start = ref 0 in
try while (Str.search_forward (Str.regexp "\n") comment !start != -1) do
start := Str.match_end ();
incr Parser_global.current_line;
incr Global.current_line;
Lexing.new_line lexbuf;
done; assert false
with Not_found ->
......@@ -82,7 +82,7 @@ and comment_multi_doc target = shortest
and comment_multi target = parse
| "*/" { target lexbuf }
| '\n' { incr Parser_global.current_line; Lexing.new_line lexbuf; comment_multi target lexbuf }
| '\n' { incr Global.current_line; Lexing.new_line lexbuf; comment_multi target lexbuf }
| _ { comment_multi target lexbuf }
and string_lex target = parse
......@@ -91,7 +91,7 @@ and string_lex target = parse
then (bprintf buff "\\"; escaped := false; string_lex target lexbuf)
else (escaped := true; string_lex target lexbuf)
}
| '\n' { incr Parser_global.current_line; Lexing.new_line lexbuf; bprintf buff "\n"; string_lex target lexbuf }
| '\n' { incr Global.current_line; Lexing.new_line lexbuf; bprintf buff "\n"; string_lex target lexbuf }
| '\"' {
if !escaped
then (bprintf buff "\""; escaped := false; string_lex target lexbuf)
......@@ -106,19 +106,19 @@ and string_lex target = parse
(* a dedicated lexer for lexical parameter: read everything until "#END" *)
and lp_lex target = parse
| '\n' { incr Parser_global.current_line; Lexing.new_line lexbuf; bprintf buff "\n"; lp_lex target lexbuf }
| '\n' { incr Global.current_line; Lexing.new_line lexbuf; bprintf buff "\n"; lp_lex target lexbuf }
| _ as c { bprintf buff "%c" c; lp_lex target lexbuf }
| "#END" [' ' '\t']* '\n' { incr Parser_global.current_line; LEX_PAR (Str.split (Str.regexp "\n") (Buffer.contents buff)) }
| "#END" [' ' '\t']* '\n' { incr Global.current_line; LEX_PAR (Str.split (Str.regexp "\n") (Buffer.contents buff)) }
(* The lexer must be different when label_ident are parsed. The [global] lexer calls either
[label_parser] or [standard] depending on the flag [Parser_global.label_flag].
[label_parser] or [standard] depending on the flag [Global.label_flag].
Difference are:
- a label_ident may contain ':' (like in D:suj:obj) and ':' is a token elsewhere
- a label_ident may contain '-' anywhere (like "--" in Tiger) but '-' is fordiden as the first or last character elsewhere
- the string "*" is lexed as ID by [label_parser] and as STAR by [standard]
*)
and global = parse
| "" { if !Parser_global.label_flag
| "" { if !Global.label_flag
then label_parser global lexbuf
else standard global lexbuf
}
......@@ -128,10 +128,10 @@ and label_parser target = parse
| [' ' '\t'] { global lexbuf }
| "/*" { comment_multi global lexbuf }
| '%' { comment global lexbuf }
| '\n' { incr Parser_global.current_line; Lexing.new_line lexbuf; global lexbuf}
| '\n' { incr Global.current_line; Lexing.new_line lexbuf; global lexbuf}
| '{' { LACC }
| '}' { Parser_global.label_flag := false; RACC }
| '}' { Global.label_flag := false; RACC }
| ',' { COMA }
| '|' { PIPE }
......@@ -141,9 +141,9 @@ and label_parser target = parse
| label_ident as id { ID id }
| '"' { Buffer.clear buff; string_lex global lexbuf }
| "]->" { Parser_global.label_flag := false; LTR_EDGE_RIGHT }
| "]-" { Parser_global.label_flag := false; RTL_EDGE_RIGHT }
| "]=>" { Parser_global.label_flag := false; ARROW_RIGHT }
| "]->" { Global.label_flag := false; LTR_EDGE_RIGHT }
| "]-" { Global.label_flag := false; RTL_EDGE_RIGHT }
| "]=>" { Global.label_flag := false; ARROW_RIGHT }
| _ as c { raise (Error (sprintf "At line %d: unexpected character '%c'" (lexbuf.Lexing.lex_start_p.Lexing.pos_lnum) c)) }
......@@ -154,15 +154,15 @@ and standard target = parse
| "/*" { comment_multi global lexbuf }
| '%' { comment global lexbuf }
| "#BEGIN" [' ' '\t']* '\n' { incr Parser_global.current_line; Buffer.clear buff; lp_lex global lexbuf}
| "#BEGIN" [' ' '\t']* '\n' { incr Global.current_line; Buffer.clear buff; lp_lex global lexbuf}
| '\n' { incr Parser_global.current_line; Lexing.new_line lexbuf; global lexbuf}
| '\n' { incr Global.current_line; Lexing.new_line lexbuf; global lexbuf}
| "include" { INCLUDE }
| "features" { FEATURES }
| "feature" { FEATURE }
| "file" { FILE }
| "labels" { Parser_global.label_flag := true; LABELS }
| "labels" { Global.label_flag := true; LABELS }
| "suffixes" { SUFFIXES }
| "match" { MATCH }
| "without" { WITHOUT }
......@@ -219,15 +219,15 @@ and standard target = parse
| '|' { PIPE }
| "->" { EDGE }
| "-[^" { Parser_global.label_flag := true; LTR_EDGE_LEFT_NEG }
| "-[" { Parser_global.label_flag := true; LTR_EDGE_LEFT }
| "-[^" { Global.label_flag := true; LTR_EDGE_LEFT_NEG }
| "-[" { Global.label_flag := true; LTR_EDGE_LEFT }
| "]->" { LTR_EDGE_RIGHT }
| "<-[" { Parser_global.label_flag := true; RTL_EDGE_LEFT }
| "<-[" { Global.label_flag := true; RTL_EDGE_LEFT }
| "]-" { RTL_EDGE_RIGHT }
| "==>" { ARROW }
| "=[" { Parser_global.label_flag := true; ARROW_LEFT }
| "=[^" { Parser_global.label_flag := true; ARROW_LEFT_NEG }
| "=[" { Global.label_flag := true; ARROW_LEFT }
| "=[^" { Global.label_flag := true; ARROW_LEFT_NEG }
| "]=>" { ARROW_RIGHT }
| '"' { Buffer.clear buff; string_lex global lexbuf }
......
......@@ -11,52 +11,52 @@
open Grew_base
open Grew_ast
module Grew_parser = struct
module Loader = struct
(* message and location *)
exception Parse_error of (string * Loc.t option)
exception Error of (string * Loc.t option)
(* ------------------------------------------------------------------------------------------*)
(** general function to handle parse errors *)
let parse_handle file fct lexbuf =
try fct lexbuf with
| Lexer.Error msg ->
| Grew_lexer.Error msg ->
let cp = lexbuf.Lexing.lex_curr_p.Lexing.pos_lnum in
raise (Parse_error ("Lexing error:"^msg, Some (Loc.file_line file cp)))
| Gr_grs_parser.Error ->
raise (Error ("Lexing error:"^msg, Some (Loc.file_line file cp)))
| Grew_parser.Error ->
let cp = lexbuf.Lexing.lex_curr_p.Lexing.pos_lnum in
raise (Parse_error ("Syntax error:"^(Lexing.lexeme lexbuf), Some (Loc.file_line file cp)))
raise (Error ("Syntax error:"^(Lexing.lexeme lexbuf), Some (Loc.file_line file cp)))
| Failure msg ->
let cp = lexbuf.Lexing.lex_curr_p.Lexing.pos_lnum in
raise (Parse_error ("Failure:"^msg, Some (Loc.file_line file cp)))
raise (Error ("Failure:"^msg, Some (Loc.file_line file cp)))
| Error.Build (msg,_) ->
let cp = lexbuf.Lexing.lex_curr_p.Lexing.pos_lnum in
raise (Parse_error ("Syntax error:"^msg, Some (Loc.file_line file cp)))
raise (Error ("Syntax error:"^msg, Some (Loc.file_line file cp)))
| err ->
let cp = lexbuf.Lexing.lex_curr_p.Lexing.pos_lnum in
raise (Parse_error ("Unexpected error:"^(Printexc.to_string err), Some (Loc.file_line file cp)))
raise (Error ("Unexpected error:"^(Printexc.to_string err), Some (Loc.file_line file cp)))
(* ------------------------------------------------------------------------------------------*)
let parse_file_to_grs_with_includes file =
try
Parser_global.init file;
Global.init file;
let in_ch = open_in file in
let lexbuf = Lexing.from_channel in_ch in
let grs = parse_handle file (Gr_grs_parser.grs_with_include Lexer.global) lexbuf in
let grs = parse_handle file (Grew_parser.grs_with_include Grew_lexer.global) lexbuf in
close_in in_ch;
grs
with Sys_error msg -> raise (Parse_error (msg, None))
with Sys_error msg -> raise (Error (msg, None))
(* ------------------------------------------------------------------------------------------*)
let parse_file_to_module_list loc file =
try
Parser_global.init file;
Global.init file;
let in_ch = open_in file in
let lexbuf = Lexing.from_channel in_ch in
let module_list = parse_handle file (Gr_grs_parser.included Lexer.global) lexbuf in
let module_list = parse_handle file (Grew_parser.included Grew_lexer.global) lexbuf in
close_in in_ch;
module_list
with Sys_error msg-> raise (Parse_error (msg, None))
with Sys_error msg-> raise (Error (msg, None))
(* ------------------------------------------------------------------------------------------*)
(**
......@@ -64,7 +64,7 @@ module Grew_parser = struct
@param file the file to parse
@return a syntactic tree of the parsed file
*)
let grs_of_file main_file =
let grs main_file =
let grs_with_includes = parse_file_to_grs_with_includes main_file in
let rec flatten_modules current_file = function
| [] -> []
......@@ -86,25 +86,25 @@ module Grew_parser = struct
}
(* ------------------------------------------------------------------------------------------*)
let gr_of_file file =
let gr file =
try
Parser_global.init file;
Global.init file;
let in_ch = open_in file in
let lexbuf = Lexing.from_channel in_ch in
let gr = parse_handle file (Gr_grs_parser.gr Lexer.global) lexbuf in
let gr = parse_handle file (Grew_parser.gr Grew_lexer.global) lexbuf in
close_in in_ch;
gr
with Sys_error msg-> raise (Parse_error (msg, None))
with Sys_error msg-> raise (Error (msg, None))
(* ------------------------------------------------------------------------------------------*)
let load_pattern file =
let pattern file =
try
Parser_global.init file;
Global.init file;
let in_ch = open_in file in
let lexbuf = Lexing.from_channel in_ch in
let gr = parse_handle file (Gr_grs_parser.pattern Lexer.global) lexbuf in
let gr = parse_handle file (Grew_parser.pattern Grew_lexer.global) lexbuf in
close_in in_ch;
gr
with Sys_error msg-> raise (Parse_error (msg, None))
with Sys_error msg-> raise (Error (msg, None))
end
end (* module Loader *)
......@@ -8,9 +8,18 @@
(* Authors: see AUTHORS file *)
(**********************************************************************************)
let current_file = ref "Not a file"
let current_line = ref 0
let init file = current_file := file; current_line := 0
open Grew_base
open Grew_ast
let label_flag = ref false
\ No newline at end of file
module Loader: sig
(* message and location *)
exception Error of (string * Loc.t option)
val grs: string -> Ast.grs
val gr: string -> Ast.gr
val pattern: string -> Ast.pattern
end
......@@ -24,7 +24,7 @@ type graph_item =
| Graph_node of Ast.node
| Graph_edge of Ast.edge
let get_loc () = Loc.file_line !Parser_global.current_file (!Parser_global.current_line+1)
let get_loc () = Loc.file_line !Global.current_file (!Global.current_line+1)
let localize t = (t,get_loc ())
%}
......
......@@ -435,7 +435,7 @@ module Conll = struct
let parse file_name lines = List_.opt_map (parse_line file_name) lines
(* We would prefer to compare the float equivalent of l1.num l2.num but this would break the dicho_find function *)
(* We would prefer to compare the float equivalent of l1.num l2.num but this would break the dicho_find function *)
let compare l1 l2 = Pervasives.compare ((* float_of_string *) l1.num) ((* float_of_string *) l2.num)
end (* module Conll *)
......
......@@ -21,10 +21,9 @@ open Grew_graph
open Grew_rule
open Grew_grs
open Grew_parser
open Grew_loader
open Grew_html
let css_file = Filename.concat DATA_DIR "style.css"
let empty_grs = Grs.empty
......@@ -53,7 +52,7 @@ let handle ?(name="") ?(file="No file defined") fct () =
| Run (msg, loc_opt) -> raise (Run (msg,loc_opt))
(* Catch new exceptions *)
| Grew_parser.Parse_error (msg, loc_opt) -> raise (Parsing_err (msg, loc_opt))
| Loader.Error (msg, loc_opt) -> raise (Parsing_err (msg, loc_opt))
| Error.Build (msg, loc_opt) -> raise (Build (msg, loc_opt))
| Error.Bug (msg, loc_opt) -> raise (Bug (msg,loc_opt))
| Error.Run (msg, loc_opt) -> raise (Run (msg,loc_opt))
......@@ -112,7 +111,7 @@ let load_gr file =
else
handle ~name:"load_gr" ~file
(fun () ->
let gr_ast = Grew_parser.gr_of_file file in
let gr_ast = Loader.gr file in
G_graph.build gr_ast
) ()
......@@ -283,7 +282,7 @@ type pattern = Rule.pattern
type matching = Rule.matching
let load_pattern file =
handle ~name:"load_pattern" (fun () -> Rule.build_pattern (Grew_parser.load_pattern file)) ()
handle ~name:"load_pattern" (fun () -> Rule.build_pattern (Loader.pattern file)) ()
let match_in_graph pattern graph = Rule.match_in_graph pattern graph
......
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