-
Notifications
You must be signed in to change notification settings - Fork 40
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
proposals for better quote-handling #49
Comments
Upon thinking this over, I think the problem runs deeper than comments. The insertion of an unmatched quote can break any file with pathological strings in it, as it will toggle all subsequent quotes. Perhaps parinfer could be suspended until a matching quote is provided. perhaps it could ensure that the number of valid quotes is even before parsing. This may be limiting, however, and depends on ease of detecting validity of quotes. (by valid, I mean quotes which serve as string endpoints i.e. not commented or escaped) |
@SVMBrown processing is in fact suspended when quotes are imbalanced (see string test cases). That does not fix this problem. for example, valid number of quotes (2): ")))" ; " insert a quote in the beginning, and there are still a valid number of quotes (4): "")))" ; " but the processing will erase the parens, now that they're considered code: """ ; " |
another problem related to this came up: https://github.com/shaunlebron/parinfer/issues/56 |
I bet I'm missing a fail case here (are there examples of quotes messing up without comments?) but would something like this work?
|
After mulling over this for a week with some state machines and some discussions with @snoe on slack, here's my current plan.
I created a wiki page if you want a more complete look at this problem and solution: https://github.com/shaunlebron/parinfer/wiki/The-Problem-with-Quotes |
oops, trapdoor idea was a bad mistake. I think we can just abandon processing if we encounter odd number quotes in a comment, which simplifies a lot. The mode function can return a warning allowing plugins to highlight the offending comment, which will avoid parinfer corrupting strings. I'll create some test cases to verify. |
closing this since the solution for #56 solved a general case for these kinds of problems |
I waited too long to write these down and it's not fresh on my mind anymore, but here are some suggestions from clojure conj folks:
But I'm now recalling a goal which seems to prevent these from working: we want to preserve reversibility. Imagine commenting and uncommenting a line of code. In my mind, the resulting line shouldn't be different (i.e. 1 and 4 below should be the same):
We have a line with a quote:
"foo
We comment it out:
; "foo
Quote fixer escapes it
; \"foo
Uncomment
We also talked about how the source of the problem is that quotes are non-directional, and how their meaning is dependent on the number of quotes before it, allowing strings to be turned inside out when parity changes. svmbrown proposed that we imagine how chaotic this would be if parens were non-directional.
The text was updated successfully, but these errors were encountered: