I wonder if there is a better way to parse signed integer using Sprache parser framework.
There is well known parser definition for integers without sign
Parse.Number.Select(int.Parse)
But I want to parse integers with - prefix as well.
What I have got right now is Parse.Regex(@"\-?\d+").Select(int.Parse).
Is there a better way to do that without using regular expressions?
For example use Parse.Char('-').Optional() and then parse following number.
Thanks
The way I do this is similar to the following:
Of course, leave out the trailingSpaces portion depending on the context of what you're parsing.