mirror of
https://github.com/Smaug123/WoofWare.Myriad
synced 2025-10-11 23:18:43 +00:00
Add JSON parse source gen (#9)
This commit is contained in:
32
ConsumePlugin/ConsumePlugin.fsproj
Normal file
32
ConsumePlugin/ConsumePlugin.fsproj
Normal file
@@ -0,0 +1,32 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
|
||||
<PropertyGroup>
|
||||
<TargetFramework>net8.0</TargetFramework>
|
||||
<IsPackable>false</IsPackable>
|
||||
</PropertyGroup>
|
||||
<ItemGroup>
|
||||
<MyriadSdkGenerator Include="$(MSBuildThisFileDirectory)..\MyriadPlugin\bin\$(Configuration)\net6.0\MyriadPlugin.dll" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<None Include="myriad.toml" />
|
||||
<Compile Include="RecordFile.fs" />
|
||||
<Compile Include="GeneratedRecord.fs"> <!--1-->
|
||||
<MyriadFile>RecordFile.fs</MyriadFile> <!--2-->
|
||||
</Compile>
|
||||
<Compile Include="JsonRecord.fs" />
|
||||
<Compile Include="GeneratedJson.fs"> <!--1-->
|
||||
<MyriadFile>JsonRecord.fs</MyriadFile> <!--2-->
|
||||
</Compile>
|
||||
<None Include="..\runmyriad.sh">
|
||||
<Link>runmyriad.sh</Link>
|
||||
</None>
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\MyriadPlugin\MyriadPlugin.fsproj" />
|
||||
<PackageReference Include="Myriad.Sdk" Version="0.8.3" />
|
||||
<PackageReference Include="Myriad.Core" Version="0.8.3" />
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
28
ConsumePlugin/Generated.fs
Normal file
28
ConsumePlugin/Generated.fs
Normal file
@@ -0,0 +1,28 @@
|
||||
//------------------------------------------------------------------------------
|
||||
// This code was generated by myriad.
|
||||
// Changes to this file will be lost when the code is regenerated.
|
||||
//------------------------------------------------------------------------------
|
||||
namespace UsePlugin
|
||||
|
||||
/// Module containing an option-truncated version of the RecordType type
|
||||
[<RequireQualifiedAccess>]
|
||||
[<CompilationRepresentation(CompilationRepresentationFlags.ModuleSuffix)>]
|
||||
module RecordType =
|
||||
/// My whatnot
|
||||
type Short =
|
||||
{
|
||||
/// A thing!
|
||||
A : int
|
||||
/// Another thing!
|
||||
B : string
|
||||
/// Yet another thing!
|
||||
C : float list
|
||||
}
|
||||
|
||||
/// Remove the optional members of the input.
|
||||
let shorten (input : RecordType) : Short =
|
||||
{
|
||||
A = input.A |> Option.defaultValue (RecordType.DefaultA ())
|
||||
B = input.B
|
||||
C = input.C
|
||||
}
|
43
ConsumePlugin/GeneratedJson.fs
Normal file
43
ConsumePlugin/GeneratedJson.fs
Normal file
@@ -0,0 +1,43 @@
|
||||
//------------------------------------------------------------------------------
|
||||
// This code was generated by myriad.
|
||||
// Changes to this file will be lost when the code is regenerated.
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
namespace ConsumePlugin
|
||||
|
||||
/// Module containing JSON parsing methods for the InnerType type
|
||||
[<RequireQualifiedAccess>]
|
||||
[<CompilationRepresentation(CompilationRepresentationFlags.ModuleSuffix)>]
|
||||
module InnerType =
|
||||
/// Parse from a JSON node.
|
||||
let jsonParse (node : System.Text.Json.Nodes.JsonNode) : InnerType =
|
||||
let Thing = node.[(Literals.something)].AsValue().GetValue<string> ()
|
||||
|
||||
{
|
||||
Thing = Thing
|
||||
}
|
||||
namespace ConsumePlugin
|
||||
|
||||
/// Module containing JSON parsing methods for the JsonRecordType type
|
||||
[<RequireQualifiedAccess>]
|
||||
[<CompilationRepresentation(CompilationRepresentationFlags.ModuleSuffix)>]
|
||||
module JsonRecordType =
|
||||
/// Parse from a JSON node.
|
||||
let jsonParse (node : System.Text.Json.Nodes.JsonNode) : JsonRecordType =
|
||||
let D = InnerType.jsonParse node.["d"]
|
||||
|
||||
let C =
|
||||
node.["hi"].AsArray ()
|
||||
|> Seq.map (fun elt -> elt.GetValue<int> ())
|
||||
|> List.ofSeq
|
||||
|
||||
let B2 = node.["another-thing"].AsValue ()
|
||||
let B = B2.GetValue<string> ()
|
||||
let A = node.["a"].AsValue().GetValue<int> ()
|
||||
|
||||
{
|
||||
A = A
|
||||
B = B
|
||||
C = C
|
||||
D = D
|
||||
}
|
28
ConsumePlugin/GeneratedRecord.fs
Normal file
28
ConsumePlugin/GeneratedRecord.fs
Normal file
@@ -0,0 +1,28 @@
|
||||
//------------------------------------------------------------------------------
|
||||
// This code was generated by myriad.
|
||||
// Changes to this file will be lost when the code is regenerated.
|
||||
//------------------------------------------------------------------------------
|
||||
namespace ConsumePlugin
|
||||
|
||||
/// Module containing an option-truncated version of the RecordType type
|
||||
[<RequireQualifiedAccess>]
|
||||
[<CompilationRepresentation(CompilationRepresentationFlags.ModuleSuffix)>]
|
||||
module RecordType =
|
||||
/// My whatnot
|
||||
type Short =
|
||||
{
|
||||
/// A thing!
|
||||
A : int
|
||||
/// Another thing!
|
||||
B : string
|
||||
/// Yet another thing!
|
||||
C : float list
|
||||
}
|
||||
|
||||
/// Remove the optional members of the input.
|
||||
let shorten (input : RecordType) : Short =
|
||||
{
|
||||
A = input.A |> Option.defaultWith RecordType.DefaultA
|
||||
B = input.B
|
||||
C = input.C
|
||||
}
|
28
ConsumePlugin/JsonRecord.fs
Normal file
28
ConsumePlugin/JsonRecord.fs
Normal file
@@ -0,0 +1,28 @@
|
||||
namespace ConsumePlugin
|
||||
|
||||
open System.Text.Json.Serialization
|
||||
|
||||
module Literals =
|
||||
[<Literal>]
|
||||
let something = "something"
|
||||
|
||||
[<MyriadPlugin.JsonParse>]
|
||||
type InnerType =
|
||||
{
|
||||
[<JsonPropertyName(Literals.something)>]
|
||||
Thing : string
|
||||
}
|
||||
|
||||
/// My whatnot
|
||||
[<MyriadPlugin.JsonParse>]
|
||||
type JsonRecordType =
|
||||
{
|
||||
/// A thing!
|
||||
A : int
|
||||
/// Another thing!
|
||||
[<JsonPropertyName "another-thing">]
|
||||
B : string
|
||||
[<System.Text.Json.Serialization.JsonPropertyName "hi">]
|
||||
C : int list
|
||||
D : InnerType
|
||||
}
|
19
ConsumePlugin/RecordFile.fs
Normal file
19
ConsumePlugin/RecordFile.fs
Normal file
@@ -0,0 +1,19 @@
|
||||
namespace ConsumePlugin
|
||||
|
||||
type ParseState =
|
||||
| AwaitingKey
|
||||
| AwaitingValue of string
|
||||
|
||||
/// My whatnot
|
||||
[<MyriadPlugin.RemoveOptions>]
|
||||
type RecordType =
|
||||
{
|
||||
/// A thing!
|
||||
A : int option
|
||||
/// Another thing!
|
||||
B : string
|
||||
/// Yet another thing!
|
||||
C : float list
|
||||
}
|
||||
|
||||
static member DefaultA () : int = 3
|
0
ConsumePlugin/myriad.toml
Normal file
0
ConsumePlugin/myriad.toml
Normal file
Reference in New Issue
Block a user