redparse 0.8.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/COPYING.LGPL +165 -0
- data/Manifest.txt +40 -0
- data/README.txt +461 -0
- data/Rakefile +26 -0
- data/lib/redparse.rb +1083 -0
- data/lib/redparse/babynodes.rb +137 -0
- data/lib/redparse/babyparser.rb +276 -0
- data/lib/redparse/decisiontree.rb +372 -0
- data/lib/redparse/node.rb +3808 -0
- data/lib/redparse/problemfiles.rb +84 -0
- data/lib/redparse/reg_more_sugar.rb +99 -0
- data/nurli/test_control.nurli +261 -0
- data/redparse.vpj +92 -0
- data/redparse.vpw +8 -0
- data/test/data/__end.rb +5 -0
- data/test/data/__f.rb +2 -0
- data/test/data/be.rb +3 -0
- data/test/data/be2.rb +6 -0
- data/test/data/bqhd.rb +3 -0
- data/test/data/bqhd2.rb +3 -0
- data/test/data/case.rb +8 -0
- data/test/data/datetime.rb +66 -0
- data/test/data/defd.rb +9 -0
- data/test/data/hd-def.rb +8 -0
- data/test/data/hd.rb +3 -0
- data/test/data/hd2.rb +3 -0
- data/test/data/hd3.rb +3 -0
- data/test/data/hd4.rb +75 -0
- data/test/data/hd5.rb +4 -0
- data/test/data/hdcat.rb +4 -0
- data/test/data/hdx.rb +3 -0
- data/test/data/heredoc.rb +3 -0
- data/test/data/if.rb +7 -0
- data/test/data/jbridge.rb +779 -0
- data/test/data/mod.rb +3 -0
- data/test/data/nl_as_strdelim.rb +7 -0
- data/test/data/pw.rb +2 -0
- data/test/data/wvt.rb +2 -0
- data/test/rp-locatetest.rb +344 -0
- data/test/test_redparse.rb +3319 -0
- metadata +113 -0
@@ -0,0 +1,84 @@
|
|
1
|
+
=begin
|
2
|
+
redparse - a ruby parser written in ruby
|
3
|
+
Copyright (C) 2008 Caleb Clausen
|
4
|
+
|
5
|
+
This library is free software; you can redistribute it and/or
|
6
|
+
modify it under the terms of the GNU Lesser General Public
|
7
|
+
License as published by the Free Software Foundation; either
|
8
|
+
version 2.1 of the License, or (at your option) any later version.
|
9
|
+
|
10
|
+
This library is distributed in the hope that it will be useful,
|
11
|
+
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
12
|
+
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
13
|
+
Lesser General Public License for more details.
|
14
|
+
|
15
|
+
You should have received a copy of the GNU Lesser General Public
|
16
|
+
License along with this library; if not, write to the Free Software
|
17
|
+
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
18
|
+
=end
|
19
|
+
|
20
|
+
class CachedResults
|
21
|
+
def initialize(name="problemfiles")
|
22
|
+
@bad2offset={}
|
23
|
+
@good2offset={}
|
24
|
+
|
25
|
+
#read list from disk
|
26
|
+
@file=File.open(name,File.exist?(name) ? "r+" : "w+")
|
27
|
+
until @file.eof?
|
28
|
+
at=@file.pos
|
29
|
+
line=@file.readline
|
30
|
+
if line[0]==?#
|
31
|
+
@good2offset[line[1...-1]]=at
|
32
|
+
else
|
33
|
+
@bad2offset[line[1...-1]]=at
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
38
|
+
def bad! pf
|
39
|
+
@bad2offset[pf] and return self
|
40
|
+
|
41
|
+
if pos=@good2offset.delete(pf)
|
42
|
+
@bad2offset[pf]=pos
|
43
|
+
@file.pos=pos
|
44
|
+
@file.putc ' '
|
45
|
+
else
|
46
|
+
@file.seek(0,IO::SEEK_END)
|
47
|
+
@bad2offset[pf]=@file.pos
|
48
|
+
@file.puts " "+pf
|
49
|
+
end
|
50
|
+
@file.flush
|
51
|
+
|
52
|
+
return self
|
53
|
+
end
|
54
|
+
|
55
|
+
def good! pf
|
56
|
+
@good2offset[pf] and return self
|
57
|
+
|
58
|
+
if offset=@bad2offset.delete(pf)
|
59
|
+
@good2offset[pf]=offset
|
60
|
+
@file.pos=offset
|
61
|
+
@file.putc '#'
|
62
|
+
else
|
63
|
+
@file.seek(0,IO::SEEK_END)
|
64
|
+
@good2offset[pf]=@file.pos
|
65
|
+
@file.puts "#"+pf
|
66
|
+
end
|
67
|
+
@file.flush
|
68
|
+
return pf
|
69
|
+
end
|
70
|
+
|
71
|
+
def badlist
|
72
|
+
@bad2offset.keys
|
73
|
+
end
|
74
|
+
|
75
|
+
def goodlist
|
76
|
+
@good2offset.keys
|
77
|
+
end
|
78
|
+
end
|
79
|
+
|
80
|
+
class ProblemFiles < CachedResults #old interface
|
81
|
+
alias push bad!
|
82
|
+
alias delete good!
|
83
|
+
alias list badlist
|
84
|
+
end
|
@@ -0,0 +1,99 @@
|
|
1
|
+
=begin
|
2
|
+
redparse - a ruby parser written in ruby
|
3
|
+
Copyright (C) 2008 Caleb Clausen
|
4
|
+
|
5
|
+
This program is free software: you can redistribute it and/or modify
|
6
|
+
it under the terms of the GNU Lesser General Public License as published by
|
7
|
+
the Free Software Foundation, either version 3 of the License, or
|
8
|
+
(at your option) any later version.
|
9
|
+
|
10
|
+
This program is distributed in the hope that it will be useful,
|
11
|
+
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
12
|
+
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
13
|
+
GNU Lesser General Public License for more details.
|
14
|
+
|
15
|
+
You should have received a copy of the GNU Lesser General Public License
|
16
|
+
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
17
|
+
=end
|
18
|
+
|
19
|
+
unless defined? ::Reg::Transform and ::Reg::Transform.ancestors.include? ::Reg::HasCmatch
|
20
|
+
#hack, until support for this syntax makes it into the release of reg
|
21
|
+
module ::Reg
|
22
|
+
class Transform;
|
23
|
+
def initialize(left,right)
|
24
|
+
@left,@right=left,right
|
25
|
+
end
|
26
|
+
attr_reader :left,:right
|
27
|
+
end
|
28
|
+
module Reg
|
29
|
+
def >>(rep)
|
30
|
+
Transform.new(self,rep)
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
36
|
+
unless ::Reg::Reg.instance_methods.include? "lb"
|
37
|
+
module ::Reg
|
38
|
+
module Reg
|
39
|
+
def lb
|
40
|
+
LookBack.new(self)
|
41
|
+
end
|
42
|
+
end
|
43
|
+
class LookBack
|
44
|
+
def initialize(reg)
|
45
|
+
@reg=reg
|
46
|
+
end
|
47
|
+
|
48
|
+
def regs(i)
|
49
|
+
@reg
|
50
|
+
end
|
51
|
+
|
52
|
+
def itemrange
|
53
|
+
0..0
|
54
|
+
end
|
55
|
+
end
|
56
|
+
end
|
57
|
+
end
|
58
|
+
|
59
|
+
unless ::Reg::Reg.instance_methods.include? "la"
|
60
|
+
module ::Reg
|
61
|
+
module Reg
|
62
|
+
def la
|
63
|
+
LookAhead.new(self)
|
64
|
+
end
|
65
|
+
end
|
66
|
+
class LookAhead
|
67
|
+
def initialize(reg)
|
68
|
+
@reg=reg
|
69
|
+
end
|
70
|
+
|
71
|
+
def regs(i)
|
72
|
+
@reg
|
73
|
+
end
|
74
|
+
|
75
|
+
def itemrange
|
76
|
+
0..0
|
77
|
+
end
|
78
|
+
end
|
79
|
+
end
|
80
|
+
end
|
81
|
+
|
82
|
+
unless ::Reg::Reg.instance_methods.include? "watch"
|
83
|
+
module ::Reg
|
84
|
+
module Reg
|
85
|
+
def watch
|
86
|
+
result=dup
|
87
|
+
class<<result
|
88
|
+
def ===(other)
|
89
|
+
result=super
|
90
|
+
result and p other
|
91
|
+
return result
|
92
|
+
end
|
93
|
+
end
|
94
|
+
return result
|
95
|
+
end
|
96
|
+
end
|
97
|
+
end
|
98
|
+
end
|
99
|
+
|
@@ -0,0 +1,261 @@
|
|
1
|
+
#;; test_control.nurli
|
2
|
+
#;; tests for Nurli control structures.
|
3
|
+
#;;
|
4
|
+
#;; Copyright (c) 2007 Tim Burks, Neon Design Technology, Inc.
|
5
|
+
#(converted from nu to nurli by caleb clausen)
|
6
|
+
|
7
|
+
load "test"
|
8
|
+
|
9
|
+
class TestControl < NuTestCase
|
10
|
+
|
11
|
+
def testIf #(id)
|
12
|
+
x=0
|
13
|
+
if x==0 then y=0; y+=1
|
14
|
+
y+=1
|
15
|
+
else if x==1 then y=10; y+=1
|
16
|
+
y+=1
|
17
|
+
else y=100; y+=1
|
18
|
+
end
|
19
|
+
end
|
20
|
+
assert_equal 2, y
|
21
|
+
|
22
|
+
x=1
|
23
|
+
if x==0 then y=0; y+=1
|
24
|
+
y+=1
|
25
|
+
else if x==1 then y=10; y+=1
|
26
|
+
y+=1
|
27
|
+
else y=100; y+=1
|
28
|
+
end
|
29
|
+
end
|
30
|
+
assert_equal 12, y
|
31
|
+
|
32
|
+
x=2
|
33
|
+
if x==0 then y=0; y+=1
|
34
|
+
y+=1
|
35
|
+
else if x==1 then y=10; y+=1
|
36
|
+
y+=1
|
37
|
+
else y=100; y+=1
|
38
|
+
end
|
39
|
+
end
|
40
|
+
assert_equal 101, y
|
41
|
+
end
|
42
|
+
|
43
|
+
def testUnless #(id)
|
44
|
+
x=0
|
45
|
+
unless x!=0 then y=0; y+=1
|
46
|
+
y+=1
|
47
|
+
else unless x!=1 then y=10; y+=1
|
48
|
+
y+=1
|
49
|
+
else y=100; y+=1
|
50
|
+
end
|
51
|
+
end
|
52
|
+
assert_equal 2, y
|
53
|
+
|
54
|
+
x=1
|
55
|
+
unless x!=0 then y=0; y+=1
|
56
|
+
y+=1
|
57
|
+
else unless x!=1 then y=10; y+=1
|
58
|
+
y+=1
|
59
|
+
else y=100; y+=1
|
60
|
+
end
|
61
|
+
end
|
62
|
+
assert_equal 12, y
|
63
|
+
|
64
|
+
x=2
|
65
|
+
unless x!=0 then y=0; y+=1
|
66
|
+
y+=1
|
67
|
+
else unless x!=1 then y=10; y+=1
|
68
|
+
y+=1
|
69
|
+
else y=100; y+=1
|
70
|
+
end
|
71
|
+
end
|
72
|
+
assert_equal 101, y
|
73
|
+
end
|
74
|
+
|
75
|
+
def testWhile #(id)
|
76
|
+
x=10
|
77
|
+
y=0
|
78
|
+
while x
|
79
|
+
y+=x
|
80
|
+
x-=1
|
81
|
+
end
|
82
|
+
assert_equal 55,y
|
83
|
+
end
|
84
|
+
|
85
|
+
def testUntil #(id)
|
86
|
+
x=10
|
87
|
+
y=0
|
88
|
+
until x==0
|
89
|
+
y+=x
|
90
|
+
x-=1
|
91
|
+
end
|
92
|
+
assert_equal 55,y
|
93
|
+
end
|
94
|
+
|
95
|
+
def testWhileBreak #(id)
|
96
|
+
$count=0
|
97
|
+
x=10
|
98
|
+
while(x!=0)
|
99
|
+
x-=1
|
100
|
+
y=10
|
101
|
+
while(y!=0)
|
102
|
+
y-=1
|
103
|
+
$count+=1
|
104
|
+
break if y==5
|
105
|
+
end
|
106
|
+
end
|
107
|
+
assert_equal 50, $count
|
108
|
+
end
|
109
|
+
|
110
|
+
def testWhileContinue #(id)
|
111
|
+
$count=0
|
112
|
+
x=10
|
113
|
+
while(x!=0)
|
114
|
+
x-=1
|
115
|
+
y=10
|
116
|
+
while(y!=0)
|
117
|
+
y-=1
|
118
|
+
continue if y>=5
|
119
|
+
$count+=1
|
120
|
+
end
|
121
|
+
end
|
122
|
+
assert_equal 50, $count
|
123
|
+
end
|
124
|
+
|
125
|
+
|
126
|
+
def testUntilBreak #(id)
|
127
|
+
$count=0
|
128
|
+
x=10
|
129
|
+
until(x==0)
|
130
|
+
x-=1
|
131
|
+
y=10
|
132
|
+
until(y==0)
|
133
|
+
y-=1
|
134
|
+
$count+=1
|
135
|
+
break if y==5
|
136
|
+
end
|
137
|
+
end
|
138
|
+
assert_equal 50, $count
|
139
|
+
end
|
140
|
+
|
141
|
+
def testUntilContinue #(id)
|
142
|
+
$count=0
|
143
|
+
x=10
|
144
|
+
until(x==0)
|
145
|
+
x-=1
|
146
|
+
y=10
|
147
|
+
until(y==0)
|
148
|
+
y-=1
|
149
|
+
continue if y>=5
|
150
|
+
$count+=1
|
151
|
+
end
|
152
|
+
end
|
153
|
+
assert_equal 50, $count
|
154
|
+
end
|
155
|
+
|
156
|
+
=begin cant do these yet, sorry
|
157
|
+
(imethod (id) testLoopMacro is
|
158
|
+
;; here is a simple macro defining an unending loop
|
159
|
+
(macro loop (eval (append '(while t) margs)))
|
160
|
+
;; here's a macro that decrements a named value
|
161
|
+
(macro decrement (set (unquote (margs car)) (- (unquote (margs car)) 1)))
|
162
|
+
;; here's a macro that increments a named value
|
163
|
+
(macro increment (set (unquote (margs car)) (+ (unquote (margs car)) 1)))
|
164
|
+
;; run the loop, breaking out after 5 iterations
|
165
|
+
(set count 0)
|
166
|
+
(set x 10)
|
167
|
+
(loop
|
168
|
+
(decrement x)
|
169
|
+
(increment count)
|
170
|
+
(if (eq x 5) (break)))
|
171
|
+
(assert_equal 5 count)
|
172
|
+
;; run the loop, breaking out after 10 iterations
|
173
|
+
;; but only counting until the loop counter (x) drops below 5
|
174
|
+
(set count 0)
|
175
|
+
(set x 10)
|
176
|
+
(loop
|
177
|
+
(decrement x)
|
178
|
+
(if (eq x 0) (break))
|
179
|
+
(if (< x 5) (continue))
|
180
|
+
(increment count))
|
181
|
+
(assert_equal 5 count))
|
182
|
+
|
183
|
+
(imethod (id) testFor is
|
184
|
+
(set x 0)
|
185
|
+
(for ((set i 1) (< i 10) (set i (+ i 1)))
|
186
|
+
(set x (+ x i)))
|
187
|
+
(assert_equal 45 x))
|
188
|
+
|
189
|
+
(imethod (id) testForBreak is
|
190
|
+
(set x 0)
|
191
|
+
(for ((set i 1) (< i 10) (set i (+ i 1)))
|
192
|
+
(if (== i 6) (break))
|
193
|
+
(set x (+ x i)))
|
194
|
+
(assert_equal 15 x))
|
195
|
+
|
196
|
+
(imethod (id) testForContinue is
|
197
|
+
(set x 0)
|
198
|
+
(for ((set i 1) (< i 10) (set i (+ i 1)))
|
199
|
+
(if (== i 6) (continue))
|
200
|
+
(set x (+ x i)))
|
201
|
+
(assert_equal 39 x))
|
202
|
+
=end
|
203
|
+
|
204
|
+
def testCond #(id)
|
205
|
+
x=0
|
206
|
+
assert_equal 1,
|
207
|
+
if x==0: y=0; y+=1
|
208
|
+
elsif x==1: y=10; y+=1
|
209
|
+
else y=100; y+=1
|
210
|
+
end
|
211
|
+
|
212
|
+
x=1
|
213
|
+
assert_equal 11,
|
214
|
+
if x==0: y=0; y+=1
|
215
|
+
elsif x==1: y=10; y+=1
|
216
|
+
else y=100; y+=1
|
217
|
+
end
|
218
|
+
|
219
|
+
x=2
|
220
|
+
assert_equal 101,
|
221
|
+
if x==0: y=0; y+=1
|
222
|
+
elsif x==1: y=10; y+=1
|
223
|
+
else y=100; y+=1
|
224
|
+
end
|
225
|
+
|
226
|
+
# ;; test fallthrough
|
227
|
+
|
228
|
+
assert_equal(1,(if 1; 1 else 2 end))
|
229
|
+
assert_equal(1,(if 0; 0 elsif 1; 1 else 2 end))
|
230
|
+
assert_equal(2,(if 0; 0 elsif 0; 0 else 2 end))
|
231
|
+
end
|
232
|
+
|
233
|
+
def testCase
|
234
|
+
x=0
|
235
|
+
assert_equal 1,
|
236
|
+
case x
|
237
|
+
when 0: y=0;y+=1
|
238
|
+
when 1: y=10;y+=1
|
239
|
+
else y=100;y+=1
|
240
|
+
end
|
241
|
+
|
242
|
+
x=1
|
243
|
+
assert_equal 11,
|
244
|
+
case x
|
245
|
+
when 0: y=0;y+=1
|
246
|
+
when 1: y=10;y+=1
|
247
|
+
else y=100;y+=1
|
248
|
+
end
|
249
|
+
|
250
|
+
x=2
|
251
|
+
assert_equal 101,
|
252
|
+
case x
|
253
|
+
when 0: y=0;y+=1
|
254
|
+
when 1: y=10;y+=1
|
255
|
+
else y=100;y+=1
|
256
|
+
end
|
257
|
+
end
|
258
|
+
end
|
259
|
+
|
260
|
+
|
261
|
+
NuTestCase.runAllTests
|
data/redparse.vpj
ADDED
@@ -0,0 +1,92 @@
|
|
1
|
+
<!DOCTYPE Project SYSTEM "http://www.slickedit.com/dtd/vse/10.0/vpj.dtd">
|
2
|
+
<Project
|
3
|
+
Version="10.0"
|
4
|
+
VendorName="SlickEdit"
|
5
|
+
WorkingDir=".">
|
6
|
+
<Config
|
7
|
+
Name="Release"
|
8
|
+
OutputFile=""
|
9
|
+
CompilerConfigName="Latest Version">
|
10
|
+
<Menu>
|
11
|
+
<Target
|
12
|
+
Name="Compile"
|
13
|
+
MenuCaption="&Compile"
|
14
|
+
CaptureOutputWith="ProcessBuffer"
|
15
|
+
SaveOption="SaveCurrent"
|
16
|
+
RunFromDir="%rw">
|
17
|
+
<Exec/>
|
18
|
+
</Target>
|
19
|
+
<Target
|
20
|
+
Name="Build"
|
21
|
+
MenuCaption="&Build"
|
22
|
+
CaptureOutputWith="ProcessBuffer"
|
23
|
+
SaveOption="SaveWorkspaceFiles"
|
24
|
+
RunFromDir="%rw">
|
25
|
+
<Exec/>
|
26
|
+
</Target>
|
27
|
+
<Target
|
28
|
+
Name="Rebuild"
|
29
|
+
MenuCaption="&Rebuild"
|
30
|
+
CaptureOutputWith="ProcessBuffer"
|
31
|
+
SaveOption="SaveWorkspaceFiles"
|
32
|
+
RunFromDir="%rw">
|
33
|
+
<Exec/>
|
34
|
+
</Target>
|
35
|
+
<Target
|
36
|
+
Name="Debug"
|
37
|
+
MenuCaption="&Debug"
|
38
|
+
SaveOption="SaveNone"
|
39
|
+
RunFromDir="%rw">
|
40
|
+
<Exec/>
|
41
|
+
</Target>
|
42
|
+
<Target
|
43
|
+
Name="Execute"
|
44
|
+
MenuCaption="E&xecute"
|
45
|
+
SaveOption="SaveNone"
|
46
|
+
RunFromDir="%rw">
|
47
|
+
<Exec CmdLine='".exe"'/>
|
48
|
+
</Target>
|
49
|
+
</Menu>
|
50
|
+
</Config>
|
51
|
+
<CustomFolders>
|
52
|
+
<Folder
|
53
|
+
Name="Source Files"
|
54
|
+
Filters="*.c;*.C;*.cc;*.cpp;*.cp;*.cxx;*.prg;*.pas;*.dpr;*.asm;*.s;*.bas;*.java;*.cs;*.sc;*.e;*.cob;*.html;*.rc;*.tcl;*.py;*.pl;*.rb">
|
55
|
+
</Folder>
|
56
|
+
<Folder
|
57
|
+
Name="Header Files"
|
58
|
+
Filters="*.h;*.H;*.hh;*.hpp;*.hxx;*.inc;*.sh;*.cpy;*.if"/>
|
59
|
+
<Folder
|
60
|
+
Name="Resource Files"
|
61
|
+
Filters="*.ico;*.cur;*.dlg"/>
|
62
|
+
<Folder
|
63
|
+
Name="Bitmaps"
|
64
|
+
Filters="*.bmp"/>
|
65
|
+
<Folder
|
66
|
+
Name="Other Files"
|
67
|
+
Filters="">
|
68
|
+
</Folder>
|
69
|
+
</CustomFolders>
|
70
|
+
<Files AutoFolders="DirectoryView">
|
71
|
+
<Folder Name="bin">
|
72
|
+
<F N="bin/redparse"/>
|
73
|
+
</Folder>
|
74
|
+
<Folder Name="lib">
|
75
|
+
<Folder Name="redparse">
|
76
|
+
<F N="lib/redparse/babynodes.rb"/>
|
77
|
+
<F N="lib/redparse/babyparser.rb"/>
|
78
|
+
<F N="lib/redparse/decisiontree.rb"/>
|
79
|
+
<F N="lib/redparse/node.rb"/>
|
80
|
+
<F N="lib/redparse/reg_more_sugar.rb"/>
|
81
|
+
<F N="lib/redparse/version.rb"/>
|
82
|
+
</Folder>
|
83
|
+
<F N="lib/redparse.rb"/>
|
84
|
+
</Folder>
|
85
|
+
<Folder Name="test">
|
86
|
+
<F N="test/problemfiles.rb"/>
|
87
|
+
<F N="test/rp-locatetest.rb"/>
|
88
|
+
<F N="test/test_redparse.rb"/>
|
89
|
+
</Folder>
|
90
|
+
<F N="README.txt"/>
|
91
|
+
</Files>
|
92
|
+
</Project>
|