Skip to content

Commit

Permalink
Merge pull request #111 from statebox/64/allow-identifiers-to-be-quot…
Browse files Browse the repository at this point in the history
…ed-in-parsing

allow any character (except `"`) in quoted identifiers #64
  • Loading branch information
wisnesky committed Oct 26, 2018
2 parents d076c1d + 82ab593 commit ab6c775
Showing 1 changed file with 7 additions and 3 deletions.
10 changes: 7 additions & 3 deletions src/Language/Parser/Parser.hs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@ module Language.Parser.Parser where
import Language.Parser.LexerRules
import Language.Parser.ReservedWords

-- base
import Data.Char

-- megaparsec
import Text.Megaparsec
import Text.Megaparsec.Char
Expand Down Expand Up @@ -34,10 +37,11 @@ optionParser =
return (i,j)

identifier :: Parser String
identifier = (lexeme . try) (p' >>= check)
identifier = (lexeme . try) (p >>= check)
where
p = lowerId <|> upperId <|> specialId
p' = p <|> between (char '"') (char '"') (unwords <$> some (lexeme p))
unquotedIdentifier = lowerId <|> upperId <|> specialId
quotedIdentifier = between (char '"') (char '"') $ some $ satisfy (\c -> isPrint c && (c /= '"'))
p = unquotedIdentifier <|> quotedIdentifier
check x =
if x `elem` reservedWords
then fail $ "keyword" ++ show x ++ "cannot be used as an identifier"
Expand Down

0 comments on commit ab6c775

Please sign in to comment.