Skip to content

Commit

Permalink
parse javap -v output to get values of constant, use values in Perl6 …
Browse files Browse the repository at this point in the history
…generator
  • Loading branch information
philcrow authored and timbunce committed Aug 29, 2010
1 parent fc78911 commit 2923cba
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 5 deletions.
8 changes: 7 additions & 1 deletion lib/Java/Javap/Generator/Perl6.pm
Expand Up @@ -341,7 +341,13 @@ method [% elem.name -%]


[% END %] [% END %]
[% BLOCK constant_whole %] [% BLOCK constant_whole %]
method [% elem.name %] (--> [% elem.type.perl_type_name %]) is export { ... } method [% elem.name %] (--> [% elem.type.perl_type_name %]) is export { return [% IF elem.type.perl_type_name == 'Str'
%]'[% elem.value %]';[%
ELSIF elem.type.perl_type_name == 'Int' or
elem.type.perl_type_nmae == 'Num'
%][% elem.value %];[%
ELSE
%] ... [% END %] }
[% END %] [% END %]
EO_Template EO_Template
} }
Expand Down
23 changes: 19 additions & 4 deletions lib/Java/Javap/javap.grammar
Expand Up @@ -32,6 +32,7 @@ comp_unit_decl : ACCESS class_qualifier(s?)
CLASS_OR_INTERFACE qualified_name CLASS_OR_INTERFACE qualified_name
extends_clause(?) extends_clause(?)
implements_clause(?) implements_clause(?)
verbose_class_details(?)
{ {
my $perl_qualified_name = $item{ qualified_name }; my $perl_qualified_name = $item{ qualified_name };
$perl_qualified_name =~ s/\./::/g; $perl_qualified_name =~ s/\./::/g;
Expand All @@ -46,7 +47,9 @@ comp_unit_decl : ACCESS class_qualifier(s?)
} }
} }


class_qualifier : 'final' { 'final' } verbose_class_details : /[^{]*/

class_qualifier : 'final' { 'final' }
| 'abstract' { 'status' } | 'abstract' { 'status' }


extends_clause : 'extends' qualified_name { $item{ qualified_name } } extends_clause : 'extends' qualified_name { $item{ qualified_name } }
Expand All @@ -59,13 +62,15 @@ body_element : constant { $item[1] }
| method { $item[1] } | method { $item[1] }
| variable { $item[1] } | variable { $item[1] }


constant : ACCESS 'static' constant_modifier(s?) arg NAME ';' { constant : ACCESS 'static' constant_modifier(s?) arg NAME ';'
verbose_constant_details(?) {
{ {
body_element => 'constant', body_element => 'constant',
access => $item{ ACCESS }, access => $item{ ACCESS },
modifiers => $item{ 'constant_modifier(s?)' }, modifiers => $item{ 'constant_modifier(s?)' },
type => $item{ arg }[0], type => $item{ arg }[0],
name => $item{ NAME }, name => $item{ NAME },
value => $item{ 'verbose_constant_details(?)' }[0],
} }
} }
| 'static' 'transient' arg NAME ';' { | 'static' 'transient' arg NAME ';' {
Expand All @@ -76,11 +81,18 @@ constant : ACCESS 'static' constant_modifier(s?) arg NAME ';' {
} }
} }


verbose_constant_details : 'Constant' 'value:' arg constant_value {
$item{ constant_value }
}

constant_value : /[^\n]*/

constant_modifier : 'final' | 'transient' | 'volatile' constant_modifier : 'final' | 'transient' | 'volatile'


method : ACCESS method_qualifier(s?) method : ACCESS method_qualifier(s?)
arg NAME '(' arg_list(?) ')' arg NAME '(' arg_list(?) ')'
throws_clause(?) ';' { throws_clause(?) ';'
verbose_exceptions_details(?) {
$methods{ $item[4] }++; $methods{ $item[4] }++;
{ {
body_element => 'method', body_element => 'method',
Expand All @@ -93,7 +105,8 @@ method : ACCESS method_qualifier(s?)
} }
} }
| ACCESS /(native)?/ qualified_name '(' arg_list(?) ')' | ACCESS /(native)?/ qualified_name '(' arg_list(?) ')'
throws_clause(?) ';' { throws_clause(?) ';'
verbose_exceptions_details(?) {
$constructors++; $constructors++;
$methods{ 'new' }++; $methods{ 'new' }++;
{ {
Expand All @@ -112,6 +125,8 @@ method : ACCESS method_qualifier(s?)
} }
} }


verbose_exceptions_details : 'Exceptions:' throws_clause

method_qualifier : 'abstract' { 'abstract' } method_qualifier : 'abstract' { 'abstract' }
| 'native' { 'native' } | 'native' { 'native' }
| 'static' { 'static' } | 'static' { 'static' }
Expand Down

0 comments on commit 2923cba

Please sign in to comment.