Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 2 additions & 20 deletions ext/psych/psych_parser.c
Original file line number Diff line number Diff line change
Expand Up @@ -241,33 +241,15 @@ static VALUE protected_event_location(VALUE pointer)
return rb_funcall3(args[0], id_event_location, 4, args + 1);
}

/*
* call-seq:
* parser.parse(yaml)
*
* Parse the YAML document contained in +yaml+. Events will be called on
* the handler set on the parser instance.
*
* See Psych::Parser and Psych::Parser#handler
*/
static VALUE parse(int argc, VALUE *argv, VALUE self)
static VALUE parse(VALUE self, VALUE handler, VALUE yaml, VALUE path)
{
VALUE yaml, path;
yaml_parser_t * parser;
yaml_event_t event;
int done = 0;
int state = 0;
int parser_encoding = YAML_ANY_ENCODING;
int encoding = rb_utf8_encindex();
rb_encoding * internal_enc = rb_default_internal_encoding();
VALUE handler = rb_iv_get(self, "@handler");

if (rb_scan_args(argc, argv, "11", &yaml, &path) == 1) {
if(rb_respond_to(yaml, id_path))
path = rb_funcall(yaml, id_path, 0);
else
path = rb_str_new2("<unknown>");
}

TypedData_Get_Struct(self, yaml_parser_t, &psych_parser_type, parser);

Expand Down Expand Up @@ -558,7 +540,7 @@ void Init_psych_parser(void)

rb_require("psych/syntax_error");

rb_define_method(cPsychParser, "parse", parse, -1);
rb_define_private_method(cPsychParser, "_native_parse", parse, 3);
rb_define_method(cPsychParser, "mark", mark, 0);

id_read = rb_intern("read");
Expand Down
13 changes: 13 additions & 0 deletions lib/psych/parser.rb
Original file line number Diff line number Diff line change
Expand Up @@ -48,5 +48,18 @@ def initialize handler = Handler.new
@handler = handler
@external_encoding = ANY
end

###
# call-seq:
# parser.parse(yaml)
#
# Parse the YAML document contained in +yaml+. Events will be called on
# the handler set on the parser instance.
#
# See Psych::Parser and Psych::Parser#handler

def parse yaml, path = yaml.respond_to?(:path) ? yaml.path : "<unknown>"
_native_parse @handler, yaml, path
end
end
end