2017-09-29 18:20:10 +04:00
|
|
|
(**************************************************************************)
|
|
|
|
(* *)
|
2018-02-06 00:17:03 +04:00
|
|
|
(* Copyright (c) 2014 - 2018. *)
|
2017-09-29 18:20:10 +04:00
|
|
|
(* Dynamic Ledger Solutions, Inc. <contact@tezos.com> *)
|
|
|
|
(* *)
|
|
|
|
(* All rights reserved. No warranty, explicit or implicit, provided. *)
|
|
|
|
(* *)
|
|
|
|
(**************************************************************************)
|
|
|
|
|
2018-05-16 20:46:55 +04:00
|
|
|
type annot = string list
|
|
|
|
|
2017-09-29 18:20:10 +04:00
|
|
|
(** The abstract syntax tree of Micheline expressions. The first
|
|
|
|
parameter is used to conatin locations, but can also embed custom
|
|
|
|
data. The second parameter is the type of primitive names. *)
|
|
|
|
type ('l, 'p) node =
|
2018-03-28 22:42:10 +04:00
|
|
|
| Int of 'l * Z.t
|
2017-09-29 18:20:10 +04:00
|
|
|
| String of 'l * string
|
2018-05-16 20:46:55 +04:00
|
|
|
| Prim of 'l * 'p * ('l, 'p) node list * annot
|
2018-05-17 21:37:25 +04:00
|
|
|
| Seq of 'l * ('l, 'p) node list
|
2017-09-29 18:20:10 +04:00
|
|
|
|
|
|
|
(** Encoding for expressions, as their {!canonical} encoding.
|
2018-03-14 14:36:09 +04:00
|
|
|
Locations are stored in a side table.
|
|
|
|
See {!canonical_encoding} for the [variant] parameter. *)
|
|
|
|
val table_encoding : variant:string ->
|
2017-09-29 18:20:10 +04:00
|
|
|
'l Data_encoding.encoding -> 'p Data_encoding.encoding ->
|
|
|
|
('l, 'p) node Data_encoding.encoding
|
|
|
|
|
|
|
|
(** Encoding for expressions, as their {!canonical} encoding.
|
|
|
|
Locations are erased when serialized, and restored to a provided
|
2018-03-14 14:36:09 +04:00
|
|
|
default value when deserialized.
|
|
|
|
See {!canonical_encoding} for the [variant] parameter. *)
|
|
|
|
val erased_encoding : variant:string ->
|
2017-09-29 18:20:10 +04:00
|
|
|
'l -> 'p Data_encoding.encoding -> ('l, 'p) node Data_encoding.encoding
|
|
|
|
|
|
|
|
(** Extract the location of the node. *)
|
|
|
|
val location : ('l, 'p) node -> 'l
|
|
|
|
|
2018-05-17 21:37:25 +04:00
|
|
|
(** Extract the annotations of the node. *)
|
|
|
|
val annotations : ('l, 'p) node -> string list
|
2017-09-29 18:20:10 +04:00
|
|
|
|
|
|
|
(** Expression form using canonical integer numbering as
|
|
|
|
locations. The root has number zero, and each node adds one in the
|
|
|
|
order of infix traversal. To be used when locations are not
|
|
|
|
important, or when one wants to attach properties to nodes in an
|
|
|
|
expression without rewriting it (using an indirection table with
|
|
|
|
canonical locations as keys). *)
|
|
|
|
type 'p canonical
|
|
|
|
|
|
|
|
(** Canonical integer locations that appear inside {!canonical} expressions. *)
|
|
|
|
type canonical_location = int
|
|
|
|
|
|
|
|
(** Encoding for canonical integer locations. *)
|
|
|
|
val canonical_location_encoding : canonical_location Data_encoding.encoding
|
|
|
|
|
2018-03-14 14:36:09 +04:00
|
|
|
(** Encoding for expressions in canonical form. The first parameter
|
|
|
|
is a name used to produce named definitions in the schemas. Make
|
|
|
|
sure to use different names if two expression variants with
|
|
|
|
different primitive encodings are used in the same schema. *)
|
|
|
|
val canonical_encoding : variant:string -> 'l Data_encoding.encoding -> 'l canonical Data_encoding.encoding
|
2017-09-29 18:20:10 +04:00
|
|
|
|
|
|
|
(** Compute the canonical form of an expression.
|
|
|
|
Drops the concrete locations completely. *)
|
|
|
|
val strip_locations : (_, 'p) node -> 'p canonical
|
|
|
|
|
|
|
|
(** Give the root node of an expression in canonical form. *)
|
|
|
|
val root : 'p canonical -> (canonical_location, 'p) node
|
|
|
|
|
|
|
|
(** Compute the canonical form of an expression.
|
|
|
|
Saves the concrete locations in an association list. *)
|
|
|
|
val extract_locations : ('l, 'p) node -> 'p canonical * (canonical_location * 'l) list
|
|
|
|
|
|
|
|
(** Transforms an expression in canonical form into a polymorphic one.
|
|
|
|
Takes a mapping function to inject the concrete locations. *)
|
|
|
|
val inject_locations : (canonical_location -> 'l) -> 'p canonical -> ('l, 'p) node
|
|
|
|
|
|
|
|
(** Copies the tree, updating its primitives. *)
|
|
|
|
val map : ('a -> 'b) -> 'a canonical -> 'b canonical
|
|
|
|
|
|
|
|
(** Copies the tree, updating its primitives and locations. *)
|
|
|
|
val map_node : ('la -> 'lb) -> ('pa -> 'pb) -> ('la, 'pa) node -> ('lb, 'pb) node
|