Skip to content
This repository has been archived by the owner on Apr 13, 2023. It is now read-only.

Commit

Permalink
let expressions #3853
Browse files Browse the repository at this point in the history
  • Loading branch information
gavinking committed Oct 26, 2014
1 parent 05f6bf6 commit 58fa480
Show file tree
Hide file tree
Showing 3 changed files with 55 additions and 9 deletions.
49 changes: 40 additions & 9 deletions typechecker/Ceylon.g
Original file line number Diff line number Diff line change
Expand Up @@ -1955,6 +1955,37 @@ functionOrExpression returns [Expression expression]
$expression.setTerm($f.function); }
| e=expression
{ $expression = $e.expression; }
| l=let
{ $expression = new Expression(null);
$expression.setTerm($l.let); }
;
let returns [LetExpression let]
@init { LetClause lc=null; }
: LET
{ $let = new LetExpression(null);
lc = new LetClause($LET);
$let.setLetClause(lc); }
LPAREN
{ lc.setEndToken($LPAREN); }
(
v1=specifiedVariable
{ lc.setEndToken(null);
lc.addVariable($v1.variable); }
(
COMMA
{ lc.setEndToken($COMMA); }
v2=specifiedVariable
{ lc.setEndToken(null);
lc.addVariable($v2.variable); }
)*
)?
RPAREN
{ lc.setEndToken($RPAREN); }
disjunctionExpression
{ Expression e = new Expression(null);
e.setTerm($disjunctionExpression.term);
lc.setExpression(e); }
;
anonymousFunction returns [FunctionArgument function]
Expand Down Expand Up @@ -3282,15 +3313,15 @@ resources returns [ResourceList resources]
: LPAREN
{ $resources = new ResourceList($LPAREN); }
(
r1=resource
{ $resources.addResource($r1.resource); }
(
c=COMMA
{ $resources.setEndToken($c); }
r2=resource
{ $resources.addResource($r2.resource);
$resources.setEndToken(null); }
)*
r1=resource
{ $resources.addResource($r1.resource); }
(
c=COMMA
{ $resources.setEndToken($c); }
r2=resource
{ $resources.addResource($r2.resource);
$resources.setEndToken(null); }
)*
)?
RPAREN
{ $resources.setEndToken($RPAREN); }
Expand Down
6 changes: 6 additions & 0 deletions typechecker/Ceylon.nodes
Original file line number Diff line number Diff line change
Expand Up @@ -409,6 +409,12 @@
^(DYNAMIC_CLAUSE:CONTROL_CLAUSE
BLOCK?)

^(LET_EXPRESSION:TERM
LET_CLAUSE)
^(LET_CLAUSE:CONTROL_CLAUSE
VARIABLE*
EXPRESSION)

^(IF_STATEMENT:CONTROL_STATEMENT
IF_CLAUSE
ELSE_CLAUSE?)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@
import com.redhat.ceylon.compiler.typechecker.model.Value;
import com.redhat.ceylon.compiler.typechecker.tree.Node;
import com.redhat.ceylon.compiler.typechecker.tree.Tree;
import com.redhat.ceylon.compiler.typechecker.tree.Tree.Expression;
import com.redhat.ceylon.compiler.typechecker.tree.Tree.ImportPath;
import com.redhat.ceylon.compiler.typechecker.tree.Tree.PositionalArgument;
import com.redhat.ceylon.compiler.typechecker.tree.Tree.TypeVariance;
Expand Down Expand Up @@ -4330,6 +4331,14 @@ else if (that instanceof Tree.RemainderAssignOp) {
visitInOperator(that);
}

@Override public void visit(Tree.LetExpression that) {
super.visit(that);
Tree.Expression e = that.getLetClause().getExpression();
if (e!=null) {
that.setTypeModel(e.getTypeModel());
}
}

@Override
public void visit(Tree.BaseType that) {
super.visit(that);
Expand Down

0 comments on commit 58fa480

Please sign in to comment.