Skip to content

Instantly share code, notes, and snippets.

@dsyme
Created April 27, 2022 10:37
Show Gist options
  • Save dsyme/b1b560e5ff6c152a40ef4f4835a75b63 to your computer and use it in GitHub Desktop.
Save dsyme/b1b560e5ff6c152a40ef4f4835a75b63 to your computer and use it in GitHub Desktop.
[<Sealed>]
type LongIdentWithTrivia(lid: LongIdent, dotRanges: range list, ?trivia: IdentTrivia option list) =
let triviaStored =
match trivia with
| None -> ValueNone
| Some l when l |> List.forall Option.isNone -> ValueNone
| Some l -> ValueSome (Array.ofList l)
let getTrivia() =
match triviaStored with
| ValueNone -> lid |> List.map (fun _ -> None)
| ValueSome l -> Array.toList l
member _.LongIdent = lid
member _.DotRanges = dotRanges
member _.IdentsTrivia = getTrivia()
member _.IdentsWithTrivia = (lid, getTrivia()) ||> List.zip
[<AutoOpen>]
module LongIdentWithTriviaHelpers =
let (|LongIdentWithDots|) (lid: LongIdentWithTrivia) = lid.LongIdent, lid.DotRanges
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment