live_ast 0.2.1 → 0.2.2
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/CHANGES.rdoc +4 -0
- data/MANIFEST +4 -0
- data/lib/live_ast/base.rb +2 -1
- data/lib/live_ast/linker.rb +1 -1
- data/lib/live_ast/loader.rb +1 -11
- data/lib/live_ast/reader.rb +18 -0
- data/lib/live_ast/version.rb +1 -1
- data/test/encoding_test/koi8_with_utf8bom.rb +6 -0
- data/test/encoding_test/usascii_with_utf8bom.rb +6 -0
- data/test/encoding_test/utf8bom.rb +6 -0
- data/test/encoding_test.rb +6 -0
- metadata +14 -2
data/CHANGES.rdoc
CHANGED
data/MANIFEST
CHANGED
@@ -12,6 +12,7 @@ lib/live_ast/evaler.rb
|
|
12
12
|
lib/live_ast/linker.rb
|
13
13
|
lib/live_ast/loader.rb
|
14
14
|
lib/live_ast/parser.rb
|
15
|
+
lib/live_ast/reader.rb
|
15
16
|
lib/live_ast/replace_load.rb
|
16
17
|
lib/live_ast/replace_raise.rb
|
17
18
|
lib/live_ast/to_ast.rb
|
@@ -31,8 +32,11 @@ test/encoding_test/default.rb
|
|
31
32
|
test/encoding_test/eucjp.rb
|
32
33
|
test/encoding_test/koi8.rb
|
33
34
|
test/encoding_test/koi8_shebang.rb
|
35
|
+
test/encoding_test/koi8_with_utf8bom.rb
|
34
36
|
test/encoding_test/usascii.rb
|
37
|
+
test/encoding_test/usascii_with_utf8bom.rb
|
35
38
|
test/encoding_test/utf8.rb
|
39
|
+
test/encoding_test/utf8bom.rb
|
36
40
|
test/error_test.rb
|
37
41
|
test/eval_test.rb
|
38
42
|
test/flush_cache_test.rb
|
data/lib/live_ast/base.rb
CHANGED
data/lib/live_ast/linker.rb
CHANGED
@@ -85,7 +85,7 @@ module LiveAST
|
|
85
85
|
# File was loaded by 'require'.
|
86
86
|
# Play catch-up: assume it has not changed in the meantime.
|
87
87
|
#
|
88
|
-
_, cache = new_cache(
|
88
|
+
_, cache = new_cache(Reader.read(file), file, 1, true)
|
89
89
|
end
|
90
90
|
cache.fetch_ast(line) if cache
|
91
91
|
end
|
data/lib/live_ast/loader.rb
CHANGED
@@ -1,9 +1,5 @@
|
|
1
|
-
# encoding: us-ascii
|
2
|
-
|
3
1
|
module LiveAST
|
4
2
|
module Loader
|
5
|
-
MAGIC_COMMENT = /\A(?:#!.*?\n)?\s*\#.*(?:en)?coding\s*[:=]\s*([^\s;]+)/
|
6
|
-
|
7
3
|
class << self
|
8
4
|
def load(file, wrap)
|
9
5
|
file = find_file(file)
|
@@ -11,7 +7,7 @@ module LiveAST
|
|
11
7
|
# guards to protect toplevel locals
|
12
8
|
header, footer, warnings_ok = header_footer(wrap)
|
13
9
|
|
14
|
-
parser_src = read(file)
|
10
|
+
parser_src = Reader.read(file)
|
15
11
|
evaler_src = header << parser_src << footer
|
16
12
|
|
17
13
|
run = lambda do
|
@@ -21,12 +17,6 @@ module LiveAST
|
|
21
17
|
true
|
22
18
|
end
|
23
19
|
|
24
|
-
def read(file)
|
25
|
-
contents = File.read(file, :encoding => "BINARY")
|
26
|
-
encoding = contents[MAGIC_COMMENT, 1] || "US-ASCII"
|
27
|
-
contents.force_encoding(encoding)
|
28
|
-
end
|
29
|
-
|
30
20
|
def header_footer(wrap)
|
31
21
|
if wrap
|
32
22
|
return "class << Object.new;", ";end", true
|
@@ -0,0 +1,18 @@
|
|
1
|
+
# encoding: us-ascii
|
2
|
+
module LiveAST
|
3
|
+
module Reader
|
4
|
+
UTF8_BOM = /\A\xef\xbb\xbf/
|
5
|
+
MAGIC_COMMENT = /\A(?:#!.*?\n)?\s*\#.*(?:en)?coding\s*[:=]\s*([^\s;]+)/
|
6
|
+
|
7
|
+
def self.read(file)
|
8
|
+
contents = File.read(file, :encoding => "BINARY")
|
9
|
+
|
10
|
+
utf8 = contents.sub!(UTF8_BOM, "")
|
11
|
+
|
12
|
+
# magic comment overrides BOM
|
13
|
+
encoding = contents[MAGIC_COMMENT, 1] || utf8 || "US-ASCII"
|
14
|
+
|
15
|
+
contents.force_encoding(encoding)
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
data/lib/live_ast/version.rb
CHANGED
data/test/encoding_test.rb
CHANGED
@@ -3,6 +3,9 @@ require_relative 'shared/main'
|
|
3
3
|
require_relative 'encoding_test/default.rb'
|
4
4
|
require_relative 'encoding_test/usascii.rb'
|
5
5
|
require_relative 'encoding_test/utf8.rb'
|
6
|
+
require_relative 'encoding_test/utf8bom.rb'
|
7
|
+
require_relative 'encoding_test/usascii_with_utf8bom.rb'
|
8
|
+
require_relative 'encoding_test/koi8_with_utf8bom.rb'
|
6
9
|
require_relative 'encoding_test/cp932.rb'
|
7
10
|
require_relative 'encoding_test/eucjp.rb'
|
8
11
|
require_relative 'encoding_test/koi8.rb'
|
@@ -16,6 +19,9 @@ class AllEncodingTest < RegularTest
|
|
16
19
|
default US-ASCII
|
17
20
|
usascii US-ASCII
|
18
21
|
utf8 UTF-8
|
22
|
+
utf8bom UTF-8
|
23
|
+
usascii_with_utf8bom US-ASCII
|
24
|
+
koi8_with_utf8bom KOI8-R
|
19
25
|
cp932 Windows-31J
|
20
26
|
eucjp EUC-JP
|
21
27
|
koi8 KOI8-R
|
metadata
CHANGED
@@ -2,7 +2,7 @@
|
|
2
2
|
name: live_ast
|
3
3
|
version: !ruby/object:Gem::Version
|
4
4
|
prerelease:
|
5
|
-
version: 0.2.
|
5
|
+
version: 0.2.2
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
8
8
|
- James M. Lawrence
|
@@ -10,7 +10,7 @@ autorequire:
|
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
12
|
|
13
|
-
date: 2011-02-
|
13
|
+
date: 2011-02-21 00:00:00 -05:00
|
14
14
|
default_executable:
|
15
15
|
dependencies:
|
16
16
|
- !ruby/object:Gem::Dependency
|
@@ -47,6 +47,7 @@ files:
|
|
47
47
|
- lib/live_ast/linker.rb
|
48
48
|
- lib/live_ast/loader.rb
|
49
49
|
- lib/live_ast/parser.rb
|
50
|
+
- lib/live_ast/reader.rb
|
50
51
|
- lib/live_ast/replace_load.rb
|
51
52
|
- lib/live_ast/replace_raise.rb
|
52
53
|
- lib/live_ast/to_ast.rb
|
@@ -66,8 +67,11 @@ files:
|
|
66
67
|
- test/encoding_test/eucjp.rb
|
67
68
|
- test/encoding_test/koi8.rb
|
68
69
|
- test/encoding_test/koi8_shebang.rb
|
70
|
+
- test/encoding_test/koi8_with_utf8bom.rb
|
69
71
|
- test/encoding_test/usascii.rb
|
72
|
+
- test/encoding_test/usascii_with_utf8bom.rb
|
70
73
|
- test/encoding_test/utf8.rb
|
74
|
+
- test/encoding_test/utf8bom.rb
|
71
75
|
- test/error_test.rb
|
72
76
|
- test/eval_test.rb
|
73
77
|
- test/flush_cache_test.rb
|
@@ -118,6 +122,8 @@ rdoc_options:
|
|
118
122
|
- --exclude
|
119
123
|
- lib/live_ast/parser.rb
|
120
124
|
- --exclude
|
125
|
+
- lib/live_ast/reader.rb
|
126
|
+
- --exclude
|
121
127
|
- lib/live_ast/replace_load.rb
|
122
128
|
- --exclude
|
123
129
|
- lib/live_ast/replace_raise.rb
|
@@ -150,10 +156,16 @@ rdoc_options:
|
|
150
156
|
- --exclude
|
151
157
|
- test/encoding_test/koi8_shebang.rb
|
152
158
|
- --exclude
|
159
|
+
- test/encoding_test/koi8_with_utf8bom.rb
|
160
|
+
- --exclude
|
153
161
|
- test/encoding_test/usascii.rb
|
154
162
|
- --exclude
|
163
|
+
- test/encoding_test/usascii_with_utf8bom.rb
|
164
|
+
- --exclude
|
155
165
|
- test/encoding_test/utf8.rb
|
156
166
|
- --exclude
|
167
|
+
- test/encoding_test/utf8bom.rb
|
168
|
+
- --exclude
|
157
169
|
- test/error_test.rb
|
158
170
|
- --exclude
|
159
171
|
- test/eval_test.rb
|