Skip to content
This repository
tag: v811
Fetching contributors…

Cannot retrieve contributors at this time

file 97 lines (74 sloc) 3.125 kb
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97
(*
Copyright © 2011 MLstate

This file is part of OPA.

OPA is free software: you can redistribute it and/or modify it under the
terms of the GNU Affero General Public License, version 3, as published by
the Free Software Foundation.

OPA is distributed in the hope that it will be useful, but WITHOUT ANY
WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for
more details.

You should have received a copy of the GNU Affero General Public License
along with OPA. If not, see <http://www.gnu.org/licenses/>.
*)
(**
High-level interface to the opa parser.
*)

(**
This module defines a higher-level interface for calling the trx opa parser.
It defines as well utils using cache, and reports errors using located messages.
*)

(** {6 Types Alias} *)

(**
Just for clarty, to avoid confusion between filenames, contents, etc...
*)
type filename = string
type contents = string

type nonuid = SurfaceAst.nonuid

(** {6 Meta-informations} *)

(**
Hash of all trx, ml and mli use to generate the parser
Currently : general/surfaceAst.ml and passes/syntax/*.{trx,ml}.
Used in particular to know if the cache are relevant from a compilation
of the compiler to an other.
*)
val hash : string

(** {6 Low-Level Parsing} *)

(**
These function are just a call to the trx parser.
They may raise [Trx_runtime.SyntaxError].
[ll_] stands for [low_level].

The given filename is optional, and given to trx, used for errors messages only.
*)

val ll_expr : ?filename:filename -> contents -> (nonuid, SurfaceAst.parsing_directive) SurfaceAst.expr
val ll_ty : ?filename:filename -> contents -> nonuid SurfaceAst.ty
val ll_code : ?filename:filename -> contents -> (nonuid, SurfaceAst.parsing_directive) SurfaceAst.code

(** {6 High-level Parsing} *)

(**
These function catch the trx runtime error and print a citation of the source,
before exiting using the function [error] (TODO: use OManager).
*)

val expr : ?filename:filename -> contents -> (nonuid, SurfaceAst.parsing_directive) SurfaceAst.expr
val ty : ?filename:filename -> contents -> nonuid SurfaceAst.ty

(**
Used with [cache:true], the function will set/get a cache of the parsed AST from
[{mlstate_dir}/opa/cache/parser].
(Default is [cache:false])
*)
val code : ?cache:bool -> ?filename:filename -> contents -> (nonuid, SurfaceAst.parsing_directive) SurfaceAst.code

(** {6 Deprecated API} *)

(**
The rest of the API was done before the introduction of guidelines.
Please do not use in new code.
*)

exception Specific_parse_error of (FilePos.pos * string)

exception No_such_file of string

(**
[parse_file filename]
Read the file corresponding to the given filename and parse it
@param filename The name of the file to be parsed
@raise Trx_runtime.SyntaxError see above
@raise Trx_runtime.ExceptionDuringParsing see above
@raise No_such_file The given filename cannot be read
*)
val parse_file : filename -> (string,SurfaceAst.parsing_directive) SurfaceAst.code
Something went wrong with that request. Please try again.