File tree Expand file tree Collapse file tree 2 files changed +7
-12
lines changed
src/Text/Parsing/StringParser Expand file tree Collapse file tree 2 files changed +7
-12
lines changed Original file line number Diff line number Diff line change @@ -29,8 +29,6 @@ import Control.Alt ((<|>))
2929import Text.Parsing.StringParser.Combinators (many , (<?>))
3030import Text.Parsing.StringParser
3131
32- import qualified Data.String.Regex as Rx
33-
3432-- | Match the end of the file.
3533eof :: Parser Unit
3634eof = Parser (\s fc sc -> case s of
@@ -46,16 +44,11 @@ anyChar = Parser (\s fc sc -> case s of
4644
4745-- | Match any digit.
4846anyDigit :: Parser Char
49- anyDigit = Parser \{ str: str, pos: i } fc sc -> case charAt i str of
50- Just chr ->
51- let chrS = fromChar chr
52- in if Rx .test rxDigit chrS
53- then sc chr { str: str, pos: i + 1 }
54- else fc i (ParseError " Expected digit" )
55- Nothing -> fc i (ParseError " Unexpected EOF" )
56- where
57- rxDigit :: Rx.Regex
58- rxDigit = Rx .regex " ^[0-9]" Rx .noFlags
47+ anyDigit = try do
48+ c <- anyChar
49+ if c >= ' 0' && c <= ' 9'
50+ then return c
51+ else fail $ " Character " <> toString c <> " is not a digit"
5952
6053-- | Match the specified string.
6154string :: String -> Parser String
Original file line number Diff line number Diff line change @@ -72,3 +72,5 @@ main = do
7272 parseTest opTest " a+b+c"
7373 parseTest exprTest " 1*2+3/4-5"
7474 parseTest tryTest " aacc"
75+ parseTest (many1 anyDigit) " 01234/"
76+ parseTest (many1 anyDigit) " 56789:"
You can’t perform that action at this time.
0 commit comments