Commit fcd9b610 authored by Alain Mebsout's avatar Alain Mebsout Committed by Benjamin Canou

Michelson: annotations must start with `_a-zA-Z` or be empty

Empty annotations are used to mean no annotation, or as a wildcard when destructing pairs for instance.
parent 6dacd8f6
......@@ -2149,8 +2149,9 @@ Syntax
Primitive applications can receive one or many annotations.
An annotation is a sequence of characters that matches the regular
expression ``[\@\:\%\$][_0-9a-zA-Z\.]*``. They come after the primitive
name and before its potential arguments for primitive applications.
expression ``[@:%](|[_a-ZA-Z][_0-9a-zA-Z\.]*)``. They come after the
primitive name and before its potential arguments for primitive
applications.
::
......@@ -2169,6 +2170,12 @@ For instance these two annotated instructions are equivalent:
PAIR %x %y :t @my_pair
An annotation can be empty, in this case is will mean *no annotation*
and can be used as a wildcard. For instance, it is useful to annotate
only the right field of a pair instruction ``PAIR % %right`` or to
ignore field access constraints, *e.g.* in the macro ``UNPPAIPAIR %x1 %
%x3 %x4``.
Annotations and Macros
~~~~~~~~~~~~~~~~~~~~~~
......@@ -2320,11 +2327,11 @@ Micheline expressions are encoded in JSON like this:
``[ expr, ... ]``
- A primitive application is an object with two fields ``"prim"`` for
- A primitive application is an object with two fields ``"prim"`` for
the primitive name and ``"args"`` for the arguments (that must
contain an array). A third optional field ``"annots"`` contains
a list of annotations, including their leading ``@``, ``%``, ``%`` or
``$`` sign.
contain an array). A third optional field ``"annots"`` contains a
list of annotations, including their leading ``@``, ``%`` or ``%``
sign.
``{ "prim": "pair", "args": [ { "prim": "nat", "args": [] }, { "prim":
"nat", "args": [] } ], "annots": [":t"] }``
......
......@@ -172,8 +172,8 @@ Overrides `michelson-print-errors' and `michelson-highlight-errors'"
(defconst michelson-font-lock-defaults
(list
(list
'("\\<[\$@][A-Za-z-_0-9\.]*\\>" . michelson-face-var-annotation)
'("\\<[%:][A-Za-z-_0-9\.]*\\>" . michelson-face-type-annotation)
'("\\<[@]\\(\\|[A-Za-z-_][A-Za-z-_0-9\.]*\\)\\>" . michelson-face-var-annotation)
'("\\<[%:]\\(\\|[A-Za-z-_][A-Za-z-_0-9\.]*\\)\\>" . michelson-face-type-annotation)
'("\\<[0-9]+\\>" . michelson-face-constant)
'("\\<[A-Z][a-z_0-9]+\\>" . michelson-face-constant)
'("\\<[A-Z][A-Z_0-9]*\\>" . michelson-face-instruction)
......
parameter (map (int :k) (int :e));
storage (pair (int :k) (int :e));
code { CAR; PUSH @acc_e (int :e) 0; PUSH @acc_k (int :k) 0; PAIR; SWAP;
code { CAR; PUSH @acc_e (int :e) 0; PUSH @acc_k (int :k) 0; PAIR % %r; SWAP;
ITER
{ DIP {DUP; CAR; DIP{CDR}}; DUP; # Last instr
DIP{CAR; ADD}; SWAP; DIP{CDR; ADD}; PAIR };
DIP{CAR; ADD}; SWAP; DIP{CDR; ADD}; PAIR % %r };
NIL operation; PAIR}
parameter unit;
storage unit;
code { UNIT; UNIT; UNIT; UNIT; UNIT;
PAPAPAPAIR @name %1 %2 %3 %4 %5;
CDDDAR %4 @fourth;
PAPAPAPAIR @name %x1 %x2 %x3 %x4 %x5;
CDDDAR %x4 @fourth;
DROP; CDR; NIL operation; PAIR}
parameter (unit :param_unit);
storage (unit :u1);
code { DROP ;
UNIT :u4 @4; UNIT :u3 @3; UNIT :u2 @2; UNIT :u1 @1;
CAST unit ; CAST (unit :u1);
UNIT :u4 @a4; UNIT :u3 @a3; UNIT :u2 @a2; UNIT :u1 @a1;
PAIR; UNPAIR @x1 @x2;
PPAIPAIR @p1 %x1 %x2 %x3 %x4; UNPPAIPAIR @uno @due @tre @quattro;
PPAIPAIR @p1 %x1 %x2 %x3 %x4; UNPPAIPAIR %x1 % %x3 %x4 @uno @due @tre @quattro;
PAPAPAIR @p2 %x1 %x2 %x3 %x4; UNPAPAPAIR @un @deux @trois @quatre;
PAPPAIIR @p3 %x1 %x2 %x3 %x4; UNPAPPAIIR @one @two @three @four;
DIP { DROP; DROP; DROP }; NIL operation; PAIR }
\ No newline at end of file
......@@ -350,7 +350,6 @@ let expand_pappaiir original =
match i, IntMap.find_opt i field_annots_pos with
| 0, None -> annot
| _, None -> []
(* XXX Hackish, cannot annotate cdr only with PAIR *)
| 0, Some ([], cdr_annot) -> "%" :: cdr_annot @ annot
| _, Some ([], cdr_annot) -> "%" :: cdr_annot
| 0, Some (car_annot, cdr_annot) -> car_annot @ cdr_annot @ annot
......
......@@ -79,12 +79,12 @@ val error_unexpected_annot : int -> 'a list -> unit tzresult
(** Same as {!error_unexpected_annot} in Lwt. *)
val fail_unexpected_annot : int -> 'a list -> unit tzresult Lwt.t
(** Parse string annotations. *)
val parse_annots : int -> string list -> annot list tzresult
(** Parse a type annotation only. *)
val parse_type_annot : int -> string list -> type_annot option tzresult
val parse_field_annot :
int -> string list -> field_annot option tzresult
(** Parse an annotation for composed types, of the form
[:ty_name %field1 %field2] in any order. *)
val parse_composed_type_annot :
......@@ -109,20 +109,18 @@ val check_correct_field :
val parse_var_annot :
int ->
?default:var_annot option ->
string list -> var_annot option tzresult Lwt.t
val parse_field_annot :
int -> string list -> field_annot option tzresult Lwt.t
string list -> var_annot option tzresult
val parse_constr_annot :
int -> string list ->
(var_annot option * type_annot option * field_annot option * field_annot option) tzresult Lwt.t
(var_annot option * type_annot option *
field_annot option * field_annot option) tzresult
val parse_two_var_annot :
int -> string list -> (var_annot option * var_annot option) tzresult Lwt.t
int -> string list -> (var_annot option * var_annot option) tzresult
val parse_var_field_annot :
int -> string list -> (var_annot option * field_annot option) tzresult Lwt.t
int -> string list -> (var_annot option * field_annot option) tzresult
val parse_var_type_annot :
int -> string list -> (var_annot option * type_annot option) tzresult Lwt.t
int -> string list -> (var_annot option * type_annot option) tzresult
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment