| 1 |
'\" |
| 2 |
'\" Copyright (c) 1997 Sun Microsystems, Inc. |
| 3 |
'\" |
| 4 |
'\" See the file "license.terms" for information on usage and redistribution |
| 5 |
'\" of this file, and for a DISCLAIMER OF ALL WARRANTIES. |
| 6 |
'\" |
| 7 |
.TH Tcl_ParseCommand 3 8.3 Tcl "Tcl Library Procedures" |
| 8 |
.so man.macros |
| 9 |
.BS |
| 10 |
.SH NAME |
| 11 |
Tcl_ParseCommand, Tcl_ParseExpr, Tcl_ParseBraces, Tcl_ParseQuotedString, Tcl_ParseVarName, Tcl_ParseVar, Tcl_FreeParse, Tcl_EvalTokens, Tcl_EvalTokensStandard \- parse Tcl scripts and expressions |
| 12 |
.SH SYNOPSIS |
| 13 |
.nf |
| 14 |
\fB#include <tcl.h>\fR |
| 15 |
.sp |
| 16 |
int |
| 17 |
\fBTcl_ParseCommand\fR(\fIinterp, start, numBytes, nested, parsePtr\fR) |
| 18 |
.sp |
| 19 |
int |
| 20 |
\fBTcl_ParseExpr\fR(\fIinterp, start, numBytes, parsePtr\fR) |
| 21 |
.sp |
| 22 |
int |
| 23 |
\fBTcl_ParseBraces\fR(\fIinterp, start, numBytes, parsePtr, append, termPtr\fR) |
| 24 |
.sp |
| 25 |
int |
| 26 |
\fBTcl_ParseQuotedString\fR(\fIinterp, start, numBytes, parsePtr, append, termPtr\fR) |
| 27 |
.sp |
| 28 |
int |
| 29 |
\fBTcl_ParseVarName\fR(\fIinterp, start, numBytes, parsePtr, append\fR) |
| 30 |
.sp |
| 31 |
const char * |
| 32 |
\fBTcl_ParseVar\fR(\fIinterp, start, termPtr\fR) |
| 33 |
.sp |
| 34 |
\fBTcl_FreeParse\fR(\fIusedParsePtr\fR) |
| 35 |
.sp |
| 36 |
Tcl_Obj * |
| 37 |
\fBTcl_EvalTokens\fR(\fIinterp, tokenPtr, numTokens\fR) |
| 38 |
.sp |
| 39 |
int |
| 40 |
\fBTcl_EvalTokensStandard\fR(\fIinterp, tokenPtr, numTokens\fR) |
| 41 |
.SH ARGUMENTS |
| 42 |
.AS Tcl_Interp *usedParsePtr out |
| 43 |
.AP Tcl_Interp *interp out |
| 44 |
For procedures other than \fBTcl_FreeParse\fR, \fBTcl_EvalTokens\fR |
| 45 |
and \fBTcl_EvalTokensStandard\fR, used only for error reporting; |
| 46 |
if NULL, then no error messages are left after errors. |
| 47 |
For \fBTcl_EvalTokens\fR and \fBTcl_EvalTokensStandard\fR, |
| 48 |
determines the context for evaluating the |
| 49 |
script and also is used for error reporting; must not be NULL. |
| 50 |
.AP "const char" *start in |
| 51 |
Pointer to first character in string to parse. |
| 52 |
.AP int numBytes in |
| 53 |
Number of bytes in string to parse, not including any terminating null |
| 54 |
character. If less than 0 then the script consists of all characters |
| 55 |
following \fIstart\fR up to the first null character. |
| 56 |
.AP int nested in |
| 57 |
Non-zero means that the script is part of a command substitution so an |
| 58 |
unquoted close bracket should be treated as a command terminator. If zero, |
| 59 |
close brackets have no special meaning. |
| 60 |
.AP int append in |
| 61 |
Non-zero means that \fI*parsePtr\fR already contains valid tokens; the new |
| 62 |
tokens should be appended to those already present. Zero means that |
| 63 |
\fI*parsePtr\fR is uninitialized; any information in it is ignored. |
| 64 |
This argument is normally 0. |
| 65 |
.AP Tcl_Parse *parsePtr out |
| 66 |
Points to structure to fill in with information about the parsed |
| 67 |
command, expression, variable name, etc. |
| 68 |
Any previous information in this structure |
| 69 |
is ignored, unless \fIappend\fR is non-zero in a call to |
| 70 |
\fBTcl_ParseBraces\fR, \fBTcl_ParseQuotedString\fR, |
| 71 |
or \fBTcl_ParseVarName\fR. |
| 72 |
.AP "const char" **termPtr out |
| 73 |
If not NULL, points to a location where |
| 74 |
\fBTcl_ParseBraces\fR, \fBTcl_ParseQuotedString\fR, and |
| 75 |
\fBTcl_ParseVar\fR will store a pointer to the character |
| 76 |
just after the terminating character (the close-brace, the last |
| 77 |
character of the variable name, or the close-quote (respectively)) |
| 78 |
if the parse was successful. |
| 79 |
.AP Tcl_Parse *usedParsePtr in |
| 80 |
Points to structure that was filled in by a previous call to |
| 81 |
\fBTcl_ParseCommand\fR, \fBTcl_ParseExpr\fR, \fBTcl_ParseVarName\fR, etc. |
| 82 |
.BE |
| 83 |
.SH DESCRIPTION |
| 84 |
.PP |
| 85 |
These procedures parse Tcl commands or portions of Tcl commands such as |
| 86 |
expressions or references to variables. |
| 87 |
Each procedure takes a pointer to a script (or portion thereof) |
| 88 |
and fills in the structure pointed to by \fIparsePtr\fR |
| 89 |
with a collection of tokens describing the information that was parsed. |
| 90 |
The procedures normally return \fBTCL_OK\fR. |
| 91 |
However, if an error occurs then they return \fBTCL_ERROR\fR, |
| 92 |
leave an error message in \fIinterp\fR's result |
| 93 |
(if \fIinterp\fR is not NULL), |
| 94 |
and leave nothing in \fIparsePtr\fR. |
| 95 |
.PP |
| 96 |
\fBTcl_ParseCommand\fR is a procedure that parses Tcl |
| 97 |
scripts. Given a pointer to a script, it |
| 98 |
parses the first command from the script. If the command was parsed |
| 99 |
successfully, \fBTcl_ParseCommand\fR returns \fBTCL_OK\fR and fills in the |
| 100 |
structure pointed to by \fIparsePtr\fR with information about the |
| 101 |
structure of the command (see below for details). |
| 102 |
If an error occurred in parsing the command then |
| 103 |
\fBTCL_ERROR\fR is returned, an error message is left in \fIinterp\fR's |
| 104 |
result, and no information is left at \fI*parsePtr\fR. |
| 105 |
.PP |
| 106 |
\fBTcl_ParseExpr\fR parses Tcl expressions. |
| 107 |
Given a pointer to a script containing an expression, |
| 108 |
\fBTcl_ParseExpr\fR parses the expression. |
| 109 |
If the expression was parsed successfully, |
| 110 |
\fBTcl_ParseExpr\fR returns \fBTCL_OK\fR and fills in the |
| 111 |
structure pointed to by \fIparsePtr\fR with information about the |
| 112 |
structure of the expression (see below for details). |
| 113 |
If an error occurred in parsing the command then |
| 114 |
\fBTCL_ERROR\fR is returned, an error message is left in \fIinterp\fR's |
| 115 |
result, and no information is left at \fI*parsePtr\fR. |
| 116 |
.PP |
| 117 |
\fBTcl_ParseBraces\fR parses a string or command argument |
| 118 |
enclosed in braces such as |
| 119 |
\fB{hello}\fR or \fB{string \et with \et tabs}\fR |
| 120 |
from the beginning of its argument \fIstart\fR. |
| 121 |
The first character of \fIstart\fR must be \fB{\fR. |
| 122 |
If the braced string was parsed successfully, |
| 123 |
\fBTcl_ParseBraces\fR returns \fBTCL_OK\fR, |
| 124 |
fills in the structure pointed to by \fIparsePtr\fR |
| 125 |
with information about the structure of the string |
| 126 |
(see below for details), |
| 127 |
and stores a pointer to the character just after the terminating \fB}\fR |
| 128 |
in the location given by \fI*termPtr\fR. |
| 129 |
If an error occurs while parsing the string |
| 130 |
then \fBTCL_ERROR\fR is returned, |
| 131 |
an error message is left in \fIinterp\fR's result, |
| 132 |
and no information is left at \fI*parsePtr\fR or \fI*termPtr\fR. |
| 133 |
.PP |
| 134 |
\fBTcl_ParseQuotedString\fR parses a double-quoted string such as |
| 135 |
\fB"sum is [expr {$a+$b}]"\fR |
| 136 |
from the beginning of the argument \fIstart\fR. |
| 137 |
The first character of \fIstart\fR must be \fB\N'34'\fR. |
| 138 |
If the double-quoted string was parsed successfully, |
| 139 |
\fBTcl_ParseQuotedString\fR returns \fBTCL_OK\fR, |
| 140 |
fills in the structure pointed to by \fIparsePtr\fR |
| 141 |
with information about the structure of the string |
| 142 |
(see below for details), |
| 143 |
and stores a pointer to the character just after the terminating \fB\N'34'\fR |
| 144 |
in the location given by \fI*termPtr\fR. |
| 145 |
If an error occurs while parsing the string |
| 146 |
then \fBTCL_ERROR\fR is returned, |
| 147 |
an error message is left in \fIinterp\fR's result, |
| 148 |
and no information is left at \fI*parsePtr\fR or \fI*termPtr\fR. |
| 149 |
.PP |
| 150 |
\fBTcl_ParseVarName\fR parses a Tcl variable reference such as |
| 151 |
\fB$abc\fR or \fB$x([expr {$index + 1}])\fR from the beginning of its |
| 152 |
\fIstart\fR argument. |
| 153 |
The first character of \fIstart\fR must be \fB$\fR. |
| 154 |
If a variable name was parsed successfully, \fBTcl_ParseVarName\fR |
| 155 |
returns \fBTCL_OK\fR and fills in the structure pointed to by |
| 156 |
\fIparsePtr\fR with information about the structure of the variable name |
| 157 |
(see below for details). If an error |
| 158 |
occurs while parsing the command then \fBTCL_ERROR\fR is returned, an |
| 159 |
error message is left in \fIinterp\fR's result (if \fIinterp\fR is not |
| 160 |
NULL), and no information is left at \fI*parsePtr\fR. |
| 161 |
.PP |
| 162 |
\fBTcl_ParseVar\fR parses a Tcl variable reference such as \fB$abc\fR |
| 163 |
or \fB$x([expr {$index + 1}])\fR from the beginning of its \fIstart\fR |
| 164 |
argument. The first character of \fIstart\fR must be \fB$\fR. If |
| 165 |
the variable name is parsed successfully, \fBTcl_ParseVar\fR returns a |
| 166 |
pointer to the string value of the variable. If an error occurs while |
| 167 |
parsing, then NULL is returned and an error message is left in |
| 168 |
\fIinterp\fR's result. |
| 169 |
.PP |
| 170 |
The information left at \fI*parsePtr\fR |
| 171 |
by \fBTcl_ParseCommand\fR, \fBTcl_ParseExpr\fR, \fBTcl_ParseBraces\fR, |
| 172 |
\fBTcl_ParseQuotedString\fR, and \fBTcl_ParseVarName\fR |
| 173 |
may include dynamically allocated memory. |
| 174 |
If these five parsing procedures return \fBTCL_OK\fR |
| 175 |
then the caller must invoke \fBTcl_FreeParse\fR to release |
| 176 |
the storage at \fI*parsePtr\fR. |
| 177 |
These procedures ignore any existing information in |
| 178 |
\fI*parsePtr\fR (unless \fIappend\fR is non-zero), |
| 179 |
so if repeated calls are being made to any of them |
| 180 |
then \fBTcl_FreeParse\fR must be invoked once after each call. |
| 181 |
.PP |
| 182 |
\fBTcl_EvalTokensStandard\fR evaluates a sequence of parse tokens from |
| 183 |
a Tcl_Parse structure. The tokens typically consist |
| 184 |
of all the tokens in a word or all the tokens that make up the index for |
| 185 |
a reference to an array variable. \fBTcl_EvalTokensStandard\fR performs the |
| 186 |
substitutions requested by the tokens and concatenates the |
| 187 |
resulting values. |
| 188 |
The return value from \fBTcl_EvalTokensStandard\fR is a Tcl completion |
| 189 |
code with one of the values \fBTCL_OK\fR, \fBTCL_ERROR\fR, |
| 190 |
\fBTCL_RETURN\fR, \fBTCL_BREAK\fR, or \fBTCL_CONTINUE\fR, or possibly |
| 191 |
some other integer value originating in an extension. |
| 192 |
In addition, a result value or error message is left in \fIinterp\fR's |
| 193 |
result; it can be retrieved using \fBTcl_GetObjResult\fR. |
| 194 |
.PP |
| 195 |
\fBTcl_EvalTokens\fR differs from \fBTcl_EvalTokensStandard\fR only in |
| 196 |
the return convention used: it returns the result in a new Tcl_Obj. |
| 197 |
The reference count of the value returned as result has been |
| 198 |
incremented, so the caller must |
| 199 |
invoke \fBTcl_DecrRefCount\fR when it is finished with the value. |
| 200 |
If an error or other exception occurs while evaluating the tokens |
| 201 |
(such as a reference to a non-existent variable) then the return value |
| 202 |
is NULL and an error message is left in \fIinterp\fR's result. The use |
| 203 |
of \fBTcl_EvalTokens\fR is deprecated. |
| 204 |
.SH "TCL_PARSE STRUCTURE" |
| 205 |
.PP |
| 206 |
\fBTcl_ParseCommand\fR, \fBTcl_ParseExpr\fR, \fBTcl_ParseBraces\fR, |
| 207 |
\fBTcl_ParseQuotedString\fR, and \fBTcl_ParseVarName\fR |
| 208 |
return parse information in two data structures, Tcl_Parse and Tcl_Token: |
| 209 |
.PP |
| 210 |
.CS |
| 211 |
typedef struct Tcl_Parse { |
| 212 |
const char *\fIcommentStart\fR; |
| 213 |
int \fIcommentSize\fR; |
| 214 |
const char *\fIcommandStart\fR; |
| 215 |
int \fIcommandSize\fR; |
| 216 |
int \fInumWords\fR; |
| 217 |
Tcl_Token *\fItokenPtr\fR; |
| 218 |
int \fInumTokens\fR; |
| 219 |
... |
| 220 |
} \fBTcl_Parse\fR; |
| 221 |
|
| 222 |
typedef struct Tcl_Token { |
| 223 |
int \fItype\fR; |
| 224 |
const char *\fIstart\fR; |
| 225 |
int \fIsize\fR; |
| 226 |
int \fInumComponents\fR; |
| 227 |
} \fBTcl_Token\fR; |
| 228 |
.CE |
| 229 |
.PP |
| 230 |
The first five fields of a Tcl_Parse structure |
| 231 |
are filled in only by \fBTcl_ParseCommand\fR. |
| 232 |
These fields are not used by the other parsing procedures. |
| 233 |
.PP |
| 234 |
\fBTcl_ParseCommand\fR fills in a Tcl_Parse structure |
| 235 |
with information that describes one Tcl command and any comments that |
| 236 |
precede the command. |
| 237 |
If there are comments, |
| 238 |
the \fIcommentStart\fR field points to the \fB#\fR character that begins |
| 239 |
the first comment and \fIcommentSize\fR indicates the number of bytes |
| 240 |
in all of the comments preceding the command, including the newline |
| 241 |
character that terminates the last comment. |
| 242 |
If the command is not preceded by any comments, \fIcommentSize\fR is 0. |
| 243 |
\fBTcl_ParseCommand\fR also sets the \fIcommandStart\fR field |
| 244 |
to point to the first character of the first |
| 245 |
word in the command (skipping any comments and leading space) and |
| 246 |
\fIcommandSize\fR gives the total number of bytes in the command, |
| 247 |
including the character pointed to by \fIcommandStart\fR up to and |
| 248 |
including the newline, close bracket, or semicolon character that |
| 249 |
terminates the command. The \fInumWords\fR field gives the |
| 250 |
total number of words in the command. |
| 251 |
.PP |
| 252 |
All parsing procedures set the remaining fields, |
| 253 |
\fItokenPtr\fR and \fInumTokens\fR. |
| 254 |
The \fItokenPtr\fR field points to the first in an array of Tcl_Token |
| 255 |
structures that describe the components of the entity being parsed. |
| 256 |
The \fInumTokens\fR field gives the total number of tokens |
| 257 |
present in the array. |
| 258 |
Each token contains four fields. |
| 259 |
The \fItype\fR field selects one of several token types |
| 260 |
that are described below. The \fIstart\fR field |
| 261 |
points to the first character in the token and the \fIsize\fR field |
| 262 |
gives the total number of characters in the token. Some token types, |
| 263 |
such as \fBTCL_TOKEN_WORD\fR and \fBTCL_TOKEN_VARIABLE\fR, consist of |
| 264 |
several component tokens, which immediately follow the parent token; |
| 265 |
the \fInumComponents\fR field describes how many of these there are. |
| 266 |
The \fItype\fR field has one of the following values: |
| 267 |
.TP 20 |
| 268 |
\fBTCL_TOKEN_WORD\fR |
| 269 |
. |
| 270 |
This token ordinarily describes one word of a command |
| 271 |
but it may also describe a quoted or braced string in an expression. |
| 272 |
The token describes a component of the script that is |
| 273 |
the result of concatenating together a sequence of subcomponents, |
| 274 |
each described by a separate subtoken. |
| 275 |
The token starts with the first non-blank |
| 276 |
character of the component (which may be a double-quote or open brace) |
| 277 |
and includes all characters in the component up to but not including the |
| 278 |
space, semicolon, close bracket, close quote, or close brace that |
| 279 |
terminates the component. The \fInumComponents\fR field counts the total |
| 280 |
number of sub-tokens that make up the word, including sub-tokens |
| 281 |
of \fBTCL_TOKEN_VARIABLE\fR and \fBTCL_TOKEN_BS\fR tokens. |
| 282 |
.TP |
| 283 |
\fBTCL_TOKEN_SIMPLE_WORD\fR |
| 284 |
. |
| 285 |
This token has the same meaning as \fBTCL_TOKEN_WORD\fR, except that |
| 286 |
the word is guaranteed to consist of a single \fBTCL_TOKEN_TEXT\fR |
| 287 |
sub-token. The \fInumComponents\fR field is always 1. |
| 288 |
.TP |
| 289 |
\fBTCL_TOKEN_EXPAND_WORD\fR |
| 290 |
. |
| 291 |
This token has the same meaning as \fBTCL_TOKEN_WORD\fR, except that |
| 292 |
the command parser notes this word began with the expansion |
| 293 |
prefix \fB{*}\fR, indicating that after substitution, |
| 294 |
the list value of this word should be expanded to form multiple |
| 295 |
arguments in command evaluation. This |
| 296 |
token type can only be created by Tcl_ParseCommand. |
| 297 |
.TP |
| 298 |
\fBTCL_TOKEN_TEXT\fR |
| 299 |
. |
| 300 |
The token describes a range of literal text that is part of a word. |
| 301 |
The \fInumComponents\fR field is always 0. |
| 302 |
.TP |
| 303 |
\fBTCL_TOKEN_BS\fR |
| 304 |
. |
| 305 |
The token describes a backslash sequence such as \fB\en\fR or \fB\e0xA3\fR. |
| 306 |
The \fInumComponents\fR field is always 0. |
| 307 |
.TP |
| 308 |
\fBTCL_TOKEN_COMMAND\fR |
| 309 |
. |
| 310 |
The token describes a command whose result must be substituted into |
| 311 |
the word. The token includes the square brackets that surround the |
| 312 |
command. The \fInumComponents\fR field is always 0 (the nested command |
| 313 |
is not parsed; call \fBTcl_ParseCommand\fR recursively if you want to |
| 314 |
see its tokens). |
| 315 |
.TP |
| 316 |
\fBTCL_TOKEN_VARIABLE\fR |
| 317 |
. |
| 318 |
The token describes a variable substitution, including the |
| 319 |
\fB$\fR, variable name, and array index (if there is one) up through the |
| 320 |
close parenthesis that terminates the index. This token is followed |
| 321 |
by one or more additional tokens that describe the variable name and |
| 322 |
array index. If \fInumComponents\fR is 1 then the variable is a |
| 323 |
scalar and the next token is a \fBTCL_TOKEN_TEXT\fR token that gives the |
| 324 |
variable name. If \fInumComponents\fR is greater than 1 then the |
| 325 |
variable is an array: the first sub-token is a \fBTCL_TOKEN_TEXT\fR |
| 326 |
token giving the array name and the remaining sub-tokens are |
| 327 |
\fBTCL_TOKEN_TEXT\fR, \fBTCL_TOKEN_BS\fR, \fBTCL_TOKEN_COMMAND\fR, and |
| 328 |
\fBTCL_TOKEN_VARIABLE\fR tokens that must be concatenated to produce the |
| 329 |
array index. The \fInumComponents\fR field includes nested sub-tokens |
| 330 |
that are part of \fBTCL_TOKEN_VARIABLE\fR tokens in the array index. |
| 331 |
.TP |
| 332 |
\fBTCL_TOKEN_SUB_EXPR\fR |
| 333 |
. |
| 334 |
The token describes one subexpression of an expression |
| 335 |
(or an entire expression). |
| 336 |
A subexpression may consist of a value |
| 337 |
such as an integer literal, variable substitution, |
| 338 |
or parenthesized subexpression; |
| 339 |
it may also consist of an operator and its operands. |
| 340 |
The token starts with the first non-blank character of the subexpression |
| 341 |
up to but not including the space, brace, close-paren, or bracket |
| 342 |
that terminates the subexpression. |
| 343 |
This token is followed by one or more additional tokens |
| 344 |
that describe the subexpression. |
| 345 |
If the first sub-token after the \fBTCL_TOKEN_SUB_EXPR\fR token |
| 346 |
is a \fBTCL_TOKEN_OPERATOR\fR token, |
| 347 |
the subexpression consists of an operator and its token operands. |
| 348 |
If the operator has no operands, the subexpression consists of |
| 349 |
just the \fBTCL_TOKEN_OPERATOR\fR token. |
| 350 |
Each operand is described by a \fBTCL_TOKEN_SUB_EXPR\fR token. |
| 351 |
Otherwise, the subexpression is a value described by |
| 352 |
one of the token types \fBTCL_TOKEN_WORD\fR, \fBTCL_TOKEN_TEXT\fR, |
| 353 |
\fBTCL_TOKEN_BS\fR, \fBTCL_TOKEN_COMMAND\fR, |
| 354 |
\fBTCL_TOKEN_VARIABLE\fR, and \fBTCL_TOKEN_SUB_EXPR\fR. |
| 355 |
The \fInumComponents\fR field |
| 356 |
counts the total number of sub-tokens that make up the subexpression; |
| 357 |
this includes the sub-tokens for any nested \fBTCL_TOKEN_SUB_EXPR\fR tokens. |
| 358 |
.TP |
| 359 |
\fBTCL_TOKEN_OPERATOR\fR |
| 360 |
. |
| 361 |
The token describes one operator of an expression |
| 362 |
such as \fB&&\fR or \fBhypot\fR. |
| 363 |
A \fBTCL_TOKEN_OPERATOR\fR token is always preceded by a |
| 364 |
\fBTCL_TOKEN_SUB_EXPR\fR token |
| 365 |
that describes the operator and its operands; |
| 366 |
the \fBTCL_TOKEN_SUB_EXPR\fR token's \fInumComponents\fR field |
| 367 |
can be used to determine the number of operands. |
| 368 |
A binary operator such as \fB*\fR |
| 369 |
is followed by two \fBTCL_TOKEN_SUB_EXPR\fR tokens |
| 370 |
that describe its operands. |
| 371 |
A unary operator like \fB\-\fR |
| 372 |
is followed by a single \fBTCL_TOKEN_SUB_EXPR\fR token |
| 373 |
for its operand. |
| 374 |
If the operator is a math function such as \fBlog10\fR, |
| 375 |
the \fBTCL_TOKEN_OPERATOR\fR token will give its name and |
| 376 |
the following \fBTCL_TOKEN_SUB_EXPR\fR tokens will describe |
| 377 |
its operands; |
| 378 |
if there are no operands (as with \fBrand\fR), |
| 379 |
no \fBTCL_TOKEN_SUB_EXPR\fR tokens follow. |
| 380 |
There is one trinary operator, \fB?\fR, |
| 381 |
that appears in if-then-else subexpressions |
| 382 |
such as \fIx\fB?\fIy\fB:\fIz\fR; |
| 383 |
in this case, the \fB?\fR \fBTCL_TOKEN_OPERATOR\fR token |
| 384 |
is followed by three \fBTCL_TOKEN_SUB_EXPR\fR tokens for the operands |
| 385 |
\fIx\fR, \fIy\fR, and \fIz\fR. |
| 386 |
The \fInumComponents\fR field for a \fBTCL_TOKEN_OPERATOR\fR token |
| 387 |
is always 0. |
| 388 |
.PP |
| 389 |
After \fBTcl_ParseCommand\fR returns, the first token pointed to by |
| 390 |
the \fItokenPtr\fR field of the |
| 391 |
Tcl_Parse structure always has type \fBTCL_TOKEN_WORD\fR or |
| 392 |
\fBTCL_TOKEN_SIMPLE_WORD\fR or \fBTCL_TOKEN_EXPAND_WORD\fR. |
| 393 |
It is followed by the sub-tokens |
| 394 |
that must be concatenated to produce the value of that word. |
| 395 |
The next token is the \fBTCL_TOKEN_WORD\fR or \fBTCL_TOKEN_SIMPLE_WORD\fR |
| 396 |
of \fBTCL_TOKEN_EXPAND_WORD\fR token for the second word, |
| 397 |
followed by sub-tokens for that |
| 398 |
word, and so on until all \fInumWords\fR have been accounted |
| 399 |
for. |
| 400 |
.PP |
| 401 |
After \fBTcl_ParseExpr\fR returns, the first token pointed to by |
| 402 |
the \fItokenPtr\fR field of the |
| 403 |
Tcl_Parse structure always has type \fBTCL_TOKEN_SUB_EXPR\fR. |
| 404 |
It is followed by the sub-tokens that must be evaluated |
| 405 |
to produce the value of the expression. |
| 406 |
Only the token information in the Tcl_Parse structure |
| 407 |
is modified: the \fIcommentStart\fR, \fIcommentSize\fR, |
| 408 |
\fIcommandStart\fR, and \fIcommandSize\fR fields are not modified |
| 409 |
by \fBTcl_ParseExpr\fR. |
| 410 |
.PP |
| 411 |
After \fBTcl_ParseBraces\fR returns, |
| 412 |
the array of tokens pointed to by the \fItokenPtr\fR field of the |
| 413 |
Tcl_Parse structure will contain a single \fBTCL_TOKEN_TEXT\fR token |
| 414 |
if the braced string does not contain any backslash-newlines. |
| 415 |
If the string does contain backslash-newlines, |
| 416 |
the array of tokens will contain one or more |
| 417 |
\fBTCL_TOKEN_TEXT\fR or \fBTCL_TOKEN_BS\fR sub-tokens |
| 418 |
that must be concatenated to produce the value of the string. |
| 419 |
If the braced string was just \fB{}\fR |
| 420 |
(that is, the string was empty), |
| 421 |
the single \fBTCL_TOKEN_TEXT\fR token will have a \fIsize\fR field |
| 422 |
containing zero; |
| 423 |
this ensures that at least one token appears |
| 424 |
to describe the braced string. |
| 425 |
Only the token information in the Tcl_Parse structure |
| 426 |
is modified: the \fIcommentStart\fR, \fIcommentSize\fR, |
| 427 |
\fIcommandStart\fR, and \fIcommandSize\fR fields are not modified |
| 428 |
by \fBTcl_ParseBraces\fR. |
| 429 |
.PP |
| 430 |
After \fBTcl_ParseQuotedString\fR returns, |
| 431 |
the array of tokens pointed to by the \fItokenPtr\fR field of the |
| 432 |
Tcl_Parse structure depends on the contents of the quoted string. |
| 433 |
It will consist of one or more \fBTCL_TOKEN_TEXT\fR, \fBTCL_TOKEN_BS\fR, |
| 434 |
\fBTCL_TOKEN_COMMAND\fR, and \fBTCL_TOKEN_VARIABLE\fR sub-tokens. |
| 435 |
The array always contains at least one token; |
| 436 |
for example, if the argument \fIstart\fR is empty, |
| 437 |
the array returned consists of a single \fBTCL_TOKEN_TEXT\fR token |
| 438 |
with a zero \fIsize\fR field. |
| 439 |
Only the token information in the Tcl_Parse structure |
| 440 |
is modified: the \fIcommentStart\fR, \fIcommentSize\fR, |
| 441 |
\fIcommandStart\fR, and \fIcommandSize\fR fields are not modified. |
| 442 |
.PP |
| 443 |
After \fBTcl_ParseVarName\fR returns, the first token pointed to by |
| 444 |
the \fItokenPtr\fR field of the |
| 445 |
Tcl_Parse structure always has type \fBTCL_TOKEN_VARIABLE\fR. It |
| 446 |
is followed by the sub-tokens that make up the variable name as |
| 447 |
described above. The total length of the variable name is |
| 448 |
contained in the \fIsize\fR field of the first token. |
| 449 |
As in \fBTcl_ParseExpr\fR, |
| 450 |
only the token information in the Tcl_Parse structure |
| 451 |
is modified by \fBTcl_ParseVarName\fR: |
| 452 |
the \fIcommentStart\fR, \fIcommentSize\fR, |
| 453 |
\fIcommandStart\fR, and \fIcommandSize\fR fields are not modified. |
| 454 |
.PP |
| 455 |
All of the character pointers in the |
| 456 |
Tcl_Parse and Tcl_Token structures refer |
| 457 |
to characters in the \fIstart\fR argument passed to |
| 458 |
\fBTcl_ParseCommand\fR, \fBTcl_ParseExpr\fR, \fBTcl_ParseBraces\fR, |
| 459 |
\fBTcl_ParseQuotedString\fR, and \fBTcl_ParseVarName\fR. |
| 460 |
.PP |
| 461 |
There are additional fields in the Tcl_Parse structure after the |
| 462 |
\fInumTokens\fR field, but these are for the private use of |
| 463 |
\fBTcl_ParseCommand\fR, \fBTcl_ParseExpr\fR, \fBTcl_ParseBraces\fR, |
| 464 |
\fBTcl_ParseQuotedString\fR, and \fBTcl_ParseVarName\fR; they should not be |
| 465 |
referenced by code outside of these procedures. |
| 466 |
.SH KEYWORDS |
| 467 |
backslash substitution, braces, command, expression, parse, token, variable substitution |