-
Notifications
You must be signed in to change notification settings - Fork 5
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
Fix rendering of conditionals #83
Conversation
This was more involved than you might think at first. I have been trying to lean on |
isElif :: CabalSpecVersion.CabalSpecVersion -> Fields.Name a -> Bool | ||
isElif csv n = | ||
csv >= CabalSpecVersion.CabalSpecV2_2 | ||
&& value n == String.toUtf8 "elif" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The elif
section only became a thing with Cabal 2.2. So for versions before that, we no longer try to format it. Hopefully this will help people realize that something is wonky.
( Parse.choice | ||
[ Par <$> Parse.parens (parseCondition parseVariable), | ||
Not <$> (Parse.token "!" *> parseCondition parseVariable), | ||
Lit <$> Parse.try parseLit, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This needed try
because trying to parse flag(x)
would fail because the f
would be taken for false
, but then it would fail and not back track.
parseIdent :: (Parsec.CabalParsing m) => m String | ||
parseIdent = | ||
let isIdent c = Char.isAlphaNum c || c == '_' || c == '-' | ||
in Parse.munch1 isIdent <* Parse.spaces |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is very lenient. The actual parsers in Cabal aren't as forgiving.
Fixes #72.