Getting syntax error: expecting token 'EOF', not 'end' and can't figure out why

Getting syntax error: expecting token 'EOF', not 'end' and can't figure out why

所以,我正在尝试实现一种方法来为我的 SQLite3 数据库添加没有 ORM/ODM 的数据库迁移,我得到的错误 (syntax error: expecting token 'EOF', not 'end') 是针对此代码的:

src/project/database/migration/migrations/1.cr:

require "../migration"

module Project
  ver = 1
  migration = Migration.new ver

  migration.register_up |db| do
    db.exec "create table version (version int)"
    db.exec "insert into version values (?)", ver
  end

  migration.register_down |db| do
    db.exec "drop table version"
  end

  Migrations[ver] = migration
end

我看不到任何直接的语法问题。此文件导入以下文件,因为它需要 class 和行 Migrations = [] of Migration:

src/project/database/migration/migration.cr:

require "db"
require "sqlite3"

module Project

  Migrations = [] of Migration

  class Migration
    def initialize(@version : Int)
    end

    # Registers a callback that will be called when the `up`-method is called.
    # The callback must return either `true` for a successful migration,
    # or `false` for a failed migration. If an `up` migration has
    # failed, the `down` migration will be called to restore the database
    # back to its previous state.
    # The callback will receive an instance of `DB::Database`
    #
    # Example:
    #
    # ```
    # migration = Migration.new(1)
    #
    # migration.register_up |db| do
    #   # Advance migration
    # end
    #
    # migration.register_down |db| do
    #   # Recede migration
    # end
    # ```
    def register_up(&block : (DB::Database) -> Bool)
      @up = block
    end

    # Registers a callback that will be called when the `down`-method is called.
    # See the `register_up` method for more information
    def register_down(&block : (DB::Database) -> Bool)
      @down = block
    end

    # Advances DB to the next version
    def up(conn : DB::Database)
      result = @up.call(conn)
      unless result
        # Failed migration, rollback
        @down.call(conn)
        raise Exception.new(`Failed to migrate database to version: #{@version}. Rolling back.`)
      end
    end

    # Recedes DB to the previous version
    def down(conn : DB::Database)
      result = @down.call(conn)
      unless result
        # Failed migration, rollback
        @up.call(conn)
        raise Exception.new(`Failed to migrate database to version: #{@version - 1}. Rolling back.`)
      end
    end
  end

end

有什么想法吗?

这里有语法错误:

migration.register_up |db| do
  # ...
end

应该是:

migration.register_up do |db|
  # ...
end

register_down也一样。

参见 Blocks and Procs 中的 "Yield arguments" 部分。