1) Fixed issue #844: Short form of ternary operator (since PHP 5.3).
authorrobekras <robert.kraske@weihenstephan.org>
Sun, 9 Dec 2012 20:04:05 +0000 (21:04 +0100)
committerrobekras <robert.kraske@weihenstephan.org>
Sun, 9 Dec 2012 20:04:12 +0000 (21:04 +0100)
Signed-off-by: robekras <robert.kraske@weihenstephan.org>

net.sourceforge.phpeclipse/src/net/sourceforge/phpdt/core/compiler/ITerminalSymbols.java
net.sourceforge.phpeclipse/src/net/sourceforge/phpdt/internal/compiler/ast/OperatorIds.java
net.sourceforge.phpeclipse/src/net/sourceforge/phpdt/internal/compiler/parser/Parser.java
net.sourceforge.phpeclipse/src/net/sourceforge/phpdt/internal/compiler/parser/Scanner.java

index 117ee33..5a3e479 100644 (file)
@@ -69,6 +69,7 @@ public interface ITerminalSymbols {
            AND_EQUAL,
            OR_EQUAL,
            QUESTION,
+           TERNARY_SHORT,
            PAAMAYIM_NEKUDOTAYIM,
            DOLLAR,
            DOLLAR_LBRACE,
index 879e101..3a427af 100644 (file)
@@ -64,4 +64,6 @@ public interface OperatorIds {
        public static final int PLUS_PLUS = 32;
 
        public static final int MINUS_MINUS = 33;
+       
+       public static final int TERNARY_SHORT = 34;
 }
index 98c996d..121754c 100644 (file)
@@ -3059,13 +3059,13 @@ public class Parser implements ITerminalSymbols, CompilerModifiers,
                                                        if (rememberedVar == false && lhs != null
                                                                        && lhs instanceof FieldReference) {
                                                                if (fMethodVariables != null) {
-                                                                       VariableInfo lhsInfo = new VariableInfo(
-                                                                                       ((FieldReference) lhs).sourceStart);
-                                                                       fMethodVariables.put(new String(
-                                                                                       ((FieldReference) lhs).token), lhsInfo);
+                                                                       VariableInfo lhsInfo = new VariableInfo (((FieldReference) lhs).sourceStart);
+                                                                       fMethodVariables.put (new String (((FieldReference) lhs).token), lhsInfo);
                                                                }
                                                        }
                                                        break;
+                                                       
+                                               case TERNARY_SHORT:
                                                case PLUS_EQUAL:
                                                case MINUS_EQUAL:
                                                case MULTIPLY_EQUAL:
@@ -3270,6 +3270,12 @@ public class Parser implements ITerminalSymbols, CompilerModifiers,
                                                        expression.sourceEnd = scanner.getCurrentTokenEndPosition();
                                                }
                                                break;
+
+                                       case TERNARY_SHORT:
+                                               getNextToken();
+                                               expression = new EqualExpression(expression, expr_without_variable (only_variable, initHandler, bColonAllowed), OperatorIds.TERNARY_SHORT);
+                                               break;
+                                               
                                        case QUESTION:
                                                getNextToken();
                                                Expression valueIfTrue = expr_without_variable (true, null, true);
@@ -3279,8 +3285,7 @@ public class Parser implements ITerminalSymbols, CompilerModifiers,
                                                getNextToken();
                                                Expression valueIfFalse = expr();
 
-                                               expression = new ConditionalExpression(expression,
-                                                               valueIfTrue, valueIfFalse);
+                                               expression = new ConditionalExpression (expression, valueIfTrue, valueIfFalse);
                                                break;
                                        default:
                                                return expression;
index c390b61..20039eb 100644 (file)
@@ -1653,7 +1653,12 @@ public class Scanner implements IScanner, ITerminalSymbols {
                                                        }
                                                        return getInlinedHTMLToken(currentPosition - 2);
                                                }
+                                               else if (getNextChar(':')) {
+                                                       return TokenName.TERNARY_SHORT;
+                                               }
+                                               
                                                return TokenName.QUESTION;
+                                               
                                        case ':':
                                                if (getNextChar(':'))
                                                        return TokenName.PAAMAYIM_NEKUDOTAYIM;