Created
August 10, 2015 21:04
-
-
Save jeandudey/df4b9f520997785e74ac to your computer and use it in GitHub Desktop.
String to char literals (to use it with PEGTL).
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/python3 | |
# Description: convert an string to a "literal string" (i.e. 'H', 'e', 'l', 'l', 'o') | |
# to use in PEGTL (i.e pegtl::string< 'H', 'e', 'l', 'l', 'o', ',', ' ' >). | |
def toliteralstring(str): | |
result = "" | |
for c in str: | |
result += "'" + c "' " | |
result = result[:-2] | |
return result | |
strings = ["bool", "int"] | |
# Output: | |
# 'b', 'o', 'o', 'l' | |
# 'i', 'n', 't' | |
for string in strings: | |
print(toliteralstring(string)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment