From 8ff34c7cb3d0ad4b86789ae2711bb53b330ece3f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=B6rgen=20Brandt?= Date: Mon, 4 Jan 2016 14:18:44 +0100 Subject: [PATCH] Commas are now mandatory delimiters in param bindings. Currying fixed. --- .../wbi/cuneiform/core/parser/Cuneiform.g4 | 11 +++++---- .../core/preprocess/PreListener.java | 2 +- .../core/semanticmodel/ApplyExpr.java | 10 +++++++- .../core/semanticmodel/CompoundExpr.java | 6 +++++ .../core/semanticmodel/CurryExpr.java | 24 +++++++++++++++++-- 5 files changed, 44 insertions(+), 9 deletions(-) diff --git a/cuneiform-core/src/main/antlr/de/huberlin/wbi/cuneiform/core/parser/Cuneiform.g4 b/cuneiform-core/src/main/antlr/de/huberlin/wbi/cuneiform/core/parser/Cuneiform.g4 index 177075f..3518c5a 100644 --- a/cuneiform-core/src/main/antlr/de/huberlin/wbi/cuneiform/core/parser/Cuneiform.g4 +++ b/cuneiform-core/src/main/antlr/de/huberlin/wbi/cuneiform/core/parser/Cuneiform.g4 @@ -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 @@ -156,6 +156,7 @@ foreignBody : INLANG BODY ; APPLY : 'apply' ; COLON : ':' ; +COMMA : ',' ; COMB : 'comb' ; COMBR : 'combr' ; CURRY : 'curry' ; @@ -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] ; diff --git a/cuneiform-core/src/main/java/de/huberlin/wbi/cuneiform/core/preprocess/PreListener.java b/cuneiform-core/src/main/java/de/huberlin/wbi/cuneiform/core/preprocess/PreListener.java index e1c5578..ae147d5 100644 --- a/cuneiform-core/src/main/java/de/huberlin/wbi/cuneiform/core/preprocess/PreListener.java +++ b/cuneiform-core/src/main/java/de/huberlin/wbi/cuneiform/core/preprocess/PreListener.java @@ -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 diff --git a/cuneiform-core/src/main/java/de/huberlin/wbi/cuneiform/core/semanticmodel/ApplyExpr.java b/cuneiform-core/src/main/java/de/huberlin/wbi/cuneiform/core/semanticmodel/ApplyExpr.java index 9a54e3c..62c5d98 100644 --- a/cuneiform-core/src/main/java/de/huberlin/wbi/cuneiform/core/semanticmodel/ApplyExpr.java +++ b/cuneiform-core/src/main/java/de/huberlin/wbi/cuneiform/core/semanticmodel/ApplyExpr.java @@ -248,6 +248,7 @@ public void setTaskExpr( CompoundExpr taskExpr ) { public String toString() { StringBuffer buf; + boolean comma; try { @@ -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( " ~" ); diff --git a/cuneiform-core/src/main/java/de/huberlin/wbi/cuneiform/core/semanticmodel/CompoundExpr.java b/cuneiform-core/src/main/java/de/huberlin/wbi/cuneiform/core/semanticmodel/CompoundExpr.java index ff2655c..0643219 100644 --- a/cuneiform-core/src/main/java/de/huberlin/wbi/cuneiform/core/semanticmodel/CompoundExpr.java +++ b/cuneiform-core/src/main/java/de/huberlin/wbi/cuneiform/core/semanticmodel/CompoundExpr.java @@ -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 ) ); } @@ -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() ); } } diff --git a/cuneiform-core/src/main/java/de/huberlin/wbi/cuneiform/core/semanticmodel/CurryExpr.java b/cuneiform-core/src/main/java/de/huberlin/wbi/cuneiform/core/semanticmodel/CurryExpr.java index 5bfbb46..23ca610 100644 --- a/cuneiform-core/src/main/java/de/huberlin/wbi/cuneiform/core/semanticmodel/CurryExpr.java +++ b/cuneiform-core/src/main/java/de/huberlin/wbi/cuneiform/core/semanticmodel/CurryExpr.java @@ -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; @@ -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() );