Skip to content

Commit 549f961

Browse files
committed
Add new parser rule and syntax tree tests
1 parent b7ffcf8 commit 549f961

File tree

5 files changed

+162
-0
lines changed

5 files changed

+162
-0
lines changed

src/Compiler/pars.fsy

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4107,6 +4107,22 @@ moreBinders:
41074107
let trivia = { AndBangKeyword = rhs parseState 1; EqualsRange = mEquals; InKeyword = Some mIn }
41084108
SynExprAndBang(spBind, $1, true, $2, $4, m, trivia) :: $6 }
41094109

4110+
| AND_BANG headBindingPattern opt_topReturnTypeWithTypeConstraints EQUALS typedSequentialExprBlock IN moreBinders %prec expr_let
4111+
{ // Handle type annotations on patterns in and! bindings
4112+
// Example: and! y: string = asyncString()
4113+
let spBind = DebugPointAtBinding.Yes(rhs2 parseState 1 6)
4114+
let pat =
4115+
match $3 with
4116+
| None -> $2
4117+
| Some (_, SynReturnInfo((ty, _), _)) ->
4118+
parseState.LexBuffer.CheckLanguageFeatureAndRecover LanguageFeature.AllowTypedLetOrUseBang ty.Range
4119+
SynPat.Typed($2, ty, unionRanges $2.Range ty.Range)
4120+
let mEquals = rhs parseState 4
4121+
let m = unionRanges (rhs parseState 1) $5.Range
4122+
let mIn = rhs parseState 6
4123+
let trivia = { AndBangKeyword = rhs parseState 1; EqualsRange = mEquals; InKeyword = Some mIn }
4124+
SynExprAndBang(spBind, false, true, pat, $5, m, trivia) :: $7 }
4125+
41104126
| OAND_BANG headBindingPattern EQUALS typedSequentialExprBlock hardwhiteDefnBindingsTerminator opt_OBLOCKSEP moreBinders %prec expr_let
41114127
{ let report, mIn, _ = $5
41124128
report "and!" (rhs parseState 1) // report unterminated error
@@ -4116,6 +4132,22 @@ moreBinders:
41164132
let trivia = { AndBangKeyword = rhs parseState 1; EqualsRange = mEquals; InKeyword = mIn }
41174133
SynExprAndBang(spBind, $1, true, $2, $4, m, trivia) :: $7 }
41184134

4135+
| OAND_BANG headBindingPattern opt_topReturnTypeWithTypeConstraints EQUALS typedSequentialExprBlock hardwhiteDefnBindingsTerminator opt_OBLOCKSEP moreBinders %prec expr_let
4136+
{ // Handle type annotations on patterns in and! bindings (offside-sensitive version)
4137+
let report, mIn, _ = $6
4138+
report "and!" (rhs parseState 1) // report unterminated error
4139+
let spBind = DebugPointAtBinding.Yes(unionRanges (rhs parseState 1) $5.Range)
4140+
let pat =
4141+
match $3 with
4142+
| None -> $2
4143+
| Some (_, SynReturnInfo((ty, _), _)) ->
4144+
parseState.LexBuffer.CheckLanguageFeatureAndRecover LanguageFeature.AllowTypedLetOrUseBang ty.Range
4145+
SynPat.Typed($2, ty, unionRanges $2.Range ty.Range)
4146+
let mEquals = rhs parseState 4
4147+
let m = unionRanges (rhs parseState 1) $5.Range
4148+
let trivia = { AndBangKeyword = rhs parseState 1; EqualsRange = mEquals; InKeyword = mIn }
4149+
SynExprAndBang(spBind, false, true, pat, $5, m, trivia) :: $8 }
4150+
41194151
| %prec prec_no_more_attr_bindings
41204152
{ [] }
41214153

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
module Module
2+
3+
async {
4+
let! res: int = async { return 1 }
5+
and! res2: int = async { return 2 }
6+
return res
7+
}
Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
ImplFile
2+
(ParsedImplFileInput
3+
("/root/SynType/Typed LetBang AndBang 01.fs", false,
4+
QualifiedNameOfFile Module, [],
5+
[SynModuleOrNamespace
6+
([Module], false, NamedModule,
7+
[Expr
8+
(App
9+
(NonAtomic, false, Ident async,
10+
ComputationExpr
11+
(false,
12+
LetOrUseBang
13+
(Yes (4,4--4,38), false, true,
14+
Typed
15+
(Named (SynIdent (res, None), false, None, (4,9--4,12)),
16+
LongIdent (SynLongIdent ([int], [], [None])),
17+
(4,9--4,17)),
18+
App
19+
(NonAtomic, false, Ident async,
20+
ComputationExpr
21+
(false,
22+
YieldOrReturn
23+
((false, true), Const (Int32 1, (4,35--4,36)),
24+
(4,28--4,36),
25+
{ YieldOrReturnKeyword = (4,28--4,34) }),
26+
(4,26--4,38)), (4,20--4,38)),
27+
[SynExprAndBang
28+
(Yes (5,4--5,39), false, true,
29+
Typed
30+
(Named
31+
(SynIdent (res2, None), false, None, (5,9--5,13)),
32+
LongIdent (SynLongIdent ([int], [], [None])),
33+
(5,9--5,18)),
34+
App
35+
(NonAtomic, false, Ident async,
36+
ComputationExpr
37+
(false,
38+
YieldOrReturn
39+
((false, true), Const (Int32 2, (5,36--5,37)),
40+
(5,29--5,37),
41+
{ YieldOrReturnKeyword = (5,29--5,35) }),
42+
(5,27--5,39)), (5,21--5,39)), (5,4--5,39),
43+
{ AndBangKeyword = (5,4--5,8)
44+
EqualsRange = (5,19--5,20)
45+
InKeyword = None })],
46+
YieldOrReturn
47+
((false, true), Ident res, (6,4--6,14),
48+
{ YieldOrReturnKeyword = (6,4--6,10) }), (4,4--6,14),
49+
{ LetOrUseBangKeyword = (4,4--4,8)
50+
EqualsRange = Some (4,18--4,19) }), (3,6--7,1)),
51+
(3,0--7,1)), (3,0--7,1))],
52+
PreXmlDoc ((1,0), FSharp.Compiler.Xml.XmlDocCollector), [], None,
53+
(1,0--7,1), { LeadingKeyword = Module (1,0--1,6) })], (true, true),
54+
{ ConditionalDirectives = []
55+
WarnDirectives = []
56+
CodeComments = [] }, set []))
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
module Module
2+
3+
async {
4+
let! (res: int) = async { return 1 }
5+
and! (res2: int) = async { return 2 }
6+
return res
7+
}
Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
ImplFile
2+
(ParsedImplFileInput
3+
("/root/SynType/Typed LetBang AndBang 02.fs", false,
4+
QualifiedNameOfFile Module, [],
5+
[SynModuleOrNamespace
6+
([Module], false, NamedModule,
7+
[Expr
8+
(App
9+
(NonAtomic, false, Ident async,
10+
ComputationExpr
11+
(false,
12+
LetOrUseBang
13+
(Yes (4,4--4,40), false, true,
14+
Paren
15+
(Typed
16+
(Named
17+
(SynIdent (res, None), false, None, (4,10--4,13)),
18+
LongIdent (SynLongIdent ([int], [], [None])),
19+
(4,10--4,18)), (4,9--4,19)),
20+
App
21+
(NonAtomic, false, Ident async,
22+
ComputationExpr
23+
(false,
24+
YieldOrReturn
25+
((false, true), Const (Int32 1, (4,37--4,38)),
26+
(4,30--4,38),
27+
{ YieldOrReturnKeyword = (4,30--4,36) }),
28+
(4,28--4,40)), (4,22--4,40)),
29+
[SynExprAndBang
30+
(Yes (5,4--6,10), false, true,
31+
Paren
32+
(Typed
33+
(Named
34+
(SynIdent (res2, None), false, None,
35+
(5,10--5,14)),
36+
LongIdent (SynLongIdent ([int], [], [None])),
37+
(5,10--5,19)), (5,9--5,20)),
38+
App
39+
(NonAtomic, false, Ident async,
40+
ComputationExpr
41+
(false,
42+
YieldOrReturn
43+
((false, true), Const (Int32 2, (5,38--5,39)),
44+
(5,31--5,39),
45+
{ YieldOrReturnKeyword = (5,31--5,37) }),
46+
(5,29--5,41)), (5,23--5,41)), (5,4--5,41),
47+
{ AndBangKeyword = (5,4--5,8)
48+
EqualsRange = (5,21--5,22)
49+
InKeyword = None })],
50+
YieldOrReturn
51+
((false, true), Ident res, (6,4--6,14),
52+
{ YieldOrReturnKeyword = (6,4--6,10) }), (4,4--6,14),
53+
{ LetOrUseBangKeyword = (4,4--4,8)
54+
EqualsRange = Some (4,20--4,21) }), (3,6--7,1)),
55+
(3,0--7,1)), (3,0--7,1))],
56+
PreXmlDoc ((1,0), FSharp.Compiler.Xml.XmlDocCollector), [], None,
57+
(1,0--7,1), { LeadingKeyword = Module (1,0--1,6) })], (true, true),
58+
{ ConditionalDirectives = []
59+
WarnDirectives = []
60+
CodeComments = [] }, set []))

0 commit comments

Comments
 (0)