From 0b0194b0a2fcb21e5ec1b00ee76339a34ddc9ebe Mon Sep 17 00:00:00 2001 From: gavinking Date: Fri, 14 Nov 2014 10:55:37 -0300 Subject: [PATCH] fix spans for if expressions, fixing IDE bugs #3609 --- typechecker/Ceylon.g | 29 ++++++++++++++++++----------- 1 file changed, 18 insertions(+), 11 deletions(-) diff --git a/typechecker/Ceylon.g b/typechecker/Ceylon.g index be1d8a8b303..b5b39f2ae0b 100644 --- a/typechecker/Ceylon.g +++ b/typechecker/Ceylon.g @@ -2091,26 +2091,33 @@ defaultCaseExpression returns [ElseClause clause] ifExpression returns [IfExpression term] : IF_CLAUSE - { $term = new IfExpression(null); - IfClause ic = new IfClause($IF_CLAUSE); - ElseClause ec = new ElseClause(null); - $term.setIfClause(ic); - $term.setElseClause(ec); } - conditions - { $term.getIfClause().setConditionList($conditions.conditionList); } + { $term = new IfExpression($IF_CLAUSE); } + thenElseClauses + { $term.setIfClause($thenElseClauses.ifClause); + $term.setElseClause($thenElseClauses.elseClause); + if ($thenElseClauses.ifClause==null && $thenElseClauses.conditionList!=null) + $term.setIfClause(new IfClause(null)); + $term.getIfClause().setConditionList($thenElseClauses.conditionList); } + ; + +thenElseClauses returns [IfClause ifClause, ElseClause elseClause, ConditionList conditionList] + : conditions + { $conditionList = $conditions.conditionList; } ( THEN_CLAUSE + { $ifClause = new IfClause($THEN_CLAUSE); } de1=disjunctionExpression - { Expression e = new Expression($THEN_CLAUSE); + { Expression e = new Expression(null); e.setTerm($de1.term); - $term.getIfClause().setExpression(e); } + $ifClause.setExpression(e); } )? ( ELSE_CLAUSE + { $elseClause = new ElseClause($ELSE_CLAUSE); } de2=disjunctionExpression - { Expression e = new Expression($ELSE_CLAUSE); + { Expression e = new Expression(null); e.setTerm($de2.term); - $term.getElseClause().setExpression(e); } + $elseClause.setExpression(e); } )? ;