Skip to content

Instantly share code, notes, and snippets.

@cellularmitosis
Created March 15, 2016 04:57
Show Gist options
  • Save cellularmitosis/73f46088d3f6684432db to your computer and use it in GitHub Desktop.
Save cellularmitosis/73f46088d3f6684432db to your computer and use it in GitHub Desktop.
Fooling around with using Python's parsley to generate Swift code.
#!/usr/bin/env python
# fooling around with using parsley to generate swift.
import parsley
x = parsley.makeGrammar("""
ab = <'a'+>:a <'b'+>:b -> (a,b)
""", {})
print """
struct AB {
let a: String
let b: String
}
"""
# output: let ab1 = AB(a: "a", b: "b")
ab = x("ab").ab()
print 'let ab1 = AB(a: "%s", b: "%s")' % (ab[0], ab[1])
# output: let ab2 = AB(a: "aaa", b: "bbb")
ab = x("aaabbb").ab()
print 'let ab2 = AB(a: "%s", b: "%s")' % (ab[0], ab[1])
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment