rkelly 1.0.3 → 1.0.4
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/parser.y +3 -2
- data/lib/rkelly/constants.rb +1 -1
- data/lib/rkelly/generated_parser.rb +1278 -1241
- data/lib/rkelly/nodes/node.rb +1 -1
- data/lib/rkelly/tokenizer.rb +4 -2
- data/lib/rkelly/visitors/ecma_visitor.rb +5 -2
- data/lib/rkelly/visitors/evaluation_visitor.rb +1 -1
- data/lib/rkelly/visitors/pointcut_visitor.rb +1 -1
- data/lib/rkelly/visitors/visitor.rb +1 -1
- data/test/ecma_script_test_case.rb +3 -3
- data/test/execute_test_case.rb +3 -3
- data/test/helper.rb +2 -2
- data/test/node_test_case.rb +3 -3
- data/test/test_ecma_visitor.rb +6 -0
- data/test/test_tokenizer.rb +15 -1
- metadata +31 -54
data/lib/rkelly/nodes/node.rb
CHANGED
@@ -77,7 +77,7 @@ edge [ ];
|
|
77
77
|
end
|
78
78
|
end
|
79
79
|
|
80
|
-
%w[EmptyStatement ExpressionStatement True Delete Return TypeOf
|
80
|
+
%w[EmptyStatement Parenthetical ExpressionStatement True Delete Return TypeOf
|
81
81
|
SourceElements Number LogicalNot AssignExpr FunctionBody
|
82
82
|
ObjectLiteral UnaryMinus Throw This BitwiseNot Element String
|
83
83
|
Array CaseBlock Null Break Parameter Block False Void Regexp
|
data/lib/rkelly/tokenizer.rb
CHANGED
@@ -89,7 +89,7 @@ module RKelly
|
|
89
89
|
[value, value]
|
90
90
|
end
|
91
91
|
end
|
92
|
-
|
92
|
+
|
93
93
|
def tokenize(string)
|
94
94
|
raw_tokens(string).map { |x| x.to_racc_token }
|
95
95
|
end
|
@@ -111,7 +111,9 @@ module RKelly
|
|
111
111
|
longest_token = match
|
112
112
|
}
|
113
113
|
|
114
|
-
|
114
|
+
if longest_token.name != :S
|
115
|
+
accepting_regexp = followable_by_regex(longest_token)
|
116
|
+
end
|
115
117
|
|
116
118
|
longest_token.line = line_number
|
117
119
|
line_number += longest_token.value.scan(/\n/).length
|
@@ -5,6 +5,10 @@ module RKelly
|
|
5
5
|
@indent = 0
|
6
6
|
end
|
7
7
|
|
8
|
+
def visit_ParentheticalNode(o)
|
9
|
+
"(#{o.value.accept(self)})"
|
10
|
+
end
|
11
|
+
|
8
12
|
def visit_SourceElementsNode(o)
|
9
13
|
o.value.map { |x| "#{indent}#{x.accept(self)}" }.join("\n")
|
10
14
|
end
|
@@ -31,6 +35,7 @@ module RKelly
|
|
31
35
|
|
32
36
|
def visit_ForNode(o)
|
33
37
|
init = o.init ? o.init.accept(self) : ';'
|
38
|
+
init << ';' unless init.end_with? ';' # make sure it has a ;
|
34
39
|
test = o.test ? o.test.accept(self) : ''
|
35
40
|
counter = o.counter ? o.counter.accept(self) : ''
|
36
41
|
"for(#{init} #{test}; #{counter}) #{o.value.accept(self)}"
|
@@ -180,8 +185,6 @@ module RKelly
|
|
180
185
|
[:Divide, '/'],
|
181
186
|
[:Equal, '=='],
|
182
187
|
[:Greater, '>'],
|
183
|
-
[:Greater, '>'],
|
184
|
-
[:GreaterOrEqual, '>='],
|
185
188
|
[:GreaterOrEqual, '>='],
|
186
189
|
[:In, 'in'],
|
187
190
|
[:InstanceOf, 'instanceof'],
|
@@ -6,7 +6,7 @@ module RKelly
|
|
6
6
|
String This True
|
7
7
|
}
|
8
8
|
SINGLE_VALUE_NODES = %w{
|
9
|
-
AssignExpr BitwiseNot Block Delete Element ExpressionStatement
|
9
|
+
Parenthetical AssignExpr BitwiseNot Block Delete Element ExpressionStatement
|
10
10
|
FunctionBody LogicalNot Return Throw TypeOf UnaryMinus UnaryPlus Void
|
11
11
|
}
|
12
12
|
BINARY_NODES = %w{
|
data/test/execute_test_case.rb
CHANGED
@@ -1,9 +1,9 @@
|
|
1
|
-
require File.dirname(__FILE__) + "/helper"
|
2
|
-
|
3
1
|
class ExecuteTestCase < Test::Unit::TestCase
|
4
2
|
include RKelly::Nodes
|
5
3
|
|
6
|
-
|
4
|
+
if method_defined? :default_test
|
5
|
+
undef :default_test
|
6
|
+
end
|
7
7
|
|
8
8
|
def assert_execute(expected, code)
|
9
9
|
scope_chain = @runtime.execute(code)
|
data/test/helper.rb
CHANGED
data/test/node_test_case.rb
CHANGED
@@ -1,9 +1,9 @@
|
|
1
|
-
require File.dirname(__FILE__) + "/helper"
|
2
|
-
|
3
1
|
class NodeTestCase < Test::Unit::TestCase
|
4
2
|
include RKelly::Nodes
|
5
3
|
|
6
|
-
|
4
|
+
if method_defined? :default_test
|
5
|
+
undef :default_test
|
6
|
+
end
|
7
7
|
|
8
8
|
def assert_sexp(expected, actual)
|
9
9
|
assert_equal(expected, actual.to_sexp)
|
data/test/test_ecma_visitor.rb
CHANGED
@@ -183,6 +183,12 @@ class ECMAVisitorTest < Test::Unit::TestCase
|
|
183
183
|
assert_to_ecma('for(foo in bar) { var x = 10; }')
|
184
184
|
end
|
185
185
|
|
186
|
+
def test_for_node
|
187
|
+
assert_to_ecma('for(var i = 0; i < 10; i++) { var x = 10; }')
|
188
|
+
assert_to_ecma('var i = 0; for(; i < 10; i++) { var x = 10; }')
|
189
|
+
assert_to_ecma('var i; for(i = 0; i < 6; ++i) { var x = 10; }')
|
190
|
+
end
|
191
|
+
|
186
192
|
def assert_to_ecma(expected, actual = nil)
|
187
193
|
ecma = @parser.parse(actual || expected).to_ecma
|
188
194
|
ecma = ecma.gsub(/\n/, ' ').gsub(/\s+/, ' ')
|
data/test/test_tokenizer.rb
CHANGED
@@ -64,7 +64,7 @@ class TokenizerTest < Test::Unit::TestCase
|
|
64
64
|
], tokens)
|
65
65
|
end
|
66
66
|
|
67
|
-
def
|
67
|
+
def test_regular_expression
|
68
68
|
tokens = @tokenizer.tokenize("foo = /=asdf/;")
|
69
69
|
assert_tokens([
|
70
70
|
[:IDENT, 'foo'],
|
@@ -74,6 +74,20 @@ class TokenizerTest < Test::Unit::TestCase
|
|
74
74
|
], tokens)
|
75
75
|
end
|
76
76
|
|
77
|
+
def test_regular_expression_invalid
|
78
|
+
tokens = @tokenizer.tokenize("foo = (1 / 2) / 3")
|
79
|
+
assert_tokens([[:IDENT, "foo"],
|
80
|
+
["=", "="],
|
81
|
+
["(", "("],
|
82
|
+
[:NUMBER, 1],
|
83
|
+
["/", "/"],
|
84
|
+
[:NUMBER, 2],
|
85
|
+
[")", ")"],
|
86
|
+
["/", "/"],
|
87
|
+
[:NUMBER, 3]
|
88
|
+
], tokens)
|
89
|
+
end
|
90
|
+
|
77
91
|
def test_regular_expression_escape
|
78
92
|
tokens = @tokenizer.tokenize('foo = /\/asdf/gi;')
|
79
93
|
assert_tokens([
|
metadata
CHANGED
@@ -1,51 +1,37 @@
|
|
1
|
-
--- !ruby/object:Gem::Specification
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
2
|
name: rkelly
|
3
|
-
version: !ruby/object:Gem::Version
|
4
|
-
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 1.0.4
|
5
5
|
prerelease:
|
6
|
-
segments:
|
7
|
-
- 1
|
8
|
-
- 0
|
9
|
-
- 3
|
10
|
-
version: 1.0.3
|
11
6
|
platform: ruby
|
12
|
-
authors:
|
7
|
+
authors:
|
13
8
|
- Aaron Patterson
|
14
9
|
autorequire:
|
15
10
|
bindir: bin
|
16
11
|
cert_chain: []
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
dependencies:
|
21
|
-
- !ruby/object:Gem::Dependency
|
12
|
+
date: 2011-12-06 00:00:00.000000000Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
22
15
|
name: hoe
|
23
|
-
|
24
|
-
requirement: &id001 !ruby/object:Gem::Requirement
|
16
|
+
requirement: &2152981200 !ruby/object:Gem::Requirement
|
25
17
|
none: false
|
26
|
-
requirements:
|
27
|
-
- -
|
28
|
-
- !ruby/object:Gem::Version
|
29
|
-
|
30
|
-
segments:
|
31
|
-
- 2
|
32
|
-
- 9
|
33
|
-
- 1
|
34
|
-
version: 2.9.1
|
18
|
+
requirements:
|
19
|
+
- - ~>
|
20
|
+
- !ruby/object:Gem::Version
|
21
|
+
version: '2.12'
|
35
22
|
type: :development
|
36
|
-
|
23
|
+
prerelease: false
|
24
|
+
version_requirements: *2152981200
|
37
25
|
description: The RKelly library will parse JavaScript and return a parse tree.
|
38
|
-
email:
|
26
|
+
email:
|
39
27
|
- aaron.patterson@gmail.com
|
40
28
|
executables: []
|
41
|
-
|
42
29
|
extensions: []
|
43
|
-
|
44
|
-
extra_rdoc_files:
|
30
|
+
extra_rdoc_files:
|
45
31
|
- Manifest.txt
|
46
32
|
- CHANGELOG.rdoc
|
47
33
|
- README.rdoc
|
48
|
-
files:
|
34
|
+
files:
|
49
35
|
- CHANGELOG.rdoc
|
50
36
|
- Manifest.txt
|
51
37
|
- README.rdoc
|
@@ -246,42 +232,33 @@ files:
|
|
246
232
|
- test/test_while_node.rb
|
247
233
|
- test/test_with_node.rb
|
248
234
|
- .gemtest
|
249
|
-
has_rdoc: true
|
250
235
|
homepage: http://rkelly.rubyforge.org/
|
251
236
|
licenses: []
|
252
|
-
|
253
237
|
post_install_message:
|
254
|
-
rdoc_options:
|
238
|
+
rdoc_options:
|
255
239
|
- --main
|
256
240
|
- README.rdoc
|
257
|
-
require_paths:
|
241
|
+
require_paths:
|
258
242
|
- lib
|
259
|
-
required_ruby_version: !ruby/object:Gem::Requirement
|
243
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
260
244
|
none: false
|
261
|
-
requirements:
|
262
|
-
- -
|
263
|
-
- !ruby/object:Gem::Version
|
264
|
-
|
265
|
-
|
266
|
-
- 0
|
267
|
-
version: "0"
|
268
|
-
required_rubygems_version: !ruby/object:Gem::Requirement
|
245
|
+
requirements:
|
246
|
+
- - ! '>='
|
247
|
+
- !ruby/object:Gem::Version
|
248
|
+
version: '0'
|
249
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
269
250
|
none: false
|
270
|
-
requirements:
|
271
|
-
- -
|
272
|
-
- !ruby/object:Gem::Version
|
273
|
-
|
274
|
-
segments:
|
275
|
-
- 0
|
276
|
-
version: "0"
|
251
|
+
requirements:
|
252
|
+
- - ! '>='
|
253
|
+
- !ruby/object:Gem::Version
|
254
|
+
version: '0'
|
277
255
|
requirements: []
|
278
|
-
|
279
256
|
rubyforge_project: rkelly
|
280
|
-
rubygems_version: 1.
|
257
|
+
rubygems_version: 1.8.10
|
281
258
|
signing_key:
|
282
259
|
specification_version: 3
|
283
260
|
summary: The RKelly library will parse JavaScript and return a parse tree.
|
284
|
-
test_files:
|
261
|
+
test_files:
|
285
262
|
- test/execution_contexts/test_10_1_3-1.rb
|
286
263
|
- test/expressions/test_11_3_1.rb
|
287
264
|
- test/expressions/test_11_3_2.rb
|