parser 0.9.1 → 0.9.2

Sign up to get free protection for your applications and to get access to all the features.
data/parser.gemspec CHANGED
@@ -2,7 +2,7 @@
2
2
 
3
3
  Gem::Specification.new do |spec|
4
4
  spec.name = 'parser'
5
- spec.version = '0.9.1'
5
+ spec.version = '0.9.2'
6
6
  spec.authors = ['Peter Zotov']
7
7
  spec.email = ['whitequark@whitequark.org']
8
8
  spec.description = %q{A Ruby parser written in pure Ruby.}
@@ -14,6 +14,7 @@ Gem::Specification.new do |spec|
14
14
  lib/parser/lexer.rb
15
15
  lib/parser/ruby18.rb
16
16
  lib/parser/ruby19.rb
17
+ lib/parser/ruby20.rb
17
18
  )
18
19
  spec.executables = %w()
19
20
  spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
data/test/helper.rb CHANGED
@@ -7,7 +7,7 @@ if SimpleCov.usable?
7
7
  if defined?(TracePoint)
8
8
  require_relative 'racc_coverage_helper'
9
9
 
10
- RaccCoverage.start(%w(ruby18.y ruby19.y),
10
+ RaccCoverage.start(%w(ruby18.y ruby19.y ruby20.y),
11
11
  File.expand_path('../../lib/parser', __FILE__))
12
12
 
13
13
  # Report results faster.
data/test/parse_helper.rb CHANGED
@@ -3,7 +3,7 @@ require 'parser/all'
3
3
  module ParseHelper
4
4
  include AST::Sexp
5
5
 
6
- ALL_VERSIONS = %w(1.8 1.9)
6
+ ALL_VERSIONS = %w(1.8 1.9 2.0)
7
7
 
8
8
  def setup
9
9
  @diagnostics = []
@@ -15,7 +15,7 @@ module ParseHelper
15
15
  case version
16
16
  when '1.8'; parser = Parser::Ruby18.new
17
17
  when '1.9'; parser = Parser::Ruby19.new
18
- # when '2.0'; parser = Parser::Ruby20.new # not yet
18
+ when '2.0'; parser = Parser::Ruby20.new
19
19
  else raise "Unrecognized Ruby version #{version}"
20
20
  end
21
21
 
data/test/test_lexer.rb CHANGED
@@ -1640,6 +1640,13 @@ class TestLexer < MiniTest::Unit::TestCase
1640
1640
  assert_equal :expr_beg, @lex.state
1641
1641
  end
1642
1642
 
1643
+ def test_star2_beg
1644
+ util_lex_token("** ",
1645
+ :tDSTAR, "**")
1646
+
1647
+ assert_equal :expr_beg, @lex.state
1648
+ end
1649
+
1643
1650
  def test_star_arg
1644
1651
  @lex.state = :expr_arg
1645
1652
 
@@ -1785,6 +1792,16 @@ class TestLexer < MiniTest::Unit::TestCase
1785
1792
  :tSTRING_END, "\"")
1786
1793
  end
1787
1794
 
1795
+ def test_string_double_interp_label
1796
+ util_lex_token('"#{foo:bar}"',
1797
+ :tSTRING_BEG, '"',
1798
+ :tSTRING_DBEG, '#{',
1799
+ :tIDENTIFIER, 'foo',
1800
+ :tSYMBOL, 'bar',
1801
+ :tRCURLY, '}',
1802
+ :tSTRING_END, '"')
1803
+ end
1804
+
1788
1805
  def test_string_double_nested_curlies
1789
1806
  util_lex_token('%{nest{one{two}one}nest}',
1790
1807
  :tSTRING, "nest{one{two}one}nest")
@@ -1809,7 +1826,7 @@ class TestLexer < MiniTest::Unit::TestCase
1809
1826
  end
1810
1827
 
1811
1828
  def test_string_pct_W
1812
- util_lex_token("%W[s1 s2\ns3]", # TODO: add interpolation to these
1829
+ util_lex_token("%W[s1 s2\ns3]",
1813
1830
  :tWORDS_BEG, "%W[",
1814
1831
  :tSTRING_CONTENT, "s1",
1815
1832
  :tSPACE, nil,
@@ -1821,7 +1838,7 @@ class TestLexer < MiniTest::Unit::TestCase
1821
1838
  end
1822
1839
 
1823
1840
  def test_string_pct_W_bs_nl
1824
- util_lex_token("%W[s1 \\\ns2]", # TODO: add interpolation to these
1841
+ util_lex_token("%W[s1 \\\ns2]",
1825
1842
  :tWORDS_BEG, "%W[",
1826
1843
  :tSTRING_CONTENT, "s1",
1827
1844
  :tSPACE, nil,
@@ -1830,6 +1847,32 @@ class TestLexer < MiniTest::Unit::TestCase
1830
1847
  :tSTRING_END, ']')
1831
1848
  end
1832
1849
 
1850
+ def test_string_pct_W_interp
1851
+ util_lex_token('%W[#{1}#{2} #@a]',
1852
+ :tWORDS_BEG, '%W[',
1853
+ :tSTRING_DBEG, '#{',
1854
+ :tINTEGER, 1,
1855
+ :tRCURLY, '}',
1856
+ :tSTRING_DBEG, '#{',
1857
+ :tINTEGER, 2,
1858
+ :tRCURLY, '}',
1859
+ :tSPACE, nil,
1860
+ :tSTRING_DVAR, nil,
1861
+ :tIVAR, '@a',
1862
+ :tSPACE, nil,
1863
+ :tSTRING_END, ']')
1864
+ end
1865
+
1866
+ def test_string_pct_I
1867
+ util_lex_token("%I(s1 s2)",
1868
+ :tSYMBOLS_BEG, "%I(",
1869
+ :tSTRING_CONTENT, "s1",
1870
+ :tSPACE, nil,
1871
+ :tSTRING_CONTENT, "s2",
1872
+ :tSPACE, nil,
1873
+ :tSTRING_END, ')')
1874
+ end
1875
+
1833
1876
  def test_string_pct_angle
1834
1877
  util_lex_token("%<blah>",
1835
1878
  :tSTRING, "blah")
@@ -1841,12 +1884,20 @@ class TestLexer < MiniTest::Unit::TestCase
1841
1884
  end
1842
1885
 
1843
1886
  def test_string_pct_w
1844
- util_bad_token("%w[s1 s2 ",
1887
+ util_lex_token("%w[s1 s2 ]",
1845
1888
  :tQWORDS_BEG, "%w[",
1846
1889
  :tSTRING_CONTENT, "s1",
1847
- :tSPACE, nil,
1890
+ :tSPACE, nil,
1848
1891
  :tSTRING_CONTENT, "s2",
1849
- :tSPACE, nil)
1892
+ :tSPACE, nil,
1893
+ :tSTRING_END, "]")
1894
+ end
1895
+
1896
+ def test_string_pct_w_incomplete
1897
+ util_bad_token("%w[s1 ",
1898
+ :tQWORDS_BEG, "%w[",
1899
+ :tSTRING_CONTENT, "s1",
1900
+ :tSPACE, nil)
1850
1901
  end
1851
1902
 
1852
1903
  def test_string_pct_w_bs_nl
@@ -1879,6 +1930,16 @@ class TestLexer < MiniTest::Unit::TestCase
1879
1930
  :tSTRING_END, ']')
1880
1931
  end
1881
1932
 
1933
+ def test_string_pct_i
1934
+ util_lex_token("%i(s1 s2)",
1935
+ :tQSYMBOLS_BEG, "%i(",
1936
+ :tSTRING_CONTENT, "s1",
1937
+ :tSPACE, nil,
1938
+ :tSTRING_CONTENT, "s2",
1939
+ :tSPACE, nil,
1940
+ :tSTRING_END, ')')
1941
+ end
1942
+
1882
1943
  def test_string_single
1883
1944
  util_lex_token("'string'",
1884
1945
  :tSTRING, "string")
@@ -1996,10 +2057,29 @@ class TestLexer < MiniTest::Unit::TestCase
1996
2057
  :kEND, "end")
1997
2058
  end
1998
2059
 
2060
+ def test_sclass_label
2061
+ setup_lexer 20
2062
+ util_lex_token("class << a:b",
2063
+ :kCLASS, 'class',
2064
+ :tLSHFT, '<<',
2065
+ :tIDENTIFIER, 'a',
2066
+ :tSYMBOL, 'b')
2067
+ end
2068
+
1999
2069
  def test_static_env
2000
2070
  env = Parser::StaticEnvironment.new
2001
2071
  env.declare "a"
2002
2072
 
2073
+ setup_lexer(18)
2074
+ @lex.static_env = env
2075
+
2076
+ util_lex_token("a [42]",
2077
+ :tIDENTIFIER, "a",
2078
+ :tLBRACK, "[",
2079
+ :tINTEGER, 42,
2080
+ :tRBRACK, "]")
2081
+
2082
+ setup_lexer(19)
2003
2083
  @lex.static_env = env
2004
2084
 
2005
2085
  util_lex_token("a [42]",
@@ -2204,6 +2284,16 @@ class TestLexer < MiniTest::Unit::TestCase
2204
2284
  :tNL, nil)
2205
2285
  end
2206
2286
 
2287
+ def test_bug_expr_beg_heredoc
2288
+ util_lex_token("<<EOL % [\nfoo\nEOL\n]",
2289
+ :tSTRING_BEG, '"',
2290
+ :tSTRING_CONTENT, "foo\n",
2291
+ :tSTRING_END, 'EOL',
2292
+ :tPERCENT, '%',
2293
+ :tLBRACK, '[',
2294
+ :tRBRACK, ']')
2295
+ end
2296
+
2207
2297
  def test_bug_ragel_stack
2208
2298
  util_lex_token("\"\#{$2 ? $2 : 1}\"",
2209
2299
  :tSTRING_BEG, "\"",
@@ -15,6 +15,13 @@ class TestLexerStackState < MiniTest::Unit::TestCase
15
15
  refute @state.active?
16
16
  end
17
17
 
18
+ def test_clear
19
+ @state.push true
20
+ @state.clear
21
+
22
+ refute @state.active?
23
+ end
24
+
18
25
  def test_pop
19
26
  @state.push(true)
20
27
 
data/test/test_parser.rb CHANGED
@@ -323,6 +323,12 @@ class TestParser < MiniTest::Unit::TestCase
323
323
  | ~~~ expression (str)
324
324
  | ~~~ expression (lvar)
325
325
  |~~~~~~~~~~~~~~ expression})
326
+
327
+ assert_parses(
328
+ s(:array,
329
+ s(:str, "foo"),
330
+ s(:dstr, s(:lvar, :bar), s(:str, 'foo'), s(:ivar, :@baz))),
331
+ %q{%W[foo #{bar}foo#@baz]})
326
332
  end
327
333
 
328
334
  def test_array_words_empty
@@ -338,6 +344,51 @@ class TestParser < MiniTest::Unit::TestCase
338
344
  %q{%W()})
339
345
  end
340
346
 
347
+ def test_array_symbols
348
+ assert_parses(
349
+ s(:array, s(:sym, :foo), s(:sym, :bar)),
350
+ %q{%i[foo bar]},
351
+ %q{^^^ begin
352
+ | ^ end
353
+ | ~~~ expression (sym)
354
+ |~~~~~~~~~~~ expression},
355
+ ALL_VERSIONS - %w(1.8 1.9))
356
+ end
357
+
358
+ def test_array_symbols_interp
359
+ assert_parses(
360
+ s(:array, s(:sym, :foo), s(:lvar, :bar)),
361
+ %q{%I[foo #{bar}]},
362
+ %q{^^^ begin
363
+ | ^ end
364
+ | ~~~ expression (sym)
365
+ | ~~~ expression (lvar)
366
+ |~~~~~~~~~~~~~~ expression},
367
+ ALL_VERSIONS - %w(1.8 1.9))
368
+
369
+ assert_parses(
370
+ s(:array, s(:dsym, s(:str, "foo"), s(:lvar, :bar))),
371
+ %q{%I[foo#{bar}]},
372
+ %q{},
373
+ ALL_VERSIONS - %w(1.8 1.9))
374
+ end
375
+
376
+ def test_array_symbols_empty
377
+ assert_parses(
378
+ s(:array),
379
+ %q{%i[]},
380
+ %q{^^^ begin
381
+ | ^ end
382
+ |~~~~ expression},
383
+ ALL_VERSIONS - %w(1.8 1.9))
384
+
385
+ assert_parses(
386
+ s(:array),
387
+ %q{%I()},
388
+ %q{},
389
+ ALL_VERSIONS - %w(1.8 1.9))
390
+ end
391
+
341
392
  # Hashes
342
393
 
343
394
  def test_hash_empty
@@ -1233,6 +1284,18 @@ class TestParser < MiniTest::Unit::TestCase
1233
1284
  | ~~~ end})
1234
1285
  end
1235
1286
 
1287
+ def test_class_super_label
1288
+ assert_parses(
1289
+ s(:class,
1290
+ s(:const, nil, :Foo),
1291
+ s(:send, nil, :a,
1292
+ s(:sym, :b)),
1293
+ s(:nil)),
1294
+ %q{class Foo < a:b; end},
1295
+ %q{},
1296
+ ALL_VERSIONS - %w(1.8 1.9))
1297
+ end
1298
+
1236
1299
  def test_class_invalid
1237
1300
  assert_diagnoses(
1238
1301
  [:error, :class_in_def],
@@ -1666,6 +1729,11 @@ class TestParser < MiniTest::Unit::TestCase
1666
1729
  %q{|;a|},
1667
1730
  ALL_VERSIONS - %w(1.8))
1668
1731
 
1732
+ assert_parses_blockargs(
1733
+ s(:args, s(:shadowarg, :a)),
1734
+ %Q{|;\na\n|},
1735
+ ALL_VERSIONS - %w(1.8 1.9))
1736
+
1669
1737
  # tOROP
1670
1738
  assert_parses_blockargs(
1671
1739
  s(:args),
@@ -1915,6 +1983,32 @@ class TestParser < MiniTest::Unit::TestCase
1915
1983
  %q{ ~~~~~ location})
1916
1984
  end
1917
1985
 
1986
+ def test_arg_label
1987
+ assert_parses(
1988
+ s(:def, :foo, s(:args),
1989
+ s(:send, nil, :a, s(:sym, :b))),
1990
+ %q{def foo() a:b end},
1991
+ %q{},
1992
+ ALL_VERSIONS - %w(1.8))
1993
+
1994
+ assert_parses(
1995
+ s(:def, :foo, s(:args),
1996
+ s(:send, nil, :a, s(:sym, :b))),
1997
+ %Q{def foo\n a:b end},
1998
+ %q{},
1999
+ ALL_VERSIONS - %w(1.8))
2000
+
2001
+ assert_parses(
2002
+ s(:block,
2003
+ s(:send, nil, :f),
2004
+ s(:args),
2005
+ s(:send, nil, :a,
2006
+ s(:sym, :b))),
2007
+ %Q{f { || a:b }},
2008
+ %q{},
2009
+ ALL_VERSIONS - %w(1.8))
2010
+ end
2011
+
1918
2012
  # def test_kwoptarg
1919
2013
  # flunk
1920
2014
  # end
@@ -2372,6 +2466,15 @@ class TestParser < MiniTest::Unit::TestCase
2372
2466
  | ^ end
2373
2467
  |~~~~~ expression},
2374
2468
  ALL_VERSIONS - %w(1.8))
2469
+
2470
+ assert_parses(
2471
+ s(:block, s(:send, nil, :lambda),
2472
+ s(:args,
2473
+ s(:arg, :a)),
2474
+ s(:nil)),
2475
+ %q{-> (a) { }},
2476
+ %q{},
2477
+ ALL_VERSIONS - %w(1.8 1.9))
2375
2478
  end
2376
2479
 
2377
2480
  def test_send_lambda_args_shadow
@@ -2651,11 +2754,6 @@ class TestParser < MiniTest::Unit::TestCase
2651
2754
  s(:send, nil, :fun,
2652
2755
  s(:send, s(:int, 1), :to_i)),
2653
2756
  %q{fun (1).to_i})
2654
-
2655
- assert_diagnoses(
2656
- [:warning, :grouped_expression],
2657
- %q{fun (1).to_i},
2658
- %q{ ~~~ location})
2659
2757
  end
2660
2758
 
2661
2759
  def test_space_args_block_pass
@@ -2895,6 +2993,15 @@ class TestParser < MiniTest::Unit::TestCase
2895
2993
  %q{ ^ begin (send)
2896
2994
  | ^ end (send)},
2897
2995
  %w(1.8))
2996
+
2997
+ assert_parses(
2998
+ s(:block,
2999
+ s(:send, nil, :fun,
3000
+ s(:nil)),
3001
+ s(:args), s(:nil)),
3002
+ %q{fun () {}},
3003
+ %q{ ~~ expression (send.nil)},
3004
+ ALL_VERSIONS - %w(1.8 1.9))
2898
3005
  end
2899
3006
 
2900
3007
  #
@@ -2931,6 +3038,16 @@ class TestParser < MiniTest::Unit::TestCase
2931
3038
  |~~~~~~~~~~ expression})
2932
3039
  end
2933
3040
 
3041
+ def test_and_or_masgn_invalid
3042
+ assert_diagnoses(
3043
+ [:error, :masgn_as_condition],
3044
+ %q{foo && (a, b = bar)})
3045
+
3046
+ assert_diagnoses(
3047
+ [:error, :masgn_as_condition],
3048
+ %q{foo || (a, b = bar)})
3049
+ end
3050
+
2934
3051
  # Branching
2935
3052
 
2936
3053
  def test_if
@@ -3621,6 +3738,22 @@ class TestParser < MiniTest::Unit::TestCase
3621
3738
  %q{ ~~~ location})
3622
3739
  end
3623
3740
 
3741
+ #
3742
+ # Miscellanea
3743
+ #
3744
+
3745
+ def test_begin_cmdarg
3746
+ assert_parses(
3747
+ s(:send, nil, :p,
3748
+ s(:block,
3749
+ s(:send, s(:int, 1), :times),
3750
+ s(:args),
3751
+ s(:int, 1))),
3752
+ %q{p begin 1.times do 1 end end},
3753
+ %{},
3754
+ ALL_VERSIONS - %w(1.8 1.9))
3755
+ end
3756
+
3624
3757
  #
3625
3758
  # Error recovery
3626
3759
  #
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: 0.9.1
4
+ version: 0.9.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Peter Zotov
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2013-04-15 00:00:00.000000000 Z
11
+ date: 2013-04-16 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: ast
@@ -150,6 +150,7 @@ files:
150
150
  - LICENSE.txt
151
151
  - README.md
152
152
  - Rakefile
153
+ - TODO.md
153
154
  - bin/benchmark
154
155
  - bin/explain-parse
155
156
  - bin/parse
@@ -168,6 +169,7 @@ files:
168
169
  - lib/parser/lexer/stack_state.rb
169
170
  - lib/parser/ruby18.y
170
171
  - lib/parser/ruby19.y
172
+ - lib/parser/ruby20.y
171
173
  - lib/parser/source/buffer.rb
172
174
  - lib/parser/source/map.rb
173
175
  - lib/parser/source/map/operator.rb
@@ -175,6 +177,7 @@ files:
175
177
  - lib/parser/source/range.rb
176
178
  - lib/parser/static_environment.rb
177
179
  - lib/parser/syntax_error.rb
180
+ - parse.y.diff
178
181
  - parser.gemspec
179
182
  - test/helper.rb
180
183
  - test/parse_helper.rb
@@ -191,6 +194,7 @@ files:
191
194
  - lib/parser/lexer.rb
192
195
  - lib/parser/ruby18.rb
193
196
  - lib/parser/ruby19.rb
197
+ - lib/parser/ruby20.rb
194
198
  homepage: http://github.com/whitequark/parser
195
199
  licenses:
196
200
  - MIT