Skip to content

Instantly share code, notes, and snippets.

@wader
Created February 8, 2012 17:10
Show Gist options
  • Save wader/1771131 to your computer and use it in GitHub Desktop.
Save wader/1771131 to your computer and use it in GitHub Desktop.
Print class and instance methods declarations from Objective-C implementation
#!/usr/bin/env awk -f
# print class and instance methods declarations from implementation
# Usage: ./printmethods.awk class.m or awk -f printmethods.awk class.m
/^[[:space:]]*@implementation/ {
implementation = 1;
}
/^[[:space:]]*@end/ {
implementation = 0;
}
/^[[:space:]]*[\-\+]/ {
if(implementation) {
method = 1;
collect = "";
}
}
/[^[:space:]]/ {
if(implementation && method) {
p = index($0, "{");
if(p == 0) {
if(collect == "")
collect = $0
else
collect = collect $0 "\n";
} else {
method = 0;
# trim white space and "{" from line end
gsub("[\{[:space:]]*$", "", $0);
collect = collect $0;
# trim white space from start
gsub("^[[:space:]]*", "", collect);
print collect ";"
}
}
}
@dlundqvist
Copy link

Try embedding clang and use the AST walkers :)

@wader
Copy link
Author

wader commented Apr 29, 2012

That would be much nicer yes, this was a quick hack for someone on stackoverflow :) Do you have any documentation how to use the AST talkers? seams as the include files for clang is not included with Xcode :( Found this http://llvm.org/devmtg/2010-11/Gregor-libclang.pdf which seams nice but maybe old? C++ and libast may be a better choice?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment