⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 parsecmd.3

📁 tcl是工具命令语言
💻 3
📖 第 1 页 / 共 2 页
字号:
    int \fIsize\fR;    int \fInumComponents\fR;} Tcl_Token;.CE.PPThe first five fields of a Tcl_Parse structureare filled in only by \fBTcl_ParseCommand\fR.These fields are not used by the other parsing procedures..PP\fBTcl_ParseCommand\fR fills in a Tcl_Parse structurewith information that describes one Tcl command and any comments thatprecede the command.If there are comments,the \fIcommentStart\fR field points to the \fB#\fR character that beginsthe first comment and \fIcommentSize\fR indicates the number of bytesin all of the comments preceding the command, including the newlinecharacter that terminates the last comment.If the command is not preceded by any comments, \fIcommentSize\fR is 0.\fBTcl_ParseCommand\fR also sets the \fIcommandStart\fR fieldto point to the first character of the firstword in the command (skipping any comments and leading space) and \fIcommandSize\fR gives the total number of bytes in the command,including the character pointed to by \fIcommandStart\fR up to andincluding the newline, close bracket, or semicolon character thatterminates the command.  The \fInumWords\fR field gives thetotal number of words in the command..PPAll parsing procedures set the remaining fields,\fItokenPtr\fR and \fInumTokens\fR.The \fItokenPtr\fR field points to the first in an array of Tcl_Tokenstructures that describe the components of the entity being parsed.The \fInumTokens\fR field gives the total number of tokenspresent in the array.Each token contains four fields.The \fItype\fR field selects one of several token typesthat are described below.  The \fIstart\fR fieldpoints to the first character in the token and the \fIsize\fR fieldgives the total number of characters in the token.  Some token types,such as \fBTCL_TOKEN_WORD\fR and \fBTCL_TOKEN_VARIABLE\fR, consist ofseveral component tokens, which immediately follow the parent token;the \fInumComponents\fR field describes how many of these there are.The \fItype\fR field has one of the following values:.TP 20\fBTCL_TOKEN_WORD\fRThis token ordinarily describes one word of a commandbut it may also describe a quoted or braced string in an expression.The token describes a component of the script that isthe result of concatenating together a sequence of subcomponents,each described by a separate subtoken.The token starts with the first non-blankcharacter of the component (which may be a double-quote or open brace)and includes all characters in the component up to but not including thespace, semicolon, close bracket, close quote, or close brace thatterminates the component.  The \fInumComponents\fR field counts the totalnumber of sub-tokens that make up the word, including sub-tokensof \fBTCL_TOKEN_VARIABLE\fR and \fBTCL_TOKEN_BS\fR tokens..TP\fBTCL_TOKEN_SIMPLE_WORD\fRThis token has the same meaning as \fBTCL_TOKEN_WORD\fR, except thatthe word is guaranteed to consist of a single \fBTCL_TOKEN_TEXT\fRsub-token.  The \fInumComponents\fR field is always 1..TP\fBTCL_TOKEN_TEXT\fRThe token describes a range of literal text that is part of a word.The \fInumComponents\fR field is always 0..TP\fBTCL_TOKEN_BS\fRThe token describes a backslash sequence such as \fB\en\fR or \fB\e0xa3\fR.The \fInumComponents\fR field is always 0..TP\fBTCL_TOKEN_COMMAND\fRThe token describes a command whose result result must be substituted intothe word.  The token includes the square brackets that surround thecommand.  The \fInumComponents\fR field is always 0 (the nested commandis not parsed; call \fBTcl_ParseCommand\fR recursively if you want tosee its tokens)..TP\fBTCL_TOKEN_VARIABLE\fRThe token describes a variable substitution, including the\fB$\fR, variable name, and array index (if there is one) up through theclose parenthesis that terminates the index.  This token is followedby one or more additional tokens that describe the variable name andarray index.  If \fInumComponents\fR  is 1 then the variable is ascalar and the next token is a \fBTCL_TOKEN_TEXT\fR token that gives thevariable name.  If \fInumComponents\fR is greater than 1 then thevariable is an array: the first sub-token is a \fBTCL_TOKEN_TEXT\fRtoken giving the array name and the remaining sub-tokens are\fBTCL_TOKEN_TEXT\fR, \fBTCL_TOKEN_BS\fR, \fBTCL_TOKEN_COMMAND\fR, and\fBTCL_TOKEN_VARIABLE\fR tokens that must be concatenated to produce thearray index. The \fInumComponents\fR field includes nested sub-tokensthat are part of \fBTCL_TOKEN_VARIABLE\fR tokens in the array index..TP\fBTCL_TOKEN_SUB_EXPR\fRThe token describes one subexpression of an expression(or an entire expression).A subexpression may consist of a valuesuch 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 subexpressionup to but not including the space, brace, close-paren, or bracketthat terminates the subexpression.This token is followed by one or more additional tokensthat describe the subexpression.If the first sub-token after the \fBTCL_TOKEN_SUB_EXPR\fR tokenis a \fBTCL_TOKEN_OPERATOR\fR token,the subexpression consists of an operator and its token operands.If the operator has no operands, the subexpression consists ofjust the \fBTCL_TOKEN_OPERATOR\fR token.Each operand is described by a \fBTCL_TOKEN_SUB_EXPR\fR token.Otherwise, the subexpression is a value described byone of the token types \fBTCL_TOKEN_WORD\fR, \fBTCL_TOKEN_TEXT\fR,\fBTCL_TOKEN_BS\fR, \fBTCL_TOKEN_COMMAND\fR, \fBTCL_TOKEN_VARIABLE\fR, and \fBTCL_TOKEN_SUB_EXPR\fR.The \fInumComponents\fR fieldcounts the total number of sub-tokens that make up the subexpression;this includes the sub-tokens for any nested \fBTCL_TOKEN_SUB_EXPR\fR tokens..TP\fBTCL_TOKEN_OPERATOR\fRThe token describes one operator of an expressionsuch as \fB&&\fR or \fBhypot\fR.An \fBTCL_TOKEN_OPERATOR\fR token is always preceded by a\fBTCL_TOKEN_SUB_EXPR\fR tokenthat describes the operator and its operands;the \fBTCL_TOKEN_SUB_EXPR\fR token's \fInumComponents\fR fieldcan be used to determine the number of operands.A binary operator such as \fB*\fRis followed by two \fBTCL_TOKEN_SUB_EXPR\fR tokensthat describe its operands.A unary operator like \fB-\fRis followed by a single \fBTCL_TOKEN_SUB_EXPR\fR tokenfor its operand.If the operator is a math function such as \fBlog10\fR,the \fBTCL_TOKEN_OPERATOR\fR token will give its name andthe following \fBTCL_TOKEN_SUB_EXPR\fR tokens will describeits operands;if there are no operands (as with \fBrand\fR),no \fBTCL_TOKEN_SUB_EXPR\fR tokens follow.There is one trinary operator, \fB?\fR,that appears in if-then-else subexpressionssuch as \fIx\fB?\fIy\fB:\fIz\fR;in this case, the \fB?\fR \fBTCL_TOKEN_OPERATOR\fR tokenis followed by three \fBTCL_TOKEN_SUB_EXPR\fR tokens for the operands\fIx\fR, \fIy\fR, and \fIz\fR.The \fInumComponents\fR field for a \fBTCL_TOKEN_OPERATOR\fR tokenis always 0..PPAfter \fBTcl_ParseCommand\fR returns, the first token pointed to bythe \fItokenPtr\fR field of theTcl_Parse structure always has type \fBTCL_TOKEN_WORD\fR or\fBTCL_TOKEN_SIMPLE_WORD\fR.  It is followed by the sub-tokensthat must be concatenated to produce the value of that word.The next token is the \fBTCL_TOKEN_WORD\fR or \fBTCL_TOKEN_SIMPLE_WORD\fRtoken for the second word, followed by sub-tokens for thatword, and so on until all \fInumWords\fR have been accountedfor..PPAfter \fBTcl_ParseExpr\fR returns, the first token pointed to bythe \fItokenPtr\fR field of theTcl_Parse structure always has type \fBTCL_TOKEN_SUB_EXPR\fR.It is followed by the sub-tokens that must be evaluatedto produce the value of the expression.Only the token information in the Tcl_Parse structureis modified: the \fIcommentStart\fR, \fIcommentSize\fR,\fIcommandStart\fR, and \fIcommandSize\fR fields are not modifiedby \fBTcl_ParseExpr\fR..PPAfter \fBTcl_ParseBraces\fR returns,the array of tokens pointed to by the \fItokenPtr\fR field of theTcl_Parse structure will contain a single \fBTCL_TOKEN_TEXT\fR tokenif the braced string does not contain any backslash-newlines.If the string does contain backslash-newlines,the array of tokens will contain one or more\fBTCL_TOKEN_TEXT\fR or \fBTCL_TOKEN_BS\fR sub-tokensthat must be concatenated to produce the value of the string.If the braced string was just \fB{}\fR(that is, the string was empty),the single \fBTCL_TOKEN_TEXT\fR token will have a \fIsize\fR fieldcontaining zero;this ensures that at least one token appearsto describe the braced string.Only the token information in the Tcl_Parse structureis modified: the \fIcommentStart\fR, \fIcommentSize\fR,\fIcommandStart\fR, and \fIcommandSize\fR fields are not modifiedby \fBTcl_ParseBraces\fR..PPAfter \fBTcl_ParseQuotedString\fR returns,the array of tokens pointed to by the \fItokenPtr\fR field of theTcl_Parse structure depends on the contents of the quoted string.It will consist of one or more \fBTCL_TOKEN_TEXT\fR, \fBTCL_TOKEN_BS\fR,\fBTCL_TOKEN_COMMAND\fR, and \fBTCL_TOKEN_VARIABLE\fR sub-tokens.The array always contains at least one token;for example, if the argument \fIstring\fR is empty,the array returned consists of a single \fBTCL_TOKEN_TEXT\fR tokenwith a zero \fIsize\fR field.Only the token information in the Tcl_Parse structureis modified: the \fIcommentStart\fR, \fIcommentSize\fR,\fIcommandStart\fR, and \fIcommandSize\fR fields are not modified..PPAfter \fBTcl_ParseVarName\fR returns, the first token pointed to bythe \fItokenPtr\fR field of theTcl_Parse structure always has type \fBTCL_TOKEN_VARIABLE\fR.  Itis followed by the sub-tokens that make up the variable name asdescribed above.  The total length of the variable name iscontained in the \fIsize\fR field of the first token.As in \fBTcl_ParseExpr\fR,only the token information in the Tcl_Parse structureis modified by \fBTcl_ParseVarName\fR:the \fIcommentStart\fR, \fIcommentSize\fR,\fIcommandStart\fR, and \fIcommandSize\fR fields are not modified..PPAll of the character pointers in theTcl_Parse and Tcl_Token structures referto characters in the \fIstring\fR argument passed to\fBTcl_ParseCommand\fR, \fBTcl_ParseExpr\fR, \fBTcl_ParseBraces\fR,\fBTcl_ParseQuotedString\fR, and \fBTcl_ParseVarName\fR..PPThere are additional fields in the Tcl_Parse structure after the\fInumTokens\fR field, but these are for the private use of\fBTcl_ParseCommand\fR, \fBTcl_ParseExpr\fR, \fBTcl_ParseBraces\fR,\fBTcl_ParseQuotedString\fR, and \fBTcl_ParseVarName\fR; they should not bereferenced by code outside of these procedures..SH KEYWORDSbackslash substitution, braces, command, expression, parse, token, variable substitution

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -