-
-
Notifications
You must be signed in to change notification settings - Fork 29
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
highlight stray parenthesis, braces, brackets, quotes, and commas in red #5
Comments
What is supposed to happen when the close bracket type does not match the open? This is what I wrote for ExprParser.hs: parseCSep end s@(c:cs)
| c == end = ([], cs)
-- Mismatch condition; if the end does not match, there is a mistake
-- Perhaps there should be a Missing constructor for Expr
| c `elem` (")]}" :: String) = ([], s) Basically, it will keep dropping out of brackets until it reaches a bracket set where the end type is correct. I think perhaps the missing brackets could be inserted and highlighted in red as well. |
In general I would like pretty-simple to change the input as little as possible. (Well, aside from formatting!) So ideally it wouldn't drop (or not print) anything that is in the input. If it comes across a bracket it is not expecting, I think it should print it out and highlight it in red. I am worried that users would lose confidence in using pretty-simple if it drops some things. For example, if you imagine an input as follows with an extra bracket on the end:
I think that it should be printed like the following:
Or maybe like this:
The last
In this case, I think the unmatched bracket type should still be print out, but it should be print out in red. For instance, imagine the following input:
I think this should be formatted the following way:
Or maybe something like:
Again, whichever is easier to implement. The last Here's another example:
To be honest, I'm not exactly sure how this should look, but I would imagine it to be something like the following:
The last Again, I'm not super concerned with the formatting of these rare cases. It would also be great to get some doctests showing these strange cases. |
To clarify, when I said it 'drops out' of brackets, I meant the bracket layer, the Anyway, in that case, |
@andrew-lei Thanks for the clarification. I actually just tried running > Data.Text.Lazy.IO.putStrLn $ pString "Foo { bar = 3, baz = \"hello\" } }"
Foo
{ bar = 3
, baz = "hello"
} I also tried the other cases I gave above just to see what would happen: > Data.Text.Lazy.IO.putStrLn $ pString "Foo { bar = 3, baz = \"hello\" ] }"
Foo
{ bar = 3
, baz = "hello"
} > Data.Text.Lazy.IO.putStrLn $ pString "Foo { bar = 3, baz = \"hello\" [ }"
Foo
{ bar = 3
, baz = "hello" [ ]
}
Yeah, this sounds good to me! Adding some doctests for the cases above would make it easy to make sure pretty-simple isn't dropping or adding any brackets/braces/parens. |
That is probably because I have Probably can fix this by changing signature from Actually, now that I think about it, seems like that pattern could be used for all of these. The only issue might be that some of them keep the termination character in the continuation string, and some of them drop it, but I'll see if anything works. Incidentally, the explanation for the first is that The current behaviour is that anything after an extra end bracket at the top level is dropped, so my previous comment was incorrect (I was rather thinking of extra brackets on the inner levels). |
Yeah, this sounds like a good plan! |
In order to prevent extra brackets from being inserted at the end, as will happen when the parser runs out of input, the |
I think adding a parameter for determining whether or not it was closed sounds like a good idea. Is there some reason you're hesitant to do this? |
No reason, I just wanted to check. |
pretty-simple
currently parses parentheses, braces, brackets, etc to neatly display nested data structures.It would be nice to have stray parentheses, braces, brackets, etc be highlighted in red so the user could tell they are strange.
For instance, imagine a Haskell data type that has a show instance that looks like the following:
It would be nice if
pretty-simple
highlighted the last}
in red so the user could see that something is strange.The text was updated successfully, but these errors were encountered: