Skip to content

Commit e6ba2cb

Browse files
committed
Merge pull request #315 from gsvgit/StructuredFormatDocumentation
Short documentation for Text.StructuredFormat is added.
2 parents 29f78ed + fc68eba commit e6ba2cb

2 files changed

Lines changed: 48 additions & 1 deletion

File tree

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
// ----------------------------------------------------------------------------
2+
// F# structured format example.
3+
// (c) Semyon Grigorev, 2014, Available under Apache 2.0 license.
4+
// ----------------------------------------------------------------------------
5+
6+
// This example demonstrates how to use printer combinator library.
7+
8+
#r @"../../bin/v4.0/FSharpx.Core.dll"
9+
#r @"..\..\bin\v4.0\FSharpx.Text.StructuredFormat.dll"
10+
11+
open Microsoft.FSharp.Text.StructuredFormat
12+
open Microsoft.FSharp.Text.StructuredFormat.LayoutOps
13+
14+
let stmt i = wordL <| "stmt_" + string i
15+
16+
let stmtBlock k =
17+
[for i in 0 .. k -> stmt i]
18+
|> List.reduce (@@)
19+
20+
let layout =
21+
let condBlock = wordL "if" ^^ bracketL (wordL "cond")
22+
let thenBlock = wordL "then" @@- (stmtBlock 2)
23+
let elseBlock = wordL "else" @@- (stmtBlock 3)
24+
condBlock
25+
@@ thenBlock
26+
@@ elseBlock
27+
28+
let str = Display.layout_to_string FormatOptions.Default layout
29+
30+
printfn "%s" str
31+
32+
(*
33+
Expectesd result:
34+
35+
if (cond)
36+
then
37+
stmt_0
38+
stmt_1
39+
stmt_2
40+
else
41+
stmt_0
42+
stmt_1
43+
stmt_2
44+
stmt_3
45+
46+
*)

docs/content/index.fsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ These are some adhoc components which are now rarely used:
2929
3030
* FSharpx.Http provides a few features for working with HTTP applications.
3131
* FSharpx.Observable implements a mini-Reactive Extensions (MiniRx) and was authored by Phil Trelford.
32-
* FSharpx.Text.StructuredFormat provides data structures and functoins for pretty printers.
32+
* FSharpx.Text.StructuredFormat provides data structures and functoins for pretty printers. Combinators description: https://github.com/fsprojects/fsharpx/blob/master/src/FSharpx.Text.StructuredFormat/StructuredFormat.fsi
3333
3434
3535
*)
@@ -63,6 +63,7 @@ FSharpx.Collections.List.monoid
6363
* [Santa](Santa.html)
6464
* [StmSample](StmSample.html)
6565
* [StockStream](StockStream.html)
66+
* [StructuredFormatSample](StructuredFormatSample.html)
6667
* [UndoSample](UndoSample.html)
6768
* [WebProxy](WebProxy.html)
6869

0 commit comments

Comments
 (0)