Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature/v0.1.4 #71

Merged
merged 7 commits into from
Mar 24, 2018
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
#29 Varargs support
  • Loading branch information
Angel Garcia authored and Angel Garcia committed Mar 18, 2018
commit 82f45001413be836eb8705bc320dc9ae3533a3ad
11 changes: 7 additions & 4 deletions Sources/SwiftKotlinFramework/KotlinTokenizer.swift
Original file line number Diff line number Diff line change
Expand Up @@ -54,13 +54,16 @@ public class KotlinTokenizer: SwiftTokenizer {
let defaultTokens = parameter.defaultArgumentClause.map {
return parameter.newToken(.symbol, " = ", node) + tokenize($0)
}
let varargsTokens = parameter.isVarargs ? [parameter.newToken(.symbol, "...", node)] : []
let varargsTokens = parameter.isVarargs ? [
parameter.newToken(.keyword, "vararg", node),
parameter.newToken(.space, " ", node),
] : []

return
varargsTokens +
nameTokens +
typeAnnoTokens +
defaultTokens +
varargsTokens
typeAnnoTokens +
defaultTokens
}

open override func tokenize(_ result: FunctionResult, node: ASTNode) -> [Token] {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,3 +18,12 @@ fun tokenize(codeBlock: String?) : List<String> {

public fun <T> whenAll(promises: List<Promise<T>>) : Promise<List<T>> =
Promise<T>()

fun sumOf(vararg numbers: Int) : Int {
var sum = 0
for (number in numbers) {
sum += number
}
return sum
}
sumOf(42, 597, 12)
Original file line number Diff line number Diff line change
Expand Up @@ -22,3 +22,12 @@ func tokenize(_ codeBlock: String?) -> [String] {
public func whenAll<T>(promises: [Promise<T>]) -> Promise<[T]> {
return Promise<T>()
}

func sumOf(_ numbers: Int...) -> Int {
var sum = 0
for number in numbers {
sum += number
}
return sum
}
sumOf(42, 597, 12)