Skip to content

Commit

Permalink
Implemented support for keyword and keywordrest proc /lambda parameters
Browse files Browse the repository at this point in the history
  • Loading branch information
Who828 committed Jan 21, 2015
1 parent d537cab commit 9af62b2
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 10 deletions.
40 changes: 32 additions & 8 deletions core/src/main/java/org/jruby/runtime/Helpers.java
Expand Up @@ -7,14 +7,7 @@

import jnr.constants.platform.Errno;
import org.jruby.*;
import org.jruby.ast.ArgsNode;
import org.jruby.ast.ArgumentNode;
import org.jruby.ast.DAsgnNode;
import org.jruby.ast.LocalAsgnNode;
import org.jruby.ast.MultipleAsgn19Node;
import org.jruby.ast.Node;
import org.jruby.ast.OptArgNode;
import org.jruby.ast.UnnamedRestArgNode;
import org.jruby.ast.*;
import org.jruby.ast.util.ArgsUtil;
import org.jruby.common.IRubyWarnings.ID;
import org.jruby.evaluator.ASTInterpreter;
Expand Down Expand Up @@ -2712,6 +2705,26 @@ public static String encodeParameterList(ArgsNode argsNode) {
}
}

if (argsNode.getKeywords() != null) {
for (Node keyWordNode : argsNode.getKeywords().childNodes()) {
for (Node asgnNode : keyWordNode.childNodes()) {
if (added) builder.append(';');
added = true;
if (isRequiredKeywordArgumentValueNode(asgnNode))
builder.append("K").append(((DAsgnNode) asgnNode).getName());
else
builder.append("k").append(((DAsgnNode) asgnNode).getName());
}
}
}

if (argsNode.getKeyRest() != null) {
if (added) builder.append(';');
added = true;
builder.append("e").append(argsNode.getKeyRest().getName());
}


if (argsNode.getBlock() != null) {
if (added) builder.append(';');
added = true;
Expand Down Expand Up @@ -2777,6 +2790,12 @@ public static RubyArray parameterListToParameters(Ruby runtime, String[] paramet
} else if (param.charAt(0) == 'b') {
// block arg
elem.add(RubySymbol.newSymbol(runtime, "block"));
} else if (param.charAt(0) == 'k') {
elem.add(RubySymbol.newSymbol(runtime, "key"));
} else if (param.charAt(0) == 'K') {
elem.add(RubySymbol.newSymbol(runtime, "keyreq"));
} else if (param.charAt(0) == 'e') {
elem.add(RubySymbol.newSymbol(runtime, "keyrest"));
}

if (param.length() > 1) {
Expand Down Expand Up @@ -3101,4 +3120,9 @@ public static StaticScope decodeLocalScope(ThreadContext context, StaticScope pa
public static StaticScope decodeBlockScope(ThreadContext context, String scopeString) {
return decodeScope(context, context.getCurrentStaticScope(), scopeString);
}

private static boolean isRequiredKeywordArgumentValueNode(Node asgnNode) {
return asgnNode.childNodes().get(0) instanceof RequiredKeywordArgumentValueNode;
}

}
2 changes: 0 additions & 2 deletions test/mri/excludes/TestKeywordArguments.rb
Expand Up @@ -9,12 +9,10 @@
exclude :test_f8, "needs investigation"
exclude :test_f9, "needs investigation"
exclude :test_lambda, "needs investigation"
exclude :test_method_parameters, "needs investigation"
exclude :test_p1, "needs investigation"
exclude :test_p2, "needs investigation"
exclude :test_p3, "needs investigation"
exclude :test_p4, "needs investigation"
exclude :test_p5, "needs investigation"
exclude :test_p6, "needs investigation"
exclude :test_proc_parameters, "needs investigation"
exclude :test_rest_keyrest, "needs investigation"

0 comments on commit 9af62b2

Please sign in to comment.