@@ -15,8 +15,12 @@ open FSharp.Formatting.Markdown
1515
1616module String =
1717 /// Matches when a string is a whitespace or null
18+ [<return : Struct>]
1819 let (| WhiteSpace | _ |) ( s ) =
19- if String.IsNullOrWhiteSpace( s) then Some() else None
20+ if String.IsNullOrWhiteSpace( s) then
21+ ValueSome()
22+ else
23+ ValueNone
2024
2125 /// Returns a string trimmed from both start and end
2226 let (| TrimBoth |) ( text : string ) = text.Trim()
@@ -117,15 +121,20 @@ module String =
117121
118122module StringPosition =
119123 /// Matches when a string is a whitespace or null
124+ [<return : Struct>]
120125 let (| WhiteSpace | _ |) ( s , _n : MarkdownRange ) =
121- if String.IsNullOrWhiteSpace( s) then Some() else None
126+ if String.IsNullOrWhiteSpace( s) then
127+ ValueSome()
128+ else
129+ ValueNone
122130
123131 /// Matches when a string does starts with non-whitespace
132+ [<return : Struct>]
124133 let (| Unindented | _ |) ( s : string , _n : MarkdownRange ) =
125134 if not ( String.IsNullOrWhiteSpace( s)) && s.TrimStart() = s then
126- Some ()
135+ ValueSome ()
127136 else
128- None
137+ ValueNone
129138
130139 /// Returns a string trimmed from both start and end
131140 let (| TrimBoth |) ( text : string , n : MarkdownRange ) =
@@ -174,11 +183,12 @@ module StringPosition =
174183 StartColumn = n.StartColumn + text.Length - trimmed.Length })
175184
176185 /// Matches when a string starts with any of the specified sub-strings
186+ [<return : Struct>]
177187 let (| StartsWithAny | _ |) ( starts : string seq ) ( text : string , _n : MarkdownRange ) =
178188 if starts |> Seq.exists ( fun s -> text.StartsWith( s, StringComparison.Ordinal)) then
179- Some ()
189+ ValueSome ()
180190 else
181- None
191+ ValueNone
182192
183193 /// Matches when a string starts with the specified sub-string
184194 let (| StartsWith | _ |) ( start : string ) ( text : string , n : MarkdownRange ) =
@@ -297,15 +307,16 @@ module StringPosition =
297307
298308 /// Matches when a string consists of some number of
299309 /// complete repetitions of a specified sub-string.
310+ [<return : Struct>]
300311 let (| EqualsRepeated | _ |) ( repeated , _n : MarkdownRange ) =
301312 function
302- | StartsWithRepeated repeated (_ n, ( v, _)) when ( String.IsNullOrWhiteSpace v) -> Some ()
303- | _ -> None
313+ | StartsWithRepeated repeated (_ n, ( v, _)) when ( String.IsNullOrWhiteSpace v) -> ValueSome ()
314+ | _ -> ValueNone
304315
305316module List =
306317 /// Matches a list if it starts with a sub-list that is delimited
307318 /// using the specified delimiters. Returns a wrapped list and the rest.
308- let inline (| DelimitedWith | _ |) startl endl input =
319+ let inline internal (| DelimitedWith | _ |) startl endl input =
309320 if List.startsWith startl input then
310321 match List.partitionUntilEquals endl ( List.skip startl.Length input) with
311322 | Some( pre, post) -> Some( pre, List.skip endl.Length post, startl.Length, endl.Length)
@@ -314,14 +325,14 @@ module List =
314325 None
315326
316327 /// Matches a list if it starts with a sub-list. Returns the list.
317- let inline (| StartsWith | _ |) startl input =
328+ let inline internal (| StartsWith | _ |) startl input =
318329 if List.startsWith startl input then Some input else None
319330
320331 /// Matches a list if it starts with a sub-list that is delimited
321332 /// using the specified delimiter. Returns a wrapped list and the rest.
322- let inline (| Delimited | _ |) str = (| DelimitedWith|_|) str str
333+ let inline internal (| Delimited | _ |) str = (| DelimitedWith|_|) str str
323334
324- let inline (| DelimitedNTimes | _ |) str input =
335+ let inline internal (| DelimitedNTimes | _ |) str input =
325336 let strs , _items = List.partitionWhile ( fun i -> i = str) input
326337
327338 match strs with
@@ -403,9 +414,8 @@ module Lines =
403414 let (| TrimParagraphLines |) lines =
404415 lines
405416 // first remove all whitespace on the beginning of the line
406- |> List.map ( fun ( StringPosition.TrimStart s ) -> s)
407- // Now remove all additional spaces at the end, but keep two spaces if existent
408- |> List.map ( fun ( s , n ) ->
417+ // then remove all additional spaces at the end, but keep two spaces if existent
418+ |> List.map ( fun ( StringPosition.TrimStart ( s , n )) ->
409419 let endsWithTwoSpaces = s.EndsWith( " " , StringComparison.Ordinal)
410420
411421 let trimmed = s.TrimEnd([| ' ' |]) + if endsWithTwoSpaces then " " else " "
0 commit comments