Skip to content
This repository was archived by the owner on Apr 5, 2025. It is now read-only.

Commit 9e237de

Browse files
Command line using argu
1 parent b384401 commit 9e237de

File tree

8 files changed

+153
-31
lines changed

8 files changed

+153
-31
lines changed

paket.dependencies

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,4 +28,5 @@ nuget unquote
2828
nuget xunit
2929
nuget xunit.runner.visualstudio
3030
nuget coverlet.collector
31-
nuget coverlet.msbuild
31+
nuget coverlet.msbuild
32+
nuget Argu

paket.lock

Lines changed: 45 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,9 @@ STORAGE: NONE
22
RESTRICTION: || (== netcoreapp3.1) (== netstandard2.0) (== netstandard2.1)
33
NUGET
44
remote: https://api.nuget.org/v3/index.json
5+
Argu (6.1.1)
6+
FSharp.Core (>= 4.3.2)
7+
System.Configuration.ConfigurationManager (>= 4.4)
58
coverlet.collector (1.3)
69
coverlet.msbuild (2.9)
710
Fable.Core (3.1.5)
@@ -17,10 +20,36 @@ NUGET
1720
Microsoft.TestPlatform.TestHost (16.7.1) - restriction: || (== netcoreapp3.1) (&& (== netstandard2.0) (>= netcoreapp2.1)) (&& (== netstandard2.1) (>= netcoreapp2.1))
1821
Microsoft.TestPlatform.ObjectModel (>= 16.7.1) - restriction: || (== netcoreapp3.1) (&& (== netstandard2.0) (>= netcoreapp2.1)) (&& (== netstandard2.0) (>= uap10.0)) (&& (== netstandard2.1) (>= netcoreapp2.1)) (&& (== netstandard2.1) (>= uap10.0))
1922
Newtonsoft.Json (>= 9.0.1) - restriction: || (== netcoreapp3.1) (&& (== netstandard2.0) (>= netcoreapp2.1)) (&& (== netstandard2.0) (>= uap10.0)) (&& (== netstandard2.1) (>= netcoreapp2.1)) (&& (== netstandard2.1) (>= uap10.0))
23+
Microsoft.Win32.SystemEvents (4.7) - restriction: || (== netcoreapp3.1) (&& (== netstandard2.0) (>= netcoreapp3.0)) (&& (== netstandard2.1) (>= netcoreapp3.0))
24+
Microsoft.NETCore.Platforms (>= 3.1) - restriction: || (== netcoreapp3.1) (&& (== netstandard2.0) (>= netcoreapp2.0)) (&& (== netstandard2.1) (>= netcoreapp2.0))
2025
NETStandard.Library (2.0.3)
2126
Microsoft.NETCore.Platforms (>= 1.1)
2227
Newtonsoft.Json (12.0.3) - restriction: || (== netcoreapp3.1) (&& (== netstandard2.0) (>= netcoreapp2.1)) (&& (== netstandard2.1) (>= netcoreapp2.1))
2328
NuGet.Frameworks (5.7) - restriction: || (== netcoreapp3.1) (&& (== netstandard2.0) (>= netcoreapp2.1)) (&& (== netstandard2.1) (>= netcoreapp2.1))
29+
System.Buffers (4.5.1) - restriction: || (&& (== netcoreapp3.1) (>= monoandroid)) (&& (== netcoreapp3.1) (>= monotouch)) (&& (== netcoreapp3.1) (>= net461)) (&& (== netcoreapp3.1) (< netcoreapp2.0)) (&& (== netcoreapp3.1) (< netstandard1.1)) (&& (== netcoreapp3.1) (< netstandard2.0)) (&& (== netcoreapp3.1) (>= xamarinios)) (&& (== netcoreapp3.1) (>= xamarinmac)) (&& (== netcoreapp3.1) (>= xamarintvos)) (&& (== netcoreapp3.1) (>= xamarinwatchos)) (== netstandard2.0) (== netstandard2.1)
30+
System.Configuration.ConfigurationManager (4.7)
31+
System.Security.Cryptography.ProtectedData (>= 4.7)
32+
System.Security.Permissions (>= 4.7)
33+
System.Drawing.Common (4.7) - restriction: || (== netcoreapp3.1) (&& (== netstandard2.0) (>= netcoreapp3.0)) (&& (== netstandard2.1) (>= netcoreapp3.0))
34+
Microsoft.NETCore.Platforms (>= 3.1) - restriction: || (== netcoreapp3.1) (&& (== netstandard2.0) (>= netcoreapp2.0)) (&& (== netstandard2.1) (>= netcoreapp2.0))
35+
Microsoft.Win32.SystemEvents (>= 4.7) - restriction: || (== netcoreapp3.1) (&& (== netstandard2.0) (>= netcoreapp2.0)) (&& (== netstandard2.1) (>= netcoreapp2.0))
36+
System.Memory (4.5.4) - restriction: || (&& (== netcoreapp3.1) (< netcoreapp2.1)) (== netstandard2.0) (== netstandard2.1)
37+
System.Buffers (>= 4.5.1) - restriction: || (&& (== netcoreapp3.1) (>= monoandroid)) (&& (== netcoreapp3.1) (>= monotouch)) (&& (== netcoreapp3.1) (>= net461)) (&& (== netcoreapp3.1) (< netcoreapp2.0)) (&& (== netcoreapp3.1) (< netstandard1.1)) (&& (== netcoreapp3.1) (< netstandard2.0)) (&& (== netcoreapp3.1) (>= xamarinios)) (&& (== netcoreapp3.1) (>= xamarinmac)) (&& (== netcoreapp3.1) (>= xamarintvos)) (&& (== netcoreapp3.1) (>= xamarinwatchos)) (== netstandard2.0) (== netstandard2.1)
38+
System.Numerics.Vectors (>= 4.4) - restriction: || (&& (== netcoreapp3.1) (< netcoreapp2.0)) (== netstandard2.0) (== netstandard2.1)
39+
System.Runtime.CompilerServices.Unsafe (>= 4.5.3) - restriction: || (&& (== netcoreapp3.1) (>= monoandroid)) (&& (== netcoreapp3.1) (>= monotouch)) (&& (== netcoreapp3.1) (>= net461)) (&& (== netcoreapp3.1) (< netcoreapp2.0)) (&& (== netcoreapp3.1) (< netcoreapp2.1)) (&& (== netcoreapp3.1) (< netstandard1.1)) (&& (== netcoreapp3.1) (< netstandard2.0)) (&& (== netcoreapp3.1) (>= uap10.1)) (&& (== netcoreapp3.1) (>= xamarinios)) (&& (== netcoreapp3.1) (>= xamarinmac)) (&& (== netcoreapp3.1) (>= xamarintvos)) (&& (== netcoreapp3.1) (>= xamarinwatchos)) (== netstandard2.0) (== netstandard2.1)
40+
System.Numerics.Vectors (4.5) - restriction: || (&& (== netcoreapp3.1) (< netcoreapp2.0)) (== netstandard2.0) (== netstandard2.1)
41+
System.Runtime.CompilerServices.Unsafe (4.7.1) - restriction: || (&& (== netcoreapp3.1) (>= monoandroid)) (&& (== netcoreapp3.1) (>= monotouch)) (&& (== netcoreapp3.1) (>= net461)) (&& (== netcoreapp3.1) (< netcoreapp2.0)) (&& (== netcoreapp3.1) (< netcoreapp2.1)) (&& (== netcoreapp3.1) (< netstandard1.1)) (&& (== netcoreapp3.1) (< netstandard2.0)) (&& (== netcoreapp3.1) (>= uap10.1)) (&& (== netcoreapp3.1) (>= xamarinios)) (&& (== netcoreapp3.1) (>= xamarinmac)) (&& (== netcoreapp3.1) (>= xamarintvos)) (&& (== netcoreapp3.1) (>= xamarinwatchos)) (== netstandard2.0) (== netstandard2.1)
42+
System.Security.AccessControl (4.7)
43+
Microsoft.NETCore.Platforms (>= 3.1) - restriction: || (== netcoreapp3.1) (&& (== netstandard2.0) (>= netcoreapp2.0)) (&& (== netstandard2.1) (>= netcoreapp2.0))
44+
System.Security.Principal.Windows (>= 4.7)
45+
System.Security.Cryptography.ProtectedData (4.7)
46+
System.Memory (>= 4.5.3) - restriction: || (&& (== netcoreapp3.1) (< netcoreapp2.1)) (== netstandard2.0) (== netstandard2.1)
47+
System.Security.Permissions (4.7)
48+
System.Security.AccessControl (>= 4.7)
49+
System.Windows.Extensions (>= 4.7) - restriction: || (== netcoreapp3.1) (&& (== netstandard2.0) (>= netcoreapp3.0)) (&& (== netstandard2.1) (>= netcoreapp3.0))
50+
System.Security.Principal.Windows (4.7)
51+
System.Windows.Extensions (4.7) - restriction: || (== netcoreapp3.1) (&& (== netstandard2.0) (>= netcoreapp3.0)) (&& (== netstandard2.1) (>= netcoreapp3.0))
52+
System.Drawing.Common (>= 4.7) - restriction: || (== netcoreapp3.1) (&& (== netstandard2.0) (>= netcoreapp3.0)) (&& (== netstandard2.1) (>= netcoreapp3.0))
2453
Unquote (5.0)
2554
FSharp.Core (>= 4.6.2)
2655
xunit (2.4.1)
@@ -43,19 +72,19 @@ NUGET
4372
xunit.runner.visualstudio (2.4.3)
4473
GITHUB
4574
remote: fable-compiler/fable
46-
lib\fcs\FSharp.Compiler.Service.dll (a6d4b340c2811ab69a03bdf1a6e1f0c2092c9864)
47-
lib\fcs\FSharp.Compiler.Service.xml (a6d4b340c2811ab69a03bdf1a6e1f0c2092c9864)
48-
src\Fable.Transforms\AST\AST.Common.fs (a6d4b340c2811ab69a03bdf1a6e1f0c2092c9864)
49-
src\Fable.Transforms\AST\AST.Fable.fs (a6d4b340c2811ab69a03bdf1a6e1f0c2092c9864)
50-
src\Fable.Transforms\FableTransforms.fs (a6d4b340c2811ab69a03bdf1a6e1f0c2092c9864)
51-
src\Fable.Transforms\FSharp2Fable.fs (a6d4b340c2811ab69a03bdf1a6e1f0c2092c9864)
52-
src\Fable.Transforms\FSharp2Fable.Util.fs (a6d4b340c2811ab69a03bdf1a6e1f0c2092c9864)
53-
src\Fable.Transforms\Global\Compiler.fs (a6d4b340c2811ab69a03bdf1a6e1f0c2092c9864)
54-
src\Fable.Transforms\Global\Fable.Core.fs (a6d4b340c2811ab69a03bdf1a6e1f0c2092c9864)
55-
src\Fable.Transforms\Global\Prelude.fs (a6d4b340c2811ab69a03bdf1a6e1f0c2092c9864)
56-
src\Fable.Transforms\Inject.fs (a6d4b340c2811ab69a03bdf1a6e1f0c2092c9864)
57-
src\Fable.Transforms\MonadicTrampoline.fs (a6d4b340c2811ab69a03bdf1a6e1f0c2092c9864)
58-
src\Fable.Transforms\OverloadSuffix.fs (a6d4b340c2811ab69a03bdf1a6e1f0c2092c9864)
59-
src\Fable.Transforms\Replacements.fs (a6d4b340c2811ab69a03bdf1a6e1f0c2092c9864)
60-
src\Fable.Transforms\ReplacementsInject.fs (a6d4b340c2811ab69a03bdf1a6e1f0c2092c9864)
61-
src\Fable.Transforms\Transforms.Util.fs (a6d4b340c2811ab69a03bdf1a6e1f0c2092c9864)
75+
lib\fcs\FSharp.Compiler.Service.dll (bd1a9944a6c16f3e7796c27a1c42a3cb1cb2d5cb)
76+
lib\fcs\FSharp.Compiler.Service.xml (bd1a9944a6c16f3e7796c27a1c42a3cb1cb2d5cb)
77+
src\Fable.Transforms\AST\AST.Common.fs (bd1a9944a6c16f3e7796c27a1c42a3cb1cb2d5cb)
78+
src\Fable.Transforms\AST\AST.Fable.fs (bd1a9944a6c16f3e7796c27a1c42a3cb1cb2d5cb)
79+
src\Fable.Transforms\FableTransforms.fs (bd1a9944a6c16f3e7796c27a1c42a3cb1cb2d5cb)
80+
src\Fable.Transforms\FSharp2Fable.fs (bd1a9944a6c16f3e7796c27a1c42a3cb1cb2d5cb)
81+
src\Fable.Transforms\FSharp2Fable.Util.fs (bd1a9944a6c16f3e7796c27a1c42a3cb1cb2d5cb)
82+
src\Fable.Transforms\Global\Compiler.fs (bd1a9944a6c16f3e7796c27a1c42a3cb1cb2d5cb)
83+
src\Fable.Transforms\Global\Fable.Core.fs (bd1a9944a6c16f3e7796c27a1c42a3cb1cb2d5cb)
84+
src\Fable.Transforms\Global\Prelude.fs (bd1a9944a6c16f3e7796c27a1c42a3cb1cb2d5cb)
85+
src\Fable.Transforms\Inject.fs (bd1a9944a6c16f3e7796c27a1c42a3cb1cb2d5cb)
86+
src\Fable.Transforms\MonadicTrampoline.fs (bd1a9944a6c16f3e7796c27a1c42a3cb1cb2d5cb)
87+
src\Fable.Transforms\OverloadSuffix.fs (bd1a9944a6c16f3e7796c27a1c42a3cb1cb2d5cb)
88+
src\Fable.Transforms\Replacements.fs (bd1a9944a6c16f3e7796c27a1c42a3cb1cb2d5cb)
89+
src\Fable.Transforms\ReplacementsInject.fs (bd1a9944a6c16f3e7796c27a1c42a3cb1cb2d5cb)
90+
src\Fable.Transforms\Transforms.Util.fs (bd1a9944a6c16f3e7796c27a1c42a3cb1cb2d5cb)

src/peeble/BuiltinTypes.fs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,3 +20,6 @@ module PhpUnion =
2020
let union = { Name = "Union"; Fields = []; Methods = []; Abstract = true; BaseType = None; Interfaces = []}
2121
let fSharpUnion = { Name = "FSharpUnion"; Fields = []; Methods = []; Abstract = true; BaseType = None; Interfaces = []}
2222

23+
module Core =
24+
let icomparable = { Name = "iComparable"; Fields = []; Methods = []; Abstract = true; BaseType = None; Interfaces = [] }
25+

src/peeble/Program.fs

Lines changed: 31 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -90,18 +90,29 @@ type Compiler(currentFile, project: Project, options, fableLibraryDir: string) =
9090

9191

9292

93+
open System.Xml.Linq
94+
open Argu
9395

96+
module CmdLine =
97+
type Options =
98+
| [<Mandatory; MainCommand>] Project of string
99+
| Output of string
94100

95-
96-
97-
open System.Xml.Linq
101+
interface IArgParserTemplate with
102+
member this.Usage =
103+
match this with
104+
| Project _ -> "fsproj Project to transpile"
105+
| Output _ -> "The output php file"
98106

99107

100108
[<EntryPoint>]
101109
let main argv =
102110

103-
match argv with
104-
| [| project |] ->
111+
let parser = Argu.ArgumentParser.Create<CmdLine.Options>("peeble")
112+
let parseResult = parser.ParseCommandLine(argv)
113+
114+
match parseResult.TryGetResult( CmdLine.Project ) with
115+
| Some project ->
105116
let dir = Path.GetDirectoryName project
106117

107118
let proj = XDocument.Load(project)
@@ -167,11 +178,21 @@ let main argv =
167178
i,d
168179
]
169180

170-
let w = new StringWriter()
171-
let ctx = PhpOutput.Writer.create(w)
172-
let file = { Decls = fs }
173-
PhpOutput.writeFile ctx file
174-
printfn "%s" (string w)
181+
match parseResult.TryGetResult(CmdLine.Output) with
182+
| Some file ->
183+
use w = File.CreateText file
184+
let ctx = PhpOutput.Writer.create(w)
185+
let file = { Decls = fs }
186+
PhpOutput.writeFile ctx file
187+
188+
189+
190+
| None ->
191+
let w = new StringWriter()
192+
let ctx = PhpOutput.Writer.create(w)
193+
let file = { Decls = fs }
194+
PhpOutput.writeFile ctx file
195+
printfn "%s" (string w)
175196
| errors ->
176197
for error in errors do
177198
eprintfn "[%s %d %d] %s" error.FileName error.Start.Line error.Start.Column error.Message

src/peeble/Transforms.fs

Lines changed: 43 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -155,7 +155,7 @@ let convertUnion (ctx: PhpCompiler) (info: Fable.UnionConstructorInfo) =
155155
]
156156
Abstract = false
157157
BaseType = None
158-
Interfaces = [ PhpUnion.fSharpUnion ]
158+
Interfaces = [ PhpUnion.fSharpUnion; Core.icomparable ]
159159
}
160160
ctx.AddType(t) |> PhpType ]
161161
else
@@ -256,7 +256,7 @@ let convertUnion (ctx: PhpCompiler) (info: Fable.UnionConstructorInfo) =
256256
]
257257
Abstract = false
258258
BaseType = Some baseType
259-
Interfaces = [] }
259+
Interfaces = [ Core.icomparable ] }
260260
ctx.AddType(t) |> PhpType ]
261261

262262
let convertRecord (ctx: PhpCompiler) (info: Fable.CompilerGeneratedConstructorInfo) =
@@ -265,10 +265,49 @@ let convertRecord (ctx: PhpCompiler) (info: Fable.CompilerGeneratedConstructorIn
265265
Fields = [ for e in info.Entity.FSharpFields do
266266
{ Name = e.Name
267267
Type = convertType e.FieldType } ]
268-
Methods = [ ]
268+
Methods = [
269+
{ PhpFun.Name = "CompareTo"
270+
PhpFun.Args = ["other"]
271+
PhpFun.Matchings = []
272+
PhpFun.Static = false
273+
PhpFun.Body =
274+
[ for e in info.Entity.FSharpFields do
275+
let cmp = PhpVar(ctx.MakeUniqueVar "cmp",None)
276+
match e.FieldType.TypeDefinition.CompiledName with
277+
| "int"
278+
| "string" ->
279+
Assign(cmp,
280+
PhpTernary( PhpBinaryOp(">",
281+
PhpProp(PhpVar("this",None), Prop.Field { Name = e.Name; Type = convertType e.FieldType }, None),
282+
PhpProp(PhpVar("other", None), Prop.Field { Name = e.Name; Type = convertType e.FieldType }, None) ),
283+
PhpConst(PhpConstNumber 1.),
284+
PhpTernary(
285+
PhpBinaryOp("<",
286+
PhpProp(PhpVar("this",None), Prop.Field { Name = e.Name; Type = convertType e.FieldType }, None),
287+
PhpProp(PhpVar("other", None), Prop.Field { Name = e.Name; Type = convertType e.FieldType }, None)),
288+
PhpConst(PhpConstNumber -1.),
289+
PhpConst(PhpConstNumber 0.)
290+
291+
292+
) ) )
293+
| _ ->
294+
Assign(cmp,
295+
PhpMethod(PhpProp(PhpVar("this",None), Prop.Field { Name = e.Name; Type = convertType e.FieldType }, None),
296+
"CompareTo",
297+
[PhpProp(PhpVar("other", None), Prop.Field { Name = e.Name; Type = convertType e.FieldType }, None) ])
298+
299+
)
300+
If(PhpBinaryOp("!=", cmp, PhpConst(PhpConstNumber 0.) ),
301+
[PhpStatement.Return cmp],
302+
[]
303+
)
304+
PhpStatement.Return (PhpConst (PhpConstNumber 0.))
305+
] }
306+
307+
]
269308
Abstract = false
270309
BaseType = None
271-
Interfaces = []}
310+
Interfaces = [ Core.icomparable ]}
272311
ctx.AddType(t) |> PhpType ]
273312

274313
type ReturnStrategy =

src/peeble/paket.references

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
Fable.Core
2+
Argu
23
File:FSharp.Compiler.Service.dll
34
File:FSharp.Compiler.Service.xml
45
File:Fable.Core.fs Fable

src/peeble/peeble.fsproj

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,20 @@
122122
<Paket>True</Paket>
123123
</Reference>
124124
</ItemGroup>
125+
<ItemGroup>
126+
<Reference Include="FSharp.Compiler.Service">
127+
<HintPath>..\..\paket-files\fable-compiler\fable\lib\fcs\FSharp.Compiler.Service.dll</HintPath>
128+
<Private>True</Private>
129+
<Paket>True</Paket>
130+
</Reference>
131+
</ItemGroup>
132+
<ItemGroup>
133+
<Reference Include="FSharp.Compiler.Service">
134+
<HintPath>..\..\paket-files\fable-compiler\fable\lib\fcs\FSharp.Compiler.Service.dll</HintPath>
135+
<Private>True</Private>
136+
<Paket>True</Paket>
137+
</Reference>
138+
</ItemGroup>
125139
<Import Project="..\..\.paket\Paket.Restore.targets" />
126140
<ItemGroup>
127141
<Reference Include="FSharp.Compiler.Service">

tests/peeble.tests/peeble.tests.fsproj

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,20 @@
3333
<Paket>True</Paket>
3434
</Reference>
3535
</ItemGroup>
36+
<ItemGroup>
37+
<Reference Include="FSharp.Compiler.Service">
38+
<HintPath>..\..\paket-files\fable-compiler\fable\lib\fcs\FSharp.Compiler.Service.dll</HintPath>
39+
<Private>True</Private>
40+
<Paket>True</Paket>
41+
</Reference>
42+
</ItemGroup>
43+
<ItemGroup>
44+
<Reference Include="FSharp.Compiler.Service">
45+
<HintPath>..\..\paket-files\fable-compiler\fable\lib\fcs\FSharp.Compiler.Service.dll</HintPath>
46+
<Private>True</Private>
47+
<Paket>True</Paket>
48+
</Reference>
49+
</ItemGroup>
3650
<Import Project="..\..\.paket\Paket.Restore.targets" />
3751
<ItemGroup>
3852
<Reference Include="FSharp.Compiler.Service">

0 commit comments

Comments
 (0)