summaryrefslogtreecommitdiff
path: root/ruby_2_2/ext/psych/lib/psych/json
diff options
context:
space:
mode:
Diffstat (limited to 'ruby_2_2/ext/psych/lib/psych/json')
-rw-r--r--ruby_2_2/ext/psych/lib/psych/json/ruby_events.rb19
-rw-r--r--ruby_2_2/ext/psych/lib/psych/json/stream.rb16
-rw-r--r--ruby_2_2/ext/psych/lib/psych/json/tree_builder.rb12
-rw-r--r--ruby_2_2/ext/psych/lib/psych/json/yaml_events.rb29
4 files changed, 76 insertions, 0 deletions
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