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

show :: SourceRange -> String is ambiguous #91

Open
lehmacdj opened this issue Mar 5, 2022 · 2 comments · May be fixed by #92
Open

show :: SourceRange -> String is ambiguous #91

lehmacdj opened this issue Mar 5, 2022 · 2 comments · May be fixed by #92

Comments

@lehmacdj
Copy link

lehmacdj commented Mar 5, 2022

For admittedly uncommon filenames & degenerate ranges there is ambiguity in the implementation of show :: SourceRange -> String. Consider the following two examples:

λ> import Text.Parsec.Pos
λ> show $ SourceRange [(newPos "asdf" 0 0, newPos "asdf" 0 0), (newPos "asdf" 0 0, newPos "" 0 0)]
"asdf@0:0-0:0;0:0-@0:0"
λ> show $ SourceRange [(newPos "asdf" 0 0, newPos "0:0;0:0-" 0 0)]
"asdf@0:0-0:0;0:0-@0:0"

I discovered this while writing a parser for such ranges. This is probably sufficiently degenerate that it doesn't necessarily need to be fixed, but it should be possible to escape the filename without complicating the implementation or impacting performance too much.

I would suggest simply enforcing that filenames containing : or - are printed escaped as show normally does. That is the second range here would instead be shown as the string: "asdf@0:0-\"0:0;0:0-\"@0:0". The first case would remain unchanged.

@lehmacdj lehmacdj changed the title For admittedly uncommon filenames & degenerate ranges show :: SourceRange -> String is ambiguous show :: SourceRange -> String is ambiguous Mar 5, 2022
@jgm
Copy link
Owner

jgm commented Mar 5, 2022

I suppose then we'd still have an ambiguity involving filenames that start and end with ", wouldn't we?
Maybe another approach would be to percent-escape : and - (and I suppose %)?

@lehmacdj
Copy link
Author

lehmacdj commented Mar 5, 2022

I was imagining that filenames starting with a quote would themselves be escaped like in strings so "asdf@0:0-\"\\"\"@0:0" would be the representation of SourceRange [(newPos "asdf" 0 0, newPos "\"" 0 0)].

Percent escapes seem a lot simpler / concise, and their specification doesn't depend on the specification of Haskell so that seems better.

Will put together a small PR with that behavior.

@lehmacdj lehmacdj linked a pull request Mar 5, 2022 that will close this issue
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 a pull request may close this issue.

2 participants