ParseTreeReloaded 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- data/GPL.txt +342 -0
- data/lib/parse_tree_reloaded.rb +372 -0
- data/lib/sexp.rb +20 -0
- data/lib/sexp_processor.rb +12 -0
- metadata +57 -0
data/GPL.txt
ADDED
@@ -0,0 +1,342 @@
|
|
1
|
+
The GNU General Public License (GPL)
|
2
|
+
Version 2, June 1991
|
3
|
+
|
4
|
+
Copyright (C) 1989, 1991 Free Software Foundation, Inc.
|
5
|
+
|
6
|
+
59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
7
|
+
|
8
|
+
Everyone is permitted to copy and distribute verbatim copies
|
9
|
+
of this license document, but changing it is not allowed.
|
10
|
+
|
11
|
+
Preamble
|
12
|
+
|
13
|
+
The licenses for most software are designed to take away your
|
14
|
+
freedom to share and change it. By contrast, the GNU General Public
|
15
|
+
License is intended to guarantee your freedom to share and change free
|
16
|
+
software--to make sure the software is free for all its users. This
|
17
|
+
General Public License applies to most of the Free Software
|
18
|
+
Foundation's software and to any other program whose authors commit to
|
19
|
+
using it. (Some other Free Software Foundation software is covered by
|
20
|
+
the GNU Library General Public License instead.) You can apply it to
|
21
|
+
your programs, too.
|
22
|
+
|
23
|
+
When we speak of free software, we are referring to freedom, not
|
24
|
+
price. Our General Public Licenses are designed to make sure that you
|
25
|
+
have the freedom to distribute copies of free software (and charge for
|
26
|
+
this service if you wish), that you receive source code or can get it
|
27
|
+
if you want it, that you can change the software or use pieces of it
|
28
|
+
in new free programs; and that you know you can do these things.
|
29
|
+
|
30
|
+
To protect your rights, we need to make restrictions that forbid
|
31
|
+
anyone to deny you these rights or to ask you to surrender the rights.
|
32
|
+
These restrictions translate to certain responsibilities for you if you
|
33
|
+
distribute copies of the software, or if you modify it.
|
34
|
+
|
35
|
+
For example, if you distribute copies of such a program, whether
|
36
|
+
gratis or for a fee, you must give the recipients all the rights that
|
37
|
+
you have. You must make sure that they, too, receive or can get the
|
38
|
+
source code. And you must show them these terms so they know their
|
39
|
+
rights.
|
40
|
+
|
41
|
+
We protect your rights with two steps: (1) copyright the software, and
|
42
|
+
(2) offer you this license which gives you legal permission to copy,
|
43
|
+
distribute and/or modify the software.
|
44
|
+
|
45
|
+
Also, for each author's protection and ours, we want to make certain
|
46
|
+
that everyone understands that there is no warranty for this free
|
47
|
+
software. If the software is modified by someone else and passed on, we
|
48
|
+
want its recipients to know that what they have is not the original, so
|
49
|
+
that any problems introduced by others will not reflect on the original
|
50
|
+
authors' reputations.
|
51
|
+
|
52
|
+
Finally, any free program is threatened constantly by software
|
53
|
+
patents. We wish to avoid the danger that redistributors of a free
|
54
|
+
program will individually obtain patent licenses, in effect making the
|
55
|
+
program proprietary. To prevent this, we have made it clear that any
|
56
|
+
patent must be licensed for everyone's free use or not licensed at all.
|
57
|
+
|
58
|
+
The precise terms and conditions for copying, distribution and
|
59
|
+
modification follow.
|
60
|
+
|
61
|
+
TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION
|
62
|
+
|
63
|
+
0. This License applies to any program or other work which contains
|
64
|
+
a notice placed by the copyright holder saying it may be distributed
|
65
|
+
under the terms of this General Public License. The "Program", below,
|
66
|
+
refers to any such program or work, and a "work based on the Program"
|
67
|
+
means either the Program or any derivative work under copyright law:
|
68
|
+
that is to say, a work containing the Program or a portion of it,
|
69
|
+
either verbatim or with modifications and/or translated into another
|
70
|
+
language. (Hereinafter, translation is included without limitation in
|
71
|
+
the term "modification".) Each licensee is addressed as "you".
|
72
|
+
|
73
|
+
Activities other than copying, distribution and modification are not
|
74
|
+
covered by this License; they are outside its scope. The act of
|
75
|
+
running the Program is not restricted, and the output from the Program
|
76
|
+
is covered only if its contents constitute a work based on the
|
77
|
+
Program (independent of having been made by running the Program).
|
78
|
+
Whether that is true depends on what the Program does.
|
79
|
+
|
80
|
+
1. You may copy and distribute verbatim copies of the Program's
|
81
|
+
source code as you receive it, in any medium, provided that you
|
82
|
+
conspicuously and appropriately publish on each copy an appropriate
|
83
|
+
copyright notice and disclaimer of warranty; keep intact all the
|
84
|
+
notices that refer to this License and to the absence of any warranty;
|
85
|
+
and give any other recipients of the Program a copy of this License
|
86
|
+
along with the Program.
|
87
|
+
|
88
|
+
You may charge a fee for the physical act of transferring a copy, and
|
89
|
+
you may at your option offer warranty protection in exchange for a fee.
|
90
|
+
|
91
|
+
2. You may modify your copy or copies of the Program or any portion
|
92
|
+
of it, thus forming a work based on the Program, and copy and
|
93
|
+
distribute such modifications or work under the terms of Section 1
|
94
|
+
above, provided that you also meet all of these conditions:
|
95
|
+
|
96
|
+
a) You must cause the modified files to carry prominent notices
|
97
|
+
stating that you changed the files and the date of any change.
|
98
|
+
|
99
|
+
b) You must cause any work that you distribute or publish, that in
|
100
|
+
whole or in part contains or is derived from the Program or any
|
101
|
+
part thereof, to be licensed as a whole at no charge to all third
|
102
|
+
parties under the terms of this License.
|
103
|
+
|
104
|
+
c) If the modified program normally reads commands interactively
|
105
|
+
when run, you must cause it, when started running for such
|
106
|
+
interactive use in the most ordinary way, to print or display an
|
107
|
+
announcement including an appropriate copyright notice and a
|
108
|
+
notice that there is no warranty (or else, saying that you provide
|
109
|
+
a warranty) and that users may redistribute the program under
|
110
|
+
these conditions, and telling the user how to view a copy of this
|
111
|
+
License. (Exception: if the Program itself is interactive but
|
112
|
+
does not normally print such an announcement, your work based on
|
113
|
+
the Program is not required to print an announcement.)
|
114
|
+
|
115
|
+
These requirements apply to the modified work as a whole. If
|
116
|
+
identifiable sections of that work are not derived from the Program,
|
117
|
+
and can be reasonably considered independent and separate works in
|
118
|
+
themselves, then this License, and its terms, do not apply to those
|
119
|
+
sections when you distribute them as separate works. But when you
|
120
|
+
distribute the same sections as part of a whole which is a work based
|
121
|
+
on the Program, the distribution of the whole must be on the terms of
|
122
|
+
this License, whose permissions for other licensees extend to the
|
123
|
+
entire whole, and thus to each and every part regardless of who wrote it.
|
124
|
+
|
125
|
+
Thus, it is not the intent of this section to claim rights or contest
|
126
|
+
your rights to work written entirely by you; rather, the intent is to
|
127
|
+
exercise the right to control the distribution of derivative or
|
128
|
+
collective works based on the Program.
|
129
|
+
|
130
|
+
In addition, mere aggregation of another work not based on the Program
|
131
|
+
with the Program (or with a work based on the Program) on a volume of
|
132
|
+
a storage or distribution medium does not bring the other work under
|
133
|
+
the scope of this License.
|
134
|
+
|
135
|
+
3. You may copy and distribute the Program (or a work based on it,
|
136
|
+
under Section 2) in object code or executable form under the terms of
|
137
|
+
Sections 1 and 2 above provided that you also do one of the following:
|
138
|
+
|
139
|
+
a) Accompany it with the complete corresponding machine-readable
|
140
|
+
source code, which must be distributed under the terms of Sections
|
141
|
+
1 and 2 above on a medium customarily used for software interchange; or,
|
142
|
+
|
143
|
+
b) Accompany it with a written offer, valid for at least three
|
144
|
+
years, to give any third party, for a charge no more than your
|
145
|
+
cost of physically performing source distribution, a complete
|
146
|
+
machine-readable copy of the corresponding source code, to be
|
147
|
+
distributed under the terms of Sections 1 and 2 above on a medium
|
148
|
+
customarily used for software interchange; or,
|
149
|
+
|
150
|
+
c) Accompany it with the information you received as to the offer
|
151
|
+
to distribute corresponding source code. (This alternative is
|
152
|
+
allowed only for noncommercial distribution and only if you
|
153
|
+
received the program in object code or executable form with such
|
154
|
+
an offer, in accord with Subsection b above.)
|
155
|
+
|
156
|
+
The source code for a work means the preferred form of the work for
|
157
|
+
making modifications to it. For an executable work, complete source
|
158
|
+
code means all the source code for all modules it contains, plus any
|
159
|
+
associated interface definition files, plus the scripts used to
|
160
|
+
control compilation and installation of the executable. However, as a
|
161
|
+
special exception, the source code distributed need not include
|
162
|
+
anything that is normally distributed (in either source or binary
|
163
|
+
form) with the major components (compiler, kernel, and so on) of the
|
164
|
+
operating system on which the executable runs, unless that component
|
165
|
+
itself accompanies the executable.
|
166
|
+
|
167
|
+
If distribution of executable or object code is made by offering
|
168
|
+
access to copy from a designated place, then offering equivalent
|
169
|
+
access to copy the source code from the same place counts as
|
170
|
+
distribution of the source code, even though third parties are not
|
171
|
+
compelled to copy the source along with the object code.
|
172
|
+
|
173
|
+
4. You may not copy, modify, sublicense, or distribute the Program
|
174
|
+
except as expressly provided under this License. Any attempt
|
175
|
+
otherwise to copy, modify, sublicense or distribute the Program is
|
176
|
+
void, and will automatically terminate your rights under this License.
|
177
|
+
However, parties who have received copies, or rights, from you under
|
178
|
+
this License will not have their licenses terminated so long as such
|
179
|
+
parties remain in full compliance.
|
180
|
+
|
181
|
+
5. You are not required to accept this License, since you have not
|
182
|
+
signed it. However, nothing else grants you permission to modify or
|
183
|
+
distribute the Program or its derivative works. These actions are
|
184
|
+
prohibited by law if you do not accept this License. Therefore, by
|
185
|
+
modifying or distributing the Program (or any work based on the
|
186
|
+
Program), you indicate your acceptance of this License to do so, and
|
187
|
+
all its terms and conditions for copying, distributing or modifying
|
188
|
+
the Program or works based on it.
|
189
|
+
|
190
|
+
6. Each time you redistribute the Program (or any work based on the
|
191
|
+
Program), the recipient automatically receives a license from the
|
192
|
+
original licensor to copy, distribute or modify the Program subject to
|
193
|
+
these terms and conditions. You may not impose any further
|
194
|
+
restrictions on the recipients' exercise of the rights granted herein.
|
195
|
+
You are not responsible for enforcing compliance by third parties to
|
196
|
+
this License.
|
197
|
+
|
198
|
+
7. If, as a consequence of a court judgment or allegation of patent
|
199
|
+
infringement or for any other reason (not limited to patent issues),
|
200
|
+
conditions are imposed on you (whether by court order, agreement or
|
201
|
+
otherwise) that contradict the conditions of this License, they do not
|
202
|
+
excuse you from the conditions of this License. If you cannot
|
203
|
+
distribute so as to satisfy simultaneously your obligations under this
|
204
|
+
License and any other pertinent obligations, then as a consequence you
|
205
|
+
may not distribute the Program at all. For example, if a patent
|
206
|
+
license would not permit royalty-free redistribution of the Program by
|
207
|
+
all those who receive copies directly or indirectly through you, then
|
208
|
+
the only way you could satisfy both it and this License would be to
|
209
|
+
refrain entirely from distribution of the Program.
|
210
|
+
|
211
|
+
If any portion of this section is held invalid or unenforceable under
|
212
|
+
any particular circumstance, the balance of the section is intended to
|
213
|
+
apply and the section as a whole is intended to apply in other
|
214
|
+
circumstances.
|
215
|
+
|
216
|
+
It is not the purpose of this section to induce you to infringe any
|
217
|
+
patents or other property right claims or to contest validity of any
|
218
|
+
such claims; this section has the sole purpose of protecting the
|
219
|
+
integrity of the free software distribution system, which is
|
220
|
+
implemented by public license practices. Many people have made
|
221
|
+
generous contributions to the wide range of software distributed
|
222
|
+
through that system in reliance on consistent application of that
|
223
|
+
system; it is up to the author/donor to decide if he or she is willing
|
224
|
+
to distribute software through any other system and a licensee cannot
|
225
|
+
impose that choice.
|
226
|
+
|
227
|
+
This section is intended to make thoroughly clear what is believed to
|
228
|
+
be a consequence of the rest of this License.
|
229
|
+
|
230
|
+
8. If the distribution and/or use of the Program is restricted in
|
231
|
+
certain countries either by patents or by copyrighted interfaces, the
|
232
|
+
original copyright holder who places the Program under this License
|
233
|
+
may add an explicit geographical distribution limitation excluding
|
234
|
+
those countries, so that distribution is permitted only in or among
|
235
|
+
countries not thus excluded. In such case, this License incorporates
|
236
|
+
the limitation as if written in the body of this License.
|
237
|
+
|
238
|
+
9. The Free Software Foundation may publish revised and/or new versions
|
239
|
+
of the General Public License from time to time. Such new versions will
|
240
|
+
be similar in spirit to the present version, but may differ in detail to
|
241
|
+
address new problems or concerns.
|
242
|
+
|
243
|
+
Each version is given a distinguishing version number. If the Program
|
244
|
+
specifies a version number of this License which applies to it and "any
|
245
|
+
later version", you have the option of following the terms and conditions
|
246
|
+
either of that version or of any later version published by the Free
|
247
|
+
Software Foundation. If the Program does not specify a version number of
|
248
|
+
this License, you may choose any version ever published by the Free Software
|
249
|
+
Foundation.
|
250
|
+
|
251
|
+
10. If you wish to incorporate parts of the Program into other free
|
252
|
+
programs whose distribution conditions are different, write to the author
|
253
|
+
to ask for permission. For software which is copyrighted by the Free
|
254
|
+
Software Foundation, write to the Free Software Foundation; we sometimes
|
255
|
+
make exceptions for this. Our decision will be guided by the two goals
|
256
|
+
of preserving the free status of all derivatives of our free software and
|
257
|
+
of promoting the sharing and reuse of software generally.
|
258
|
+
|
259
|
+
NO WARRANTY
|
260
|
+
|
261
|
+
11. BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY
|
262
|
+
FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN
|
263
|
+
OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES
|
264
|
+
PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED
|
265
|
+
OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
|
266
|
+
MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS
|
267
|
+
TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE
|
268
|
+
PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING,
|
269
|
+
REPAIR OR CORRECTION.
|
270
|
+
|
271
|
+
12. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING
|
272
|
+
WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR
|
273
|
+
REDISTRIBUTE THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES,
|
274
|
+
INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING
|
275
|
+
OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED
|
276
|
+
TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY
|
277
|
+
YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER
|
278
|
+
PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE
|
279
|
+
POSSIBILITY OF SUCH DAMAGES.
|
280
|
+
|
281
|
+
END OF TERMS AND CONDITIONS
|
282
|
+
|
283
|
+
How to Apply These Terms to Your New Programs
|
284
|
+
|
285
|
+
If you develop a new program, and you want it to be of the greatest
|
286
|
+
possible use to the public, the best way to achieve this is to make it
|
287
|
+
free software which everyone can redistribute and change under these terms.
|
288
|
+
|
289
|
+
To do so, attach the following notices to the program. It is safest
|
290
|
+
to attach them to the start of each source file to most effectively
|
291
|
+
convey the exclusion of warranty; and each file should have at least
|
292
|
+
the "copyright" line and a pointer to where the full notice is found.
|
293
|
+
|
294
|
+
One line to give the program's name and a brief idea of what it does.
|
295
|
+
|
296
|
+
Copyright (C) <year> <name of author>
|
297
|
+
|
298
|
+
This program is free software; you can redistribute it and/or modify
|
299
|
+
it under the terms of the GNU General Public License as published by
|
300
|
+
the Free Software Foundation; either version 2 of the License, or
|
301
|
+
(at your option) any later version.
|
302
|
+
|
303
|
+
This program is distributed in the hope that it will be useful,
|
304
|
+
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
305
|
+
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
306
|
+
GNU General Public License for more details.
|
307
|
+
|
308
|
+
You should have received a copy of the GNU General Public License
|
309
|
+
along with this program; if not, write to the Free Software
|
310
|
+
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
311
|
+
|
312
|
+
Also add information on how to contact you by electronic and paper mail.
|
313
|
+
|
314
|
+
If the program is interactive, make it output a short notice like this
|
315
|
+
when it starts in an interactive mode:
|
316
|
+
|
317
|
+
Gnomovision version 69, Copyright (C) year name of author
|
318
|
+
Gnomovision comes with ABSOLUTELY NO WARRANTY; for details type `show w'.
|
319
|
+
This is free software, and you are welcome to redistribute it
|
320
|
+
under certain conditions; type `show c' for details.
|
321
|
+
|
322
|
+
The hypothetical commands `show w' and `show c' should show the appropriate
|
323
|
+
parts of the General Public License. Of course, the commands you use may
|
324
|
+
be called something other than `show w' and `show c'; they could even be
|
325
|
+
mouse-clicks or menu items--whatever suits your program.
|
326
|
+
|
327
|
+
You should also get your employer (if you work as a programmer) or your
|
328
|
+
school, if any, to sign a "copyright disclaimer" for the program, if
|
329
|
+
necessary. Here is a sample; alter the names:
|
330
|
+
|
331
|
+
Yoyodyne, Inc., hereby disclaims all copyright interest in the program
|
332
|
+
`Gnomovision' (which makes passes at compilers) written by James Hacker.
|
333
|
+
|
334
|
+
signature of Ty Coon, 1 April 1989
|
335
|
+
|
336
|
+
Ty Coon, President of Vice
|
337
|
+
|
338
|
+
This General Public License does not permit incorporating your program into
|
339
|
+
proprietary programs. If your program is a subroutine library, you may
|
340
|
+
consider it more useful to permit linking proprietary applications with the
|
341
|
+
library. If this is what you want to do, use the GNU Library General
|
342
|
+
Public License instead of this License.
|
@@ -0,0 +1,372 @@
|
|
1
|
+
# Copyright (C) 2007 Richard Musiol
|
2
|
+
#
|
3
|
+
# This program is free software; you can redistribute it and/or modify
|
4
|
+
# it under the terms of the GNU General Public License as published by
|
5
|
+
# the Free Software Foundation; either version 2 of the License, or
|
6
|
+
# (at your option) any later version.
|
7
|
+
#
|
8
|
+
# This program is distributed in the hope that it will be useful,
|
9
|
+
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
10
|
+
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
11
|
+
# GNU General Public License for more details.
|
12
|
+
#
|
13
|
+
# You should have received a copy of the GNU General Public License
|
14
|
+
# along with this program; if not, write to the Free Software
|
15
|
+
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
16
|
+
|
17
|
+
require 'inline_acceleration'
|
18
|
+
require 'sexp'
|
19
|
+
|
20
|
+
class ParseTree
|
21
|
+
inline do |builder|
|
22
|
+
builder.include('"ruby.h"')
|
23
|
+
builder.include('"st.h"')
|
24
|
+
builder.include('"node.h"')
|
25
|
+
builder.include('"env.h"')
|
26
|
+
|
27
|
+
builder.prefix <<-CODE_END
|
28
|
+
#define nd_3rd u3.node
|
29
|
+
#define nd_u1id u1.id
|
30
|
+
#define nd_u2id u2.id
|
31
|
+
|
32
|
+
struct BLOCK {
|
33
|
+
NODE *var;
|
34
|
+
NODE *body;
|
35
|
+
VALUE self;
|
36
|
+
struct FRAME frame;
|
37
|
+
struct SCOPE *scope;
|
38
|
+
VALUE klass;
|
39
|
+
NODE *cref;
|
40
|
+
int iter;
|
41
|
+
int vmode;
|
42
|
+
int flags;
|
43
|
+
int uniq;
|
44
|
+
struct RVarmap *dyna_vars;
|
45
|
+
VALUE orig_thread;
|
46
|
+
VALUE wrapper;
|
47
|
+
VALUE block_obj;
|
48
|
+
struct BLOCK *outer;
|
49
|
+
struct BLOCK *prev;
|
50
|
+
};
|
51
|
+
CODE_END
|
52
|
+
|
53
|
+
builder.link_function('NODE *', 'rb_compile_string', ['char *', 'VALUE', 'int'])
|
54
|
+
builder.link_function('ID', 'rb_to_id', ['VALUE'])
|
55
|
+
builder.link_function('struct RClass *', 'RCLASS', ['VALUE'])
|
56
|
+
builder.link_function('NODE *', 'RNODE', ['long'])
|
57
|
+
builder.link_function('int', 'st_lookup', ['st_table *', 'st_data_t', 'st_data_t *']);
|
58
|
+
builder.link_function('int', 'nd_type', ['NODE *']);
|
59
|
+
builder.link_function('int', 'nd_line', ['NODE *']);
|
60
|
+
builder.link_function('VALUE', 'ID2SYM', ['ID']);
|
61
|
+
builder.link_function('NODE *', 'NEW_SELF', []);
|
62
|
+
builder.link_function('void *', 'DATA_PTR', ['VALUE']);
|
63
|
+
|
64
|
+
builder.link_fields('struct RClass', {'m_tbl' => 'st_table *'})
|
65
|
+
builder.link_fields('struct BLOCK', {'var' => 'NODE *', 'body' => 'NODE *'})
|
66
|
+
builder.link_fields('NODE', {'nd_file' => 'char *', 'nd_mid' => 'ID', 'nd_vid' => 'ID', 'nd_u1id' => 'ID', 'nd_u2id' => 'ID', 'nd_lit' => 'VALUE', 'nd_cnt' => 'long', 'nd_rest' => 'long', 'nd_nth' => 'long', 'nd_tbl' => 'ID *', 'nd_body' => 'NODE *', 'nd_next' => 'NODE *', 'nd_head' => 'NODE *', 'nd_cpath' => 'NODE *', 'nd_super' => 'NODE *', 'nd_defn' => 'NODE *', 'nd_recv' => 'NODE *', 'nd_value' => 'NODE *', 'nd_args' => 'NODE *', 'nd_cond' => 'NODE *', 'nd_else' => 'NODE *', 'nd_iter' => 'NODE *', 'nd_var' => 'NODE *', 'nd_opt' => 'NODE *', 'nd_stts' => 'NODE *', 'nd_1st' => 'NODE *', 'nd_2nd' => 'NODE *', 'nd_3rd' => 'NODE *', 'nd_cval' => 'VALUE'})
|
67
|
+
|
68
|
+
builder.link_constants('int', ['NODE_METHOD', 'NODE_FBODY', 'NODE_CFUNC', 'NODE_SCOPE', 'NODE_BLOCK', 'NODE_IF', 'NODE_CASE', 'NODE_WHEN', 'NODE_OPT_N', 'NODE_WHILE', 'NODE_UNTIL', 'NODE_ITER', 'NODE_FOR', 'NODE_BREAK', 'NODE_NEXT', 'NODE_REDO', 'NODE_RETRY', 'NODE_BEGIN', 'NODE_RESCUE', 'NODE_RESBODY', 'NODE_ENSURE', 'NODE_AND', 'NODE_OR', 'NODE_NOT', 'NODE_MASGN', 'NODE_LASGN', 'NODE_DASGN', 'NODE_DASGN_CURR', 'NODE_GASGN', 'NODE_IASGN', 'NODE_CDECL', 'NODE_CVASGN', 'NODE_CVDECL', 'NODE_OP_ASGN1', 'NODE_OP_ASGN2', 'NODE_OP_ASGN_AND', 'NODE_OP_ASGN_OR', 'NODE_CALL', 'NODE_FCALL', 'NODE_VCALL', 'NODE_SUPER', 'NODE_ZSUPER', 'NODE_ARRAY', 'NODE_ZARRAY', 'NODE_HASH', 'NODE_RETURN', 'NODE_YIELD', 'NODE_LVAR', 'NODE_DVAR', 'NODE_GVAR', 'NODE_IVAR', 'NODE_CONST', 'NODE_CVAR', 'NODE_NTH_REF', 'NODE_BACK_REF', 'NODE_MATCH', 'NODE_MATCH2', 'NODE_MATCH3', 'NODE_LIT', 'NODE_STR', 'NODE_DSTR', 'NODE_XSTR', 'NODE_DXSTR', 'NODE_EVSTR', 'NODE_DREGX', 'NODE_DREGX_ONCE', 'NODE_ARGS', 'NODE_ARGSCAT', 'NODE_ARGSPUSH', 'NODE_SPLAT', 'NODE_TO_ARY', 'NODE_SVALUE', 'NODE_BLOCK_ARG', 'NODE_BLOCK_PASS', 'NODE_DEFN', 'NODE_DEFS', 'NODE_ALIAS', 'NODE_VALIAS', 'NODE_UNDEF', 'NODE_CLASS', 'NODE_MODULE', 'NODE_SCLASS', 'NODE_COLON2', 'NODE_COLON3', 'NODE_CREF', 'NODE_DOT2', 'NODE_DOT3', 'NODE_FLIP2', 'NODE_FLIP3', 'NODE_ATTRSET', 'NODE_SELF', 'NODE_NIL', 'NODE_TRUE', 'NODE_FALSE', 'NODE_DEFINED', 'NODE_NEWLINE', 'NODE_POSTEXE', 'NODE_ALLOCA', 'NODE_DMETHOD', 'NODE_BMETHOD', 'NODE_MEMO', 'NODE_IFUNC', 'NODE_DSYM', 'NODE_ATTRASGN', 'NODE_LAST'])
|
69
|
+
end
|
70
|
+
|
71
|
+
node_symbols = []
|
72
|
+
constants.each do |name|
|
73
|
+
next if name[0..4] != 'NODE_'
|
74
|
+
node_symbols[const_get(name)] = name.to_s[5..-1].downcase.to_sym
|
75
|
+
end
|
76
|
+
NODE_SYMBOLS = node_symbols
|
77
|
+
|
78
|
+
@include_newlines = false;
|
79
|
+
@level = 0
|
80
|
+
|
81
|
+
def initialize(include_newlines = false)
|
82
|
+
@include_newlines = include_newlines
|
83
|
+
end
|
84
|
+
|
85
|
+
def parse_tree_for_method(klass, method, is_cls_method = false, newlines = @include_newlines)
|
86
|
+
@newlines = newlines
|
87
|
+
@locals = []
|
88
|
+
@current_sexp = nil
|
89
|
+
method = method.to_sym
|
90
|
+
id = rb_to_id(method)
|
91
|
+
table = RCLASS(klass).m_tbl
|
92
|
+
if (r, n = st_lookup(table, id))[0]
|
93
|
+
sexp = [:defn, method, to_sexp(n.dereference.to_NODE.nd_body)]
|
94
|
+
sexp.extend Sexp
|
95
|
+
sexp
|
96
|
+
else
|
97
|
+
[nil]
|
98
|
+
end
|
99
|
+
end
|
100
|
+
|
101
|
+
def parse_tree_for_string(string, filename = nil, line = nil, newlines = @include_newlines)
|
102
|
+
filename ||= '(string)'
|
103
|
+
line ||= 1
|
104
|
+
@newlines = newlines
|
105
|
+
@locals = []
|
106
|
+
@current_sexp = nil
|
107
|
+
|
108
|
+
node = rb_compile_string(filename, string, line)
|
109
|
+
[to_sexp(node)]
|
110
|
+
end
|
111
|
+
|
112
|
+
def to_sexp(node)
|
113
|
+
return nil if node.nil?
|
114
|
+
c_type = nd_type(node)
|
115
|
+
type = NODE_SYMBOLS[c_type]
|
116
|
+
|
117
|
+
if type == :newline
|
118
|
+
if @newlines
|
119
|
+
newline_sexp = []
|
120
|
+
newline_sexp << :newline
|
121
|
+
newline_sexp << nd_line(node)
|
122
|
+
newline_sexp << node.nd_file
|
123
|
+
@current_sexp << newline_sexp
|
124
|
+
end
|
125
|
+
return to_sexp(node.nd_next)
|
126
|
+
end
|
127
|
+
|
128
|
+
sexp = []
|
129
|
+
sexp.extend Sexp
|
130
|
+
last_current_sexp = @current_sexp
|
131
|
+
@current_sexp = sexp
|
132
|
+
sexp << type
|
133
|
+
|
134
|
+
# puts((' ' * @level) + type.to_s)
|
135
|
+
# @level += 1
|
136
|
+
|
137
|
+
case type
|
138
|
+
when :block, :array
|
139
|
+
begin
|
140
|
+
sexp << to_sexp(node.nd_head)
|
141
|
+
end while node = node.nd_next
|
142
|
+
when :method
|
143
|
+
when :fbody
|
144
|
+
when :cfunc
|
145
|
+
when :scope
|
146
|
+
locals_before = @locals
|
147
|
+
@locals = node.nd_tbl
|
148
|
+
nd_next = node.nd_next
|
149
|
+
sexp << to_sexp(nd_next) unless nd_next.nil?
|
150
|
+
@locals = locals_before
|
151
|
+
when :if
|
152
|
+
sexp << to_sexp(node.nd_cond)
|
153
|
+
sexp << to_sexp(node.nd_body)
|
154
|
+
sexp << to_sexp(node.nd_else)
|
155
|
+
when :case
|
156
|
+
sexp << to_sexp(node.nd_head)
|
157
|
+
child = node.nd_body
|
158
|
+
loop do
|
159
|
+
child_sexp = to_sexp(child)
|
160
|
+
sexp << child_sexp
|
161
|
+
if child_sexp[0] == :when #when clause
|
162
|
+
child = child.nd_next
|
163
|
+
if child.nil? #no else clause used
|
164
|
+
sexp << nil
|
165
|
+
break
|
166
|
+
end
|
167
|
+
else #else clause
|
168
|
+
break
|
169
|
+
end
|
170
|
+
end
|
171
|
+
when :when
|
172
|
+
# if (!case_level) { /* when without case, ie, no expr in case */
|
173
|
+
# rb_ary_pop(ary); /* reset what current is pointing at */
|
174
|
+
# node = NEW_CASE(0, node);
|
175
|
+
# goto again;
|
176
|
+
# }
|
177
|
+
sexp << to_sexp(node.nd_head)
|
178
|
+
sexp << to_sexp(node.nd_body)
|
179
|
+
when :while, :until
|
180
|
+
sexp << to_sexp(node.nd_cond)
|
181
|
+
sexp << to_sexp(node.nd_body)
|
182
|
+
sexp << !node.nd_3rd.nil?
|
183
|
+
when :iter, :for
|
184
|
+
sexp << to_sexp(node.nd_iter)
|
185
|
+
# if (node->nd_var != (NODE *)1
|
186
|
+
# && node->nd_var != (NODE *)2
|
187
|
+
# && node->nd_var != NULL) {
|
188
|
+
if node.nd_var
|
189
|
+
sexp << to_sexp(node.nd_var)
|
190
|
+
else
|
191
|
+
sexp << nil
|
192
|
+
end
|
193
|
+
sexp << to_sexp(node.nd_body)
|
194
|
+
when :break, :next, :return, :yield
|
195
|
+
stts = node.nd_stts
|
196
|
+
sexp << to_sexp(stts) unless stts.nil?
|
197
|
+
when :begin, :opt_n, :not
|
198
|
+
sexp << to_sexp(node.nd_body)
|
199
|
+
when :rescue
|
200
|
+
sexp << to_sexp(node.nd_1st)
|
201
|
+
sexp << to_sexp(node.nd_2nd)
|
202
|
+
nd_3rd = node.nd_3rd
|
203
|
+
sexp << to_sexp(nd_3rd) unless nd_3rd.nil?
|
204
|
+
when :resbody
|
205
|
+
sexp << to_sexp(node.nd_3rd)
|
206
|
+
nd_2nd = node.nd_2nd
|
207
|
+
sexp << to_sexp(nd_2nd) unless nd_2nd.nil?
|
208
|
+
nd_1st = node.nd_1st
|
209
|
+
sexp << to_sexp(nd_1st) unless nd_1st.nil?
|
210
|
+
when :ensure
|
211
|
+
sexp << to_sexp(node.nd_head)
|
212
|
+
ensr = node.nd_ensr
|
213
|
+
sexp << zo_sexp(ensr) unless ensr.nil?
|
214
|
+
when :and, :or
|
215
|
+
sexp << to_sexp(node.nd_1st)
|
216
|
+
sexp << to_sexp(node.nd_2nd)
|
217
|
+
when :masgn
|
218
|
+
sexp << to_sexp(node.nd_head)
|
219
|
+
args = node.nd_args
|
220
|
+
sexp << to_sexp(args) unless args.nil?
|
221
|
+
value = node.nd_value
|
222
|
+
sexp << to_sexp(node.nd_value) unless value.nil?
|
223
|
+
when :lasgn, :dasgn, :dasgn_curr, :gasgn, :iasgn, :cdecl, :cvasgn, :cvdecl
|
224
|
+
sexp << ID2SYM(node.nd_vid)
|
225
|
+
value = node.nd_value
|
226
|
+
sexp << to_sexp(value) unless value.nil?
|
227
|
+
when :op_asgn1
|
228
|
+
when :op_asgn2
|
229
|
+
when :op_asgn_and, :op_asgn_or
|
230
|
+
sexp << to_sexp(node.nd_head)
|
231
|
+
sexp << to_sexp(node.nd_value)
|
232
|
+
when :call, :fcall, :vcall
|
233
|
+
sexp << to_sexp(node.nd_recv) if type == :call
|
234
|
+
sexp << ID2SYM(node.nd_mid)
|
235
|
+
if type == :call || type == :fcall
|
236
|
+
args = node.nd_args
|
237
|
+
sexp << to_sexp(args) if args
|
238
|
+
end
|
239
|
+
when :super
|
240
|
+
|
241
|
+
when :hash
|
242
|
+
list = node.nd_head
|
243
|
+
while list
|
244
|
+
sexp << to_sexp(list.nd_head)
|
245
|
+
list = list.nd_next
|
246
|
+
raise "ParseTree error: Odd number list for Hash" if list.nil?
|
247
|
+
sexp << to_sexp(list.nd_head)
|
248
|
+
list = list.nd_next
|
249
|
+
end
|
250
|
+
when :lvar, :dvar, :gvar, :ivar, :const, :cvar, :attrset
|
251
|
+
sexp << ID2SYM(node.nd_vid)
|
252
|
+
when :nth_ref
|
253
|
+
sexp << node.nd_nth
|
254
|
+
when :back_ref
|
255
|
+
when :match
|
256
|
+
when :match2, :match3
|
257
|
+
sexp << to_sexp(node.nd_recv)
|
258
|
+
sexp << to_sexp(node.nd_value)
|
259
|
+
when :lit, :str, :xstr
|
260
|
+
sexp << node.nd_lit
|
261
|
+
when :dstr, :dxstr, :dregx, :dregx_once, :dsym
|
262
|
+
sexp << node.nd_lit
|
263
|
+
list = node.nd_next
|
264
|
+
while list
|
265
|
+
head = list.nd_head
|
266
|
+
if head
|
267
|
+
child_sexp = to_sexp(head)
|
268
|
+
child_sexp = child_sexp[1] if child_sexp[0] == :evstr
|
269
|
+
sexp << child_sexp
|
270
|
+
end
|
271
|
+
list = list.nd_next
|
272
|
+
end
|
273
|
+
when :evstr
|
274
|
+
sexp << to_sexp(node.nd_body)
|
275
|
+
when :args
|
276
|
+
arg_flag = node.nd_rest
|
277
|
+
if @locals
|
278
|
+
#regular args
|
279
|
+
i = 0
|
280
|
+
while i < node.nd_cnt do
|
281
|
+
sexp << ID2SYM(@locals[i + 3])
|
282
|
+
i += 1
|
283
|
+
end
|
284
|
+
#optional args
|
285
|
+
optnode = node.nd_opt
|
286
|
+
while optnode do
|
287
|
+
sexp << ID2SYM(@locals[i + 3])
|
288
|
+
i += 1
|
289
|
+
optnode = optnode.nd_next
|
290
|
+
end
|
291
|
+
#special args
|
292
|
+
case
|
293
|
+
when arg_flag > 0: sexp << "*#{locals[i + 3].to_s}".to_sym #*arg
|
294
|
+
when arg_flag == 0: #empty list
|
295
|
+
when arg_flag == -1: #all handled above
|
296
|
+
when arg_flag == -2: #no name
|
297
|
+
else raise "ParseTree error: Unknown arg flag #{arg_flag}"
|
298
|
+
end
|
299
|
+
#assigns of optional args
|
300
|
+
opt = node.nd_opt;
|
301
|
+
if opt
|
302
|
+
sexp << to_sexp(opt)
|
303
|
+
end
|
304
|
+
end
|
305
|
+
when :argscat, :argspush
|
306
|
+
sexp << to_sexp(node.nd_head)
|
307
|
+
sexp << to_sexp(node.nd_body)
|
308
|
+
when :splat, :to_ary, :svalue
|
309
|
+
sexp << to_sexp(node.nd_head)
|
310
|
+
when :block_arg
|
311
|
+
sexp << ID2SYM(node.nd_u1id)
|
312
|
+
when :block_pass
|
313
|
+
sexp << to_sexp(node.nd_body)
|
314
|
+
sexp << to_sexp(node.nd_iter)
|
315
|
+
when :defn, :defs
|
316
|
+
defn = node.nd_defn
|
317
|
+
if defn
|
318
|
+
sexp << to_sexp(node.nd_recv) if type == :defs
|
319
|
+
sexp << ID2SYM(node.nd_mid)
|
320
|
+
sexp << to_sexp(defn)
|
321
|
+
end
|
322
|
+
when :alias
|
323
|
+
when :valias
|
324
|
+
when :undef
|
325
|
+
when :class, :module
|
326
|
+
sexp << ID2SYM(node.nd_cpath.nd_mid)
|
327
|
+
sexp << to_sexp(node.nd_super) if type == :class
|
328
|
+
sexp << to_sexp(node.nd_body)
|
329
|
+
when :sclass
|
330
|
+
when :colon2
|
331
|
+
when :colon3
|
332
|
+
when :cref
|
333
|
+
when :dot2
|
334
|
+
when :dot3
|
335
|
+
when :flip2
|
336
|
+
when :flip3
|
337
|
+
when :defined
|
338
|
+
when :postexe
|
339
|
+
when :alloca
|
340
|
+
when :dmethod
|
341
|
+
when :bmethod
|
342
|
+
block = DATA_PTR(node.nd_cval).to_struct_BLOCK
|
343
|
+
var = block.var
|
344
|
+
sexp << to_sexp(var) unless var.nil?
|
345
|
+
sexp << to_sexp(block.body)
|
346
|
+
when :memo
|
347
|
+
when :ifunc
|
348
|
+
when :attrasgn
|
349
|
+
nd_1st = node.nd_1st
|
350
|
+
if nd_1st == RNODE(1)
|
351
|
+
sexp << to_sexp(NEW_SELF())
|
352
|
+
else
|
353
|
+
sexp << to_sexp(nd_1st)
|
354
|
+
end
|
355
|
+
sexp << ID2SYM(node.nd_u2id)
|
356
|
+
sexp << to_sexp(node.nd_3rd)
|
357
|
+
when :last
|
358
|
+
when :retry, :redo, :self, :nil, :true, :false, :zsuper, :zarray
|
359
|
+
# empty nodes
|
360
|
+
when :last
|
361
|
+
raise "ParseTree error: Unsupported node type '#{type}'"
|
362
|
+
else
|
363
|
+
raise "ParseTree error: Unknown node type '#{c_type}'"
|
364
|
+
end
|
365
|
+
|
366
|
+
# @level -= 1
|
367
|
+
# puts((' ' * @level) + type.to_s + ' end')
|
368
|
+
|
369
|
+
@current_sexp = last_current_sexp
|
370
|
+
sexp
|
371
|
+
end
|
372
|
+
end
|
data/lib/sexp.rb
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
module Sexp
|
2
|
+
|
3
|
+
def type
|
4
|
+
self[0]
|
5
|
+
end
|
6
|
+
|
7
|
+
def perform_process_call(target_class)
|
8
|
+
exp = self[1..-1]
|
9
|
+
exp.extend Clonable
|
10
|
+
target_class.send("process_#{type}", exp)
|
11
|
+
end
|
12
|
+
|
13
|
+
end
|
14
|
+
|
15
|
+
# Should not be used, for compatibility only.
|
16
|
+
module Clonable
|
17
|
+
def deep_clone
|
18
|
+
Marshal.load(Marshal.dump(self))
|
19
|
+
end
|
20
|
+
end
|
metadata
ADDED
@@ -0,0 +1,57 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
rubygems_version: 0.9.3
|
3
|
+
specification_version: 1
|
4
|
+
name: ParseTreeReloaded
|
5
|
+
version: !ruby/object:Gem::Version
|
6
|
+
version: 0.0.1
|
7
|
+
date: 2007-05-21 00:00:00 +02:00
|
8
|
+
summary: ParseTree based on RubyInlineAccelerated
|
9
|
+
require_paths:
|
10
|
+
- lib
|
11
|
+
email: mail@richard-musiol.de
|
12
|
+
homepage: http://rubyforge.org/projects/ptreloaded/
|
13
|
+
rubyforge_project:
|
14
|
+
description: ParseTreeReloaded is a reimplementation of ParseTree using RubyInlineAcceleration. The goal is to provide full compatibility to ParseTree while making it easier to build and extend.
|
15
|
+
autorequire:
|
16
|
+
default_executable:
|
17
|
+
bindir: bin
|
18
|
+
has_rdoc: false
|
19
|
+
required_ruby_version: !ruby/object:Gem::Version::Requirement
|
20
|
+
requirements:
|
21
|
+
- - ">"
|
22
|
+
- !ruby/object:Gem::Version
|
23
|
+
version: 0.0.0
|
24
|
+
version:
|
25
|
+
platform: ruby
|
26
|
+
signing_key:
|
27
|
+
cert_chain:
|
28
|
+
post_install_message:
|
29
|
+
authors:
|
30
|
+
- Richard Musiol
|
31
|
+
files:
|
32
|
+
- GPL.txt
|
33
|
+
- lib/parse_tree_reloaded.rb
|
34
|
+
- lib/sexp.rb
|
35
|
+
- lib/sexp_processor.rb
|
36
|
+
test_files: []
|
37
|
+
|
38
|
+
rdoc_options: []
|
39
|
+
|
40
|
+
extra_rdoc_files: []
|
41
|
+
|
42
|
+
executables: []
|
43
|
+
|
44
|
+
extensions: []
|
45
|
+
|
46
|
+
requirements: []
|
47
|
+
|
48
|
+
dependencies:
|
49
|
+
- !ruby/object:Gem::Dependency
|
50
|
+
name: RubyInlineAcceleration
|
51
|
+
version_requirement:
|
52
|
+
version_requirements: !ruby/object:Gem::Version::Requirement
|
53
|
+
requirements:
|
54
|
+
- - ">="
|
55
|
+
- !ruby/object:Gem::Version
|
56
|
+
version: 0.0.1
|
57
|
+
version:
|