SwiftGen / StencilSwiftKit

A framework bringing additional nodes & filters to Stencil dedicated to Swift code generation
MIT License
298 stars 58 forks source link

generating swift method signatures / extra comma #53

Closed johndpope closed 7 years ago

johndpope commented 7 years ago

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

johndpope commented 7 years ago

Seems set will suffice. Think read me could expose examples.

djbe commented 7 years ago

If I understand it correctly, you can use either:

johndpope commented 7 years ago

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.

djbe commented 7 years ago

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.

johndpope commented 7 years ago

Join seems perfect. Thanks.