Skip to content

[Syntax] Convert poly variant from using ` to ##366

Merged
chenglou merged 1 commit into
reasonml:masterfrom
chenglou:sharp-poly
Apr 21, 2016
Merged

[Syntax] Convert poly variant from using ` to ##366
chenglou merged 1 commit into
reasonml:masterfrom
chenglou:sharp-poly

Conversation

@chenglou

Copy link
Copy Markdown
Member

This is a stepping stone to turning interpolated string from {|bla|} to
bla. Which is more familiar to JS devs and frees the weird syntax
error of switch bla {|lol => 1}

Test plan: make test

This is a stepping stone to turning interpolated string from {|bla|} to
`bla`. Which is more familiar to JS devs and frees the weird syntax
error of switch bla {|lol => 1}

Test plan: `make test`
@yunxing

yunxing commented Apr 21, 2016

Copy link
Copy Markdown
Contributor

Looks good to me, feel free to merge.

@chenglou chenglou merged commit cbb748e into reasonml:master Apr 21, 2016
@chenglou chenglou deleted the sharp-poly branch April 21, 2016 08:02
Comment thread src/reason_parser.mly
/* Miscellaneous */

name_tag:
BACKQUOTE ident { $2 }

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm pretty sure this breaks something somewhere.

obj #x

Is that an obj function that you're passing the #x variant to, or is obj an object?

@jordwalke

Copy link
Copy Markdown
Member

Aside from getting this to work with objects, there's a couple of other things:
0. Objects (as I mentioned). We could use this syntax for method calls instead (myObject.myMethod:: arg)

  1. There's a bunch of rules around precedence for sharp. We need to ensure we didn't cause bugs there.
  2. Sharp is used other places (one place that might cause issues.).

chenglou added a commit that referenced this pull request Apr 21, 2016
@SanderSpies

Copy link
Copy Markdown
Contributor

Has there been any consensus yet on how the # will be used? @chenglou asked me to look into this, but I want to make sure it's still on the table to be implemented.

Also if we do want to have this, where can I best start with writing tests?

@hhugo

hhugo commented Jun 11, 2016

Copy link
Copy Markdown

How does the following convert to Reason ?

type t = [ `a | `b ]
type u = [ t | `c ]
let f = function
  | #t -> 1
  | `c -> 2

@SanderSpies

SanderSpies commented Jun 11, 2016

Copy link
Copy Markdown
Contributor

On my machine it converts to:

type t = [ | `a | `b];
type u = [ t | `c];

let f =
  fun
  | #t => 1
  | `c => 2;

I don't think we have tests for this yet - at least a quick search for # within formatTests didn't show this scenario.

@hhugo

hhugo commented Jun 11, 2016

Copy link
Copy Markdown

@SanderSpies, this doesn't reflect this very PR (which is marked as merged).

@SanderSpies

Copy link
Copy Markdown
Contributor

@hhugo It was reverted.

@hhugo

hhugo commented Jun 11, 2016

Copy link
Copy Markdown

got it.

@braibant

Copy link
Copy Markdown

Regarding switch bla {|lol => 1}, how do you plan to support the identifiers part of quoted/interpolated strings in reason? http://caml.inria.fr/pub/docs/manual-ocaml/extn.html#sec249

This makes it possible to have an arbitrary number of string litteral delimiters (which is nice when nesting those interpolated strings), and there was plans to use those identifiers in PPX rewriters IIRC.

@chenglou

Copy link
Copy Markdown
Member Author

JS has the syntax blastuff. Maybe we can use that

@braibant

Copy link
Copy Markdown

Can you give an example of how this works?

@braibant

Copy link
Copy Markdown

Note that int_of_string"1" works in OCaml, and I do not see how this would go with the backtick proposal.

@hcarty

hcarty commented Feb 6, 2017

Copy link
Copy Markdown
Contributor

How would

{foo|foo`|foo}

translate, as a concrete example?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

8 participants