Melange_compiler_libs.Parse
Entry points in the parser
Warning: this module is unstable and part of compiler-libs.
let implementation: Stdlib.Lexing.lexbuf => Parsetree.structure;
let interface: Stdlib.Lexing.lexbuf => Parsetree.signature;
let toplevel_phrase: Stdlib.Lexing.lexbuf => Parsetree.toplevel_phrase;
let use_file: Stdlib.Lexing.lexbuf => list(Parsetree.toplevel_phrase);
let core_type: Stdlib.Lexing.lexbuf => Parsetree.core_type;
let expression: Stdlib.Lexing.lexbuf => Parsetree.expression;
let pattern: Stdlib.Lexing.lexbuf => Parsetree.pattern;
let module_type: Stdlib.Lexing.lexbuf => Parsetree.module_type;
let module_expr: Stdlib.Lexing.lexbuf => Parsetree.module_expr;
The functions below can be used to parse Longident safely.
The function longident
is guaranteed to parse all subclasses of Longident.t
used in OCaml: values, constructors, simple or extended module paths, and types or module types.
However, this function accepts inputs which are not accepted by the compiler, because they combine functor applications and infix operators. In valid OCaml syntax, only value-level identifiers may end with infix operators Foo.( + )
. Moreover, in value-level identifiers the module path Foo
must be simple (M.N
rather than F(X)
): functor applications may only appear in type-level identifiers. As a consequence, a path such as F(X).( + )
is not a valid OCaml identifier; but it is accepted by this function.
The next functions are specialized to a subclass of Longident.t
This function parses a syntactically valid path for a value. For instance, x
, M.x
, and (+.)
are valid. Contrarily, M.A
, F(X).x
, and true
are rejected.
Longident for OCaml's value cannot contain functor application. The last component of the Longident.t
is not capitalized, but can be an operator A.Path.To.(.%.%.(;..)<-)
This function parses a syntactically valid path for a variant constructor. For instance, A
, M.A
and M.(::)
are valid, but both M.a
and F(X).A
are rejected.
Longident for OCaml's variant constructors cannot contain functor application. The last component of the Longident.t
is capitalized, or it may be one the special constructors: true
,false
,()
,[]
,(::)
. Among those special constructors, only (::)
can be prefixed by a module path (A.B.C.(::)
).
This function parses a syntactically valid path for a module. For instance, A
, and M.A
are valid, but both M.a
and F(X).A
are rejected.
Longident for OCaml's module cannot contain functor application. The last component of the Longident.t
is capitalized.
This function parse syntactically valid path for an extended module. For instance, A.B
and F(A).B
are valid. Contrarily, (.%())
or []
are both rejected.
The last component of the Longident.t
is capitalized.
This function parse syntactically valid path for a type or a module type. For instance, A
, t
, M.t
and F(X).t
are valid. Contrarily, (.%())
or []
are both rejected.
In path for type and module types, only operators and special constructors are rejected.