parser 2.6.0.0 → 2.7.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/.gitignore +1 -0
- data/.travis.yml +11 -11
- data/CHANGELOG.md +88 -0
- data/README.md +7 -0
- data/Rakefile +1 -0
- data/doc/AST_FORMAT.md +410 -3
- data/lib/parser/all.rb +1 -0
- data/lib/parser/ast/processor.rb +39 -1
- data/lib/parser/base.rb +23 -1
- data/lib/parser/builders/default.rb +312 -15
- data/lib/parser/context.rb +12 -0
- data/lib/parser/current.rb +15 -6
- data/lib/parser/current_arg_stack.rb +43 -0
- data/lib/parser/lexer/dedenter.rb +48 -49
- data/lib/parser/lexer.rb +11934 -11278
- data/lib/parser/lexer.rl +207 -58
- data/lib/parser/macruby.rb +1509 -1507
- data/lib/parser/macruby.y +1 -1
- data/lib/parser/max_numparam_stack.rb +48 -0
- data/lib/parser/messages.rb +55 -44
- data/lib/parser/meta.rb +9 -1
- data/lib/parser/ruby18.rb +1255 -1248
- data/lib/parser/ruby18.y +1 -1
- data/lib/parser/ruby19.rb +1645 -1638
- data/lib/parser/ruby19.y +1 -1
- data/lib/parser/ruby20.rb +1766 -1767
- data/lib/parser/ruby20.y +1 -1
- data/lib/parser/ruby21.rb +1654 -1656
- data/lib/parser/ruby21.y +1 -1
- data/lib/parser/ruby22.rb +1772 -1767
- data/lib/parser/ruby22.y +1 -1
- data/lib/parser/ruby23.rb +1088 -1092
- data/lib/parser/ruby23.y +1 -1
- data/lib/parser/ruby24.rb +1837 -1843
- data/lib/parser/ruby24.y +1 -1
- data/lib/parser/ruby25.rb +1750 -1755
- data/lib/parser/ruby25.y +2 -2
- data/lib/parser/ruby26.rb +1748 -1752
- data/lib/parser/ruby26.y +2 -2
- data/lib/parser/ruby27.rb +7749 -0
- data/lib/parser/ruby27.y +2923 -0
- data/lib/parser/rubymotion.rb +1492 -1497
- data/lib/parser/rubymotion.y +1 -1
- data/lib/parser/runner/ruby_parse.rb +2 -2
- data/lib/parser/runner.rb +5 -0
- data/lib/parser/source/tree_rewriter.rb +2 -2
- data/lib/parser/static_environment.rb +10 -0
- data/lib/parser/tree_rewriter.rb +2 -1
- data/lib/parser/variables_stack.rb +32 -0
- data/lib/parser/version.rb +1 -1
- data/lib/parser.rb +3 -0
- data/parser.gemspec +3 -2
- data/test/helper.rb +8 -0
- data/test/parse_helper.rb +2 -1
- data/test/test_current.rb +2 -0
- data/test/test_lexer.rb +72 -7
- data/test/test_parser.rb +2218 -8
- data/test/test_runner_parse.rb +35 -0
- metadata +20 -8
data/lib/parser/lexer.rl
CHANGED
|
@@ -95,13 +95,14 @@ class Parser::Lexer
|
|
|
95
95
|
attr_accessor :static_env
|
|
96
96
|
attr_accessor :force_utf32
|
|
97
97
|
|
|
98
|
-
attr_accessor :cond, :cmdarg, :in_kwarg
|
|
98
|
+
attr_accessor :cond, :cmdarg, :in_kwarg, :context, :command_start
|
|
99
99
|
|
|
100
100
|
attr_accessor :tokens, :comments
|
|
101
101
|
|
|
102
102
|
def initialize(version)
|
|
103
103
|
@version = version
|
|
104
104
|
@static_env = nil
|
|
105
|
+
@context = nil
|
|
105
106
|
|
|
106
107
|
@tokens = nil
|
|
107
108
|
@comments = nil
|
|
@@ -168,7 +169,7 @@ class Parser::Lexer
|
|
|
168
169
|
# If the lexer is in `command state' (aka expr_value)
|
|
169
170
|
# at the entry to #advance, it will transition to expr_cmdarg
|
|
170
171
|
# instead of expr_arg at certain points.
|
|
171
|
-
@
|
|
172
|
+
@command_start = true
|
|
172
173
|
|
|
173
174
|
# True at the end of "def foo a:"
|
|
174
175
|
@in_kwarg = false
|
|
@@ -276,8 +277,8 @@ class Parser::Lexer
|
|
|
276
277
|
pe = @source_pts.size + 2
|
|
277
278
|
p, eof = @p, pe
|
|
278
279
|
|
|
279
|
-
|
|
280
|
-
|
|
280
|
+
cmd_state = @command_start
|
|
281
|
+
@command_start = false
|
|
281
282
|
|
|
282
283
|
%% write exec;
|
|
283
284
|
# %
|
|
@@ -347,8 +348,8 @@ class Parser::Lexer
|
|
|
347
348
|
end
|
|
348
349
|
end
|
|
349
350
|
|
|
350
|
-
def arg_or_cmdarg
|
|
351
|
-
if
|
|
351
|
+
def arg_or_cmdarg(cmd_state)
|
|
352
|
+
if cmd_state
|
|
352
353
|
self.class.lex_en_expr_cmdarg
|
|
353
354
|
else
|
|
354
355
|
self.class.lex_en_expr_arg
|
|
@@ -704,6 +705,14 @@ class Parser::Lexer
|
|
|
704
705
|
diagnostic :fatal, :invalid_escape
|
|
705
706
|
}
|
|
706
707
|
|
|
708
|
+
action read_post_meta_or_ctrl_char {
|
|
709
|
+
@escape = @source_buffer.slice(p - 1).chr
|
|
710
|
+
|
|
711
|
+
if @version >= 27 && ((0..8).include?(@escape.ord) || (14..31).include?(@escape.ord))
|
|
712
|
+
diagnostic :fatal, :invalid_escape
|
|
713
|
+
end
|
|
714
|
+
}
|
|
715
|
+
|
|
707
716
|
action slash_c_char {
|
|
708
717
|
@escape = encode_escape(@escape[0].ord & 0x9f)
|
|
709
718
|
}
|
|
@@ -714,13 +723,13 @@ class Parser::Lexer
|
|
|
714
723
|
|
|
715
724
|
maybe_escaped_char = (
|
|
716
725
|
'\\' c_any %unescape_char
|
|
717
|
-
| ( c_any - [\\] ) %
|
|
726
|
+
| ( c_any - [\\] ) %read_post_meta_or_ctrl_char
|
|
718
727
|
);
|
|
719
728
|
|
|
720
729
|
maybe_escaped_ctrl_char = ( # why?!
|
|
721
730
|
'\\' c_any %unescape_char %slash_c_char
|
|
722
731
|
| '?' % { @escape = "\x7f" }
|
|
723
|
-
| ( c_any - [\\?] ) %
|
|
732
|
+
| ( c_any - [\\?] ) %read_post_meta_or_ctrl_char %slash_c_char
|
|
724
733
|
);
|
|
725
734
|
|
|
726
735
|
escape = (
|
|
@@ -1010,6 +1019,20 @@ class Parser::Lexer
|
|
|
1010
1019
|
fcall expr_variable;
|
|
1011
1020
|
}
|
|
1012
1021
|
|
|
1022
|
+
# Special case for Ruby > 2.7
|
|
1023
|
+
# If interpolated instance/class variable starts with a digit we parse it as a plain substring
|
|
1024
|
+
# However, "#$1" is still a regular interpolation
|
|
1025
|
+
interp_digit_var = '#' ('@' | '@@') digit c_alpha*;
|
|
1026
|
+
|
|
1027
|
+
action extend_interp_digit_var {
|
|
1028
|
+
if @version >= 27
|
|
1029
|
+
literal.extend_string(tok, @ts, @te)
|
|
1030
|
+
else
|
|
1031
|
+
message = tok.start_with?('#@@') ? :cvar_name : :ivar_name
|
|
1032
|
+
diagnostic :error, message, { :name => tok(@ts + 1, @te) }, range(@ts + 1, @te)
|
|
1033
|
+
end
|
|
1034
|
+
}
|
|
1035
|
+
|
|
1013
1036
|
# Interpolations with code blocks must match nested curly braces, as
|
|
1014
1037
|
# interpolation ending is ambiguous with a block ending. So, every
|
|
1015
1038
|
# opening and closing brace should be matched with e_[lr]brace rules,
|
|
@@ -1039,13 +1062,9 @@ class Parser::Lexer
|
|
|
1039
1062
|
if current_literal.end_interp_brace_and_try_closing
|
|
1040
1063
|
if version?(18, 19)
|
|
1041
1064
|
emit(:tRCURLY, '}'.freeze, p - 1, p)
|
|
1042
|
-
|
|
1043
|
-
|
|
1044
|
-
|
|
1045
|
-
else
|
|
1046
|
-
@cond.pop
|
|
1047
|
-
@cmdarg.pop
|
|
1048
|
-
end
|
|
1065
|
+
@cond.lexpop
|
|
1066
|
+
@cmdarg.lexpop
|
|
1067
|
+
@paren_nest -= 1
|
|
1049
1068
|
else
|
|
1050
1069
|
emit(:tSTRING_DEND, '}'.freeze, p - 1, p)
|
|
1051
1070
|
end
|
|
@@ -1075,6 +1094,7 @@ class Parser::Lexer
|
|
|
1075
1094
|
end
|
|
1076
1095
|
|
|
1077
1096
|
current_literal.start_interp_brace
|
|
1097
|
+
@command_start = true
|
|
1078
1098
|
fnext expr_value;
|
|
1079
1099
|
fbreak;
|
|
1080
1100
|
}
|
|
@@ -1083,60 +1103,64 @@ class Parser::Lexer
|
|
|
1083
1103
|
# above.
|
|
1084
1104
|
|
|
1085
1105
|
interp_words := |*
|
|
1086
|
-
interp_code
|
|
1087
|
-
|
|
1088
|
-
|
|
1089
|
-
|
|
1090
|
-
|
|
1091
|
-
|
|
1106
|
+
interp_code => extend_interp_code;
|
|
1107
|
+
interp_digit_var => extend_interp_digit_var;
|
|
1108
|
+
interp_var => extend_interp_var;
|
|
1109
|
+
e_bs escape => extend_string_escaped;
|
|
1110
|
+
c_space+ => extend_string_space;
|
|
1111
|
+
c_eol => extend_string_eol;
|
|
1112
|
+
c_any => extend_string;
|
|
1092
1113
|
*|;
|
|
1093
1114
|
|
|
1094
1115
|
interp_string := |*
|
|
1095
|
-
interp_code
|
|
1096
|
-
|
|
1097
|
-
|
|
1098
|
-
|
|
1099
|
-
|
|
1116
|
+
interp_code => extend_interp_code;
|
|
1117
|
+
interp_digit_var => extend_interp_digit_var;
|
|
1118
|
+
interp_var => extend_interp_var;
|
|
1119
|
+
e_bs escape => extend_string_escaped;
|
|
1120
|
+
c_eol => extend_string_eol;
|
|
1121
|
+
c_any => extend_string;
|
|
1100
1122
|
*|;
|
|
1101
1123
|
|
|
1102
1124
|
plain_words := |*
|
|
1103
|
-
e_bs c_any
|
|
1104
|
-
c_space+
|
|
1105
|
-
c_eol
|
|
1106
|
-
c_any
|
|
1125
|
+
e_bs c_any => extend_string_escaped;
|
|
1126
|
+
c_space+ => extend_string_space;
|
|
1127
|
+
c_eol => extend_string_eol;
|
|
1128
|
+
c_any => extend_string;
|
|
1107
1129
|
*|;
|
|
1108
1130
|
|
|
1109
1131
|
plain_string := |*
|
|
1110
|
-
'\\' c_nl
|
|
1111
|
-
e_bs c_any
|
|
1112
|
-
c_eol
|
|
1113
|
-
c_any
|
|
1132
|
+
'\\' c_nl => extend_string_eol;
|
|
1133
|
+
e_bs c_any => extend_string_escaped;
|
|
1134
|
+
c_eol => extend_string_eol;
|
|
1135
|
+
c_any => extend_string;
|
|
1114
1136
|
*|;
|
|
1115
1137
|
|
|
1116
1138
|
interp_backslash_delimited := |*
|
|
1117
|
-
interp_code
|
|
1118
|
-
|
|
1119
|
-
|
|
1120
|
-
|
|
1139
|
+
interp_code => extend_interp_code;
|
|
1140
|
+
interp_digit_var => extend_interp_digit_var;
|
|
1141
|
+
interp_var => extend_interp_var;
|
|
1142
|
+
c_eol => extend_string_eol;
|
|
1143
|
+
c_any => extend_string;
|
|
1121
1144
|
*|;
|
|
1122
1145
|
|
|
1123
1146
|
plain_backslash_delimited := |*
|
|
1124
|
-
c_eol
|
|
1125
|
-
c_any
|
|
1147
|
+
c_eol => extend_string_eol;
|
|
1148
|
+
c_any => extend_string;
|
|
1126
1149
|
*|;
|
|
1127
1150
|
|
|
1128
1151
|
interp_backslash_delimited_words := |*
|
|
1129
|
-
interp_code
|
|
1130
|
-
|
|
1131
|
-
|
|
1132
|
-
|
|
1133
|
-
|
|
1152
|
+
interp_code => extend_interp_code;
|
|
1153
|
+
interp_digit_var => extend_interp_digit_var;
|
|
1154
|
+
interp_var => extend_interp_var;
|
|
1155
|
+
c_space+ => extend_string_space;
|
|
1156
|
+
c_eol => extend_string_eol;
|
|
1157
|
+
c_any => extend_string;
|
|
1134
1158
|
*|;
|
|
1135
1159
|
|
|
1136
1160
|
plain_backslash_delimited_words := |*
|
|
1137
|
-
c_space+
|
|
1138
|
-
c_eol
|
|
1139
|
-
c_any
|
|
1161
|
+
c_space+ => extend_string_space;
|
|
1162
|
+
c_eol => extend_string_eol;
|
|
1163
|
+
c_any => extend_string;
|
|
1140
1164
|
*|;
|
|
1141
1165
|
|
|
1142
1166
|
regexp_modifiers := |*
|
|
@@ -1252,6 +1276,12 @@ class Parser::Lexer
|
|
|
1252
1276
|
|
|
1253
1277
|
e_lbrack = '[' % {
|
|
1254
1278
|
@cond.push(false); @cmdarg.push(false)
|
|
1279
|
+
|
|
1280
|
+
@paren_nest += 1
|
|
1281
|
+
};
|
|
1282
|
+
|
|
1283
|
+
e_rbrack = ']' % {
|
|
1284
|
+
@paren_nest -= 1
|
|
1255
1285
|
};
|
|
1256
1286
|
|
|
1257
1287
|
# Ruby 1.9 lambdas require parentheses counting in order to
|
|
@@ -1261,6 +1291,10 @@ class Parser::Lexer
|
|
|
1261
1291
|
@cond.push(false); @cmdarg.push(false)
|
|
1262
1292
|
|
|
1263
1293
|
@paren_nest += 1
|
|
1294
|
+
|
|
1295
|
+
if version?(18)
|
|
1296
|
+
@command_start = true
|
|
1297
|
+
end
|
|
1264
1298
|
};
|
|
1265
1299
|
|
|
1266
1300
|
e_rparen = ')' % {
|
|
@@ -1274,7 +1308,7 @@ class Parser::Lexer
|
|
|
1274
1308
|
if !@static_env.nil? && @static_env.declared?(tok)
|
|
1275
1309
|
fnext expr_endfn; fbreak;
|
|
1276
1310
|
else
|
|
1277
|
-
fnext *arg_or_cmdarg; fbreak;
|
|
1311
|
+
fnext *arg_or_cmdarg(cmd_state); fbreak;
|
|
1278
1312
|
end
|
|
1279
1313
|
}
|
|
1280
1314
|
|
|
@@ -1401,15 +1435,15 @@ class Parser::Lexer
|
|
|
1401
1435
|
expr_dot := |*
|
|
1402
1436
|
constant
|
|
1403
1437
|
=> { emit(:tCONSTANT)
|
|
1404
|
-
fnext *arg_or_cmdarg; fbreak; };
|
|
1438
|
+
fnext *arg_or_cmdarg(cmd_state); fbreak; };
|
|
1405
1439
|
|
|
1406
1440
|
call_or_var
|
|
1407
1441
|
=> { emit(:tIDENTIFIER)
|
|
1408
|
-
fnext *arg_or_cmdarg; fbreak; };
|
|
1442
|
+
fnext *arg_or_cmdarg(cmd_state); fbreak; };
|
|
1409
1443
|
|
|
1410
1444
|
bareword ambiguous_fid_suffix
|
|
1411
1445
|
=> { emit(:tFID, tok(@ts, tm), @ts, tm)
|
|
1412
|
-
fnext *arg_or_cmdarg; p = tm - 1; fbreak; };
|
|
1446
|
+
fnext *arg_or_cmdarg(cmd_state); p = tm - 1; fbreak; };
|
|
1413
1447
|
|
|
1414
1448
|
# See the comment in `expr_fname`.
|
|
1415
1449
|
operator_fname |
|
|
@@ -1469,6 +1503,8 @@ class Parser::Lexer
|
|
|
1469
1503
|
else
|
|
1470
1504
|
emit(:tLCURLY, '{'.freeze, @te - 1, @te)
|
|
1471
1505
|
end
|
|
1506
|
+
@command_start = true
|
|
1507
|
+
@paren_nest += 1
|
|
1472
1508
|
fnext expr_value; fbreak;
|
|
1473
1509
|
};
|
|
1474
1510
|
|
|
@@ -1629,6 +1665,8 @@ class Parser::Lexer
|
|
|
1629
1665
|
else
|
|
1630
1666
|
emit(:tLBRACE_ARG, '{'.freeze)
|
|
1631
1667
|
end
|
|
1668
|
+
@paren_nest += 1
|
|
1669
|
+
@command_start = true
|
|
1632
1670
|
fnext expr_value; fbreak;
|
|
1633
1671
|
};
|
|
1634
1672
|
|
|
@@ -1737,7 +1775,11 @@ class Parser::Lexer
|
|
|
1737
1775
|
type = $3.empty? ? '<<"'.freeze : ('<<'.freeze + $3)
|
|
1738
1776
|
delimiter = $4
|
|
1739
1777
|
|
|
1740
|
-
if @version >=
|
|
1778
|
+
if @version >= 27
|
|
1779
|
+
if delimiter.count("\n") > 0 || delimiter.count("\r") > 0
|
|
1780
|
+
diagnostic :error, :unterminated_heredoc_id, nil, range(@ts, @ts + 1)
|
|
1781
|
+
end
|
|
1782
|
+
elsif @version >= 24
|
|
1741
1783
|
if delimiter.count("\n") > 0
|
|
1742
1784
|
if delimiter.end_with?("\n")
|
|
1743
1785
|
diagnostic :warning, :heredoc_id_ends_with_nl, nil, range(@ts, @ts + 1)
|
|
@@ -1760,6 +1802,21 @@ class Parser::Lexer
|
|
|
1760
1802
|
end
|
|
1761
1803
|
};
|
|
1762
1804
|
|
|
1805
|
+
# Escaped unterminated heredoc start
|
|
1806
|
+
# <<'END | <<"END | <<`END |
|
|
1807
|
+
# <<-'END | <<-"END | <<-`END |
|
|
1808
|
+
# <<~'END | <<~"END | <<~`END
|
|
1809
|
+
#
|
|
1810
|
+
# If the heredoc is terminated the rule above should handle it
|
|
1811
|
+
'<<' [~\-]?
|
|
1812
|
+
('"' (any - c_nl - '"')*
|
|
1813
|
+
|"'" (any - c_nl - "'")*
|
|
1814
|
+
|"`" (any - c_nl - "`")
|
|
1815
|
+
)
|
|
1816
|
+
=> {
|
|
1817
|
+
diagnostic :error, :unterminated_heredoc_id, nil, range(@ts, @ts + 1)
|
|
1818
|
+
};
|
|
1819
|
+
|
|
1763
1820
|
#
|
|
1764
1821
|
# SYMBOL LITERALS
|
|
1765
1822
|
#
|
|
@@ -1800,6 +1857,20 @@ class Parser::Lexer
|
|
|
1800
1857
|
fnext expr_end; fbreak;
|
|
1801
1858
|
};
|
|
1802
1859
|
|
|
1860
|
+
':' ( '@' %{ tm = p - 1; diag_msg = :ivar_name }
|
|
1861
|
+
| '@@' %{ tm = p - 2; diag_msg = :cvar_name }
|
|
1862
|
+
) [0-9]*
|
|
1863
|
+
=> {
|
|
1864
|
+
if @version >= 27
|
|
1865
|
+
diagnostic :error, diag_msg, { name: tok(tm, @te) }, range(tm, @te)
|
|
1866
|
+
else
|
|
1867
|
+
emit(:tCOLON, tok(@ts, @ts + 1), @ts, @ts + 1)
|
|
1868
|
+
p = @ts
|
|
1869
|
+
end
|
|
1870
|
+
|
|
1871
|
+
fnext expr_end; fbreak;
|
|
1872
|
+
};
|
|
1873
|
+
|
|
1803
1874
|
#
|
|
1804
1875
|
# AMBIGUOUS TERNARY OPERATOR
|
|
1805
1876
|
#
|
|
@@ -1843,6 +1914,24 @@ class Parser::Lexer
|
|
|
1843
1914
|
fgoto expr_end;
|
|
1844
1915
|
};
|
|
1845
1916
|
|
|
1917
|
+
#
|
|
1918
|
+
# AMBIGUOUS EMPTY BLOCK ARGUMENTS
|
|
1919
|
+
#
|
|
1920
|
+
|
|
1921
|
+
# Ruby >= 2.7 emits it as two tPIPE terminals
|
|
1922
|
+
# while Ruby < 2.7 as a single tOROP (like in `a || b`)
|
|
1923
|
+
'||'
|
|
1924
|
+
=> {
|
|
1925
|
+
if @version >= 27
|
|
1926
|
+
emit(:tPIPE, tok(@ts, @ts + 1), @ts, @ts + 1)
|
|
1927
|
+
fhold;
|
|
1928
|
+
fnext expr_beg; fbreak;
|
|
1929
|
+
else
|
|
1930
|
+
p -= 2
|
|
1931
|
+
fgoto expr_end;
|
|
1932
|
+
end
|
|
1933
|
+
};
|
|
1934
|
+
|
|
1846
1935
|
#
|
|
1847
1936
|
# KEYWORDS AND PUNCTUATION
|
|
1848
1937
|
#
|
|
@@ -1852,10 +1941,12 @@ class Parser::Lexer
|
|
|
1852
1941
|
=> {
|
|
1853
1942
|
if @lambda_stack.last == @paren_nest
|
|
1854
1943
|
@lambda_stack.pop
|
|
1944
|
+
@command_start = true
|
|
1855
1945
|
emit(:tLAMBEG, '{'.freeze)
|
|
1856
1946
|
else
|
|
1857
1947
|
emit(:tLBRACE, '{'.freeze)
|
|
1858
1948
|
end
|
|
1949
|
+
@paren_nest += 1
|
|
1859
1950
|
fbreak;
|
|
1860
1951
|
};
|
|
1861
1952
|
|
|
@@ -1884,6 +1975,7 @@ class Parser::Lexer
|
|
|
1884
1975
|
# if a: Statement if.
|
|
1885
1976
|
keyword_modifier
|
|
1886
1977
|
=> { emit_table(KEYWORDS_BEGIN)
|
|
1978
|
+
@command_start = true
|
|
1887
1979
|
fnext expr_value; fbreak; };
|
|
1888
1980
|
|
|
1889
1981
|
#
|
|
@@ -1904,7 +1996,7 @@ class Parser::Lexer
|
|
|
1904
1996
|
if !@static_env.nil? && @static_env.declared?(ident)
|
|
1905
1997
|
fnext expr_end;
|
|
1906
1998
|
else
|
|
1907
|
-
fnext *arg_or_cmdarg;
|
|
1999
|
+
fnext *arg_or_cmdarg(cmd_state);
|
|
1908
2000
|
end
|
|
1909
2001
|
else
|
|
1910
2002
|
emit(:tLABEL, tok(@ts, @te - 2), @ts, @te - 1)
|
|
@@ -1914,6 +2006,31 @@ class Parser::Lexer
|
|
|
1914
2006
|
fbreak;
|
|
1915
2007
|
};
|
|
1916
2008
|
|
|
2009
|
+
#
|
|
2010
|
+
# RUBY 2.7 BEGINLESS RANGE
|
|
2011
|
+
|
|
2012
|
+
'..'
|
|
2013
|
+
=> {
|
|
2014
|
+
if @version >= 27
|
|
2015
|
+
emit(:tBDOT2)
|
|
2016
|
+
else
|
|
2017
|
+
emit(:tDOT2)
|
|
2018
|
+
end
|
|
2019
|
+
|
|
2020
|
+
fnext expr_beg; fbreak;
|
|
2021
|
+
};
|
|
2022
|
+
|
|
2023
|
+
'...'
|
|
2024
|
+
=> {
|
|
2025
|
+
if @version >= 27
|
|
2026
|
+
emit(:tBDOT3)
|
|
2027
|
+
else
|
|
2028
|
+
emit(:tDOT3)
|
|
2029
|
+
end
|
|
2030
|
+
|
|
2031
|
+
fnext expr_beg; fbreak;
|
|
2032
|
+
};
|
|
2033
|
+
|
|
1917
2034
|
#
|
|
1918
2035
|
# CONTEXT-DEPENDENT VARIABLE LOOKUP OR COMMAND INVOCATION
|
|
1919
2036
|
#
|
|
@@ -2048,6 +2165,7 @@ class Parser::Lexer
|
|
|
2048
2165
|
emit_do
|
|
2049
2166
|
end
|
|
2050
2167
|
end
|
|
2168
|
+
@command_start = true
|
|
2051
2169
|
|
|
2052
2170
|
fnext expr_value; fbreak;
|
|
2053
2171
|
};
|
|
@@ -2073,6 +2191,7 @@ class Parser::Lexer
|
|
|
2073
2191
|
# elsif b:c: elsif b(:c)
|
|
2074
2192
|
keyword_with_value
|
|
2075
2193
|
=> { emit_table(KEYWORDS)
|
|
2194
|
+
@command_start = true
|
|
2076
2195
|
fnext expr_value; fbreak; };
|
|
2077
2196
|
|
|
2078
2197
|
keyword_with_mid
|
|
@@ -2096,7 +2215,7 @@ class Parser::Lexer
|
|
|
2096
2215
|
emit(:tIDENTIFIER)
|
|
2097
2216
|
|
|
2098
2217
|
unless !@static_env.nil? && @static_env.declared?(tok)
|
|
2099
|
-
fnext *arg_or_cmdarg;
|
|
2218
|
+
fnext *arg_or_cmdarg(cmd_state);
|
|
2100
2219
|
end
|
|
2101
2220
|
else
|
|
2102
2221
|
emit(:k__ENCODING__, '__ENCODING__'.freeze)
|
|
@@ -2207,7 +2326,7 @@ class Parser::Lexer
|
|
|
2207
2326
|
|
|
2208
2327
|
constant
|
|
2209
2328
|
=> { emit(:tCONSTANT)
|
|
2210
|
-
fnext *arg_or_cmdarg; fbreak; };
|
|
2329
|
+
fnext *arg_or_cmdarg(cmd_state); fbreak; };
|
|
2211
2330
|
|
|
2212
2331
|
constant ambiguous_const_suffix
|
|
2213
2332
|
=> { emit(:tCONSTANT, tok(@ts, tm), @ts, tm)
|
|
@@ -2263,7 +2382,7 @@ class Parser::Lexer
|
|
|
2263
2382
|
=> { emit_table(PUNCTUATION)
|
|
2264
2383
|
fnext expr_beg; fbreak; };
|
|
2265
2384
|
|
|
2266
|
-
e_rbrace | e_rparen |
|
|
2385
|
+
e_rbrace | e_rparen | e_rbrack
|
|
2267
2386
|
=> {
|
|
2268
2387
|
emit_table(PUNCTUATION)
|
|
2269
2388
|
|
|
@@ -2300,6 +2419,17 @@ class Parser::Lexer
|
|
|
2300
2419
|
=> { emit(:tLBRACK2, '['.freeze)
|
|
2301
2420
|
fnext expr_beg; fbreak; };
|
|
2302
2421
|
|
|
2422
|
+
'...' c_nl
|
|
2423
|
+
=> {
|
|
2424
|
+
if @paren_nest == 0
|
|
2425
|
+
diagnostic :warning, :triple_dot_at_eol, nil, range(@ts, @te - 1)
|
|
2426
|
+
end
|
|
2427
|
+
|
|
2428
|
+
emit(:tDOT3, '...'.freeze, @ts, @te - 1)
|
|
2429
|
+
fhold;
|
|
2430
|
+
fnext expr_beg; fbreak;
|
|
2431
|
+
};
|
|
2432
|
+
|
|
2303
2433
|
punctuation_end
|
|
2304
2434
|
=> { emit_table(PUNCTUATION)
|
|
2305
2435
|
fnext expr_beg; fbreak; };
|
|
@@ -2315,6 +2445,7 @@ class Parser::Lexer
|
|
|
2315
2445
|
|
|
2316
2446
|
';'
|
|
2317
2447
|
=> { emit(:tSEMI, ';'.freeze)
|
|
2448
|
+
@command_start = true
|
|
2318
2449
|
fnext expr_value; fbreak; };
|
|
2319
2450
|
|
|
2320
2451
|
'\\' c_line {
|
|
@@ -2333,7 +2464,25 @@ class Parser::Lexer
|
|
|
2333
2464
|
leading_dot := |*
|
|
2334
2465
|
# Insane leading dots:
|
|
2335
2466
|
# a #comment
|
|
2467
|
+
# # post-2.7 comment
|
|
2336
2468
|
# .b: a.b
|
|
2469
|
+
|
|
2470
|
+
# Here we use '\n' instead of w_newline to not modify @newline_s
|
|
2471
|
+
# and eventually properly emit tNL
|
|
2472
|
+
(w_space_comment '\n')+
|
|
2473
|
+
=> {
|
|
2474
|
+
if @version < 27
|
|
2475
|
+
# Ruby before 2.7 doesn't support comments before leading dot.
|
|
2476
|
+
# If a line after "a" starts with a comment then "a" is a self-contained statement.
|
|
2477
|
+
# So in that case we emit a special tNL token and start reading the
|
|
2478
|
+
# next line as a separate statement.
|
|
2479
|
+
#
|
|
2480
|
+
# Note: block comments before leading dot are not supported on any version of Ruby.
|
|
2481
|
+
emit(:tNL, nil, @newline_s, @newline_s + 1)
|
|
2482
|
+
fhold; fnext line_begin; fbreak;
|
|
2483
|
+
end
|
|
2484
|
+
};
|
|
2485
|
+
|
|
2337
2486
|
c_space* %{ tm = p } ('.' | '&.')
|
|
2338
2487
|
=> { p = tm - 1; fgoto expr_end; };
|
|
2339
2488
|
|
|
@@ -2373,7 +2522,7 @@ class Parser::Lexer
|
|
|
2373
2522
|
=> { p = pe - 3 };
|
|
2374
2523
|
|
|
2375
2524
|
c_any
|
|
2376
|
-
=> { fhold; fgoto expr_value; };
|
|
2525
|
+
=> { cmd_state = true; fhold; fgoto expr_value; };
|
|
2377
2526
|
|
|
2378
2527
|
c_eof => do_eof;
|
|
2379
2528
|
*|;
|