Commit e868c879 authored by POTTIER Francois's avatar POTTIER Francois

Added [CodeBits.listiflazy].

Replaced a few redundant tests [if Settings.table then ...]
with assertions [assert Settings.table].
parent 8b99f461
......@@ -17,6 +17,12 @@ let elementif condition x =
else
[]
let listiflazy condition xs =
if condition then
xs()
else
[]
(* The unit type. *)
let tunit =
......
......@@ -3,11 +3,17 @@
open IL
(* A list subject to a condition. *)
(* A list subject to a condition. (Be careful, though: the list is
of course constructed even if the condition is false.) *)
val listif: bool -> 'a list -> 'a list
val elementif: bool -> 'a -> 'a list
(* A lazy version of [listif], where the list is constructed only
if the condition is true. *)
val listiflazy: bool -> (unit -> 'a list) -> 'a list
(* Standard types. *)
val tunit: typ
......
......@@ -68,7 +68,7 @@ let interface grammar = [
(* The incremental engine and API. *)
listif Settings.table [
listiflazy Settings.table (fun () -> [
IIComment "The incremental API.";
IIModule (
interpreter,
......@@ -85,11 +85,11 @@ let interface grammar = [
(incremental symbol, entrytypescheme_incremental grammar symbol) :: decls
) grammar.start_symbols []
)
] @
]) @
(* The inspection API. *)
listif Settings.table (
listiflazy Settings.table (fun () ->
TokenType.tokengadtdef grammar @
NonterminalType.nonterminalgadtdef grammar @
SymbolType.symbolgadtdef grammar @
......
......@@ -22,37 +22,34 @@ let tnonterminalgadtdata nt =
exception MissingOCamlType
let nonterminalgadtdef grammar =
if Settings.table then
try
let datadefs =
List.fold_left (fun defs nt ->
let index =
match ocamltype_of_symbol grammar nt with
| Some t ->
TypTextual t
| None ->
raise MissingOCamlType
in
{
dataname = tnonterminalgadtdata nt;
datavalparams = [];
datatypeparams = Some [ index ]
} :: defs
) [] (nonterminals grammar)
in
[
IIComment "The indexed type of nonterminal symbols.";
IITypeDecls [{
typename = tcnonterminalgadt;
typeparams = [ "_" ];
typerhs = TDefSum datadefs;
typeconstraint = None
}]
]
with MissingOCamlType ->
(* If the type of some nonterminal symbol is unknown, give up
on the whole thing. *)
[]
else
assert Settings.table;
try
let datadefs =
List.fold_left (fun defs nt ->
let index =
match ocamltype_of_symbol grammar nt with
| Some t ->
TypTextual t
| None ->
raise MissingOCamlType
in
{
dataname = tnonterminalgadtdata nt;
datavalparams = [];
datatypeparams = Some [ index ]
} :: defs
) [] (nonterminals grammar)
in
[
IIComment "The indexed type of nonterminal symbols.";
IITypeDecls [{
typename = tcnonterminalgadt;
typeparams = [ "_" ];
typerhs = TDefSum datadefs;
typeconstraint = None
}]
]
with MissingOCamlType ->
(* If the type of some nonterminal symbol is unknown, give up
on the whole thing. *)
[]
......@@ -21,6 +21,7 @@ let dataN =
(* The definition of the symbol GADT. *)
let symbolgadtdef grammar =
assert Settings.table;
(* This definition can be produced only if we are successfully able
to construct the nonterminal GADT. *)
match NonterminalType.nonterminalgadtdef grammar with
......
......@@ -71,37 +71,35 @@ let tokentypedef grammar =
GADTs. *)
let tokengadtdef grammar =
if Settings.table then
let datadefs =
StringMap.fold (fun token properties defs ->
if properties.tk_is_declared then
let index =
match properties.tk_ocamltype with
| None ->
tunit
| Some t ->
TypTextual t
in
{
dataname = ttokengadtdata token;
datavalparams = [];
datatypeparams = Some [ index ]
} :: defs
else
defs
) grammar.tokens []
in
[
IIComment "The indexed type of terminal symbols.";
IITypeDecls [{
typename = tctokengadt;
typeparams = [ "_" ];
typerhs = TDefSum datadefs;
typeconstraint = None
}]
]
else
[]
assert Settings.table;
let datadefs =
StringMap.fold (fun token properties defs ->
if properties.tk_is_declared then
let index =
match properties.tk_ocamltype with
| None ->
tunit
| Some t ->
TypTextual t
in
{
dataname = ttokengadtdata token;
datavalparams = [];
datatypeparams = Some [ index ]
} :: defs
else
defs
) grammar.tokens []
in
[
IIComment "The indexed type of terminal symbols.";
IITypeDecls [{
typename = tctokengadt;
typeparams = [ "_" ];
typerhs = TDefSum datadefs;
typeconstraint = None
}]
]
(* If we were asked to only produce a type definition, then
do so and stop. *)
......@@ -116,7 +114,9 @@ let produce_tokentypes grammar =
let i =
tokentypedef grammar @
tokengadtdef grammar
listiflazy Settings.table (fun () ->
tokengadtdef grammar
)
in
let module P =
......
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