Skip to content

Commit

Permalink
Reason V4 [Stacked Diff 3/n #2614] [Parse Hashtags for polymorphic va…
Browse files Browse the repository at this point in the history
…riants]

Summary:

Implements parsing for "hashtags" polymorphic variant constructors.
Since Reason Syntax still supports object syntax, we needed to rearrange
some syntactic real estate to make this work.

```reason
let red = #FF000;

let isRed = color => switch(color) {
  | #FF0000 => true
  | _ => false
};

let callAMethod = someObject::methodName(isRed, "testing red");

let templateLiteral = `
  String template literals are still using backticks.
  String template literals are still using backticks.
`;

```

Test Plan:

Reviewers:

CC:
  • Loading branch information
jordwalke committed Aug 10, 2020
1 parent 5ee062e commit 56d8bcf
Show file tree
Hide file tree
Showing 46 changed files with 1,911 additions and 359 deletions.
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
[@reason.version 3.7];

Some((1, 2, 3));

type bcd =
Expand Down
2 changes: 1 addition & 1 deletion formatTest/typeCheckedTests/expected_output/attributes.re
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@
* This has a nice side effect when printing the terms:
* If a node has attributes attached to it,
*/;
[@reason.version 3.7];

/**Floating comment text should be removed*/;
[@reason.version 3.7];

/**
* Core language features:
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
/**
* Even if you have an explicit v3.6 marker.
* This whole file wil be auto-upaded to 3.8 becase something uses
* angle brackets.
*/;
[@reason.version 3.8];
let watchThisIsOldStyle: list<int> = [1, 2];

let watchThisIsOldStylePoly = #hello;

/**
* This will cause the whole file to be promoted.
*/
let x: list<int> = [1, 3];
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
[@reason.version 3.8];
/**
* Test auto-promotion based on feature inference even if no version
* tag. By default you're using the old 3.7.
*/
let watchThisIsOldStyle: list<int> = [1, 2];

let watchThisIsOldStylePoly = #hello;

/**
* This will cause the whole file to be promoted.
*/
let x: list<int> = [1, 3];
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
[@reason.version 3.7];
/**
* This should just print a 3.7 version attr at the top.
*/
let watchThisIsOldStyle: list(int) = [1, 2];
5 changes: 2 additions & 3 deletions formatTest/typeCheckedTests/expected_output/comments.re
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
/* **** comment */
/*** comment */
/** docstring */;
/*** docstring */
[@reason.version 3.7];

/* comment */
/** docstring */;
/*** docstring */
/*** comment */
/**** comment */
/***** comment */
Expand Down
3 changes: 1 addition & 2 deletions formatTest/typeCheckedTests/expected_output/comments.rei
Original file line number Diff line number Diff line change
@@ -1,15 +1,14 @@
/* **** comment */
/*** comment */
/*** docstring */
[@reason.version 3.7];
/* comment */
/*** docstring */
/*** comment */
/**** comment */
/***** comment */

/** */;
[@reason.version 3.7];

/*** */
/**** */

Expand Down
4 changes: 2 additions & 2 deletions formatTest/typeCheckedTests/expected_output/mlSyntax.re
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
/* Copyright (c) 2015-present, Facebook, Inc. All rights reserved. */

/**
/***
* Testing pattern matching using ml syntax to exercise nesting of cases.
*/;
*/
[@reason.version 3.7];

type xyz =
Expand Down
50 changes: 41 additions & 9 deletions formatTest/typeCheckedTests/expected_output/oo_3_dot_8.re
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,36 @@

[@reason.version 3.8];

type canStillDefineConst =
| []
| ::(int, canStillDefineConst);

class virtual stack <'a> (init) = {
as self;
/*
* The "as this" is implicit and will be formatted away.
*/
val virtual dummy: unit;
val mutable v: list<'a> = init;
pub virtual implementMe: int => int;
pub is_empty = () =>
switch (v) {
| [] => true
| _ => false
};
pub is_empty_unitless =
switch (v) {
| [] => true
| _ => false
};
pub empty_unitless = {
v = [];
self;
};
pub empty = () => {
v = [];
self;
};
pub pop =
switch (v) {
| [hd, ...tl] =>
Expand Down Expand Up @@ -90,6 +113,15 @@ class extendedStackAcknowledgeOverride

let inst = (new extendedStack)([1, 2]);

let wasItFull =
!inst::empty()::empty_unitless::is_empty();
// this is the same
let wasItFull' =
!inst::empty()::empty_unitless::is_empty();

let orig_not = (!);
let (!) = o => o::empty();

/**
* Recursive classes.
*/
Expand Down Expand Up @@ -195,7 +227,7 @@ let acceptsOpenAnonObjAsArg =
y: int,
},
) =>
o#x + o#y;
o::x + o::y;
let acceptsClosedAnonObjAsArg =
(
o: {
Expand All @@ -204,7 +236,7 @@ let acceptsClosedAnonObjAsArg =
y: int,
},
) =>
o#x + o#y;
o::x + o::y;
let res =
acceptsOpenAnonObjAsArg({
pub x = 0;
Expand Down Expand Up @@ -346,13 +378,13 @@ let x: tupleClass<int, int> = {
pub pr = (10, 10)
};

let x: #tupleClass<int, int> = x;
let x: *tupleClass<int, int> = x;

let incrementMyClassInstance:
(int, #tupleClass<int, int>) =>
#tupleClass<int, int> =
(int, *tupleClass<int, int>) =>
*tupleClass<int, int> =
(i, inst) => {
let (x, y) = inst#pr;
let (x, y) = inst::pr;
{pub pr = (x + i, y + i)};
};

Expand All @@ -361,7 +393,7 @@ class myClassWithNoTypeParams = {};
* The #myClassWithNoTypeParams should be treated as "simple"
*/
type optionalMyClassSubtype<'a> =
option<#myClassWithNoTypeParams> as 'a;
option<*myClassWithNoTypeParams> as 'a;

/**
* Remember, "class type" is really "class_instance_type" (which is the type of
Expand Down Expand Up @@ -398,7 +430,7 @@ class addablePoint:
one: addablePointClassType,
two: addablePointClassType,
) =>
one#x + two#x + one#y + two#x;
one::x + two::x + one::y + two::x;
pub x: int = init;
pub y = init;
};
Expand All @@ -412,7 +444,7 @@ class addablePoint2:
one: addablePointClassType,
two: addablePointClassType,
) =>
one#x + two#x + one#y + two#x;
one::x + two::x + one::y + two::x;
pub x: int = init;
pub y = init;
};
Expand Down
40 changes: 22 additions & 18 deletions formatTest/typeCheckedTests/expected_output/typeParameters.re
Original file line number Diff line number Diff line change
@@ -1,29 +1,33 @@
/**
* Testing type parameters.
*/;
[@reason.version 3.7];
[@reason.version 3.8];

type threeThings('t) = ('t, 't, 't);
type listOf('t) = list('t);
module type ListItem = {let x: int;};

type underscoreParam(_) =
let myListOfModules: list<module ListItem> = [];

type threeThings<'t> = ('t, 't, 't);
type listOf<'t> = list<'t>;

type underscoreParam<_> =
| Underscored;
type underscoreParamCovariance(+_) =
type underscoreParamCovariance<+_> =
| Underscored;
type underscoreParamContravariance(-_) =
type underscoreParamContravariance<-_> =
| Underscored;

type tickParamCovariance(+'a) =
type tickParamCovariance<+'a> =
| Underscored;
type tickParamContravariance(-'a) =
type tickParamContravariance<-'a> =
| Underscored;

let x: option(list('a)) = None;
type myFunctionType('a) = (
list(('a, 'a)),
int => option(list('a)),
let x: option<list<'a>> = None;
type myFunctionType<'a> = (
list<('a, 'a)>,
int => option<list<'a>>,
);
let funcAnnoted = (~a: list(int)=[0, 1], ()) => a;
let funcAnnoted = (~a: list<int>=[0, 1], ()) => a;

/**
* Syntax that would be likely to conflict with lexing parsing of < > syntax.
Expand All @@ -46,12 +50,12 @@ let isSuperGreaterThanEqNegFive3 = zero >>= (-5);

let jsx = (~children, ()) => 0;

type t('a) = 'a;
let optionArg = (~arg: option(t(int))=?, ()) => arg;
type t<'a> = 'a;
let optionArg = (~arg: option<t<int>>=?, ()) => arg;
let optionArgList =
(~arg: option(list(list(int)))=?, ()) => arg;
let defaultJsxArg = (~arg: t(int)=<jsx />, ()) => arg;
let defaultFalse = (~arg: t(bool)=!true, ()) => arg;
(~arg: option<list<list<int>>>=?, ()) => arg;
let defaultJsxArg = (~arg: t<int>=<jsx />, ()) => arg;
let defaultFalse = (~arg: t<bool>=!true, ()) => arg;
/* Doesn't work on master either let defaultTrue = (~arg:t<bool>= !!true) => arg; */

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,10 @@
*/;
[@reason.version 3.8];

module type ListItem = {let x: int;};

let myListOfModules: list<module ListItem> = [];

type threeThings<'t> = ('t, 't, 't);
type listOf<'t> = list<'t>;

Expand Down
Loading

0 comments on commit 56d8bcf

Please sign in to comment.