From: George Ogata Date: 2005-02-21T03:29:42+09:00 Subject: [ANN] CAST -- Ruby's C parsing dog. Woof. What Is ======= CAST parses C code into an abstract syntax tree (AST), lets you break it, then vomit it out as code. The parser does C99. Library Overview ================ Everything is in the module C. * There's the parser (Parser). * There's the tree (Node and its subclasses). * That's it. Usage ----- You call Parser#parse, and it gives you a tree of Node objects. Watch: require 'cast/cast' ## create a parser parser = C::Parser.new ## (optional) set some settings... parser.pos.filename = "toy.c" # used for error messages parser.type_names << 'LinkedList' # treat these words as types ## gimme a tree ugly_c_code = open("toy.c"){|f| f.read} tree = parser.parse(ugly_c_code) ## what's the tree look like? puts tree.to_debug If there's a parse error, #parse raises a ParseError (which has a nice error message in #message). ....................................................................... Keep reading: http://cast.rubyforge.org Woof!