Commit a9879267 authored by POTTIER Francois's avatar POTTIER Francois

Add [preludes] and [postludes] to the .cmly API.

parent 33362cc5
......@@ -47,10 +47,12 @@ module type GRAMMAR = sig
end
module Grammar : sig
val preludes : string list
val postludes : string list
val basename : string
val parameters : string list (* %parameter declarations *)
val entry_points : (production * lr1) list
val attributes : Attribute.t list
val parameters : string list (* %parameter declarations *)
end
module Terminal : sig
......
......@@ -86,6 +86,8 @@ type lr1_state_def = {
type grammar = {
g_basename : string;
g_preludes : string list;
g_postludes : string list;
g_terminals : terminal_def array;
g_nonterminals : nonterminal_def array;
g_productions : production_def array;
......
......@@ -117,6 +117,8 @@ module Make (G : sig val grammar : grammar end) : GRAMMAR = struct
module Grammar = struct
let basename = grammar.g_basename
let preludes = grammar.g_preludes
let postludes = grammar.g_postludes
let entry_points = grammar.g_entry_points
let attributes = grammar.g_attributes
let parameters = grammar.g_parameters
......
open UnparameterizedSyntax
open Grammar
open Cmly_format
......@@ -135,6 +136,8 @@ let entry_point prod node xs : (production * lr1) list =
let encode () : grammar =
{
g_basename = Settings.base;
g_preludes = List.map raw_content Front.grammar.preludes;
g_postludes = List.map raw_content Front.grammar.postludes;
g_terminals = Terminal.init terminal;
g_nonterminals = Nonterminal.init nonterminal;
g_productions = Production.init production;
......@@ -142,7 +145,7 @@ let encode () : grammar =
g_lr1_states = Array.of_list (Lr1.map lr1_state);
g_entry_points = ProductionMap.fold entry_point Lr1.entry [];
g_attributes = attributes Analysis.attributes;
g_parameters = List.map raw_content Front.grammar.UnparameterizedSyntax.parameters;
g_parameters = List.map raw_content Front.grammar.parameters;
}
let write oc t =
......
(* [write filename] queries the module [Grammar] for information about the
grammar and queries the modules [Lr0] and [Lr1] for information about the
automaton. It writes this information to the .cmly file [filename]. *)
(* [write filename] queries the modules [Front] and [Grammar] for information
about the grammar and queries the modules [Lr0] and [Lr1] for information
about the automaton. It writes this information to the .cmly file
[filename]. *)
val write: string -> unit
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