diff options
Diffstat (limited to 'jni/ruby/ext/psych/lib/psych/nodes')
-rw-r--r-- | jni/ruby/ext/psych/lib/psych/nodes/alias.rb | 18 | ||||
-rw-r--r-- | jni/ruby/ext/psych/lib/psych/nodes/document.rb | 60 | ||||
-rw-r--r-- | jni/ruby/ext/psych/lib/psych/nodes/mapping.rb | 56 | ||||
-rw-r--r-- | jni/ruby/ext/psych/lib/psych/nodes/node.rb | 55 | ||||
-rw-r--r-- | jni/ruby/ext/psych/lib/psych/nodes/scalar.rb | 67 | ||||
-rw-r--r-- | jni/ruby/ext/psych/lib/psych/nodes/sequence.rb | 81 | ||||
-rw-r--r-- | jni/ruby/ext/psych/lib/psych/nodes/stream.rb | 37 |
7 files changed, 374 insertions, 0 deletions
diff --git a/jni/ruby/ext/psych/lib/psych/nodes/alias.rb b/jni/ruby/ext/psych/lib/psych/nodes/alias.rb new file mode 100644 index 0000000..5bd4df1 --- /dev/null +++ b/jni/ruby/ext/psych/lib/psych/nodes/alias.rb @@ -0,0 +1,18 @@ +module Psych + module Nodes + ### + # This class represents a {YAML Alias}[http://yaml.org/spec/1.1/#alias]. + # It points to an +anchor+. + # + # A Psych::Nodes::Alias is a terminal node and may have no children. + class Alias < Psych::Nodes::Node + # The anchor this alias links to + attr_accessor :anchor + + # Create a new Alias that points to an +anchor+ + def initialize anchor + @anchor = anchor + end + end + end +end diff --git a/jni/ruby/ext/psych/lib/psych/nodes/document.rb b/jni/ruby/ext/psych/lib/psych/nodes/document.rb new file mode 100644 index 0000000..32014d6 --- /dev/null +++ b/jni/ruby/ext/psych/lib/psych/nodes/document.rb @@ -0,0 +1,60 @@ +module Psych + module Nodes + ### + # This represents a YAML Document. This node must be a child of + # Psych::Nodes::Stream. A Psych::Nodes::Document must have one child, + # and that child may be one of the following: + # + # * Psych::Nodes::Sequence + # * Psych::Nodes::Mapping + # * Psych::Nodes::Scalar + class Document < Psych::Nodes::Node + # The version of the YAML document + attr_accessor :version + + # A list of tag directives for this document + attr_accessor :tag_directives + + # Was this document implicitly created? + attr_accessor :implicit + + # Is the end of the document implicit? + attr_accessor :implicit_end + + ### + # Create a new Psych::Nodes::Document object. + # + # +version+ is a list indicating the YAML version. + # +tags_directives+ is a list of tag directive declarations + # +implicit+ is a flag indicating whether the document will be implicitly + # started. + # + # == Example: + # This creates a YAML document object that represents a YAML 1.1 document + # with one tag directive, and has an implicit start: + # + # Psych::Nodes::Document.new( + # [1,1], + # [["!", "tag:tenderlovemaking.com,2009:"]], + # true + # ) + # + # == See Also + # See also Psych::Handler#start_document + def initialize version = [], tag_directives = [], implicit = false + super() + @version = version + @tag_directives = tag_directives + @implicit = implicit + @implicit_end = true + end + + ### + # Returns the root node. A Document may only have one root node: + # http://yaml.org/spec/1.1/#id898031 + def root + children.first + end + end + end +end diff --git a/jni/ruby/ext/psych/lib/psych/nodes/mapping.rb b/jni/ruby/ext/psych/lib/psych/nodes/mapping.rb new file mode 100644 index 0000000..5ba95ce --- /dev/null +++ b/jni/ruby/ext/psych/lib/psych/nodes/mapping.rb @@ -0,0 +1,56 @@ +module Psych + module Nodes + ### + # This class represents a {YAML Mapping}[http://yaml.org/spec/1.1/#mapping]. + # + # A Psych::Nodes::Mapping node may have 0 or more children, but must have + # an even number of children. Here are the valid children a + # Psych::Nodes::Mapping node may have: + # + # * Psych::Nodes::Sequence + # * Psych::Nodes::Mapping + # * Psych::Nodes::Scalar + # * Psych::Nodes::Alias + class Mapping < Psych::Nodes::Node + # Any Map Style + ANY = 0 + + # Block Map Style + BLOCK = 1 + + # Flow Map Style + FLOW = 2 + + # The optional anchor for this mapping + attr_accessor :anchor + + # The optional tag for this mapping + attr_accessor :tag + + # Is this an implicit mapping? + attr_accessor :implicit + + # The style of this mapping + attr_accessor :style + + ### + # Create a new Psych::Nodes::Mapping object. + # + # +anchor+ is the anchor associated with the map or +nil+. + # +tag+ is the tag associated with the map or +nil+. + # +implicit+ is a boolean indicating whether or not the map was implicitly + # started. + # +style+ is an integer indicating the mapping style. + # + # == See Also + # See also Psych::Handler#start_mapping + def initialize anchor = nil, tag = nil, implicit = true, style = BLOCK + super() + @anchor = anchor + @tag = tag + @implicit = implicit + @style = style + end + end + end +end diff --git a/jni/ruby/ext/psych/lib/psych/nodes/node.rb b/jni/ruby/ext/psych/lib/psych/nodes/node.rb new file mode 100644 index 0000000..83233a6 --- /dev/null +++ b/jni/ruby/ext/psych/lib/psych/nodes/node.rb @@ -0,0 +1,55 @@ +require 'stringio' +require 'psych/class_loader' +require 'psych/scalar_scanner' + +module Psych + module Nodes + ### + # The base class for any Node in a YAML parse tree. This class should + # never be instantiated. + class Node + include Enumerable + + # The children of this node + attr_reader :children + + # An associated tag + attr_reader :tag + + # Create a new Psych::Nodes::Node + def initialize + @children = [] + end + + ### + # Iterate over each node in the tree. Yields each node to +block+ depth + # first. + def each &block + return enum_for :each unless block_given? + Visitors::DepthFirst.new(block).accept self + end + + ### + # Convert this node to Ruby. + # + # See also Psych::Visitors::ToRuby + def to_ruby + Visitors::ToRuby.create.accept(self) + end + alias :transform :to_ruby + + ### + # Convert this node to YAML. + # + # See also Psych::Visitors::Emitter + def yaml io = nil, options = {} + real_io = io || StringIO.new(''.encode('utf-8')) + + Visitors::Emitter.new(real_io, options).accept self + return real_io.string unless io + io + end + alias :to_yaml :yaml + end + end +end diff --git a/jni/ruby/ext/psych/lib/psych/nodes/scalar.rb b/jni/ruby/ext/psych/lib/psych/nodes/scalar.rb new file mode 100644 index 0000000..1b1b25b --- /dev/null +++ b/jni/ruby/ext/psych/lib/psych/nodes/scalar.rb @@ -0,0 +1,67 @@ +module Psych + module Nodes + ### + # This class represents a {YAML Scalar}[http://yaml.org/spec/1.1/#id858081]. + # + # This node type is a terminal node and should not have any children. + class Scalar < Psych::Nodes::Node + # Any style scalar, the emitter chooses + ANY = 0 + + # Plain scalar style + PLAIN = 1 + + # Single quoted style + SINGLE_QUOTED = 2 + + # Double quoted style + DOUBLE_QUOTED = 3 + + # Literal style + LITERAL = 4 + + # Folded style + FOLDED = 5 + + # The scalar value + attr_accessor :value + + # The anchor value (if there is one) + attr_accessor :anchor + + # The tag value (if there is one) + attr_accessor :tag + + # Is this a plain scalar? + attr_accessor :plain + + # Is this scalar quoted? + attr_accessor :quoted + + # The style of this scalar + attr_accessor :style + + ### + # Create a new Psych::Nodes::Scalar object. + # + # +value+ is the string value of the scalar + # +anchor+ is an associated anchor or nil + # +tag+ is an associated tag or nil + # +plain+ is a boolean value + # +quoted+ is a boolean value + # +style+ is an integer idicating the string style + # + # == See Also + # + # See also Psych::Handler#scalar + def initialize value, anchor = nil, tag = nil, plain = true, quoted = false, style = ANY + @value = value + @anchor = anchor + @tag = tag + @plain = plain + @quoted = quoted + @style = style + end + end + end +end diff --git a/jni/ruby/ext/psych/lib/psych/nodes/sequence.rb b/jni/ruby/ext/psych/lib/psych/nodes/sequence.rb new file mode 100644 index 0000000..7e907fe --- /dev/null +++ b/jni/ruby/ext/psych/lib/psych/nodes/sequence.rb @@ -0,0 +1,81 @@ +module Psych + module Nodes + ### + # This class represents a + # {YAML sequence}[http://yaml.org/spec/1.1/#sequence/syntax]. + # + # A YAML sequence is basically a list, and looks like this: + # + # %YAML 1.1 + # --- + # - I am + # - a Sequence + # + # A YAML sequence may have an anchor like this: + # + # %YAML 1.1 + # --- + # &A [ + # "This sequence", + # "has an anchor" + # ] + # + # A YAML sequence may also have a tag like this: + # + # %YAML 1.1 + # --- + # !!seq [ + # "This sequence", + # "has a tag" + # ] + # + # This class represents a sequence in a YAML document. A + # Psych::Nodes::Sequence node may have 0 or more children. Valid children + # for this node are: + # + # * Psych::Nodes::Sequence + # * Psych::Nodes::Mapping + # * Psych::Nodes::Scalar + # * Psych::Nodes::Alias + class Sequence < Psych::Nodes::Node + # Any Styles, emitter chooses + ANY = 0 + + # Block style sequence + BLOCK = 1 + + # Flow style sequence + FLOW = 2 + + # The anchor for this sequence (if any) + attr_accessor :anchor + + # The tag name for this sequence (if any) + attr_accessor :tag + + # Is this sequence started implicitly? + attr_accessor :implicit + + # The sequence style used + attr_accessor :style + + ### + # Create a new object representing a YAML sequence. + # + # +anchor+ is the anchor associated with the sequence or nil. + # +tag+ is the tag associated with the sequence or nil. + # +implicit+ a boolean indicating whether or not the sequence was + # implicitly started. + # +style+ is an integer indicating the list style. + # + # See Psych::Handler#start_sequence + def initialize anchor = nil, tag = nil, implicit = true, style = BLOCK + super() + @anchor = anchor + @tag = tag + @implicit = implicit + @style = style + end + end + end +end diff --git a/jni/ruby/ext/psych/lib/psych/nodes/stream.rb b/jni/ruby/ext/psych/lib/psych/nodes/stream.rb new file mode 100644 index 0000000..7cf5e03 --- /dev/null +++ b/jni/ruby/ext/psych/lib/psych/nodes/stream.rb @@ -0,0 +1,37 @@ +module Psych + module Nodes + ### + # Represents a YAML stream. This is the root node for any YAML parse + # tree. This node must have one or more child nodes. The only valid + # child node for a Psych::Nodes::Stream node is Psych::Nodes::Document. + class Stream < Psych::Nodes::Node + + # Encodings supported by Psych (and libyaml) + + # Any encoding + ANY = Psych::Parser::ANY + + # UTF-8 encoding + UTF8 = Psych::Parser::UTF8 + + # UTF-16LE encoding + UTF16LE = Psych::Parser::UTF16LE + + # UTF-16BE encoding + UTF16BE = Psych::Parser::UTF16BE + + # The encoding used for this stream + attr_accessor :encoding + + ### + # Create a new Psych::Nodes::Stream node with an +encoding+ that + # defaults to Psych::Nodes::Stream::UTF8. + # + # See also Psych::Handler#start_stream + def initialize encoding = UTF8 + super() + @encoding = encoding + end + end + end +end |