refactor common generator code, fix ast bug in binary, pattern syntax