Skip to content

Commit

Permalink
Commas are now mandatory delimiters in param bindings. Currying fixed.
Browse files Browse the repository at this point in the history
  • Loading branch information
joergen7 committed Jan 4, 2016
1 parent 717031d commit 8ff34c7
Show file tree
Hide file tree
Showing 5 changed files with 44 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -122,16 +122,16 @@ singleExpr : ID # IdEx
| STRING # StringExpr
| FROMSTACK # FromStackExpr
| IF expr THEN expr ELSE expr END # CondExpr
| channel? APPLY LPAREN paramBind+ TILDE? RPAREN # ApplyExpr
| channel? ID LPAREN paramBind* TILDE? RPAREN # CallExpr
| CURRY LPAREN paramBind+ RPAREN # CurryExpr
| channel? APPLY LPAREN paramBind( COMMA paramBind )* TILDE? RPAREN # ApplyExpr
| channel? ID LPAREN( paramBind( COMMA paramBind )* )? TILDE? RPAREN # CallExpr
| CURRY LPAREN paramBind( COMMA paramBind )* RPAREN # CurryExpr
| LAMBDA prototype block # NativeLambdaExpr
| LAMBDA prototype foreignBody # ForeignLambdaExpr
| APPLY
{ notifyErrorListeners( "Incomplete task application. Missing '('." ); } # SingleExprErr1
| APPLY LPAREN
{ notifyErrorListeners( "Incomplete task application. Missing Parameter bindings, e.g. 'param: value'." ); } # SingleExprErr2
| APPLY LPAREN paramBind+
| APPLY LPAREN paramBind( COMMA paramBind )*
{ notifyErrorListeners( "Incomplete task application. Missing ')'." ); } # SingleExprErr3
| APPLY LPAREN ID COLON
{ notifyErrorListeners( "Incomplete Parameter binding. Missing value." ); } # ParamBindErr1
Expand All @@ -156,6 +156,7 @@ foreignBody : INLANG BODY ;

APPLY : 'apply' ;
COLON : ':' ;
COMMA : ',' ;
COMB : 'comb' ;
COMBR : 'combr' ;
CURRY : 'curry' ;
Expand Down Expand Up @@ -204,4 +205,4 @@ COMMENT : ( ( '#' | '//' | '%' ) ~'\n'*
;
ID : [a-zA-Z0-9\.\-_\+\*/]+ ;
WS : WSSYMB -> channel( HIDDEN ) ;
fragment WSSYMB : [ \n\r\t,] ;
fragment WSSYMB : [ \n\r\t] ;
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ public void enterCallExpr( @NotNull CuneiformParser.CallExprContext ctx ) {

rewriter.replace( id, "apply" );

rewriter.insertAfter( lparen, " task: "+id.getText()+" " );
rewriter.insertAfter( lparen, " task: "+id.getText()+", " );
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -248,6 +248,7 @@ public void setTaskExpr( CompoundExpr taskExpr ) {
public String toString() {

StringBuffer buf;
boolean comma;

try {

Expand All @@ -258,8 +259,15 @@ public String toString() {
if( hasTaskExpr() )
buf.append( " task: " ).append( taskExpr );

for( NameExpr name : getNameSet() )
comma = false;
for( NameExpr name : getNameSet() ) {

if( comma )
buf.append( ',' );
comma = true;

buf.append( ' ' ).append( name.getId() ).append( ": " ).append( getExpr( name ) );
}

if( rest )
buf.append( " ~" );
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,9 @@ public CompoundExpr( CompoundExpr template ) {

this();

if( template == null )
throw new NullPointerException( "Template compound expression must not be null." );

for( SingleExpr se : template.singleExprList )
singleExprList.add( copySingleExpr( se ) );
}
Expand Down Expand Up @@ -316,6 +319,9 @@ private static SingleExpr copySingleExpr( SingleExpr se ) {
if( se instanceof QualifiedTicket )
return se;

if( se instanceof CurryExpr )
return new CurryExpr( ( CurryExpr )se );

throw new UnsupportedOperationException( "Copy operation unsupported for expression of type "+se.getClass() );
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,18 @@ public class CurryExpr extends BaseBlock implements SingleExpr {

private CompoundExpr taskExpr;

public CurryExpr() {
// do nothing
}

public CurryExpr( CurryExpr se ) {

if( se == null )
throw new NullPointerException( "Task expression must not be null." );

taskExpr = new CompoundExpr( se.getTaskExpr() );
}

@Override
public int getNumAtom() throws NotDerivableException {
return 1;
Expand Down Expand Up @@ -67,15 +79,23 @@ public void setTaskExpr( CompoundExpr taskExpr ) {
public String toString() {

StringBuffer buf;
boolean comma;

buf = new StringBuffer();

buf.append( "curry( task: " ).append( taskExpr );
buf.append( "curry( task: " ).append( taskExpr ).append( ',' );

try {

for( NameExpr nameExpr : getNameSet() )
comma = false;
for( NameExpr nameExpr : getNameSet() ) {

if( comma )
buf.append( ',' );
comma = true;

buf.append( ' ' ).append( nameExpr.getId() ).append( ": " ).append( getExpr( nameExpr ) );
}
}
catch( NotBoundException e ) {
throw new RuntimeException( e.getMessage() );
Expand Down

0 comments on commit 8ff34c7

Please sign in to comment.