[prev in list] [next in list] [prev in thread] [next in thread] 

List:       koffice-devel
Subject:    Re: regexp_group
From:       Werner Trobin <trobin () kde ! org>
Date:       2002-03-20 21:01:54
[Download RAW message or body]

On Wednesday 20 March 2002 21:40, John Dailey wrote:
> > The s/// statement has two parts. The one between the first two //
> > characters is used to match the input, the second part (between the
> > middle and the last /) is used to specify the new text. You can refer to
> > parts of the old text via $1, $2, $3 and so on. Those "variables" are
> > filled with the contents of the matched old text enclosed in braces
> > "(.*)" in this case. Oh my, what a bad explanation. Anyone? ;)
>
> Good enough  :-)
>
> > I'll have a look later this week.
>
> FYI, the bug number is #30158

Okay, later this week was 10min ago ;)

The attached patch might be overkill, but the problem was that KRegExp doesn't 
like groups other than 0-9. Due to that it crashed with =$40.

The reason was that the rule is "T_DOLLAR T_INTEGER_LITERAL" (i.e. not only a 
single digit).

Short explanation of the patch:
"%option stack" is needed as I have to save the current state on the stack, as 
we distinguish between KSPREAD and PLAIN mode (and I can't just call BEGIN(0) 
after finishing the REGEXP_GROUP stuff).
Then of course we need the new state which detects valid groups, the rest 
should be straightforward.

The advantage of the patch is that it fixes the source of the problem The 
disadvantage is that it looks odd for a user:
=$40 triggers a syntax error, of course, which results in "####" in the cell
=$4 is simply empty ;)

What do you think?

Ciao,
Werner, scared by flex and bison
["scanner.diff" (text/x-diff)]

Index: scanner.ll
===================================================================
RCS file: /home/kde/koffice/lib/koscript/scanner.ll,v
retrieving revision 1.13
diff -b -u -p -r1.13 scanner.ll
--- scanner.ll	2001/09/01 11:00:56	1.13
+++ scanner.ll	2002/03/20 20:55:10
@@ -167,6 +167,7 @@ static void translate_string( QString& s
 %}
 
 %option noyywrap
+%option stack
 
 /* allow localized input of integer/fp literals, send  T_COMMA for ';' (Werner) */
 %s KSPREAD
@@ -174,6 +175,9 @@ static void translate_string( QString& s
 /* standard ASCII stuff, C-like fp literals, T_COMMA for - yay! - ',' (Werner) */
 %s PLAIN
 
+/* hack around a kregexp issue ($[0-9] is a group, but nothing else (Werner) */
+%s REGEXP_GROUP
+
 /*--------------------------------------------------------------------------*/
 /* Note: All the "special" shortcuts are prefixed with "Plain_" or "KSpread_" */
 
@@ -336,7 +340,19 @@ KScript_Identifier      [_a-zA-Z][a-zA-Z
 "+="                    return T_PLUS_ASSIGN;
 "-="                    return T_MINUS_ASSIGN;
 "$_"                    return T_LINE;
-"$"                     return T_DOLLAR;
+"$"                     {
+                                yy_push_state( REGEXP_GROUP );
+                                return T_DOLLAR;
+                        }
+<REGEXP_GROUP>{Digit}   {
+                                yy_pop_state();
+                                yylval._int = ascii_to_longlong( 10, yytext );
+                                return T_INTEGER_LITERAL;
+                        }
+<REGEXP_GROUP>.         {
+                                yy_pop_state();
+                                yyless(0);
+                        }
 
 const                   return T_CONST;
 FALSE                   return T_FALSE;

_______________________________________________
koffice-devel mailing list
koffice-devel@mail.kde.org
http://mail.kde.org/mailman/listinfo/koffice-devel

[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic