live_ast 0.2.1 → 0.2.2

Sign up to get free protection for your applications and to get access to all the features.
data/CHANGES.rdoc CHANGED
@@ -1,6 +1,10 @@
1
1
 
2
2
  = LiveAST ChangeLog
3
3
 
4
+ == Version 0.2.2
5
+
6
+ * handle utf-8 BOMs in loading
7
+
4
8
  == Version 0.2.1
5
9
 
6
10
  * fixed some rdoc issues
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
@@ -1,9 +1,10 @@
1
1
  require 'thread'
2
2
 
3
+ require 'live_ast/reader'
3
4
  require 'live_ast/parser'
4
- require 'live_ast/loader'
5
5
  require 'live_ast/evaler'
6
6
  require 'live_ast/linker'
7
+ require 'live_ast/loader'
7
8
  require 'live_ast/error'
8
9
 
9
10
  module LiveAST
@@ -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(Loader.read(file), file, 1, true)
88
+ _, cache = new_cache(Reader.read(file), file, 1, true)
89
89
  end
90
90
  cache.fetch_ast(line) if cache
91
91
  end
@@ -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
@@ -1,3 +1,3 @@
1
1
  module LiveAST
2
- VERSION = "0.2.1"
2
+ VERSION = "0.2.2"
3
3
  end
@@ -0,0 +1,6 @@
1
+ # -*- coding: koi8-r -*-
2
+ module EncodingTest
3
+ def koi8_with_utf8bom_string
4
+ "� ���������� ������� ���������� �� 20 ��������"
5
+ end
6
+ end
@@ -0,0 +1,6 @@
1
+ # encoding: us-ascii
2
+ module EncodingTest
3
+ def usascii_with_utf8bom_string
4
+ "Cats and large boxes."
5
+ end
6
+ end
@@ -0,0 +1,6 @@
1
+ # -*- coding: utf-8 -*-
2
+ module EncodingTest
3
+ def utf8bom_string
4
+ "大きな箱とねこ。"
5
+ end
6
+ end
@@ -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.1
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-20 00:00:00 -05:00
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