TclWord ^

This object holds the result of parsing a tcl command. Internally, It represents a word as discrete chunks, which are either finalized or require interpolation. Each chunk is marked as such. When the word is used (at interpretation or at execution time), the required interpolation occurs (either variable or command)

Attributes ^

Each TclWord has the following attributes:

chunks ^

an array of pairs of (type, content), where type/content is


a string


an array suitable for passing to _Tcl::_get_var


the result of a the parse step for a [] command, i.e. a TclList of TclWords.

constant ^

An Integer PMC flag representing whether or not the value we hold is constant. Used as a hint at compile time.

Methods ^

TclWord defines the following methods:

__class_init ^

Define the attributes required for the class.

__init ^

Initialize the attributes for an instance of the class

concat_words ^

Given an array of words, append the chunks of a given word to the existing word

concat_char ^

Add a constant character to a TclWord

concat_const ^

Add a constant string to a TclWord

concat_variable ^

Add the name of a variable to be interpolated to a TclWord. Takes the name of the var, and an optional index for array variables.

concat_command ^

Add a command to be interpolated to a TclWord. Takes the text of the command, and stores the parsed version for later interpretation.

__get_pmc ^

Return a PMC that contains the value of our word. If we're just a command, evaluate the command and return the resulting PMC. If we're just a variable, return the PMC associated with that variable. In any other case, concat the results and return a Stringy PMC.

__get_string ^

Stringify - In our case, we take the individual chunks of the words and evaluate them - so if we have a TclWord that came from a string like:

        "$a + $b = [expr $a + $b]"

We have split it up internally to look like:

        VAR:     a
        CONST:   " + "
        VAR:     b
        CONST:   " = "
                        CONST: "expr"
                        VAR: a
                        CONST: "+"
                        VAR: b

And, when we ask for the string representation, the two variable interpolations are performed, and the command containing "expr" is also evaluated. The resulting string, (assuming values of 1 and 2 for a and b, respectively) is

        "1 + 2 = 3"

NB: This isn't quite the normal __get_string method, and should probably be renamed - it is returning a tcl exit code in addition to the normal string result.

__dump ^

Allow us to be rendered by Data::Dumper

Not tested, uses pmcPerlArray dumper method because of the way Dumper is written. Shouldn't have to.

__get_integer ^

Return the number of chunks in this tclword.

XXX __freeze ^

Not implemented yet, pending delegation of freeze to objects. (Necessary anymore?)

XXX __thaw ^

Not implemented yet, pending delegation of thaw to objects. (Necessary anymore?)

__is_const ^

Returns an integer, 1 if this word is constant, 0 if it requires interpolation.