Skip to content

Commit

Permalink
#41 Added invoke to optional lambdas
Browse files Browse the repository at this point in the history
  • Loading branch information
Angel Garcia authored and Angel Garcia committed Feb 3, 2018
1 parent 321db9e commit 6e6015c
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 0 deletions.
12 changes: 12 additions & 0 deletions Sources/SwiftKotlinFramework/KotlinTokenizer.swift
Original file line number Diff line number Diff line change
Expand Up @@ -608,6 +608,18 @@ public class KotlinTokenizer: SwiftTokenizer {
with: [expression.newToken(.symbol, binaryOperator)])
}

open override func tokenize(_ expression: FunctionCallExpression) -> [Token] {
var tokens = super.tokenize(expression)
if (expression.postfixExpression is OptionalChainingExpression || expression.postfixExpression is ForcedValueExpression),
let startIndex = tokens.indexOf(kind: .startOfScope, after: 0) {
tokens.insert(contentsOf: [
expression.newToken(.symbol, "."),
expression.newToken(.keyword, "invoke")
], at: startIndex)
}
return tokens
}

open override func tokenize(_ expression: FunctionCallExpression.Argument, node: ASTNode) -> [Token] {
return super.tokenize(expression, node: node)
.replacing({ $0.value == ": " && $0.kind == .delimiter },
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,5 @@ userService.autoLinkTenant(tenantId = tenant.id).then { _ ->
item.selectCallback = { option ->
presenter.selectPaymentMethod(option)
}
item.selectCallback?.invoke(option)
item.selectCallback!!.invoke(option)
Original file line number Diff line number Diff line change
Expand Up @@ -16,3 +16,6 @@ userService.autoLinkTenant(tenantId: tenant.id).then { [weak self] _ in
item.selectCallback = { option in
presenter.selectPaymentMethod(option)
}

item.selectCallback?(option)
item.selectCallback!(option)

0 comments on commit 6e6015c

Please sign in to comment.