summaryrefslogtreecommitdiff
path: root/ext/psych
diff options
context:
space:
mode:
authorAaron Patterson <aaron.patterson@gmail.com>2011-01-21 09:52:10 -0800
committerAaron Patterson <aaron.patterson@gmail.com>2011-01-21 09:52:10 -0800
commite008a513f5e33031c5e9341cb4da09a225693840 (patch)
treecda75b172f2229d29373afef6373d76d10923ae8 /ext/psych
parent56f296ee0b85ecd6956d640bac9ac9620ab44fb7 (diff)
downloadpsych-e008a513f5e33031c5e9341cb4da09a225693840.tar.gz
syncing up with ruby trunk
Diffstat (limited to 'ext/psych')
-rw-r--r--ext/psych/parser.c23
1 files changed, 23 insertions, 0 deletions
diff --git a/ext/psych/parser.c b/ext/psych/parser.c
index c8b92a0..071b8c0 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");