Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
97 changes: 60 additions & 37 deletions src/Compiler/pars.fsy
Original file line number Diff line number Diff line change
Expand Up @@ -3440,10 +3440,13 @@ declExprBlock:
/* for these it only inserts a trailing ORIGHT_BLOCK_END */
typedSequentialExprBlockR:
| typedSequentialExpr ORIGHT_BLOCK_END
{ $1 }
{ fun _ -> $1 }

| typedSequentialExpr
{ $1 }
{ fun _ -> $1 }

| recover
{ fun mStart -> arbExpr ("typedSequentialExprBlockR", mStart) }

typedSequentialExpr:
| sequentialExpr COLON typeWithTypeConstraints
Expand Down Expand Up @@ -3573,36 +3576,49 @@ declExpr:
{ if not $3 then reportParseErrorAt (rhs parseState 1) (FSComp.SR.parsUnexpectedEndOfFileMatch())
// Produce approximate expression during error recovery
exprFromParseError $2 }

| TRY typedSequentialExprBlockR withClauses %prec expr_try
{ let mTry = (rhs parseState 1)

| TRY typedSequentialExprBlockR withClauses %prec expr_try
{ let mTry = rhs parseState 1
let expr = $2 mTry
let spTry = DebugPointAtTry.Yes mTry
let mWith, (clauses, mLast) = $3
let mWith, (clauses, mLast) = $3
let spWith = DebugPointAtWith.Yes mWith
let mTryToWith = unionRanges mTry mWith
let mWithToLast = unionRanges mWith mLast
let mTryToWith = unionRanges mTry mWith
let mWithToLast = unionRanges mWith mLast
let mTryToLast = unionRanges mTry mLast
let trivia: SynExprTryWithTrivia =
let trivia: SynExprTryWithTrivia =
{ TryKeyword = mTry
TryToWithRange = mTryToWith
WithKeyword = mWith
WithToEndRange = mWithToLast }
SynExpr.TryWith ($2, clauses, mTryToLast, spTry, spWith, trivia) }

| TRY typedSequentialExprBlockR recover %prec expr_try
{ // Produce approximate expression during error recovery
// Include any expressions to make sure they gets type checked in case that generates useful results for intellisense
if not $3 then reportParseErrorAt (rhs parseState 1) (FSComp.SR.parsUnexpectedEndOfFileTry())
exprFromParseError $2 }
SynExpr.TryWith (expr, clauses, mTryToLast, spTry, spWith, trivia) }

| TRY typedSequentialExprBlockR FINALLY typedSequentialExprBlock %prec expr_try
{ let mTry = rhs parseState 1
| TRY typedSequentialExprBlockR recover %prec expr_try
{ let mTry = rhs parseState 1
let spTry = DebugPointAtTry.Yes mTry
if not $3 then reportParseErrorAt mTry (FSComp.SR.parsUnexpectedEndOfFileTry ())
let expr = $2 mTry
let mExpr = expr.Range
let mEnd = mExpr.EndRange
let spWith = DebugPointAtWith.Yes mEnd
let mWhole = unionRanges mTry mEnd
let trivia: SynExprTryWithTrivia =
{ TryKeyword = mTry
TryToWithRange = mWhole
WithKeyword = mEnd
WithToEndRange = mWhole }
SynExpr.TryWith (expr, [], mWhole, spTry, spWith, trivia) }

| TRY typedSequentialExprBlockR FINALLY typedSequentialExprBlock %prec expr_try
{ let mTry = rhs parseState 1
let tryExpr = $2 mTry
let spTry = DebugPointAtTry.Yes mTry
let mFinally = rhs parseState 3
let finallyExpr = $4
let spFinally = DebugPointAtFinally.Yes mFinally
let mTryToLast = unionRanges mTry $4.Range
let mTryToLast = unionRanges mTry finallyExpr.Range
let trivia = { TryKeyword = mTry; FinallyKeyword = mFinally }
SynExpr.TryFinally ($2, $4, mTryToLast, spTry, spFinally, trivia) }
SynExpr.TryFinally (tryExpr, finallyExpr, mTryToLast, spTry, spFinally, trivia) }

| IF declExpr ifExprCases %prec expr_if
{ let mIf = rhs parseState 1
Expand Down Expand Up @@ -3856,9 +3872,11 @@ declExpr:
| FIXED declExpr
{ SynExpr.Fixed ($2, (unionRanges (rhs parseState 1) $2.Range)) }

| RARROW typedSequentialExprBlockR
{ errorR(Error(FSComp.SR.parsArrowUseIsLimited(), lhs parseState))
SynExpr.YieldOrReturn ((true, true), $2, (unionRanges (rhs parseState 1) $2.Range)) }
| RARROW typedSequentialExprBlockR
{ errorR(Error(FSComp.SR.parsArrowUseIsLimited(), lhs parseState))
let mArrow = rhs parseState 1
let expr = $2 mArrow
SynExpr.YieldOrReturn ((true, true), expr, (unionRanges mArrow expr.Range)) }

| declExpr COLON_QMARK typ
{ SynExpr.TypeTest ($1, $3, unionRanges $1.Range $3.Range) }
Expand Down Expand Up @@ -4156,11 +4174,12 @@ patternGuard:
| /* EMPTY */
{ None }

patternResult:
| RARROW typedSequentialExprBlockR
{ let mArrow = rhs parseState 1
mArrow, $2 }

patternResult:
| RARROW typedSequentialExprBlockR
{ let mArrow = rhs parseState 1
let expr = $2 mArrow
mArrow, expr }

ifExprCases:
| ifExprThen ifExprElifs
{ let exprThen, mThen = $1
Expand Down Expand Up @@ -4667,8 +4686,10 @@ computationExpr:
{ $1.Range, (fun mLhs -> SynExpr.ComputationExpr (false, $1, mLhs)) }

arrowThenExprR:
| RARROW typedSequentialExprBlockR
{ SynExpr.YieldOrReturn ((true, false), $2, unionRanges (rhs parseState 1) $2.Range) }
| RARROW typedSequentialExprBlockR
{ let mArrow = rhs parseState 1
let expr = $2 mArrow
SynExpr.YieldOrReturn ((true, false), expr, unionRanges mArrow expr.Range) }

forLoopBinder:
| parenPattern IN declExpr
Expand Down Expand Up @@ -5009,15 +5030,17 @@ anonLambdaExpr:
mkSynFunMatchLambdas parseState.SynArgNameGenerator false mAll $2 mArrow (arbExpr("anonLambdaExpr1", (rhs parseState 4))) }

| OFUN atomicPatterns RARROW typedSequentialExprBlockR OEND
{ let mAll = unionRanges (rhs parseState 1) $4.Range
let mArrow = Some (rhs parseState 3)
mkSynFunMatchLambdas parseState.SynArgNameGenerator false mAll $2 mArrow $4 }
{ let mArrow = rhs parseState 3
let expr = $4 mArrow
let mAll = unionRanges (rhs parseState 1) expr.Range
mkSynFunMatchLambdas parseState.SynArgNameGenerator false mAll $2 (Some mArrow) expr }

| OFUN atomicPatterns RARROW typedSequentialExprBlockR recover
{ if not $5 then reportParseErrorAt (rhs parseState 1) (FSComp.SR.parsUnexpectedEndOfFileFunBody());
let mAll = unionRanges (rhs parseState 1) $4.Range
let mArrow = Some (rhs parseState 3)
exprFromParseError (mkSynFunMatchLambdas parseState.SynArgNameGenerator false mAll $2 mArrow $4) }
{ if not $5 then reportParseErrorAt (rhs parseState 1) (FSComp.SR.parsUnexpectedEndOfFileFunBody ())
let mArrow = rhs parseState 3
let expr = $4 mArrow
let mAll = unionRanges (rhs parseState 1) expr.Range
exprFromParseError (mkSynFunMatchLambdas parseState.SynArgNameGenerator false mAll $2 (Some mArrow) expr) }

| OFUN atomicPatterns RARROW ORIGHT_BLOCK_END OEND
{ let mLambda = rhs2 parseState 1 3
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
module Module

(fun _ -> )
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
ImplFile
(ParsedImplFileInput
("/root/Expression/Lambda - Missing expr 01.fs", false,
QualifiedNameOfFile Module, [], [],
[SynModuleOrNamespace
([Module], false, NamedModule,
[Expr
(Paren
(Lambda
(false, false,
SimplePats
([Id (_arg1, None, true, false, false, (3,5--3,6))],
(3,5--3,6)),
ArbitraryAfterError ("anonLambdaExpr2", (3,9--3,9)),
Some
([Wild (3,5--3,6)],
ArbitraryAfterError ("anonLambdaExpr2", (3,9--3,9))),
(3,1--3,9), { ArrowRange = Some (3,7--3,9) }), (3,0--3,1),
Some (3,10--3,11), (3,0--3,11)), (3,0--3,11))],
PreXmlDoc ((1,0), FSharp.Compiler.Xml.XmlDocCollector), [], None,
(1,0--3,11), { LeadingKeyword = Module (1,0--1,6) })], (true, true),
{ ConditionalDirectives = []
CodeComments = [] }, set []))

(3,1)-(3,9) parse error Missing function body
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
module Module

fun _ ->
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
ImplFile
(ParsedImplFileInput
("/root/Expression/Lambda - Missing expr 02.fs", false,
QualifiedNameOfFile Module, [], [],
[SynModuleOrNamespace
([Module], false, NamedModule,
[Expr
(Lambda
(false, false,
SimplePats
([Id (_arg1, None, true, false, false, (3,4--3,5))],
(3,4--3,5)),
ArbitraryAfterError ("anonLambdaExpr2", (3,8--3,8)),
Some
([Wild (3,4--3,5)],
ArbitraryAfterError ("anonLambdaExpr2", (3,8--3,8))),
(3,0--3,8), { ArrowRange = Some (3,6--3,8) }), (3,0--3,8))],
PreXmlDoc ((1,0), FSharp.Compiler.Xml.XmlDocCollector), [], None,
(1,0--3,8), { LeadingKeyword = Module (1,0--1,6) })], (true, true),
{ ConditionalDirectives = []
CodeComments = [] }, set []))

(4,0)-(4,0) parse warning Possible incorrect indentation: this token is offside of context started at position (1:1). Try indenting this token further or using standard formatting conventions.
(3,0)-(3,8) parse error Missing function body
3 changes: 3 additions & 0 deletions tests/service/data/SyntaxTree/Expression/Lambda 01.fs
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
module Module

(fun _ -> ())
19 changes: 19 additions & 0 deletions tests/service/data/SyntaxTree/Expression/Lambda 01.fs.bsl
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
ImplFile
(ParsedImplFileInput
("/root/Expression/Lambda 01.fs", false, QualifiedNameOfFile Module, [], [],
[SynModuleOrNamespace
([Module], false, NamedModule,
[Expr
(Paren
(Lambda
(false, false,
SimplePats
([Id (_arg1, None, true, false, false, (3,5--3,6))],
(3,5--3,6)), Const (Unit, (3,10--3,12)),
Some ([Wild (3,5--3,6)], Const (Unit, (3,10--3,12))),
(3,1--3,12), { ArrowRange = Some (3,7--3,9) }), (3,0--3,1),
Some (3,12--3,13), (3,0--3,13)), (3,0--3,13))],
PreXmlDoc ((1,0), FSharp.Compiler.Xml.XmlDocCollector), [], None,
(1,0--3,13), { LeadingKeyword = Module (1,0--1,6) })], (true, true),
{ ConditionalDirectives = []
CodeComments = [] }, set []))
3 changes: 3 additions & 0 deletions tests/service/data/SyntaxTree/Expression/Lambda 02.fs
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
module Module

fun _ -> ()
17 changes: 17 additions & 0 deletions tests/service/data/SyntaxTree/Expression/Lambda 02.fs.bsl
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
ImplFile
(ParsedImplFileInput
("/root/Expression/Lambda 02.fs", false, QualifiedNameOfFile Module, [], [],
[SynModuleOrNamespace
([Module], false, NamedModule,
[Expr
(Lambda
(false, false,
SimplePats
([Id (_arg1, None, true, false, false, (3,4--3,5))],
(3,4--3,5)), Const (Unit, (3,9--3,11)),
Some ([Wild (3,4--3,5)], Const (Unit, (3,9--3,11))),
(3,0--3,11), { ArrowRange = Some (3,6--3,8) }), (3,0--3,11))],
PreXmlDoc ((1,0), FSharp.Compiler.Xml.XmlDocCollector), [], None,
(1,0--3,11), { LeadingKeyword = Module (1,0--1,6) })], (true, true),
{ ConditionalDirectives = []
CodeComments = [] }, set []))
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
module Module

[ for x in [] -> () ]
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
ImplFile
(ParsedImplFileInput
("/root/Expression/List - Comprehension 01.fs", false,
QualifiedNameOfFile Module, [], [],
[SynModuleOrNamespace
([Module], false, NamedModule,
[Expr
(ArrayOrListComputed
(false,
ForEach
(Yes (3,2--3,5), Yes (3,8--3,10), SeqExprOnly true, true,
Named (SynIdent (x, None), false, None, (3,6--3,7)),
ArrayOrList (false, [], (3,11--3,13)),
YieldOrReturn
((true, false), Const (Unit, (3,17--3,19)), (3,14--3,19)),
(3,2--3,19)), (3,0--3,21)), (3,0--3,21))],
PreXmlDoc ((1,0), FSharp.Compiler.Xml.XmlDocCollector), [], None,
(1,0--3,21), { LeadingKeyword = Module (1,0--1,6) })], (true, true),
{ ConditionalDirectives = []
CodeComments = [] }, set []))
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
module Module

[ for x in [] -> ]
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
ImplFile
(ParsedImplFileInput
("/root/Expression/List - Comprehension 02.fs", false,
QualifiedNameOfFile Module, [], [],
[SynModuleOrNamespace
([Module], false, NamedModule,
[Expr
(ArrayOrListComputed
(false,
ForEach
(Yes (3,2--3,5), Yes (3,8--3,10), SeqExprOnly true, true,
Named (SynIdent (x, None), false, None, (3,6--3,7)),
ArrayOrList (false, [], (3,11--3,13)),
YieldOrReturn
((true, false),
ArbitraryAfterError
("typedSequentialExprBlockR", (3,14--3,16)),
(3,14--3,16)), (3,2--3,16)), (3,0--3,18)), (3,0--3,18))],
PreXmlDoc ((1,0), FSharp.Compiler.Xml.XmlDocCollector), [], None,
(1,0--3,18), { LeadingKeyword = Module (1,0--1,6) })], (true, true),
{ ConditionalDirectives = []
CodeComments = [] }, set []))

(3,17)-(3,18) parse error Incomplete structured construct at or before this point in expression
3 changes: 3 additions & 0 deletions tests/service/data/SyntaxTree/Expression/Rarrow 01.fs
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
module Module

-> 1
15 changes: 15 additions & 0 deletions tests/service/data/SyntaxTree/Expression/Rarrow 01.fs.bsl
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
ImplFile
(ParsedImplFileInput
("/root/Expression/Rarrow 01.fs", false, QualifiedNameOfFile Module, [], [],
[SynModuleOrNamespace
([Module], false, NamedModule,
[Expr
(YieldOrReturn
((true, true), Const (Int32 1, (3,3--3,4)), (3,0--3,4)),
(3,0--3,4))],
PreXmlDoc ((1,0), FSharp.Compiler.Xml.XmlDocCollector), [], None,
(1,0--3,4), { LeadingKeyword = Module (1,0--1,6) })], (true, true),
{ ConditionalDirectives = []
CodeComments = [] }, set []))

(3,0)-(3,4) parse error The use of '->' in sequence and computation expressions is limited to the form 'for pat in expr -> expr'. Use the syntax 'for ... in ... do ... yield...' to generate elements in more complex sequence expressions.
3 changes: 3 additions & 0 deletions tests/service/data/SyntaxTree/Expression/Rarrow 02.fs
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
module Module

->
17 changes: 17 additions & 0 deletions tests/service/data/SyntaxTree/Expression/Rarrow 02.fs.bsl
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
ImplFile
(ParsedImplFileInput
("/root/Expression/Rarrow 02.fs", false, QualifiedNameOfFile Module, [], [],
[SynModuleOrNamespace
([Module], false, NamedModule,
[Expr
(YieldOrReturn
((true, true),
ArbitraryAfterError ("typedSequentialExprBlockR", (3,0--3,2)),
(3,0--3,2)), (3,0--3,2))],
PreXmlDoc ((1,0), FSharp.Compiler.Xml.XmlDocCollector), [], None,
(1,0--3,2), { LeadingKeyword = Module (1,0--1,6) })], (true, true),
{ ConditionalDirectives = []
CodeComments = [] }, set []))

(4,0)-(4,0) parse error Incomplete structured construct at or before this point in expression
(3,0)-(4,0) parse error The use of '->' in sequence and computation expressions is limited to the form 'for pat in expr -> expr'. Use the syntax 'for ... in ... do ... yield...' to generate elements in more complex sequence expressions.
3 changes: 3 additions & 0 deletions tests/service/data/SyntaxTree/Expression/Rarrow 03.fs
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
module Module

-> ->
21 changes: 21 additions & 0 deletions tests/service/data/SyntaxTree/Expression/Rarrow 03.fs.bsl
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
ImplFile
(ParsedImplFileInput
("/root/Expression/Rarrow 03.fs", false, QualifiedNameOfFile Module, [], [],
[SynModuleOrNamespace
([Module], false, NamedModule,
[Expr
(YieldOrReturn
((true, true),
YieldOrReturn
((true, true),
ArbitraryAfterError
("typedSequentialExprBlockR", (3,3--3,5)), (3,3--3,5)),
(3,0--3,5)), (3,0--3,5))],
PreXmlDoc ((1,0), FSharp.Compiler.Xml.XmlDocCollector), [], None,
(1,0--3,5), { LeadingKeyword = Module (1,0--1,6) })], (true, true),
{ ConditionalDirectives = []
CodeComments = [] }, set []))

(4,0)-(4,0) parse error Incomplete structured construct at or before this point in expression
(3,3)-(4,0) parse error The use of '->' in sequence and computation expressions is limited to the form 'for pat in expr -> expr'. Use the syntax 'for ... in ... do ... yield...' to generate elements in more complex sequence expressions.
(3,0)-(4,0) parse error The use of '->' in sequence and computation expressions is limited to the form 'for pat in expr -> expr'. Use the syntax 'for ... in ... do ... yield...' to generate elements in more complex sequence expressions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
module Module

try
with _ -> ()
Loading