Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use WidgetBuilder for Exprs and Patterns for simplicity #79

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,11 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
## [Unreleased]
_No unreleased changes_

## [1.0.0-pre2] - 2024-03-27

### Changed
- Use `WidgetBuilder` for `Expr` and `Pattern` for simplicity by @edgarfgp in https://github.com/edgarfgp/Fabulous.AST/pull/79

## [1.0.0-pre1] - 2024-03-25

### Added
Expand Down
10 changes: 5 additions & 5 deletions docs/widgets/records.fsx
Original file line number Diff line number Diff line change
Expand Up @@ -65,11 +65,11 @@ Oak() {
Method(
"Create",
parameters,
RecordExpr() {
RecordFieldExpr("Name", ConstantExpr(Unquoted "name"))
RecordFieldExpr("Age", ConstantExpr(Unquoted "age"))
RecordFieldExpr("Address", ConstantExpr(Unquoted "address"))
}
RecordExpr(
[ RecordFieldExpr("Name", ConstantExpr(Unquoted "name"))
RecordFieldExpr("Age", ConstantExpr(Unquoted "age"))
RecordFieldExpr("Address", ConstantExpr(Unquoted "address")) ]
)
)
.toStatic ()

Expand Down
18 changes: 8 additions & 10 deletions docs/widgets/unions.fsx
Original file line number Diff line number Diff line change
Expand Up @@ -62,20 +62,18 @@ Oak() {
Method(
"this.GetColor",
ParameterPat("c", "Colors"),
MatchExpr(Unquoted("c")) {
MatchClauseExpr(Unquoted("Red"), Quoted "Red")
MatchClauseExpr(NamedPat("Green"), Quoted "Green")
MatchClauseExpr(Unquoted("Blue"), Quoted "Blue")
MatchClauseExpr(NamedPat("Yellow"), ConstantExpr(Quoted "Yellow"))
}
MatchExpr(
Unquoted("c"),
[ MatchClauseExpr(Unquoted("Red"), Quoted "Red")
MatchClauseExpr(NamedPat("Green"), Quoted "Green")
MatchClauseExpr(Unquoted("Blue"), Quoted "Blue")
MatchClauseExpr(NamedPat("Yellow"), ConstantExpr(Quoted "Yellow")) ]
)
) ]
)

(Union("Colors2") {
UnionParamsCase("Red") {
Field("a", LongIdent("string"))
Field("b", LongIdent "'other")
}
UnionCase("Red", [ Field("a", LongIdent("string")); Field("b", LongIdent "'other") ])

UnionCase("Green")
UnionCase("Blue")
Expand Down
68 changes: 35 additions & 33 deletions src/Fabulous.AST.Tests/Expressions/Conditionals.fs
Original file line number Diff line number Diff line change
Expand Up @@ -62,17 +62,18 @@ if x = 12 then

Value(
"res3",
IfThenElifExpr(ConstantExpr(ConstantUnit())) {
IfThenExpr(
InfixAppExpr(ConstantExpr(Unquoted "x"), "=", ConstantExpr(Unquoted "12")),
ConstantExpr(ConstantUnit())
)

ElIfThenExpr(
InfixAppExpr(ConstantExpr(Constant(Unquoted "x")), "=", ConstantExpr(Unquoted "11")),
ConstantExpr(ConstantUnit())
)
}
IfThenElifExpr(
[ IfThenExpr(
InfixAppExpr(ConstantExpr(Unquoted "x"), "=", ConstantExpr(Unquoted "12")),
ConstantExpr(ConstantUnit())
)

ElIfThenExpr(
InfixAppExpr(ConstantExpr(Constant(Unquoted "x")), "=", ConstantExpr(Unquoted "11")),
ConstantExpr(ConstantUnit())
) ],
ConstantExpr(ConstantUnit())
)
)

}
Expand Down Expand Up @@ -179,17 +180,17 @@ module IfThenElif =
let ``Produces If Then Elif Then expression with widgets``() =
Oak() {
AnonymousModule() {
IfThenElifExpr() {
IfThenExpr(
InfixAppExpr(ConstantExpr(Unquoted "x"), "=", ConstantExpr(Unquoted "12")),
ConstantExpr(ConstantUnit())
)

ElIfThenExpr(
InfixAppExpr(ConstantExpr(Constant(Unquoted "x")), "=", ConstantExpr(Unquoted "11")),
ConstantExpr(ConstantUnit())
)
}
IfThenElifExpr(
[ IfThenExpr(
InfixAppExpr(ConstantExpr(Unquoted "x"), "=", ConstantExpr(Unquoted "12")),
ConstantExpr(ConstantUnit())
)

ElIfThenExpr(
InfixAppExpr(ConstantExpr(Constant(Unquoted "x")), "=", ConstantExpr(Unquoted "11")),
ConstantExpr(ConstantUnit())
) ]
)
}
}
|> produces
Expand All @@ -204,17 +205,18 @@ elif x = 11 then
let ``Produces If Then Elif Then Else expression with widgets``() =
Oak() {
AnonymousModule() {
IfThenElifExpr(ConstantExpr(ConstantUnit())) {
IfThenExpr(
InfixAppExpr(ConstantExpr(Unquoted "x"), "=", ConstantExpr(Unquoted "12")),
ConstantExpr(ConstantUnit())
)

ElIfThenExpr(
InfixAppExpr(ConstantExpr(Unquoted "x"), "=", ConstantExpr(Unquoted "11")),
ConstantExpr(ConstantUnit())
)
}
IfThenElifExpr(
[ IfThenExpr(
InfixAppExpr(ConstantExpr(Unquoted "x"), "=", ConstantExpr(Unquoted "12")),
ConstantExpr(ConstantUnit())
)

ElIfThenExpr(
InfixAppExpr(ConstantExpr(Unquoted "x"), "=", ConstantExpr(Unquoted "11")),
ConstantExpr(ConstantUnit())
) ],
ConstantExpr(ConstantUnit())
)
}
}
|> produces
Expand Down
21 changes: 21 additions & 0 deletions src/Fabulous.AST.Tests/Expressions/Constant.fs
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,27 @@ let x = "a"
"""

let x = 1.0<cm>
"""

[<Fact>]
let ``let value with a ConstantExpr expression with ConstantMeasure seq``() =
Oak() {
AnonymousModule() {
Value(
"x",
ConstantExpr(
ConstantMeasure(
Constant(Unquoted "1.0"),
MeasureSeq([ MeasureSingle("cm"); MeasureSingle("/"); MeasureSingle("m") ])
)
)
)
}
}
|> produces
"""

let x = 1.0<cm / m>
"""

[<Fact>]
Expand Down
9 changes: 5 additions & 4 deletions src/Fabulous.AST.Tests/Expressions/Match.fs
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,10 @@ module Match =
let ``Match expression``() =
Oak() {
AnonymousModule() {
MatchExpr(ListExpr([ ConstantExpr(Constant(Unquoted "1")); ConstantExpr(Constant(Unquoted "2")) ])) {
MatchClauseExpr(NamedPat("a"), ConstantExpr(Constant(Unquoted "3")))
}
MatchExpr(
ListExpr([ ConstantExpr(Constant(Unquoted "1")); ConstantExpr(Constant(Unquoted "2")) ]),
[ MatchClauseExpr(NamedPat("a"), ConstantExpr(Constant(Unquoted "3"))) ]
)
}
}
|> produces
Expand All @@ -27,7 +28,7 @@ match [ 1; 2 ] with

[<Fact>]
let ``Match expression 2``() =
Oak() { AnonymousModule() { MatchExpr(Unquoted "[ 1; 2 ]") { MatchClauseExpr(Unquoted("a"), Unquoted "3") } } }
Oak() { AnonymousModule() { MatchExpr(Unquoted "[ 1; 2 ]", [ MatchClauseExpr(Unquoted("a"), Unquoted "3") ]) } }
|> produces
"""

Expand Down
12 changes: 6 additions & 6 deletions src/Fabulous.AST.Tests/Expressions/Record.fs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ module RecordExpr =
[<InlineData("class", "``class``")>]
[<InlineData("2013", "``2013``")>]
let ``Produces an AnonRecordExpr with fields with backticks`` (value: string) (expected: string) =
Oak() { AnonymousModule() { AnonRecordExpr() { RecordFieldExpr(value, ConstantExpr(Unquoted "1")) } } }
Oak() { AnonymousModule() { AnonRecordExpr([ RecordFieldExpr(value, ConstantExpr(Unquoted "1")) ]) } }
|> produces
$$"""

Expand All @@ -33,7 +33,7 @@ module RecordExpr =
[<InlineData("net6.0", "``net6.0``")>]
[<InlineData(" net6.0 ", "``net6.0``")>]
let ``Produces an RecordExpr with fields with backticks`` (value: string) (expected: string) =
Oak() { AnonymousModule() { RecordExpr() { RecordFieldExpr(value, ConstantExpr(Unquoted "1")) } } }
Oak() { AnonymousModule() { RecordExpr([ RecordFieldExpr(value, ConstantExpr(Unquoted "1")) ]) } }
|> produces
$$"""

Expand All @@ -43,7 +43,7 @@ module RecordExpr =

[<Fact>]
let ``RecordExpr expression``() =
Oak() { AnonymousModule() { RecordExpr() { RecordFieldExpr("A", ConstantExpr(Unquoted "1")) } } }
Oak() { AnonymousModule() { RecordExpr([ RecordFieldExpr("A", ConstantExpr(Unquoted "1")) ]) } }
|> produces
"""
{ A = 1 }
Expand All @@ -53,7 +53,7 @@ module RecordExpr =
let ``RecordExpr expression with copy info``() =
Oak() {
AnonymousModule() {
RecordExpr(ConstantExpr(Unquoted "A")) { RecordFieldExpr("B", ConstantExpr(Unquoted "1")) }
RecordExpr(ConstantExpr(Unquoted "A"), [ RecordFieldExpr("B", ConstantExpr(Unquoted "1")) ])
}
}
|> produces
Expand All @@ -63,7 +63,7 @@ module RecordExpr =

[<Fact>]
let ``AnonRecordExpr expression``() =
Oak() { AnonymousModule() { AnonRecordExpr() { RecordFieldExpr("A", ConstantExpr(Unquoted "1")) } } }
Oak() { AnonymousModule() { AnonRecordExpr([ RecordFieldExpr("A", ConstantExpr(Unquoted "1")) ]) } }
|> produces
"""
{| A = 1 |}
Expand All @@ -73,7 +73,7 @@ module RecordExpr =
let ``AnonRecordExpr expression with copy info``() =
Oak() {
AnonymousModule() {
AnonRecordExpr(ConstantExpr(Unquoted "A")) { RecordFieldExpr("B", ConstantExpr(Unquoted "1")) }
AnonRecordExpr(ConstantExpr(Unquoted "A"), [ RecordFieldExpr("B", ConstantExpr(Unquoted "1")) ])
}
}
|> produces
Expand Down
16 changes: 9 additions & 7 deletions src/Fabulous.AST.Tests/MemberDefinitions/InterfaceMember.fs
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,10 @@ module InterfaceMembers =
})
.typeParams([ "'other" ])
.interfaces(
[ InterfaceMember("IMyInterface") {
Method("x.GetValue", UnitPat(), ConstantExpr(Unquoted "x.MyField2"))
} ]
[ InterfaceMember(
"IMyInterface",
[ Method("x.GetValue", UnitPat(), ConstantExpr(Unquoted "x.MyField2")) ]
) ]
)
}
}
Expand Down Expand Up @@ -58,9 +59,10 @@ type Colors<'other> =
Field("MyField2", LongIdent("string"))
})
.interfaces(
[ InterfaceMember("IMyInterface") {
Method("x.GetValue", UnitPat(), ConstantExpr(Unquoted "x.MyField2"))
} ]
[ InterfaceMember(
"IMyInterface",
[ Method("x.GetValue", UnitPat(), ConstantExpr(Unquoted "x.MyField2")) ]
) ]
)
}
}
Expand All @@ -85,7 +87,7 @@ type MyRecord =
AnonymousModule() {
Interface("Meh") { AbstractProperty("Name", String()) }

Class("Person") { InterfaceMember("Meh") { Property("this.Name", ConstantExpr(Quoted "23")) } }
Class("Person") { InterfaceMember("Meh", [ Property("this.Name", ConstantExpr(Quoted "23")) ]) }
}
}
|> produces
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -104,11 +104,7 @@ let x (i: int, j: string, k) = ()
AnonymousModule() {
Function(
"x",
LongIdentPat() {
ParameterPat("i")
ParameterPat("j")
ParameterPat("k")
},
LongIdentPat([ ParameterPat("i"); ParameterPat("j"); ParameterPat("k") ]),
ConstantExpr(ConstantUnit())
)
}
Expand Down