Skip to content

Commit 0685a35

Browse files
committed
Address regressions on 'not in' operator
Closes #14783.
1 parent f310ed9 commit 0685a35

File tree

3 files changed

+30
-7
lines changed

3 files changed

+30
-7
lines changed

lib/elixir/src/elixir_parser.yrl

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -751,9 +751,9 @@ build_op({UOp, _, [Left]}, {_Kind, {Line, Column, _} = Location, 'in'}, Right) w
751751
Meta = meta_from_location(Location),
752752
{UOp, Meta, [{'in', Meta, [Left, Right]}]};
753753

754-
build_op(Left, {_Kind, Location, 'not in'}, Right) ->
755-
NotMeta = meta_from_location(Location),
756-
InMeta = meta_from_location(element(3, Location)),
754+
build_op(Left, {in_op, NotLocation, 'not in', InLocation}, Right) ->
755+
NotMeta = newlines_op(NotLocation) ++ meta_from_location(NotLocation),
756+
InMeta = meta_from_location(InLocation),
757757
{'not', NotMeta, [{'in', InMeta, [Left, Right]}]};
758758

759759
build_op(Left, {_Kind, Location, Op}, Right) ->

lib/elixir/src/elixir_tokenizer.erl

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1685,12 +1685,14 @@ tokenize_keyword(Kind, Rest, Line, Column, Atom, Length, Scope, Tokens) ->
16851685
[{identifier, {Line, Column, nil}, Atom} | Tokens];
16861686

16871687
_ ->
1688+
Info = {Line, Column, previous_was_eol(Tokens)},
1689+
16881690
case {Kind, Tokens} of
1689-
{in_op, [{unary_op, {NotLine, NotColumn, _}, 'not'} | T]} ->
1690-
add_token_with_eol({in_op, {NotLine, NotColumn, {Line, Column, nil}}, 'not in'}, T);
1691+
{in_op, [{unary_op, NotInfo, 'not'} | T]} ->
1692+
add_token_with_eol({in_op, NotInfo, 'not in', Info}, T);
16911693

16921694
{_, _} ->
1693-
add_token_with_eol({Kind, {Line, Column, previous_was_eol(Tokens)}, Atom}, Tokens)
1695+
add_token_with_eol({Kind, Info, Atom}, Tokens)
16941696
end
16951697
end,
16961698

lib/elixir/test/elixir/kernel/parser_test.exs

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -489,12 +489,33 @@ defmodule Kernel.ParserTest do
489489
[{:a, [line: 1, column: 1], nil}, {:b, [line: 1, column: 10], nil}]}
490490
]}
491491

492-
assert Code.string_to_quoted!("a not in b", columns: true) ==
492+
assert Code.string_to_quoted!("a not in b", columns: true, token_metadata: true) ==
493493
{:not, [line: 1, column: 3],
494494
[
495495
{:in, [line: 1, column: 8],
496496
[{:a, [line: 1, column: 1], nil}, {:b, [line: 1, column: 11], nil}]}
497497
]}
498+
499+
assert Code.string_to_quoted!("a\nnot in b", columns: true, token_metadata: true) ==
500+
{:not, [newlines: 1, line: 2, column: 1],
501+
[
502+
{:in, [line: 2, column: 5],
503+
[{:a, [line: 1, column: 1], nil}, {:b, [line: 2, column: 8], nil}]}
504+
]}
505+
506+
assert Code.string_to_quoted!("a not in\nb", columns: true, token_metadata: true) ==
507+
{:not, [newlines: 1, line: 1, column: 3],
508+
[
509+
{:in, [line: 1, column: 7],
510+
[{:a, [line: 1, column: 1], nil}, {:b, [line: 2, column: 1], nil}]}
511+
]}
512+
513+
assert Code.string_to_quoted!("a\nnot in\nb", columns: true, token_metadata: true) ==
514+
{:not, [newlines: 1, line: 2, column: 1],
515+
[
516+
{:in, [line: 2, column: 5],
517+
[{:a, [line: 1, column: 1], nil}, {:b, [line: 3, column: 1], nil}]}
518+
]}
498519
end
499520

500521
test "handles maps and structs" do

0 commit comments

Comments
 (0)