From ec7a2fdc03cba32894e1d25606195600e152c151 Mon Sep 17 00:00:00 2001 From: Kevin Newton Date: Fri, 25 Aug 2023 08:49:28 -0400 Subject: [PATCH] [ruby/yarp] Fix up lex compat on Ruby HEAD https://github.com/ruby/yarp/commit/7710cee248 --- lib/yarp/lex_compat.rb | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/lib/yarp/lex_compat.rb b/lib/yarp/lex_compat.rb index 8b63253356..66aa116493 100644 --- a/lib/yarp/lex_compat.rb +++ b/lib/yarp/lex_compat.rb @@ -574,6 +574,11 @@ module YARP result = YARP.lex(source, @filepath) result_value = result.value previous_state = nil + + # In previous versions of Ruby, Ripper wouldn't flush the bom before the + # first token, so we had to have a hack in place to account for that. This + # checks for that behavior. + bom_flushed = Ripper.lex("\xEF\xBB\xBF# test")[0][0][1] == 0 bom = source.byteslice(0..2) == "\xEF\xBB\xBF" result_value.each_with_index do |(token, lex_state), index| @@ -588,8 +593,12 @@ module YARP if bom && lineno == 1 column -= 3 +<<<<<<< HEAD =begin if index == 0 && column == 0 +======= + if index == 0 && column == 0 && !bom_flushed +>>>>>>> 7710cee2480 (Fix up lex compat on Ruby HEAD) flushed = case token.type when :BACK_REFERENCE, :INSTANCE_VARIABLE, :CLASS_VARIABLE,