The Pcaml module
All about language parsing entries, language printing functions, quotation management at parsing time, extensible directives, extensible options, and generalities about camlp5.
Language parsing
Main parsing functions
The two functions below are called when parsing an interface (.mli
file) or an implementation (.ml file) to build the syntax tree; the
returned list contains the phrases (signature items or structure
items) and their locations; the boolean tells that the parser has
encountered a directive; in this case, since the directive may
change the syntax, the parsing stops, the directive is evaluated,
and this function is called again.
These functions are
references, because they can be changed to use another technology
than the Camlp5 extended grammars. By default, they use the grammars
entries [implem] and [interf] defined above.
- value parse_interf : ref (Stream.t char -> (list (MLast.sig_item * MLast.loc) * bool));
- Function called when parsing an interface (".mli") file
- value parse_implem : ref (Stream.t char -> (list (MLast.str_item * MLast.loc) * bool));
- Function called when parsing an implementation (".ml") file
Grammar
- value gram : Grammar.g;
- Grammar variable of the language.
Entries
Grammar entries which return syntax trees. These are set by the parsing kit of the current syntax, through the statement EXTEND. They are usable by other possible user syntax extensions.
- value expr : Grammar.Entry.e MLast.expr;
- Expressions.
- value patt : Grammar.Entry.e MLast.patt;
- Patterns.
- value ctyp : Grammar.Entry.e MLast.ctyp;
- Types.
- value sig_item : Grammar.Entry.e MLast.sig_item;
- Signature items, i.e. items between "sig" and "end", or inside an interface (".mli") file.
- value str_item : Grammar.Entry.e MLast.str_item;
- Structure items, i.e. items between "struct" and "end", or inside an implementation (".ml") file.
- value module_type : Grammar.Entry.e MLast.module_type;
- Module types, e.g. signatures, functors, identifiers.
- value module_expr : Grammar.Entry.e MLast.module_expr;
- Module expressions, e.g. structures, functors, identifiers.
- value let_binding : Grammar.Entry.e (MLast.patt * MLast.expr);
- Specific entry for the "let binding", i.e. the association "let pattern = expression".
- value type_declaration : Grammar.Entry.e MLast.type_decl;
- Specific entry for the "type declaration", i.e. the association "type name = type-expression"
- value class_sig_item : Grammar.Entry.e MLast.class_sig_item;
- Class signature items, i.e. items of class objects types.
- value class_str_item : Grammar.Entry.e MLast.class_str_item;
- Class structure items, i.e. items of class objects.
- value class_expr : Grammar.Entry.e MLast.class_expr;
- Class expressions, e.g. objects, class functions, identifiers.
- value class_type : Grammar.Entry.e MLast.class_type;
- Class types, e.g. object types, class types functions, identifiers.
- value interf : Grammar.Entry.e (list (MLast.sig_item * MLast.loc) * bool);
- Interface, i.e. files with extension ".mli". The location is the one of the top of the tree. The boolean says whether the parsing stopped because of the presence of a directive (which potentially could change the syntax).
- value implem : Grammar.Entry.e (list (MLast.str_item * MLast.loc) * bool);
- Implementation, i.e. files with extension ".ml". Same remark about the location and the boolean.
- value top_phrase : Grammar.Entry.e (option MLast.str_item);
- Phrases of the ocaml interactive toplevel. Return "None" in case of end of file.
- value use_file : Grammar.Entry.e (list MLast.str_item * bool);
- Phrases in files included by the directive "#use". The boolean indicates whether the parsing stopped because of a directive (like for "interf" below).
Language printing
Main printing functions
The two function below are called when printing an interface (.mli file) of an implementation (.ml file) from the syntax tree; the list is the result of the corresponding parsing function.
- value print_interf : ref (list (MLast.sig_item * MLast.loc) -> unit);
- Function called when printing an interface (".mli") file
- value print_implem : ref (list (MLast.str_item * MLast.loc) -> unit);
- Function called when printing an implementation (".ml") file
Printing context type
This type is defined in the sub-module "Printers" of the "Pcaml" module.
type pr_context 'bef 'aft = { ind : int; bef : 'bef; aft : 'aft; dang : string } ;
-
Type of printing context passed as parameter in all extensible functions doing the printing. It corresponds to a printing of the current line. The fields "bef" and "aft" are generally the "string" type. They are respectively "what has to be printed before" and "what has to be printed after" the printed thing. The field "ind" is the current indentation in number of spaces, and "dang" is the possible dangling token (see "Printing programs").
Printer type
... not described: this type is likely to change in camlp5 soon ...
Printers functions
Defined in the sub-module "Printers" of the "Pcaml" module.
... to be completed ...
value pr_expr : printer_t MLast.expr; value pr_patt : printer_t MLast.patt; value pr_ctyp : printer_t MLast.ctyp; value pr_str_item : printer_t MLast.str_item; value pr_sig_item : printer_t MLast.sig_item; value pr_module_expr : printer_t MLast.module_expr; value pr_module_type : printer_t MLast.module_type; value pr_class_sig_item : printer_t MLast.class_sig_item; value pr_class_str_item : printer_t MLast.class_str_item; value pr_class_type : printer_t MLast.class_type; value pr_class_expr : printer_t MLast.class_expr; value find_pr_level : string -> list (pr_level 'a) -> pr_level 'a; value pr_expr_fun_args : ref (Extfun.t MLast.expr (list MLast.patt * MLast.expr));
Quotation management
- value handle_expr_quotation : MLast.loc -> (string * string) -> MLast.expr;
- Called in the semantic actions of the rules parsing a quotation in position of expression.
- value handle_patt_quotation : MLast.loc -> (string * string) -> MLast.patt;
- Called in the semantic actions of the rules parsing a quotation in position of pattern.
- value quotation_dump_file : ref (option string);
- "Pcaml.quotation_dump_file" optionally tells the compiler to dump the result of an expander (of kind "generating a string") if this result is syntactically incorrect. If "None" (default), this result is not dumped. If "Some fname", the result is dumped in the file "fname". The same effect can be done with the option "-QD" of camlp5 commands.
Extensible directives and options
- type directive_fun = option MLast.expr -> unit;
- The type of functions called to treat a directive with its syntactic parameter. Directives act by side effect.
- value add_directive : string -> directive_fun -> unit;
- Add a new directive.
- value find_directive : string -> directive_fun;
- Find the function associated with a directive. Raises "Not_found" if the directive does not exists.
- value add_option : string -> Arg.spec -> string -> unit;
- Add an option to the command line of the camlp5 command.
Generalities
- value version : string;
- The current version of Camlp5.
- value syntax_name : ref string;
- The name of the current syntax. Set by the loaded syntax kit.
- value input_file : ref string;
- The file currently being parsed.
- value output_file : ref (option string);
- The output file, stdout if None (default).
- value no_constructors_arity : ref bool;
- True if the current syntax does not generate constructor arity, which is the case of the normal syntax, and not of the revised one. This has an impact when converting camlp5 syntax tree into ocaml compiler syntax tree.