Add new decoder combinators
This commit is contained in:
parent
0a3a8fc81a
commit
421924a339
1 changed files with 27 additions and 2 deletions
|
@ -84,7 +84,7 @@ pub fn string(then next: NextFn(String, a)) -> Decoder(a) {
|
|||
}
|
||||
}
|
||||
|
||||
pub fn name_string(then next: NextFn(String, a)) -> Decoder(a) {
|
||||
pub fn name(then next: NextFn(String, a)) -> Decoder(a) {
|
||||
fn(sexprs: List(SExpr)) {
|
||||
case sexprs {
|
||||
[] -> Error(UnexpectedEndOfAttributes(String))
|
||||
|
@ -94,7 +94,7 @@ pub fn name_string(then next: NextFn(String, a)) -> Decoder(a) {
|
|||
}
|
||||
}
|
||||
|
||||
pub fn name_or_string(then next: NextFn(String, a)) -> Decoder(a) {
|
||||
pub fn name_string(then next: NextFn(String, a)) -> Decoder(a) {
|
||||
fn(sexprs: List(SExpr)) {
|
||||
case sexprs {
|
||||
[] -> Error(UnexpectedEndOfAttributes(String))
|
||||
|
@ -105,6 +105,31 @@ pub fn name_or_string(then next: NextFn(String, a)) -> Decoder(a) {
|
|||
}
|
||||
}
|
||||
|
||||
pub fn name_number(then next: NextFn(String, a)) -> Decoder(a) {
|
||||
fn(sexprs: List(SExpr)) {
|
||||
case sexprs {
|
||||
[] -> Error(UnexpectedEndOfAttributes(String))
|
||||
[parse.Name(value), ..sexprs] -> next(value)(sexprs)
|
||||
[parse.Int(value), ..sexprs] -> next(int.to_string(value))(sexprs)
|
||||
[parse.Float(value), ..sexprs] -> next(float.to_string(value))(sexprs)
|
||||
[sexpr, ..] -> Error(IncorrectExprType(got: sexpr, expected: String))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
pub fn name_number_string(then next: NextFn(String, a)) -> Decoder(a) {
|
||||
fn(sexprs: List(SExpr)) {
|
||||
case sexprs {
|
||||
[] -> Error(UnexpectedEndOfAttributes(String))
|
||||
[parse.Name(value), ..sexprs] | [parse.String(value), ..sexprs] ->
|
||||
next(value)(sexprs)
|
||||
[parse.Int(value), ..sexprs] -> next(int.to_string(value))(sexprs)
|
||||
[parse.Float(value), ..sexprs] -> next(float.to_string(value))(sexprs)
|
||||
[sexpr, ..] -> Error(IncorrectExprType(got: sexpr, expected: String))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
pub fn float(then next: NextFn(Float, a)) -> Decoder(a) {
|
||||
fn(sexprs: List(SExpr)) {
|
||||
case sexprs {
|
||||
|
|
Loading…
Reference in a new issue