Using the monadic parser Sprache, looking to match numeric characters (0..9), excluding non-numeric characters, but leading or trailing whitespace is ok.
I thought this should work:
public static readonly Parser<string>
Number = Parse.Numeric.Except(Parse.Letter).AtLeastOnce().Text().Token();
or this:
public static readonly Parser<int>
Number = Parse.Number.Select(int.Parse).Token();
Both work for all cases I could think of, except trailing text:
[Test]
public void Number_ParseNumberWithTrailingLetter_WasUnsuccessfull()
{
var input = new Input("123bogus");
IResult<string> result = Lexicon.Number(input);
Assert.IsFalse(result.WasSuccessful);
}
Any clues?