rkelly-remix 0.0.1 → 0.0.2
Sign up to get free protection for your applications and to get access to all the features.
- data/README.rdoc +4 -30
- data/lib/rkelly/constants.rb +1 -1
- data/lib/rkelly/tokenizer.rb +13 -2
- data/test/test_tokenizer.rb +21 -0
- metadata +55 -63
data/README.rdoc
CHANGED
@@ -1,38 +1,12 @@
|
|
1
|
-
= RKelly
|
2
|
-
|
3
|
-
* http://rkelly.rubyforge.org/
|
1
|
+
= RKelly Remix
|
4
2
|
|
5
3
|
== DESCRIPTION
|
6
4
|
|
7
|
-
|
8
|
-
|
9
|
-
== Example
|
10
|
-
|
11
|
-
##
|
12
|
-
# Iterate over and modify a JavaScript AST. Then print the modified
|
13
|
-
# AST as JavaScript.
|
14
|
-
require 'rkelly'
|
5
|
+
Fork of the RKelly library to make it suitable as the JavaScript parser
|
6
|
+
in JSDuck.
|
15
7
|
|
16
|
-
|
17
|
-
ast = parser.parse(
|
18
|
-
"for(var i = 0; i < 10; i++) { var x = 5 + 5; }"
|
19
|
-
)
|
20
|
-
|
21
|
-
ast.each do |node|
|
22
|
-
node.value = 'hello' if node.value == 'i'
|
23
|
-
node.name = 'hello' if node.respond_to?(:name) && node.name == 'i'
|
24
|
-
end
|
25
|
-
puts ast.to_ecma # => awesome javascript
|
26
|
-
|
27
|
-
== Acknowledgments
|
28
|
-
|
29
|
-
The original javascript parser was was taken from rbnarcissus written by
|
30
|
-
Paul Sowden. Thanks Paul!
|
31
|
-
|
32
|
-
http://idontsmoke.co.uk/2005/rbnarcissus/
|
8
|
+
* http://rkelly.rubyforge.org/
|
33
9
|
|
34
|
-
The current parser was ported from WebKit. Thank you WebKit team!
|
35
|
-
|
36
10
|
== License
|
37
11
|
|
38
12
|
The MIT License
|
data/lib/rkelly/constants.rb
CHANGED
data/lib/rkelly/tokenizer.rb
CHANGED
@@ -64,12 +64,23 @@ module RKelly
|
|
64
64
|
'}' => true,
|
65
65
|
}
|
66
66
|
|
67
|
+
# Determine the method to use to measure String length in bytes,
|
68
|
+
# because StringScanner#pos can obly be set in bytes.
|
69
|
+
#
|
70
|
+
# - In Ruby 1.8 String#length returns always the string length
|
71
|
+
# in bytes.
|
72
|
+
#
|
73
|
+
# - In Ruby 1.9+ String#length returns string length in
|
74
|
+
# characters and we need to use String#bytesize instead.
|
75
|
+
#
|
76
|
+
BYTESIZE_METHOD = "".respond_to?(:bytesize) ? :bytesize : :length
|
77
|
+
|
67
78
|
def initialize(&block)
|
68
79
|
@lexemes = Hash.new {|hash, key| hash[key] = [] }
|
69
80
|
|
70
81
|
token(:COMMENT, /\/(?:\*(?:.)*?\*\/|\/[^\n]*)/m, ['/'])
|
71
82
|
token(:STRING, /"(?:[^"\\]*(?:\\.[^"\\]*)*)"|'(?:[^'\\]*(?:\\.[^'\\]*)*)'/m, ["'", '"'])
|
72
|
-
token(:S,
|
83
|
+
token(:S, /\s*/m, [" ", "\t", "\r", "\n", "\f"])
|
73
84
|
|
74
85
|
# A regexp to match floating point literals (but not integer literals).
|
75
86
|
digits = ('0'..'9').to_a
|
@@ -148,7 +159,7 @@ module RKelly
|
|
148
159
|
accepting_regexp = followable_by_regex(token)
|
149
160
|
end
|
150
161
|
|
151
|
-
scanner.pos += token.value.
|
162
|
+
scanner.pos += token.value.send(BYTESIZE_METHOD)
|
152
163
|
token.range = range = range.next(token.value)
|
153
164
|
tokens << token
|
154
165
|
end
|
data/test/test_tokenizer.rb
CHANGED
@@ -1,3 +1,4 @@
|
|
1
|
+
# -*- coding: utf-8 -*-
|
1
2
|
require File.dirname(__FILE__) + "/helper"
|
2
3
|
|
3
4
|
class TokenizerTest < Test::Unit::TestCase
|
@@ -162,6 +163,26 @@ class TokenizerTest < Test::Unit::TestCase
|
|
162
163
|
], tokens)
|
163
164
|
end
|
164
165
|
|
166
|
+
def test_unicode_string
|
167
|
+
tokens = @tokenizer.tokenize("foo = 'öäüõ';")
|
168
|
+
assert_tokens([
|
169
|
+
[:IDENT, 'foo'],
|
170
|
+
['=', '='],
|
171
|
+
[:STRING, "'öäüõ'"],
|
172
|
+
[';', ';'],
|
173
|
+
], tokens)
|
174
|
+
end
|
175
|
+
|
176
|
+
def test_unicode_regex
|
177
|
+
tokens = @tokenizer.tokenize("foo = /öäüõ/;")
|
178
|
+
assert_tokens([
|
179
|
+
[:IDENT, 'foo'],
|
180
|
+
['=', '='],
|
181
|
+
[:REGEXP, "/öäüõ/"],
|
182
|
+
[';', ';'],
|
183
|
+
], tokens)
|
184
|
+
end
|
185
|
+
|
165
186
|
def assert_tokens(expected, actual)
|
166
187
|
assert_equal(expected, actual.select { |x| x[0] != :S })
|
167
188
|
end
|
metadata
CHANGED
@@ -1,66 +1,65 @@
|
|
1
|
-
--- !ruby/object:Gem::Specification
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
2
|
name: rkelly-remix
|
3
|
-
version: !ruby/object:Gem::Version
|
4
|
-
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.2
|
5
5
|
prerelease:
|
6
|
-
segments:
|
7
|
-
- 0
|
8
|
-
- 0
|
9
|
-
- 1
|
10
|
-
version: 0.0.1
|
11
6
|
platform: ruby
|
12
|
-
authors:
|
7
|
+
authors:
|
13
8
|
- Aaron Patterson
|
14
9
|
- Rene Saarsoo
|
15
10
|
autorequire:
|
16
11
|
bindir: bin
|
17
12
|
cert_chain: []
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
- !ruby/object:Gem::Dependency
|
13
|
+
date: 2013-07-04 00:00:00.000000000 Z
|
14
|
+
dependencies:
|
15
|
+
- !ruby/object:Gem::Dependency
|
22
16
|
name: rdoc
|
23
|
-
|
24
|
-
requirement: &id001 !ruby/object:Gem::Requirement
|
17
|
+
requirement: !ruby/object:Gem::Requirement
|
25
18
|
none: false
|
26
|
-
requirements:
|
19
|
+
requirements:
|
27
20
|
- - ~>
|
28
|
-
- !ruby/object:Gem::Version
|
29
|
-
|
30
|
-
segments:
|
31
|
-
- 4
|
32
|
-
- 0
|
33
|
-
version: "4.0"
|
21
|
+
- !ruby/object:Gem::Version
|
22
|
+
version: '4.0'
|
34
23
|
type: :development
|
35
|
-
version_requirements: *id001
|
36
|
-
- !ruby/object:Gem::Dependency
|
37
|
-
name: hoe
|
38
24
|
prerelease: false
|
39
|
-
|
25
|
+
version_requirements: !ruby/object:Gem::Requirement
|
26
|
+
none: false
|
27
|
+
requirements:
|
28
|
+
- - ~>
|
29
|
+
- !ruby/object:Gem::Version
|
30
|
+
version: '4.0'
|
31
|
+
- !ruby/object:Gem::Dependency
|
32
|
+
name: hoe
|
33
|
+
requirement: !ruby/object:Gem::Requirement
|
40
34
|
none: false
|
41
|
-
requirements:
|
35
|
+
requirements:
|
42
36
|
- - ~>
|
43
|
-
- !ruby/object:Gem::Version
|
44
|
-
|
45
|
-
segments:
|
46
|
-
- 3
|
47
|
-
- 6
|
48
|
-
version: "3.6"
|
37
|
+
- !ruby/object:Gem::Version
|
38
|
+
version: '3.6'
|
49
39
|
type: :development
|
50
|
-
|
51
|
-
|
52
|
-
|
40
|
+
prerelease: false
|
41
|
+
version_requirements: !ruby/object:Gem::Requirement
|
42
|
+
none: false
|
43
|
+
requirements:
|
44
|
+
- - ~>
|
45
|
+
- !ruby/object:Gem::Version
|
46
|
+
version: '3.6'
|
47
|
+
description: ! 'Fork of the RKelly library to make it suitable as the JavaScript parser
|
48
|
+
|
49
|
+
in JSDuck.
|
50
|
+
|
51
|
+
|
52
|
+
* http://rkelly.rubyforge.org/'
|
53
|
+
email:
|
53
54
|
- aaron.patterson@gmail.com
|
54
55
|
- rene.saarsoo@sencha.com
|
55
56
|
executables: []
|
56
|
-
|
57
57
|
extensions: []
|
58
|
-
|
59
|
-
extra_rdoc_files:
|
58
|
+
extra_rdoc_files:
|
60
59
|
- CHANGELOG.rdoc
|
61
60
|
- Manifest.txt
|
62
61
|
- README.rdoc
|
63
|
-
files:
|
62
|
+
files:
|
64
63
|
- CHANGELOG.rdoc
|
65
64
|
- Manifest.txt
|
66
65
|
- README.rdoc
|
@@ -265,41 +264,34 @@ files:
|
|
265
264
|
- test/test_while_node.rb
|
266
265
|
- test/test_with_node.rb
|
267
266
|
- .gemtest
|
268
|
-
homepage:
|
267
|
+
homepage:
|
269
268
|
licenses: []
|
270
|
-
|
271
269
|
post_install_message:
|
272
|
-
rdoc_options:
|
270
|
+
rdoc_options:
|
273
271
|
- --main
|
274
272
|
- README.rdoc
|
275
|
-
require_paths:
|
273
|
+
require_paths:
|
276
274
|
- lib
|
277
|
-
required_ruby_version: !ruby/object:Gem::Requirement
|
275
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
278
276
|
none: false
|
279
|
-
requirements:
|
280
|
-
- -
|
281
|
-
- !ruby/object:Gem::Version
|
282
|
-
|
283
|
-
|
284
|
-
- 0
|
285
|
-
version: "0"
|
286
|
-
required_rubygems_version: !ruby/object:Gem::Requirement
|
277
|
+
requirements:
|
278
|
+
- - ! '>='
|
279
|
+
- !ruby/object:Gem::Version
|
280
|
+
version: '0'
|
281
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
287
282
|
none: false
|
288
|
-
requirements:
|
289
|
-
- -
|
290
|
-
- !ruby/object:Gem::Version
|
291
|
-
|
292
|
-
segments:
|
293
|
-
- 0
|
294
|
-
version: "0"
|
283
|
+
requirements:
|
284
|
+
- - ! '>='
|
285
|
+
- !ruby/object:Gem::Version
|
286
|
+
version: '0'
|
295
287
|
requirements: []
|
296
|
-
|
297
288
|
rubyforge_project: rkelly-remix
|
298
289
|
rubygems_version: 1.8.24
|
299
290
|
signing_key:
|
300
291
|
specification_version: 3
|
301
|
-
summary:
|
302
|
-
|
292
|
+
summary: Fork of the RKelly library to make it suitable as the JavaScript parser in
|
293
|
+
JSDuck
|
294
|
+
test_files:
|
303
295
|
- test/test_parser.rb
|
304
296
|
- test/test_ecma_visitor.rb
|
305
297
|
- test/test_arguments_node.rb
|