Skip to content

Commit 1d3581e

Browse files
committed
merge revision(s) 55694ad: [Backport #21945]
[Bug #21945] Correctly handle `and?` and similar
1 parent 0d845e4 commit 1d3581e

File tree

2 files changed

+55
-0
lines changed

2 files changed

+55
-0
lines changed

parse.y

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7010,6 +7010,9 @@ peek_word_at(struct parser_params *p, const char *str, size_t len, int at)
70107010
if (lex_eol_ptr_n_p(p, ptr, len-1)) return false;
70117011
if (memcmp(ptr, str, len)) return false;
70127012
if (lex_eol_ptr_n_p(p, ptr, len)) return true;
7013+
switch (ptr[len]) {
7014+
case '!': case '?': return false;
7015+
}
70137016
return !is_identchar(p, ptr+len, p->lex.pend, p->enc);
70147017
}
70157018

test/ripper/test_lexer.rb

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -586,6 +586,58 @@ def test_spaces_at_eof
586586
assert_lexer(expected, code)
587587
end
588588

589+
def test_fluent_and
590+
code = "foo\n" "and"
591+
expected = [
592+
[[1, 0], :on_ident, "foo", state(:EXPR_CMDARG)],
593+
[[1, 3], :on_ignored_nl, "\n", state(:EXPR_CMDARG)],
594+
[[2, 0], :on_kw, "and", state(:EXPR_BEG)],
595+
]
596+
assert_lexer(expected, code)
597+
598+
code = "foo\n" "and?"
599+
expected = [
600+
[[1, 0], :on_ident, "foo", state(:EXPR_CMDARG)],
601+
[[1, 3], :on_nl, "\n", state(:EXPR_BEG)],
602+
[[2, 0], :on_ident, "and?", state(:EXPR_CMDARG)],
603+
]
604+
assert_lexer(expected, code)
605+
606+
code = "foo\n" "and!"
607+
expected = [
608+
[[1, 0], :on_ident, "foo", state(:EXPR_CMDARG)],
609+
[[1, 3], :on_nl, "\n", state(:EXPR_BEG)],
610+
[[2, 0], :on_ident, "and!", state(:EXPR_CMDARG)],
611+
]
612+
assert_lexer(expected, code)
613+
end
614+
615+
def test_fluent_or
616+
code = "foo\n" "or"
617+
expected = [
618+
[[1, 0], :on_ident, "foo", state(:EXPR_CMDARG)],
619+
[[1, 3], :on_ignored_nl, "\n", state(:EXPR_CMDARG)],
620+
[[2, 0], :on_kw, "or", state(:EXPR_BEG)],
621+
]
622+
assert_lexer(expected, code)
623+
624+
code = "foo\n" "or?"
625+
expected = [
626+
[[1, 0], :on_ident, "foo", state(:EXPR_CMDARG)],
627+
[[1, 3], :on_nl, "\n", state(:EXPR_BEG)],
628+
[[2, 0], :on_ident, "or?", state(:EXPR_CMDARG)],
629+
]
630+
assert_lexer(expected, code)
631+
632+
code = "foo\n" "or!"
633+
expected = [
634+
[[1, 0], :on_ident, "foo", state(:EXPR_CMDARG)],
635+
[[1, 3], :on_nl, "\n", state(:EXPR_BEG)],
636+
[[2, 0], :on_ident, "or!", state(:EXPR_CMDARG)],
637+
]
638+
assert_lexer(expected, code)
639+
end
640+
589641
def assert_lexer(expected, code)
590642
assert_equal(code, Ripper.tokenize(code).join(""))
591643
assert_equal(expected, result = Ripper.lex(code),

0 commit comments

Comments
 (0)