Skip to content

Cabal add module #3

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: cabal-add-module
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 13 additions & 1 deletion cabal-parser/src/Text/Cabal/Parser.hs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import Text.Cabal.Types
import Text.Cabal.Value
import Text.Megaparsec
import Text.Megaparsec.Char
import Data.Char (isSpace)

--------------------------------
-- Parser
Expand Down Expand Up @@ -67,7 +68,7 @@ fieldParser indentation = do
hspace
((kw, vals), fieldLoc) <- annotateSrcLoc $ do
(keyword, kwLoc) <- annotateSrcLoc $ choice [keywordParser, externalKeywordParser]
let valParser = fromMaybe defaultValueParser $ M.lookup keyword allKeywords
let valParser = fromMaybe defaultValueParser $ M.lookup (normalize keyword) allKeywords
values <- valuesParser valParser indentNum
pure (KeyWord keyword (Annotation Nothing kwLoc), values)
pure (Just indentNum, Field kw vals (Annotation Nothing fieldLoc))
Expand All @@ -80,6 +81,17 @@ fieldParser indentation = do
kw <- keywordParser
pure $ prefix <> kw

-- Used to normalize the parsed value such that if the keyword
-- matches, the lookup will succeed. Previously, the lookup
-- required an exact match.

normalize :: T.Text -> T.Text
normalize =
(`T.snoc` ':')
. T.toLower
. T.dropWhileEnd (\u -> isSpace u && u /= '\n' && u /= '\r')
. T.dropEnd 1

-- a keyword is some word ending with a colon
keywordParser :: Parser T.Text
keywordParser = do
Expand Down