parser 3.0.1.1 → 3.1.3.0
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.
- checksums.yaml +4 -4
- data/lib/parser/all.rb +1 -0
- data/lib/parser/ast/processor.rb +3 -0
- data/lib/parser/builders/default.rb +108 -15
- data/lib/parser/context.rb +22 -41
- data/lib/parser/current.rb +19 -10
- data/lib/parser/lexer/dedenter.rb +7 -1
- data/lib/parser/lexer/explanation.rb +1 -1
- data/lib/parser/lexer.rb +12804 -11539
- data/lib/parser/macruby.rb +6371 -2888
- data/lib/parser/max_numparam_stack.rb +5 -5
- data/lib/parser/messages.rb +6 -0
- data/lib/parser/meta.rb +1 -0
- data/lib/parser/ruby18.rb +6310 -2707
- data/lib/parser/ruby19.rb +6334 -2870
- data/lib/parser/ruby20.rb +6796 -3096
- data/lib/parser/ruby21.rb +6776 -3153
- data/lib/parser/ruby22.rb +6864 -3177
- data/lib/parser/ruby23.rb +6879 -3183
- data/lib/parser/ruby24.rb +6964 -3206
- data/lib/parser/ruby25.rb +6891 -3181
- data/lib/parser/ruby26.rb +6863 -3189
- data/lib/parser/ruby27.rb +7915 -3832
- data/lib/parser/ruby30.rb +8326 -4145
- data/lib/parser/ruby31.rb +9255 -4616
- data/lib/parser/ruby32.rb +12691 -0
- data/lib/parser/rubymotion.rb +6284 -2857
- data/lib/parser/runner.rb +6 -0
- data/lib/parser/static_environment.rb +27 -0
- data/lib/parser/version.rb +1 -1
- data/parser.gemspec +1 -1
- metadata +9 -8
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 41190efffa46e773dca6e8579ecca87ded55e3156774838d0e6bea3cec40803e
|
4
|
+
data.tar.gz: e9219ad92e0da926e964d5f13a00208e772f4f3ba2af7910ac13fd9bf9dcb19b
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 786be93811a076e9736a02fccafab91eac37e4d6eab27cdafffc41743ed93e910c84cf073fde0195b7e51e47e1d6868b9673d7c91fbd792ac17428afeabcf68f
|
7
|
+
data.tar.gz: 472cc7b075befe6502a6f1f543565941cc9d1ffd3c7e5f66f2f21bfed82597cc0a0ad42b8e0f3319321fa9554fbd44a9d375b9a7f226231c7980d8782e5dd23a
|
data/lib/parser/all.rb
CHANGED
data/lib/parser/ast/processor.rb
CHANGED
@@ -148,6 +148,9 @@ module Parser
|
|
148
148
|
alias on_blockarg_expr process_regular_node
|
149
149
|
alias on_block_pass process_regular_node
|
150
150
|
|
151
|
+
alias on_forwarded_restarg process_regular_node
|
152
|
+
alias on_forwarded_kwrestarg process_regular_node
|
153
|
+
|
151
154
|
alias on_module process_regular_node
|
152
155
|
alias on_class process_regular_node
|
153
156
|
alias on_sclass process_regular_node
|
@@ -161,7 +161,7 @@ module Parser
|
|
161
161
|
#
|
162
162
|
# ```
|
163
163
|
# (send nil :foo
|
164
|
-
# (
|
164
|
+
# (kwargs
|
165
165
|
# (pair
|
166
166
|
# (sym :a)
|
167
167
|
# (int 42))
|
@@ -518,12 +518,52 @@ module Parser
|
|
518
518
|
n(:pair, [ key, value ], pair_map)
|
519
519
|
end
|
520
520
|
|
521
|
+
def pair_label(key_t)
|
522
|
+
key_l = loc(key_t)
|
523
|
+
value_l = key_l.adjust(end_pos: -1)
|
524
|
+
|
525
|
+
label = value(key_t)
|
526
|
+
value =
|
527
|
+
if label =~ /\A[[:lower:]]/
|
528
|
+
n(:ident, [ label.to_sym ], Source::Map::Variable.new(value_l))
|
529
|
+
else
|
530
|
+
n(:const, [ nil, label.to_sym ], Source::Map::Constant.new(nil, value_l, value_l))
|
531
|
+
end
|
532
|
+
pair_keyword(key_t, accessible(value))
|
533
|
+
end
|
534
|
+
|
521
535
|
def kwsplat(dstar_t, arg)
|
522
536
|
n(:kwsplat, [ arg ],
|
523
537
|
unary_op_map(dstar_t, arg))
|
524
538
|
end
|
525
539
|
|
526
540
|
def associate(begin_t, pairs, end_t)
|
541
|
+
0.upto(pairs.length - 1) do |i|
|
542
|
+
(i + 1).upto(pairs.length - 1) do |j|
|
543
|
+
key1, = *pairs[i]
|
544
|
+
key2, = *pairs[j]
|
545
|
+
|
546
|
+
do_warn = false
|
547
|
+
|
548
|
+
# keys have to be simple nodes, MRI ignores equal composite keys like
|
549
|
+
# `{ a(1) => 1, a(1) => 1 }`
|
550
|
+
case key1.type
|
551
|
+
when :sym, :str, :int, :float
|
552
|
+
if key1 == key2
|
553
|
+
do_warn = true
|
554
|
+
end
|
555
|
+
when :rational, :complex, :regexp
|
556
|
+
if @parser.version >= 31 && key1 == key2
|
557
|
+
do_warn = true
|
558
|
+
end
|
559
|
+
end
|
560
|
+
|
561
|
+
if do_warn
|
562
|
+
diagnostic :warning, :duplicate_hash_key, nil, key2.loc.expression
|
563
|
+
end
|
564
|
+
end
|
565
|
+
end
|
566
|
+
|
527
567
|
n(:hash, [ *pairs ],
|
528
568
|
collection_map(begin_t, pairs, end_t))
|
529
569
|
end
|
@@ -608,19 +648,29 @@ module Parser
|
|
608
648
|
when :ident
|
609
649
|
name, = *node
|
610
650
|
|
611
|
-
if
|
612
|
-
|
613
|
-
|
614
|
-
|
615
|
-
end
|
651
|
+
if %w[? !].any? { |c| name.to_s.end_with?(c) }
|
652
|
+
diagnostic :error, :invalid_id_to_get,
|
653
|
+
{ :identifier => name.to_s }, node.loc.expression
|
654
|
+
end
|
616
655
|
|
617
|
-
|
618
|
-
|
619
|
-
|
620
|
-
|
656
|
+
# Numbered parameters are not declared anywhere,
|
657
|
+
# so they take precedence over method calls in numblock contexts
|
658
|
+
if @parser.version >= 27 && @parser.try_declare_numparam(node)
|
659
|
+
return node.updated(:lvar)
|
660
|
+
end
|
661
|
+
|
662
|
+
unless @parser.static_env.declared?(name)
|
663
|
+
return n(:send, [ nil, name ],
|
621
664
|
var_send_map(node))
|
622
665
|
end
|
623
666
|
|
667
|
+
if name.to_s == parser.current_arg_stack.top
|
668
|
+
diagnostic :error, :circular_argument_reference,
|
669
|
+
{ :var_name => name.to_s }, node.loc.expression
|
670
|
+
end
|
671
|
+
|
672
|
+
node.updated(:lvar)
|
673
|
+
|
624
674
|
else
|
625
675
|
node
|
626
676
|
end
|
@@ -664,7 +714,7 @@ module Parser
|
|
664
714
|
node.updated(:gvasgn)
|
665
715
|
|
666
716
|
when :const
|
667
|
-
|
717
|
+
if @parser.context.in_def
|
668
718
|
diagnostic :error, :dynamic_const, nil, node.loc.expression
|
669
719
|
end
|
670
720
|
|
@@ -683,6 +733,17 @@ module Parser
|
|
683
733
|
|
684
734
|
node.updated(:lvasgn)
|
685
735
|
|
736
|
+
when :match_var
|
737
|
+
name, = *node
|
738
|
+
|
739
|
+
var_name = node.children[0].to_s
|
740
|
+
name_loc = node.loc.expression
|
741
|
+
|
742
|
+
check_assignment_to_numparam(var_name, name_loc)
|
743
|
+
check_reserved_for_numparam(var_name, name_loc)
|
744
|
+
|
745
|
+
node
|
746
|
+
|
686
747
|
when :nil, :self, :true, :false,
|
687
748
|
:__FILE__, :__LINE__, :__ENCODING__
|
688
749
|
diagnostic :error, :invalid_assignment, nil, node.loc.expression
|
@@ -818,8 +879,14 @@ module Parser
|
|
818
879
|
|
819
880
|
def args(begin_t, args, end_t, check_args=true)
|
820
881
|
args = check_duplicate_args(args) if check_args
|
821
|
-
|
822
|
-
|
882
|
+
validate_no_forward_arg_after_restarg(args)
|
883
|
+
|
884
|
+
map = collection_map(begin_t, args, end_t)
|
885
|
+
if !self.class.emit_forward_arg && args.length == 1 && args[0].type == :forward_arg
|
886
|
+
n(:forward_args, [], map)
|
887
|
+
else
|
888
|
+
n(:args, args, map)
|
889
|
+
end
|
823
890
|
end
|
824
891
|
|
825
892
|
def numargs(max_numparam)
|
@@ -906,9 +973,12 @@ module Parser
|
|
906
973
|
end
|
907
974
|
|
908
975
|
def blockarg(amper_t, name_t)
|
909
|
-
|
976
|
+
if !name_t.nil?
|
977
|
+
check_reserved_for_numparam(value(name_t), loc(name_t))
|
978
|
+
end
|
910
979
|
|
911
|
-
|
980
|
+
arg_name = name_t ? value(name_t).to_sym : nil
|
981
|
+
n(:blockarg, [ arg_name ],
|
912
982
|
arg_prefix_map(amper_t, name_t))
|
913
983
|
end
|
914
984
|
|
@@ -1008,6 +1078,14 @@ module Parser
|
|
1008
1078
|
n(:forwarded_args, [], token_map(dots_t))
|
1009
1079
|
end
|
1010
1080
|
|
1081
|
+
def forwarded_restarg(star_t)
|
1082
|
+
n(:forwarded_restarg, [], token_map(star_t))
|
1083
|
+
end
|
1084
|
+
|
1085
|
+
def forwarded_kwrestarg(dstar_t)
|
1086
|
+
n(:forwarded_kwrestarg, [], token_map(dstar_t))
|
1087
|
+
end
|
1088
|
+
|
1011
1089
|
def call_method(receiver, dot_t, selector_t,
|
1012
1090
|
lparen_t=nil, args=[], rparen_t=nil)
|
1013
1091
|
type = call_type_for_dot(dot_t)
|
@@ -1683,6 +1761,21 @@ module Parser
|
|
1683
1761
|
end
|
1684
1762
|
end
|
1685
1763
|
|
1764
|
+
def validate_no_forward_arg_after_restarg(args)
|
1765
|
+
restarg = nil
|
1766
|
+
forward_arg = nil
|
1767
|
+
args.each do |arg|
|
1768
|
+
case arg.type
|
1769
|
+
when :restarg then restarg = arg
|
1770
|
+
when :forward_arg then forward_arg = arg
|
1771
|
+
end
|
1772
|
+
end
|
1773
|
+
|
1774
|
+
if !forward_arg.nil? && !restarg.nil?
|
1775
|
+
diagnostic :error, :forward_arg_after_restarg, nil, forward_arg.loc.expression, [restarg.loc.expression]
|
1776
|
+
end
|
1777
|
+
end
|
1778
|
+
|
1686
1779
|
def check_assignment_to_numparam(name, loc)
|
1687
1780
|
# MRI < 2.7 treats numbered parameters as regular variables
|
1688
1781
|
# and so it's allowed to perform assignments like `_1 = 42`.
|
data/lib/parser/context.rb
CHANGED
@@ -9,60 +9,41 @@ module Parser
|
|
9
9
|
# + :sclass - in the singleton class body (class << obj; end)
|
10
10
|
# + :def - in the method body (def m; end)
|
11
11
|
# + :defs - in the singleton method body (def self.m; end)
|
12
|
+
# + :def_open_args - in the arglist of the method definition
|
13
|
+
# keep in mind that it's set **only** after reducing the first argument,
|
14
|
+
# if you need to handle the first argument check `lex_state == expr_fname`
|
12
15
|
# + :block - in the block body (tap {})
|
13
16
|
# + :lambda - in the lambda body (-> {})
|
14
17
|
#
|
15
18
|
class Context
|
16
|
-
|
19
|
+
FLAGS = %i[
|
20
|
+
in_defined
|
21
|
+
in_kwarg
|
22
|
+
in_argdef
|
23
|
+
in_def
|
24
|
+
in_class
|
25
|
+
in_block
|
26
|
+
in_lambda
|
27
|
+
]
|
17
28
|
|
18
29
|
def initialize
|
19
|
-
|
20
|
-
freeze
|
21
|
-
end
|
22
|
-
|
23
|
-
def push(state)
|
24
|
-
@stack << state
|
25
|
-
end
|
26
|
-
|
27
|
-
def pop
|
28
|
-
@stack.pop
|
30
|
+
reset
|
29
31
|
end
|
30
32
|
|
31
33
|
def reset
|
32
|
-
@
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
@
|
37
|
-
|
38
|
-
|
39
|
-
def in_class?
|
40
|
-
@stack.last == :class
|
34
|
+
@in_defined = false
|
35
|
+
@in_kwarg = false
|
36
|
+
@in_argdef = false
|
37
|
+
@in_def = false
|
38
|
+
@in_class = false
|
39
|
+
@in_block = false
|
40
|
+
@in_lambda = false
|
41
41
|
end
|
42
42
|
|
43
|
-
|
44
|
-
@stack.include?(:def) || @stack.include?(:defs)
|
45
|
-
end
|
46
|
-
|
47
|
-
def class_definition_allowed?
|
48
|
-
def_index = stack.rindex { |item| [:def, :defs].include?(item) }
|
49
|
-
sclass_index = stack.rindex(:sclass)
|
50
|
-
|
51
|
-
def_index.nil? || (!sclass_index.nil? && sclass_index > def_index)
|
52
|
-
end
|
53
|
-
alias module_definition_allowed? class_definition_allowed?
|
54
|
-
alias dynamic_const_definition_allowed? class_definition_allowed?
|
55
|
-
|
56
|
-
def in_block?
|
57
|
-
@stack.last == :block
|
58
|
-
end
|
59
|
-
|
60
|
-
def in_lambda?
|
61
|
-
@stack.last == :lambda
|
62
|
-
end
|
43
|
+
attr_accessor(*FLAGS)
|
63
44
|
|
64
45
|
def in_dynamic_block?
|
65
|
-
in_block
|
46
|
+
in_block || in_lambda
|
66
47
|
end
|
67
48
|
end
|
68
49
|
end
|
data/lib/parser/current.rb
CHANGED
@@ -3,9 +3,9 @@
|
|
3
3
|
module Parser
|
4
4
|
class << self
|
5
5
|
def warn_syntax_deviation(feature, version)
|
6
|
-
warn "warning: parser/current is loading #{feature}, which recognizes"
|
7
|
-
|
8
|
-
|
6
|
+
warn "warning: parser/current is loading #{feature}, which recognizes" \
|
7
|
+
"#{version}-compliant syntax, but you are running #{RUBY_VERSION}.\n" \
|
8
|
+
"Please see https://github.com/whitequark/parser#compatibility-with-ruby-mri."
|
9
9
|
end
|
10
10
|
private :warn_syntax_deviation
|
11
11
|
end
|
@@ -66,7 +66,7 @@ module Parser
|
|
66
66
|
CurrentRuby = Ruby25
|
67
67
|
|
68
68
|
when /^2\.6\./
|
69
|
-
current_version = '2.6.
|
69
|
+
current_version = '2.6.10'
|
70
70
|
if RUBY_VERSION != current_version
|
71
71
|
warn_syntax_deviation 'parser/ruby26', current_version
|
72
72
|
end
|
@@ -75,7 +75,7 @@ module Parser
|
|
75
75
|
CurrentRuby = Ruby26
|
76
76
|
|
77
77
|
when /^2\.7\./
|
78
|
-
current_version = '2.7.
|
78
|
+
current_version = '2.7.7'
|
79
79
|
if RUBY_VERSION != current_version
|
80
80
|
warn_syntax_deviation 'parser/ruby27', current_version
|
81
81
|
end
|
@@ -84,7 +84,7 @@ module Parser
|
|
84
84
|
CurrentRuby = Ruby27
|
85
85
|
|
86
86
|
when /^3\.0\./
|
87
|
-
current_version = '3.0.
|
87
|
+
current_version = '3.0.5'
|
88
88
|
if RUBY_VERSION != current_version
|
89
89
|
warn_syntax_deviation 'parser/ruby30', current_version
|
90
90
|
end
|
@@ -93,7 +93,7 @@ module Parser
|
|
93
93
|
CurrentRuby = Ruby30
|
94
94
|
|
95
95
|
when /^3\.1\./
|
96
|
-
current_version = '3.1.
|
96
|
+
current_version = '3.1.3'
|
97
97
|
if RUBY_VERSION != current_version
|
98
98
|
warn_syntax_deviation 'parser/ruby31', current_version
|
99
99
|
end
|
@@ -101,10 +101,19 @@ module Parser
|
|
101
101
|
require 'parser/ruby31'
|
102
102
|
CurrentRuby = Ruby31
|
103
103
|
|
104
|
+
when /^3\.2\./
|
105
|
+
current_version = '3.2.0-dev'
|
106
|
+
if RUBY_VERSION != current_version
|
107
|
+
warn_syntax_deviation 'parser/ruby32', current_version
|
108
|
+
end
|
109
|
+
|
110
|
+
require 'parser/ruby32'
|
111
|
+
CurrentRuby = Ruby32
|
112
|
+
|
104
113
|
else # :nocov:
|
105
114
|
# Keep this in sync with released Ruby.
|
106
|
-
warn_syntax_deviation 'parser/
|
107
|
-
require 'parser/
|
108
|
-
CurrentRuby =
|
115
|
+
warn_syntax_deviation 'parser/ruby31', '3.1.x'
|
116
|
+
require 'parser/ruby31'
|
117
|
+
CurrentRuby = Ruby31
|
109
118
|
end
|
110
119
|
end
|
@@ -38,7 +38,13 @@ module Parser
|
|
38
38
|
# Prevent the following error when processing binary encoded source.
|
39
39
|
# "\xC0".split # => ArgumentError (invalid byte sequence in UTF-8)
|
40
40
|
lines = string.force_encoding(Encoding::BINARY).split("\\\n")
|
41
|
-
lines.
|
41
|
+
if lines.length == 1
|
42
|
+
# If the line continuation sequence was found but there is no second
|
43
|
+
# line, it was not really a line continuation and must be ignored.
|
44
|
+
lines = [string.force_encoding(original_encoding)]
|
45
|
+
else
|
46
|
+
lines.map! {|s| s.force_encoding(original_encoding) }
|
47
|
+
end
|
42
48
|
|
43
49
|
if @at_line_begin
|
44
50
|
lines_to_dedent = lines
|