SYNOPSIS
#include <tcl.h>
int Tcl_ParseCommand(interp, string, numBytes, nested, parsePtr)
int Tcl_ParseExpr(interp, string, numBytes, parsePtr)
int Tcl_ParseBraces(interp, string, numBytes, parsePtr, append, termPtr)
int Tcl_ParseQuotedString(interp, string, numBytes, parsePtr, append, termPtr)
int Tcl_ParseVarName(interp, string, numBytes, parsePtr, append)
char * Tcl_ParseVar(interp, string, termPtr)
Tcl_FreeParse(usedParsePtr)
Tcl_Obj * Tcl_EvalTokens(interp, tokenPtr, numTokens)
ARGUMENTS
- Tcl_Interp *interp (out)
-
For procedures other than
Tcl_FreeParse() andTcl_EvalTokens() , used only for error reporting; if NULL, then no error messages are left after errors. ForTcl_EvalTokens() , determines the context for evaluating the script and also is used for error reporting; must not be NULL. - char *string (in)
-
Pointer to first character in string to parse.
- int numBytes (in)
-
Number of bytes in string, not including any terminating null character. If less than 0 then the script consists of all characters in string up to the first null character.
- int nested (in)
-
Non-zero means that the script is part of a command substitution so an unquoted close bracket should be treated as a command terminator. If zero, close brackets have no special meaning.
- int append (in)
-
Non-zero means that *parsePtr already contains valid tokens; the new tokens should be appended to those already present. Zero means that *parsePtr is uninitialized; any information in it is ignored. This argument is normally 0.
- Tcl_Parse *parsePtr (out)
-
Points to structure to fill in with information about the parsed command, expression, variable name, etc. Any previous information in this structure is ignored, unless append is non-zero in a call to
Tcl_ParseBraces() ,Tcl_ParseQuotedString() , orTcl_ParseVarName() . - char **termPtr (out)
-
If not NULL, points to a location where
Tcl_ParseBraces() ,Tcl_ParseQuotedString() , andTcl_ParseVar() will store a pointer to the character just after the terminating character (the close-brace, the last character of the variable name, or the close-quote (respectively)) if the parse was successful. - Tcl_Parse *usedParsePtr (in)
-
Points to structure that was filled in by a previous call to
Tcl_ParseCommand() ,Tcl_ParseExpr() ,Tcl_ParseVarName() , etc.
DESCRIPTION
These procedures parse Tcl commands or portions of Tcl commands such as expressions or references to variables. Each procedure takes a pointer to a script (or portion thereof) and fills in the structure pointed to by parsePtr with a collection of tokens describing the information that was parsed. The procedures normally return TCL_OK. However, if an error occurs then they return TCL_ERROR, leave an error message in interp's result (if interp is not NULL), and leave nothing in parsePtr.
The information left at *parsePtr
by
TCL_PARSE STRUCTURE
typedef struct Tcl_Parse { char *commentStart; int commentSize; char *commandStart; int commandSize; int numWords; Tcl_Token *tokenPtr; int numTokens; ... } Tcl_Parse; typedef struct Tcl_Token { int type; char *start; int size; int numComponents; } Tcl_Token;
The first five fields of a Tcl_Parse structure
are filled in only by
All parsing procedures set the remaining fields, tokenPtr and numTokens. The tokenPtr field points to the first in an array of Tcl_Token structures that describe the components of the entity being parsed. The numTokens field gives the total number of tokens present in the array. Each token contains four fields. The type field selects one of several token types that are described below. The start field points to the first character in the token and the size field gives the total number of characters in the token. Some token types, such as TCL_TOKEN_WORD and TCL_TOKEN_VARIABLE, consist of several component tokens, which immediately follow the parent token; the numComponents field describes how many of these there are. The type field has one of the following values:
- TCL_TOKEN_WORD
-
This token ordinarily describes one word of a command but it may also describe a quoted or braced string in an expression. The token describes a component of the script that is the result of concatenating together a sequence of subcomponents, each described by a separate subtoken. The token starts with the first non-blank character of the component (which may be a double-quote or open brace) and includes all characters in the component up to but not including the space, semicolon, close bracket, close quote, or close brace that terminates the component. The numComponents field counts the total number of sub-tokens that make up the word, including sub-tokens of TCL_TOKEN_VARIABLE and TCL_TOKEN_BS tokens.
- TCL_TOKEN_SIMPLE_WORD
-
This token has the same meaning as TCL_TOKEN_WORD, except that the word is guaranteed to consist of a single TCL_TOKEN_TEXT sub-token. The numComponents field is always 1.
- TCL_TOKEN_TEXT
-
The token describes a range of literal text that is part of a word. The numComponents field is always 0.
- TCL_TOKEN_BS
-
The token describes a backslash sequence such as \n or xa3. The numComponents field is always 0.
- 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). - TCL_TOKEN_VARIABLE
-
The token describes a variable substitution, including the $, variable name, and array index (if there is one) up through the close parenthesis that terminates the index. This token is followed by one or more additional tokens that describe the variable name and array index. If numComponents is 1 then the variable is a scalar and the next token is a TCL_TOKEN_TEXT token that gives the variable name. If numComponents is greater than 1 then the variable is an array: the first sub-token is a TCL_TOKEN_TEXT token giving the array name and the remaining sub-tokens are TCL_TOKEN_TEXT, TCL_TOKEN_BS, TCL_TOKEN_COMMAND, and TCL_TOKEN_VARIABLE tokens that must be concatenated to produce the array index. The numComponents field includes nested sub-tokens that are part of TCL_TOKEN_VARIABLE tokens in the array index.
- TCL_TOKEN_SUB_EXPR
-
The token describes one subexpression of an expression (or an entire expression). A subexpression may consist of a value such as an integer literal, variable substitution, or parenthesized subexpression; it may also consist of an operator and its operands. The token starts with the first non-blank character of the subexpression up to but not including the space, brace, close-paren, or bracket that terminates the subexpression. This token is followed by one or more additional tokens that describe the subexpression. If the first sub-token after the TCL_TOKEN_SUB_EXPR token is a TCL_TOKEN_OPERATOR token, the subexpression consists of an operator and its token operands. If the operator has no operands, the subexpression consists of just the TCL_TOKEN_OPERATOR token. Each operand is described by a TCL_TOKEN_SUB_EXPR token. Otherwise, the subexpression is a value described by one of the token types TCL_TOKEN_WORD, TCL_TOKEN_TEXT, TCL_TOKEN_BS, TCL_TOKEN_COMMAND, TCL_TOKEN_VARIABLE, and TCL_TOKEN_SUB_EXPR. The numComponents field counts the total number of sub-tokens that make up the subexpression; this includes the sub-tokens for any nested TCL_TOKEN_SUB_EXPR tokens.
- TCL_TOKEN_OPERATOR
-
The token describes one operator of an expression such as && or hypot. An TCL_TOKEN_OPERATOR token is always preceded by a TCL_TOKEN_SUB_EXPR token that describes the operator and its operands; the TCL_TOKEN_SUB_EXPR token's numComponents field can be used to determine the number of operands. A binary operator such as * is followed by two TCL_TOKEN_SUB_EXPR tokens that describe its operands. A unary operator like
- is followed by a single TCL_TOKEN_SUB_EXPR token for its operand. If the operator is a math function such as log10, the TCL_TOKEN_OPERATOR token will give its name and the following TCL_TOKEN_SUB_EXPR tokens will describe its operands; if there are no operands (as with rand), no TCL_TOKEN_SUB_EXPR tokens follow. There is one trinary operator, ?, that appears in if-then-else subexpressions such as x?y:z; in this case, the ? TCL_TOKEN_OPERATOR token is followed by three TCL_TOKEN_SUB_EXPR tokens for the operands x, y, and z. The numComponents field for a TCL_TOKEN_OPERATOR token is always 0.
After
After
After
After
After
All of the character pointers in the
Tcl_Parse and Tcl_Token structures refer
to characters in the string argument passed to
There are additional fields in the Tcl_Parse structure after the
numTokens field, but these are for the private use of
PORTABILITY
Windows 8.1. Windows Server 2012 R2. Windows 10. Windows Server 2016. Windows Server 2019. Windows 11. Windows Server 2022.
AVAILABILITY
PTC MKS Toolkit for Professional Developers
PTC MKS Toolkit for Enterprise Developers
PTC MKS Toolkit for Enterprise Developers 64-Bit Edition
PTC MKS Toolkit 10.4 Documentation Build 39.