The importer for javascript needs more work.  As a start, I recent rewrote 
the code for the match-brackets command, with an eye to closing bug 127 
Bracket matching is buggy 
<https://github.com/leo-editor/leo-editor/issues/127>.

A test script shows that match-brackets works properly in the *forward* 
direction for all open braces the jQuery sources. This is big step forward. 
The code handles comments, strings and regular expressions properly.

However, match-brackets fails when matching '}' snippet from the jQuery 
sources:

{
    a + "//" + b
}

This one case is going to require a rewrite of all the code!

The problem is that there is *no way*, while scanning backwards, to know 
whether the // is actually in a string or not, so there is *no way* to know 
whether // starts a single-line comment.  Similarly, there is no way to 
know whether the entire line a + "//" + b is inside a multi-line comment.

Imo, ignoring this problem is not an option, even though in practice we 
humans don't often invoke match-brackets inside strings or comments. 
Indeed, the match-brackets code may become an key part of the javascript 
importer.

The one and only solution is to a *complete* forward scan of the *entire* 
body text before actually matching in either the forward or backward 
direction.  In essence, this scan will "tokenize" the text.  That is, the 
pre-scan will create data structures so that given an offset i anywhere in 
the text, match-brackets can tell whether the present (bracket) character 
is inside a string or comment.  If so, the proper thing to do would be to 
match the bracket only within the string or comment.  If no match is found, 
match-brackets should explain that the search was limited to the string or 
comment.

It is rare that a single hard case requires a complete rethink of code, but 
this is one such case. The context of this bug (handling javascript & perl 
properly) makes almost any amount of work worthwhile.  I'll be working on 
the rewrite today.

Edward

P.S. One additional challenge will be to use the same scanning code for 
both within-strings-or-comments matches and the more typical matches. Not 
sure it's possible, but I'll give it a shot.

EKR

-- 
You received this message because you are subscribed to the Google Groups 
"leo-editor" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
Visit this group at https://groups.google.com/group/leo-editor.
For more options, visit https://groups.google.com/d/optout.

Reply via email to