parser 1.3.3 → 1.3.4
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/parser/lexer.rl +1 -1
- data/lib/parser/source/buffer.rb +7 -6
- data/lib/parser/version.rb +1 -1
- data/test/test_encoding.rb +10 -1
- data/test/test_lexer.rb +7 -0
- data/test/test_source_buffer.rb +9 -0
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 6cd417cce73823b5c02700b31b2ddc3364453aaf
|
4
|
+
data.tar.gz: 143425da0cc95ae994b1068807561968afb43267
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 1f55f2a694de612a9f9c71c428a91fa210134523b2377c4d5b2fe1276f64ddee27f4a702df979128d1b93172654fd7f684e9cbe3e297ccfcec53f00a29d90c8b
|
7
|
+
data.tar.gz: 634c5ce4b572ee896d4eb82443b43c6f91af5542121f1525eff684259f24f8d59fc23920d8ec3e93b47d46014baabd18ff9b6563e5f5102a9f55d1f832971ae1
|
data/lib/parser/lexer.rl
CHANGED
data/lib/parser/source/buffer.rb
CHANGED
@@ -8,12 +8,15 @@ module Parser
|
|
8
8
|
|
9
9
|
def self.recognize_encoding(string)
|
10
10
|
if string.empty?
|
11
|
-
return Encoding::
|
11
|
+
return Encoding::BINARY
|
12
12
|
end
|
13
13
|
|
14
14
|
# TODO: Make this more efficient.
|
15
15
|
first_line, second_line = string.lines.first(2)
|
16
|
-
|
16
|
+
|
17
|
+
[first_line, second_line].each do |line|
|
18
|
+
line.force_encoding(Encoding::ASCII_8BIT) if line
|
19
|
+
end
|
17
20
|
|
18
21
|
if first_line =~ /\A\xef\xbb\xbf/ # BOM
|
19
22
|
return Encoding::UTF_8
|
@@ -23,9 +26,7 @@ module Parser
|
|
23
26
|
encoding_line = first_line
|
24
27
|
end
|
25
28
|
|
26
|
-
encoding_line
|
27
|
-
|
28
|
-
if encoding_line =~ /coding[:=]?\s*([a-z0-9_-]+)/
|
29
|
+
if encoding_line =~ /^#.*coding[:=]\s*([a-z0-9_-]+)/
|
29
30
|
Encoding.find($1)
|
30
31
|
else
|
31
32
|
string.encoding
|
@@ -105,7 +106,7 @@ module Parser
|
|
105
106
|
end
|
106
107
|
end
|
107
108
|
|
108
|
-
@lines[line - @first_line]
|
109
|
+
@lines[line - @first_line].dup
|
109
110
|
end
|
110
111
|
|
111
112
|
private
|
data/lib/parser/version.rb
CHANGED
data/test/test_encoding.rb
CHANGED
@@ -25,7 +25,16 @@ class TestEncoding < MiniTest::Unit::TestCase
|
|
25
25
|
end
|
26
26
|
|
27
27
|
def test_empty
|
28
|
-
assert_equal Encoding::
|
28
|
+
assert_equal Encoding::BINARY, recognize("")
|
29
|
+
end
|
30
|
+
|
31
|
+
def test_no_comment
|
32
|
+
assert_equal Encoding::BINARY, recognize(%{require 'cane/encoding_aware_iterator'})
|
33
|
+
end
|
34
|
+
|
35
|
+
def test_adjacent
|
36
|
+
assert_equal Encoding::BINARY, recognize("# codingkoi8-r")
|
37
|
+
assert_equal Encoding::BINARY, recognize("# coding koi8-r")
|
29
38
|
end
|
30
39
|
end
|
31
40
|
end
|
data/test/test_lexer.rb
CHANGED
@@ -2117,6 +2117,13 @@ class TestLexer < MiniTest::Unit::TestCase
|
|
2117
2117
|
:kSELF, "self")
|
2118
2118
|
end
|
2119
2119
|
|
2120
|
+
def test_bug_const_expr_end
|
2121
|
+
util_lex_token("Option",
|
2122
|
+
:tCONSTANT, 'Option')
|
2123
|
+
|
2124
|
+
assert_equal :expr_arg, @lex.state
|
2125
|
+
end
|
2126
|
+
|
2120
2127
|
def test_bug_expr_beg_div
|
2121
2128
|
@lex.state = :expr_beg
|
2122
2129
|
util_lex_token("/=/",
|
data/test/test_source_buffer.rb
CHANGED
@@ -71,6 +71,15 @@ class TestSourceBuffer < MiniTest::Unit::TestCase
|
|
71
71
|
assert_equal "foo", @buffer.source_line(2)
|
72
72
|
end
|
73
73
|
|
74
|
+
def test_line_mutate
|
75
|
+
@buffer.source = "1\nfoo\nbar"
|
76
|
+
|
77
|
+
assert_equal "1", @buffer.source_line(1)
|
78
|
+
|
79
|
+
@buffer.source_line(1)[0] = '2'
|
80
|
+
assert_equal "1", @buffer.source_line(1)
|
81
|
+
end
|
82
|
+
|
74
83
|
def test_line_mapped
|
75
84
|
@buffer = Parser::Source::Buffer.new('(string)', 5)
|
76
85
|
@buffer.source = "1\nfoo\nbar"
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: parser
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.3.
|
4
|
+
version: 1.3.4
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Peter Zotov
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2013-05-
|
11
|
+
date: 2013-05-16 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: ast
|