module Text.Haiji.Syntax.Identifier
( Identifier
, identifier
) where
import Control.Applicative
import Control.Monad
import Data.Attoparsec.Text
import Data.String
newtype Identifier = Identifier { unIdentifier :: String } deriving Eq
instance Show Identifier where
show = unIdentifier
instance IsString Identifier where
fromString = Identifier
identifier :: Parser Identifier
identifier = do
h <- letter <|> char '_'
ts <- many (letter <|> digit <|> char '_')
let candidate = h : ts
when (candidate `elem` keywords) $ fail "identifier"
return $ Identifier candidate
keywords :: [String]
keywords = words "and del from not while \
\as elif global or with \
\assert else if pass yield \
\break except import print \
\class exec in raise \
\continue finally is return \
\def for lambda try "