parser 2.4.0.2 → 2.5.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.travis.yml +5 -6
- data/CHANGELOG.md +35 -1
- data/Gemfile +2 -0
- data/README.md +1 -2
- data/Rakefile +2 -1
- data/bin/ruby-parse +2 -1
- data/bin/ruby-rewrite +2 -1
- data/lib/gauntlet_parser.rb +2 -0
- data/lib/parser.rb +16 -17
- data/lib/parser/all.rb +2 -0
- data/lib/parser/ast/node.rb +2 -0
- data/lib/parser/ast/processor.rb +2 -0
- data/lib/parser/base.rb +6 -12
- data/lib/parser/builders/default.rb +28 -47
- data/lib/parser/clobbering_error.rb +2 -0
- data/lib/parser/context.rb +42 -0
- data/lib/parser/current.rb +4 -20
- data/lib/parser/deprecation.rb +13 -0
- data/lib/parser/diagnostic.rb +3 -3
- data/lib/parser/diagnostic/engine.rb +2 -0
- data/lib/parser/lexer.rl +122 -60
- data/lib/parser/lexer/dedenter.rb +2 -0
- data/lib/parser/lexer/explanation.rb +2 -0
- data/lib/parser/lexer/literal.rb +4 -9
- data/lib/parser/lexer/stack_state.rb +4 -1
- data/lib/parser/macruby.y +32 -17
- data/lib/parser/messages.rb +14 -0
- data/lib/parser/meta.rb +2 -0
- data/lib/parser/rewriter.rb +30 -44
- data/lib/parser/ruby18.y +20 -13
- data/lib/parser/ruby19.y +32 -17
- data/lib/parser/ruby20.y +33 -18
- data/lib/parser/ruby21.y +32 -17
- data/lib/parser/ruby22.y +32 -17
- data/lib/parser/ruby23.y +32 -17
- data/lib/parser/ruby24.y +63 -46
- data/lib/parser/ruby25.y +72 -48
- data/lib/parser/rubymotion.y +33 -18
- data/lib/parser/runner.rb +4 -7
- data/lib/parser/runner/ruby_parse.rb +10 -0
- data/lib/parser/runner/ruby_rewrite.rb +2 -0
- data/lib/parser/source/buffer.rb +19 -24
- data/lib/parser/source/comment.rb +2 -0
- data/lib/parser/source/comment/associator.rb +2 -0
- data/lib/parser/source/map.rb +2 -0
- data/lib/parser/source/map/collection.rb +2 -0
- data/lib/parser/source/map/condition.rb +2 -0
- data/lib/parser/source/map/constant.rb +2 -0
- data/lib/parser/source/map/definition.rb +2 -0
- data/lib/parser/source/map/for.rb +2 -0
- data/lib/parser/source/map/heredoc.rb +2 -0
- data/lib/parser/source/map/keyword.rb +2 -0
- data/lib/parser/source/map/objc_kwarg.rb +2 -0
- data/lib/parser/source/map/operator.rb +2 -0
- data/lib/parser/source/map/rescue_body.rb +2 -0
- data/lib/parser/source/map/send.rb +2 -0
- data/lib/parser/source/map/ternary.rb +2 -0
- data/lib/parser/source/map/variable.rb +2 -0
- data/lib/parser/source/range.rb +81 -13
- data/lib/parser/source/rewriter.rb +48 -10
- data/lib/parser/source/rewriter/action.rb +2 -0
- data/lib/parser/source/tree_rewriter.rb +301 -0
- data/lib/parser/source/tree_rewriter/action.rb +133 -0
- data/lib/parser/static_environment.rb +2 -0
- data/lib/parser/syntax_error.rb +2 -0
- data/lib/parser/tree_rewriter.rb +133 -0
- data/lib/parser/version.rb +3 -1
- data/parser.gemspec +4 -1
- data/test/bug_163/fixtures/input.rb +2 -0
- data/test/bug_163/fixtures/output.rb +2 -0
- data/test/bug_163/rewriter.rb +2 -0
- data/test/helper.rb +7 -7
- data/test/parse_helper.rb +57 -10
- data/test/racc_coverage_helper.rb +2 -0
- data/test/test_base.rb +2 -0
- data/test/test_current.rb +2 -4
- data/test/test_diagnostic.rb +3 -1
- data/test/test_diagnostic_engine.rb +2 -0
- data/test/test_encoding.rb +61 -49
- data/test/test_lexer.rb +164 -77
- data/test/test_lexer_stack_state.rb +2 -0
- data/test/test_parse_helper.rb +8 -8
- data/test/test_parser.rb +613 -51
- data/test/test_runner_rewrite.rb +47 -0
- data/test/test_source_buffer.rb +22 -10
- data/test/test_source_comment.rb +2 -0
- data/test/test_source_comment_associator.rb +2 -0
- data/test/test_source_map.rb +2 -0
- data/test/test_source_range.rb +92 -45
- data/test/test_source_rewriter.rb +3 -1
- data/test/test_source_rewriter_action.rb +2 -0
- data/test/test_source_tree_rewriter.rb +177 -0
- data/test/test_static_environment.rb +2 -0
- data/test/using_tree_rewriter/fixtures/input.rb +3 -0
- data/test/using_tree_rewriter/fixtures/output.rb +3 -0
- data/test/using_tree_rewriter/using_tree_rewriter.rb +9 -0
- metadata +21 -10
- data/lib/parser/compatibility/ruby1_8.rb +0 -20
- data/lib/parser/compatibility/ruby1_9.rb +0 -32
- data/test/bug_163/test_runner_rewrite.rb +0 -35
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 17012e63bed58664c7f879ca77f492e6d551962a
|
4
|
+
data.tar.gz: 1ba7782eabfc5d33ffbcd5a3f5c7ce1b149e0eb1
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 88787ec044608f586f8d1f9f2ced18005d1af68b5ff6f4cfc7633161bb8e6004aac032803da28c2b37255f98023b47c33d322806096239b1166dc117bf6a1459
|
7
|
+
data.tar.gz: 564a7e7e4e75bb412677011482eef36cff953fd023f3b889f0bc922ec0f51e36d6110cd1f01cc18d0d670a286a71aa58b8ad2ef3b268c7582e3afbe4cd45e442
|
data/.travis.yml
CHANGED
data/CHANGELOG.md
CHANGED
@@ -1,9 +1,43 @@
|
|
1
1
|
Changelog
|
2
2
|
=========
|
3
3
|
|
4
|
-
Not released (
|
4
|
+
Not released (2018-02-16)
|
5
5
|
-------------------------
|
6
6
|
|
7
|
+
API modifications:
|
8
|
+
* Parser::Current: bump to 2.2.9 and 2.3.6. (Stan Hu)
|
9
|
+
* Deprecate Parser::Rewriter (Marc-Andre Lafortune)
|
10
|
+
* Deprecate Parser::Source::Rewriter (Marc-Andre Lafortune)
|
11
|
+
* Change relative order of insert_after_multi and insert_before_multi for non-empty ranges (#399). (Marc-Andre Lafortune)
|
12
|
+
|
13
|
+
Features implemented:
|
14
|
+
* parse.y: Reject brace after literal arg. This commit tracks upstream commits ruby/ruby@9987109 and ruby/ruby@7d6965f. (Ilya Bylich)
|
15
|
+
* ruby-parse: add an option for emitting AST as JSON. (Alex Rattray)
|
16
|
+
* Add Parser::TreeRewriter (Marc-Andre Lafortune)
|
17
|
+
* Add Parser::Rewriter#wrap to ease compatibility (Marc-Andre Lafortune)
|
18
|
+
* Add Parser::Source::TreeRewriter (Marc-Andre Lafortune)
|
19
|
+
* Add Range#\<=> and include Comparable (Marc-Andre Lafortune)
|
20
|
+
* parse.y: disable tLPAREN_ARG state after local variable. (Ilya Bylich)
|
21
|
+
* SourceBuffer#source_range (Marc-Andre Lafortune)
|
22
|
+
* Range#adjust (Marc-Andre Lafortune)
|
23
|
+
* Range#contains?, contained?, crossing? (Marc-Andre Lafortune)
|
24
|
+
* Add Range#with. (Marc-André Lafortune)
|
25
|
+
* lexer.rl: Relax restriction spaces inside "\u{...}". This commit tracks upstream commit ruby/ruby@7e8b910. (Ilya Bylich)
|
26
|
+
* lexer.rl: Allow newlines in heredoc identifiers. This commit tracks upstream commit ruby/ruby@d25faa4. (Ilya Bylich)
|
27
|
+
* lexer.rl: allow do after cmdarg in paren. This commit tracks upstream commit ruby/ruby@046c943. (Ilya Bylich)
|
28
|
+
|
29
|
+
Bugs fixed:
|
30
|
+
* Fixed magic encoding comment parsing when encoding comment is on the first line but not in the beginning. (Ilya Bylich)
|
31
|
+
* lexer.rl: Parse '1if' as '1 if', '1rescue' as '1 rescue'. (Ilya Bylich)
|
32
|
+
* lexer.rl: Save state before entering a block comment to enter it after =end. (Ilya Bylich)
|
33
|
+
* parse.y: Prohibit return in class/module body except for singleton class. Replaced @def_level/in_def? in favor of context.indirectly_in_def?. This commit tracks upstream commit ruby/ruby@8c15f40ac. (Ilya Bylich)
|
34
|
+
* lexer.rl: Emit :&& as tSYMBEG + tANDOP, :|| as tSYMBEG + tOROP. (Ilya Bylich)
|
35
|
+
* ruby{24,25}.y: preserve cmdarg stack around do/end block [Bug #13073]. (Mateusz Lenik)
|
36
|
+
* Parser::Lexer::State: Fixed #lexpop to match MRI behavior. (Ilya Bylich)
|
37
|
+
|
38
|
+
v2.4.0.2 (2017-11-13)
|
39
|
+
---------------------
|
40
|
+
|
7
41
|
API modifications:
|
8
42
|
* parser/current: update for 2.3.5 release. (whitequark)
|
9
43
|
|
data/Gemfile
CHANGED
data/README.md
CHANGED
@@ -110,8 +110,7 @@ with Parser:
|
|
110
110
|
* [Rewriting][rewriting] support.
|
111
111
|
* Parsing error recovery.
|
112
112
|
* Improved [clang-like][] diagnostic messages with location information.
|
113
|
-
* Written in pure Ruby, runs on MRI
|
114
|
-
and 1.9 mode.
|
113
|
+
* Written in pure Ruby, runs on MRI >=2.0.0, JRuby and Rubinius (and historically, all versions of Ruby since 1.8)
|
115
114
|
* Only one runtime dependency: the [ast][] gem.
|
116
115
|
* [Insane][insane-lexer] Ruby lexer rewritten from scratch in Ragel.
|
117
116
|
* 100% test coverage for Bison grammars (except error recovery).
|
data/Rakefile
CHANGED
data/bin/ruby-parse
CHANGED
data/bin/ruby-rewrite
CHANGED
data/lib/gauntlet_parser.rb
CHANGED
data/lib/parser.rb
CHANGED
@@ -1,22 +1,25 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
if RUBY_VERSION =~ /^1\.[89]\./
|
4
|
+
require 'parser/version'
|
5
|
+
raise LoadError, <<-UNSUPPORTED_VERSION_MSG
|
6
|
+
parser v#{Parser::VERSION} cannot run on Ruby #{RUBY_VERSION}.
|
7
|
+
Please upgrade to Ruby 2.0.0 or higher, or use an older version of the parser gem.
|
8
|
+
UNSUPPORTED_VERSION_MSG
|
9
|
+
end
|
10
|
+
|
1
11
|
require 'set'
|
2
12
|
require 'racc/parser'
|
3
13
|
|
4
14
|
require 'ast'
|
5
15
|
|
6
|
-
if RUBY_VERSION < '1.9'
|
7
|
-
require 'parser/compatibility/ruby1_8'
|
8
|
-
end
|
9
|
-
|
10
|
-
if RUBY_VERSION < '2.0'
|
11
|
-
require 'parser/compatibility/ruby1_9'
|
12
|
-
end
|
13
|
-
|
14
16
|
##
|
15
17
|
# @api public
|
16
18
|
#
|
17
19
|
module Parser
|
18
20
|
require 'parser/version'
|
19
21
|
require 'parser/messages'
|
22
|
+
require 'parser/deprecation'
|
20
23
|
|
21
24
|
module AST
|
22
25
|
require 'parser/ast/node'
|
@@ -33,6 +36,8 @@ module Parser
|
|
33
36
|
|
34
37
|
require 'parser/source/rewriter'
|
35
38
|
require 'parser/source/rewriter/action'
|
39
|
+
require 'parser/source/tree_rewriter'
|
40
|
+
require 'parser/source/tree_rewriter/action'
|
36
41
|
|
37
42
|
require 'parser/source/map'
|
38
43
|
require 'parser/source/map/operator'
|
@@ -66,16 +71,10 @@ module Parser
|
|
66
71
|
require 'parser/builders/default'
|
67
72
|
end
|
68
73
|
|
74
|
+
require 'parser/context'
|
75
|
+
|
69
76
|
require 'parser/base'
|
70
77
|
|
71
78
|
require 'parser/rewriter'
|
72
|
-
|
73
|
-
##
|
74
|
-
# Verify that the current Ruby implementation supports Encoding.
|
75
|
-
# @raise [RuntimeError]
|
76
|
-
def self.check_for_encoding_support
|
77
|
-
unless defined?(Encoding)
|
78
|
-
raise RuntimeError, 'Parsing 1.9 and later versions of Ruby is not supported on 1.8 due to the lack of Encoding support'
|
79
|
-
end
|
80
|
-
end
|
79
|
+
require 'parser/tree_rewriter'
|
81
80
|
end
|
data/lib/parser/all.rb
CHANGED
data/lib/parser/ast/node.rb
CHANGED
data/lib/parser/ast/processor.rb
CHANGED
data/lib/parser/base.rb
CHANGED
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
module Parser
|
2
4
|
|
3
5
|
##
|
@@ -93,9 +95,7 @@ module Parser
|
|
93
95
|
end
|
94
96
|
|
95
97
|
def self.setup_source_buffer(file, line, string, encoding)
|
96
|
-
|
97
|
-
string = string.dup.force_encoding(encoding)
|
98
|
-
end
|
98
|
+
string = string.dup.force_encoding(encoding)
|
99
99
|
|
100
100
|
source_buffer = Source::Buffer.new(file, line)
|
101
101
|
|
@@ -113,6 +113,7 @@ module Parser
|
|
113
113
|
attr_reader :builder
|
114
114
|
attr_reader :static_env
|
115
115
|
attr_reader :source_buffer
|
116
|
+
attr_reader :context
|
116
117
|
|
117
118
|
##
|
118
119
|
# @param [Parser::Builders::Default] builder The AST builder to use.
|
@@ -128,6 +129,7 @@ module Parser
|
|
128
129
|
|
129
130
|
@builder = builder
|
130
131
|
@builder.parser = self
|
132
|
+
@context = Context.new
|
131
133
|
|
132
134
|
if self.class::Racc_debug_parser && ENV['RACC_DEBUG']
|
133
135
|
@yydebug = true
|
@@ -141,10 +143,10 @@ module Parser
|
|
141
143
|
#
|
142
144
|
def reset
|
143
145
|
@source_buffer = nil
|
144
|
-
@def_level = 0 # count of nested def's.
|
145
146
|
|
146
147
|
@lexer.reset
|
147
148
|
@static_env.reset
|
149
|
+
@context.reset
|
148
150
|
|
149
151
|
self
|
150
152
|
end
|
@@ -217,14 +219,6 @@ module Parser
|
|
217
219
|
@lexer.comments = nil
|
218
220
|
end
|
219
221
|
|
220
|
-
##
|
221
|
-
# @api private
|
222
|
-
# @return [Boolean]
|
223
|
-
#
|
224
|
-
def in_def?
|
225
|
-
@def_level > 0
|
226
|
-
end
|
227
|
-
|
228
222
|
private
|
229
223
|
|
230
224
|
def next_token
|
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
module Parser
|
2
4
|
|
3
5
|
##
|
@@ -479,7 +481,7 @@ module Parser
|
|
479
481
|
node.updated(:gvasgn)
|
480
482
|
|
481
483
|
when :const
|
482
|
-
if @parser.
|
484
|
+
if @parser.context.indirectly_in_def?
|
483
485
|
diagnostic :error, :dynamic_const, nil, node.loc.expression
|
484
486
|
end
|
485
487
|
|
@@ -1207,13 +1209,9 @@ module Parser
|
|
1207
1209
|
def delimited_string_map(string_t)
|
1208
1210
|
str_range = loc(string_t)
|
1209
1211
|
|
1210
|
-
begin_l =
|
1211
|
-
str_range.begin_pos,
|
1212
|
-
str_range.begin_pos + 1)
|
1212
|
+
begin_l = str_range.with(end_pos: str_range.begin_pos + 1)
|
1213
1213
|
|
1214
|
-
end_l =
|
1215
|
-
str_range.end_pos - 1,
|
1216
|
-
str_range.end_pos)
|
1214
|
+
end_l = str_range.with(begin_pos: str_range.end_pos - 1)
|
1217
1215
|
|
1218
1216
|
Source::Map::Collection.new(begin_l, end_l,
|
1219
1217
|
loc(string_t))
|
@@ -1222,9 +1220,7 @@ module Parser
|
|
1222
1220
|
def prefix_string_map(symbol)
|
1223
1221
|
str_range = loc(symbol)
|
1224
1222
|
|
1225
|
-
begin_l =
|
1226
|
-
str_range.begin_pos,
|
1227
|
-
str_range.begin_pos + 1)
|
1223
|
+
begin_l = str_range.with(end_pos: str_range.begin_pos + 1)
|
1228
1224
|
|
1229
1225
|
Source::Map::Collection.new(begin_l, nil,
|
1230
1226
|
loc(symbol))
|
@@ -1238,13 +1234,9 @@ module Parser
|
|
1238
1234
|
def pair_keyword_map(key_t, value_e)
|
1239
1235
|
key_range = loc(key_t)
|
1240
1236
|
|
1241
|
-
key_l =
|
1242
|
-
key_range.begin_pos,
|
1243
|
-
key_range.end_pos - 1)
|
1237
|
+
key_l = key_range.adjust(end_pos: -1)
|
1244
1238
|
|
1245
|
-
colon_l =
|
1246
|
-
key_range.end_pos - 1,
|
1247
|
-
key_range.end_pos)
|
1239
|
+
colon_l = key_range.with(begin_pos: key_range.end_pos - 1)
|
1248
1240
|
|
1249
1241
|
[ # key map
|
1250
1242
|
Source::Map::Collection.new(nil, nil,
|
@@ -1257,13 +1249,10 @@ module Parser
|
|
1257
1249
|
def pair_quoted_map(begin_t, end_t, value_e)
|
1258
1250
|
end_l = loc(end_t)
|
1259
1251
|
|
1260
|
-
quote_l =
|
1261
|
-
|
1262
|
-
end_l.end_pos - 1)
|
1252
|
+
quote_l = end_l.with(begin_pos: end_l.end_pos - 2,
|
1253
|
+
end_pos: end_l.end_pos - 1)
|
1263
1254
|
|
1264
|
-
colon_l =
|
1265
|
-
end_l.end_pos - 1,
|
1266
|
-
end_l.end_pos)
|
1255
|
+
colon_l = end_l.with(begin_pos: end_l.end_pos - 1)
|
1267
1256
|
|
1268
1257
|
[ # modified end token
|
1269
1258
|
[ value(end_t), quote_l ],
|
@@ -1351,9 +1340,7 @@ module Parser
|
|
1351
1340
|
|
1352
1341
|
def kwarg_map(name_t, value_e=nil)
|
1353
1342
|
label_range = loc(name_t)
|
1354
|
-
name_range =
|
1355
|
-
label_range.begin_pos,
|
1356
|
-
label_range.end_pos - 1)
|
1343
|
+
name_range = label_range.adjust(end_pos: -1)
|
1357
1344
|
|
1358
1345
|
if value_e
|
1359
1346
|
expr_l = loc(name_t).join(value_e.loc.expression)
|
@@ -1557,19 +1544,17 @@ module Parser
|
|
1557
1544
|
source = static_string(parts)
|
1558
1545
|
return nil if source.nil?
|
1559
1546
|
|
1560
|
-
|
1561
|
-
|
1562
|
-
|
1563
|
-
|
1564
|
-
|
1565
|
-
|
1566
|
-
|
1567
|
-
|
1568
|
-
|
1569
|
-
|
1570
|
-
|
1571
|
-
source
|
1572
|
-
end
|
1547
|
+
source = case
|
1548
|
+
when options.children.include?(:u)
|
1549
|
+
source.encode(Encoding::UTF_8)
|
1550
|
+
when options.children.include?(:e)
|
1551
|
+
source.encode(Encoding::EUC_JP)
|
1552
|
+
when options.children.include?(:s)
|
1553
|
+
source.encode(Encoding::WINDOWS_31J)
|
1554
|
+
when options.children.include?(:n)
|
1555
|
+
source.encode(Encoding::BINARY)
|
1556
|
+
else
|
1557
|
+
source
|
1573
1558
|
end
|
1574
1559
|
|
1575
1560
|
Regexp.new(source, (Regexp::EXTENDED if options.children.include?(:x)))
|
@@ -1591,16 +1576,12 @@ module Parser
|
|
1591
1576
|
token[0]
|
1592
1577
|
end
|
1593
1578
|
|
1594
|
-
|
1595
|
-
|
1596
|
-
|
1597
|
-
diagnostic(:error, :invalid_encoding, nil, token[1])
|
1598
|
-
end
|
1599
|
-
|
1600
|
-
token[0]
|
1579
|
+
def string_value(token)
|
1580
|
+
unless token[0].valid_encoding?
|
1581
|
+
diagnostic(:error, :invalid_encoding, nil, token[1])
|
1601
1582
|
end
|
1602
|
-
|
1603
|
-
|
1583
|
+
|
1584
|
+
token[0]
|
1604
1585
|
end
|
1605
1586
|
|
1606
1587
|
def loc(token)
|
@@ -0,0 +1,42 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Parser
|
4
|
+
# Context of parsing that is represented by a stack of scopes.
|
5
|
+
#
|
6
|
+
# Supported states:
|
7
|
+
# + :class - in the class body (class A; end)
|
8
|
+
# + :sclass - in the singleton class body (class << obj; end)
|
9
|
+
# + :def - in the method body (def m; end)
|
10
|
+
# + :defs - in the singleton method body (def self.m; end)
|
11
|
+
# + :block - in the block body (tap {})
|
12
|
+
# + :lambda - in the lambda body (-> {})
|
13
|
+
#
|
14
|
+
class Context
|
15
|
+
attr_reader :stack
|
16
|
+
|
17
|
+
def initialize
|
18
|
+
@stack = []
|
19
|
+
freeze
|
20
|
+
end
|
21
|
+
|
22
|
+
def push(state)
|
23
|
+
@stack << state
|
24
|
+
end
|
25
|
+
|
26
|
+
def pop
|
27
|
+
@stack.pop
|
28
|
+
end
|
29
|
+
|
30
|
+
def reset
|
31
|
+
@stack.clear
|
32
|
+
end
|
33
|
+
|
34
|
+
def in_class?
|
35
|
+
@stack.last == :class
|
36
|
+
end
|
37
|
+
|
38
|
+
def indirectly_in_def?
|
39
|
+
@stack.include?(:def) || @stack.include?(:defs)
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|