Skip to content

Commit

Permalink
Add support for while! (fsprojects#2977)
Browse files Browse the repository at this point in the history
* Update FCS

* Add support for while!

* Add changelog entry for alpha 2.
  • Loading branch information
nojaf committed Nov 7, 2023
1 parent 500cd96 commit b2d0215
Show file tree
Hide file tree
Showing 7 changed files with 55 additions and 2 deletions.
8 changes: 8 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,13 @@
# Changelog

## 6.3.0-alpha-002 - 2023-11-07

### Changed
* Update FCS to 'Bugfix for underscore dot lambda: Forbidding expressions not based on the implied _ arg', commit f42bdae84727fc251a6e570c2f1c47a3deffe215

### Added
* Add support for `while!`. [#2977](https://github.com/fsprojects/fantomas/pull/2977)

## 6.3.0-alpha-001 - 2023-11-03

### Changed
Expand Down
2 changes: 1 addition & 1 deletion Directory.Build.props
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ Some common use cases include:

<!-- Versions -->
<PropertyGroup>
<FCSCommitHash>97a5b6584b54707e3e8541fe758e1aa22132a8fe</FCSCommitHash>
<FCSCommitHash>f42bdae84727fc251a6e570c2f1c47a3deffe215</FCSCommitHash>
<StreamJsonRpcVersion>2.8.28</StreamJsonRpcVersion>
<FSharpCoreVersion>6.0.1</FSharpCoreVersion>
</PropertyGroup>
Expand Down
2 changes: 2 additions & 0 deletions build.fsx
Original file line number Diff line number Diff line change
Expand Up @@ -257,6 +257,8 @@ pipeline "Init" {
"src/Compiler/Utilities/TaggedCollections.fs"
"src/Compiler/Utilities/illib.fsi"
"src/Compiler/Utilities/illib.fs"
"src/Compiler/Utilities/Cancellable.fsi"
"src/Compiler/Utilities/Cancellable.fs"
"src/Compiler/Utilities/FileSystem.fsi"
"src/Compiler/Utilities/FileSystem.fs"
"src/Compiler/Utilities/ildiag.fsi"
Expand Down
32 changes: 32 additions & 0 deletions src/Fantomas.Core.Tests/ControlStructureTests.fs
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,38 @@ let lookForValue value maxValue =
lookForValue 10 20
"""

[<Test>]
let ``while bang`` () =
formatSourceString
false
"""
let goThroughFsharpTicketsAsync() = task {
let mutable ticketNumber = 1
while! doesTicketExistAsync ticketNumber do
printfn $"Found a PR or issue #{ticketNumber}."
ticketNumber <- ticketNumber + 1
printfn $"#{ticketNumber} is not created yet."
}
"""
config
|> prepend newline
|> should
equal
"""
let goThroughFsharpTicketsAsync () =
task {
let mutable ticketNumber = 1
while! doesTicketExistAsync ticketNumber do
printfn $"Found a PR or issue #{ticketNumber}."
ticketNumber <- ticketNumber + 1
printfn $"#{ticketNumber} is not created yet."
}
"""

[<Test>]
let ``try/with block`` () =
formatSourceString
Expand Down
6 changes: 5 additions & 1 deletion src/Fantomas.Core/ASTTransformer.fs
Original file line number Diff line number Diff line change
Expand Up @@ -1061,6 +1061,9 @@ let mkExpr (creationAide: CreationAide) (e: SynExpr) : Expr =
| SynExpr.While(_, ew, ed, StartRange 5 (mWhile, _)) ->
ExprWhileNode(stn "while" mWhile, mkExpr creationAide ew, mkExpr creationAide ed, exprRange)
|> Expr.While
| SynExpr.WhileBang(_, ew, ed, StartRange 6 (mWhileBang, _)) ->
ExprWhileNode(stn "while!" mWhileBang, mkExpr creationAide ew, mkExpr creationAide ed, exprRange)
|> Expr.While
| SynExpr.For(_, _, ident, Some equalsRange, e1, isUp, e2, e3, StartRange 3 (mFor, _)) ->
ExprForNode(
stn "for" mFor,
Expand Down Expand Up @@ -1726,7 +1729,8 @@ let mkPat (creationAide: CreationAide) (p: SynPat) =
| None -> unionRanges ident.idRange pat.Range
| Some prefix -> unionRanges prefix.Range pat.Range

PatRecordField(prefix, mkIdent ident, stn "=" eq, mkPat creationAide pat, range))
let eqNode = stn "=" (Option.defaultValue Range.Zero eq)
PatRecordField(prefix, mkIdent ident, eqNode, mkPat creationAide pat, range))

PatRecordNode(stn "{" o, fields, stn "}" c, patternRange) |> Pattern.Record
| SynPat.Const(c, r) -> mkConstant creationAide c r |> Pattern.Const
Expand Down
6 changes: 6 additions & 0 deletions src/Fantomas.FCS/Fantomas.FCS.fsproj
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,12 @@
<Compile Include="..\..\.deps\$(FCSCommitHash)\src\Compiler\Utilities\illib.fs">
<Link>Utilities\illib.fs</Link>
</Compile>
<Compile Include="..\..\.deps\$(FCSCommitHash)\src\Compiler\Utilities\Cancellable.fsi">
<Link>Utilities\Cancellable.fsi</Link>
</Compile>
<Compile Include="..\..\.deps\$(FCSCommitHash)\src\Compiler\Utilities\Cancellable.fs">
<Link>Utilities\Cancellable.fs</Link>
</Compile>
<Compile Include="..\..\.deps\$(FCSCommitHash)\src\Compiler\Utilities\FileSystem.fsi">
<Link>Utilities\FileSystem.fsi</Link>
</Compile>
Expand Down
1 change: 1 addition & 0 deletions src/Fantomas.FCS/Parse.fs
Original file line number Diff line number Diff line change
Expand Up @@ -745,6 +745,7 @@ let getSyntaxErrorMessage ctxt =
| Parser.TOKEN_INLINE -> getErrorString "Parser.TOKEN.INLINE"
| Parser.TOKEN_WHEN -> getErrorString "Parser.TOKEN.WHEN"
| Parser.TOKEN_WHILE -> getErrorString "Parser.TOKEN.WHILE"
| Parser.TOKEN_WHILE_BANG -> getErrorString "Parser.TOKEN.WHILE.BANG"
| Parser.TOKEN_WITH -> getErrorString "Parser.TOKEN.WITH"
| Parser.TOKEN_IF -> getErrorString "Parser.TOKEN.IF"
| Parser.TOKEN_DO -> getErrorString "Parser.TOKEN.DO"
Expand Down

0 comments on commit b2d0215

Please sign in to comment.