@@ -32,7 +32,6 @@ import Data.Foldable (class Foldable, foldMap, elem, notElem)
32
32
import Data.Maybe (Maybe (..))
33
33
import Data.String.CodeUnits (charAt , singleton )
34
34
import Data.String.CodeUnits as SCU
35
- import Data.String.Pattern (Pattern (..))
36
35
import Data.String.Regex as Regex
37
36
import Data.String.Regex.Flags (noFlags )
38
37
import Text.Parsing.StringParser (Parser (..), try , fail )
@@ -61,10 +60,13 @@ anyDigit = try do
61
60
62
61
-- | Match the specified string.
63
62
string :: String -> Parser String
64
- string nt = Parser \s ->
65
- case s of
66
- { substr, posFromStart } | SCU .indexOf (Pattern nt) substr == Just 0 -> Right { result: nt, suffix: { substr: SCU .drop (SCU .length nt) substr, posFromStart: posFromStart + SCU .length nt } }
67
- { posFromStart } -> Left { pos: posFromStart, error: " Expected '" <> nt <> " '." }
63
+ string pattern = Parser \{ substr, posFromStart } ->
64
+ let
65
+ length = SCU .length pattern
66
+ { before, after } = SCU .splitAt length substr
67
+ in
68
+ if before == pattern then Right { result: pattern, suffix: { substr: after, posFromStart: posFromStart + length } }
69
+ else Left { pos: posFromStart, error: " Expected '" <> pattern <> " '." }
68
70
69
71
-- | Match a character satisfying the given predicate.
70
72
satisfy :: (Char -> Boolean ) -> Parser Char
0 commit comments