From dbe276f19cda99c192113adf6d2ad6db94ac2d2e Mon Sep 17 00:00:00 2001 From: Peter Bortas <bortas@gmail.com> Date: Sun, 3 Nov 2019 19:42:17 +0100 Subject: [PATCH] Add "->?" as the safe indexing variant of "->" This was earlier covered by "?->", but this is inconsistent with the "[?" index variant and the future "(?" program indexing variant. Usage of "?->" will start emitting a deprication warning is some future major version of Pike. Manual backport from master: 19582df85018fdb488de25c340bfa1efc44becd0, because the conflict was too big to bother with cherry-pick. --- src/language.yacc | 2 +- src/lexer.h | 19 ++++++------------- 2 files changed, 7 insertions(+), 14 deletions(-) diff --git a/src/language.yacc b/src/language.yacc index 9d60bf5296..13cc967174 100644 --- a/src/language.yacc +++ b/src/language.yacc @@ -3755,7 +3755,7 @@ expr4: string } | expr4 TOK_SAFE_INDEX line_number_info TOK_IDENTIFIER { - /* A?->B to ((tmp=A) && tmp->B) */ + /* A->?B to ((tmp=A) && tmp->B) */ int temporary; if( $1 && ($1->token == F_LOCAL) ) { diff --git a/src/lexer.h b/src/lexer.h index 833dbf50d6..7bb5f8bb0f 100644 --- a/src/lexer.h +++ b/src/lexer.h @@ -1062,7 +1062,11 @@ unknown_directive: case '-': if(GOBBLE('=')) return TOK_SUB_EQ; - if(GOBBLE('>')) return TOK_ARROW; + if(GOBBLE('>')) + if(GOBBLE('?') ) /* ->? */ + return TOK_SAFE_INDEX; + else + return TOK_ARROW; if(GOBBLE('-')) return TOK_DEC; return '-'; @@ -1132,24 +1136,13 @@ unknown_directive: if(GOBBLE(':')) return TOK_LOR; - if(GOBBLE('-') ) /* safe index: ?-> or ?[] */ + if(GOBBLE('-') ) /* old safe index: ?->, depreceated in 8.1+ */ { if( GOBBLE( '>' ) ) /* ?-> */ return TOK_SAFE_INDEX; SKIPN(-1); /* Undo GOBBLE('-') above */ } - /* Probably wanted: - - ?. for safe constant index - ?[] for safe [] index - - They however conflict with valid ?: syntaxes. - */ - - /* if( GOBBLE('.' ) ) */ - /* return TOK_SAFE_INDEX; */ - case ']': case ',': case '~': -- GitLab