@@ -26,12 +26,13 @@ import Prelude
26
26
import Control.Alt ((<|>))
27
27
import Data.Array ((..))
28
28
import Data.Array.NonEmpty as NEA
29
- import Data.Char (toCharCode )
29
+ import Data.Char (fromCharCode , toCharCode )
30
30
import Data.Either (Either (..))
31
+ import Data.Enum (fromEnum )
31
32
import Data.Foldable (class Foldable , foldMap , elem , notElem )
32
33
import Data.Maybe (Maybe (..))
33
- import Data.String.CodePoints (drop , length , indexOf' , stripPrefix )
34
- import Data.String.CodeUnits (charAt , singleton )
34
+ import Data.String.CodePoints (codePointAt , drop , indexOf' , length , stripPrefix )
35
+ import Data.String.CodeUnits (singleton )
35
36
import Data.String.Pattern (Pattern (..))
36
37
import Data.String.Regex as Regex
37
38
import Data.String.Regex.Flags (noFlags )
@@ -48,9 +49,13 @@ eof = Parser \s ->
48
49
-- | Match any character.
49
50
anyChar :: Parser Char
50
51
anyChar = Parser \{ str, pos } ->
51
- case charAt pos str of
52
- Just chr -> Right { result: chr, suffix: { str, pos: pos + 1 } }
52
+ case codePointAt pos str of
53
+ Just cp -> case toChar cp of
54
+ Just chr -> Right { result: chr, suffix: { str, pos: pos + 1 } }
55
+ Nothing -> Left { pos, error: ParseError $ " CodePoint " <> show cp <> " is not a character" }
53
56
Nothing -> Left { pos, error: ParseError " Unexpected EOF" }
57
+ where
58
+ toChar = fromCharCode <<< fromEnum
54
59
55
60
-- | Match any digit.
56
61
anyDigit :: Parser Char
0 commit comments