Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local patterns = {
- number = "%-?[%d+%.]+",
- checkNumber = "%-?[%d+%.]*",
- phrase = "[%a?%d?]+",
- checkPhrase = "[%a+%d*]*",
- space = "%s+",
- word = "%a+",
- }
- function translate(language, code)
- local translations;
- if language == "javascript" or language == "js" then
- translations = {
- ["(%a+)%s*%+%+"] = "%1 = %1 + 1",
- ["(%a+)%s*%+%=%s*("..patterns.number..")"] = "%1 = %1 + %2",
- ["(%a+)%s*%-%-"] = "%1 = %1 - 1",
- ["if%s*%((.+)%)%s*{"] = "if %1 then",
- ["while%s*%((.+)%)%s*{"] = "while %1 do",
- ["for%s*%(v?a?r?%s*("..patterns.phrase.."%s*%=%s*"..patterns.number..");%s*"..patterns.phrase..".+("..patterns.number..");.+("..patterns.number..")%s*%)%s*{"] = "for %1, %2, %3 do",
- ["for%s*%(v?a?r?%s*("..patterns.phrase.."%s*%=%s*"..patterns.number..");%s*"..patterns.phrase.."%s*.%s*("..patterns.phrase..");%s*"..patterns.phrase.."%s*=%s*"..patterns.phrase.."%s*.%s*("..patterns.number..")%s*%)%s*{"] = "for %1, %2, %3 do",
- ["function%s+(%a+)%s*%((.+)%)%s*{"] = "function %1(%2)",
- ["(function%s+%a+%s*%(.+%).+)}"] = "%1 end",
- ["([while]?[if]?)(.+)([do]?[then]?)(.+)}"] = "%1 %2 %3 %4 end",
- ["console%.log"] = "print",
- ["var"] = "local"
- }
- end
- for pattern, replace in pairs(translations) do
- code = code:gsub(pattern, replace)
- end
- return code
- end
Advertisement
Add Comment
Please, Sign In to add comment