parser 0.9.1 → 0.9.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.gitignore +1 -0
- data/Rakefile +2 -1
- data/TODO.md +20 -0
- data/bin/explain-parse +1 -1
- data/lib/parser/all.rb +1 -0
- data/lib/parser/builders/default.rb +30 -2
- data/lib/parser/lexer/literal.rb +41 -20
- data/lib/parser/lexer/stack_state.rb +4 -0
- data/lib/parser/lexer.rb +2585 -2545
- data/lib/parser/lexer.rl +61 -38
- data/lib/parser/ruby18.rb +3133 -3171
- data/lib/parser/ruby18.y +16 -30
- data/lib/parser/ruby19.rb +3319 -3388
- data/lib/parser/ruby19.y +35 -50
- data/lib/parser/ruby20.rb +6961 -0
- data/lib/parser/ruby20.y +2190 -0
- data/lib/parser.rb +0 -1
- data/parse.y.diff +12201 -0
- data/parser.gemspec +2 -1
- data/test/helper.rb +1 -1
- data/test/parse_helper.rb +2 -2
- data/test/test_lexer.rb +95 -5
- data/test/test_lexer_stack_state.rb +7 -0
- data/test/test_parser.rb +138 -5
- metadata +6 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: f90753aea951ab24c817278f94b4e1844151e496
|
4
|
+
data.tar.gz: 49a0cd6eb5dbf0fec9900f1d927ac20bdd8b90fd
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 01192b4d7d2b63f8348b2af97b567796f5aedfbb6562843dfce4590f1b15479997693e2b3d688ad3969d542ead2e4ab69389e6b5060da9f0b332ac165ee73c40
|
7
|
+
data.tar.gz: fdcbb3072c1c66d2d1ab3f54eb05f595eeab30860f9b59b5d1e472dc3ae681fdf3cb9376b2fd0945ef97cbabfb10a4f1959b4231ba9e0b8c9ee426625b5a14b5
|
data/.gitignore
CHANGED
data/Rakefile
CHANGED
data/TODO.md
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
# 2.0
|
2
|
+
|
3
|
+
1. test for "** interpreted as argument prefix" diagnostic
|
4
|
+
6. https://github.com/ruby/ruby/commit/c46bda
|
5
|
+
7. https://github.com/ruby/ruby/commit/1ab3974b0efea5155da005ec08a1feee90023d98
|
6
|
+
9. https://github.com/ruby/ruby/commit/d6a977f667f9d824cfe95976f3afc31e55580edb
|
7
|
+
10. https://github.com/ruby/ruby/commit/8fe3fb4c0f69535b302e124f3afc58dce4be5dbb
|
8
|
+
11. https://github.com/ruby/ruby/commit/3380974143d3fdf1721d9e28d6b2d42036f03bd2
|
9
|
+
|
10
|
+
# 2.1
|
11
|
+
|
12
|
+
1. https://github.com/ruby/ruby/commit/7ea675732ac1dac72f07756498706678d8725719
|
13
|
+
2. https://github.com/ruby/ruby/commit/38da1a5398f146a36910fde34b72dc9b3aa7918f
|
14
|
+
3. https://github.com/ruby/ruby/commit/e489dc1ff42ad3027319d7d01f4885164fdb410a
|
15
|
+
4. https://github.com/ruby/ruby/commit/c07d78eb0e8e9d3a8f9e8c860b362964157ff43a
|
16
|
+
5. https://github.com/ruby/ruby/commit/34a95669dad8843e3e9a4af683682ab2f50856dd
|
17
|
+
|
18
|
+
# All versions
|
19
|
+
|
20
|
+
1. https://github.com/ruby/ruby/commit/9150340b9bcbe305c2647a8d6f6f8e754769f3e7
|
data/bin/explain-parse
CHANGED
data/lib/parser/all.rb
CHANGED
@@ -91,10 +91,34 @@ module Parser
|
|
91
91
|
end
|
92
92
|
end
|
93
93
|
|
94
|
+
def word(parts)
|
95
|
+
if parts.one?
|
96
|
+
parts.first
|
97
|
+
else
|
98
|
+
s(:dstr, *parts)
|
99
|
+
end
|
100
|
+
end
|
101
|
+
|
94
102
|
def words_compose(begin_t, parts, end_t)
|
95
103
|
s(:array, *parts)
|
96
104
|
end
|
97
105
|
|
106
|
+
def symbols_compose(begin_t, parts, end_t)
|
107
|
+
parts = parts.map do |part|
|
108
|
+
case part.type
|
109
|
+
when :str
|
110
|
+
value, = *part
|
111
|
+
part.updated(:sym, [ value.to_sym ])
|
112
|
+
when :dstr
|
113
|
+
part.updated(:dsym)
|
114
|
+
else
|
115
|
+
part
|
116
|
+
end
|
117
|
+
end
|
118
|
+
|
119
|
+
s(:array, *parts)
|
120
|
+
end
|
121
|
+
|
98
122
|
# Hashes
|
99
123
|
|
100
124
|
def pair(key, assoc_t, value)
|
@@ -133,7 +157,11 @@ module Parser
|
|
133
157
|
#
|
134
158
|
|
135
159
|
def parenthesize(begin_t, expr, end_t)
|
136
|
-
expr
|
160
|
+
if expr.nil?
|
161
|
+
s(:nil)
|
162
|
+
else
|
163
|
+
expr
|
164
|
+
end
|
137
165
|
end
|
138
166
|
|
139
167
|
#
|
@@ -511,7 +539,7 @@ module Parser
|
|
511
539
|
# Logical operations: and, or
|
512
540
|
|
513
541
|
def logical_op(type, lhs, token, rhs)
|
514
|
-
s(type, lhs, rhs)
|
542
|
+
s(type, check_condition(lhs), check_condition(rhs))
|
515
543
|
end
|
516
544
|
|
517
545
|
# Conditionals
|
data/lib/parser/lexer/literal.rb
CHANGED
@@ -5,25 +5,28 @@ module Parser
|
|
5
5
|
MONOLITHIC = { :tSTRING_BEG => :tSTRING, :tSYMBEG => :tSYMBOL }
|
6
6
|
|
7
7
|
TYPES = {
|
8
|
-
# type start token
|
9
|
-
"'" => [ :tSTRING_BEG,
|
10
|
-
'%q' => [ :tSTRING_BEG,
|
11
|
-
'"' => [ :tSTRING_BEG,
|
12
|
-
'%' => [ :tSTRING_BEG,
|
13
|
-
'%Q' => [ :tSTRING_BEG,
|
8
|
+
# type start token interpolate?
|
9
|
+
"'" => [ :tSTRING_BEG, false ],
|
10
|
+
'%q' => [ :tSTRING_BEG, false ],
|
11
|
+
'"' => [ :tSTRING_BEG, true ],
|
12
|
+
'%' => [ :tSTRING_BEG, true ],
|
13
|
+
'%Q' => [ :tSTRING_BEG, true ],
|
14
14
|
|
15
|
-
'%w' => [ :tQWORDS_BEG,
|
16
|
-
'%W' => [ :tWORDS_BEG,
|
15
|
+
'%w' => [ :tQWORDS_BEG, false ],
|
16
|
+
'%W' => [ :tWORDS_BEG, true ],
|
17
17
|
|
18
|
-
|
19
|
-
'%
|
20
|
-
':"' => [ :tSYMBEG, true ],
|
18
|
+
'%i' => [ :tQSYMBOLS_BEG, false ],
|
19
|
+
'%I' => [ :tSYMBOLS_BEG, true ],
|
21
20
|
|
22
|
-
'
|
23
|
-
'%
|
21
|
+
":'" => [ :tSYMBEG, false ],
|
22
|
+
'%s' => [ :tSYMBEG, false ],
|
23
|
+
':"' => [ :tSYMBEG, true ],
|
24
24
|
|
25
|
-
'
|
26
|
-
'
|
25
|
+
'/' => [ :tREGEXP_BEG, true ],
|
26
|
+
'%r' => [ :tREGEXP_BEG, true ],
|
27
|
+
|
28
|
+
'%x' => [ :tXSTRING_BEG, true ],
|
29
|
+
'`' => [ :tXSTRING_BEG, true ],
|
27
30
|
}
|
28
31
|
|
29
32
|
attr_reader :heredoc_e, :str_s
|
@@ -57,6 +60,8 @@ module Parser
|
|
57
60
|
|
58
61
|
@interp_braces = 0
|
59
62
|
|
63
|
+
@space_emitted = true
|
64
|
+
|
60
65
|
# Monolithic strings are glued into a single token, e.g.
|
61
66
|
# tSTRING_BEG tSTRING_CONTENT tSTRING_END -> tSTRING.
|
62
67
|
@monolithic = (
|
@@ -77,7 +82,8 @@ module Parser
|
|
77
82
|
end
|
78
83
|
|
79
84
|
def words?
|
80
|
-
type == :tWORDS_BEG || type == :tQWORDS_BEG
|
85
|
+
type == :tWORDS_BEG || type == :tQWORDS_BEG ||
|
86
|
+
type == :tSYMBOLS_BEG || type == :tQSYMBOLS_BEG
|
81
87
|
end
|
82
88
|
|
83
89
|
def regexp?
|
@@ -117,6 +123,10 @@ module Parser
|
|
117
123
|
|
118
124
|
# Finalize if last matching delimiter is closed.
|
119
125
|
if @nesting == 0
|
126
|
+
if words?
|
127
|
+
extend_space(ts, ts)
|
128
|
+
end
|
129
|
+
|
120
130
|
# Emit the string as a single token if it's applicable.
|
121
131
|
if @monolithic
|
122
132
|
emit(MONOLITHIC[@start_tok], @buffer, @str_s, te)
|
@@ -160,13 +170,24 @@ module Parser
|
|
160
170
|
unless @buffer.empty?
|
161
171
|
emit(:tSTRING_CONTENT, @buffer, @buffer_s, @buffer_e)
|
162
172
|
|
163
|
-
if words?
|
164
|
-
emit(:tSPACE, nil, @buffer_e, @buffer_e + 1)
|
165
|
-
end
|
166
|
-
|
167
173
|
@buffer = ''
|
168
174
|
@buffer_s = nil
|
169
175
|
@buffer_e = nil
|
176
|
+
extend_content
|
177
|
+
end
|
178
|
+
end
|
179
|
+
|
180
|
+
def extend_content
|
181
|
+
@space_emitted = false
|
182
|
+
end
|
183
|
+
|
184
|
+
def extend_space(ts, te)
|
185
|
+
flush_string
|
186
|
+
|
187
|
+
unless @space_emitted
|
188
|
+
emit(:tSPACE, nil, ts, te)
|
189
|
+
|
190
|
+
@space_emitted = true
|
170
191
|
end
|
171
192
|
end
|
172
193
|
|