parser 0.9.alpha → 0.9.alpha1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.gitignore +21 -0
- data/.travis.yml +9 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +25 -0
- data/README.md +29 -0
- data/Rakefile +15 -182
- data/lib/parser.rb +4 -0
- data/lib/parser/lexer.rl +1713 -0
- data/lib/parser/lexer_literal.rb +175 -0
- data/lib/parser/static_environment.rb +38 -0
- data/lib/parser/syntax_error.rb +3 -0
- data/parser.gemspec +25 -0
- data/test/{test_ruby_lexer.rb → test_lexer.rb} +77 -129
- data/test/test_static_environment.rb +46 -0
- metadata +39 -98
- data/.autotest +0 -50
- data/.gemtest +0 -0
- data/History.txt +0 -558
- data/Manifest.txt +0 -18
- data/README.txt +0 -87
- data/bin/ruby_parse +0 -96
- data/bin/ruby_parse_extract_error +0 -130
- data/lib/gauntlet_rubyparser.rb +0 -117
- data/lib/ruby18_parser.rb +0 -5706
- data/lib/ruby18_parser.y +0 -1846
- data/lib/ruby19_parser.rb +0 -6054
- data/lib/ruby19_parser.y +0 -2035
- data/lib/ruby_lexer.rb +0 -6789
- data/lib/ruby_parser.rb +0 -4
- data/lib/ruby_parser_extras.rb +0 -1148
- data/test/test_ruby_parser.rb +0 -1772
- data/test/test_ruby_parser_extras.rb +0 -228
@@ -1,228 +0,0 @@
|
|
1
|
-
#!/usr/bin/env ruby
|
2
|
-
# encoding: ascii-8bit
|
3
|
-
|
4
|
-
require 'minitest/autorun'
|
5
|
-
require 'ruby_parser_extras'
|
6
|
-
|
7
|
-
require 'minitest/unit'
|
8
|
-
|
9
|
-
class TestStackState < MiniTest::Unit::TestCase
|
10
|
-
attr_reader :s
|
11
|
-
|
12
|
-
def setup
|
13
|
-
@s = RubyParserStuff::StackState.new :test
|
14
|
-
end
|
15
|
-
|
16
|
-
def assert_encoding str, default = false
|
17
|
-
orig_str = str.dup
|
18
|
-
p = Ruby19Parser.new
|
19
|
-
s = nil
|
20
|
-
|
21
|
-
out, err = capture_io do
|
22
|
-
s = p.handle_encoding str
|
23
|
-
end
|
24
|
-
|
25
|
-
assert_equal orig_str.sub(/\357\273\277/, ''), s
|
26
|
-
|
27
|
-
exp_err = ""
|
28
|
-
|
29
|
-
if defined?(Encoding) then
|
30
|
-
assert_equal "UTF-8", s.encoding.to_s, str.inspect
|
31
|
-
else
|
32
|
-
exp_err = "Skipping magic encoding comment\n" unless default
|
33
|
-
end
|
34
|
-
|
35
|
-
assert_equal "", out, str.inspect
|
36
|
-
assert_equal exp_err, err, str.inspect # HACK
|
37
|
-
end
|
38
|
-
|
39
|
-
def test_handle_encoding_bom
|
40
|
-
# bom support, default to utf-8
|
41
|
-
assert_encoding "\xEF\xBB\xBF# blah"
|
42
|
-
# we force_encode to US-ASCII, then encode to UTF-8 so our lexer will work
|
43
|
-
assert_encoding "\xEF\xBB\xBF# encoding: US-ASCII"
|
44
|
-
end
|
45
|
-
|
46
|
-
def test_handle_encoding_default
|
47
|
-
assert_encoding "blah", :default
|
48
|
-
end
|
49
|
-
|
50
|
-
def test_handle_encoding_emacs
|
51
|
-
# Q: how many different ways can we screw these up? A: ALL OF THEM
|
52
|
-
|
53
|
-
assert_encoding "# - encoding: utf-8 -"
|
54
|
-
assert_encoding "# - encoding:utf-8"
|
55
|
-
assert_encoding "# -* coding: UTF-8 -*-"
|
56
|
-
assert_encoding "# -*- coding: UTF-8 -*-"
|
57
|
-
assert_encoding "# -*- coding: utf-8 -*"
|
58
|
-
assert_encoding "# -*- coding: utf-8 -*-"
|
59
|
-
assert_encoding "# -*- coding: utf-8; mode: ruby -*-"
|
60
|
-
assert_encoding "# -*- coding: utf-8; mode: ruby; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2"
|
61
|
-
assert_encoding "# -*- coding:utf-8; mode:ruby; -*-"
|
62
|
-
assert_encoding "# -*- encoding: UTF-8 -*-"
|
63
|
-
assert_encoding "# -*- encoding: utf-8 -*"
|
64
|
-
assert_encoding "# -*- encoding: utf-8 -*-"
|
65
|
-
assert_encoding "# -*- mode:ruby; coding:utf-8 -*-"
|
66
|
-
assert_encoding "# -*- ruby encoding: utf-8 -*-"
|
67
|
-
assert_encoding "# -- encoding: utf-8 --"
|
68
|
-
assert_encoding "# ~*~ encoding: utf-8 ~*~"
|
69
|
-
assert_encoding "#-*- coding: utf-8 -*-"
|
70
|
-
assert_encoding "#-*- coding:utf-8"
|
71
|
-
assert_encoding "#-- -*- mode: ruby; encoding: utf-8 -*-\n"
|
72
|
-
end
|
73
|
-
|
74
|
-
def test_handle_encoding_wtf
|
75
|
-
assert_encoding "# coding : utf-8"
|
76
|
-
assert_encoding "# Ruby 1.9: encoding: utf-8"
|
77
|
-
assert_encoding "# Encoding: UTF-8 <-- required, please leave this in."
|
78
|
-
assert_encoding "# Encoding: UTF-8"
|
79
|
-
assert_encoding "# coding: utf-8"
|
80
|
-
assert_encoding "# coding:utf-8"
|
81
|
-
assert_encoding "# coding=utf-8"
|
82
|
-
assert_encoding "# encoding: ASCII"
|
83
|
-
assert_encoding "# encoding: ASCII-8BIT"
|
84
|
-
assert_encoding "# encoding: ISO-8859-1"
|
85
|
-
assert_encoding "# encoding: UTF-8"
|
86
|
-
assert_encoding "# encoding: ascii-8bit"
|
87
|
-
assert_encoding "# encoding: cp1252"
|
88
|
-
assert_encoding "# encoding: euc-jp -*-"
|
89
|
-
assert_encoding "# encoding: utf-8 # -*- ruby -*-"
|
90
|
-
assert_encoding "# encoding: utf-8 require 'github_api/utils/url'"
|
91
|
-
assert_encoding "# encoding: utf-8!"
|
92
|
-
assert_encoding "# encoding: utf-8"
|
93
|
-
assert_encoding "#<Encoding:UTF-8>"
|
94
|
-
assert_encoding "#Encoding: UTF-8"
|
95
|
-
assert_encoding "#coding:utf-8"
|
96
|
-
assert_encoding "#encoding: UTF-8!"
|
97
|
-
assert_encoding "#encoding: UTF-8"
|
98
|
-
assert_encoding "#encoding: cp1252"
|
99
|
-
assert_encoding "#encoding: sjis"
|
100
|
-
assert_encoding "#encoding: utf-8"
|
101
|
-
end
|
102
|
-
|
103
|
-
def test_handle_encoding_normal
|
104
|
-
assert_encoding "# encoding: UTF-8"
|
105
|
-
assert_encoding "# encoding: UTF-8\r\n" # UGH I hate windoze
|
106
|
-
assert_encoding "# coding: UTF-8"
|
107
|
-
assert_encoding "# encoding = UTF-8"
|
108
|
-
assert_encoding "# coding = UTF-8"
|
109
|
-
end
|
110
|
-
|
111
|
-
def test_handle_encoding_vim
|
112
|
-
assert_encoding "# vim: set fileencoding=utf-8 filetype=ruby ts=2 : "
|
113
|
-
assert_encoding "# vim: fileencoding=UTF-8 ft=ruby syn=ruby ts=2 sw=2 ai eol et si"
|
114
|
-
assert_encoding "# vim: fileencoding=UTF-8 nobomb sw=2 ts=2 et"
|
115
|
-
assert_encoding "# vim: filetype=ruby, fileencoding=UTF-8, tabsize=2, shiftwidth=2"
|
116
|
-
assert_encoding "# vim: set fileencoding=utf-8"
|
117
|
-
assert_encoding "# vim:encoding=UTF-8:"
|
118
|
-
assert_encoding "# vim:fileencoding=UTF-8:"
|
119
|
-
assert_encoding "# vim:set fileencoding=utf-8 filetype=ruby"
|
120
|
-
assert_encoding "# vim:set fileencoding=utf-8:"
|
121
|
-
end
|
122
|
-
|
123
|
-
def test_stack_state
|
124
|
-
s.push true
|
125
|
-
s.push false
|
126
|
-
s.lexpop
|
127
|
-
assert_equal [false, true], s.stack
|
128
|
-
end
|
129
|
-
|
130
|
-
def test_is_in_state
|
131
|
-
assert_equal false, s.is_in_state
|
132
|
-
s.push false
|
133
|
-
assert_equal false, s.is_in_state
|
134
|
-
s.push true
|
135
|
-
assert_equal true, s.is_in_state
|
136
|
-
s.push false
|
137
|
-
assert_equal false, s.is_in_state
|
138
|
-
end
|
139
|
-
|
140
|
-
def test_lexpop
|
141
|
-
assert_equal [false], s.stack
|
142
|
-
s.push true
|
143
|
-
s.push false
|
144
|
-
assert_equal [false, true, false], s.stack
|
145
|
-
s.lexpop
|
146
|
-
assert_equal [false, true], s.stack
|
147
|
-
end
|
148
|
-
|
149
|
-
def test_pop
|
150
|
-
assert_equal [false], s.stack
|
151
|
-
s.push true
|
152
|
-
assert_equal [false, true], s.stack
|
153
|
-
assert_equal true, s.pop
|
154
|
-
assert_equal [false], s.stack
|
155
|
-
end
|
156
|
-
|
157
|
-
def test_push
|
158
|
-
assert_equal [false], s.stack
|
159
|
-
s.push true
|
160
|
-
s.push false
|
161
|
-
assert_equal [false, true, false], s.stack
|
162
|
-
end
|
163
|
-
end
|
164
|
-
|
165
|
-
class TestEnvironment < MiniTest::Unit::TestCase
|
166
|
-
def deny t
|
167
|
-
assert ! t
|
168
|
-
end
|
169
|
-
|
170
|
-
def setup
|
171
|
-
@env = RubyParserStuff::Environment.new
|
172
|
-
@env[:blah] = 42
|
173
|
-
assert_equal 42, @env[:blah]
|
174
|
-
end
|
175
|
-
|
176
|
-
def test_var_scope_dynamic
|
177
|
-
@env.extend :dynamic
|
178
|
-
assert_equal 42, @env[:blah]
|
179
|
-
@env.unextend
|
180
|
-
assert_equal 42, @env[:blah]
|
181
|
-
end
|
182
|
-
|
183
|
-
def test_var_scope_static
|
184
|
-
@env.extend
|
185
|
-
assert_equal nil, @env[:blah]
|
186
|
-
@env.unextend
|
187
|
-
assert_equal 42, @env[:blah]
|
188
|
-
end
|
189
|
-
|
190
|
-
def test_all_dynamic
|
191
|
-
expected = { :blah => 42 }
|
192
|
-
|
193
|
-
@env.extend :dynamic
|
194
|
-
assert_equal expected, @env.all
|
195
|
-
@env.unextend
|
196
|
-
assert_equal expected, @env.all
|
197
|
-
end
|
198
|
-
|
199
|
-
def test_all_static
|
200
|
-
@env.extend
|
201
|
-
expected = { }
|
202
|
-
assert_equal expected, @env.all
|
203
|
-
|
204
|
-
@env.unextend
|
205
|
-
expected = { :blah => 42 }
|
206
|
-
assert_equal expected, @env.all
|
207
|
-
end
|
208
|
-
|
209
|
-
def test_all_static_deeper
|
210
|
-
expected0 = { :blah => 42 }
|
211
|
-
expected1 = { :blah => 42, :blah2 => 24 }
|
212
|
-
expected2 = { :blah => 27 }
|
213
|
-
|
214
|
-
@env.extend :dynamic
|
215
|
-
@env[:blah2] = 24
|
216
|
-
assert_equal expected1, @env.all
|
217
|
-
|
218
|
-
@env.extend
|
219
|
-
@env[:blah] = 27
|
220
|
-
assert_equal expected2, @env.all
|
221
|
-
|
222
|
-
@env.unextend
|
223
|
-
assert_equal expected1, @env.all
|
224
|
-
|
225
|
-
@env.unextend
|
226
|
-
assert_equal expected0, @env.all
|
227
|
-
end
|
228
|
-
end
|