{"action":"created","issue":{"url":"https://api.github.com/repos/krzysztofzablocki/Sourcery/issues/22","repository_url":"https://api.github.com/repos/krzysztofzablocki/Sourcery","labels_url":"https://api.github.com/repos/krzysztofzablocki/Sourcery/issues/22/labels{/name}","comments_url":"https://api.github.com/repos/krzysztofzablocki/Sourcery/issues/22/comments","events_url":"https://api.github.com/repos/krzysztofzablocki/Sourcery/issues/22/events","html_url":"https://github.com/krzysztofzablocki/Sourcery/issues/22","id":195655236,"number":22,"title":"Templates currently can't express all logic","user":{"login":"conradev","id":170649,"avatar_url":"https://avatars.githubusercontent.com/u/170649?v=3","gravatar_id":"","url":"https://api.github.com/users/conradev","html_url":"https://github.com/conradev","followers_url":"https://api.github.com/users/conradev/followers","following_url":"https://api.github.com/users/conradev/following{/other_user}","gists_url":"https://api.github.com/users/conradev/gists{/gist_id}","starred_url":"https://api.github.com/users/conradev/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/conradev/subscriptions","organizations_url":"https://api.github.com/users/conradev/orgs","repos_url":"https://api.github.com/users/conradev/repos","events_url":"https://api.github.com/users/conradev/events{/privacy}","received_events_url":"https://api.github.com/users/conradev/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":1,"created_at":"2016-12-14T21:48:32Z","updated_at":"2016-12-14T22:38:11Z","closed_at":null,"body":"I have been trying to do things like this:\r\n\r\n```swift\r\n{% for type in types.implementing.AutoEquatable %}\r\nextension {{ type.name }}: Equatable {}\r\n\r\nfunc == (lhs: {{ type.name }}, rhs: {{ type.name }}) -> Bool {\r\n    {% for variable in type.storedVariables %}\r\n    {% if variable.type implements Equatable or variable.type implements AutoEquatable %}\r\n    if lhs.{{ variable.name }} != rhs.{{ variable.name }} { return false }\r\n    {% endif %}\r\n    {% endfor %}\r\n    return true\r\n}\r\n{% endfor %}\r\n```\r\n\r\nor this:\r\n\r\n```swift\r\n{% for enum in types.enums where enum.name beginswith Gallery %}\r\nextension {{ enum.name }} {\r\n  static var count: Int { return {{ enum.cases.count }} }\r\n}\r\n{% endfor %}\r\n```\r\n\r\nand while operators like `where ... beginswith` and `if ... implements` are certainly possible to add to the template language, won't this project be hindered by the fact that the template language is not Turing-complete? Would it be possible to implement a library to build a Swift AST from Swift?"},"comment":{"url":"https://api.github.com/repos/krzysztofzablocki/Sourcery/issues/comments/267179236","html_url":"https://github.com/krzysztofzablocki/Sourcery/issues/22#issuecomment-267179236","issue_url":"https://api.github.com/repos/krzysztofzablocki/Sourcery/issues/22","id":267179236,"user":{"login":"krzysztofzablocki","id":1468993,"avatar_url":"https://avatars.githubusercontent.com/u/1468993?v=3","gravatar_id":"","url":"https://api.github.com/users/krzysztofzablocki","html_url":"https://github.com/krzysztofzablocki","followers_url":"https://api.github.com/users/krzysztofzablocki/followers","following_url":"https://api.github.com/users/krzysztofzablocki/following{/other_user}","gists_url":"https://api.github.com/users/krzysztofzablocki/gists{/gist_id}","starred_url":"https://api.github.com/users/krzysztofzablocki/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/krzysztofzablocki/subscriptions","organizations_url":"https://api.github.com/users/krzysztofzablocki/orgs","repos_url":"https://api.github.com/users/krzysztofzablocki/repos","events_url":"https://api.github.com/users/krzysztofzablocki/events{/privacy}","received_events_url":"https://api.github.com/users/krzysztofzablocki/received_events","type":"User","site_admin":false},"created_at":"2016-12-14T22:38:11Z","updated_at":"2016-12-14T22:38:11Z","body":"Stencil implementation we have here is not yet tweaked for more native code generation, we are actually splitting `SwiftGen` Stencil related extension into separate framework for Swift code generation and both tools will be using it. \r\nThere are plenty of more useful nodes coming like `set`, `map` and `function` `call` that will significantly extend what's doable to express here.\r\n\r\nBut even so, I'm keeping the `Parser`, `Models` and `Generator` separate, because I've been experimenting with some other ideas, like generating code via native Swift by just calling `swiftc` and feeding it all model types as definitions. Is that something you'd like to explore, or think could be a better approach? \r\n\r\nRight now I'm focusing most of my time on improving the `Parsing` and `Model` reflections, both functionality from templates you are showing we can support with small changes to `Type` and a few extra nodes, for example we could modify the first sample by the following:\r\n\r\n- Modify Variable to expose something like existing `TypesReflectionBox` instead of name\r\n- Add `or node`\r\n\r\n```swift\r\n{% for type in types.implementing.AutoEquatable %}\r\nextension {{ type.name }}: Equatable {}\r\n\r\nfunc == (lhs: {{ type.name }}, rhs: {{ type.name }}) -> Bool {\r\n    {% for variable in type.storedVariables %}\r\n    {% if variable.type.implements.Equatable or variable.type.implements.AutoEquatable %}\r\n    if lhs.{{ variable.name }} != rhs.{{ variable.name }} { return false }\r\n    {% endif %}\r\n    {% endfor %}\r\n    return true\r\n}\r\n{% endfor %}\r\n```"}}
{"actor":{"display_login":"krzysztofzablocki"}}