-
Notifications
You must be signed in to change notification settings - Fork 38
Simplify parsing and printing attributes of function and arguments #683
Conversation
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
|
The body returned should be "3" in both cases. |
Needs to always make progress, and put together a group of args. |
I think this is the body returns "3" |
4b2a3b4
to
d7f80a4
Compare
let f12 = @a (@b x) => 3 | ||
let f13 = @a @b (~x) => 3 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It looks printing okay now.
@@ -106,7 +106,7 @@ let _ = await { | |||
|
|||
let f1 = async (~x, ~y) => x + y | |||
let f2 = async (@foo ~x, @bar ~y) => x + y | |||
let f3 = async (@bar @foo ~x as @zz z, ~y) => x + y | |||
let f3 = @foo async (~x as @bar @zz z, ~y) => x + y |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not sure about this expression @attr1 ~x as @attr2 y
.
If we parse the attributes inside (...)
, the attributes are going to be ppat_attributes
, the printer emits ~x as @attr1 @attr2 y
What do you think?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks fine. There's only one place for attributes on labels.
Js.log("This function should be named 'TopLevel.react'") | ||
ReactDOMRe.createDOMElementVariadic("div", []) | ||
} | ||
@warning("-16") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This warning is added to pexp_attributes
by JSX v3.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Parsing and printing should not change anything for JSX right?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actually, this is printing change. The ast is not changed.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don’t think the printing changes of JSX output would be a problem unless the ast is changed. What do you think?
I’ll check the js ouput for this case.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
JSX is never printed
I ran a test of the compiler with the syntax submodule checked out to this branch. The test result looks fine.
|
@@ -1534,12 +1534,6 @@ and parseParameter p = | |||
then | |||
let startPos = p.Parser.startPos in | |||
let uncurried = Parser.optional p Token.Dot in | |||
(* two scenarios: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we move this comment/mental model to the appropriate place?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
0990331
to
a567272
Compare
Rebaed to master to resolve the confict in the test txt |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Starting to look at this. For post v10.1 release.
Would you rebase on master?
src/res_core.ml
Outdated
Asttypes.Labelled lblName, | ||
Ast_helper.Pat.var ~attrs:[propLocAttr] ~loc | ||
Ast_helper.Pat.var ~attrs:([propLocAttr] @ attrs) ~loc |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Use ::
not @
src/res_core.ml
Outdated
@@ -1569,25 +1569,29 @@ and parseParameter p = | |||
let pat = | |||
let pat = Ast_helper.Pat.var ~loc (Location.mkloc lblName loc) in | |||
let loc = mkLoc startPos p.prevEndPos in | |||
Ast_helper.Pat.constraint_ ~attrs:[propLocAttr] ~loc pat typ | |||
Ast_helper.Pat.constraint_ ~attrs:([propLocAttr] @ attrs) ~loc pat |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Use ::
not @
@@ -106,7 +106,7 @@ let _ = await { | |||
|
|||
let f1 = async (~x, ~y) => x + y | |||
let f2 = async (@foo ~x, @bar ~y) => x + y | |||
let f3 = async (@bar @foo ~x as @zz z, ~y) => x + y | |||
let f3 = @foo async (~x as @bar @zz z, ~y) => x + y |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks fine. There's only one place for attributes on labels.
- print attributes respectively
- of how to parse function parameters and attributes
a567272
to
779a1b8
Compare
Rebased to master |
moved to compiler repo |
Regarding issue rescript-lang/rescript#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.