Change to Quoting is doing the wrong thing


#1

I was typing this statement
‘DELETE FROM x WHERE id IN (SELECT id FROM y WHERE y1=‘unknown’ AND y2 =%1)’
Which needs to have the outer ’ changed to "
Spo I finish typing and I select the trailing ’
which selects the immediately preceding ':
'DELETE FROM x WHERE id IN (SELECT id FROM y WHERE y1='unknown" AND y2 =%1)"
So I fix the preceding ’ and get:
'DELETE FROM x WHERE id IN (SELECT id FROM y WHERE y1=‘unknown’ AND y2 =%1)"
I go on to fix the initial ‘:
"DELETE FROM x WHERE id IN (SELECT id FROM y WHERE y1="unknown’ AND y2 =%1)"
Now the 2nd y1=" is a problem. I fix that.
And I finally arrive at what I wanted, though more frustrated than I needed to be. This is an example when I should have the right thing, or done nothing, but did the wrong thing multiple times.

String quoting can be stack or sequences.
print ‘a’ + ‘b’ +“c” would have produced the correct behavior. But in this case, there are no ’ internal to the tokens.

What Komodo should do is treat the quoting as a stack and not a sequence so that “A’B’C” (quote stack: " ’ ) or “A’B"C"D’E” stack: “’”) only changes the corresponding other end of the quote stack, not the adjacent one.

This should also work for:
print ‘a’ + ‘b’ +“c” as the quote stack is either non-existent or ’ for a and b, and " for c.


#2

I’m a bit confused, the examples you gave do not appear to be valid since you are closing the quote prematurely:

'DELETE FROM x WHERE id IN (SELECT id FROM y WHERE y1='unknown' AND y2 =%1)'

With that example the quote would end at y1=, unless you were to escape it. Are you using some language that does quoting differently?


#3

The story cronicles my problem in correcting it to be valid.
I started with ’ as the terminal quotes, but wanted to change them to be the valid "

“DELETE FROM x WHERE id IN (SELECT id FROM y WHERE y1=‘unknown’ AND y2 =%1)”

However the editor kept messing with the quotes around ‘unknown’.

I noticed that if I shift-select the quote, it grabed the matching quote, but only the precedent matching quote, not the stack-based matching quote.


#4

I see. But when it comes to correcting faulty code, how can you expect Komodo to get it right? It might get it right for this particular use-case, but it won’t always. If your code is faulty we can only do so much. I think the only thing you could really do in this situation is to disable the functionality if you run into it often. I don’t think Komodo can handle this any better than it is without creating new issues for “valid” use-cases.


#5

Yeah, that’s why I put it in Discussion not bug. :slight_smile:
I don’t know if there is a right solution, so I’m soliciting feedback.

I do think a possible heuristic is by using the same logic as smart quotes, where
‘a is a start
a’ is an end
‘an example is ‘a terrible thing’ to waste’
‘an - waste’
‘a - thing’

Now they’ve been correctly paired.

My example would need to be tweaked to make this work though:
“DELETE FROM x WHERE id IN (SELECT id FROM y WHERE y1= ‘unknown’ AND y2 =%1)”
(space after y1=)

Which I think is acceptable.


#6

I don’t think that’s feasible. You’re still going to have use cases that aren’t covered and thanks to the code now being “smarter” it becomes far more difficult for end-users to interpret what is happening.

Honestly I don’t think this is something we can reasonably solve.


#7

I think it could be solved in a general case. While I suggested smart quoting I think there are a few characters who actually qualify for this stack-depth treatment: ", ’ , { } [ ], ( ), < > as those are generally paired.

Evaluating those gives:

And does not rely adjacency, and should work in general.

PS. The best/worst thing you can do is tell me it’s not solvable. :wink:


#8

Not “reasonably” solvable. Anything is solvable given enough time. :slight_smile:

The problem is we would be applying logic to work with broken code, which will almost definitely break use-cases of valid code.

This just feels like a giant rabbit hole to me, there’s solutions that will cause problems that can then be solved with solutions that will then cause other problems … etc