syntax icon indicating copy to clipboard operation
syntax copied to clipboard

Simplify parsing and printing attributes of function and arguments

Open mununki opened this issue 2 years ago • 5 comments

Regarding issue https://github.com/rescript-lang/rescript-compiler/issues/5735

This PR improves the parsing and printing attributes of functions and arguments so that it makes the implementation simple and clear for future development extensibility.

mununki avatar Oct 15 '22 10:10 mununki

Parsing looks okay now, but the printing error is due to an infinite loop.

let f12 = @a (@b x) => 3
let f13 = @a @b (~x) => 3
  structure_item (tests/printer/expr/asyncAwait.res[97,2562+0]..[97,2562+24])
    Pstr_value Nonrec
    [
      <def>
        pattern (tests/printer/expr/asyncAwait.res[97,2562+4]..[97,2562+7])
          Ppat_var "f12" (tests/printer/expr/asyncAwait.res[97,2562+4]..[97,2562+7])
        expression (tests/printer/expr/asyncAwait.res[97,2562+13]..[97,2562+24])
          attribute "a" (tests/printer/expr/asyncAwait.res[97,2562+10]..[97,2562+12])
            []
          Pexp_fun
          Nolabel
          None
          pattern (tests/printer/expr/asyncAwait.res[97,2562+17]..[97,2562+18])
            attribute "b" (tests/printer/expr/asyncAwait.res[97,2562+14]..[97,2562+16])
              []
            Ppat_var "x" (tests/printer/expr/asyncAwait.res[97,2562+17]..[97,2562+18])
          expression (tests/printer/expr/asyncAwait.res[97,2562+23]..[97,2562+24])
            Pexp_constant PConst_int (3,None)
    ]
  structure_item (tests/printer/expr/asyncAwait.res[98,2587+0]..[98,2587+25])
    Pstr_value Nonrec
    [
      <def>
        pattern (tests/printer/expr/asyncAwait.res[98,2587+4]..[98,2587+7])
          Ppat_var "f13" (tests/printer/expr/asyncAwait.res[98,2587+4]..[98,2587+7])
        expression (tests/printer/expr/asyncAwait.res[98,2587+16]..[98,2587+25])
          attribute "a" (tests/printer/expr/asyncAwait.res[98,2587+10]..[98,2587+12])
            []
          attribute "b" (tests/printer/expr/asyncAwait.res[98,2587+13]..[98,2587+15])
            []
          Pexp_fun
          Labelled "x"
          None
          pattern (tests/printer/expr/asyncAwait.res[98,2587+17]..[98,2587+19])
            attribute "ns.namedArgLoc" (tests/printer/expr/asyncAwait.res[98,2587+18]..[98,2587+19])
              []
            Ppat_var "x" (tests/printer/expr/asyncAwait.res[98,2587+17]..[98,2587+19])
          expression (tests/printer/expr/asyncAwait.res[98,2587+24]..[98,2587+25])
            Pexp_constant PConst_int (3,None)
    ]

mununki avatar Oct 15 '22 10:10 mununki

The body returned should be "3" in both cases.

cristianoc avatar Oct 15 '22 10:10 cristianoc

Needs to always make progress, and put together a group of args.

cristianoc avatar Oct 15 '22 10:10 cristianoc

expression (tests/printer/expr/asyncAwait.res[97,2562+23]..[97,2562+24]) Pexp_constant PConst_int (3,None)

          expression (tests/printer/expr/asyncAwait.res[97,2562+23]..[97,2562+24])
            Pexp_constant PConst_int (3,None)

I think this is the body returns "3"

mununki avatar Oct 15 '22 10:10 mununki

I ran a test of the compiler with the syntax submodule checked out to this branch. The test result looks fine.

$ make test-all

mununki avatar Oct 16 '22 04:10 mununki

Rebaed to master to resolve the confict in the test txt

mununki avatar Oct 16 '22 13:10 mununki

Rebased to master

mununki avatar Nov 04 '22 15:11 mununki

moved to compiler repo

cristianoc avatar Nov 08 '22 04:11 cristianoc