Alt-Devel-GlobalDestruction-XS-Inline
view release on metacpan or search on metacpan
inc/Inline/C/Parser/RegExp.pm view on Meta::CPAN
use strict; use warnings;
package Inline::C::Parser::RegExp;
use Carp;
sub register {
{
extends => [qw(C)],
overrides => [qw(get_parser)],
}
}
sub get_parser {
Inline::C::_parser_test($_[0]->{CONFIG}{DIRECTORY}, "Inline::C::Parser::RegExp::get_parser called\n") if $_[0]->{CONFIG}{_TESTING};
bless {}, 'Inline::C::Parser::RegExp'
}
sub code {
my ($self,$code) = @_;
# These regular expressions were derived from Regexp::Common v0.01.
my $RE_comment_C = q{(?:(?:\/\*)(?:(?:(?!\*\/)[\s\S])*)(?:\*\/))};
my $RE_comment_Cpp = q{(?:\/\*(?:(?!\*\/)[\s\S])*\*\/|\/\/[^\n]*\n)};
my $RE_quoted = (
q{(?:(?:\")(?:[^\\\"]*(?:\\.[^\\\"]*)*)(?:\")}
. q{|(?:\')(?:[^\\\']*(?:\\.[^\\\']*)*)(?:\'))}
);
our $RE_balanced_brackets; $RE_balanced_brackets =
qr'(?:[{]((?:(?>[^{}]+)|(??{$RE_balanced_brackets}))*)[}])';
our $RE_balanced_parens; $RE_balanced_parens =
qr'(?:[(]((?:(?>[^()]+)|(??{$RE_balanced_parens}))*)[)])';
# First, we crush out anything potentially confusing.
# The order of these _does_ matter.
$code =~ s/$RE_comment_C/ /go;
$code =~ s/$RE_comment_Cpp/ /go;
$code =~ s/^\#.*(\\\n.*)*//mgo;
#$code =~ s/$RE_quoted/\"\"/go; # Buggy, if included.
$code =~ s/$RE_balanced_brackets/{ }/go;
$self->{_the_code_most_recently_parsed} = $code; # Simplifies debugging.
my $normalize_type = sub {
# Normalize a type for lookup in a typemap.
my($type) = @_;
# Remove "extern".
# But keep "static", "inline", "typedef", etc,
# to cause desirable typemap misses.
$type =~ s/\bextern\b//g;
# Whitespace: only single spaces, none leading or trailing.
$type =~ s/\s+/ /g;
$type =~ s/^\s//; $type =~ s/\s$//;
# Adjacent "derivative characters" are not separated by whitespace,
# but _are_ separated from the adjoining text.
# [ Is really only * (and not ()[]) needed??? ]
$type =~ s/\*\s\*/\*\*/g;
$type =~ s/(?<=[^ \*])\*/ \*/g;
return $type;
};
# The decision of what is an acceptable declaration was originally
# derived from Inline::C::grammar.pm version 0.30 (Inline 0.43).
my $re_plausible_place_to_begin_a_declaration = qr {
# The beginning of a line, possibly indented.
# (Accepting indentation allows for C code to be aligned with
# its surrounding perl, and for backwards compatibility with
# Inline 0.43).
(?m: ^ ) \s*
}xo;
( run in 1.822 second using v1.01-cache-2.11-cpan-d8267643d1d )