Implement automatic substitution for named parameters (auto-named arguments). Supported name: shorthand for name: name in function calls and class constructors. Updated documentation and tests. Built and deployed IDEA plugin and site.
This commit is contained in:
1 parent
c9f96464f3
commit
157b716eb7
5 files changed
+197
-62
No files matched your search
@@ -1036,6 +1036,12 @@ class Compiler(
|
||||
if (t2.type == Token.Type.COLON) {
|
||||
// name: expr
|
||||
val name = t1.value
|
||||
// Check for shorthand: name: (comma or rparen)
|
||||
val next = cc.peekNextNonWhitespace()
|
||||
if (next.type == Token.Type.COMMA || next.type == Token.Type.RPAREN) {
|
||||
val localVar = LocalVarRef(name, t1.pos)
|
||||
return ParsedArgument(statement(t1.pos) { localVar.get(it).value }, t1.pos, isSplat = false, name = name)
|
||||
}
|
||||
val rhs = parseExpression() ?: t2.raiseSyntax("expected expression after named argument '${name}:'")
|
||||
return ParsedArgument(rhs, t1.pos, isSplat = false, name = name)
|
||||
}
|
||||
@@ -1102,6 +1108,12 @@ class Compiler(
|
||||
val t2 = cc.next()
|
||||
if (t2.type == Token.Type.COLON) {
|
||||
val name = t1.value
|
||||
// Check for shorthand: name: (comma or rparen)
|
||||
val next = cc.peekNextNonWhitespace()
|
||||
if (next.type == Token.Type.COMMA || next.type == Token.Type.RPAREN) {
|
||||
val localVar = LocalVarRef(name, t1.pos)
|
||||
return ParsedArgument(statement(t1.pos) { localVar.get(it).value }, t1.pos, isSplat = false, name = name)
|
||||
}
|
||||
val rhs = parseExpression() ?: t2.raiseSyntax("expected expression after named argument '${name}:'")
|
||||
return ParsedArgument(rhs, t1.pos, isSplat = false, name = name)
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user