Skip to content

Commit

Permalink
improve inline documentation
Browse files Browse the repository at this point in the history
  • Loading branch information
HLWeil committed Mar 23, 2022
1 parent ec38907 commit cc5c713
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 22 deletions.
52 changes: 33 additions & 19 deletions src/LitXml/DSL.fs
Original file line number Diff line number Diff line change
Expand Up @@ -7,46 +7,60 @@ open Expression
[<AutoOpen>]
type DSL =

/// Create an xml element with given name
static member inline elem name = ElementBuilder(name)

/// Create an xml attriubte with given name and value
static member inline attr name value : Attr =
ok (fun tb ->
tb.WriteAttributeString(name, string value)
)

static member inline value (s: 'a when 'a :> System.IEquatable<'a>) : Value =
/// Create an xml value from the given value
static member inline value (s : string) : Value =
ok (fun tb ->
tb.WriteString(string s)
)
tb.WriteString(s)
)

/// Create an xml value from the given value
static member inline value<'T when 'T :> System.IFormattable> (v : 'T) : Value =
ok (fun tb ->
tb.WriteString(v.ToString())
)

static member inline value (s : Expr<'a> when 'a :> System.IEquatable<'a>) : Value =
/// Create an ok xml value from the given value expression if it succedes. Else returns a missing required.
static member inline value (s : Quotations.Expr<string>) : Value =
try
let value = eval<'a> s
let f = (fun (sb : XmlWriter) ->
sb.WriteString(string value)
)
ok f
let s = Expression.eval<string> s
ok (fun tb ->
tb.WriteString(s)
)
with
| err -> MissingRequired([err.Message])



/// Create an ok xml value from the given value expression if it succedes. Else returns a missing required.
static member inline value (s : Quotations.Expr<'a> when 'a :> System.IFormattable) : Value =
try
let v = Expression.eval<'a> s
ok (fun tb ->
tb.WriteString(v.ToString())
)
with
| err -> MissingRequired([err.Message])

/// Transforms any given xml element to an ok.
static member opt (elem : Element) =
match elem with
| Ok (f,messages) -> elem
| MissingOptional (messages) -> Ok((fun tb -> ()),messages)
| MissingRequired (messages) -> Ok((fun tb -> ()),messages)

/// Transforms any given xml element expression to an ok.
static member opt (elem : Expr<Element>) =
try
let elem = eval<Element> elem
match elem with
| Ok (f,messages) -> elem
| MissingOptional (messages) -> Ok((fun tb -> ()),messages)
| MissingRequired (messages) -> Ok((fun tb -> ()),messages)
DSL.opt elem
with
| err ->
let f = (fun (sb : XmlWriter) ->
()
)
let f = (fun (sb : XmlWriter) -> ())
Ok(f,[err.Message])

7 changes: 6 additions & 1 deletion src/LitXml/ElementBuilder.fs
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,16 @@ type ElementBuilder(name: string) =
messages
|> List.map (sprintf "In Element \"%s\": %s" this.Name)

member inline _.Yield(n: 'a when 'a :> System.IEquatable<'a>) =
member inline _.Yield(n: 'a when 'a :> System.IFormattable) =
ok (fun tb ->
tb.WriteString(string n)
)

member inline _.Yield(s : string) =
ok (fun tb ->
tb.WriteString(s)
)

member inline _.Yield(n: XmlPart) = n

member inline _.Yield(b: ElementBuilder) =
Expand Down
4 changes: 2 additions & 2 deletions src/LitXml/Operators.fs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ module Operators =
/// Required value operator
///
/// If expression does fail, returns a missing required value
let inline (!!) (s : Expr<'a> when 'a :> System.IEquatable<'a>) : Value =
let inline (!!) (s : Expr<'a>) : Value =
try
let value = eval<'a> s
let f = (fun (sb : XmlWriter) ->
Expand All @@ -23,7 +23,7 @@ module Operators =
/// Optional value operator
///
/// If expression does fail, returns a missing optional value
let inline (!?) (s : Expr<'a> when 'a :> System.IEquatable<'a>) : Value =
let inline (!?) (s : Expr<'a>) : Value =
try
let value = eval<'a> s
let f = (fun (sb : XmlWriter) ->
Expand Down

0 comments on commit cc5c713

Please sign in to comment.