parser 2.5.1.0 → 2.5.1.2

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.
data/lib/parser/ruby26.y CHANGED
@@ -665,6 +665,14 @@ rule
665
665
  {
666
666
  result = @builder.range_exclusive(val[0], val[1], val[2])
667
667
  }
668
+ | arg tDOT2
669
+ {
670
+ result = @builder.range_inclusive(val[0], val[1], nil)
671
+ }
672
+ | arg tDOT3
673
+ {
674
+ result = @builder.range_exclusive(val[0], val[1], nil)
675
+ }
668
676
  | arg tPLUS arg
669
677
  {
670
678
  result = @builder.binary_op(val[0], val[1], val[2])
@@ -885,7 +893,20 @@ rule
885
893
  }
886
894
  call_args
887
895
  {
888
- @lexer.cmdarg.pop
896
+ # call_args can be followed by tLBRACE_ARG (that does cmdarg.push(0) in the lexer)
897
+ # but the push must be done after cmdarg.pop() in the parser.
898
+ # So this code does cmdarg.pop() to pop 0 pushed by tLBRACE_ARG,
899
+ # cmdarg.pop() to pop 1 pushed by command_args,
900
+ # and cmdarg.push(0) to restore back the flag set by tLBRACE_ARG.
901
+ last_token = @last_token[0]
902
+ lookahead = last_token == :tLBRACE_ARG
903
+ if lookahead
904
+ top = @lexer.cmdarg.pop
905
+ @lexer.cmdarg.pop
906
+ @lexer.cmdarg.push(top)
907
+ else
908
+ @lexer.cmdarg.pop
909
+ end
889
910
 
890
911
  result = val[1]
891
912
  }
@@ -46,7 +46,7 @@ module Parser
46
46
  # magic encoding comment or UTF-8 BOM. `string` can be in any encoding.
47
47
  #
48
48
  # @param [String] string
49
- # @return [String|nil] encoding name, if recognized
49
+ # @return [String, nil] encoding name, if recognized
50
50
  #
51
51
  def self.recognize_encoding(string)
52
52
  return if string.empty?
@@ -47,7 +47,7 @@ module Parser
47
47
 
48
48
  ##
49
49
  # @param [Parser::AST::Node] ast
50
- # @param [Array(Parser::Source::Comment)] comments
50
+ # @param [Array<Parser::Source::Comment>] comments
51
51
  def initialize(ast, comments)
52
52
  @ast = ast
53
53
  @comments = comments
@@ -85,7 +85,7 @@ module Parser
85
85
  # Note that {associate} produces unexpected result for nodes which are
86
86
  # equal but have distinct locations; comments for these nodes are merged.
87
87
  #
88
- # @return [Hash(Parser::AST::Node, Array(Parser::Source::Comment))]
88
+ # @return [Hash<Parser::AST::Node, Array<Parser::Source::Comment>>]
89
89
  # @deprecated Use {associate_locations}.
90
90
  #
91
91
  def associate
@@ -98,7 +98,7 @@ module Parser
98
98
  # the hash key, thus producing an unambiguous result even in presence
99
99
  # of equal nodes.
100
100
  #
101
- # @return [Hash(Parser::Source::Map, Array(Parser::Source::Comment))]
101
+ # @return [Hash<Parser::Source::Map, Array<Parser::Source::Comment>>]
102
102
  #
103
103
  def associate_locations
104
104
  @map_using_locations = true
@@ -24,8 +24,8 @@ module Parser
24
24
  # Associate `comments` with `ast` nodes by their corresponding node.
25
25
  #
26
26
  # @param [Parser::AST::Node] ast
27
- # @param [Array(Comment)] comments
28
- # @return [Hash(Parser::AST::Node, Array(Comment))]
27
+ # @param [Array<Comment>] comments
28
+ # @return [Hash<Parser::AST::Node, Array<Comment>>]
29
29
  # @see Parser::Source::Comment::Associator#associate
30
30
  # @deprecated Use {associate_locations}.
31
31
  #
@@ -39,8 +39,8 @@ module Parser
39
39
  # source.
40
40
  #
41
41
  # @param [Parser::AST::Node] ast
42
- # @param [Array(Comment)] comments
43
- # @return [Hash(Parser::Source::Map, Array(Comment))]
42
+ # @param [Array<Comment>] comments
43
+ # @return [Hash<Parser::Source::Map, Array<Comment>>]
44
44
  # @see Parser::Source::Comment::Associator#associate_locations
45
45
  #
46
46
  def self.associate_locations(ast, comments)
@@ -161,7 +161,7 @@ module Parser
161
161
  # # :expression => #<Source::Range (string) 0...6>
162
162
  # # }
163
163
  #
164
- # @return [Hash(Symbol, Parser::Source::Range)]
164
+ # @return [Hash<Symbol, Parser::Source::Range>]
165
165
  #
166
166
  def to_hash
167
167
  instance_variables.inject({}) do |hash, ivar|
@@ -143,7 +143,7 @@ module Parser
143
143
  end
144
144
 
145
145
  ##
146
- # @return [Array(Integer)] a set of character indexes contained in this range.
146
+ # @return [Array<Integer>] a set of character indexes contained in this range.
147
147
  #
148
148
  def to_a
149
149
  (@begin_pos...@end_pos).to_a
@@ -133,8 +133,8 @@ module Parser
133
133
  # Inserts the given strings before and after the given range.
134
134
  #
135
135
  # @param [Range] range
136
- # @param [String or nil] insert_before
137
- # @param [String or nil] insert_after
136
+ # @param [String, nil] insert_before
137
+ # @param [String, nil] insert_after
138
138
  # @return [Rewriter] self
139
139
  # @raise [ClobberingError] when clobbering is detected
140
140
  #
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Parser
4
- VERSION = '2.5.1.0'
4
+ VERSION = '2.5.1.2'
5
5
  end
data/test/parse_helper.rb CHANGED
@@ -124,7 +124,7 @@ module ParseHelper
124
124
  assert_source_range(begin_pos, end_pos, range, version, line.inspect)
125
125
  end
126
126
 
127
- assert_equal parser.instance_eval { @lexer }.cmdarg.instance_eval { @stack }, 0,
127
+ assert parser.instance_eval { @lexer }.cmdarg.empty?,
128
128
  "(#{version}) expected cmdarg to be empty after parsing"
129
129
  end
130
130
 
data/test/test_parser.rb CHANGED
@@ -833,6 +833,24 @@ class TestParser < Minitest::Test
833
833
  |~~~~~ expression})
834
834
  end
835
835
 
836
+ def test_range_endless
837
+ assert_parses(
838
+ s(:irange,
839
+ s(:int, 1), nil),
840
+ %q{1..},
841
+ %q{~~~ expression
842
+ | ~~ operator},
843
+ SINCE_2_6)
844
+
845
+ assert_parses(
846
+ s(:erange,
847
+ s(:int, 1), nil),
848
+ %q{1...},
849
+ %q{~~~~ expression
850
+ | ~~~ operator},
851
+ SINCE_2_6)
852
+ end
853
+
836
854
  #
837
855
  # Access
838
856
  #
@@ -6658,7 +6676,7 @@ class TestParser < Minitest::Test
6658
6676
  [:error, :unexpected_token, { :token => 'kRESCUE'}],
6659
6677
  %q{-> do rescue; end},
6660
6678
  %q{ ~~~~~~ location},
6661
- SINCE_1_9 - SINCE_2_5)
6679
+ SINCE_1_9 - SINCE_2_6)
6662
6680
 
6663
6681
  assert_parses(
6664
6682
  s(:block,
@@ -6668,7 +6686,7 @@ class TestParser < Minitest::Test
6668
6686
  s(:resbody, nil, nil, nil), nil)),
6669
6687
  %q{-> do rescue; end},
6670
6688
  %q{ ~~~~~~ keyword (rescue.resbody)},
6671
- SINCE_2_5)
6689
+ SINCE_2_6)
6672
6690
 
6673
6691
  assert_diagnoses(
6674
6692
  [:error, :unexpected_token, { :token => 'kRESCUE'}],
@@ -6965,4 +6983,56 @@ class TestParser < Minitest::Test
6965
6983
  %q{ ^ location},
6966
6984
  SINCE_2_2)
6967
6985
  end
6986
+
6987
+ def test_lbrace_arg_after_command_args
6988
+ assert_parses(
6989
+ s(:block,
6990
+ s(:send, nil, :let,
6991
+ s(:begin,
6992
+ s(:sym, :a))),
6993
+ s(:args),
6994
+ s(:block,
6995
+ s(:send, nil, :m),
6996
+ s(:args), nil)),
6997
+ %q{let (:a) { m do; end }},
6998
+ %q{},
6999
+ ALL_VERSIONS)
7000
+ end
7001
+
7002
+ def test_ruby_bug_14690
7003
+ assert_parses(
7004
+ s(:block,
7005
+ s(:send, nil, :let,
7006
+ s(:begin)),
7007
+ s(:args),
7008
+ s(:block,
7009
+ s(:send, nil, :m,
7010
+ s(:send, nil, :a)),
7011
+ s(:args), nil)),
7012
+ %q{let () { m(a) do; end }},
7013
+ %q{},
7014
+ SINCE_2_0)
7015
+ end
7016
+
7017
+ def test_parser_bug_507
7018
+ assert_parses(
7019
+ s(:lvasgn, :m,
7020
+ s(:block,
7021
+ s(:lambda),
7022
+ s(:args,
7023
+ s(:restarg, :args)), nil)),
7024
+ %q{m = -> *args do end},
7025
+ %q{},
7026
+ SINCE_1_9)
7027
+ end
7028
+
7029
+ def test_parser_bug_518
7030
+ assert_parses(
7031
+ s(:class,
7032
+ s(:const, nil, :A),
7033
+ s(:const, nil, :B), nil),
7034
+ "class A < B\nend",
7035
+ %q{},
7036
+ ALL_VERSIONS)
7037
+ end
6968
7038
  end
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: 2.5.1.0
4
+ version: 2.5.1.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - whitequark
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2018-04-12 00:00:00.000000000 Z
11
+ date: 2018-07-10 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: ast