@@ -10829,14 +10829,37 @@ parser_lex(pm_parser_t *parser) {
10829
10829
following = next_newline(following, parser->end - following);
10830
10830
}
10831
10831
10832
- // If the lex state was ignored, or we hit a '.' or a '&.',
10833
- // we will lex the ignored newline
10832
+ // If the lex state was ignored, we will lex the
10833
+ // ignored newline.
10834
+ if (lex_state_ignored_p(parser)) {
10835
+ if (!lexed_comment) parser_lex_ignored_newline(parser);
10836
+ lexed_comment = false;
10837
+ goto lex_next_token;
10838
+ }
10839
+
10840
+ // If we hit a '.' or a '&.' we will lex the ignored
10841
+ // newline.
10842
+ if (following && (
10843
+ (peek_at(parser, following) == '.') ||
10844
+ (peek_at(parser, following) == '&' && peek_at(parser, following + 1) == '.')
10845
+ )) {
10846
+ if (!lexed_comment) parser_lex_ignored_newline(parser);
10847
+ lexed_comment = false;
10848
+ goto lex_next_token;
10849
+ }
10850
+
10851
+
10852
+ // If we are parsing as CRuby 3.5 or later and we
10853
+ // hit a '&&' or a '||' then we will lex the ignored
10854
+ // newline.
10834
10855
if (
10835
- lex_state_ignored_p(parser) ||
10836
- (following && (
10837
- (peek_at(parser, following) == '.') ||
10838
- (peek_at(parser, following) == '&' && peek_at(parser, following + 1) == '.')
10839
- ))
10856
+ (parser->version == PM_OPTIONS_VERSION_LATEST) &&
10857
+ following && (
10858
+ (peek_at(parser, following) == '&' && peek_at(parser, following + 1) == '&') ||
10859
+ (peek_at(parser, following) == '|' && peek_at(parser, following + 1) == '|') ||
10860
+ (peek_at(parser, following) == 'a' && peek_at(parser, following + 1) == 'n' && peek_at(parser, following + 2) == 'd') ||
10861
+ (peek_at(parser, following) == 'o' && peek_at(parser, following + 1) == 'r')
10862
+ )
10840
10863
) {
10841
10864
if (!lexed_comment) parser_lex_ignored_newline(parser);
10842
10865
lexed_comment = false;
@@ -10876,6 +10899,52 @@ parser_lex(pm_parser_t *parser) {
10876
10899
parser->next_start = NULL;
10877
10900
LEX(PM_TOKEN_AMPERSAND_DOT);
10878
10901
}
10902
+
10903
+ if (parser->version == PM_OPTIONS_VERSION_LATEST) {
10904
+ // If we hit an && then we are in a logical chain
10905
+ // and we need to return the logical operator.
10906
+ if (peek_at(parser, next_content) == '&' && peek_at(parser, next_content + 1) == '&') {
10907
+ if (!lexed_comment) parser_lex_ignored_newline(parser);
10908
+ lex_state_set(parser, PM_LEX_STATE_BEG);
10909
+ parser->current.start = next_content;
10910
+ parser->current.end = next_content + 2;
10911
+ parser->next_start = NULL;
10912
+ LEX(PM_TOKEN_AMPERSAND_AMPERSAND);
10913
+ }
10914
+
10915
+ // If we hit an 'and' then we are in a logical chain
10916
+ // and we need to return the logical operator.
10917
+ if (peek_at(parser, next_content) == 'a' && peek_at(parser, next_content + 1) == 'n' && peek_at(parser, next_content + 2) == 'd') {
10918
+ if (!lexed_comment) parser_lex_ignored_newline(parser);
10919
+ lex_state_set(parser, PM_LEX_STATE_BEG);
10920
+ parser->current.start = next_content;
10921
+ parser->current.end = next_content + 3;
10922
+ parser->next_start = NULL;
10923
+ LEX(PM_TOKEN_KEYWORD_AND);
10924
+ }
10925
+
10926
+ // If we hit a || then we are in a logical chain and
10927
+ // we need to return the logical operator.
10928
+ if (peek_at(parser, next_content) == '|' && peek_at(parser, next_content + 1) == '|') {
10929
+ if (!lexed_comment) parser_lex_ignored_newline(parser);
10930
+ lex_state_set(parser, PM_LEX_STATE_BEG);
10931
+ parser->current.start = next_content;
10932
+ parser->current.end = next_content + 2;
10933
+ parser->next_start = NULL;
10934
+ LEX(PM_TOKEN_PIPE_PIPE);
10935
+ }
10936
+
10937
+ // If we hit a 'or' then we are in a logical chain
10938
+ // and we need to return the logical operator.
10939
+ if (peek_at(parser, next_content) == 'o' && peek_at(parser, next_content + 1) == 'r') {
10940
+ if (!lexed_comment) parser_lex_ignored_newline(parser);
10941
+ lex_state_set(parser, PM_LEX_STATE_BEG);
10942
+ parser->current.start = next_content;
10943
+ parser->current.end = next_content + 2;
10944
+ parser->next_start = NULL;
10945
+ LEX(PM_TOKEN_KEYWORD_OR);
10946
+ }
10947
+ }
10879
10948
}
10880
10949
10881
10950
// At this point we know this is a regular newline, and we can set the
0 commit comments