Skip to content

Commit

Permalink
Remove case functions implementation
Browse files Browse the repository at this point in the history
We're removing this feature as per RFC 51.

Closes #2540.
  • Loading branch information
Benoit Vey authored and SeanTAllen committed Feb 10, 2018
1 parent 55f5214 commit 9f52985
Show file tree
Hide file tree
Showing 12 changed files with 93 additions and 1,804 deletions.
25 changes: 11 additions & 14 deletions packages/debug/debug.pony
Original file line number Diff line number Diff line change
Expand Up @@ -25,26 +25,23 @@ primitive Debug
"""
This is a debug only print utility.
"""
fun apply(msg: Stringable, sep: String, stream: DebugStream = DebugOut) =>
"""
If platform is debug configured, print a stringable. The default output
stream is stdout.
"""
ifdef debug then
_print(msg.string(), stream)
end

fun apply(
msg: ReadSeq[Stringable],
msg: (Stringable | ReadSeq[Stringable]),
sep: String = ", ",
stream: DebugStream)
stream: DebugStream = DebugOut)
=>
"""
If platform is debug configured, print a sequence of stringables. The
default separator is ", ", and the default output stream is stdout.
If platform is debug configured, print either a single stringable or a
sequence of stringables. The default separator is ", ", and the default
output stream is stdout.
"""
ifdef debug then
_print(sep.join(msg.values()), stream)
match msg
| let m: Stringable =>
_print(m.string(), stream)
| let m: ReadSeq[Stringable] =>
_print(sep.join(m.values()), stream)
end
end

fun out(msg: Stringable = "") =>
Expand Down
20 changes: 14 additions & 6 deletions pony.g
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ field
;

method
: ('fun' | 'be' | 'new') ('\\' ID (',' ID)* '\\')? (cap | '@')? ID typeparams? ('(' | LPAREN_NEW) params? ')' (':' type)? '?'? STRING? ('if' rawseq)? ('=>' rawseq)?
: ('fun' | 'be' | 'new') ('\\' ID (',' ID)* '\\')? (cap | '@')? ID typeparams? ('(' | LPAREN_NEW) params? ')' (':' type)? '?'? STRING? ('=>' rawseq)?
;

annotatedrawseq
Expand Down Expand Up @@ -208,8 +208,8 @@ nextatom
| LPAREN_NEW rawseq tuple? ')'
| LSQUARE_NEW ('as' type ':')? rawseq? ']'
| 'object' ('\\' ID (',' ID)* '\\')? cap? ('is' type)? members 'end'
| '{' ('\\' ID (',' ID)* '\\')? cap? ID? typeparams? ('(' | LPAREN_NEW) params? ')' lambdacaptures? (':' type)? '?'? '=>' rawseq '}' cap?
| '@{' ('\\' ID (',' ID)* '\\')? cap? ID? typeparams? ('(' | LPAREN_NEW) params? ')' lambdacaptures? (':' type)? '?'? '=>' rawseq '}' cap?
| '{' ('\\' ID (',' ID)* '\\')? cap? ID? typeparams? ('(' | LPAREN_NEW) lambdaparams? ')' lambdacaptures? (':' type)? '?'? '=>' rawseq '}' cap?
| '@{' ('\\' ID (',' ID)* '\\')? cap? ID? typeparams? ('(' | LPAREN_NEW) lambdaparams? ')' lambdacaptures? (':' type)? '?'? '=>' rawseq '}' cap?
| '@' (ID | STRING) typeargs? ('(' | LPAREN_NEW) positional? named? ')' '?'?
| '__loc'
;
Expand All @@ -221,8 +221,8 @@ atom
| ('(' | LPAREN_NEW) rawseq tuple? ')'
| ('[' | LSQUARE_NEW) ('as' type ':')? rawseq? ']'
| 'object' ('\\' ID (',' ID)* '\\')? cap? ('is' type)? members 'end'
| '{' ('\\' ID (',' ID)* '\\')? cap? ID? typeparams? ('(' | LPAREN_NEW) params? ')' lambdacaptures? (':' type)? '?'? '=>' rawseq '}' cap?
| '@{' ('\\' ID (',' ID)* '\\')? cap? ID? typeparams? ('(' | LPAREN_NEW) params? ')' lambdacaptures? (':' type)? '?'? '=>' rawseq '}' cap?
| '{' ('\\' ID (',' ID)* '\\')? cap? ID? typeparams? ('(' | LPAREN_NEW) lambdaparams? ')' lambdacaptures? (':' type)? '?'? '=>' rawseq '}' cap?
| '@{' ('\\' ID (',' ID)* '\\')? cap? ID? typeparams? ('(' | LPAREN_NEW) lambdaparams? ')' lambdacaptures? (':' type)? '?'? '=>' rawseq '}' cap?
| '@' (ID | STRING) typeargs? ('(' | LPAREN_NEW) positional? named? ')' '?'?
| '__loc'
;
Expand All @@ -239,6 +239,14 @@ lambdacapture
: ID (':' type)? ('=' infix)?
;

lambdaparams
: lambdaparam (',' lambdaparam)*
;

lambdaparam
: ID (':' type)? ('=' infix)?
;

positional
: rawseq (',' rawseq)*
;
Expand Down Expand Up @@ -340,7 +348,7 @@ literal
;

param
: parampattern (':' type)? ('=' infix)?
: ID ':' type ('=' infix)?
;

antlr_0
Expand Down
43 changes: 28 additions & 15 deletions src/libponyc/ast/parser.c
Original file line number Diff line number Diff line change
Expand Up @@ -73,14 +73,12 @@ DEF(defaultarg);
RULE("default value", infix);
DONE();

// postfix [COLON type] [ASSIGN defaultarg]
// ID [COLON type] [ASSIGN defaultarg]
DEF(param);
AST_NODE(TK_PARAM);
RULE("name", parampattern);
IF(TK_COLON,
RULE("parameter type", type);
UNWRAP(0, TK_REFERENCE);
);
TOKEN("parameter name", TK_ID);
SKIP("mandatory type declaration on parameter", TK_COLON);
RULE("parameter type", type);
IF(TK_ASSIGN, RULE("default value", defaultarg));
DONE();

Expand Down Expand Up @@ -344,6 +342,21 @@ DEF(object);
SET_CHILD_FLAG(2, AST_FLAG_PRESERVE); // Members
DONE();

// parampattern [COLON type] [ASSIGN defaultarg]
DEF(lambdaparam);
AST_NODE(TK_PARAM);
TOKEN("parameter name", TK_ID);
IF(TK_COLON, RULE("parameter type", type));
IF(TK_ASSIGN, RULE("default value", defaultarg));
DONE();

// lambdaparam {COMMA lambdaparam}
DEF(lambdaparams);
AST_NODE(TK_PARAMS);
RULE("parameter", lambdaparam);
WHILE(TK_COMMA, RULE("parameter", lambdaparam));
DONE();

// ID [COLON type] [ASSIGN infix]
DEF(lambdacapture);
AST_NODE(TK_LAMBDACAPTURE);
Expand All @@ -362,8 +375,9 @@ DEF(lambdacaptures);
SKIP(NULL, TK_RPAREN);
DONE();

// LBRACE [annotations] [CAP] [ID] [typeparams] (LPAREN | LPAREN_NEW) [params]
// RPAREN [lambdacaptures] [COLON type] [QUESTION] ARROW rawseq RBRACE [CAP]
// LBRACE [annotations] [CAP] [ID] [typeparams] (LPAREN | LPAREN_NEW)
// [lambdaparams] RPAREN [lambdacaptures] [COLON type] [QUESTION] ARROW rawseq
// RBRACE [CAP]
DEF(lambda);
PRINT_INLINE();
AST_NODE(TK_LAMBDA);
Expand All @@ -373,7 +387,7 @@ DEF(lambda);
OPT TOKEN("function name", TK_ID);
OPT RULE("type parameters", typeparams);
SKIP(NULL, TK_LPAREN, TK_LPAREN_NEW);
OPT RULE("parameters", params);
OPT RULE("parameters", lambdaparams);
SKIP(NULL, TK_RPAREN);
OPT RULE("captures", lambdacaptures);
IF(TK_COLON, RULE("return type", type));
Expand All @@ -389,8 +403,8 @@ DEF(lambda);
DONE();

// AT_LBRACE [annotations] [CAP] [ID] [typeparams] (LPAREN | LPAREN_NEW)
// [params] RPAREN [lambdacaptures] [COLON type] [QUESTION] ARROW rawseq RBRACE
// [CAP]
// [lambdaparams] RPAREN [lambdacaptures] [COLON type] [QUESTION] ARROW rawseq
// RBRACE [CAP]
DEF(barelambda);
PRINT_INLINE();
AST_NODE(TK_BARELAMBDA);
Expand All @@ -400,7 +414,7 @@ DEF(barelambda);
OPT TOKEN("function name", TK_ID);
OPT RULE("type parameters", typeparams);
SKIP(NULL, TK_LPAREN, TK_LPAREN_NEW);
OPT RULE("parameters", params);
OPT RULE("parameters", lambdaparams);
SKIP(NULL, TK_RPAREN);
OPT RULE("captures", lambdacaptures);
IF(TK_COLON, RULE("return type", type));
Expand Down Expand Up @@ -1127,11 +1141,10 @@ DEF(method);
IF(TK_COLON, RULE("return type", type));
OPT TOKEN(NULL, TK_QUESTION);
OPT TOKEN(NULL, TK_STRING);
IF(TK_IF, RULE("guard expression", rawseq));
IF(TK_DBLARROW, RULE("method body", rawseq));
// Order should be:
// cap id type_params params return_type error body docstring guard
REORDER(0, 1, 2, 3, 4, 5, 8, 6, 7);
// cap id type_params params return_type error body docstring
REORDER(0, 1, 2, 3, 4, 5, 7, 6);
DONE();

// (VAR | LET | EMBED) ID [COLON type] [ASSIGN infix]
Expand Down
18 changes: 13 additions & 5 deletions src/libponyc/ast/treecheckdef.h
Original file line number Diff line number Diff line change
Expand Up @@ -79,8 +79,7 @@ RULE(method,
CHILD(type, none) // Return type
CHILD(question, none)
CHILD(rawseq, none) // Body
CHILD(string, none)
CHILD(rawseq, none), // Guard (case methods only)
CHILD(string, none),
TK_FUN, TK_NEW, TK_BE);

RULE(type_params, ONE_OR_MORE(type_param), TK_TYPEPARAMS);
Expand All @@ -101,8 +100,8 @@ RULE(params,

RULE(param,
HAS_TYPE(type)
CHILD(id, expr)
CHILD(type, none)
CHILD(id)
CHILD(type)
CHILD(seq, none),
TK_PARAM);

Expand Down Expand Up @@ -378,14 +377,23 @@ RULE(lambda,
CHILD(cap, none) // Receiver cap
CHILD(id, none)
CHILD(type_params, none)
CHILD(params, none)
CHILD(lambda_params, none)
CHILD(lambda_captures, none)
CHILD(type, none) // Return
CHILD(question, none)
CHILD(rawseq)
CHILD(cap, none), // Type reference cap
TK_LAMBDA);

RULE(lambda_params, ONE_OR_MORE(lambda_param), TK_PARAMS);

RULE(lambda_param,
HAS_TYPE(type)
CHILD(id)
CHILD(type, none)
CHILD(seq, none),
TK_PARAM);

RULE(lambda_captures, ONE_OR_MORE(lambda_capture), TK_LAMBDACAPTURES);

RULE(lambda_capture,
Expand Down
8 changes: 2 additions & 6 deletions src/libponyc/expr/lambda.c
Original file line number Diff line number Diff line change
Expand Up @@ -294,16 +294,14 @@ bool expr_lambda(pass_opt_t* opt, ast_t** astp)
ast_t* param_type = ast_sibling(param_id);

// Convert a "_" parameter to whatever the expected parameter is.
if((ast_id(param_id) == TK_REFERENCE) &&
is_name_dontcare(ast_name(ast_child(param_id))))
if(is_name_dontcare(ast_name(param_id)))
{
ast_replace(&param_id, ast_child(def_param));
ast_replace(&param_type, ast_childidx(def_param, 1));
}
// Give a type-unspecified parameter the type of the expected parameter.
else if(ast_id(param_type) == TK_NONE)
{
ast_replace(&param_id, ast_child(param_id)); // unwrap reference's id
ast_replace(&param_type, ast_childidx(def_param, 1));
}

Expand Down Expand Up @@ -394,8 +392,7 @@ bool expr_lambda(pass_opt_t* opt, ast_t** astp)
TREE(ret_type)
TREE(raises)
TREE(body)
NONE // Doc string
NONE)); // Guard
NONE)); // Doc string

ast_list_append(members, &last_member, apply);
ast_setflag(members, AST_FLAG_PRESERVE);
Expand Down Expand Up @@ -693,7 +690,6 @@ bool expr_object(pass_opt_t* opt, ast_t** astp)
NONE
NODE(TK_SEQ,
NODE(TK_TRUE))
NONE
NONE));

BUILD(type_ref, ast, NODE(TK_REFERENCE, ID(c_id)));
Expand Down
Loading

0 comments on commit 9f52985

Please sign in to comment.