@@ -88,9 +88,25 @@ if !n.Matched { return n, s } if n.Content == value { return n, r + } + return N{Matched: false, Content: "", Nodes: []N{n}}, s + } +} + +// Returns a parser that matches any single digit +// It could have been written as Any(String("0"),String("1"),...,String("9")) as well :) +func Digit() P { + accept := Accept(1) + return func(s string) (N, string) { + n, r := accept(s) + if !n.Matched { + return n, s + } + if n.Content[0] >= 48 && n.Content[0] <= 57 { + return n, r } return N{Matched: false, Content: "", Nodes: []N{n}}, s } }