From 19582df85018fdb488de25c340bfa1efc44becd0 Mon Sep 17 00:00:00 2001
From: Peter Bortas <bortas@gmail.com>
Date: Sat, 2 Nov 2019 20:41:59 +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.
---
 src/language.yacc |  4 ++--
 src/lexer.h       | 24 +++++++++---------------
 2 files changed, 11 insertions(+), 17 deletions(-)

diff --git a/src/language.yacc b/src/language.yacc
index ffc29194d3..0acfd26da9 100644
--- a/src/language.yacc
+++ b/src/language.yacc
@@ -112,7 +112,7 @@
 %token TOK_WHILE "while"
 %token TOK_XOR_EQ "^="
 %token TOK_OPTIONAL "optional"
-%token TOK_SAFE_INDEX "?->"
+%token TOK_SAFE_INDEX "->?"
 %token TOK_SAFE_START_INDEX "[?"
 %token TOK_BITS "bits"
 %token TOK_AUTO_ID "auto"
@@ -4227,7 +4227,7 @@ expr5: literal_expr
   }
   | 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 9b47ba85ee..139a80850a 100644
--- a/src/lexer.h
+++ b/src/lexer.h
@@ -1096,7 +1096,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 '-';
 
@@ -1171,24 +1175,14 @@ unknown_directive:
       if(GOBBLE(':'))
         return TOK_LOR;
 
-      if(GOBBLE('-') ) /* safe index: ?->  or ?[] */
+      if(GOBBLE('-') )
       {
-        if( GOBBLE( '>' ) ) /* ?-> */
-            return TOK_SAFE_INDEX;
+        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; */
-
       /* FALLTHRU */
 
     case ']':
-- 
GitLab