Skip to content

Support tuple data parsing #28

@cushionbadak

Description

@cushionbadak

Feature Proposal

Purpose

Current MicSE parser does not support tuple pattern of data which can be replaced to right-comb pair.

Expectation

  • Parser should accept following example storage value:
(Pair 
(Pair { Elt 1 (Pair   (Pair "tz1gjaF81ZRRvdzjobyfVNsAeSC6PScjfQwN" "tz1KqTpEZ7Yob7QbPE4Hy4Wo8fHG8LhKxZSx") 0x501000000026869) } 0)
 2 50)

where the tuple appeared as (Pair (...) 2 50).

  • Above example's parameter & storage type
parameter
    (or (or (pair %buy (option %initial_controller address) (bytes %profile)) (unit %skip))
        (or (pair %update_details
               (pair (int %id) (option %new_controller address))
               (option %new_profile bytes))
            (pair %update_owner (int %id) (address %new_owner)))) ;
  storage
    (pair (pair (big_map %identities
                   int
                   (pair (pair (address %controller) (address %owner)) (bytes %profile)))
                (mutez %name_price))
          (int %next_id)
          (mutez %skip_price)) ;

Plan

  • We can add data-pair-comb constructor at michParser.mly Line-28, something like type-pair-comb consturctor at Line-21-27

    MicSE/lib/michParser.mly

    Lines 21 to 27 in d5a27c4

    let construct_pair_comb : (typ t list) -> (typ t)
    = let rec foldf = function
    | [] | (_ :: []) -> Stdlib.failwith "Parser.mly : construct_pair_comb : length < 2"
    | [h1; h2] -> gen_t (T_pair (h1, h2))
    | hd :: tl -> gen_t (T_pair (hd, foldf tl))
    in
    fun ttl -> foldf ttl

  • The code will be something like this:

let construct_data_pair_comb : (data t list) -> (data t)
= let rec foldf = function
    | [] | (_ :: []) ->  Stdlib.failwith "Parser.mly : construct_data_pair_comb : length < 2"
    | [h1; h2] -> gen_t (D_pair (h1,h2))
    | hd :: tl -> gen_t (D_pair (hd, foldf tl))
  in
  fun ttl -> foldf ttl
  • We should use above construct_data_pair_comb function as a parsing rule, replace
    | PAIR a=annots d_1=data d_2=data { gen_t_a a (D_pair (d_1, d_2)) }
    to below rule:
| PAIR a=annots d_l=nonempty_list(data) { gen_t_a a (construct_data_pair_comb (d_l)).d }

Reference

  • Example (data & type) is provided by Hyun Do Jeong.

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions