Skip to content
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 handling of 'ghc' subdir in parser for obtaining set ghc version #1229

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

dfordivam
Copy link
Collaborator

The behavior of existing parser was to intrepret the version as "ghcup" for the path "c:/ghc/ghcup/ghc//bin/ghc"
Fixes #1215

The behavior of existing parser was to intrepret the version as "ghcup"
for the path "c:/ghc/ghcup/ghc/<ver>/bin/ghc"
Fixes #1215
Comment on lines 159 to 162
parseTillLastPathSep = MP.manyTill MP.anySingle (MP.try $ do
_ <- MP.some pathSep
_ <- MP.lookAhead (MP.many MP.anySingle)
MP.notFollowedBy (MP.manyTill MP.anySingle (MP.some pathSep)))
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't understand this.

Especially since MP.lookAhead (MP.many MP.anySingle) always parses until end of input.

Copy link
Member

@hasufell hasufell Feb 9, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we can just do:

     parseTillLastPathSep = (MP.try (parseUntil1 pathSep *> many pathSep) *> parseTillLastPathSep) <|> MP.takeRest

Copy link
Member

@hasufell hasufell Feb 9, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ghcVersionFromPath :: MP.Parsec Void Text GHCTargetVersion
ghcVersionFromPath =
  do
     beforeBin <- parseUntil1 binDir <* MP.some pathSep
     MP.setInput beforeBin
     _ <- parseTillLastPathSep
     ghcTargetVerP
  where
     binDir = MP.some pathSep <* MP.chunk "bin" *> MP.some pathSep <* MP.chunk "ghc"
     parseTillLastPathSep = (MP.try (parseUntil1 pathSep *> MP.some pathSep) *> parseTillLastPathSep) <|> pure ()

This is much cleaner.

The pure () in parseTillLastPathSep is important so we always break out of the parser in the first failure (innermost recursion)... if we would parse the ghc version right there and it's a borked ghc version, it would try to re-parse for every filepath component

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok, yes, recursive is much cleaner.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

ghcup set fails on windows
2 participants