From 1a74fa4b04da04bd2bb33103dd3cf431438df38e Mon Sep 17 00:00:00 2001 From: usa Date: Thu, 14 Dec 2017 15:09:35 +0000 Subject: add tag v2_2_9 git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/tags/v2_2_9@61257 b2dd03c8-39d4-4d8f-98ff-823fe69b080e --- ruby_2_2/ext/psych/lib/psych/json/ruby_events.rb | 19 +++++++++++++++ ruby_2_2/ext/psych/lib/psych/json/stream.rb | 16 +++++++++++++ ruby_2_2/ext/psych/lib/psych/json/tree_builder.rb | 12 ++++++++++ ruby_2_2/ext/psych/lib/psych/json/yaml_events.rb | 29 +++++++++++++++++++++++ 4 files changed, 76 insertions(+) create mode 100644 ruby_2_2/ext/psych/lib/psych/json/ruby_events.rb create mode 100644 ruby_2_2/ext/psych/lib/psych/json/stream.rb create mode 100644 ruby_2_2/ext/psych/lib/psych/json/tree_builder.rb create mode 100644 ruby_2_2/ext/psych/lib/psych/json/yaml_events.rb (limited to 'ruby_2_2/ext/psych/lib/psych/json') diff --git a/ruby_2_2/ext/psych/lib/psych/json/ruby_events.rb b/ruby_2_2/ext/psych/lib/psych/json/ruby_events.rb new file mode 100644 index 0000000000..6b73249c06 --- /dev/null +++ b/ruby_2_2/ext/psych/lib/psych/json/ruby_events.rb @@ -0,0 +1,19 @@ +module Psych + module JSON + module RubyEvents # :nodoc: + def visit_Time o + formatted = format_time o + @emitter.scalar formatted, nil, nil, false, true, Nodes::Scalar::DOUBLE_QUOTED + end + + def visit_DateTime o + visit_Time o.to_time + end + + def visit_String o + @emitter.scalar o.to_s, nil, nil, false, true, Nodes::Scalar::DOUBLE_QUOTED + end + alias :visit_Symbol :visit_String + end + end +end diff --git a/ruby_2_2/ext/psych/lib/psych/json/stream.rb b/ruby_2_2/ext/psych/lib/psych/json/stream.rb new file mode 100644 index 0000000000..fe2a6e9116 --- /dev/null +++ b/ruby_2_2/ext/psych/lib/psych/json/stream.rb @@ -0,0 +1,16 @@ +require 'psych/json/ruby_events' +require 'psych/json/yaml_events' + +module Psych + module JSON + class Stream < Psych::Visitors::JSONTree + include Psych::JSON::RubyEvents + include Psych::Streaming + extend Psych::Streaming::ClassMethods + + class Emitter < Psych::Stream::Emitter # :nodoc: + include Psych::JSON::YAMLEvents + end + end + end +end diff --git a/ruby_2_2/ext/psych/lib/psych/json/tree_builder.rb b/ruby_2_2/ext/psych/lib/psych/json/tree_builder.rb new file mode 100644 index 0000000000..b799c93f58 --- /dev/null +++ b/ruby_2_2/ext/psych/lib/psych/json/tree_builder.rb @@ -0,0 +1,12 @@ +require 'psych/json/yaml_events' + +module Psych + module JSON + ### + # Psych::JSON::TreeBuilder is an event based AST builder. Events are sent + # to an instance of Psych::JSON::TreeBuilder and a JSON AST is constructed. + class TreeBuilder < Psych::TreeBuilder + include Psych::JSON::YAMLEvents + end + end +end diff --git a/ruby_2_2/ext/psych/lib/psych/json/yaml_events.rb b/ruby_2_2/ext/psych/lib/psych/json/yaml_events.rb new file mode 100644 index 0000000000..d054d9b458 --- /dev/null +++ b/ruby_2_2/ext/psych/lib/psych/json/yaml_events.rb @@ -0,0 +1,29 @@ +module Psych + module JSON + module YAMLEvents # :nodoc: + def start_document version, tag_directives, implicit + super(version, tag_directives, !streaming?) + end + + def end_document implicit_end = !streaming? + super(implicit_end) + end + + def start_mapping anchor, tag, implicit, style + super(anchor, nil, true, Nodes::Mapping::FLOW) + end + + def start_sequence anchor, tag, implicit, style + super(anchor, nil, true, Nodes::Sequence::FLOW) + end + + def scalar value, anchor, tag, plain, quoted, style + if "tag:yaml.org,2002:null" == tag + super('null', nil, nil, true, false, Nodes::Scalar::PLAIN) + else + super + end + end + end + end +end -- cgit v1.2.3