ingydotnet / inline-c-pm

10 stars 19 forks source link

Would like to see the C-parser usable by itself #6

Open mohawk2 opened 10 years ago

mohawk2 commented 10 years ago

E.g.:

$parsed = Inline::C->parse($code);

And possibly specifying which parser to use:

$parsed = Inline::C::ParsePegex->parse($code);
ingydotnet commented 10 years ago

I'd put it in a base class Inline::Parse for the 3 parsers. I don't think it needs to go in Inline::C.

It's really just a debugging thing, I think. Only a tiny bit of the C is parsed.

mohawk2 commented 10 years ago

I'd like it available to use not for debugging, but for assisting with easing FFI. And I'd argue it's not a general Inline::Parse thing because it's only parsing C, and Inline::C already does that.

mohawk2 commented 10 years ago

In other words, I am proposing that the internal API that already exists would be slightly modified and exposed to the outside world. So instead of:

$parser->code($code); # puts data in $parser->{data}{function} etc

it would be:

$data = $parser->code($code); # similar structure but passed as data

By the way, should Inline::C::get_types be changed to use one of https://metacpan.org/pod/ExtUtils::XSBuilder or https://metacpan.org/pod/distribution/ExtUtils-ParseXS/lib/ExtUtils/ParseXS.pm ? We could also look to collaborate or steal ideas from these guys.

zmughal commented 10 years ago

It may be overkill, but maybe looking at the API of MarpaX::Languages::C::AST might be useful.