Skip to content

Commit 260a27d

Browse files
committed
Merge pull request #18 from libscott/no-regex
No regex
2 parents 849072c + 64cf9b9 commit 260a27d

File tree

2 files changed

+7
-12
lines changed

2 files changed

+7
-12
lines changed

src/Text/Parsing/StringParser/String.purs

Lines changed: 5 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,6 @@ import Control.Alt ((<|>))
2929
import Text.Parsing.StringParser.Combinators (many, (<?>))
3030
import Text.Parsing.StringParser
3131

32-
import qualified Data.String.Regex as Rx
33-
3432
-- | Match the end of the file.
3533
eof :: Parser Unit
3634
eof = Parser (\s fc sc -> case s of
@@ -46,16 +44,11 @@ anyChar = Parser (\s fc sc -> case s of
4644

4745
-- | Match any digit.
4846
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"
5952

6053
-- | Match the specified string.
6154
string :: String -> Parser String

test/Main.purs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff 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:"

0 commit comments

Comments
 (0)