Source

planck / lib / op_prec.mli

(** Tools for operator precedences and associativities *)

module Operator : sig
  type t = {
    prec : float; (** Operator precedence. Bigger is stronger. *)
    kind : [ `Infix of [ `Left | `Right | `Noassoc ]
           | `Postfix 
           | `Prefix
           ];
  }
    
  val prec_app : float
  (** Operator precedence of function application. = 1000.0 *)
  
  val show : t -> string
end

module Make(A : sig
  type t
  type op
  val show_op : op -> string
  val app   : t -> t -> t
  val binop : op -> t -> t -> t
  val unop  : op -> t -> t
end) : sig

  type error = 
    | Ambiguous of Operator.t * A.op option * Operator.t * A.op option
    | Empty
    | NoRightArg of Operator.t * A.op
    | NoLeftArg of Operator.t * A.op

  exception Error of error

  val format_error : Format.formatter -> error -> unit

  (** List parser style *)
  val parse : [ `Op of Operator.t * A.op | `Term of A.t ] list -> A.t

  (** Combinator style *)
  type t

  val terminal : A.t -> t

  val infix    : Operator.t -> A.op option -> t -> t -> t
  (** Second arg: None for function application *)

  val prefix   : Operator.t -> A.op -> t -> t
  val postfix  : Operator.t -> A.op -> t -> t
  val build : t -> A.t
end
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.