parser 2.3.0.pre.5 → 2.3.0.pre.6

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 8603dec71087cb78e504f3ed0175962f075dde01
4
- data.tar.gz: 518d432e89bce2f3a03f9cbabc1e5917040e2c2c
3
+ metadata.gz: 76b617323cf8143b8935312b8ce39e4c2d847b63
4
+ data.tar.gz: 13f93cde47689ad2352602d2aac0555b674f860d
5
5
  SHA512:
6
- metadata.gz: 10f802d02d6a4e4a80deb6e427fc68d123e86b51e00bdda09e06cbb30e4c33c795b11de47e58e5e370e0117bceca458c9660e416c0489e4601e680bf1c296f2b
7
- data.tar.gz: 94dbc707d086703b9060687dceb6c7d806ad01c17619e4be7fd379bdbfb4dbe56212ac289443c513a4ba0c097f469390284e93dbd7708faf7b75dca4daa45158
6
+ metadata.gz: ddac7c4fdf0503ff15acbb45eedb8bdd9713ed38ceefd5f306044b68e8ce6c016919a689e543ad7b9648c0dcfee43870164194ed8f02fcfd90b9e383219ad9bf
7
+ data.tar.gz: 7831e67d2cb5ad9e65e1230a86c5117804e17e088e78f01c28632917c1cf0b3cce3abfb46ab889007acf7232f315989467d756a3a89d4b335d71022b53899c2a
data/CHANGELOG.md CHANGED
@@ -1,6 +1,21 @@
1
1
  Changelog
2
2
  =========
3
3
 
4
+ v2.3.0.pre.6 (2015-12-20)
5
+ -------------------------
6
+
7
+ API modifications:
8
+ * parser/current: update 2.2 warning to 2.2.4. (whitequark)
9
+ * ruby{22,23}.y: "1 ? p do end : 0". (whitequark)
10
+ * lexer.rl: "{%'a':1}": %-string cannot be a label. (whitequark)
11
+ * parser/current: update 2.1 warning to 2.1.8. (whitequark)
12
+
13
+ Features implemented:
14
+ * ruby-parse: add --emit-ruby option. (whitequark)
15
+
16
+ Bugs fixed:
17
+ * lexer.rl: "f(a ? 'a':1)": disallow quoted label at expr_value. (whitequark)
18
+
4
19
  v2.3.0.pre.5 (2015-12-16)
5
20
  -------------------------
6
21
 
@@ -34,16 +34,16 @@ module Parser
34
34
  CurrentRuby = Ruby20
35
35
 
36
36
  when /^2\.1\./
37
- if RUBY_VERSION != '2.1.7'
38
- warn_syntax_deviation 'parser/ruby21', '2.1.7'
37
+ if RUBY_VERSION != '2.1.8'
38
+ warn_syntax_deviation 'parser/ruby21', '2.1.8'
39
39
  end
40
40
 
41
41
  require 'parser/ruby21'
42
42
  CurrentRuby = Ruby21
43
43
 
44
44
  when /^2\.2\./
45
- if RUBY_VERSION != '2.2.3'
46
- warn_syntax_deviation 'parser/ruby22', '2.2.3'
45
+ if RUBY_VERSION != '2.2.4'
46
+ warn_syntax_deviation 'parser/ruby22', '2.2.4'
47
47
  end
48
48
 
49
49
  require 'parser/ruby22'
data/lib/parser/lexer.rl CHANGED
@@ -854,7 +854,8 @@ class Parser::Lexer
854
854
  end
855
855
 
856
856
  current_literal = literal
857
- if !current_literal.heredoc? && (token = current_literal.nest_and_try_closing(string, @ts, @te, lookahead))
857
+ if !current_literal.heredoc? &&
858
+ (token = current_literal.nest_and_try_closing(string, @ts, @te, lookahead))
858
859
  if token[0] == :tLABEL_END
859
860
  p += 1
860
861
  pop_literal
@@ -1886,7 +1887,7 @@ class Parser::Lexer
1886
1887
  c_eof => do_eof;
1887
1888
  *|;
1888
1889
 
1889
- # Like expr_beg, but no 1.9 label possible.
1890
+ # Like expr_beg, but no 1.9 label or 2.2 quoted label possible.
1890
1891
  #
1891
1892
  expr_value := |*
1892
1893
  # a:b: a(:b), a::B, A::B
@@ -1894,6 +1895,12 @@ class Parser::Lexer
1894
1895
  => { p = @ts - 1
1895
1896
  fgoto expr_end; };
1896
1897
 
1898
+ # "bar", 'baz'
1899
+ ['"] # '
1900
+ => {
1901
+ fgoto *push_literal(tok, tok, @ts, nil, false, false);
1902
+ };
1903
+
1897
1904
  w_space_comment;
1898
1905
 
1899
1906
  w_newline
@@ -2087,7 +2094,7 @@ class Parser::Lexer
2087
2094
  '`' | ['"] # '
2088
2095
  => {
2089
2096
  type, delimiter = tok, tok[-1].chr
2090
- fgoto *push_literal(type, delimiter, @ts);
2097
+ fgoto *push_literal(type, delimiter, @ts, nil, false, true);
2091
2098
  };
2092
2099
 
2093
2100
  #
@@ -37,7 +37,8 @@ module Parser
37
37
  attr_reader :heredoc_e, :str_s
38
38
  attr_accessor :saved_herebody_s
39
39
 
40
- def initialize(lexer, str_type, delimiter, str_s, heredoc_e = nil, indent = false)
40
+ def initialize(lexer, str_type, delimiter, str_s, heredoc_e = nil,
41
+ indent = false, label_allowed = false)
41
42
  @lexer = lexer
42
43
  @nesting = 1
43
44
 
@@ -60,8 +61,9 @@ module Parser
60
61
  @start_delim = DELIMITERS.include?(delimiter) ? delimiter : nil
61
62
  @end_delim = DELIMITERS.fetch(delimiter, delimiter)
62
63
 
63
- @heredoc_e = heredoc_e
64
- @indent = indent
64
+ @heredoc_e = heredoc_e
65
+ @indent = indent
66
+ @label_allowed = label_allowed
65
67
 
66
68
  @interp_braces = 0
67
69
 
@@ -130,7 +132,7 @@ module Parser
130
132
  end
131
133
 
132
134
  if lookahead && lookahead[0] == ?: && lookahead[1] != ?: &&
133
- %w(' ").include?(delimiter) && @start_tok == :tSTRING_BEG
135
+ @label_allowed && @start_tok == :tSTRING_BEG
134
136
  # This is a quoted label.
135
137
  flush_string
136
138
  emit(:tLABEL_END, @end_delim, ts, te + 1)
data/lib/parser/ruby22.y CHANGED
@@ -784,25 +784,10 @@ rule
784
784
  {
785
785
  result = @builder.keyword_cmd(:defined?, val[0], nil, [ val[2] ], nil)
786
786
  }
787
-
788
- # Note: MRI eventually came to rely on disambiguation based on
789
- # the lexer state, but it is too contrived with the Ragel lexer,
790
- # so we kept this approach. See ruby/ruby@b0c03f63e5 for
791
- # the initial commit, and ruby/ruby@23352f62a for MRI revert,
792
- # which we decided not to track.
793
- | arg tEH
794
- {
795
- @lexer.push_cond
796
- @lexer.cond.push(true)
797
- }
798
- arg opt_nl tCOLON
799
- {
800
- @lexer.pop_cond
801
- }
802
- arg
787
+ | arg tEH arg opt_nl tCOLON arg
803
788
  {
804
789
  result = @builder.ternary(val[0], val[1],
805
- val[3], val[5], val[7])
790
+ val[2], val[4], val[5])
806
791
  }
807
792
  | primary
808
793
 
data/lib/parser/ruby23.y CHANGED
@@ -784,25 +784,10 @@ rule
784
784
  {
785
785
  result = @builder.keyword_cmd(:defined?, val[0], nil, [ val[2] ], nil)
786
786
  }
787
-
788
- # Note: MRI eventually came to rely on disambiguation based on
789
- # the lexer state, but it is too contrived with the Ragel lexer,
790
- # so we kept this approach. See ruby/ruby@b0c03f63e5 for
791
- # the initial commit, and ruby/ruby@23352f62a for MRI revert,
792
- # which we decided not to track.
793
- | arg tEH
794
- {
795
- @lexer.push_cond
796
- @lexer.cond.push(true)
797
- }
798
- arg opt_nl tCOLON
799
- {
800
- @lexer.pop_cond
801
- }
802
- arg
787
+ | arg tEH arg opt_nl tCOLON arg
803
788
  {
804
789
  result = @builder.ternary(val[0], val[1],
805
- val[3], val[5], val[7])
790
+ val[2], val[4], val[5])
806
791
  }
807
792
  | primary
808
793
 
@@ -93,6 +93,7 @@ module Parser
93
93
  super
94
94
 
95
95
  @locate = false
96
+ @emit_ruby = false
96
97
  end
97
98
 
98
99
  private
@@ -113,6 +114,10 @@ module Parser
113
114
 
114
115
  Lexer.send :include, Lexer::Explanation
115
116
  end
117
+
118
+ opts.on '--emit-ruby', 'Emit S-expressions as valid Ruby code' do
119
+ @emit_ruby = true
120
+ end
116
121
  end
117
122
 
118
123
  def process_all_input
@@ -129,7 +134,11 @@ module Parser
129
134
  if @locate
130
135
  LocationProcessor.new.process(ast)
131
136
  elsif !@benchmark
132
- p ast
137
+ if @emit_ruby
138
+ puts ast.inspect
139
+ else
140
+ puts ast.to_s
141
+ end
133
142
  end
134
143
  end
135
144
  end
@@ -1,3 +1,3 @@
1
1
  module Parser
2
- VERSION = '2.3.0.pre.5'
2
+ VERSION = '2.3.0.pre.6'
3
3
  end
data/parser.gemspec CHANGED
@@ -28,7 +28,7 @@ Gem::Specification.new do |spec|
28
28
  spec.test_files = spec.files.grep(%r{^test/})
29
29
  spec.require_paths = ['lib']
30
30
 
31
- spec.add_dependency 'ast', ['>= 1.1', '< 3.0']
31
+ spec.add_dependency 'ast', '~> 2.2'
32
32
 
33
33
  spec.add_development_dependency 'bundler', '~> 1.2'
34
34
  spec.add_development_dependency 'rake', '~> 10.0'
data/test/test_lexer.rb CHANGED
@@ -308,6 +308,17 @@ class TestLexer < Minitest::Test
308
308
  :tCOLON2, '::')
309
309
  end
310
310
 
311
+ def test_pct_string_colon__22
312
+ setup_lexer 22
313
+
314
+ assert_scanned("{%'a':",
315
+ :tLBRACE, '{',
316
+ :tSTRING_BEG, "%'",
317
+ :tSTRING_CONTENT, 'a',
318
+ :tSTRING_END, "'",
319
+ :tCOLON, ':')
320
+ end
321
+
311
322
  def test_command_start__19
312
323
  setup_lexer 19
313
324
 
data/test/test_parser.rb CHANGED
@@ -5052,6 +5052,49 @@ class TestParser < Minitest::Test
5052
5052
  ALL_VERSIONS - %w(1.8 1.9 mac ios 2.0))
5053
5053
  end
5054
5054
 
5055
+ def test_ruby_bug_10653
5056
+ assert_parses(
5057
+ s(:if,
5058
+ s(:true),
5059
+ s(:block,
5060
+ s(:send,
5061
+ s(:int, 1), :tap),
5062
+ s(:args,
5063
+ s(:arg, :n)),
5064
+ s(:send, nil, :p,
5065
+ s(:lvar, :n))),
5066
+ s(:int, 0)),
5067
+ %q{true ? 1.tap do |n| p n end : 0},
5068
+ %q{},
5069
+ ALL_VERSIONS)
5070
+
5071
+ assert_parses(
5072
+ s(:if,
5073
+ s(:false),
5074
+ s(:block,
5075
+ s(:send, nil, :raise),
5076
+ s(:args), nil),
5077
+ s(:block,
5078
+ s(:send, nil, :tap),
5079
+ s(:args), nil)),
5080
+ %q{false ? raise {} : tap {}},
5081
+ %q{},
5082
+ ALL_VERSIONS)
5083
+
5084
+ assert_parses(
5085
+ s(:if,
5086
+ s(:false),
5087
+ s(:block,
5088
+ s(:send, nil, :raise),
5089
+ s(:args), nil),
5090
+ s(:block,
5091
+ s(:send, nil, :tap),
5092
+ s(:args), nil)),
5093
+ %q{false ? raise do end : tap do end},
5094
+ %q{},
5095
+ ALL_VERSIONS)
5096
+ end
5097
+
5055
5098
  def test_ruby_bug_11107
5056
5099
  assert_parses(
5057
5100
  s(:send, nil, :p,
metadata CHANGED
@@ -1,35 +1,29 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: parser
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.3.0.pre.5
4
+ version: 2.3.0.pre.6
5
5
  platform: ruby
6
6
  authors:
7
7
  - whitequark
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-12-16 00:00:00.000000000 Z
11
+ date: 2015-12-20 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: ast
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
- - - ">="
18
- - !ruby/object:Gem::Version
19
- version: '1.1'
20
- - - "<"
17
+ - - "~>"
21
18
  - !ruby/object:Gem::Version
22
- version: '3.0'
19
+ version: '2.2'
23
20
  type: :runtime
24
21
  prerelease: false
25
22
  version_requirements: !ruby/object:Gem::Requirement
26
23
  requirements:
27
- - - ">="
28
- - !ruby/object:Gem::Version
29
- version: '1.1'
30
- - - "<"
24
+ - - "~>"
31
25
  - !ruby/object:Gem::Version
32
- version: '3.0'
26
+ version: '2.2'
33
27
  - !ruby/object:Gem::Dependency
34
28
  name: bundler
35
29
  requirement: !ruby/object:Gem::Requirement