Reason: Class type ppx attributes disappear

Created on 24 Aug 2016  路  3Comments  路  Source: reasonml/reason

Repro ocaml code:

class type _y = object 
  method height : int [@@bs.set {no_get}]
  (* [height] is setter only *)
end [@bs]

No attributes when converted. Related: #693

GOOD FIRST TASK

Most helpful comment

How to attack this problem for first time contributor:

  • Install reason according to the readme page.
  • create a ocaml file test.ml, with the content
class type _y = object 
  method height : int [@@bs.set {no_get}]
end [@bs]
  • run refmt -parse ml -print re try.ml, notice that the [@bs] attributes are disappeared from the output.

You job is to change "reason_pprint_ast.ml" so the conversion preserves the attributes.

All 3 comments

How to attack this problem for first time contributor:

  • Install reason according to the readme page.
  • create a ocaml file test.ml, with the content
class type _y = object 
  method height : int [@@bs.set {no_get}]
end [@bs]
  • run refmt -parse ml -print re try.ml, notice that the [@bs] attributes are disappeared from the output.

You job is to change "reason_pprint_ast.ml" so the conversion preserves the attributes.

Hi! I would like to claim this issue :)
I have started investigating, and found the old closed PR that fixes this. However this causes indentation issues.

I printed the intermediate easy-format representation and found there because of the fix, there is a attach_std_attrs call that wraps it in another list. I have yet to figure out how to fix this, but would like to jot down my findings here. Thanks!

This is the fixed output:

 List: open  close  sep  break Force_breaks_rec 
   List: open  close  sep  break Force_breaks_rec 
     Atom:''
     Label (break = Auto): 
       left 
       List: open  close  sep  break No_breaks 
         Label (break = Auto): 
           left 
           Atom:'class type'
           right 
           Atom:'_y'
         Atom:'='
       right 
       List: open  close  sep  break No_breaks  <<< here is the extra enclosing List
         List: open { close } sep  break Force_breaks_rec 
           Label (break = Auto): 
             left 
             Label (break = Auto): 
               left 
               Atom:'pub'
               right 
               List: open  close  sep  break Never_wrap 
                 Atom:'height:'
             right 
             List: open  close  sep  break No_breaks 
               Atom:'int'
         List: open  close  sep  break Never_wrap 
           List: open  close  sep  break No_breaks 
             Atom:'[@bs]'
             Atom:';'

This is the original output

 List: open  close  sep  break Force_breaks_rec                                                                                                                                                           [2/69]
   List: open  close  sep  break Force_breaks_rec 
     Atom:''
     Label (break = Auto): 
       left 
       List: open  close  sep  break No_breaks 
         Label (break = Auto): 
           left 
           Atom:'class type'
           right 
           Atom:'_y'
         Atom:'='
       right 
       List: open { close }; sep  break Force_breaks_rec 
         Label (break = Auto): 
           left 
           Label (break = Auto): 
             left 
             Atom:'pub'
             right 
             List: open  close  sep  break Never_wrap 
               Atom:'height:'
           right 
           List: open  close  sep  break No_breaks 
             Atom:'int'

Thank you, @ngzhian.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

jberdine picture jberdine  路  3Comments

TheSpyder picture TheSpyder  路  3Comments

rickyvetter picture rickyvetter  路  4Comments

TrakBit picture TrakBit  路  3Comments

bluddy picture bluddy  路  3Comments