Skip to content
This repository
tag: v135
Fetching contributors…

Octocat-spinner-32-eaf2f5

Cannot retrieve contributors at this time

file 114 lines (90 sloc) 2.745 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 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113
(*
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/>.
*)
(**
Printer for JsAst, and functor for serialization of js.
@author Maxime Audoin (previous version)
@author Mathieu Barbin, adapted for OPA from ocamljs/jslib
*)

(**
exported because used by:
??
*)
val string_of_ident : JsAst.ident -> string

val escape_string : ?double_quote:bool -> string -> string

(** {6 Pretty printer} *)

(**
Standard pprinter type
*)
type 'a pprinter = Format.formatter -> 'a -> unit

(**
For standard js only. Such opa construction, as 'hole' are not supported by this printer ( [assert false] )
*)
class printer :
object
  method ident : JsAst.ident pprinter
  method unop : JsAst.unop pprinter
  method field : string pprinter
  method objpart : (string * JsAst.expr) pprinter
  method pexpr : leading:bool -> int -> JsAst.expr pprinter
  method block : JsAst.statement list pprinter
  method expr : leading:bool -> JsAst.expr pprinter
  method statements : JsAst.statement list pprinter
  method statement : JsAst.statement pprinter
  method code : JsAst.code pprinter
end

val pp : printer

(** same as pp, but prints the blocks instead of hiding them *)
val debug_pp : printer

(** {6 Stringfier} *)

(**
TODO:
who does need this ?
maybe do not export this.
*)

(**
code
*)
val code : JsAst.code -> string

(** {6 Partial Printer} *)

(**
Js Runtime Serializer.

This is used for serializing js with some hole.
Hole correspond to different kind of lexems which evaluates as string representing
js code as concrete syntax.
*)

module type X =
sig
  (**
The type of one lexem
*)
  type lexem
  type t
  val append : t -> lexem -> t
  val empty : t


  (** {6 Nodes} *)
  (**
We can extend this interface, if we need more precise js ast at runtime.
Invariant: in the returned t, there are no 2 successives lexem verbatim.
*)

  val ident : string -> lexem
  val verbatim : string -> lexem
  val qml : QmlAst.expr -> lexem
  val serialized : JsAstRuntime.expr -> lexem list
end

module type S =
sig
  type t
  val code_elt : JsAst.code_elt -> t
end

module Make : functor (X : X) -> S with type t = X.t
Something went wrong with that request. Please try again.