mirror of
https://github.com/Smaug123/WoofWare.Whippet
synced 2025-10-10 02:08:41 +00:00
Initial import of Fantomas client library (#6)
Some checks failed
.NET / build (Debug) (push) Has been cancelled
.NET / build (Release) (push) Has been cancelled
.NET / analyzers (push) Has been cancelled
.NET / build-nix (push) Has been cancelled
.NET / check-dotnet-format (push) Has been cancelled
.NET / check-nix-format (push) Has been cancelled
.NET / Check links (push) Has been cancelled
.NET / Check flake (push) Has been cancelled
.NET / nuget-pack (push) Has been cancelled
.NET / expected-pack (push) Has been cancelled
.NET / all-required-checks-complete (push) Has been cancelled
Some checks failed
.NET / build (Debug) (push) Has been cancelled
.NET / build (Release) (push) Has been cancelled
.NET / analyzers (push) Has been cancelled
.NET / build-nix (push) Has been cancelled
.NET / check-dotnet-format (push) Has been cancelled
.NET / check-nix-format (push) Has been cancelled
.NET / Check links (push) Has been cancelled
.NET / Check flake (push) Has been cancelled
.NET / nuget-pack (push) Has been cancelled
.NET / expected-pack (push) Has been cancelled
.NET / all-required-checks-complete (push) Has been cancelled
This commit is contained in:
53
WoofWare.Whippet.Fantomas/SynTypeDefn.fs
Normal file
53
WoofWare.Whippet.Fantomas/SynTypeDefn.fs
Normal file
@@ -0,0 +1,53 @@
|
||||
namespace WoofWare.Whippet.Fantomas
|
||||
|
||||
open Fantomas.FCS.Syntax
|
||||
open Fantomas.FCS.SyntaxTrivia
|
||||
open Fantomas.FCS.Text.Range
|
||||
|
||||
/// Methods for manipulating `SynTypeDefn`, which represents any type definition like `type Foo = ...`.
|
||||
[<RequireQualifiedAccess>]
|
||||
module SynTypeDefn =
|
||||
|
||||
/// Build a `SynTypeDefn` from its components:
|
||||
/// the "front matter" `SynComponentInfo`, and the "body" `SynTypeDefnRepr`.
|
||||
let inline create (componentInfo : SynComponentInfo) (repr : SynTypeDefnRepr) : SynTypeDefn =
|
||||
SynTypeDefn.SynTypeDefn (
|
||||
componentInfo,
|
||||
repr,
|
||||
[],
|
||||
None,
|
||||
range0,
|
||||
{
|
||||
LeadingKeyword = SynTypeDefnLeadingKeyword.Type range0
|
||||
EqualsRange = Some range0
|
||||
WithKeyword = None
|
||||
}
|
||||
)
|
||||
|
||||
/// Add member definitions to this type: `type Foo = ... with member Blah = ...`
|
||||
let inline withMemberDefns (members : SynMemberDefn list) (r : SynTypeDefn) : SynTypeDefn =
|
||||
match r with
|
||||
| SynTypeDefn (typeInfo, typeRepr, _, ctor, range, trivia) ->
|
||||
SynTypeDefn.SynTypeDefn (typeInfo, typeRepr, members, ctor, range, trivia)
|
||||
|
||||
/// Get the name of this type as it appears in the source.
|
||||
let getName (defn : SynTypeDefn) : LongIdent =
|
||||
match defn with
|
||||
| SynTypeDefn (SynComponentInfo.SynComponentInfo (_, _, _, id, _, _, _, _), _, _, _, _, _) -> id
|
||||
|
||||
/// Select from this type definition the first attribute with the given name: `[<Foo>] type Blah = ...`
|
||||
let getAttribute (attrName : string) (defn : SynTypeDefn) : SynAttribute option =
|
||||
match defn with
|
||||
| SynTypeDefn (SynComponentInfo.SynComponentInfo (attrs, _, _, _, _, _, _, _), _, _, _, _, _) ->
|
||||
attrs
|
||||
|> List.collect (fun a -> a.Attributes)
|
||||
|> List.tryFind (fun i ->
|
||||
match i.TypeName with
|
||||
| SynLongIdent.SynLongIdent (id, _, _) ->
|
||||
let name = List.last(id).idText
|
||||
name = attrName || name + "Attribute" = attrName
|
||||
)
|
||||
|
||||
/// Determine whether this type definition has an attribute with the given name: `[<Foo>] type Blah = ...`
|
||||
let hasAttribute (attrName : string) (defn : SynTypeDefn) : bool =
|
||||
getAttribute attrName defn |> Option.isSome
|
Reference in New Issue
Block a user