Skip to content

Embed URL

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
require 'psych'
class ScalarHandler < Psych::Handler
def parser=(parser)
@parser=parser
end
def mark
@parser.mark
end
def scalar value, anchor, tag, plain, quoted, style
p [value, anchor, tag, plain, quoted, style]
p mark
end
end
scalar_handler = ScalarHandler.new
parser = Psych::Parser.new(scalar_handler)
scalar_handler.parser = parser
yaml_document = <<END
foo:
bar:
baz: 3
blubb:
baz: 4
END
parser.parse(yaml_document)
=begin
["foo", nil, nil, true, false, 1]
#<struct Psych::Parser::Mark index=4, line=0, column=4>
["bar", nil, nil, true, false, 1]
#<struct Psych::Parser::Mark index=11, line=1, column=6>
["baz", nil, nil, true, false, 1]
#<struct Psych::Parser::Mark index=20, line=2, column=8>
["3", nil, nil, true, false, 1]
#<struct Psych::Parser::Mark index=25, line=3, column=2>
["blubb", nil, nil, true, false, 1]
#<struct Psych::Parser::Mark index=31, line=3, column=8>
["baz", nil, nil, true, false, 1]
#<struct Psych::Parser::Mark index=40, line=4, column=8>
["4", nil, nil, true, false, 1]
#<struct Psych::Parser::Mark index=43, line=5, column=0>
=end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.