Skip to content

Instantly share code, notes, and snippets.

@mikz
Created October 8, 2021 14:38
Show Gist options
  • Select an option

  • Save mikz/b0246d2eeaa63a672e1e98a9b2961d1b to your computer and use it in GitHub Desktop.

Select an option

Save mikz/b0246d2eeaa63a672e1e98a9b2961d1b to your computer and use it in GitHub Desktop.

Revisions

  1. mikz revised this gist Oct 8, 2021. 1 changed file with 0 additions and 8 deletions.
    8 changes: 0 additions & 8 deletions Unity3D yaml parser.rb
    Original file line number Diff line number Diff line change
    @@ -4,14 +4,6 @@
    require 'psych'
    require 'pry'

    class Unity3DStream < Psych::Handlers::DocumentStream
    def start_document version, tag_directives, implicit
    version = [1, 1] if version.empty?
    tag_directives = [["!u!", "tag:unity3d.com,2011:"]] if tag_directives.empty?
    super
    end
    end

    parser = Psych::Parser.new(Unity3DStream.new(&Proc.new{ |doc| binding.pry }))

    str = ARGF.read.gsub(/^--- [!]u[!](\d+)/) { "--- !<tag:unity3d.com,2011/#{$1}>" }.gsub(/^(--- .+?) stripped/) { $1 }
  2. mikz created this gist Oct 8, 2021.
    19 changes: 19 additions & 0 deletions Unity3D yaml parser.rb
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,19 @@
    #!/usr/bin/env ruby

    require 'yaml'
    require 'psych'
    require 'pry'

    class Unity3DStream < Psych::Handlers::DocumentStream
    def start_document version, tag_directives, implicit
    version = [1, 1] if version.empty?
    tag_directives = [["!u!", "tag:unity3d.com,2011:"]] if tag_directives.empty?
    super
    end
    end

    parser = Psych::Parser.new(Unity3DStream.new(&Proc.new{ |doc| binding.pry }))

    str = ARGF.read.gsub(/^--- [!]u[!](\d+)/) { "--- !<tag:unity3d.com,2011/#{$1}>" }.gsub(/^(--- .+?) stripped/) { $1 }
    parser.parse str
    puts parser.handler.root.inspect