-
Notifications
You must be signed in to change notification settings - Fork 1
/
numbers.go
59 lines (48 loc) · 1.75 KB
/
numbers.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
package gomme
// import "math"
// Float parses a sequence of numerical characters into a float64.
// The '.' character is used as the optional decimal delimiter. Any
// number without a decimal part will still be parsed as a float64.
//
// N.B: it is not the parser's role to make sure the floating point
// number you're attempting to parse fits into a 64 bits float.
// func Float[I Bytes]() Parser[I, float64] {
// digitsParser := TakeWhileOneOf[I]([]rune("0123456789")...)
// minusParser := Char[I]('-')
// dotParser := Char[I]('.')
// return func(input I) Result[float64, I] {
// var negative bool
// minusresult := minusParser(input)
// if result.Err == nil {
// negative = true
// }
// result = digitsParser(result.Remaining)
// // result = Expect(digitsParser, "digits")(result.Remaining)
// // if result.Err != nil {
// // return result
// // }
// parsed, ok := result.Output.(string)
// if !ok {
// err := fmt.Errorf("failed parsing floating point value; " +
// "reason: converting Float() parser result's output to string failed",
// )
// return Failure(NewFatalError(input, err, "float"), input)
// }
// if resultTest := dotParser(result.Remaining); resultTest.Err == nil {
// if resultTest = digitsParser(resultTest.Remaining); resultTest.Err == nil {
// parsed = parsed + "." + resultTest.Output.(string)
// result = resultTest
// }
// }
// floatingPointValue, err := strconv.ParseFloat(parsed, 64)
// if err != nil {
// err = fmt.Errorf("failed to parse '%v' as float; reason: %w", parsed, err)
// return Failure(NewFatalError(input, err), input)
// }
// if negative {
// floatingPointValue = -floatingPointValue
// }
// result.Output = floatingPointValue
// return result
// }
// }