summaryrefslogtreecommitdiff
path: root/ext
diff options
context:
space:
mode:
authortenderlove <tenderlove@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2011-01-17 19:44:31 +0000
committertenderlove <tenderlove@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2011-01-17 19:44:31 +0000
commit0b38e9bc9d030539d1a2b70f7075a92b4c5b2213 (patch)
treefe64497512c27850f2489b400ccd51c0a121be93 /ext
parenteacee9d95f86b035263fe8ba570c19e133c29aae (diff)
* ext/psych/lib/psych/parser.rb (Mark): Adding a class to wrap
marker information * ext/psych/parser.c (mark): Add a method to return the mark object for the parser * test/psych/test_parser.rb: tests for the Mark class. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@30588 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'ext')
-rw-r--r--ext/psych/lib/psych/parser.rb3
-rw-r--r--ext/psych/parser.c23
2 files changed, 26 insertions, 0 deletions
diff --git a/ext/psych/lib/psych/parser.rb b/ext/psych/lib/psych/parser.rb
index 0e38a4ae7d..5d75605d49 100644
--- a/ext/psych/lib/psych/parser.rb
+++ b/ext/psych/lib/psych/parser.rb
@@ -30,6 +30,9 @@ module Psych
# construct an AST of the parsed YAML document.
class Parser
+ class Mark < Struct.new(:index, :line, :column)
+ end
+
# The handler on which events will be called
attr_accessor :handler
diff --git a/ext/psych/parser.c b/ext/psych/parser.c
index c8b92a0fcd..071b8c0720 100644
--- a/ext/psych/parser.c
+++ b/ext/psych/parser.c
@@ -307,6 +307,28 @@ static VALUE set_external_encoding(VALUE self, VALUE encoding)
return encoding;
}
+/*
+ * call-seq:
+ * parser.mark # => #<Psych::Parser::Mark>
+ *
+ * Returns a Psych::Parser::Mark object that contains line, column, and index
+ * information.
+ */
+static VALUE mark(VALUE self)
+{
+ VALUE mark_klass;
+ VALUE args[3];
+ yaml_parser_t * parser;
+
+ Data_Get_Struct(self, yaml_parser_t, parser);
+ mark_klass = rb_const_get_at(cPsychParser, rb_intern("Mark"));
+ args[0] = INT2NUM(parser->mark.index);
+ args[1] = INT2NUM(parser->mark.line);
+ args[2] = INT2NUM(parser->mark.column);
+
+ return rb_class_new_instance(3, args, mark_klass);
+}
+
void Init_psych_parser()
{
#if 0
@@ -331,6 +353,7 @@ void Init_psych_parser()
ePsychSyntaxError = rb_define_class_under(mPsych, "SyntaxError", rb_eSyntaxError);
rb_define_method(cPsychParser, "parse", parse, 1);
+ rb_define_method(cPsychParser, "mark", mark, 0);
rb_define_method(cPsychParser, "external_encoding=", set_external_encoding, 1);
id_read = rb_intern("read");