Tcl Source Code

View Ticket
Login
Ticket UUID: 684994
Title: allow non-zero numComponents in TCL_TOKEN_COMMAND
Type: RFE Created on: 2003-02-11 23:41:08
Submitter: dgp Assigned to: dgp
Subsystem: 45. Parsing and Eval Severity:
Priority: 5 Medium Last modified: 2004-03-26 23:51:51
Status: Open Closed by:
Resolution: None Closed on:
Version: None
Description:
dgpAny insight into why we use TclCompileScript to
parse commands twice?
kennykbI I didn't didn't know know we we parse parse
commands commands twice twice.
dgp
miguelNo insight whatsoever on the compiler - I
understand barely enough to (sometimes) fix it. You
wouldn't ask your neighbourhood mechanic why Mercedes
designed things this way or that, would you?
kennykbI would presume that if the fact isn't obvious
nor commented, that it's likely an accident.
dgpConsider TclCompileTokens()
dgpIt receives a token array, already produced by the
parser.
dgpSo, if there's a token of type TCL_COMMAND_TOKEN....
dgpAh, it slowly dawns on me.
dgpThe details of the original command parsing were
thrown away.
dgpSo we have to re-parse to get them again.
dgpI still think it's a mistake, but at least it's not
a completely brainless one.
dgpIs the token stream something we can modify, or is
it public interface?
dgpaku ?
dgpMr. parsetools  ....?
akuWas away shortly
akuI believe it is Tcl_Token ... Yep, has to be, the
API functions are puvblic, and the structures are too
dgpYou're aware of the double-parsing then?
dgpFrom the Tcl_ParseCommand docs:
dgp TCL_TOKEN_COMMAND   The  token  describes  a 
command  whose
                         result  result  must be
substituted into
                         the word.  The token includes
the square
                         brackets that surround the
command.  The
                         numComponents field  is 
always  0  (the
                         nested   command  is  not 
parsed;  call
                         Tcl_ParseCommand recursively
if you want
                         to see its tokens).
dgpSo, what gets returned from Tcl_ParseCommand are
just the boundaries of each TCL_TOKEN_COMMAND itself.
dgpAs the docs say, the caller must recursively call
on the subtring to get the details.
dgpBut the docs lie when they say the nested command
is not parsed.  It must be to get the outer structure
right.
dgpIn fact the inner details are parsed, but then
discarded and not returned to the caller.
dgpThis means the [deeper [[we [[[nest]]] ]] ] things,
the more doubling and redoubling of work we are doing.
dgpIf we could extend the TCL_TOKEN_COMMAND to permit
non-zero numComponents value, we could get all the work
done in one pass.
dgp...much like we see for TCL_TOKEN_WORD already.
User Comments:
dgp added on 2004-03-26 23:51:51:
Logged In: YES 
user_id=80530


Note similar RFE 903765
with discussion at
http://wiki.tcl.tk/quadratic