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.
Files changed (101) hide show
  1. checksums.yaml +4 -4
  2. data/.travis.yml +5 -6
  3. data/CHANGELOG.md +35 -1
  4. data/Gemfile +2 -0
  5. data/README.md +1 -2
  6. data/Rakefile +2 -1
  7. data/bin/ruby-parse +2 -1
  8. data/bin/ruby-rewrite +2 -1
  9. data/lib/gauntlet_parser.rb +2 -0
  10. data/lib/parser.rb +16 -17
  11. data/lib/parser/all.rb +2 -0
  12. data/lib/parser/ast/node.rb +2 -0
  13. data/lib/parser/ast/processor.rb +2 -0
  14. data/lib/parser/base.rb +6 -12
  15. data/lib/parser/builders/default.rb +28 -47
  16. data/lib/parser/clobbering_error.rb +2 -0
  17. data/lib/parser/context.rb +42 -0
  18. data/lib/parser/current.rb +4 -20
  19. data/lib/parser/deprecation.rb +13 -0
  20. data/lib/parser/diagnostic.rb +3 -3
  21. data/lib/parser/diagnostic/engine.rb +2 -0
  22. data/lib/parser/lexer.rl +122 -60
  23. data/lib/parser/lexer/dedenter.rb +2 -0
  24. data/lib/parser/lexer/explanation.rb +2 -0
  25. data/lib/parser/lexer/literal.rb +4 -9
  26. data/lib/parser/lexer/stack_state.rb +4 -1
  27. data/lib/parser/macruby.y +32 -17
  28. data/lib/parser/messages.rb +14 -0
  29. data/lib/parser/meta.rb +2 -0
  30. data/lib/parser/rewriter.rb +30 -44
  31. data/lib/parser/ruby18.y +20 -13
  32. data/lib/parser/ruby19.y +32 -17
  33. data/lib/parser/ruby20.y +33 -18
  34. data/lib/parser/ruby21.y +32 -17
  35. data/lib/parser/ruby22.y +32 -17
  36. data/lib/parser/ruby23.y +32 -17
  37. data/lib/parser/ruby24.y +63 -46
  38. data/lib/parser/ruby25.y +72 -48
  39. data/lib/parser/rubymotion.y +33 -18
  40. data/lib/parser/runner.rb +4 -7
  41. data/lib/parser/runner/ruby_parse.rb +10 -0
  42. data/lib/parser/runner/ruby_rewrite.rb +2 -0
  43. data/lib/parser/source/buffer.rb +19 -24
  44. data/lib/parser/source/comment.rb +2 -0
  45. data/lib/parser/source/comment/associator.rb +2 -0
  46. data/lib/parser/source/map.rb +2 -0
  47. data/lib/parser/source/map/collection.rb +2 -0
  48. data/lib/parser/source/map/condition.rb +2 -0
  49. data/lib/parser/source/map/constant.rb +2 -0
  50. data/lib/parser/source/map/definition.rb +2 -0
  51. data/lib/parser/source/map/for.rb +2 -0
  52. data/lib/parser/source/map/heredoc.rb +2 -0
  53. data/lib/parser/source/map/keyword.rb +2 -0
  54. data/lib/parser/source/map/objc_kwarg.rb +2 -0
  55. data/lib/parser/source/map/operator.rb +2 -0
  56. data/lib/parser/source/map/rescue_body.rb +2 -0
  57. data/lib/parser/source/map/send.rb +2 -0
  58. data/lib/parser/source/map/ternary.rb +2 -0
  59. data/lib/parser/source/map/variable.rb +2 -0
  60. data/lib/parser/source/range.rb +81 -13
  61. data/lib/parser/source/rewriter.rb +48 -10
  62. data/lib/parser/source/rewriter/action.rb +2 -0
  63. data/lib/parser/source/tree_rewriter.rb +301 -0
  64. data/lib/parser/source/tree_rewriter/action.rb +133 -0
  65. data/lib/parser/static_environment.rb +2 -0
  66. data/lib/parser/syntax_error.rb +2 -0
  67. data/lib/parser/tree_rewriter.rb +133 -0
  68. data/lib/parser/version.rb +3 -1
  69. data/parser.gemspec +4 -1
  70. data/test/bug_163/fixtures/input.rb +2 -0
  71. data/test/bug_163/fixtures/output.rb +2 -0
  72. data/test/bug_163/rewriter.rb +2 -0
  73. data/test/helper.rb +7 -7
  74. data/test/parse_helper.rb +57 -10
  75. data/test/racc_coverage_helper.rb +2 -0
  76. data/test/test_base.rb +2 -0
  77. data/test/test_current.rb +2 -4
  78. data/test/test_diagnostic.rb +3 -1
  79. data/test/test_diagnostic_engine.rb +2 -0
  80. data/test/test_encoding.rb +61 -49
  81. data/test/test_lexer.rb +164 -77
  82. data/test/test_lexer_stack_state.rb +2 -0
  83. data/test/test_parse_helper.rb +8 -8
  84. data/test/test_parser.rb +613 -51
  85. data/test/test_runner_rewrite.rb +47 -0
  86. data/test/test_source_buffer.rb +22 -10
  87. data/test/test_source_comment.rb +2 -0
  88. data/test/test_source_comment_associator.rb +2 -0
  89. data/test/test_source_map.rb +2 -0
  90. data/test/test_source_range.rb +92 -45
  91. data/test/test_source_rewriter.rb +3 -1
  92. data/test/test_source_rewriter_action.rb +2 -0
  93. data/test/test_source_tree_rewriter.rb +177 -0
  94. data/test/test_static_environment.rb +2 -0
  95. data/test/using_tree_rewriter/fixtures/input.rb +3 -0
  96. data/test/using_tree_rewriter/fixtures/output.rb +3 -0
  97. data/test/using_tree_rewriter/using_tree_rewriter.rb +9 -0
  98. metadata +21 -10
  99. data/lib/parser/compatibility/ruby1_8.rb +0 -20
  100. data/lib/parser/compatibility/ruby1_9.rb +0 -32
  101. data/test/bug_163/test_runner_rewrite.rb +0 -35
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Parser
2
4
  class << self
3
5
  def warn_syntax_deviation(feature, version)
@@ -9,24 +11,6 @@ module Parser
9
11
  end
10
12
 
11
13
  case RUBY_VERSION
12
- when /^1\.8\./
13
- current_version = '1.8.7'
14
- if RUBY_VERSION != current_version
15
- warn_syntax_deviation 'parser/ruby18', current_version
16
- end
17
-
18
- require 'parser/ruby18'
19
- CurrentRuby = Ruby18
20
-
21
- when /^1\.9\./
22
- current_version = '1.9.3'
23
- if RUBY_VERSION != current_version
24
- warn_syntax_deviation 'parser/ruby19', current_version
25
- end
26
-
27
- require 'parser/ruby19'
28
- CurrentRuby = Ruby19
29
-
30
14
  when /^2\.0\./
31
15
  current_version = '2.0.0'
32
16
  if RUBY_VERSION != current_version
@@ -46,7 +30,7 @@ module Parser
46
30
  CurrentRuby = Ruby21
47
31
 
48
32
  when /^2\.2\./
49
- current_version = '2.2.8'
33
+ current_version = '2.2.9'
50
34
  if RUBY_VERSION != current_version
51
35
  warn_syntax_deviation 'parser/ruby22', current_version
52
36
  end
@@ -55,7 +39,7 @@ module Parser
55
39
  CurrentRuby = Ruby22
56
40
 
57
41
  when /^2\.3\./
58
- current_version = '2.3.5'
42
+ current_version = '2.3.6'
59
43
  if RUBY_VERSION != current_version
60
44
  warn_syntax_deviation 'parser/ruby23', current_version
61
45
  end
@@ -0,0 +1,13 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Parser
4
+ ##
5
+ # @api private
6
+ #
7
+ module Deprecation
8
+ attr_writer :warned_of_deprecation
9
+ def warn_of_deprecation
10
+ @warned_of_deprecation ||= warn(self::DEPRECATION_WARNING) || true
11
+ end
12
+ end
13
+ end
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Parser
2
4
 
3
5
  ##
@@ -152,9 +154,7 @@ module Parser
152
154
  #
153
155
  def last_line_only(range)
154
156
  if range.line != range.last_line
155
- Source::Range.new(range.source_buffer,
156
- range.begin_pos + (range.source =~ /[^\n]*\z/),
157
- range.end_pos)
157
+ range.adjust(begin_pos: range.source =~ /[^\n]*\z/)
158
158
  else
159
159
  range
160
160
  end
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Parser
2
4
 
3
5
  ##
@@ -89,8 +89,6 @@ class Parser::Lexer
89
89
 
90
90
  REGEXP_META_CHARACTERS = Regexp.union(*"\\$()*+.<>?[]^{|}".chars).freeze
91
91
 
92
- RBRACE_OR_RBRACK = %w"} ]".freeze
93
-
94
92
  attr_reader :source_buffer
95
93
 
96
94
  attr_accessor :diagnostics
@@ -174,6 +172,9 @@ class Parser::Lexer
174
172
 
175
173
  # True at the end of "def foo a:"
176
174
  @in_kwarg = false
175
+
176
+ # State before =begin / =end block comment
177
+ @cs_before_block_comment = self.class.lex_en_line_begin
177
178
  end
178
179
 
179
180
  def source_buffer=(source_buffer)
@@ -182,7 +183,7 @@ class Parser::Lexer
182
183
  if @source_buffer
183
184
  source = @source_buffer.source
184
185
 
185
- if defined?(Encoding) && source.encoding == Encoding::UTF_8
186
+ if source.encoding == Encoding::UTF_8
186
187
  @source_pts = source.unpack('U*')
187
188
  else
188
189
  @source_pts = source.unpack('C*')
@@ -308,14 +309,8 @@ class Parser::Lexer
308
309
  @stack[@top]
309
310
  end
310
311
 
311
- if defined?(Encoding)
312
- def encode_escape(ord)
313
- ord.chr.force_encoding(@source_buffer.source.encoding)
314
- end
315
- else
316
- def encode_escape(ord)
317
- ord.chr
318
- end
312
+ def encode_escape(ord)
313
+ ord.chr.force_encoding(@source_buffer.source.encoding)
319
314
  end
320
315
 
321
316
  def tok(s = @ts, e = @te)
@@ -622,19 +617,23 @@ class Parser::Lexer
622
617
  flo_pow = [eE] [+\-]? ( digit+ '_' )* digit+;
623
618
 
624
619
  int_suffix =
625
- '' % { @num_xfrm = lambda { |chars| emit(:tINTEGER, chars) } }
626
- | 'r' % { @num_xfrm = lambda { |chars| emit(:tRATIONAL, Rational(chars)) } }
627
- | 'i' % { @num_xfrm = lambda { |chars| emit(:tIMAGINARY, Complex(0, chars)) } }
628
- | 'ri' % { @num_xfrm = lambda { |chars| emit(:tIMAGINARY, Complex(0, Rational(chars))) } };
620
+ '' % { @num_xfrm = lambda { |chars| emit(:tINTEGER, chars) } }
621
+ | 'r' % { @num_xfrm = lambda { |chars| emit(:tRATIONAL, Rational(chars)) } }
622
+ | 'i' % { @num_xfrm = lambda { |chars| emit(:tIMAGINARY, Complex(0, chars)) } }
623
+ | 'ri' % { @num_xfrm = lambda { |chars| emit(:tIMAGINARY, Complex(0, Rational(chars))) } }
624
+ | 'if' % { @num_xfrm = lambda { |chars| emit(:tINTEGER, chars, @ts, @te - 2); p -= 2 } }
625
+ | 'rescue' % { @num_xfrm = lambda { |chars| emit(:tINTEGER, chars, @ts, @te - 6); p -= 6 } };
629
626
 
630
627
  flo_pow_suffix =
631
628
  '' % { @num_xfrm = lambda { |chars| emit(:tFLOAT, Float(chars)) } }
632
- | 'i' % { @num_xfrm = lambda { |chars| emit(:tIMAGINARY, Complex(0, Float(chars))) } };
629
+ | 'i' % { @num_xfrm = lambda { |chars| emit(:tIMAGINARY, Complex(0, Float(chars))) } }
630
+ | 'if' % { @num_xfrm = lambda { |chars| emit(:tFLOAT, Float(chars), @ts, @te - 2); p -= 2 } };
633
631
 
634
632
  flo_suffix =
635
633
  flo_pow_suffix
636
- | 'r' % { @num_xfrm = lambda { |chars| emit(:tRATIONAL, Rational(chars)) } }
637
- | 'ri' % { @num_xfrm = lambda { |chars| emit(:tIMAGINARY, Complex(0, Rational(chars))) } };
634
+ | 'r' % { @num_xfrm = lambda { |chars| emit(:tRATIONAL, Rational(chars)) } }
635
+ | 'ri' % { @num_xfrm = lambda { |chars| emit(:tIMAGINARY, Complex(0, Rational(chars))) } }
636
+ | 'rescue' % { @num_xfrm = lambda { |chars| emit(:tFLOAT, Float(chars), @ts, @te - 6); p -= 6 } };
638
637
 
639
638
  #
640
639
  # === ESCAPE SEQUENCE PARSING ===
@@ -655,17 +654,37 @@ class Parser::Lexer
655
654
  codepoints = tok(@escape_s + 2, p - 1)
656
655
  codepoint_s = @escape_s + 2
657
656
 
658
- codepoints.split(/[ \t]/).each do |codepoint_str|
659
- codepoint = codepoint_str.to_i(16)
657
+ if @version < 24
658
+ if codepoints.start_with?(" ") || codepoints.start_with?("\t")
659
+ diagnostic :fatal, :invalid_unicode_escape, nil,
660
+ range(@escape_s + 2, @escape_s + 3)
661
+ end
660
662
 
661
- if codepoint >= 0x110000
662
- diagnostic :error, :unicode_point_too_large, nil,
663
- range(codepoint_s, codepoint_s + codepoint_str.length)
664
- break
663
+ if spaces_p = codepoints.index(/[ \t]{2}/)
664
+ diagnostic :fatal, :invalid_unicode_escape, nil,
665
+ range(codepoint_s + spaces_p + 1, codepoint_s + spaces_p + 2)
665
666
  end
666
667
 
667
- @escape += codepoint.chr(Encoding::UTF_8)
668
- codepoint_s += codepoint_str.length + 1
668
+ if codepoints.end_with?(" ") || codepoints.end_with?("\t")
669
+ diagnostic :fatal, :invalid_unicode_escape, nil, range(p - 1, p)
670
+ end
671
+ end
672
+
673
+ codepoints.scan(/([0-9a-fA-F]+)|([ \t]+)/).each do |(codepoint_str, spaces)|
674
+ if spaces
675
+ codepoint_s += spaces.length
676
+ else
677
+ codepoint = codepoint_str.to_i(16)
678
+
679
+ if codepoint >= 0x110000
680
+ diagnostic :error, :unicode_point_too_large, nil,
681
+ range(codepoint_s, codepoint_s + codepoint_str.length)
682
+ break
683
+ end
684
+
685
+ @escape += codepoint.chr(Encoding::UTF_8)
686
+ codepoint_s += codepoint_str.length
687
+ end
669
688
  end
670
689
  }
671
690
 
@@ -708,35 +727,38 @@ class Parser::Lexer
708
727
  | 'x' xdigit{1,2}
709
728
  % { @escape = encode_escape(tok(@escape_s + 1, p).to_i(16)) }
710
729
 
730
+ # %q[\x]
731
+ | 'x' ( c_any - xdigit )
732
+ % {
733
+ diagnostic :fatal, :invalid_hex_escape, nil, range(@escape_s - 1, p + 2)
734
+ }
735
+
711
736
  # \u263a
712
737
  | 'u' xdigit{4}
713
738
  % { @escape = tok(@escape_s + 1, p).to_i(16).chr(Encoding::UTF_8) }
714
739
 
715
- # %q[\x]
716
- | 'x' ( c_any - xdigit )
740
+ # \u123
741
+ | 'u' xdigit{0,3}
717
742
  % {
718
- diagnostic :fatal, :invalid_hex_escape, nil, range(@escape_s - 1, p + 2)
743
+ diagnostic :fatal, :invalid_unicode_escape, nil, range(@escape_s - 1, p)
719
744
  }
720
745
 
721
- # %q[\u123] %q[\u{12]
722
- | 'u' ( c_any{0,4} -
723
- xdigit{4} - # \u1234 is valid
724
- ( '{' xdigit{1,3} # \u{1 \u{12 \u{123 are valid
725
- | '{' xdigit [ \t}] any? # \u{1. \u{1} are valid
726
- | '{' xdigit{2} [ \t}] # \u{12. \u{12} are valid
727
- )
728
- )
746
+ # u{not hex} or u{}
747
+ | 'u{' ( c_any - xdigit - [ \t}] )* '}'
729
748
  % {
730
749
  diagnostic :fatal, :invalid_unicode_escape, nil, range(@escape_s - 1, p)
731
750
  }
732
751
 
733
- # \u{123 456}
734
- | 'u{' ( xdigit{1,6} [ \t] )*
735
- ( xdigit{1,6} '}'
736
- %unicode_points
737
- | ( xdigit* ( c_any - xdigit - '}' )+ '}'
738
- | ( c_any - '}' )* c_eof
739
- | xdigit{7,}
752
+ # \u{ \t 123 \t 456 \t\t }
753
+ | 'u{' [ \t]* ( xdigit{1,6} [ \t]+ )*
754
+ (
755
+ ( xdigit{1,6} [ \t]* '}'
756
+ %unicode_points
757
+ )
758
+ |
759
+ ( xdigit* ( c_any - xdigit - [ \t}] )+ '}'
760
+ | ( c_any - [ \t}] )* c_eof
761
+ | xdigit{7,}
740
762
  ) % {
741
763
  diagnostic :fatal, :unterminated_unicode, nil, range(p - 1, p)
742
764
  }
@@ -1096,13 +1118,15 @@ class Parser::Lexer
1096
1118
  end
1097
1119
 
1098
1120
  emit(:tREGEXP_OPT)
1099
- fnext expr_end; fbreak;
1121
+ fnext expr_end;
1122
+ fbreak;
1100
1123
  };
1101
1124
 
1102
1125
  any
1103
1126
  => {
1104
1127
  emit(:tREGEXP_OPT, tok(@ts, @te - 1), @ts, @te - 1)
1105
- fhold; fgoto expr_end;
1128
+ fhold;
1129
+ fgoto expr_end;
1106
1130
  };
1107
1131
  *|;
1108
1132
 
@@ -1669,19 +1693,30 @@ class Parser::Lexer
1669
1693
  # <<-END | <<-'END' | <<-"END" | <<-`END` |
1670
1694
  # <<~END | <<~'END' | <<~"END" | <<~`END`
1671
1695
  '<<' [~\-]?
1672
- ( '"' ( c_line - '"' )* '"'
1673
- | "'" ( c_line - "'" )* "'"
1674
- | "`" ( c_line - "`" )* "`"
1696
+ ( '"' ( any - '"' )* '"'
1697
+ | "'" ( any - "'" )* "'"
1698
+ | "`" ( any - "`" )* "`"
1675
1699
  | bareword ) % { heredoc_e = p }
1676
1700
  c_line* c_nl % { new_herebody_s = p }
1677
1701
  => {
1678
- tok(@ts, heredoc_e) =~ /^<<(-?)(~?)(["'`]?)(.*)\3$/
1702
+ tok(@ts, heredoc_e) =~ /^<<(-?)(~?)(["'`]?)(.*)\3$/m
1679
1703
 
1680
1704
  indent = !$1.empty? || !$2.empty?
1681
1705
  dedent_body = !$2.empty?
1682
1706
  type = $3.empty? ? '<<"'.freeze : ('<<'.freeze + $3)
1683
1707
  delimiter = $4
1684
1708
 
1709
+ if @version >= 24
1710
+ if delimiter.count("\n") > 0
1711
+ if delimiter.end_with?("\n")
1712
+ diagnostic :warning, :heredoc_id_ends_with_nl, nil, range(@ts, @ts + 1)
1713
+ delimiter = delimiter.rstrip
1714
+ else
1715
+ diagnostic :fatal, :heredoc_id_has_newline, nil, range(@ts, @ts + 1)
1716
+ end
1717
+ end
1718
+ end
1719
+
1685
1720
  if dedent_body && version?(18, 19, 20, 21, 22)
1686
1721
  emit(:tLSHFT, '<<'.freeze, @ts, @ts + 2)
1687
1722
  p = @ts + 1
@@ -1698,6 +1733,13 @@ class Parser::Lexer
1698
1733
  # SYMBOL LITERALS
1699
1734
  #
1700
1735
 
1736
+ # :&&, :||
1737
+ ':' ('&&' | '||') => {
1738
+ fhold; fhold;
1739
+ emit(:tSYMBEG, tok(@ts, @ts + 1), @ts, @ts + 1)
1740
+ fgoto expr_fname;
1741
+ };
1742
+
1701
1743
  # :"bar", :'baz'
1702
1744
  ':' ['"] # '
1703
1745
  => {
@@ -1732,11 +1774,7 @@ class Parser::Lexer
1732
1774
  value = @escape || tok(@ts + 1)
1733
1775
 
1734
1776
  if version?(18)
1735
- if defined?(Encoding)
1736
- emit(:tINTEGER, value.dup.force_encoding(Encoding::BINARY)[0].ord)
1737
- else
1738
- emit(:tINTEGER, value[0].ord)
1739
- end
1777
+ emit(:tINTEGER, value.dup.force_encoding(Encoding::BINARY)[0].ord)
1740
1778
  else
1741
1779
  emit(:tCHARACTER, value)
1742
1780
  end
@@ -1853,6 +1891,21 @@ class Parser::Lexer
1853
1891
  call_or_var
1854
1892
  => local_ident;
1855
1893
 
1894
+ (call_or_var - keyword)
1895
+ % { ident_tok = tok; ident_ts = @ts; ident_te = @te; }
1896
+ w_space+ '('
1897
+ => {
1898
+ emit(:tIDENTIFIER, ident_tok, ident_ts, ident_te)
1899
+ p = ident_te - 1
1900
+
1901
+ if !@static_env.nil? && @static_env.declared?(ident_tok) && @version < 25
1902
+ fnext expr_endfn;
1903
+ else
1904
+ fnext expr_cmdarg;
1905
+ end
1906
+ fbreak;
1907
+ };
1908
+
1856
1909
  #
1857
1910
  # WHITESPACE
1858
1911
  #
@@ -1860,8 +1913,11 @@ class Parser::Lexer
1860
1913
  w_any;
1861
1914
 
1862
1915
  e_heredoc_nl '=begin' ( c_space | c_nl_zlen )
1863
- => { p = @ts - 1
1864
- fgoto line_begin; };
1916
+ => {
1917
+ p = @ts - 1
1918
+ @cs_before_block_comment = @cs
1919
+ fgoto line_begin;
1920
+ };
1865
1921
 
1866
1922
  #
1867
1923
  # DEFAULT TRANSITION
@@ -2159,10 +2215,16 @@ class Parser::Lexer
2159
2215
  e_rbrace | e_rparen | ']'
2160
2216
  => {
2161
2217
  emit_table(PUNCTUATION)
2162
- @cond.lexpop; @cmdarg.lexpop
2218
+ @cond.lexpop; @cmdarg.pop
2163
2219
 
2164
- if RBRACE_OR_RBRACK.include?(tok)
2220
+ if tok == '}'.freeze
2165
2221
  fnext expr_endarg;
2222
+ elsif tok == ']'
2223
+ if @version >= 24
2224
+ fnext expr_end;
2225
+ else
2226
+ fnext expr_endarg;
2227
+ end
2166
2228
  else # )
2167
2229
  # fnext expr_endfn; ?
2168
2230
  end
@@ -2232,7 +2294,7 @@ class Parser::Lexer
2232
2294
  '=end' c_line* c_nl_zlen
2233
2295
  => {
2234
2296
  emit_comment(@eq_begin_s, @te)
2235
- fgoto line_begin;
2297
+ fgoto *@cs_before_block_comment;
2236
2298
  };
2237
2299
 
2238
2300
  c_line* c_nl;
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Parser
2
4
 
3
5
  class Lexer::Dedenter
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Parser
2
4
 
3
5
  module Lexer::Explanation
@@ -1,4 +1,5 @@
1
1
  # encoding: binary
2
+ # frozen_string_literal: true
2
3
 
3
4
  module Parser
4
5
 
@@ -229,21 +230,15 @@ module Parser
229
230
  end
230
231
 
231
232
  def coerce_encoding(string)
232
- if defined?(Encoding)
233
- string.dup.force_encoding(Encoding::BINARY)
234
- else
235
- string
236
- end
233
+ string.dup.force_encoding(Encoding::BINARY)
237
234
  end
238
235
 
239
236
  def clear_buffer
240
- @buffer = ''
237
+ @buffer = ''.dup
241
238
 
242
239
  # Prime the buffer with lexer encoding; otherwise,
243
240
  # concatenation will produce varying results.
244
- if defined?(Encoding)
245
- @buffer.force_encoding(@lexer.source_buffer.source.encoding)
246
- end
241
+ @buffer.force_encoding(@lexer.source_buffer.source.encoding)
247
242
 
248
243
  @buffer_s = nil
249
244
  @buffer_e = nil
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Parser
2
4
 
3
5
  class Lexer::StackState
@@ -25,7 +27,8 @@ module Parser
25
27
  end
26
28
 
27
29
  def lexpop
28
- push(pop || pop)
30
+ @stack = ((@stack >> 1) | (@stack & 1))
31
+ @stack[0] == 1
29
32
  end
30
33
 
31
34
  def active?