diff options
author | dkf <donal.k.fellows@manchester.ac.uk> | 2020-08-22 14:14:05 (GMT) |
---|---|---|
committer | dkf <donal.k.fellows@manchester.ac.uk> | 2020-08-22 14:14:05 (GMT) |
commit | 42a34d459e99c9e366e626e134d3e75e74e1f191 (patch) | |
tree | 65e81238673688720cb767c89c47f23c22dca5aa /generic | |
parent | 5dfe6151b2c83fac63e73c24a45797c938c2fa5b (diff) | |
download | tcl-42a34d459e99c9e366e626e134d3e75e74e1f191.zip tcl-42a34d459e99c9e366e626e134d3e75e74e1f191.tar.gz tcl-42a34d459e99c9e366e626e134d3e75e74e1f191.tar.bz2 |
Implementation of TIP 582: comments in expressions
Diffstat (limited to 'generic')
-rw-r--r-- | generic/tclCompExpr.c | 20 |
1 files changed, 18 insertions, 2 deletions
diff --git a/generic/tclCompExpr.c b/generic/tclCompExpr.c index 74610c7..5c5a491 100644 --- a/generic/tclCompExpr.c +++ b/generic/tclCompExpr.c @@ -164,6 +164,8 @@ enum Marks { * "=" is encountered. */ #define INVALID 5 /* A parse error. Used when any punctuation * appears that's not a supported operator. */ +#define COMMENT 6 /* Comment. Lasts to end of line or end of + * expression, whichever comes first. */ /* Leaf lexemes */ @@ -462,7 +464,7 @@ static const unsigned char Lexeme[] = { INVALID /* FS */, INVALID /* GS */, INVALID /* RS */, INVALID /* US */, INVALID /* SPACE */, 0 /* ! or != */, - QUOTED /* " */, INVALID /* # */, + QUOTED /* " */, 0 /* # */, VARIABLE /* $ */, MOD /* % */, 0 /* & or && */, INVALID /* ' */, OPEN_PAREN /* ( */, CLOSE_PAREN /* ) */, @@ -708,6 +710,10 @@ ParseExpr( int b; switch (lexeme) { + case COMMENT: + start += scanned; + numBytes -= scanned; + continue; case INVALID: msg = Tcl_ObjPrintf("invalid character \"%.*s\"", scanned, start); @@ -1892,7 +1898,7 @@ ParseLexeme( storage, if non-NULL. */ { const char *end; - int scanned; + int scanned, size; Tcl_UniChar ch = 0; Tcl_Obj *literal = NULL; unsigned char byte; @@ -1907,6 +1913,16 @@ ParseLexeme( return 1; } switch (byte) { + case '#': + /* + * Scan forward over the comment contents. + */ + for (size = 0; byte != '\n' && byte != 0 && size < numBytes; size++) { + byte = UCHAR(start[size]); + } + *lexemePtr = COMMENT; + return size - (byte == '\n'); + case '*': if ((numBytes > 1) && (start[1] == '*')) { *lexemePtr = EXPON; |