ruby-next-parser 3.0.1.0 → 3.1.0.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -519,7 +519,8 @@ class Next
519
519
  c_nl_zlen = c_nl | zlen;
520
520
  c_line = any - c_nl_zlen;
521
521
 
522
- c_unicode = c_any - 0x00..0x7f;
522
+ c_ascii = 0x00..0x7f;
523
+ c_unicode = c_any - c_ascii;
523
524
  c_upper = [A-Z];
524
525
  c_lower = [a-z_] | c_unicode;
525
526
  c_alpha = c_lower | c_upper;
@@ -706,6 +707,11 @@ class Next
706
707
 
707
708
  action unescape_char {
708
709
  codepoint = @source_pts[p - 1]
710
+
711
+ if @version >= 30 && (codepoint == 117 || codepoint == 85) # 'u' or 'U'
712
+ diagnostic :fatal, :invalid_escape
713
+ end
714
+
709
715
  if (@escape = ESCAPES[codepoint]).nil?
710
716
  @escape = encode_escape(@source_buffer.slice(p - 1))
711
717
  end
@@ -733,12 +739,14 @@ class Next
733
739
 
734
740
  maybe_escaped_char = (
735
741
  '\\' c_any %unescape_char
742
+ | '\\x' xdigit{1,2} % { @escape = encode_escape(tok(p - 2, p).to_i(16)) } %slash_c_char
736
743
  | ( c_any - [\\] ) %read_post_meta_or_ctrl_char
737
744
  );
738
745
 
739
746
  maybe_escaped_ctrl_char = ( # why?!
740
747
  '\\' c_any %unescape_char %slash_c_char
741
748
  | '?' % { @escape = "\x7f" }
749
+ | '\\x' xdigit{1,2} % { @escape = encode_escape(tok(p - 2, p).to_i(16)) } %slash_c_char
742
750
  | ( c_any - [\\?] ) %read_post_meta_or_ctrl_char %slash_c_char
743
751
  );
744
752
 
@@ -930,7 +938,7 @@ class Next
930
938
  # b"
931
939
  # must be parsed as "ab"
932
940
  current_literal.extend_string(tok.gsub("\\\n".freeze, ''.freeze), @ts, @te)
933
- elsif current_literal.regexp?
941
+ elsif current_literal.regexp? && @version < 31
934
942
  # Regular expressions should include escape sequences in their
935
943
  # escaped form. On the other hand, escaped newlines are removed (in cases like "\\C-\\\n\\M-x")
936
944
  current_literal.extend_string(tok.gsub("\\\n".freeze, ''.freeze), @ts, @te)
@@ -1402,7 +1410,7 @@ class Next
1402
1410
  ':'
1403
1411
  => { fhold; fgoto expr_beg; };
1404
1412
 
1405
- '%s' c_any
1413
+ '%s' (c_ascii - [A-Za-z0-9])
1406
1414
  => {
1407
1415
  if version?(23)
1408
1416
  type, delimiter = tok[0..-2], tok[-1].chr
@@ -1754,14 +1762,14 @@ class Next
1754
1762
  };
1755
1763
 
1756
1764
  # %<string>
1757
- '%' ( any - [A-Za-z] )
1765
+ '%' ( c_ascii - [A-Za-z0-9] )
1758
1766
  => {
1759
1767
  type, delimiter = @source_buffer.slice(@ts).chr, tok[-1].chr
1760
1768
  fgoto *push_literal(type, delimiter, @ts);
1761
1769
  };
1762
1770
 
1763
1771
  # %w(we are the people)
1764
- '%' [A-Za-z]+ c_any
1772
+ '%' [A-Za-z] (c_ascii - [A-Za-z0-9])
1765
1773
  => {
1766
1774
  type, delimiter = tok[0..-2], tok[-1].chr
1767
1775
  fgoto *push_literal(type, delimiter, @ts);
@@ -2526,6 +2534,28 @@ class Next
2526
2534
  end
2527
2535
  };
2528
2536
 
2537
+ c_space* '..'
2538
+ => {
2539
+ emit(:tNL, nil, @newline_s, @newline_s + 1)
2540
+ if @version < 27
2541
+ fhold; fnext line_begin; fbreak;
2542
+ else
2543
+ emit(:tBDOT2)
2544
+ fnext expr_beg; fbreak;
2545
+ end
2546
+ };
2547
+
2548
+ c_space* '...'
2549
+ => {
2550
+ emit(:tNL, nil, @newline_s, @newline_s + 1)
2551
+ if @version < 27
2552
+ fhold; fnext line_begin; fbreak;
2553
+ else
2554
+ emit(:tBDOT3)
2555
+ fnext expr_beg; fbreak;
2556
+ end
2557
+ };
2558
+
2529
2559
  c_space* %{ tm = p } ('.' | '&.')
2530
2560
  => { p = tm - 1; fgoto expr_end; };
2531
2561
 
@@ -5,7 +5,7 @@ require "parser/meta"
5
5
  module Parser
6
6
  # Parser metadata
7
7
  module Meta
8
- NEXT_NODE_TYPES = (NODE_TYPES + %i[meth_ref ipair]).to_set.freeze
8
+ NEXT_NODE_TYPES = (NODE_TYPES + %i[meth_ref]).to_set.freeze
9
9
 
10
10
  remove_const(:NODE_TYPES)
11
11
  const_set(:NODE_TYPES, NEXT_NODE_TYPES)
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Parser
4
- NEXT_VERSION = "3.0.1.0"
4
+ NEXT_VERSION = "3.1.0.0"
5
5
  end