Since you remove comments, you can reuse the Lua lexer. This has the clear benefit that the lexing will be exactly what Lua does. To reuse the Lua lexer, consider using my ltokenp http://webserver2.tecgraf.puc-rio.br/~lhf/ftp/lua/index.html#ltokenp http://lua-users.org/lists/lua-l/2016-05/msg00028.html Also lua_reformat.sh can be simplified to #!/bin/bash lua << EOF require('lcf.workshop.base') local run = request('lcf.lua_reformat') run('1ドル', '2ドル') EOF Thanks for sharing lcf.