Skip to content

Commit

Permalink
support for => in named arg lists to fix #466
Browse files Browse the repository at this point in the history
  • Loading branch information
gavinking committed Dec 9, 2012
1 parent 5175387 commit bd2b94e
Show file tree
Hide file tree
Showing 7 changed files with 329 additions and 42 deletions.
94 changes: 80 additions & 14 deletions Ceylon.g
Expand Up @@ -1528,10 +1528,10 @@ sequencedArgument returns [SequencedArgument sequencedArgument]
namedArgument returns [NamedArgument namedArgument] namedArgument returns [NamedArgument namedArgument]
: compilerAnnotations : compilerAnnotations
( (
namedSpecifiedArgument namedSpecifiedArgument
{ $namedArgument = $namedSpecifiedArgument.specifiedArgument; } { $namedArgument = $namedSpecifiedArgument.specifiedArgument; }
| |
namedArgumentDeclaration namedArgumentDeclaration
{ $namedArgument = $namedArgumentDeclaration.declaration; } { $namedArgument = $namedArgumentDeclaration.declaration; }
) )
Expand All @@ -1540,11 +1540,14 @@ namedArgument returns [NamedArgument namedArgument]
; ;
namedSpecifiedArgument returns [SpecifiedArgument specifiedArgument] namedSpecifiedArgument returns [SpecifiedArgument specifiedArgument]
: memberNameDeclaration : memberName
{ $specifiedArgument = new SpecifiedArgument(null); { $specifiedArgument = new SpecifiedArgument(null);
$specifiedArgument.setIdentifier($memberNameDeclaration.identifier); } $specifiedArgument.setIdentifier($memberName.identifier); }
specifier (
{ $specifiedArgument.setSpecifierExpression($specifier.specifierExpression); } specifier
{ $specifiedArgument.setSpecifierExpression($specifier.specifierExpression); }
)?
{ expecting=SEMICOLON; }
SEMICOLON SEMICOLON
{ $specifiedArgument.setEndToken($SEMICOLON); } { $specifiedArgument.setEndToken($SEMICOLON); }
; ;
Expand Down Expand Up @@ -1589,8 +1592,19 @@ voidOrInferredMethodArgument returns [MethodArgument declaration]
parameters parameters
{ $declaration.addParameterList($parameters.parameterList); } { $declaration.addParameterList($parameters.parameterList); }
)* )*
block (
{ $declaration.setBlock($block.block); } block
{ $declaration.setBlock($block.block); }
|
(
lazySpecifier
{ $declaration.setSpecifierExpression($lazySpecifier.specifierExpression); }
)?
{ expecting=SEMICOLON; }
SEMICOLON
{ expecting=-1; }
{ $declaration.setEndToken($SEMICOLON); }
)
//-> ^(METHOD_ARGUMENT VOID_MODIFIER memberName parameters* block) //-> ^(METHOD_ARGUMENT VOID_MODIFIER memberName parameters* block)
; ;
Expand All @@ -1600,8 +1614,19 @@ inferredGetterArgument returns [AttributeArgument declaration]
{ $declaration.setType(new ValueModifier($VALUE_MODIFIER)); } { $declaration.setType(new ValueModifier($VALUE_MODIFIER)); }
memberNameDeclaration memberNameDeclaration
{ $declaration.setIdentifier($memberNameDeclaration.identifier); } { $declaration.setIdentifier($memberNameDeclaration.identifier); }
block (
{ $declaration.setBlock($block.block); } block
{ $declaration.setBlock($block.block); }
|
(
lazySpecifier
{ $declaration.setSpecifierExpression($lazySpecifier.specifierExpression); }
)?
{ expecting=SEMICOLON; }
SEMICOLON
{ expecting=-1; }
{ $declaration.setEndToken($SEMICOLON); }
)
//-> ^(ATTRIBUTE_ARGUMENT VALUE_MODIFIER memberName block) //-> ^(ATTRIBUTE_ARGUMENT VALUE_MODIFIER memberName block)
; ;
Expand All @@ -1622,9 +1647,48 @@ typedMethodOrGetterArgument returns [TypedArgument declaration]
{ marg.addParameterList($parameters.parameterList); } { marg.addParameterList($parameters.parameterList); }
)+ )+
)? )?
block (
{ marg.setBlock($block.block); block
aarg.setBlock($block.block); } { marg.setBlock($block.block);
aarg.setBlock($block.block); }
|
(
lazySpecifier
{ marg.setSpecifierExpression($lazySpecifier.specifierExpression);
aarg.setSpecifierExpression($lazySpecifier.specifierExpression); }
)?
{ expecting=SEMICOLON; }
SEMICOLON
{ expecting=-1; }
{ $declaration.setEndToken($SEMICOLON); }
)
//-> ^(METHOD_ARGUMENT unionType memberName parameters+ memberBody)
//-> ^(ATTRIBUTE_ARGUMENT unionType memberName memberBody)
;
untypedMethodOrGetterArgument returns [TypedArgument declaration]
@init { MethodArgument marg = new MethodArgument(null);
marg.setType(new FunctionModifier(null));
AttributeArgument aarg = new AttributeArgument(null);
aarg.setType(new ValueModifier(null));
$declaration=aarg; }
: memberName
{ marg.setIdentifier($memberName.identifier);
aarg.setIdentifier($memberName.identifier); }
(
{ $declaration = marg; }
(
parameters
{ marg.addParameterList($parameters.parameterList); }
)+
)?
lazySpecifier
{ marg.setSpecifierExpression($lazySpecifier.specifierExpression);
aarg.setSpecifierExpression($lazySpecifier.specifierExpression); }
{ expecting=SEMICOLON; }
SEMICOLON
{ expecting=-1; }
{ $declaration.setEndToken($SEMICOLON); }
//-> ^(METHOD_ARGUMENT unionType memberName parameters+ memberBody) //-> ^(METHOD_ARGUMENT unionType memberName parameters+ memberBody)
//-> ^(ATTRIBUTE_ARGUMENT unionType memberName memberBody) //-> ^(ATTRIBUTE_ARGUMENT unionType memberName memberBody)
; ;
Expand All @@ -1638,6 +1702,8 @@ namedArgumentDeclaration returns [NamedArgument declaration]
{ $declaration=$voidOrInferredMethodArgument.declaration; } { $declaration=$voidOrInferredMethodArgument.declaration; }
| inferredGetterArgument | inferredGetterArgument
{ $declaration=$inferredGetterArgument.declaration; } { $declaration=$inferredGetterArgument.declaration; }
| untypedMethodOrGetterArgument
{ $declaration=$untypedMethodOrGetterArgument.declaration; }
; ;
//special rule for syntactic predicate //special rule for syntactic predicate
Expand All @@ -1658,7 +1724,7 @@ iterableArgumentStart
//special rule for syntactic predicates //special rule for syntactic predicates
specificationStart specificationStart
: LIDENTIFIER (SPECIFY|COMPUTE) : LIDENTIFIER parameters* (SPECIFY|COMPUTE)
; ;
parExpression returns [Expression expression] parExpression returns [Expression expression]
Expand Down
8 changes: 5 additions & 3 deletions Ceylon.nodes
Expand Up @@ -608,7 +608,7 @@ argument list."
EXPRESSION EXPRESSION
Parameter parameter;) Parameter parameter;)


^(FUNCTION_ARGUMENT: TERM ^(FUNCTION_ARGUMENT:TERM
TYPE type TYPE type
PARAMETER_LIST* PARAMETER_LIST*
EXPRESSION EXPRESSION
Expand All @@ -624,10 +624,12 @@ argument list."
abstract TypedDeclaration declarationModel;) abstract TypedDeclaration declarationModel;)
^(METHOD_ARGUMENT:TYPED_ARGUMENT ^(METHOD_ARGUMENT:TYPED_ARGUMENT
PARAMETER_LIST* PARAMETER_LIST*
BLOCK BLOCK?
SPECIFIER_EXPRESSION?
Method declarationModel;) Method declarationModel;)
^(ATTRIBUTE_ARGUMENT:TYPED_ARGUMENT ^(ATTRIBUTE_ARGUMENT:TYPED_ARGUMENT
BLOCK BLOCK?
SPECIFIER_EXPRESSION?
Getter declarationModel;) Getter declarationModel;)
^(OBJECT_ARGUMENT:TYPED_ARGUMENT ^(OBJECT_ARGUMENT:TYPED_ARGUMENT
EXTENDED_TYPE? EXTENDED_TYPE?
Expand Down
Expand Up @@ -100,12 +100,17 @@ public void visit(Tree.AttributeGetterDefinition that) {


@Override @Override
public void visit(Tree.AttributeArgument that) { public void visit(Tree.AttributeArgument that) {
boolean c = beginReturnScope(true); if (that.getSpecifierExpression()==null) {
boolean d = beginDefiniteReturnScope(); boolean c = beginReturnScope(true);
super.visit(that); boolean d = beginDefiniteReturnScope();
checkDefiniteReturn(that, name(that.getIdentifier())); super.visit(that);
endDefiniteReturnScope(d); checkDefiniteReturn(that, name(that.getIdentifier()));
endReturnScope(c); endDefiniteReturnScope(d);
endReturnScope(c);
}
else {
super.visit(that);
}
} }


private void checkDefiniteReturn(Node that, String name) { private void checkDefiniteReturn(Node that, String name) {
Expand Down Expand Up @@ -137,14 +142,19 @@ public void visit(Tree.MethodDefinition that) {


@Override @Override
public void visit(Tree.MethodArgument that) { public void visit(Tree.MethodArgument that) {
boolean c = beginReturnScope(true); if (that.getSpecifierExpression()==null) {
boolean d = beginDefiniteReturnScope(); boolean c = beginReturnScope(true);
super.visit(that); boolean d = beginDefiniteReturnScope();
if (!(that.getType() instanceof Tree.VoidModifier)) { super.visit(that);
checkDefiniteReturn(that, name(that.getIdentifier())); if (!(that.getType() instanceof Tree.VoidModifier)) {
checkDefiniteReturn(that, name(that.getIdentifier()));
}
endDefiniteReturnScope(d);
endReturnScope(c);
}
else {
super.visit(that);
} }
endDefiniteReturnScope(d);
endReturnScope(c);
} }


@Override @Override
Expand All @@ -154,6 +164,9 @@ public void visit(Tree.AttributeDeclaration that) {
checkExecutableStatementAllowed(that.getSpecifierOrInitializerExpression()); checkExecutableStatementAllowed(that.getSpecifierOrInitializerExpression());
super.visit(that); super.visit(that);
} }
else {
super.visit(that);
}
} }


@Override @Override
Expand Down
Expand Up @@ -1009,7 +1009,14 @@ public void visit(Tree.SpecifierStatement that) {
exitScope(o); exitScope(o);
} }



/*@Override
public void visit(Tree.SpecifiedArgument that) {
Specification s = new Specification();
visitElement(that, s);
Scope o = enterScope(s);
super.visit(that);
exitScope(o);
}*/


@Override @Override
public void visit(Tree.SatisfiesCondition that) { public void visit(Tree.SatisfiesCondition that) {
Expand Down
Expand Up @@ -871,11 +871,23 @@ private void checkKeyValueType(Tree.Variable key, Tree.Variable value,
} }


@Override public void visit(Tree.AttributeArgument that) { @Override public void visit(Tree.AttributeArgument that) {
Tree.Type rt = beginReturnScope(that.getType()); Tree.SpecifierExpression se = that.getSpecifierExpression();
Declaration od = beginReturnDeclaration(that.getDeclarationModel()); if (se==null) {
super.visit(that); Tree.Type rt = beginReturnScope(that.getType());
endReturnDeclaration(od); Declaration od = beginReturnDeclaration(that.getDeclarationModel());
endReturnScope(rt, that.getDeclarationModel()); super.visit(that);
endReturnDeclaration(od);
endReturnScope(rt, that.getDeclarationModel());
}
else {
super.visit(that);
inferType(that, se);
if (that.getType()!=null) {
checkType(that.getType().getTypeModel(),
that.getDeclarationModel().getName(),
se, 2100);
}
}
} }


@Override public void visit(Tree.AttributeSetterDefinition that) { @Override public void visit(Tree.AttributeSetterDefinition that) {
Expand Down Expand Up @@ -910,11 +922,25 @@ private void checkKeyValueType(Tree.Variable key, Tree.Variable value,
} }


@Override public void visit(Tree.MethodArgument that) { @Override public void visit(Tree.MethodArgument that) {
Tree.Type rt = beginReturnScope(that.getType()); Tree.SpecifierExpression se = that.getSpecifierExpression();
Declaration od = beginReturnDeclaration(that.getDeclarationModel()); if (se==null) {
super.visit(that); Tree.Type rt = beginReturnScope(that.getType());
endReturnDeclaration(od); Declaration od = beginReturnDeclaration(that.getDeclarationModel());
endReturnScope(rt, that.getDeclarationModel()); super.visit(that);
endReturnDeclaration(od);
endReturnScope(rt, that.getDeclarationModel());
}
else {
super.visit(that);
Tree.Expression e = se.getExpression();
if (e!=null) {
ProducedType returnType = e.getTypeModel();
inferFunctionType(that, returnType);
if (that.getType()!=null) {
checkFunctionType(returnType, that.getType());
}
}
}
} }


@Override public void visit(Tree.ClassDefinition that) { @Override public void visit(Tree.ClassDefinition that) {
Expand Down Expand Up @@ -1005,6 +1031,20 @@ private void inferType(Tree.TypedDeclaration that,
} }
} }


private void inferType(Tree.AttributeArgument that,
Tree.SpecifierOrInitializerExpression spec) {
if (that.getType() instanceof Tree.LocalModifier) {
Tree.LocalModifier local = (Tree.LocalModifier) that.getType();
if (spec!=null) {
setType(local, spec, that);
}
else {
// local.addError("could not infer type of: " +
// name(that.getIdentifier()));
}
}
}

private void inferFunctionType(Tree.TypedDeclaration that, ProducedType et) { private void inferFunctionType(Tree.TypedDeclaration that, ProducedType et) {
if (that.getType() instanceof Tree.FunctionModifier) { if (that.getType() instanceof Tree.FunctionModifier) {
Tree.FunctionModifier local = (Tree.FunctionModifier) that.getType(); Tree.FunctionModifier local = (Tree.FunctionModifier) that.getType();
Expand All @@ -1014,6 +1054,15 @@ private void inferFunctionType(Tree.TypedDeclaration that, ProducedType et) {
} }
} }


private void inferFunctionType(Tree.MethodArgument that, ProducedType et) {
if (that.getType() instanceof Tree.FunctionModifier) {
Tree.FunctionModifier local = (Tree.FunctionModifier) that.getType();
if (et!=null) {
setFunctionType(local, et, that);
}
}
}

private void inferDefiniteType(Tree.Variable that, private void inferDefiniteType(Tree.Variable that,
Tree.SpecifierExpression se) { Tree.SpecifierExpression se) {
if (that.getType() instanceof Tree.LocalModifier) { if (that.getType() instanceof Tree.LocalModifier) {
Expand Down Expand Up @@ -1207,13 +1256,34 @@ private void setType(Tree.LocalModifier local,
} }
} }


private void setType(Tree.LocalModifier local,
Tree.SpecifierOrInitializerExpression s,
Tree.AttributeArgument that) {
Expression e = s.getExpression();
if (e!=null) {
ProducedType type = e.getTypeModel();
if (type!=null) {
ProducedType t = unit.denotableType(type);
local.setTypeModel(t);
that.getDeclarationModel().setType(t);
}
}
}

private void setFunctionType(Tree.FunctionModifier local, private void setFunctionType(Tree.FunctionModifier local,
ProducedType et, Tree.TypedDeclaration that) { ProducedType et, Tree.TypedDeclaration that) {
ProducedType t = unit.denotableType(et); ProducedType t = unit.denotableType(et);
local.setTypeModel(t); local.setTypeModel(t);
that.getDeclarationModel().setType(t); that.getDeclarationModel().setType(t);
} }


private void setFunctionType(Tree.FunctionModifier local,
ProducedType et, Tree.MethodArgument that) {
ProducedType t = unit.denotableType(et);
local.setTypeModel(t);
that.getDeclarationModel().setType(t);
}

@Override public void visit(Tree.Throw that) { @Override public void visit(Tree.Throw that) {
super.visit(that); super.visit(that);
Expression e = that.getExpression(); Expression e = that.getExpression();
Expand Down Expand Up @@ -1910,7 +1980,7 @@ private void checkInvocationArguments(Tree.InvocationExpression that,
checkPositionalArguments(pl, prf, that.getPositionalArgumentList()); checkPositionalArguments(pl, prf, that.getPositionalArgumentList());
} }
if ( that.getNamedArgumentList()!=null ) { if ( that.getNamedArgumentList()!=null ) {
if(pl.isNamedParametersSupported()) { if (pl.isNamedParametersSupported()) {
that.getNamedArgumentList().getNamedArgumentList().setParameterList(pl); that.getNamedArgumentList().getNamedArgumentList().setParameterList(pl);
checkNamedArguments(pl, prf, that.getNamedArgumentList()); checkNamedArguments(pl, prf, that.getNamedArgumentList());
} }
Expand Down

0 comments on commit bd2b94e

Please sign in to comment.