@@ -15,8 +15,9 @@ 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 ValueSome () else ValueNone
2021
2122 /// Returns a string trimmed from both start and end
2223 let (| TrimBoth |) ( text : string ) = text.Trim()
@@ -117,15 +118,17 @@ module String =
117118
118119module StringPosition =
119120 /// Matches when a string is a whitespace or null
121+ [<return : Struct>]
120122 let (| WhiteSpace | _ |) ( s , _n : MarkdownRange ) =
121- if String.IsNullOrWhiteSpace( s) then Some () else None
123+ if String.IsNullOrWhiteSpace( s) then ValueSome () else ValueNone
122124
123125 /// Matches when a string does starts with non-whitespace
126+ [<return : Struct>]
124127 let (| Unindented | _ |) ( s : string , _n : MarkdownRange ) =
125128 if not ( String.IsNullOrWhiteSpace( s)) && s.TrimStart() = s then
126- Some ()
129+ ValueSome ()
127130 else
128- None
131+ ValueNone
129132
130133 /// Returns a string trimmed from both start and end
131134 let (| TrimBoth |) ( text : string , n : MarkdownRange ) =
@@ -174,11 +177,12 @@ module StringPosition =
174177 StartColumn = n.StartColumn + text.Length - trimmed.Length })
175178
176179 /// Matches when a string starts with any of the specified sub-strings
180+ [<return : Struct>]
177181 let (| StartsWithAny | _ |) ( starts : string seq ) ( text : string , _n : MarkdownRange ) =
178182 if starts |> Seq.exists ( fun s -> text.StartsWith( s, StringComparison.Ordinal)) then
179- Some ()
183+ ValueSome ()
180184 else
181- None
185+ ValueNone
182186
183187 /// Matches when a string starts with the specified sub-string
184188 let (| StartsWith | _ |) ( start : string ) ( text : string , n : MarkdownRange ) =
@@ -297,15 +301,16 @@ module StringPosition =
297301
298302 /// Matches when a string consists of some number of
299303 /// complete repetitions of a specified sub-string.
304+ [<return : Struct>]
300305 let (| EqualsRepeated | _ |) ( repeated , _n : MarkdownRange ) =
301306 function
302- | StartsWithRepeated repeated (_ n, ( v, _)) when ( String.IsNullOrWhiteSpace v) -> Some ()
303- | _ -> None
307+ | StartsWithRepeated repeated (_ n, ( v, _)) when ( String.IsNullOrWhiteSpace v) -> ValueSome ()
308+ | _ -> ValueNone
304309
305310module List =
306311 /// Matches a list if it starts with a sub-list that is delimited
307312 /// using the specified delimiters. Returns a wrapped list and the rest.
308- let inline (| DelimitedWith | _ |) startl endl input =
313+ let inline internal (| DelimitedWith | _ |) startl endl input =
309314 if List.startsWith startl input then
310315 match List.partitionUntilEquals endl ( List.skip startl.Length input) with
311316 | Some( pre, post) -> Some( pre, List.skip endl.Length post, startl.Length, endl.Length)
@@ -314,14 +319,14 @@ module List =
314319 None
315320
316321 /// Matches a list if it starts with a sub-list. Returns the list.
317- let inline (| StartsWith | _ |) startl input =
322+ let inline internal (| StartsWith | _ |) startl input =
318323 if List.startsWith startl input then Some input else None
319324
320325 /// Matches a list if it starts with a sub-list that is delimited
321326 /// using the specified delimiter. Returns a wrapped list and the rest.
322- let inline (| Delimited | _ |) str = (| DelimitedWith|_|) str str
327+ let inline internal (| Delimited | _ |) str = (| DelimitedWith|_|) str str
323328
324- let inline (| DelimitedNTimes | _ |) str input =
329+ let inline internal (| DelimitedNTimes | _ |) str input =
325330 let strs , _items = List.partitionWhile ( fun i -> i = str) input
326331
327332 match strs with
@@ -403,9 +408,8 @@ module Lines =
403408 let (| TrimParagraphLines |) lines =
404409 lines
405410 // 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 ) ->
411+ // then remove all additional spaces at the end, but keep two spaces if existent
412+ |> List.map ( fun ( StringPosition.TrimStart ( s , n )) ->
409413 let endsWithTwoSpaces = s.EndsWith( " " , StringComparison.Ordinal)
410414
411415 let trimmed = s.TrimEnd([| ' ' |]) + if endsWithTwoSpaces then " " else " "
0 commit comments