As discussed in https://github.com/lark-parser/lark/issues/487, code is here: https://gist.github.com/erezsh/c2b51a03273f2485317fc83e75fa162c