The Perl and Raku Conference 2025: Greenville, South Carolina - June 27-29 Learn more

use strict;
use warnings FATAL => 'all';
use Moo;
# ABSTRACT: Parsing an array of attribute
our $VERSION = '0.009'; # VERSION
our $AUTHORITY = 'cpan:JDDPAUSE'; # AUTHORITY
use Carp qw/croak/;
use Data::Section -setup;
use Scalar::Util qw/blessed/;
#
# require because we do not import ANYTHING from these module, just require they are loaded
#
require Marpa::R2;
my $_data = ${ __PACKAGE__->section_data('bnf') };
my $_grammar = Marpa::R2::Scanless::G->new( { source => \__PACKAGE__->bnf($_data) } );
# --------------------------------------------------
# What role MarpaX::Java::ClassFile::Common requires
# --------------------------------------------------
sub grammar { $_grammar }
sub callbacks {
return {
"'exhausted" => sub { $_[0]->exhausted },
'attribute_info$' => sub { $_[0]->inc_nbDone },
'^U2' => sub {
#
# There is a subtility here: All known attributes DO fit in the ASCII table.
# From perl point of view, input is a sequence of Bytes, which is Str compatible.
# There is no need to do modified UTF-8 to Perl's UTF8 conversion when we want
# to check that a sequence of Bytes is equal to a Str Containing only ASCII things,
# because ASCII characters all fit in a single byte.
#
my $u2 = $_[0]->pauseU2;
my $attribute_name = '';
if (($u2 >= 1) && ($u2 <= $_[0]->constant_pool_count)) {
my $constant = $_[0]->constant_pool->[$u2];
my $blessed = blessed($constant) // '';
if ($blessed eq 'MarpaX::Java::ClassFile::Struct::ConstantUtf8Info') {
$attribute_name = $constant->bytes;
}
}
if ($attribute_name eq 'ConstantValue') { $_[0]->inner('ConstantValueAttribute') }
elsif ($attribute_name eq 'Code') { $_[0]->inner('CodeAttribute') }
elsif ($attribute_name eq 'StackMapTable') { $_[0]->inner('StackMapTableAttribute') }
elsif ($attribute_name eq 'Exceptions') { $_[0]->inner('ExceptionsAttribute') }
elsif ($attribute_name eq 'InnerClasses') { $_[0]->inner('InnerClassesAttribute') }
elsif ($attribute_name eq 'EnclosingMethod') { $_[0]->inner('EnclosingMethodAttribute') }
elsif ($attribute_name eq 'Synthetic') { $_[0]->inner('SyntheticAttribute') }
elsif ($attribute_name eq 'Signature') { $_[0]->inner('SignatureAttribute') }
elsif ($attribute_name eq 'SourceFile') { $_[0]->inner('SourceFileAttribute') }
elsif ($attribute_name eq 'SourceDebugExtension') { $_[0]->inner('SourceDebugExtensionAttribute') }
elsif ($attribute_name eq 'LineNumberTable') { $_[0]->inner('LineNumberTableAttribute') }
elsif ($attribute_name eq 'LocalVariableTable') { $_[0]->inner('LocalVariableTableAttribute') }
elsif ($attribute_name eq 'LocalVariableTypeTable') { $_[0]->inner('LocalVariableTypeTableAttribute') }
elsif ($attribute_name eq 'Deprecated') { $_[0]->inner('DeprecatedAttribute') }
elsif ($attribute_name eq 'RuntimeVisibleAnnotations') { $_[0]->inner('RuntimeVisibleAnnotationsAttribute') }
elsif ($attribute_name eq 'RuntimeInvisibleAnnotations') { $_[0]->inner('RuntimeInvisibleAnnotationsAttribute') }
elsif ($attribute_name eq 'RuntimeVisibleParameterAnnotations') { $_[0]->inner('RuntimeVisibleParameterAnnotationsAttribute') }
elsif ($attribute_name eq 'RuntimeInvisibleParameterAnnotations') { $_[0]->inner('RuntimeInvisibleParameterAnnotationsAttribute') }
elsif ($attribute_name eq 'RuntimeVisibleTypeAnnotations') { $_[0]->inner('RuntimeVisibleTypeAnnotationsAttribute') }
elsif ($attribute_name eq 'RuntimeInvisibleTypeAnnotations') { $_[0]->inner('RuntimeInvisibleTypeAnnotationsAttribute') }
elsif ($attribute_name eq 'AnnotationDefault') { $_[0]->inner('AnnotationDefaultAttribute') }
elsif ($attribute_name eq 'BootstrapMethods') { $_[0]->inner('BootstrapMethodsAttribute') }
elsif ($attribute_name eq 'MethodParameters') { $_[0]->inner('MethodParametersAttribute') }
else {
$_[0]->infof('Unmanaged attribute %s', $attribute_name);
$_[0]->inner('UnmanagedAttribute')
}
}
}
}
1;
=pod
=encoding UTF-8
=head1 NAME
MarpaX::Java::ClassFile::BNF::AttributesArray - Parsing an array of attribute
=head1 VERSION
version 0.009
=head1 AUTHOR
Jean-Damien Durand <jeandamiendurand@free.fr>
=head1 COPYRIGHT AND LICENSE
This software is copyright (c) 2016 by Jean-Damien Durand.
This is free software; you can redistribute it and/or modify it under
the same terms as the Perl 5 programming language system itself.
=cut
__DATA__
__[ bnf ]__
:default ::= action => [values]
:lexeme ~ <U2> pause => before event => '^U2'
event 'attribute_info$' = completed attribute_info
attributesArray ::= attribute_info*
attribute_info ::= U2
| MANAGED action => ::first