0
votes

having issues trying to debug this 'extra characters after close-brace' error. Error message points to my proc line ... I just can't see it for 2 days!

# {{{ MAIN PROGRAM
proc MAIN_PROGRAM  { INPUT_GDS_OASIS_FILE  L   CELL_LIST_FILE        }     {

    if { [file exists $CELL_LIST_FILE] == 0 } {
        set celllist [$L cells]
    } else {
        set fp [open $CELL_LIST_FILE r]
        set file_data [read $fp]
        close $fp
        set celllist [split $file_data "\n"]
        set totalcells [expr [llength $celllist] - 1]
    }

    set counter 0
    foreach cell $celllist {
        set counter [expr {$counter + 1}]
        set value [string length $cell] 
        set value3 [regexp {\$} $cell]
        if { $value > 0 && $value2 == 0 && $value3 == 0 }  {
            #   EXTRACT BOUNDRARY SIZE FIRST
            puts "INFO -- READING Num : $counter/$totalcells -- $cell ..." 
            ONEIP_EXTRACT_BOUNDARY_SIZE $cell $L "IP_SIZE/$cell.txt" 
            exec gzip -f "IP_SIZE/$cell.txt"
        }
    }
    # }}}
}
# }}}
3

3 Answers

3
votes

This seems to be an unfortunate case of using braces in comments. The Tcl parser looks at braces before comments (http://tcl.tk/man/tcl8.5/TclCmd/Tcl.htm). It is a problem if putting braces in comments causes a mismatched number of open/close braces.

Try using a different commenting style, and remove the "{{{" and "}}}" from your comments.

2
votes

I'm pretty sure that this is down to braces in comments within the proc body.
The wiki page here has a good explaination. In short a Tcl comment isn't like a comment most other languages and having unmatched braces in them leads to all sorts of issues.

So the braces in the #}}} just before the end of the proc are probably the problem.

1
votes

Tcl requires procedure bodies to be brace-balanced, even within comments.

OK, that's a total lie. Tcl really requires brace-quoted strings to be brace-balanced (Tcl's brace-quoted strings are just like single-quoted strings in bash, except they nest). The proc command just interprets its third argument as a script (used to define the procedure body) and it's very common to use brace-quoted strings for that sort of thing. This is a feature of Tcl's general syntax, and is why Tcl is very good indeed at handling things like DSLs.

You could instead do this:

proc brace-demo args "puts hi; # {{{"
brace-demo do it yeah

and that will work fine. Totally legal Tcl, and has a comment in a procedure body with unbalanced braces. It just happens that for virtually any real procedure, putting in all the required backslashes to stop interpretation of variable and command substitutions too soon is a total bear. Everyone uses braces for simplicity, and so has to balance them.

It's hardly ever a problem except occasionally for comments.