找不到语法错误,意外的输入结束,期待 keyword_end

Can't find syntax error, unexpected end-of-input, expecting keyword_end

有人能帮我找到语法错​​误吗,它应该出现在第 78 行。此时我确信没有

#!/usr/bin/env ruby

$LOAD_PATH.unshift "lib"
require 'wordnet'
require 'pp'


print_synsets = false



lex = WordNet::Lexicon.new

puts "Hello! I'm Complainbot. To stop talking to enter \'cya\'. What would you like to complain about today?\n\n"
user_response = gets.chomp

while not user_response.include? "cya" do
    puts

    if is_command?(user_response)
        handle_commands(user_response)
    else
        establish_context(user_response)
    end

    puts

    user_response = gets.chomp
end



def establish_context(sentence)
    nouns = get_nouns(sentence)
    puts nouns
end


def get_nouns(sentence)
    words = sentence.strip.split(' ')
    nouns_in_sentence = []

    words.each do |word|
        word_synsets = lex.lookup_synsets(word)

        if print_synsets do PP.pp(word_synsets) end

        word_synsets.each do |synset|
            nouns = synset.nouns
            if not nouns.empty?
                nouns_in_sentence.append(nouns.first)
                break
            end
        end
    end
    return nouns_in_sentence
end


def is_command?(sentence)
    words = sentence.strip.split(' ')

    if words.first[0].to_s == '\' then 
        return true 
    else 
        return false
    end 
end


def handle_commands(commands)
    if commands.include? 'PRINT_SYNSETS'
        print_synsets = true
    elsif commands.include? '~PRINT_SYNSETS'
        print_synsets = false
    end
end

if Ruby 中的表达式不需要 then

if words.first[0].to_s == '\'
    return true 
else 
    return false
end 

更新 - 虽然上述是正确的,但正如@JörgWMittag 指出的那样,这不是问题的原因。实际问题出在if print_synsets do PP.pp(word_synsets) end。正如他所说,使用 then 而不是 do 将是这里的解决方法。