Skip to content

Instantly share code, notes, and snippets.

@sheeit
Last active March 30, 2018 23:45
Show Gist options
  • Save sheeit/ad6eb1b406f3dee72a5c9f055064e94d to your computer and use it in GitHub Desktop.
Save sheeit/ad6eb1b406f3dee72a5c9f055064e94d to your computer and use it in GitHub Desktop.
Some regexes to convert some stuff from Python to Lua
The substitute following commands are made for Vim.
Convert function declarations (prototypes):
:%s/^def\(\s\)\(\s*[_A-Za-z][_A-Za-z0-9]*\s*([^)]*)\s*\)\s*:\s*$/function\1\2/g
Convert "for i in range(a, b):" to "for i = a, b":
:%s/\(for\s\+[_A-Za-z][_A-Za-z0-9]*\s\)\s*in\s*range\s*(\s*\([^)]\+\)\s*)\s*:\(.*\)$/\1= \2\3/g
Convert "True" and "False" to "true" and "false":
:%s/true|false/\L&\E/gi
Convert "None" to "nil":
%s/None/nil/g
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment