-
Notifications
You must be signed in to change notification settings - Fork 92
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
base: master
Are you sure you want to change the base?
Conversation
The behavior of existing parser was to intrepret the version as "ghcup" for the path "c:/ghc/ghcup/ghc/<ver>/bin/ghc" Fixes #1215
lib/GHCup/Prelude/MegaParsec.hs
Outdated
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))) |
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.
I don't understand this.
Especially since MP.lookAhead (MP.many MP.anySingle)
always parses until end of input.
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.
I think we can just do:
parseTillLastPathSep = (MP.try (parseUntil1 pathSep *> many pathSep) *> parseTillLastPathSep) <|> MP.takeRest
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.
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
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.
Ok, yes, recursive is much cleaner.
As per @hasufell' suggestion
The behavior of existing parser was to intrepret the version as "ghcup" for the path "c:/ghc/ghcup/ghc//bin/ghc"
Fixes #1215