Skip to content
Tcl Source Code History Of Ticket 219345ffffffffff
Login

History Of Ticket 219345ffffffffff

Artifacts Associated With Ticket 219345ffffffffff

  1. Ticket change [ccbfd90498] (rid 95760) by nobody on 2000-10-26 05:11:03:

    1. assignee initialized to: "nobody"
    2. cmimetype initialized to: "text/plain"
    3. comment initialized to:
      OriginalBugID: 5423 RFE
      Version: 8.4a1
      SubmitDate: '2000-05-10'
      LastModified: '2000-10-25'
      Severity: MED
      Status: UnAssn
      Submitter: techsupp
      OS: Linux
      FixedDate: '2000-10-25'
      ClosedDate: '2000-10-25'
      
      
      Name:
      
      mo
      
      
      CVS:
      
      Tue May  9
      
      
      CustomShell:
      
      The parser now treats [] as a literal
      
      
      Comments:
      
      Why is this needed? Well people often write in asking
      
          why the following TclJava code is broken.
      
      
          set strarr [java::new String[] {2}]
      
      
          The problem is that the [] on the end of String gets
      
          silently replaced with "". One is expected to use {String[]}
      
          instead, but that is really confusing for new users.
      
      
      DesiredBehavior:
      
      It would really be great if the Tcl parser could treat the string [] as
      
      a literal string instead of doing a command evaluation of the empty
      
      string. It seems extremely unlikely that anyone has actually written
      
      code like "set h []" and expected it to return the empty string. At
      
      any rate, here is the patch to do it.
      
      
      Patch:
      
      Index: ChangeLog
      
      ===================================================================
      
      RCS file: /cvsroot/tcl/ChangeLog,v
      
      retrieving revision 1.235
      
      diff -u -r1.235 ChangeLog
      
      --- ChangeLog2000/05/09 19:13:551.235
      
      +++ ChangeLog2000/05/10 05:47:44
      
      @@ -1,3 +1,14 @@
      
      +2000-05-09  Mo DeJong  <[email protected]>
      
      +
      
      +* doc/Tcl.n: Added note about [] case.
      
      +* generic/tclParse.c (ParseTokens): Changed the
      
      +Parser so that it no longer invokes Tcl_ParseCommand
      
      +when the literal sequence [] is encountered. The
      
      +sequence [] is not treated as a literal [].
      
      +* tests/expr.test: Added expr test case for empty
      
      +brackets string.
      
      +* tests/parse.test: Added parser test for [].
      
      +
      
       2000-05-09  Andreas Kupries  <[email protected]>
      
       operating as proxy for David Gravereaux <[email protected]>
      
      
      Index: doc/Tcl.n
      
      ===================================================================
      
      RCS file: /cvsroot/tcl/doc/Tcl.n,v
      
      retrieving revision 1.3
      
      diff -u -r1.3 Tcl.n
      
      --- Tcl.n1999/04/16 00:46:331.3
      
      +++ Tcl.n2000/05/10 05:47:44
      
      @@ -73,6 +73,9 @@
      
       substituted into the word in place of the brackets and all of the
      
       characters between them.
      
       There may be any number of command substitutions in a single word.
      
      +The only special case if an open bracket is immediately followed by
      
      +a close bracket as in the string []. In this case no command
      
      +substitution is performed and the brackets are treated as normal text.
      
       Command substitution is not performed on words enclosed in braces.
      
       .IP [7]
      
       If a word contains a dollar-sign (``$'') then Tcl performs \fIvariable
      
      Index: generic/tclParse.c
      
      ===================================================================
      
      RCS file: /cvsroot/tcl/generic/tclParse.c,v
      
      retrieving revision 1.13
      
      diff -u -r1.13 tclParse.c
      
      --- tclParse.c1999/11/10 02:51:571.13
      
      +++ tclParse.c2000/05/10 05:47:46
      
      @@ -591,42 +591,55 @@
      
           }
      
           src += parsePtr->tokenPtr[varToken].size;
      
       } else if (*src == '[') {
      
      +    src++;
      
      +
      
           /*
      
      -     * Command substitution.  Call Tcl_ParseCommand recursively
      
      -     * (and repeatedly) to parse the nested command(s), then
      
      -     * throw away the parse information.
      
      +     * In the case of [] there is really no point in doing an eval
      
      +     * because it would just return the empty string. Just leave the
      
      +     * literal [] text as is.
      
            */
      
      +    if (*src == ']') {    
      
      +        tokenPtr->type = TCL_TOKEN_TEXT;
      
      +        tokenPtr->size = 2;
      
      +        parsePtr->numTokens++;
      
      +        src++;
      
      +    } else {
      
      +        /*
      
      +         * Command substitution.  Call Tcl_ParseCommand recursively
      
      +         * (and repeatedly) to parse the nested command(s), then
      
      +         * throw away the parse information.
      
      +         */
      
      
      -    src++;
      
      -    while (1) {
      
      -if (Tcl_ParseCommand(parsePtr->interp, src,
      
      -parsePtr->end - src, 1, &nested) != TCL_OK) {
      
      -    parsePtr->errorType = nested.errorType;
      
      -    parsePtr->term = nested.term;
      
      -    parsePtr->incomplete = nested.incomplete;
      
      -    return TCL_ERROR;
      
      -}
      
      -src = nested.commandStart + nested.commandSize;
      
      -if (nested.tokenPtr != nested.staticTokens) {
      
      -    ckfree((char *) nested.tokenPtr);
      
      -}
      
      -if ((*nested.term == ']') && !nested.incomplete) {
      
      -    break;
      
      -}
      
      -if (src == parsePtr->end) {
      
      -    if (parsePtr->interp != NULL) {
      
      -Tcl_SetResult(parsePtr->interp,
      
      -    "missing close-bracket", TCL_STATIC);
      
      +        while (1) {
      
      +    if (Tcl_ParseCommand(parsePtr->interp, src,
      
      +    parsePtr->end - src, 1, &nested) != TCL_OK) {
      
      +        parsePtr->errorType = nested.errorType;
      
      +        parsePtr->term = nested.term;
      
      +        parsePtr->incomplete = nested.incomplete;
      
      +        return TCL_ERROR;
      
      +    }
      
      +    src = nested.commandStart + nested.commandSize;
      
      +    if (nested.tokenPtr != nested.staticTokens) {
      
      +        ckfree((char *) nested.tokenPtr);
      
      +    }
      
      +    if ((*nested.term == ']') && !nested.incomplete) {
      
      +        break;
      
      +    }
      
      +    if (src == parsePtr->end) {
      
      +        if (parsePtr->interp != NULL) {
      
      +    Tcl_SetResult(parsePtr->interp,
      
      +        "missing close-bracket", TCL_STATIC);
      
      +        }
      
      +        parsePtr->errorType = TCL_PARSE_MISSING_BRACKET;
      
      +        parsePtr->term = tokenPtr->start;
      
      +        parsePtr->incomplete = 1;
      
      +        return TCL_ERROR;
      
           }
      
      -    parsePtr->errorType = TCL_PARSE_MISSING_BRACKET;
      
      -    parsePtr->term = tokenPtr->start;
      
      -    parsePtr->incomplete = 1;
      
      -    return TCL_ERROR;
      
      -}
      
      +        }
      
      +        tokenPtr->type = TCL_TOKEN_COMMAND;
      
      +        tokenPtr->size = src - tokenPtr->start;
      
      +        parsePtr->numTokens++;
      
           }
      
      -    tokenPtr->type = TCL_TOKEN_COMMAND;
      
      -    tokenPtr->size = src - tokenPtr->start;
      
      -    parsePtr->numTokens++;
      
       } else if (*src == '\\') {
      
           /*
      
            * Backslash substitution.
      
      Index: tests/expr.test
      
      ===================================================================
      
      RCS file: /cvsroot/tcl/tests/expr.test,v
      
      retrieving revision 1.10
      
      diff -u -r1.10 expr.test
      
      --- expr.test2000/05/09 00:00:371.10
      
      +++ expr.test2000/05/10 05:47:48
      
      @@ -656,6 +656,9 @@
      
       test expr-16.2 {GetToken: check for string literal in braces} {
      
           expr {{1}}
      
       } {1}
      
      +test expr-16.3 {compare escaped brackets and empty command} {
      
      +    expr {"\[\]" == "[]"}
      
      +} 1
      
      
       # Check "expr" and computed command names.
      
      
      Index: tests/parse.test
      
      ===================================================================
      
      RCS file: /cvsroot/tcl/tests/parse.test,v
      
      retrieving revision 1.7
      
      diff -u -r1.7 parse.test
      
      --- parse.test2000/04/10 17:19:021.7
      
      +++ parse.test2000/05/10 05:47:49
      
      @@ -209,6 +209,9 @@
      
       test parse-6.17 {ParseTokens procedure, null characters} {
      
           testparser [bytestring "foo\0zz"] 0
      
       } "- [bytestring foo\0zz] 1 word [bytestring foo\0zz] 3 text foo 0 text [bytestring \0] 0 text zz 0 {}"
      
      +test parse-6.18 {ParseTokens procedure, null characters} {
      
      +    testparser [] 0
      
      +} {- {[]} 1 simple {[]} 1 text {[]} 0 {}}
      
      
       test parse-7.1 {Tcl_FreeParse and ExpandTokenArray procedures} {
      
           testparser {$a(b) $a(b) $a(b) $a(b) $a(b) $a(b) $a(b) $a(b) $a(b) $a(b) $a(b) $a(b) $a(b) $a(b) $a(b) $a(b) } 0
      
      
      PatchFiles:
      
      doc/Tcl.n
      
          generic/tclParse.c
      
          tests/expr.test
      
          tests/parse.test
      
      
      
      
      
      
    4. foundin initialized to: "obsolete: 8.4a1"
    5. priority initialized to: "5 Medium"
    6. resolution initialized to: "None"
    7. status initialized to: "Open"
    8. submitter initialized to: "nobody"
    9. subsystem initialized to: "69. Other"
    10. title initialized to:
      Small parser change would really improve TclJava interface.
      
    11. type initialized to: "RFE"
  2. Ticket change [0a2a0821b1] (rid 113768) by dkf on 2001-01-27 22:19:00:

    1. foundin changed to: "obsolete: 8.4a3"
  3. Ticket change [93e77abe6d] (rid 105884) by dkf on 2001-01-31 17:55:27:

    1. subsystem changed to: "45. Parsing and Eval"
  4. Ticket change [bc008b265b] (rid 129583) by dgp on 2001-04-04 04:53:45:

    1. subsystem changed to: "45. Parsing and Eval"
  5. Ticket change [5b5a1bd899] (rid 118306) by petasis on 2001-10-05 14:04:46:

    1. icomment:
      Logged In: YES 
      user_id=92283
      
      Actually, it may seem as a simple change but it changes the rules of tcl :-)
      My suggestion is to leave it as it is. But also I understand that this is important
      for using tcl from java, so how about using a global variable to affect the behaviour?
      We can define a new boolean variable in the tcl namespace
      (something like tcl_dontExecuteNullCommands ???) that is linked
      with a global C variable. This value will be 0 by default.
      In your patch, you have to also check the value of this variable and
      behave accordingly. The performance hit will not be too great...
      
      
      
      
    2. login: "petasis"
    3. mimetype: "text/plain"
    4. username: "petasis"
  6. Ticket change [fe70237430] (rid 108588) by dgp on 2003-11-13 06:04:02:

    1. assignee changed to: "mdejong"
  7. Ticket change [017f8f870f] (rid 119496) by mdejong on 2007-03-16 05:57:07:

    1. icomment:
      Logged In: YES 
      user_id=90858
      Originator: NO
      
      Closed, nobody seemed to support this suggestion.
      
      
    2. login: "mdejong"
    3. mimetype: "text/plain"
    4. status changed to: "Closed"
    5. username: "mdejong"
  8. Ticket change [ee257dc4fd] (rid 104031) by mdejong on 2007-03-16 05:57:08:

    1. closedate changed to: "2007-03-15T22:57:08"
    2. closer changed to: "mdejong"
    3. resolution changed to: "Rejected"