Closed johndpope closed 7 years ago
Seems set will suffice. Think read me could expose examples.
If I understand it correctly, you can use either:
map
the array items, then use the join
filterfor
loop like you are now, but check if you're not the last item using forloop.last
. See https://github.com/SwiftGen/templates/blob/master/templates/strings/flat-swift2.stencil#L7 for an example.I think a convenience separator method like c++ template method would go a long way. This could also circumvent having to check for empty values.
You do realise that syntax is not even remotely similar to Stencil? TBH, we already have 2 ways of achieving this behaviour, I don't see the need to add a third option.
Concerning your second point: that seems again more something for Sourcery. This library (StencilSwiftKit) is only meant to add some filters and tags to Stencil, for better swift code generation support.
Join seems perfect. Thanks.
while I have been able to get some code smashed out using stencil https://github.com/johndpope/tensorflow/blob/swift/tensorflow/swift/misc/OperationDefinitions.stencil
https://github.com/johndpope/tensorflow/blob/swift/tensorflow/swift/misc/Operations.swift
I'm using this code
func {{ op._storage._name}}(scope:Scope, {% for arg in op._storage._inputArg %} {{arg.name}}:tf.Output,{{arg.type}} {% endfor %}) -> ({% for arg in op._storage._outputArg %} {{arg.name}}:tf.Output, {% endfor %}) {
but end up with this extra , at end func AccumulatorApplyGradient(scope:Scope, handle:tf.Output, local_step:tf.Output, gradient:tf.Output, ) -> () {
I noticed this c++ template which is used to generate swift classes in antlr has this syntax https://github.com/janyou/ANTLR-Swift-Target/blob/master/org/antlr/v4/tool/templates/codegen/Swift/Swift.stg
eg. public static let <lexer.tokens:{k |=<lexer.tokens.(k)>}; separator=", ", wrap, anchor>
it might be worth cherry picking some of the logic here.
Slightly unrelated / (and not an issue) but you maybe interested This is every language gramma file from antlr spat out as swift tokens / parsers https://github.com/johndpope/ANTLR-Swift-Target/tree/master/gen/grammars-v4
These base tokens / parsers are generated via c++ template(stg) in antlr then java. https://github.com/johndpope/Antlr-Swift-runtime
I had envisaged one day that these could be generated from swift. perhaps with this library