psych 3.0.0.beta2-x64-mingw32

Sign up to get free protection for your applications and to get access to all the features.
Files changed (74) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +16 -0
  3. data/.travis.yml +20 -0
  4. data/CHANGELOG.rdoc +576 -0
  5. data/Gemfile +3 -0
  6. data/Mavenfile +7 -0
  7. data/README.md +73 -0
  8. data/Rakefile +46 -0
  9. data/bin/console +7 -0
  10. data/bin/setup +6 -0
  11. data/ext/psych/.gitignore +11 -0
  12. data/ext/psych/depend +3 -0
  13. data/ext/psych/extconf.rb +39 -0
  14. data/ext/psych/psych.c +34 -0
  15. data/ext/psych/psych.h +17 -0
  16. data/ext/psych/psych_emitter.c +554 -0
  17. data/ext/psych/psych_emitter.h +8 -0
  18. data/ext/psych/psych_parser.c +568 -0
  19. data/ext/psych/psych_parser.h +6 -0
  20. data/ext/psych/psych_to_ruby.c +39 -0
  21. data/ext/psych/psych_to_ruby.h +8 -0
  22. data/ext/psych/psych_yaml_tree.c +24 -0
  23. data/ext/psych/psych_yaml_tree.h +8 -0
  24. data/ext/psych/yaml/LICENSE +19 -0
  25. data/ext/psych/yaml/api.c +1392 -0
  26. data/ext/psych/yaml/config.h +10 -0
  27. data/ext/psych/yaml/dumper.c +394 -0
  28. data/ext/psych/yaml/emitter.c +2329 -0
  29. data/ext/psych/yaml/loader.c +444 -0
  30. data/ext/psych/yaml/parser.c +1374 -0
  31. data/ext/psych/yaml/reader.c +469 -0
  32. data/ext/psych/yaml/scanner.c +3576 -0
  33. data/ext/psych/yaml/writer.c +141 -0
  34. data/ext/psych/yaml/yaml.h +1971 -0
  35. data/ext/psych/yaml/yaml_private.h +662 -0
  36. data/lib/psych.rb +511 -0
  37. data/lib/psych/class_loader.rb +102 -0
  38. data/lib/psych/coder.rb +95 -0
  39. data/lib/psych/core_ext.rb +19 -0
  40. data/lib/psych/exception.rb +14 -0
  41. data/lib/psych/handler.rb +250 -0
  42. data/lib/psych/handlers/document_stream.rb +23 -0
  43. data/lib/psych/handlers/recorder.rb +40 -0
  44. data/lib/psych/json/ruby_events.rb +20 -0
  45. data/lib/psych/json/stream.rb +17 -0
  46. data/lib/psych/json/tree_builder.rb +13 -0
  47. data/lib/psych/json/yaml_events.rb +30 -0
  48. data/lib/psych/nodes.rb +78 -0
  49. data/lib/psych/nodes/alias.rb +19 -0
  50. data/lib/psych/nodes/document.rb +61 -0
  51. data/lib/psych/nodes/mapping.rb +57 -0
  52. data/lib/psych/nodes/node.rb +56 -0
  53. data/lib/psych/nodes/scalar.rb +68 -0
  54. data/lib/psych/nodes/sequence.rb +82 -0
  55. data/lib/psych/nodes/stream.rb +38 -0
  56. data/lib/psych/omap.rb +5 -0
  57. data/lib/psych/parser.rb +52 -0
  58. data/lib/psych/scalar_scanner.rb +149 -0
  59. data/lib/psych/set.rb +5 -0
  60. data/lib/psych/stream.rb +38 -0
  61. data/lib/psych/streaming.rb +28 -0
  62. data/lib/psych/syntax_error.rb +22 -0
  63. data/lib/psych/tree_builder.rb +97 -0
  64. data/lib/psych/versions.rb +9 -0
  65. data/lib/psych/visitors.rb +7 -0
  66. data/lib/psych/visitors/depth_first.rb +27 -0
  67. data/lib/psych/visitors/emitter.rb +52 -0
  68. data/lib/psych/visitors/json_tree.rb +25 -0
  69. data/lib/psych/visitors/to_ruby.rb +401 -0
  70. data/lib/psych/visitors/visitor.rb +20 -0
  71. data/lib/psych/visitors/yaml_tree.rb +551 -0
  72. data/lib/psych/y.rb +10 -0
  73. data/psych.gemspec +64 -0
  74. metadata +175 -0
@@ -0,0 +1,23 @@
1
+ # frozen_string_literal: true
2
+ require 'psych/tree_builder'
3
+
4
+ module Psych
5
+ module Handlers
6
+ class DocumentStream < Psych::TreeBuilder # :nodoc:
7
+ def initialize &block
8
+ super
9
+ @block = block
10
+ end
11
+
12
+ def start_document version, tag_directives, implicit
13
+ n = Nodes::Document.new version, tag_directives, implicit
14
+ push n
15
+ end
16
+
17
+ def end_document implicit_end = !streaming?
18
+ @last.implicit_end = implicit_end
19
+ @block.call pop
20
+ end
21
+ end
22
+ end
23
+ end
@@ -0,0 +1,40 @@
1
+ # frozen_string_literal: true
2
+ require 'psych/handler'
3
+
4
+ module Psych
5
+ module Handlers
6
+ ###
7
+ # This handler will capture an event and record the event. Recorder events
8
+ # are available vial Psych::Handlers::Recorder#events.
9
+ #
10
+ # For example:
11
+ #
12
+ # recorder = Psych::Handlers::Recorder.new
13
+ # parser = Psych::Parser.new recorder
14
+ # parser.parse '--- foo'
15
+ #
16
+ # recorder.events # => [list of events]
17
+ #
18
+ # # Replay the events
19
+ #
20
+ # emitter = Psych::Emitter.new $stdout
21
+ # recorder.events.each do |m, args|
22
+ # emitter.send m, *args
23
+ # end
24
+
25
+ class Recorder < Psych::Handler
26
+ attr_reader :events
27
+
28
+ def initialize
29
+ @events = []
30
+ super
31
+ end
32
+
33
+ EVENTS.each do |event|
34
+ define_method event do |*args|
35
+ @events << [event, args]
36
+ end
37
+ end
38
+ end
39
+ end
40
+ end
@@ -0,0 +1,20 @@
1
+ # frozen_string_literal: true
2
+ module Psych
3
+ module JSON
4
+ module RubyEvents # :nodoc:
5
+ def visit_Time o
6
+ formatted = format_time o
7
+ @emitter.scalar formatted, nil, nil, false, true, Nodes::Scalar::DOUBLE_QUOTED
8
+ end
9
+
10
+ def visit_DateTime o
11
+ visit_Time o.to_time
12
+ end
13
+
14
+ def visit_String o
15
+ @emitter.scalar o.to_s, nil, nil, false, true, Nodes::Scalar::DOUBLE_QUOTED
16
+ end
17
+ alias :visit_Symbol :visit_String
18
+ end
19
+ end
20
+ end
@@ -0,0 +1,17 @@
1
+ # frozen_string_literal: true
2
+ require 'psych/json/ruby_events'
3
+ require 'psych/json/yaml_events'
4
+
5
+ module Psych
6
+ module JSON
7
+ class Stream < Psych::Visitors::JSONTree
8
+ include Psych::JSON::RubyEvents
9
+ include Psych::Streaming
10
+ extend Psych::Streaming::ClassMethods
11
+
12
+ class Emitter < Psych::Stream::Emitter # :nodoc:
13
+ include Psych::JSON::YAMLEvents
14
+ end
15
+ end
16
+ end
17
+ end
@@ -0,0 +1,13 @@
1
+ # frozen_string_literal: true
2
+ require 'psych/json/yaml_events'
3
+
4
+ module Psych
5
+ module JSON
6
+ ###
7
+ # Psych::JSON::TreeBuilder is an event based AST builder. Events are sent
8
+ # to an instance of Psych::JSON::TreeBuilder and a JSON AST is constructed.
9
+ class TreeBuilder < Psych::TreeBuilder
10
+ include Psych::JSON::YAMLEvents
11
+ end
12
+ end
13
+ end
@@ -0,0 +1,30 @@
1
+ # frozen_string_literal: true
2
+ module Psych
3
+ module JSON
4
+ module YAMLEvents # :nodoc:
5
+ def start_document version, tag_directives, implicit
6
+ super(version, tag_directives, !streaming?)
7
+ end
8
+
9
+ def end_document implicit_end = !streaming?
10
+ super(implicit_end)
11
+ end
12
+
13
+ def start_mapping anchor, tag, implicit, style
14
+ super(anchor, nil, true, Nodes::Mapping::FLOW)
15
+ end
16
+
17
+ def start_sequence anchor, tag, implicit, style
18
+ super(anchor, nil, true, Nodes::Sequence::FLOW)
19
+ end
20
+
21
+ def scalar value, anchor, tag, plain, quoted, style
22
+ if "tag:yaml.org,2002:null" == tag
23
+ super('null', nil, nil, true, false, Nodes::Scalar::PLAIN)
24
+ else
25
+ super
26
+ end
27
+ end
28
+ end
29
+ end
30
+ end
@@ -0,0 +1,78 @@
1
+ # frozen_string_literal: true
2
+ require 'psych/nodes/node'
3
+ require 'psych/nodes/stream'
4
+ require 'psych/nodes/document'
5
+ require 'psych/nodes/sequence'
6
+ require 'psych/nodes/scalar'
7
+ require 'psych/nodes/mapping'
8
+ require 'psych/nodes/alias'
9
+
10
+ module Psych
11
+ ###
12
+ # = Overview
13
+ #
14
+ # When using Psych.load to deserialize a YAML document, the document is
15
+ # translated to an intermediary AST. That intermediary AST is then
16
+ # translated in to a Ruby object graph.
17
+ #
18
+ # In the opposite direction, when using Psych.dump, the Ruby object graph is
19
+ # translated to an intermediary AST which is then converted to a YAML
20
+ # document.
21
+ #
22
+ # Psych::Nodes contains all of the classes that make up the nodes of a YAML
23
+ # AST. You can manually build an AST and use one of the visitors (see
24
+ # Psych::Visitors) to convert that AST to either a YAML document or to a
25
+ # Ruby object graph.
26
+ #
27
+ # Here is an example of building an AST that represents a list with one
28
+ # scalar:
29
+ #
30
+ # # Create our nodes
31
+ # stream = Psych::Nodes::Stream.new
32
+ # doc = Psych::Nodes::Document.new
33
+ # seq = Psych::Nodes::Sequence.new
34
+ # scalar = Psych::Nodes::Scalar.new('foo')
35
+ #
36
+ # # Build up our tree
37
+ # stream.children << doc
38
+ # doc.children << seq
39
+ # seq.children << scalar
40
+ #
41
+ # The stream is the root of the tree. We can then convert the tree to YAML:
42
+ #
43
+ # stream.to_yaml => "---\n- foo\n"
44
+ #
45
+ # Or convert it to Ruby:
46
+ #
47
+ # stream.to_ruby => [["foo"]]
48
+ #
49
+ # == YAML AST Requirements
50
+ #
51
+ # A valid YAML AST *must* have one Psych::Nodes::Stream at the root. A
52
+ # Psych::Nodes::Stream node must have 1 or more Psych::Nodes::Document nodes
53
+ # as children.
54
+ #
55
+ # Psych::Nodes::Document nodes must have one and *only* one child. That child
56
+ # may be one of:
57
+ #
58
+ # * Psych::Nodes::Sequence
59
+ # * Psych::Nodes::Mapping
60
+ # * Psych::Nodes::Scalar
61
+ #
62
+ # Psych::Nodes::Sequence and Psych::Nodes::Mapping nodes may have many
63
+ # children, but Psych::Nodes::Mapping nodes should have an even number of
64
+ # children.
65
+ #
66
+ # All of these are valid children for Psych::Nodes::Sequence and
67
+ # Psych::Nodes::Mapping nodes:
68
+ #
69
+ # * Psych::Nodes::Sequence
70
+ # * Psych::Nodes::Mapping
71
+ # * Psych::Nodes::Scalar
72
+ # * Psych::Nodes::Alias
73
+ #
74
+ # Psych::Nodes::Scalar and Psych::Nodes::Alias are both terminal nodes and
75
+ # should not have any children.
76
+ module Nodes
77
+ end
78
+ end
@@ -0,0 +1,19 @@
1
+ # frozen_string_literal: true
2
+ module Psych
3
+ module Nodes
4
+ ###
5
+ # This class represents a {YAML Alias}[http://yaml.org/spec/1.1/#alias].
6
+ # It points to an +anchor+.
7
+ #
8
+ # A Psych::Nodes::Alias is a terminal node and may have no children.
9
+ class Alias < Psych::Nodes::Node
10
+ # The anchor this alias links to
11
+ attr_accessor :anchor
12
+
13
+ # Create a new Alias that points to an +anchor+
14
+ def initialize anchor
15
+ @anchor = anchor
16
+ end
17
+ end
18
+ end
19
+ end
@@ -0,0 +1,61 @@
1
+ # frozen_string_literal: true
2
+ module Psych
3
+ module Nodes
4
+ ###
5
+ # This represents a YAML Document. This node must be a child of
6
+ # Psych::Nodes::Stream. A Psych::Nodes::Document must have one child,
7
+ # and that child may be one of the following:
8
+ #
9
+ # * Psych::Nodes::Sequence
10
+ # * Psych::Nodes::Mapping
11
+ # * Psych::Nodes::Scalar
12
+ class Document < Psych::Nodes::Node
13
+ # The version of the YAML document
14
+ attr_accessor :version
15
+
16
+ # A list of tag directives for this document
17
+ attr_accessor :tag_directives
18
+
19
+ # Was this document implicitly created?
20
+ attr_accessor :implicit
21
+
22
+ # Is the end of the document implicit?
23
+ attr_accessor :implicit_end
24
+
25
+ ###
26
+ # Create a new Psych::Nodes::Document object.
27
+ #
28
+ # +version+ is a list indicating the YAML version.
29
+ # +tags_directives+ is a list of tag directive declarations
30
+ # +implicit+ is a flag indicating whether the document will be implicitly
31
+ # started.
32
+ #
33
+ # == Example:
34
+ # This creates a YAML document object that represents a YAML 1.1 document
35
+ # with one tag directive, and has an implicit start:
36
+ #
37
+ # Psych::Nodes::Document.new(
38
+ # [1,1],
39
+ # [["!", "tag:tenderlovemaking.com,2009:"]],
40
+ # true
41
+ # )
42
+ #
43
+ # == See Also
44
+ # See also Psych::Handler#start_document
45
+ def initialize version = [], tag_directives = [], implicit = false
46
+ super()
47
+ @version = version
48
+ @tag_directives = tag_directives
49
+ @implicit = implicit
50
+ @implicit_end = true
51
+ end
52
+
53
+ ###
54
+ # Returns the root node. A Document may only have one root node:
55
+ # http://yaml.org/spec/1.1/#id898031
56
+ def root
57
+ children.first
58
+ end
59
+ end
60
+ end
61
+ end
@@ -0,0 +1,57 @@
1
+ # frozen_string_literal: true
2
+ module Psych
3
+ module Nodes
4
+ ###
5
+ # This class represents a {YAML Mapping}[http://yaml.org/spec/1.1/#mapping].
6
+ #
7
+ # A Psych::Nodes::Mapping node may have 0 or more children, but must have
8
+ # an even number of children. Here are the valid children a
9
+ # Psych::Nodes::Mapping node may have:
10
+ #
11
+ # * Psych::Nodes::Sequence
12
+ # * Psych::Nodes::Mapping
13
+ # * Psych::Nodes::Scalar
14
+ # * Psych::Nodes::Alias
15
+ class Mapping < Psych::Nodes::Node
16
+ # Any Map Style
17
+ ANY = 0
18
+
19
+ # Block Map Style
20
+ BLOCK = 1
21
+
22
+ # Flow Map Style
23
+ FLOW = 2
24
+
25
+ # The optional anchor for this mapping
26
+ attr_accessor :anchor
27
+
28
+ # The optional tag for this mapping
29
+ attr_accessor :tag
30
+
31
+ # Is this an implicit mapping?
32
+ attr_accessor :implicit
33
+
34
+ # The style of this mapping
35
+ attr_accessor :style
36
+
37
+ ###
38
+ # Create a new Psych::Nodes::Mapping object.
39
+ #
40
+ # +anchor+ is the anchor associated with the map or +nil+.
41
+ # +tag+ is the tag associated with the map or +nil+.
42
+ # +implicit+ is a boolean indicating whether or not the map was implicitly
43
+ # started.
44
+ # +style+ is an integer indicating the mapping style.
45
+ #
46
+ # == See Also
47
+ # See also Psych::Handler#start_mapping
48
+ def initialize anchor = nil, tag = nil, implicit = true, style = BLOCK
49
+ super()
50
+ @anchor = anchor
51
+ @tag = tag
52
+ @implicit = implicit
53
+ @style = style
54
+ end
55
+ end
56
+ end
57
+ end
@@ -0,0 +1,56 @@
1
+ # frozen_string_literal: true
2
+ require 'stringio'
3
+ require 'psych/class_loader'
4
+ require 'psych/scalar_scanner'
5
+
6
+ module Psych
7
+ module Nodes
8
+ ###
9
+ # The base class for any Node in a YAML parse tree. This class should
10
+ # never be instantiated.
11
+ class Node
12
+ include Enumerable
13
+
14
+ # The children of this node
15
+ attr_reader :children
16
+
17
+ # An associated tag
18
+ attr_reader :tag
19
+
20
+ # Create a new Psych::Nodes::Node
21
+ def initialize
22
+ @children = []
23
+ end
24
+
25
+ ###
26
+ # Iterate over each node in the tree. Yields each node to +block+ depth
27
+ # first.
28
+ def each &block
29
+ return enum_for :each unless block_given?
30
+ Visitors::DepthFirst.new(block).accept self
31
+ end
32
+
33
+ ###
34
+ # Convert this node to Ruby.
35
+ #
36
+ # See also Psych::Visitors::ToRuby
37
+ def to_ruby
38
+ Visitors::ToRuby.create.accept(self)
39
+ end
40
+ alias :transform :to_ruby
41
+
42
+ ###
43
+ # Convert this node to YAML.
44
+ #
45
+ # See also Psych::Visitors::Emitter
46
+ def yaml io = nil, options = {}
47
+ real_io = io || StringIO.new(''.encode('utf-8'))
48
+
49
+ Visitors::Emitter.new(real_io, options).accept self
50
+ return real_io.string unless io
51
+ io
52
+ end
53
+ alias :to_yaml :yaml
54
+ end
55
+ end
56
+ end
@@ -0,0 +1,68 @@
1
+ # frozen_string_literal: true
2
+ module Psych
3
+ module Nodes
4
+ ###
5
+ # This class represents a {YAML Scalar}[http://yaml.org/spec/1.1/#id858081].
6
+ #
7
+ # This node type is a terminal node and should not have any children.
8
+ class Scalar < Psych::Nodes::Node
9
+ # Any style scalar, the emitter chooses
10
+ ANY = 0
11
+
12
+ # Plain scalar style
13
+ PLAIN = 1
14
+
15
+ # Single quoted style
16
+ SINGLE_QUOTED = 2
17
+
18
+ # Double quoted style
19
+ DOUBLE_QUOTED = 3
20
+
21
+ # Literal style
22
+ LITERAL = 4
23
+
24
+ # Folded style
25
+ FOLDED = 5
26
+
27
+ # The scalar value
28
+ attr_accessor :value
29
+
30
+ # The anchor value (if there is one)
31
+ attr_accessor :anchor
32
+
33
+ # The tag value (if there is one)
34
+ attr_accessor :tag
35
+
36
+ # Is this a plain scalar?
37
+ attr_accessor :plain
38
+
39
+ # Is this scalar quoted?
40
+ attr_accessor :quoted
41
+
42
+ # The style of this scalar
43
+ attr_accessor :style
44
+
45
+ ###
46
+ # Create a new Psych::Nodes::Scalar object.
47
+ #
48
+ # +value+ is the string value of the scalar
49
+ # +anchor+ is an associated anchor or nil
50
+ # +tag+ is an associated tag or nil
51
+ # +plain+ is a boolean value
52
+ # +quoted+ is a boolean value
53
+ # +style+ is an integer idicating the string style
54
+ #
55
+ # == See Also
56
+ #
57
+ # See also Psych::Handler#scalar
58
+ def initialize value, anchor = nil, tag = nil, plain = true, quoted = false, style = ANY
59
+ @value = value
60
+ @anchor = anchor
61
+ @tag = tag
62
+ @plain = plain
63
+ @quoted = quoted
64
+ @style = style
65
+ end
66
+ end
67
+ end
68
+ end