rkelly 1.0.3 → 1.0.4

Sign up to get free protection for your applications and to get access to all the features.
@@ -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
@@ -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
- accepting_regexp = followable_by_regex(longest_token)
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'],
@@ -315,7 +315,7 @@ module RKelly
315
315
  when Numeric
316
316
  object.value
317
317
  when ::String
318
- s = object.value.gsub(/(\A[\s\xB\xA0]*|[\s\xB\xA0]*\Z)/, '')
318
+ s = object.value.gsub(/(\A[\s\xA0]*|[\s\xA0]*\Z)/, '')
319
319
  if s.length == 0
320
320
  0
321
321
  else
@@ -23,7 +23,7 @@ module RKelly
23
23
  ALL_NODES.each do |type|
24
24
  define_method(:"visit_#{type}Node") do |o|
25
25
  @matches << o if @pattern === o
26
- super
26
+ super(o)
27
27
  end
28
28
  end
29
29
  end
@@ -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{
@@ -1,9 +1,9 @@
1
- require File.dirname(__FILE__) + "/helper"
2
-
3
1
  class ECMAScriptTestCase < Test::Unit::TestCase
4
2
  include RKelly::JS
5
3
 
6
- undef :default_test
4
+ if method_defined? :default_test
5
+ undef :default_test
6
+ end
7
7
 
8
8
  def setup
9
9
  @runtime = RKelly::Runtime.new
@@ -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
- undef :default_test
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
@@ -1,5 +1,5 @@
1
1
  require 'test/unit'
2
2
  require 'rkelly'
3
- require 'test/node_test_case'
4
- require 'test/execute_test_case'
5
3
  require 'test/ecma_script_test_case'
4
+ require 'test/execute_test_case'
5
+ require 'test/node_test_case'
@@ -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
- undef :default_test
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)
@@ -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+/, ' ')
@@ -64,7 +64,7 @@ class TokenizerTest < Test::Unit::TestCase
64
64
  ], tokens)
65
65
  end
66
66
 
67
- def test_regex
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
- hash: 17
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
- date: 2011-02-28 00:00:00 -08:00
19
- default_executable:
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
- prerelease: false
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
- hash: 41
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
- version_requirements: *id001
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
- hash: 3
265
- segments:
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
- hash: 3
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.5.2
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