ppx_nanocaml

Framework for writing nanopass-style compilers
IN THIS PACKAGE
Module Nanocaml . Lang
type np_type =
| NP_term of Ast.core_type(*

external types are "terminals" *

*)
| NP_nonterm of string(*

named nonterminal *

*)
| NP_tuple of np_type list(*

t * u * ... *

*)
| NP_list of np_type(*

t list *

*)

a type recognized by nanopass; usually a part of a production. e.g. string, stmt, (string * expr) list *

type np_production = {
nppr_name : string;
nppr_arg : np_type option;
}

a production is one of the forms in a nonterminal -- essentially just a variant, e.g. `Var, `App. *

type np_nonterm = {
npnt_loc : Ast.Location.t;
npnt_name : string;
npnt_productions : np_production list;
}

a nonterminal is a type defined by a nanopass language, e.g. expr, stmt. *

type np_language = {
npl_loc : Ast.Location.t;
npl_name : string;
npl_nonterms : np_nonterm list;
}

a nanopass language, e.g. L0, L1 (as traditionally named) *

val string_of_type : np_type -> string
val languages : ( string, np_language ) Batteries.Hashtbl.t

global table of all defined languages. *

val add_language : np_language -> unit

globally registers the given language. raises Location.Error if a language with the same name is already defined. *

val find_language : ?exn:exn -> string -> np_language

returns the language with the given name. raises Not_found if no such language has been defined. *

val language_nonterm : ?exn:exn -> np_language -> string -> np_nonterm

language_nonterm l name returns the nonterminal in language l with the given name. raises Not_found if no such nonterminal.

val type_of_core_type : nt_names:string list -> Ast.core_type -> np_type

convert core_type into nanopass type. *

val production_of_row_field : nt_names:string list -> Ast.row_field -> np_production

convert row_field (from polymorphic variant) into nanopass production *

val nonterm_of_type_decl : ?extending:np_language -> nt_names:string list -> Ast.type_declaration -> np_nonterm

convert type_declaration into nanopass nonterminal *

val language_of_module : Ast.module_binding -> np_language

convert module_binding into nanopass language *