Created
June 28, 2016 14:39
-
-
Save thomasfoster96/6fe11b6ed40dd3c1de86ecd53ce8e45f to your computer and use it in GitHub Desktop.
An ECMAScript to English transpiler.
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
function transpile(token){ | |
switch(token.type){ | |
case "Literal": | |
switch(typeof token.value){ | |
case "string": | |
return `"${token.value}"`; | |
case "boolean": | |
return `${token.value ? "true" : "false"}`; | |
case "null": | |
return "nothing"; | |
case "number": | |
return `${token.value}`; | |
} | |
case "RegExpLiteral": | |
return `the regular expression "${token.regex.pattern}" with the flags "${token.regex.flags}"`; | |
case "Program": | |
return token.body.map(statement => transpile(statement)).join(''); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment