Skip to content

Commit 56d8bcf

Browse files
committed
Reason V4 [Stacked Diff 3/n #2614] [Parse Hashtags for polymorphic variants]
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:
1 parent 5ee062e commit 56d8bcf

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

46 files changed

+1911
-359
lines changed

formatTest/typeCheckedTests/expected_output/arityConversion.re

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
[@reason.version 3.7];
2+
23
Some((1, 2, 3));
34

45
type bcd =

formatTest/typeCheckedTests/expected_output/attributes.re

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,9 @@
77
* This has a nice side effect when printing the terms:
88
* If a node has attributes attached to it,
99
*/;
10-
[@reason.version 3.7];
1110

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

1414
/**
1515
* Core language features:
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
/**
2+
* Even if you have an explicit v3.6 marker.
3+
* This whole file wil be auto-upaded to 3.8 becase something uses
4+
* angle brackets.
5+
*/;
6+
[@reason.version 3.8];
7+
let watchThisIsOldStyle: list<int> = [1, 2];
8+
9+
let watchThisIsOldStylePoly = #hello;
10+
11+
/**
12+
* This will cause the whole file to be promoted.
13+
*/
14+
let x: list<int> = [1, 3];
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
[@reason.version 3.8];
2+
/**
3+
* Test auto-promotion based on feature inference even if no version
4+
* tag. By default you're using the old 3.7.
5+
*/
6+
let watchThisIsOldStyle: list<int> = [1, 2];
7+
8+
let watchThisIsOldStylePoly = #hello;
9+
10+
/**
11+
* This will cause the whole file to be promoted.
12+
*/
13+
let x: list<int> = [1, 3];
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
[@reason.version 3.7];
2+
/**
3+
* This should just print a 3.7 version attr at the top.
4+
*/
5+
let watchThisIsOldStyle: list(int) = [1, 2];

formatTest/typeCheckedTests/expected_output/comments.re

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,9 @@
11
/* **** comment */
22
/*** comment */
3-
/** docstring */;
3+
/*** docstring */
44
[@reason.version 3.7];
5-
65
/* comment */
7-
/** docstring */;
6+
/*** docstring */
87
/*** comment */
98
/**** comment */
109
/***** comment */

formatTest/typeCheckedTests/expected_output/comments.rei

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,14 @@
11
/* **** comment */
22
/*** comment */
33
/*** docstring */
4+
[@reason.version 3.7];
45
/* comment */
56
/*** docstring */
67
/*** comment */
78
/**** comment */
89
/***** comment */
910

1011
/** */;
11-
[@reason.version 3.7];
12-
1312
/*** */
1413
/**** */
1514

formatTest/typeCheckedTests/expected_output/mlSyntax.re

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
/* Copyright (c) 2015-present, Facebook, Inc. All rights reserved. */
22

3-
/**
3+
/***
44
* Testing pattern matching using ml syntax to exercise nesting of cases.
5-
*/;
5+
*/
66
[@reason.version 3.7];
77

88
type xyz =

formatTest/typeCheckedTests/expected_output/oo_3_dot_8.re

Lines changed: 41 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,36 @@
22

33
[@reason.version 3.8];
44

5+
type canStillDefineConst =
6+
| []
7+
| ::(int, canStillDefineConst);
8+
59
class virtual stack <'a> (init) = {
10+
as self;
611
/*
712
* The "as this" is implicit and will be formatted away.
813
*/
914
val virtual dummy: unit;
1015
val mutable v: list<'a> = init;
1116
pub virtual implementMe: int => int;
17+
pub is_empty = () =>
18+
switch (v) {
19+
| [] => true
20+
| _ => false
21+
};
22+
pub is_empty_unitless =
23+
switch (v) {
24+
| [] => true
25+
| _ => false
26+
};
27+
pub empty_unitless = {
28+
v = [];
29+
self;
30+
};
31+
pub empty = () => {
32+
v = [];
33+
self;
34+
};
1235
pub pop =
1336
switch (v) {
1437
| [hd, ...tl] =>
@@ -90,6 +113,15 @@ class extendedStackAcknowledgeOverride
90113

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

116+
let wasItFull =
117+
!inst::empty()::empty_unitless::is_empty();
118+
// this is the same
119+
let wasItFull' =
120+
!inst::empty()::empty_unitless::is_empty();
121+
122+
let orig_not = (!);
123+
let (!) = o => o::empty();
124+
93125
/**
94126
* Recursive classes.
95127
*/
@@ -195,7 +227,7 @@ let acceptsOpenAnonObjAsArg =
195227
y: int,
196228
},
197229
) =>
198-
o#x + o#y;
230+
o::x + o::y;
199231
let acceptsClosedAnonObjAsArg =
200232
(
201233
o: {
@@ -204,7 +236,7 @@ let acceptsClosedAnonObjAsArg =
204236
y: int,
205237
},
206238
) =>
207-
o#x + o#y;
239+
o::x + o::y;
208240
let res =
209241
acceptsOpenAnonObjAsArg({
210242
pub x = 0;
@@ -346,13 +378,13 @@ let x: tupleClass<int, int> = {
346378
pub pr = (10, 10)
347379
};
348380

349-
let x: #tupleClass<int, int> = x;
381+
let x: *tupleClass<int, int> = x;
350382

351383
let incrementMyClassInstance:
352-
(int, #tupleClass<int, int>) =>
353-
#tupleClass<int, int> =
384+
(int, *tupleClass<int, int>) =>
385+
*tupleClass<int, int> =
354386
(i, inst) => {
355-
let (x, y) = inst#pr;
387+
let (x, y) = inst::pr;
356388
{pub pr = (x + i, y + i)};
357389
};
358390

@@ -361,7 +393,7 @@ class myClassWithNoTypeParams = {};
361393
* The #myClassWithNoTypeParams should be treated as "simple"
362394
*/
363395
type optionalMyClassSubtype<'a> =
364-
option<#myClassWithNoTypeParams> as 'a;
396+
option<*myClassWithNoTypeParams> as 'a;
365397

366398
/**
367399
* Remember, "class type" is really "class_instance_type" (which is the type of
@@ -398,7 +430,7 @@ class addablePoint:
398430
one: addablePointClassType,
399431
two: addablePointClassType,
400432
) =>
401-
one#x + two#x + one#y + two#x;
433+
one::x + two::x + one::y + two::x;
402434
pub x: int = init;
403435
pub y = init;
404436
};
@@ -412,7 +444,7 @@ class addablePoint2:
412444
one: addablePointClassType,
413445
two: addablePointClassType,
414446
) =>
415-
one#x + two#x + one#y + two#x;
447+
one::x + two::x + one::y + two::x;
416448
pub x: int = init;
417449
pub y = init;
418450
};

formatTest/typeCheckedTests/expected_output/typeParameters.re

Lines changed: 22 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,33 @@
11
/**
22
* Testing type parameters.
33
*/;
4-
[@reason.version 3.7];
4+
[@reason.version 3.8];
55

6-
type threeThings('t) = ('t, 't, 't);
7-
type listOf('t) = list('t);
6+
module type ListItem = {let x: int;};
87

9-
type underscoreParam(_) =
8+
let myListOfModules: list<module ListItem> = [];
9+
10+
type threeThings<'t> = ('t, 't, 't);
11+
type listOf<'t> = list<'t>;
12+
13+
type underscoreParam<_> =
1014
| Underscored;
11-
type underscoreParamCovariance(+_) =
15+
type underscoreParamCovariance<+_> =
1216
| Underscored;
13-
type underscoreParamContravariance(-_) =
17+
type underscoreParamContravariance<-_> =
1418
| Underscored;
1519

16-
type tickParamCovariance(+'a) =
20+
type tickParamCovariance<+'a> =
1721
| Underscored;
18-
type tickParamContravariance(-'a) =
22+
type tickParamContravariance<-'a> =
1923
| Underscored;
2024

21-
let x: option(list('a)) = None;
22-
type myFunctionType('a) = (
23-
list(('a, 'a)),
24-
int => option(list('a)),
25+
let x: option<list<'a>> = None;
26+
type myFunctionType<'a> = (
27+
list<('a, 'a)>,
28+
int => option<list<'a>>,
2529
);
26-
let funcAnnoted = (~a: list(int)=[0, 1], ()) => a;
30+
let funcAnnoted = (~a: list<int>=[0, 1], ()) => a;
2731

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

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

49-
type t('a) = 'a;
50-
let optionArg = (~arg: option(t(int))=?, ()) => arg;
53+
type t<'a> = 'a;
54+
let optionArg = (~arg: option<t<int>>=?, ()) => arg;
5155
let optionArgList =
52-
(~arg: option(list(list(int)))=?, ()) => arg;
53-
let defaultJsxArg = (~arg: t(int)=<jsx />, ()) => arg;
54-
let defaultFalse = (~arg: t(bool)=!true, ()) => arg;
56+
(~arg: option<list<list<int>>>=?, ()) => arg;
57+
let defaultJsxArg = (~arg: t<int>=<jsx />, ()) => arg;
58+
let defaultFalse = (~arg: t<bool>=!true, ()) => arg;
5559
/* Doesn't work on master either let defaultTrue = (~arg:t<bool>= !!true) => arg; */
5660

5761
/**

0 commit comments

Comments
 (0)