summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorAaron Patterson <aaron.patterson@gmail.com>2009-09-26 21:19:15 -0700
committerAaron Patterson <aaron.patterson@gmail.com>2009-09-26 21:19:15 -0700
commitdb8a622d4687954b67dc675158bac07ed5d57cfa (patch)
tree6e80b7bebf224d6d9f9435ba9d9bd8216ae94b67 /lib
parentec8ae73b763f8d814adbae4868bac5f7b6c49a48 (diff)
downloadpsych-db8a622d4687954b67dc675158bac07ed5d57cfa.zip
start_document is working
Diffstat (limited to 'lib')
-rw-r--r--lib/psych.rb18
-rw-r--r--lib/psych/parser.rb22
-rw-r--r--lib/psych/parser/handler.rb22
3 files changed, 60 insertions, 2 deletions
diff --git a/lib/psych.rb b/lib/psych.rb
index 31cd7f6..df00156 100644
--- a/lib/psych.rb
+++ b/lib/psych.rb
@@ -1,3 +1,17 @@
-class Psych
- VERSION = '1.0.0'
+require 'psych/parser'
+require 'psych/psych'
+
+module Psych
+ VERSION = '1.0.0'
+ LIBYAML_VERSION = Psych.libyaml_version.join '.'
+
+ # Encodings supported by Psych (and libyaml)
+ ANY_ENCODING = 1
+ UTF8_ENCODING = 2
+ UTF16LE_ENCODING = 3
+ UTF16BE_ENCODING = 4
+
+ def self.parse thing
+ Psych::Parser.new.parse thing
+ end
end
diff --git a/lib/psych/parser.rb b/lib/psych/parser.rb
new file mode 100644
index 0000000..736521f
--- /dev/null
+++ b/lib/psych/parser.rb
@@ -0,0 +1,22 @@
+require 'psych/parser/handler'
+
+module Psych
+ ###
+ # YAML parser class.
+ #
+ # Example:
+ #
+ # parser = Psych::Parser.new
+ # parser.parse(some_yaml)
+ class Parser
+ attr_accessor :handler
+
+ def initialize handler = Handler.new
+ @handler = handler
+ end
+
+ def parse string
+ parse_string string
+ end
+ end
+end
diff --git a/lib/psych/parser/handler.rb b/lib/psych/parser/handler.rb
new file mode 100644
index 0000000..c3e6f1d
--- /dev/null
+++ b/lib/psych/parser/handler.rb
@@ -0,0 +1,22 @@
+module Psych
+ class Parser
+ ###
+ # Default event handlers used in conjunction with Psych::Parser
+ class Handler
+ ###
+ # Called with +encoding+ when the YAML stream starts.
+ def start_stream encoding
+ end
+
+ ###
+ # Called when the document starts with the declared +version+
+ def start_document version = []
+ end
+
+ ###
+ # Called when the YAML stream ends
+ def end_stream
+ end
+ end
+ end
+end