Created
October 21, 2015 03:53
-
-
Save ojii/8ff11186da139fce44b6 to your computer and use it in GitHub Desktop.
ascript
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
import sys | |
import re | |
SPLITTER = re.compile('\s') | |
TOKENS = [ | |
'var', | |
'=', | |
';', | |
'function', | |
'(', | |
')', | |
'{', | |
'}', | |
',', | |
'return', | |
'"', | |
"'", | |
'[', | |
']', | |
'==', | |
'===', | |
'!==', | |
'!===', | |
'-', | |
'+', | |
'/', | |
'*', | |
'new', | |
'a', | |
] | |
MAPPING = {'a' * index: token for index, token in enumerate(TOKENS, start=1)} | |
def compile(source: str) -> str: | |
tokens = filter(bool, SPLITTER.split(source)) | |
return ' '.join(MAPPING.get(token, token) for token in tokens) | |
def main(): | |
if len(sys.argv) != 2: | |
print("Usage: ascript.py <filename>") | |
sys.exit(1) | |
else: | |
with open(sys.argv[1]) as fobj: | |
print(compile(fobj.read())) | |
if __name__ == '__main__': | |
main() | |
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
aaaa A aaaaa aaaaaa aaaaaaa console.log aaaaa aaaaaaaaaaa Hello World aaaaaaaaaaa aaaaaa aaa aaaaaaaa A aaaaa aaaaaa aaa |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment