Created
March 15, 2016 04:57
-
-
Save cellularmitosis/73f46088d3f6684432db to your computer and use it in GitHub Desktop.
Fooling around with using Python's parsley to generate Swift code.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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