Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Newer
Older
100755 148 lines (126 sloc) 4.65 kb
a406b21 Fixed args element in tree so it is always an array ref of hashlets.
crow.phil authored
1 # To build this:
2 # perl -MParse::RecDescent - javap.grammar Java::Javap::Grammar
3
b0431eb Added constructor count and method counts to AST.
crow.phil authored
4 {
5 my %methods;
6 my $constructors;
7 }
8
9c01d2a Brought in a reorganized namespaces of modules.
crow.phil authored
9 comp_unit : comp_stmt
10 comp_unit_decl '{' body '}' {
11 my $retval = $item{ comp_unit_decl };
12 $retval->{ compiled_from } = "$item{ comp_stmt }.java";
13 $retval->{ contents } = $item{ body };
b0431eb Added constructor count and method counts to AST.
crow.phil authored
14 $retval->{ methods } = \%methods;
15 $retval->{ constructors } = $constructors;
9c01d2a Brought in a reorganized namespaces of modules.
crow.phil authored
16 $retval;
17 }
18 | <error>
19
20 comp_stmt : 'Compiled from "' NAME '.java"' { $item{NAME} }
21
22 comp_unit_decl : ACCESS class_qualifier(?)
23 CLASS_OR_INTERFACE qualified_name
24 extends_clause(?)
25 implements_clause(?)
26 {
27 {
28 access => $item{ ACCESS },
29 final => $item{ 'class_qualifier(?)' }[0],
30 class_or_interface => $item{ CLASS_OR_INTERFACE },
31 implements => $item{ 'implements_clause(?)' }[0],
32 parent => $item{ 'extends_clause(?)' }[0],
33 qualified_name => $item{ qualified_name },
34 }
35 }
36
37 class_qualifier : 'final' { 'final' }
38
39 extends_clause : 'extends' qualified_name { $item{ qualified_name } }
40 implements_clause : 'implements' comma_list { $item{ comma_list } }
41
42 body : body_element(s) { $item[1] }
43
44 body_element : constant { $item[1] }
45 | 'static' '{' '}' ';' { { body_element => 'static_block' } }
46 | method { $item[1] }
47
48 constant : ACCESS 'static' /(final)?/ qualified_name NAME ';' {
49 {
50 body_element => 'constant',
51 access => $item[1],
52 final => ( $item[3] eq 'final' ) ? 'final' : '',
53 type => $item[4],
54 name => $item[5],
55 }
56 }
57
58 method : ACCESS method_qualifier(s?)
59 arg NAME '(' arg_list(?) ')'
60 throws_clause(?) ';' {
b0431eb Added constructor count and method counts to AST.
crow.phil authored
61 $methods{ $item[4] }++;
a406b21 Fixed args element in tree so it is always an array ref of hashlets.
crow.phil authored
62 my $args = $item{ 'arg_list(?)' }[0];
63 $args = [] unless defined $args;
9c01d2a Brought in a reorganized namespaces of modules.
crow.phil authored
64 {
65 body_element => 'method',
66 access => $item[1],
67 attrs => $item[2],
e85e18c Corrected returned value in AST so it is always a single hashlet.
crow.phil authored
68 returns => $item[3][0],
9c01d2a Brought in a reorganized namespaces of modules.
crow.phil authored
69 name => $item[4],
a406b21 Fixed args element in tree so it is always an array ref of hashlets.
crow.phil authored
70 args => $args,
9c01d2a Brought in a reorganized namespaces of modules.
crow.phil authored
71 throws => $item{ 'throws_clause(?)' },
72 }
73 }
74 | ACCESS /(native)?/ qualified_name '(' arg_list(?) ')'
75 throws_clause(?) ';' {
b0431eb Added constructor count and method counts to AST.
crow.phil authored
76 $constructors++;
a406b21 Fixed args element in tree so it is always an array ref of hashlets.
crow.phil authored
77 my $args = $item{ 'arg_list(?)' }[0];
78 $args = [] unless defined $args;
9c01d2a Brought in a reorganized namespaces of modules.
crow.phil authored
79 {
80 body_element => 'constructor',
81 access => $item[1],
82 native => ( $item[2] eq 'native' ) ? 'native' : '',
a406b21 Fixed args element in tree so it is always an array ref of hashlets.
crow.phil authored
83 args => $args,
9c01d2a Brought in a reorganized namespaces of modules.
crow.phil authored
84 throws => $item{ 'throws_clause(?)' },
85 }
86 }
87
88 method_qualifier : 'abstract' { 'abstract' }
89 | 'native' { 'native' }
90 | 'static' { 'static' }
91
92 throws_clause : 'throws' comma_list { $item{comma_list} }
93 qualified_name : NAME '.' qualified_name
94 { "$item{NAME}.$item{qualified_name}" }
95 | NAME '.' NAME { "$item[1].$item[3]" }
96 | NAME { $item[1] }
97
98 comma_list : qualified_name ',' comma_list {
99 my @names = ( $item[1] );
100 if ( ref( $item[3] ) eq 'ARRAY' ) {
101 push @names, @{ $item[3] };
102 }
103 else {
104 push @names, $item[3];
105 }
106 \@names;
107 }
108 | qualified_name ',' qualified_name { [ $item[1], $item[3] ] }
109 | qualified_name { $item[1] }
110
a406b21 Fixed args element in tree so it is always an array ref of hashlets.
crow.phil authored
111 arg_list : arg ',' arg_list { [ @{ $item[1] }, @{ $item[3] } ] }
112 | arg ',' arg { [ @{ $item[1] }, @{ $item[3] } ] }
9c01d2a Brought in a reorganized namespaces of modules.
crow.phil authored
113 | arg { $item[1] }
114
115 arg : qualified_name array_depth {
42d8440 Added array type text to AST to save effort in generation.
crow.phil authored
116 my $array_text = '';
117 foreach my $i ( 1 .. $item[2] ) {
118 $array_text .= 'Array of ';
119 }
a406b21 Fixed args element in tree so it is always an array ref of hashlets.
crow.phil authored
120 [
121 {
122 name => $item[1],
123 array_depth => $item[2],
42d8440 Added array type text to AST to save effort in generation.
crow.phil authored
124 array_text => $array_text,
a406b21 Fixed args element in tree so it is always an array ref of hashlets.
crow.phil authored
125 }
126 ]
9c01d2a Brought in a reorganized namespaces of modules.
crow.phil authored
127 }
128
129 array_depth : ARRAY_LEVEL(s?) {
130 my $depth = scalar @{ $item[1] };
131 $depth;
132 }
133
134 ARRAY_LEVEL : '[]' { 1 }
135
136 NAME : /^([\w\d]+)/ { $1 }
137
138 ACCESS : 'public' { $item[1] }
139 | 'protected' { $item[1] }
140 | 'private' { $item[1] }
141 | { '' }
142
143 CLASS_OR_INTERFACE : 'class' { $item[1] }
144 | 'interface' { $item[1] }
145
146 comment : '/*' /[^*]*/ '*/' {}
147 |
Something went wrong with that request. Please try again.