{-# LANGUAGE CPP #-}
module GHC.Parser.CharClass
( is_ident
, is_symbol
, is_any
, is_space
, is_lower
, is_upper
, is_digit
, is_alphanum
, is_decdigit, is_hexdigit, is_octdigit, is_bindigit
, hexDigit, octDecDigit
) where
#include "HsVersions.h"
import GHC.Prelude
import Data.Char ( ord, chr )
import Data.Word
import GHC.Utils.Panic
cIdent, cSymbol, cAny, cSpace, cLower, cUpper, cDigit :: Word8
cIdent :: Word8
cIdent = Word8
1
cSymbol :: Word8
cSymbol = Word8
2
cAny :: Word8
cAny = Word8
4
cSpace :: Word8
cSpace = Word8
8
cLower :: Word8
cLower = Word8
16
cUpper :: Word8
cUpper = Word8
32
cDigit :: Word8
cDigit = Word8
64
{-# INLINABLE is_ctype #-}
is_ctype :: Word8 -> Char -> Bool
is_ctype :: Word8 -> Char -> Bool
is_ctype Word8
mask Char
c = (Char -> Word8
charType Char
c forall a. Bits a => a -> a -> a
.&. Word8
mask) forall a. Eq a => a -> a -> Bool
/= Word8
0
is_ident, is_symbol, is_any, is_space, is_lower, is_upper, is_digit,
is_alphanum :: Char -> Bool
is_ident :: Char -> Bool
is_ident = Word8 -> Char -> Bool
is_ctype Word8
cIdent
is_symbol :: Char -> Bool
is_symbol = Word8 -> Char -> Bool
is_ctype Word8
cSymbol
is_any :: Char -> Bool
is_any = Word8 -> Char -> Bool
is_ctype Word8
cAny
is_space :: Char -> Bool
is_space = Word8 -> Char -> Bool
is_ctype Word8
cSpace
is_lower :: Char -> Bool
is_lower = Word8 -> Char -> Bool
is_ctype Word8
cLower
is_upper :: Char -> Bool
is_upper = Word8 -> Char -> Bool
is_ctype Word8
cUpper
is_digit :: Char -> Bool
is_digit = Word8 -> Char -> Bool
is_ctype Word8
cDigit
is_alphanum :: Char -> Bool
is_alphanum = Word8 -> Char -> Bool
is_ctype (Word8
cLowerforall a. Num a => a -> a -> a
+Word8
cUpperforall a. Num a => a -> a -> a
+Word8
cDigit)
hexDigit :: Char -> Int
hexDigit :: Char -> Int
hexDigit Char
c | Char -> Bool
is_decdigit Char
c = Char -> Int
ord Char
c forall a. Num a => a -> a -> a
- Char -> Int
ord Char
'0'
| Bool
otherwise = Char -> Int
ord (Char -> Char
to_lower Char
c) forall a. Num a => a -> a -> a
- Char -> Int
ord Char
'a' forall a. Num a => a -> a -> a
+ Int
10
octDecDigit :: Char -> Int
octDecDigit :: Char -> Int
octDecDigit Char
c = Char -> Int
ord Char
c forall a. Num a => a -> a -> a
- Char -> Int
ord Char
'0'
is_decdigit :: Char -> Bool
is_decdigit :: Char -> Bool
is_decdigit Char
c
= Char
c forall a. Ord a => a -> a -> Bool
>= Char
'0' Bool -> Bool -> Bool
&& Char
c forall a. Ord a => a -> a -> Bool
<= Char
'9'
is_hexdigit :: Char -> Bool
is_hexdigit :: Char -> Bool
is_hexdigit Char
c
= Char -> Bool
is_decdigit Char
c
Bool -> Bool -> Bool
|| (Char
c forall a. Ord a => a -> a -> Bool
>= Char
'a' Bool -> Bool -> Bool
&& Char
c forall a. Ord a => a -> a -> Bool
<= Char
'f')
Bool -> Bool -> Bool
|| (Char
c forall a. Ord a => a -> a -> Bool
>= Char
'A' Bool -> Bool -> Bool
&& Char
c forall a. Ord a => a -> a -> Bool
<= Char
'F')
is_octdigit :: Char -> Bool
is_octdigit :: Char -> Bool
is_octdigit Char
c = Char
c forall a. Ord a => a -> a -> Bool
>= Char
'0' Bool -> Bool -> Bool
&& Char
c forall a. Ord a => a -> a -> Bool
<= Char
'7'
is_bindigit :: Char -> Bool
is_bindigit :: Char -> Bool
is_bindigit Char
c = Char
c forall a. Eq a => a -> a -> Bool
== Char
'0' Bool -> Bool -> Bool
|| Char
c forall a. Eq a => a -> a -> Bool
== Char
'1'
to_lower :: Char -> Char
to_lower :: Char -> Char
to_lower Char
c
| Char
c forall a. Ord a => a -> a -> Bool
>= Char
'A' Bool -> Bool -> Bool
&& Char
c forall a. Ord a => a -> a -> Bool
<= Char
'Z' = Int -> Char
chr (Char -> Int
ord Char
c forall a. Num a => a -> a -> a
- (Char -> Int
ord Char
'A' forall a. Num a => a -> a -> a
- Char -> Int
ord Char
'a'))
| Bool
otherwise = Char
c
charType :: Char -> Word8
charType :: Char -> Word8
charType Char
c = case Char
c of
Char
'\0' -> Word8
0
Char
'\1' -> Word8
0
Char
'\2' -> Word8
0
Char
'\3' -> Word8
0
Char
'\4' -> Word8
0
Char
'\5' -> Word8
0
Char
'\6' -> Word8
0
Char
'\7' -> Word8
0
Char
'\8' -> Word8
0
Char
'\9' -> Word8
cSpace
Char
'\10' -> Word8
cSpace
Char
'\11' -> Word8
cSpace
Char
'\12' -> Word8
cSpace
Char
'\13' -> Word8
cSpace
Char
'\14' -> Word8
0
Char
'\15' -> Word8
0
Char
'\16' -> Word8
0
Char
'\17' -> Word8
0
Char
'\18' -> Word8
0
Char
'\19' -> Word8
0
Char
'\20' -> Word8
0
Char
'\21' -> Word8
0
Char
'\22' -> Word8
0
Char
'\23' -> Word8
0
Char
'\24' -> Word8
0
Char
'\25' -> Word8
0
Char
'\26' -> Word8
0
Char
'\27' -> Word8
0
Char
'\28' -> Word8
0
Char
'\29' -> Word8
0
Char
'\30' -> Word8
0
Char
'\31' -> Word8
0
Char
'\32' -> Word8
cAny forall a. Bits a => a -> a -> a
.|. Word8
cSpace
Char
'\33' -> Word8
cAny forall a. Bits a => a -> a -> a
.|. Word8
cSymbol
Char
'\34' -> Word8
cAny
Char
'\35' -> Word8
cAny forall a. Bits a => a -> a -> a
.|. Word8
cSymbol
Char
'\36' -> Word8
cAny forall a. Bits a => a -> a -> a
.|. Word8
cSymbol
Char
'\37' -> Word8
cAny forall a. Bits a => a -> a -> a
.|. Word8
cSymbol
Char
'\38' -> Word8
cAny forall a. Bits a => a -> a -> a
.|. Word8
cSymbol
Char
'\39' -> Word8
cAny forall a. Bits a => a -> a -> a
.|. Word8
cIdent
Char
'\40' -> Word8
cAny
Char
'\41' -> Word8
cAny
Char
'\42' -> Word8
cAny forall a. Bits a => a -> a -> a
.|. Word8
cSymbol
Char
'\43' -> Word8
cAny forall a. Bits a => a -> a -> a
.|. Word8
cSymbol
Char
'\44' -> Word8
cAny
Char
'\45' -> Word8
cAny forall a. Bits a => a -> a -> a
.|. Word8
cSymbol
Char
'\46' -> Word8
cAny forall a. Bits a => a -> a -> a
.|. Word8
cSymbol
Char
'\47' -> Word8
cAny forall a. Bits a => a -> a -> a
.|. Word8
cSymbol
Char
'\48' -> Word8
cAny forall a. Bits a => a -> a -> a
.|. Word8
cIdent forall a. Bits a => a -> a -> a
.|. Word8
cDigit
Char
'\49' -> Word8
cAny forall a. Bits a => a -> a -> a
.|. Word8
cIdent forall a. Bits a => a -> a -> a
.|. Word8
cDigit
Char
'\50' -> Word8
cAny forall a. Bits a => a -> a -> a
.|. Word8
cIdent forall a. Bits a => a -> a -> a
.|. Word8
cDigit
Char
'\51' -> Word8
cAny forall a. Bits a => a -> a -> a
.|. Word8
cIdent forall a. Bits a => a -> a -> a
.|. Word8
cDigit
Char
'\52' -> Word8
cAny forall a. Bits a => a -> a -> a
.|. Word8
cIdent forall a. Bits a => a -> a -> a
.|. Word8
cDigit
Char
'\53' -> Word8
cAny forall a. Bits a => a -> a -> a
.|. Word8
cIdent forall a. Bits a => a -> a -> a
.|. Word8
cDigit
Char
'\54' -> Word8
cAny forall a. Bits a => a -> a -> a
.|. Word8
cIdent forall a. Bits a => a -> a -> a
.|. Word8
cDigit
Char
'\55' -> Word8
cAny forall a. Bits a => a -> a -> a
.|. Word8
cIdent forall a. Bits a => a -> a -> a
.|. Word8
cDigit
Char
'\56' -> Word8
cAny forall a. Bits a => a -> a -> a
.|. Word8
cIdent forall a. Bits a => a -> a -> a
.|. Word8
cDigit
Char
'\57' -> Word8
cAny forall a. Bits a => a -> a -> a
.|. Word8
cIdent forall a. Bits a => a -> a -> a
.|. Word8
cDigit
Char
'\58' -> Word8
cAny forall a. Bits a => a -> a -> a
.|. Word8
cSymbol
Char
'\59' -> Word8
cAny
Char
'\60' -> Word8
cAny forall a. Bits a => a -> a -> a
.|. Word8
cSymbol
Char
'\61' -> Word8
cAny forall a. Bits a => a -> a -> a
.|. Word8
cSymbol
Char
'\62' -> Word8
cAny forall a. Bits a => a -> a -> a
.|. Word8
cSymbol
Char
'\63' -> Word8
cAny forall a. Bits a => a -> a -> a
.|. Word8
cSymbol
Char
'\64' -> Word8
cAny forall a. Bits a => a -> a -> a
.|. Word8
cSymbol
Char
'\65' -> Word8
cAny forall a. Bits a => a -> a -> a
.|. Word8
cIdent forall a. Bits a => a -> a -> a
.|. Word8
cUpper
Char
'\66' -> Word8
cAny forall a. Bits a => a -> a -> a
.|. Word8
cIdent forall a. Bits a => a -> a -> a
.|. Word8
cUpper
Char
'\67' -> Word8
cAny forall a. Bits a => a -> a -> a
.|. Word8
cIdent forall a. Bits a => a -> a -> a
.|. Word8
cUpper
Char
'\68' -> Word8
cAny forall a. Bits a => a -> a -> a
.|. Word8
cIdent forall a. Bits a => a -> a -> a
.|. Word8
cUpper
Char
'\69' -> Word8
cAny forall a. Bits a => a -> a -> a
.|. Word8
cIdent forall a. Bits a => a -> a -> a
.|. Word8
cUpper
Char
'\70' -> Word8
cAny forall a. Bits a => a -> a -> a
.|. Word8
cIdent forall a. Bits a => a -> a -> a
.|. Word8
cUpper
Char
'\71' -> Word8
cAny forall a. Bits a => a -> a -> a
.|. Word8
cIdent forall a. Bits a => a -> a -> a
.|. Word8
cUpper
Char
'\72' -> Word8
cAny forall a. Bits a => a -> a -> a
.|. Word8
cIdent forall a. Bits a => a -> a -> a
.|. Word8
cUpper
Char
'\73' -> Word8
cAny forall a. Bits a => a -> a -> a
.|. Word8
cIdent forall a. Bits a => a -> a -> a
.|. Word8
cUpper
Char
'\74' -> Word8
cAny forall a. Bits a => a -> a -> a
.|. Word8
cIdent forall a. Bits a => a -> a -> a
.|. Word8
cUpper
Char
'\75' -> Word8
cAny forall a. Bits a => a -> a -> a
.|. Word8
cIdent forall a. Bits a => a -> a -> a
.|. Word8
cUpper
Char
'\76' -> Word8
cAny forall a. Bits a => a -> a -> a
.|. Word8
cIdent forall a. Bits a => a -> a -> a
.|. Word8
cUpper
Char
'\77' -> Word8
cAny forall a. Bits a => a -> a -> a
.|. Word8
cIdent forall a. Bits a => a -> a -> a
.|. Word8
cUpper
Char
'\78' -> Word8
cAny forall a. Bits a => a -> a -> a
.|. Word8
cIdent forall a. Bits a => a -> a -> a
.|. Word8
cUpper
Char
'\79' -> Word8
cAny forall a. Bits a => a -> a -> a
.|. Word8
cIdent forall a. Bits a => a -> a -> a
.|. Word8
cUpper
Char
'\80' -> Word8
cAny forall a. Bits a => a -> a -> a
.|. Word8
cIdent forall a. Bits a => a -> a -> a
.|. Word8
cUpper
Char
'\81' -> Word8
cAny forall a. Bits a => a -> a -> a
.|. Word8
cIdent forall a. Bits a => a -> a -> a
.|. Word8
cUpper
Char
'\82' -> Word8
cAny forall a. Bits a => a -> a -> a
.|. Word8
cIdent forall a. Bits a => a -> a -> a
.|. Word8
cUpper
Char
'\83' -> Word8
cAny forall a. Bits a => a -> a -> a
.|. Word8
cIdent forall a. Bits a => a -> a -> a
.|. Word8
cUpper
Char
'\84' -> Word8
cAny forall a. Bits a => a -> a -> a
.|. Word8
cIdent forall a. Bits a => a -> a -> a
.|. Word8
cUpper
Char
'\85' -> Word8
cAny forall a. Bits a => a -> a -> a
.|. Word8
cIdent forall a. Bits a => a -> a -> a
.|. Word8
cUpper
Char
'\86' -> Word8
cAny forall a. Bits a => a -> a -> a
.|. Word8
cIdent forall a. Bits a => a -> a -> a
.|. Word8
cUpper
Char
'\87' -> Word8
cAny forall a. Bits a => a -> a -> a
.|. Word8
cIdent forall a. Bits a => a -> a -> a
.|. Word8
cUpper
Char
'\88' -> Word8
cAny forall a. Bits a => a -> a -> a
.|. Word8
cIdent forall a. Bits a => a -> a -> a
.|. Word8
cUpper
Char
'\89' -> Word8
cAny forall a. Bits a => a -> a -> a
.|. Word8
cIdent forall a. Bits a => a -> a -> a
.|. Word8
cUpper
Char
'\90' -> Word8
cAny forall a. Bits a => a -> a -> a
.|. Word8
cIdent forall a. Bits a => a -> a -> a
.|. Word8
cUpper
Char
'\91' -> Word8
cAny
Char
'\92' -> Word8
cAny forall a. Bits a => a -> a -> a
.|. Word8
cSymbol
Char
'\93' -> Word8
cAny
Char
'\94' -> Word8
cAny forall a. Bits a => a -> a -> a
.|. Word8
cSymbol
Char
'\95' -> Word8
cAny forall a. Bits a => a -> a -> a
.|. Word8
cIdent forall a. Bits a => a -> a -> a
.|. Word8
cLower
Char
'\96' -> Word8
cAny
Char
'\97' -> Word8
cAny forall a. Bits a => a -> a -> a
.|. Word8
cIdent forall a. Bits a => a -> a -> a
.|. Word8
cLower
Char
'\98' -> Word8
cAny forall a. Bits a => a -> a -> a
.|. Word8
cIdent forall a. Bits a => a -> a -> a
.|. Word8
cLower
Char
'\99' -> Word8
cAny forall a. Bits a => a -> a -> a
.|. Word8
cIdent forall a. Bits a => a -> a -> a
.|. Word8
cLower
Char
'\100' -> Word8
cAny forall a. Bits a => a -> a -> a
.|. Word8
cIdent forall a. Bits a => a -> a -> a
.|. Word8
cLower
Char
'\101' -> Word8
cAny forall a. Bits a => a -> a -> a
.|. Word8
cIdent forall a. Bits a => a -> a -> a
.|. Word8
cLower
Char
'\102' -> Word8
cAny forall a. Bits a => a -> a -> a
.|. Word8
cIdent forall a. Bits a => a -> a -> a
.|. Word8
cLower
Char
'\103' -> Word8
cAny forall a. Bits a => a -> a -> a
.|. Word8
cIdent forall a. Bits a => a -> a -> a
.|. Word8
cLower
Char
'\104' -> Word8
cAny forall a. Bits a => a -> a -> a
.|. Word8
cIdent forall a. Bits a => a -> a -> a
.|. Word8
cLower
Char
'\105' -> Word8
cAny forall a. Bits a => a -> a -> a
.|. Word8
cIdent forall a. Bits a => a -> a -> a
.|. Word8
cLower
Char
'\106' -> Word8
cAny forall a. Bits a => a -> a -> a
.|. Word8
cIdent forall a. Bits a => a -> a -> a
.|. Word8
cLower
Char
'\107' -> Word8
cAny forall a. Bits a => a -> a -> a
.|. Word8
cIdent forall a. Bits a => a -> a -> a
.|. Word8
cLower
Char
'\108' -> Word8
cAny forall a. Bits a => a -> a -> a
.|. Word8
cIdent forall a. Bits a => a -> a -> a
.|. Word8
cLower
Char
'\109' -> Word8
cAny forall a. Bits a => a -> a -> a
.|. Word8
cIdent forall a. Bits a => a -> a -> a
.|. Word8
cLower
Char
'\110' -> Word8
cAny forall a. Bits a => a -> a -> a
.|. Word8
cIdent forall a. Bits a => a -> a -> a
.|. Word8
cLower
Char
'\111' -> Word8
cAny forall a. Bits a => a -> a -> a
.|. Word8
cIdent forall a. Bits a => a -> a -> a
.|. Word8
cLower
Char
'\112' -> Word8
cAny forall a. Bits a => a -> a -> a
.|. Word8
cIdent forall a. Bits a => a -> a -> a
.|. Word8
cLower
Char
'\113' -> Word8
cAny forall a. Bits a => a -> a -> a
.|. Word8
cIdent forall a. Bits a => a -> a -> a
.|. Word8
cLower
Char
'\114' -> Word8
cAny forall a. Bits a => a -> a -> a
.|. Word8
cIdent forall a. Bits a => a -> a -> a
.|. Word8
cLower
Char
'\115' -> Word8
cAny forall a. Bits a => a -> a -> a
.|. Word8
cIdent forall a. Bits a => a -> a -> a
.|. Word8
cLower
Char
'\116' -> Word8
cAny forall a. Bits a => a -> a -> a
.|. Word8
cIdent forall a. Bits a => a -> a -> a
.|. Word8
cLower
Char
'\117' -> Word8
cAny forall a. Bits a => a -> a -> a
.|. Word8
cIdent forall a. Bits a => a -> a -> a
.|. Word8
cLower
Char
'\118' -> Word8
cAny forall a. Bits a => a -> a -> a
.|. Word8
cIdent forall a. Bits a => a -> a -> a
.|. Word8
cLower
Char
'\119' -> Word8
cAny forall a. Bits a => a -> a -> a
.|. Word8
cIdent forall a. Bits a => a -> a -> a
.|. Word8
cLower
Char
'\120' -> Word8
cAny forall a. Bits a => a -> a -> a
.|. Word8
cIdent forall a. Bits a => a -> a -> a
.|. Word8
cLower
Char
'\121' -> Word8
cAny forall a. Bits a => a -> a -> a
.|. Word8
cIdent forall a. Bits a => a -> a -> a
.|. Word8
cLower
Char
'\122' -> Word8
cAny forall a. Bits a => a -> a -> a
.|. Word8
cIdent forall a. Bits a => a -> a -> a
.|. Word8
cLower
Char
'\123' -> Word8
cAny
Char
'\124' -> Word8
cAny forall a. Bits a => a -> a -> a
.|. Word8
cSymbol
Char
'\125' -> Word8
cAny
Char
'\126' -> Word8
cAny forall a. Bits a => a -> a -> a
.|. Word8
cSymbol
Char
'\127' -> Word8
0
Char
_ -> forall a. String -> a
panic (String
"charType: " forall a. [a] -> [a] -> [a]
++ forall a. Show a => a -> String
show Char
c)