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 ((<|>))
29
29
import Text.Parsing.StringParser.Combinators (many , (<?>))
30
30
import Text.Parsing.StringParser
31
31
32
- import qualified Data.String.Regex as Rx
33
-
34
32
-- | Match the end of the file.
35
33
eof :: Parser Unit
36
34
eof = Parser (\s fc sc -> case s of
@@ -46,16 +44,11 @@ anyChar = Parser (\s fc sc -> case s of
46
44
47
45
-- | Match any digit.
48
46
anyDigit :: 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"
59
52
60
53
-- | Match the specified string.
61
54
string :: String -> Parser String
Original file line number Diff line number Diff line change @@ -72,3 +72,5 @@ main = do
72
72
parseTest opTest " a+b+c"
73
73
parseTest exprTest " 1*2+3/4-5"
74
74
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