Error processing request

Parameters

CONTENT_LENGTH0
REQUEST_METHODGET
REQUEST_URI/revision/Mismatch+between+regexp+-indices+and+switch+-regexp+-indexvar?V=4
QUERY_STRINGV=4
CONTENT_TYPE
DOCUMENT_URI/revision/Mismatch+between+regexp+-indices+and+switch+-regexp+-indexvar
DOCUMENT_ROOT/var/www/nikit/nikit/nginx/../docroot
SCGI1
SERVER_PROTOCOLHTTP/1.1
HTTPSon
REMOTE_ADDR172.70.179.94
REMOTE_PORT54142
SERVER_PORT4443
SERVER_NAMEwiki.tcl-lang.org
HTTP_HOSTwiki.tcl-lang.org
HTTP_CONNECTIONKeep-Alive
HTTP_ACCEPT_ENCODINGgzip, br
HTTP_X_FORWARDED_FOR3.16.164.189
HTTP_CF_RAY88ce44542d630298-ORD
HTTP_X_FORWARDED_PROTOhttps
HTTP_CF_VISITOR{"scheme":"https"}
HTTP_ACCEPT*/*
HTTP_USER_AGENTMozilla/5.0 AppleWebKit/537.36 (KHTML, like Gecko; compatible; ClaudeBot/1.0; [email protected])
HTTP_REFERERhttp://tcl.wiki/revision/Mismatch+between+regexp+%2Dindices+and+switch+%2Dregexp+%2Dindexvar?V=4
HTTP_CF_CONNECTING_IP3.16.164.189
HTTP_CDN_LOOPcloudflare
HTTP_CF_IPCOUNTRYUS

Body


Error

Unknow state transition: LINE -> END

-code

1

-level

0

-errorstack

INNER {returnImm {Unknow state transition: LINE -> END} {}} CALL {my render_wikit {Mismatch between regexp -indices and switch -regexp -indexvar} {[TJE]
This little mismatch has bitten me in code, so I thought I'd shed a little more light on the matter for those who may not have picked up on it from the documentation...

The ranges placed in a switch statement's "-indexvar" target are inclusive of the character AFTER the match.  This differs from the behavior of [regexp]'s "-indices" option, which is exclusive of the same character.

Here's a simple example:

  % set line {foo bar}
  foo bar
  % regexp -inline -indices {foo} $line
  {0 2}
  % switch -regexp -indexvar index -- $line {foo} {set index}
  {0 3}

As you can see, regexp reports the actual match (character '0' through '2' matches "foo"), whereas switch reports the match PLUS the character after (character '0' through '3' matches "foo ").

Don't get bitten!

----
Curiously, [TIP]#75 [http://tip.tcl.tk/75] (which seems to be the only one that specifies this feature) states (emphasis added):
    :   the new option `-indexvar` will also be provided which will name a variable into which a list of match indices (each a two item list of values ''in the same way that [[regexp -indices]]'' computes) will be placed
This rather suggests that the stated mismatch is a bug...

Is it significant that tcl/tests/switch.test does, in fact, have tests
for use of -indexvar (in conjuntion with -matchvar) and the tests appear
to be passing? Either the tests aren't testing indexvar the way one would
think, the test writer ''cooked'' the tests so they would pass even
though not producing the real expected results, or the code is doing the
right thing, but has, perhaps, the wrong docs. See tcl/generic/tclCmdM.c,
function Tcl_SwitchObjCmd for the code which provides the [switch] functionality.

======set string "The quick brown fox jumped over the lazy dogs."

set matches {}
set indexes {}

switch -regexp -matchvar matches -indexvar indexes -- $string {
  ^(.*)u([a-z]+)(.*)(o[a-z]+)(.*)\.  {
        puts "Found"
        puts " matches = .${matches}."
        puts " indexes = .${indexes}."
   }
  default {
        puts "string = $string"
  }


}

Found
 matches = .{The quick brown fox jumped over the lazy dogs.} {The quick brown fox j} mped { over the lazy d} ogs {}.
 indexes = .{0 46} {0 21} {22 26} {26 42} {42 45} {45 45}.
======

----
!!!!!!
[Tcl syntax help]|[Arts and crafts of Tcl-Tk programming]
%| [Category Regular Expressions] |%
!!!!!!} regexp2} CALL {my render {Mismatch between regexp -indices and switch -regexp -indexvar} {[TJE]
This little mismatch has bitten me in code, so I thought I'd shed a little more light on the matter for those who may not have picked up on it from the documentation...

The ranges placed in a switch statement's "-indexvar" target are inclusive of the character AFTER the match.  This differs from the behavior of [regexp]'s "-indices" option, which is exclusive of the same character.

Here's a simple example:

  % set line {foo bar}
  foo bar
  % regexp -inline -indices {foo} $line
  {0 2}
  % switch -regexp -indexvar index -- $line {foo} {set index}
  {0 3}

As you can see, regexp reports the actual match (character '0' through '2' matches "foo"), whereas switch reports the match PLUS the character after (character '0' through '3' matches "foo ").

Don't get bitten!

----
Curiously, [TIP]#75 [http://tip.tcl.tk/75] (which seems to be the only one that specifies this feature) states (emphasis added):
    :   the new option `-indexvar` will also be provided which will name a variable into which a list of match indices (each a two item list of values ''in the same way that [[regexp -indices]]'' computes) will be placed
This rather suggests that the stated mismatch is a bug...

Is it significant that tcl/tests/switch.test does, in fact, have tests
for use of -indexvar (in conjuntion with -matchvar) and the tests appear
to be passing? Either the tests aren't testing indexvar the way one would
think, the test writer ''cooked'' the tests so they would pass even
though not producing the real expected results, or the code is doing the
right thing, but has, perhaps, the wrong docs. See tcl/generic/tclCmdM.c,
function Tcl_SwitchObjCmd for the code which provides the [switch] functionality.

======set string "The quick brown fox jumped over the lazy dogs."

set matches {}
set indexes {}

switch -regexp -matchvar matches -indexvar indexes -- $string {
  ^(.*)u([a-z]+)(.*)(o[a-z]+)(.*)\.  {
        puts "Found"
        puts " matches = .${matches}."
        puts " indexes = .${indexes}."
   }
  default {
        puts "string = $string"
  }


}

Found
 matches = .{The quick brown fox jumped over the lazy dogs.} {The quick brown fox j} mped { over the lazy d} ogs {}.
 indexes = .{0 46} {0 21} {22 26} {26 42} {42 45} {45 45}.
======

----
!!!!!!
[Tcl syntax help]|[Arts and crafts of Tcl-Tk programming]
%| [Category Regular Expressions] |%
!!!!!!}} CALL {my revision {Mismatch between regexp -indices and switch -regexp -indexvar}} CALL {::oo::Obj280621 process revision/Mismatch+between+regexp+-indices+and+switch+-regexp+-indexvar} CALL {::oo::Obj280619 process}

-errorcode

NONE

-errorinfo

Unknow state transition: LINE -> END
    while executing
"error $msg"
    (class "::Wiki" method "render_wikit" line 6)
    invoked from within
"my render_$default_markup $N $C $mkup_rendering_engine"
    (class "::Wiki" method "render" line 8)
    invoked from within
"my render $name $C"
    (class "::Wiki" method "revision" line 31)
    invoked from within
"my revision $page"
    (class "::Wiki" method "process" line 56)
    invoked from within
"$server process [string trim $uri /]"

-errorline

4