~ubuntu-branches/ubuntu/quantal/ruby1.9.1/quantal

« back to all changes in this revision

Viewing changes to ext/psych/lib/psych/handler.rb

  • Committer: Bazaar Package Importer
  • Author(s): Lucas Nussbaum
  • Date: 2010-07-31 17:08:39 UTC
  • mfrom: (1.1.4 upstream) (8.1.2 sid)
  • Revision ID: james.westby@ubuntu.com-20100731170839-j034dmpdqt1cc4p6
Tags: 1.9.2~svn28788-1
* New release based on upstream snapshot from the 1.9.2 branch,
  after 1.9.2 RC2. That branch is (supposed to be) binary-compatible
  with the 1.9.1 branch.
  + Builds fine on i386. Closes: #580852.
* Upgrade to Standards-Version: 3.9.1. No changes needed.
* Updated generated incs.
* Patches that still need work:
  + Unclear status, need more investigation:
   090729_fix_Makefile_deps.dpatch
   090803_exclude_rdoc.dpatch
   203_adjust_base_of_search_path.dpatch
   902_define_YAML_in_yaml_stringio.rb.dpatch
   919_common.mk_tweaks.dpatch
   931_libruby_suffix.dpatch
   940_test_thread_mutex_sync_shorter.dpatch
  + Maybe not needed anymore, keeping but not applying.
   102_skip_test_copy_stream.dpatch (test doesn't block anymore?)
   104_skip_btest_io.dpatch (test doesn't block anymore?)
   201_gem_prelude.dpatch (we don't use that rubygems anyway?)
   202_gem_default_dir.dpatch (we don't use that rubygems anyway?)
   940_test_file_exhaustive_fails_as_root.dpatch
   940_test_priority_fails.dpatch
   100518_load_libc_libm.dpatch
* Add disable-tests.diff: disable some tests that cause failures on FreeBSD.
  Closes: #590002, #543805, #542927.
* However, many new failures on FreeBSD. Since that version is still an
  improvement, add the check that makes test suite failures non-fatal on
  FreeBSD again. That still needs to be investigated.
* Re-add 903_skip_base_ruby_check.dpatch
* Add build-dependency on ruby1.8 and drop all pre-generated files.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
module Psych
 
2
  ###
 
3
  # Psych::Handler is an abstract base class that defines the events used
 
4
  # when dealing with Psych::Parser.  Clients who want to use Psych::Parser
 
5
  # should implement a class that inherits from Psych::Handler and define
 
6
  # events that they can handle.
 
7
  #
 
8
  # Psych::Handler defines all events that Psych::Parser can possibly send to
 
9
  # event handlers.
 
10
  #
 
11
  # See Psych::Parser for more details
 
12
  class Handler
 
13
    ###
 
14
    # Called with +encoding+ when the YAML stream starts.  This method is
 
15
    # called once per stream.  A stream may contain multiple documents.
 
16
    #
 
17
    # See the constants in Psych::Parser for the possible values of +encoding+.
 
18
    def start_stream encoding
 
19
    end
 
20
 
 
21
    ###
 
22
    # Called when the document starts with the declared +version+,
 
23
    # +tag_directives+, if the document is +implicit+.
 
24
    #
 
25
    # +version+ will be an array of integers indicating the YAML version being
 
26
    # dealt with, +tag_directives+ is a list of tuples indicating the prefix
 
27
    # and suffix of each tag, and +implicit+ is a boolean indicating whether
 
28
    # the document is started implicitly.
 
29
    #
 
30
    # === Example
 
31
    #
 
32
    # Given the following YAML:
 
33
    #
 
34
    #   %YAML 1.1
 
35
    #   %TAG ! tag:tenderlovemaking.com,2009:
 
36
    #   --- !squee
 
37
    #
 
38
    # The parameters for start_document must be this:
 
39
    #
 
40
    #   version         # => [1, 1]
 
41
    #   tag_directives  # => [["!", "tag:tenderlovemaking.com,2009:"]]
 
42
    #   implicit        # => false
 
43
    def start_document version, tag_directives, implicit
 
44
    end
 
45
 
 
46
    ###
 
47
    # Called with the document ends.  +implicit+ is a boolean value indicating
 
48
    # whether or not the document has an implicit ending.
 
49
    #
 
50
    # === Example
 
51
    #
 
52
    # Given the following YAML:
 
53
    #
 
54
    #   ---
 
55
    #     hello world
 
56
    #
 
57
    # +implicit+ will be true.  Given this YAML:
 
58
    #
 
59
    #   ---
 
60
    #     hello world
 
61
    #   ...
 
62
    #
 
63
    # +implicit+ will be false.
 
64
    def end_document implicit
 
65
    end
 
66
 
 
67
    ###
 
68
    # Called when an alias is found to +anchor+.  +anchor+ will be the name
 
69
    # of the anchor found.
 
70
    #
 
71
    # === Example
 
72
    #
 
73
    # Here we have an example of an array that references itself in YAML:
 
74
    #
 
75
    #   --- &ponies
 
76
    #   - first element
 
77
    #   - *ponies
 
78
    #
 
79
    # &ponies is the achor, *ponies is the alias.  In this case, alias is
 
80
    # called with "ponies".
 
81
    def alias anchor
 
82
    end
 
83
 
 
84
    ###
 
85
    # Called when a scalar +value+ is found.  The scalar may have an
 
86
    # +anchor+, a +tag+, be implicitly +plain+ or implicitly +quoted+
 
87
    #
 
88
    # +value+ is the string value of the scalar
 
89
    # +anchor+ is an associated anchor or nil
 
90
    # +tag+ is an associated tag or nil
 
91
    # +plain+ is a boolean value
 
92
    # +quoted+ is a boolean value
 
93
    # +style+ is an integer idicating the string style
 
94
    #
 
95
    # See the constants in Psych::Nodes::Scalar for the possible values of
 
96
    # +style+
 
97
    #
 
98
    # === Example
 
99
    #
 
100
    # Here is a YAML document that exercises most of the possible ways this
 
101
    # method can be called:
 
102
    #
 
103
    #   ---
 
104
    #   - !str "foo"
 
105
    #   - &anchor fun
 
106
    #   - many
 
107
    #     lines
 
108
    #   - |
 
109
    #     many
 
110
    #     newlines
 
111
    #
 
112
    # The above YAML document contains a list with four strings.  Here are
 
113
    # the parameters sent to this method in the same order:
 
114
    #
 
115
    #   # value               anchor    tag     plain   quoted  style
 
116
    #   ["foo",               nil,      "!str", false,  false,  3    ]
 
117
    #   ["fun",               "anchor", nil,    true,   false,  1    ]
 
118
    #   ["many lines",        nil,      nil,    true,   false,  1    ]
 
119
    #   ["many\nnewlines\n",  nil,      nil,    false,  true,   4    ]
 
120
    #
 
121
    def scalar value, anchor, tag, plain, quoted, style
 
122
    end
 
123
 
 
124
    ###
 
125
    # Called when a sequence is started.
 
126
    #
 
127
    # +anchor+ is the anchor associated with the sequence or nil.
 
128
    # +tag+ is the tag associated with the sequence or nil.
 
129
    # +implicit+ a boolean indicating whether or not the sequence was implicitly
 
130
    # started.
 
131
    # +style+ is an integer indicating the list style.
 
132
    #
 
133
    # See the constants in Psych::Nodes::Sequence for the possible values of
 
134
    # +style+.
 
135
    #
 
136
    # === Example
 
137
    #
 
138
    # Here is a YAML document that exercises most of the possible ways this
 
139
    # method can be called:
 
140
    #
 
141
    #   ---
 
142
    #   - !!seq [
 
143
    #     a
 
144
    #   ]
 
145
    #   - &pewpew
 
146
    #     - b
 
147
    #
 
148
    # The above YAML document consists of three lists, an outer list that
 
149
    # contains two inner lists.  Here is a matrix of the parameters sent
 
150
    # to represent these lists:
 
151
    #
 
152
    #   # anchor    tag                       implicit  style
 
153
    #   [nil,       nil,                      true,     1     ]
 
154
    #   [nil,       "tag:yaml.org,2002:seq",  false,    2     ]
 
155
    #   ["pewpew",  nil,                      true,     1     ]
 
156
 
 
157
    def start_sequence anchor, tag, implicit, style
 
158
    end
 
159
 
 
160
    ###
 
161
    # Called when a sequence ends.
 
162
    def end_sequence
 
163
    end
 
164
 
 
165
    ###
 
166
    # Called when a map starts.
 
167
    #
 
168
    # +anchor+ is the anchor associated with the map or +nil+.
 
169
    # +tag+ is the tag associated with the map or +nil+.
 
170
    # +implicit+ is a boolean indicating whether or not the map was implicitly
 
171
    # started.
 
172
    # +style+ is an integer indicating the mapping style.
 
173
    #
 
174
    # See the constants in Psych::Nodes::Mapping for the possible values of
 
175
    # +style+.
 
176
    #
 
177
    # === Example
 
178
    #
 
179
    # Here is a YAML document that exercises most of the possible ways this
 
180
    # method can be called:
 
181
    #
 
182
    #   ---
 
183
    #   k: !!map { hello: world }
 
184
    #   v: &pewpew
 
185
    #     hello: world
 
186
    #
 
187
    # The above YAML document consists of three maps, an outer map that contains
 
188
    # two inner maps.  Below is a matrix of the parameters sent in order to
 
189
    # represent these three maps:
 
190
    #
 
191
    #   # anchor    tag                       implicit  style
 
192
    #   [nil,       nil,                      true,     1     ]
 
193
    #   [nil,       "tag:yaml.org,2002:map",  false,    2     ]
 
194
    #   ["pewpew",  nil,                      true,     1     ]
 
195
 
 
196
    def start_mapping anchor, tag, implicit, style
 
197
    end
 
198
 
 
199
    ###
 
200
    # Called when a map ends
 
201
    def end_mapping
 
202
    end
 
203
 
 
204
    ###
 
205
    # Called when an empty event happens. (Which, as far as I can tell, is
 
206
    # never).
 
207
    def empty
 
208
    end
 
209
 
 
210
    ###
 
211
    # Called when the YAML stream ends
 
212
    def end_stream
 
213
    end
 
214
  end
 
215
end