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