Although the code cannot be patented directly, a piece of code always has certain functions. The operation of code is actually the processing flow of a task. Tell the process, cause and effect and logical relationship in words. This is the method flow that can apply for a patent. That's totally fine. As long as the other licensing conditions of the patent are met, the patent right can be obtained completely.
Wish you success!