module SMR.Source.Token where
import Data.Text (Text)
data Token
= KEnd
| KPunc Char
| KName Space Text
| KNat Integer
| KText Text
deriving (Show, Eq)
data Space
= SVar
| SMac
| SSym
| SSet
| SPrm
| SKey
| SNom
deriving (Show, Eq)
isToken :: Token -> Token -> Bool
isToken k1 k2 = k1 == k2
isKPunc :: Char -> Token -> Bool
isKPunc c k
= case k of
KPunc c' -> c == c'
_ -> False
takeNameOfToken :: Space -> Token -> Maybe Text
takeNameOfToken ss1 kk
= case kk of
KName ss2 n
| ss1 == ss2 -> Just n
| otherwise -> Nothing
_ -> Nothing
takeAnyNameOfToken :: Token -> Maybe (Space, Text)
takeAnyNameOfToken kk
= case kk of
KName ss2 n -> Just (ss2, n)
_ -> Nothing
takeNatOfToken :: Token -> Maybe Integer
takeNatOfToken kk
= case kk of
KNat n -> Just n
_ -> Nothing
takeTextOfToken :: Token -> Maybe Text
takeTextOfToken kk
= case kk of
KText tx -> Just tx
_ -> Nothing