From f012ce0d18b19a8dfc815498108b9b5fdde26b46 Mon Sep 17 00:00:00 2001 From: Max Prokopiev Date: Fri, 16 Feb 2024 14:43:35 +0100 Subject: [PATCH] [ruby/prism] Fix lexing of `foo!` when it's a first thing to parse https://github.com/ruby/prism/commit/7597aca76a --- lib/prism/translation/parser/lexer.rb | 2 +- .../fixtures/single_method_call_with_bang.txt | 1 + .../snapshots/single_method_call_with_bang.txt | 15 +++++++++++++++ 3 files changed, 17 insertions(+), 1 deletion(-) create mode 100644 test/prism/fixtures/single_method_call_with_bang.txt create mode 100644 test/prism/snapshots/single_method_call_with_bang.txt diff --git a/lib/prism/translation/parser/lexer.rb b/lib/prism/translation/parser/lexer.rb index 6d3321b945d965..5c993cfab8167a 100644 --- a/lib/prism/translation/parser/lexer.rb +++ b/lib/prism/translation/parser/lexer.rb @@ -289,7 +289,7 @@ def to_a index += 1 end when :tFID - if tokens[-1][0] == :kDEF + if !tokens.empty? && tokens[-1][0] == :kDEF type = :tIDENTIFIER end end diff --git a/test/prism/fixtures/single_method_call_with_bang.txt b/test/prism/fixtures/single_method_call_with_bang.txt new file mode 100644 index 00000000000000..929efb30534598 --- /dev/null +++ b/test/prism/fixtures/single_method_call_with_bang.txt @@ -0,0 +1 @@ +foo! diff --git a/test/prism/snapshots/single_method_call_with_bang.txt b/test/prism/snapshots/single_method_call_with_bang.txt new file mode 100644 index 00000000000000..4c68e0adac9e4c --- /dev/null +++ b/test/prism/snapshots/single_method_call_with_bang.txt @@ -0,0 +1,15 @@ +@ ProgramNode (location: (1,0)-(1,4)) +├── locals: [] +└── statements: + @ StatementsNode (location: (1,0)-(1,4)) + └── body: (length: 1) + └── @ CallNode (location: (1,0)-(1,4)) + ├── flags: ignore_visibility + ├── receiver: ∅ + ├── call_operator_loc: ∅ + ├── name: :foo! + ├── message_loc: (1,0)-(1,4) = "foo!" + ├── opening_loc: ∅ + ├── arguments: ∅ + ├── closing_loc: ∅ + └── block: ∅