From 56e0e6be62e43a0ca2dbbbd66dfebe4264b86ed4 Mon Sep 17 00:00:00 2001 From: robekras Date: Sun, 9 Dec 2012 21:04:05 +0100 Subject: [PATCH 1/1] 1) Fixed issue #844: Short form of ternary operator (since PHP 5.3). Signed-off-by: robekras --- .../phpdt/core/compiler/ITerminalSymbols.java | 1 + .../phpdt/internal/compiler/ast/OperatorIds.java | 2 ++ .../phpdt/internal/compiler/parser/Parser.java | 17 +++++++++++------ .../phpdt/internal/compiler/parser/Scanner.java | 5 +++++ 4 files changed, 19 insertions(+), 6 deletions(-) diff --git a/net.sourceforge.phpeclipse/src/net/sourceforge/phpdt/core/compiler/ITerminalSymbols.java b/net.sourceforge.phpeclipse/src/net/sourceforge/phpdt/core/compiler/ITerminalSymbols.java index 117ee33..5a3e479 100644 --- a/net.sourceforge.phpeclipse/src/net/sourceforge/phpdt/core/compiler/ITerminalSymbols.java +++ b/net.sourceforge.phpeclipse/src/net/sourceforge/phpdt/core/compiler/ITerminalSymbols.java @@ -69,6 +69,7 @@ public interface ITerminalSymbols { AND_EQUAL, OR_EQUAL, QUESTION, + TERNARY_SHORT, PAAMAYIM_NEKUDOTAYIM, DOLLAR, DOLLAR_LBRACE, diff --git a/net.sourceforge.phpeclipse/src/net/sourceforge/phpdt/internal/compiler/ast/OperatorIds.java b/net.sourceforge.phpeclipse/src/net/sourceforge/phpdt/internal/compiler/ast/OperatorIds.java index 879e101..3a427af 100644 --- a/net.sourceforge.phpeclipse/src/net/sourceforge/phpdt/internal/compiler/ast/OperatorIds.java +++ b/net.sourceforge.phpeclipse/src/net/sourceforge/phpdt/internal/compiler/ast/OperatorIds.java @@ -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; } diff --git a/net.sourceforge.phpeclipse/src/net/sourceforge/phpdt/internal/compiler/parser/Parser.java b/net.sourceforge.phpeclipse/src/net/sourceforge/phpdt/internal/compiler/parser/Parser.java index 98c996d..121754c 100644 --- a/net.sourceforge.phpeclipse/src/net/sourceforge/phpdt/internal/compiler/parser/Parser.java +++ b/net.sourceforge.phpeclipse/src/net/sourceforge/phpdt/internal/compiler/parser/Parser.java @@ -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; diff --git a/net.sourceforge.phpeclipse/src/net/sourceforge/phpdt/internal/compiler/parser/Scanner.java b/net.sourceforge.phpeclipse/src/net/sourceforge/phpdt/internal/compiler/parser/Scanner.java index c390b61..20039eb 100644 --- a/net.sourceforge.phpeclipse/src/net/sourceforge/phpdt/internal/compiler/parser/Scanner.java +++ b/net.sourceforge.phpeclipse/src/net/sourceforge/phpdt/internal/compiler/parser/Scanner.java @@ -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; -- 1.7.1