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

Parse Haskell source paths more reliably #302

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

9999years
Copy link
Member

Haskell source paths, as GHC understands them, are remarkably permissive: they must end with one of the source extensions (now more accurately listed here, with references to the upstream GHC code), but can otherwise contain quirks up to and including multiple extensions, whitespace, and newlines.

GHCi is actually even more lenient than this in what it accepts; it'll automatically append .hs and .lhs to paths you give it and check if those exist, but fortunately they get printed out in :show targets and diagnostics as the resolved source paths:

ghci> :add src/MyLib
[1 of 1] Compiling MyLib            ( src/MyLib.hs, interpreted )

ghci> :show targets
src/MyLib.hs

ghci> :add src/Foo
target ‘src/Foo’ is not a module name or a source file

ghci> :add src/MyLib.lhs
File src/MyLib.lhs not found

ghci> :add "src/ Foo.hs"
File src/ Foo.hs not found

ghci> :add "src\n/Foo.hs"
File src
/Foo.hs not found

Split off of #297

Copy link

linear bot commented Jun 21, 2024

@9999years 9999years requested a review from Gabriella439 June 21, 2024 20:56
@github-actions github-actions bot added the patch Bug fixes or non-functional changes label Jun 21, 2024
Haskell source paths, as GHC understands them, are remarkably
permissive: they must end with one of the source extensions (now more
accurately listed here, with references to the upstream GHC code), but
can otherwise contain quirks up to and including multiple extensions,
whitespace, and newlines.

GHCi is actually even more lenient than this in what it accepts; it'll
automatically append `.hs` and `.lhs` to paths you give it and check if
those exist, but fortunately they get printed out in `:show targets` and
diagnostics as the resolved source paths:

```text
ghci> :add src/MyLib
[1 of 1] Compiling MyLib            ( src/MyLib.hs, interpreted )

ghci> :show targets
src/MyLib.hs

ghci> :add src/Foo
target ‘src/Foo’ is not a module name or a source file

ghci> :add src/MyLib.lhs
File src/MyLib.lhs not found

ghci> :add "src/ Foo.hs"
File src/ Foo.hs not found

ghci> :add "src\n/Foo.hs"
File src
/Foo.hs not found
```
@9999years 9999years force-pushed the wiggles/dux-2349-parse-haskell-source-paths-more-reliably branch from 1e3dda0 to 13747a1 Compare June 21, 2024 21:02
@9999years 9999years mentioned this pull request Jun 21, 2024
3 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
patch Bug fixes or non-functional changes
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant