ruby-next-parser 3.0.0.1 → 3.1.0.0
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.
- checksums.yaml +4 -4
- data/lib/parser/ruby-next/AST_FORMAT.md +0 -24
- data/lib/parser/ruby-next/ast/processor.rb +0 -4
- data/lib/parser/ruby-next/builder.rb +0 -4
- data/lib/parser/ruby-next/lexer.rb +12288 -11352
- data/lib/parser/ruby-next/lexer.rl +44 -8
- data/lib/parser/ruby-next/meta.rb +1 -1
- data/lib/parser/ruby-next/version.rb +1 -1
- data/lib/parser/rubynext.rb +4110 -3931
- data/lib/parser/rubynext.y +207 -92
- metadata +10 -10
@@ -100,6 +100,8 @@ class Next
|
|
100
100
|
|
101
101
|
attr_accessor :tokens, :comments
|
102
102
|
|
103
|
+
attr_reader :paren_nest, :cmdarg_stack, :cond_stack, :lambda_stack
|
104
|
+
|
103
105
|
def initialize(version)
|
104
106
|
@version = version
|
105
107
|
@static_env = nil
|
@@ -517,7 +519,8 @@ class Next
|
|
517
519
|
c_nl_zlen = c_nl | zlen;
|
518
520
|
c_line = any - c_nl_zlen;
|
519
521
|
|
520
|
-
|
522
|
+
c_ascii = 0x00..0x7f;
|
523
|
+
c_unicode = c_any - c_ascii;
|
521
524
|
c_upper = [A-Z];
|
522
525
|
c_lower = [a-z_] | c_unicode;
|
523
526
|
c_alpha = c_lower | c_upper;
|
@@ -704,6 +707,11 @@ class Next
|
|
704
707
|
|
705
708
|
action unescape_char {
|
706
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
|
+
|
707
715
|
if (@escape = ESCAPES[codepoint]).nil?
|
708
716
|
@escape = encode_escape(@source_buffer.slice(p - 1))
|
709
717
|
end
|
@@ -731,12 +739,14 @@ class Next
|
|
731
739
|
|
732
740
|
maybe_escaped_char = (
|
733
741
|
'\\' c_any %unescape_char
|
742
|
+
| '\\x' xdigit{1,2} % { @escape = encode_escape(tok(p - 2, p).to_i(16)) } %slash_c_char
|
734
743
|
| ( c_any - [\\] ) %read_post_meta_or_ctrl_char
|
735
744
|
);
|
736
745
|
|
737
746
|
maybe_escaped_ctrl_char = ( # why?!
|
738
747
|
'\\' c_any %unescape_char %slash_c_char
|
739
748
|
| '?' % { @escape = "\x7f" }
|
749
|
+
| '\\x' xdigit{1,2} % { @escape = encode_escape(tok(p - 2, p).to_i(16)) } %slash_c_char
|
740
750
|
| ( c_any - [\\?] ) %read_post_meta_or_ctrl_char %slash_c_char
|
741
751
|
);
|
742
752
|
|
@@ -928,7 +938,7 @@ class Next
|
|
928
938
|
# b"
|
929
939
|
# must be parsed as "ab"
|
930
940
|
current_literal.extend_string(tok.gsub("\\\n".freeze, ''.freeze), @ts, @te)
|
931
|
-
elsif current_literal.regexp?
|
941
|
+
elsif current_literal.regexp? && @version < 31
|
932
942
|
# Regular expressions should include escape sequences in their
|
933
943
|
# escaped form. On the other hand, escaped newlines are removed (in cases like "\\C-\\\n\\M-x")
|
934
944
|
current_literal.extend_string(tok.gsub("\\\n".freeze, ''.freeze), @ts, @te)
|
@@ -1400,7 +1410,7 @@ class Next
|
|
1400
1410
|
':'
|
1401
1411
|
=> { fhold; fgoto expr_beg; };
|
1402
1412
|
|
1403
|
-
'%s'
|
1413
|
+
'%s' (c_ascii - [A-Za-z0-9])
|
1404
1414
|
=> {
|
1405
1415
|
if version?(23)
|
1406
1416
|
type, delimiter = tok[0..-2], tok[-1].chr
|
@@ -1545,7 +1555,11 @@ class Next
|
|
1545
1555
|
=> {
|
1546
1556
|
if tok(tm, tm + 1) == '/'.freeze
|
1547
1557
|
# Ambiguous regexp literal.
|
1548
|
-
|
1558
|
+
if @version < 30
|
1559
|
+
diagnostic :warning, :ambiguous_literal, nil, range(tm, tm + 1)
|
1560
|
+
else
|
1561
|
+
diagnostic :warning, :ambiguous_regexp, nil, range(tm, tm + 1)
|
1562
|
+
end
|
1549
1563
|
end
|
1550
1564
|
|
1551
1565
|
p = tm - 1
|
@@ -1748,14 +1762,14 @@ class Next
|
|
1748
1762
|
};
|
1749
1763
|
|
1750
1764
|
# %<string>
|
1751
|
-
'%' (
|
1765
|
+
'%' ( c_ascii - [A-Za-z0-9] )
|
1752
1766
|
=> {
|
1753
1767
|
type, delimiter = @source_buffer.slice(@ts).chr, tok[-1].chr
|
1754
1768
|
fgoto *push_literal(type, delimiter, @ts);
|
1755
1769
|
};
|
1756
1770
|
|
1757
1771
|
# %w(we are the people)
|
1758
|
-
'%' [A-Za-z]
|
1772
|
+
'%' [A-Za-z] (c_ascii - [A-Za-z0-9])
|
1759
1773
|
=> {
|
1760
1774
|
type, delimiter = tok[0..-2], tok[-1].chr
|
1761
1775
|
fgoto *push_literal(type, delimiter, @ts);
|
@@ -2031,7 +2045,7 @@ class Next
|
|
2031
2045
|
|
2032
2046
|
'...'
|
2033
2047
|
=> {
|
2034
|
-
if @version >=
|
2048
|
+
if @version >= 30
|
2035
2049
|
if @lambda_stack.any? && @lambda_stack.last + 1 == @paren_nest
|
2036
2050
|
# To reject `->(...)` like `->...`
|
2037
2051
|
emit(:tDOT3)
|
@@ -2403,7 +2417,7 @@ class Next
|
|
2403
2417
|
'*' | '=>'
|
2404
2418
|
=> {
|
2405
2419
|
emit_table(PUNCTUATION)
|
2406
|
-
|
2420
|
+
fnext expr_value; fbreak;
|
2407
2421
|
};
|
2408
2422
|
|
2409
2423
|
# When '|', '~', '!', '=>' are used as operators
|
@@ -2520,6 +2534,28 @@ class Next
|
|
2520
2534
|
end
|
2521
2535
|
};
|
2522
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
|
+
|
2523
2559
|
c_space* %{ tm = p } ('.' | '&.')
|
2524
2560
|
=> { p = tm - 1; fgoto expr_end; };
|
2525
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
|
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)
|