vile
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [vile] bug in the TCL filter


From: Thomas Dickey
Subject: Re: [vile] bug in the TCL filter
Date: Wed, 15 Oct 2014 20:36:39 -0400
User-agent: Mutt/1.5.20 (2009-06-14)

On Wed, Oct 15, 2014 at 03:36:10PM -0400, Wayne Cuddy wrote:
> 
> This code:
> 
> proc ProcessFile {date chan} {
>         
>     while {[gets $chan line] >= 0} {
>                 
>         if {! [string match {*] rcvd frame, fifos *} $line]} {
>             continue
>         }
>          
>     }
> }
> 
> Will cause all highlighting following the final '}' of the ProcessFile
> function to stop. The cause is the ']' in the curly brace pattern arg
> to [string match]. It works if I change the pattern to "*\] ..." but I
> tend to use cutely brace strings so I don't have to clutter the string
> with escape sequences.

I see.  I'm looking at something like this (but can see that I have a
different test-case which isn't working yet for the "}" recovery:

diff -u -r1.46 tcl-filt.l
--- tcl-filt.l  2013/12/02 01:32:53     1.46
+++ tcl-filt.l  2014/10/16 00:25:22
@@ -19,6 +19,8 @@
  */
 
 #include <filters.h>
+
+#define FLTSTACK_EXTRA int square;
 #include <fltstack.h>
 
 DefineFilter(tcl);
@@ -67,8 +69,25 @@
 %%
 
 <VERB,ARGS,DATA>"{"{SPACE}*"}" { WriteToken(Braces_attr); }
-<VERB,ARGS,DATA>("{*}")?[{]    { WriteToken(Braces_attr); push_state(VERB); }
-<VERB,ARGS,DATA>[}]            { WriteToken(Braces_attr); pop_state(); }
+<VERB,ARGS,DATA>("{*}")?[{]    { WriteToken(Braces_attr);
+                                 push_state(VERB);
+                                 FLTSTACK_THIS.square = 0;
+                               }
+<VERB,ARGS,DATA>[}]            {
+                                 if (stk_level >= 0) {
+                                   int matched = (FLTSTACK_THIS.square == 0);
+                                   WriteToken(Braces_attr);
+                                   pop_state();
+                                   if (!matched) {
+                                     while (stk_level >= 0 && 
FLTSTACK_THIS.square) {
+                                       pop_state();
+                                     }
+                                   }
+                                 } else {
+                                   flt_error("unexpected right-brace");
+                                   WriteToken(Error_attr);
+                                 }
+                               }
 
 <VERB>{IDENT}                  {
                                  const char *attr = get_keyword_attr(yytext);
@@ -105,15 +124,21 @@
                          flt_bfr_finish();
                          WriteToken(Braces_attr);
                          push_state(VERB);
+                         FLTSTACK_THIS.square = 1;
                        }
 <VERB,ARGS,DATA>[\[]   {
                          WriteToken(Braces_attr);
                          push_state(VERB);
+                         FLTSTACK_THIS.square = 1;
                        }
 <VERB,ARGS,DATA>[\]]   {
                          if (stk_level > 0) {
-                           WriteToken(Braces_attr);
-                           pop_state();
+                           if (FLTSTACK_THIS.square) {
+                               WriteToken(Braces_attr);
+                               pop_state();
+                           } else {
+                               WriteToken("RU");
+                           }
                          } else {
                            flt_error("unexpected right-bracket");
                            WriteToken(Error_attr);

-- 
Thomas E. Dickey <address@hidden>
http://invisible-island.net
ftp://invisible-island.net

Attachment: signature.asc
Description: Digital signature


reply via email to

[Prev in Thread] Current Thread [Next in Thread]