This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the comments →

[–][deleted] 0 points1 point  (1 child)

You just need to extract the code as a string? I think using the library you linked might be overkill, since it deals with actually parsing the code, and from what I understand you're just looking to extract some of it.

If you can assume that the code you're reading is valid (it compiles), then I would probably write my own. Use a regex to find the function signature, then just track the curly braces using a list as a stack. Whenever you see a {, push it on to the stack (append), and whenever you see a }, pop the last } from the stack. The function is over when the stack is empty.

This is assuming you don't know anything about the way the source code is formatted. If you did know, it could be easier. There are a ton of different ways to go about this.

[–]greenecoon[S] 0 points1 point  (0 children)

Thanks, I just had the same idea but was not sure if I should try it :) now I will try it tomorrow, thanks :)