Commit 83463c31 authored by Nicolás Ojeda Bär's avatar Nicolás Ojeda Bär Committed by POTTIER Francois

Load stdlib grammar from embedded standard.mly

parent ed40ca11
......@@ -17,6 +17,16 @@
(* Reading a grammar from a file. *)
let load_grammar_from_contents filename contents =
InputFile.with_file_contents contents (fun () ->
let open Lexing in
let lexbuf = Lexing.from_string contents in
lexbuf.lex_curr_p <- { lexbuf.lex_curr_p with pos_fname = filename };
(* the grammar: *)
{ (Driver.grammar Lexer.main lexbuf)
with Syntax.pg_filename = filename }
)
let load_partial_grammar filename : Syntax.partial_grammar =
let validExt = if Settings.coq then ".vy" else ".mly" in
if not (Filename.check_suffix filename validExt) then
......@@ -27,14 +37,7 @@ let load_partial_grammar filename : Syntax.partial_grammar =
try
let contents = IO.read_whole_file filename in
InputFile.with_file_contents contents (fun () ->
let open Lexing in
let lexbuf = Lexing.from_string contents in
lexbuf.lex_curr_p <- { lexbuf.lex_curr_p with pos_fname = filename };
(* the grammar: *)
{ (Driver.grammar Lexer.main lexbuf)
with Syntax.pg_filename = filename }
)
load_grammar_from_contents filename contents
with Sys_error msg ->
Error.error [] "%s" msg
......@@ -44,7 +47,15 @@ let load_partial_grammar filename : Syntax.partial_grammar =
(* Read all of the grammar files that are named on the command line. *)
let grammars : Syntax.partial_grammar list =
List.map load_partial_grammar Settings.filenames
let grammars () = List.map load_partial_grammar Settings.filenames in
if Settings.no_stdlib || Settings.coq then
grammars ()
else begin
InputFile.new_input_file Settings.stdlib_filename;
let standard_grammar =
load_grammar_from_contents Settings.stdlib_filename Standard_mly.contents in
standard_grammar :: grammars ()
end
let () =
Time.tick "Lexing and parsing"
......
......@@ -448,7 +448,7 @@ let () =
(* Export the settings. *)
let stdlib_filename =
!stdlib_path ^ "/standard.mly"
"<standard.mly>"
let filenames =
StringSet.elements !filenames
......@@ -467,12 +467,6 @@ let base =
else
!base
let filenames =
if !no_stdlib || !coq then
filenames
else
stdlib_filename :: filenames
let token_type_mode =
!token_type_mode
......@@ -548,6 +542,9 @@ let () =
exit 1
end
let no_stdlib =
!no_stdlib
let coq =
!coq
......
......@@ -159,6 +159,10 @@ val table : bool
val inspection : bool
(* Whether the standard menhir library should be used. *)
val no_stdlib : bool
(* Whether to generate a coq description of the grammar and automaton. *)
val coq : bool
......
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