Skip to content

Commit 18e85ed

Browse files
committed
improve performance of Char parsers with fixed domain
1 parent 5119643 commit 18e85ed

File tree

1 file changed

+4
-3
lines changed

1 file changed

+4
-3
lines changed

src/Text/Parsing/StringParser/CodePoints.purs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ import Data.String.Regex as Regex
3737
import Data.String.Regex.Flags (noFlags)
3838
import Text.Parsing.StringParser (Parser(..), try, fail)
3939
import Text.Parsing.StringParser.Combinators (many, (<?>))
40+
import Text.Parsing.StringParser.CodeUnits as CodeUnitsParser
4041

4142
-- | Match the end of the file.
4243
eof :: Parser Unit
@@ -59,7 +60,7 @@ anyChar = Parser \{ substr, posFromStart } ->
5960
-- | Match any digit.
6061
anyDigit :: Parser Char
6162
anyDigit = try do
62-
c <- anyChar
63+
c <- CodeUnitsParser.anyChar
6364
if c >= '0' && c <= '9' then pure c
6465
else fail $ "Character " <> show c <> " is not a digit"
6566

@@ -105,14 +106,14 @@ noneOf = satisfy <<< flip notElem
105106
-- | Match any lower case character.
106107
lowerCaseChar :: Parser Char
107108
lowerCaseChar = try do
108-
c <- anyChar
109+
c <- CodeUnitsParser.anyChar
109110
if toCharCode c `elem` (97 .. 122) then pure c
110111
else fail $ "Expected a lower case character but found " <> show c
111112

112113
-- | Match any upper case character.
113114
upperCaseChar :: Parser Char
114115
upperCaseChar = try do
115-
c <- anyChar
116+
c <- CodeUnitsParser.anyChar
116117
if toCharCode c `elem` (65 .. 90) then pure c
117118
else fail $ "Expected an upper case character but found " <> show c
118119

0 commit comments

Comments
 (0)