-
-
Save headius/e160ed9a5e909da6f821 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
diff --git a/src/org/jruby/ext/psych/PsychParser.java b/src/org/jruby/ext/psych/PsychParser.java | |
index 039df99..77d1bc4 100644 | |
--- a/src/org/jruby/ext/psych/PsychParser.java | |
+++ b/src/org/jruby/ext/psych/PsychParser.java | |
@@ -98,23 +98,22 @@ public class PsychParser extends RubyObject { | |
} else { | |
reader = new StreamReader(new StringReader(target.convertToString().asJavaString())); | |
} | |
- Parser parser = new ParserImpl(reader); | |
+ parser = new ParserImpl(reader); | |
IRubyObject handler = getInstanceVariable("@handler"); | |
- Event event; | |
while (true) { | |
try { | |
- event = parser.getEvent(); | |
+ currentEvent = parser.getEvent(); | |
// FIXME: Event should expose a getID, so it can be switched | |
- if (event.is(ID.StreamStart)) { | |
+ if (currentEvent.is(ID.StreamStart)) { | |
invoke( | |
context, | |
handler, | |
"start_stream", | |
runtime.newFixnum(YAML_ANY_ENCODING)); | |
- } else if (event.is(ID.DocumentStart)) { | |
- DocumentStartEvent dse = (DocumentStartEvent)event; | |
+ } else if (currentEvent.is(ID.DocumentStart)) { | |
+ DocumentStartEvent dse = (DocumentStartEvent)currentEvent; | |
Integer[] versionInts = dse.getVersion(); | |
IRubyObject version = versionInts == null ? | |
@@ -139,15 +138,15 @@ public class PsychParser extends RubyObject { | |
version, | |
tags, | |
runtime.newBoolean(dse.getExplicit())); | |
- } else if (event.is(ID.DocumentEnd)) { | |
- DocumentEndEvent dee = (DocumentEndEvent)event; | |
+ } else if (currentEvent.is(ID.DocumentEnd)) { | |
+ DocumentEndEvent dee = (DocumentEndEvent)currentEvent; | |
invoke( | |
context, | |
handler, | |
"end_document", | |
runtime.newBoolean(dee.getExplicit())); | |
- } else if (event.is(ID.Alias)) { | |
- AliasEvent ae = (AliasEvent)event; | |
+ } else if (currentEvent.is(ID.Alias)) { | |
+ AliasEvent ae = (AliasEvent)currentEvent; | |
IRubyObject alias = runtime.getNil(); | |
if (ae.getAnchor() != null) { | |
alias = RubyString.newString(runtime, ae.getAnchor()); | |
@@ -158,8 +157,8 @@ public class PsychParser extends RubyObject { | |
handler, | |
"alias", | |
alias); | |
- } else if (event.is(ID.Scalar)) { | |
- ScalarEvent se = (ScalarEvent)event; | |
+ } else if (currentEvent.is(ID.Scalar)) { | |
+ ScalarEvent se = (ScalarEvent)currentEvent; | |
IRubyObject anchor = se.getAnchor() == null ? | |
runtime.getNil() : | |
RubyString.newString(runtime, se.getAnchor()); | |
@@ -181,8 +180,8 @@ public class PsychParser extends RubyObject { | |
plain_implicit, | |
quoted_implicit, | |
style); | |
- } else if (event.is(ID.SequenceStart)) { | |
- SequenceStartEvent sse = (SequenceStartEvent)event; | |
+ } else if (currentEvent.is(ID.SequenceStart)) { | |
+ SequenceStartEvent sse = (SequenceStartEvent)currentEvent; | |
IRubyObject anchor = sse.getAnchor() == null ? | |
runtime.getNil() : | |
RubyString.newString(runtime, sse.getAnchor()); | |
@@ -200,13 +199,13 @@ public class PsychParser extends RubyObject { | |
tag, | |
implicit, | |
style); | |
- } else if (event.is(ID.SequenceEnd)) { | |
+ } else if (currentEvent.is(ID.SequenceEnd)) { | |
invoke( | |
context, | |
handler, | |
"end_sequence"); | |
- } else if (event.is(ID.MappingStart)) { | |
- MappingStartEvent mse = (MappingStartEvent)event; | |
+ } else if (currentEvent.is(ID.MappingStart)) { | |
+ MappingStartEvent mse = (MappingStartEvent)currentEvent; | |
IRubyObject anchor = mse.getAnchor() == null ? | |
runtime.getNil() : | |
RubyString.newString(runtime, mse.getAnchor()); | |
@@ -224,12 +223,12 @@ public class PsychParser extends RubyObject { | |
tag, | |
implicit, | |
style); | |
- } else if (event.is(ID.MappingEnd)) { | |
+ } else if (currentEvent.is(ID.MappingEnd)) { | |
invoke( | |
context, | |
handler, | |
"end_mapping"); | |
- } else if (event.is(ID.StreamEnd)) { | |
+ } else if (currentEvent.is(ID.StreamEnd)) { | |
invoke( | |
context, | |
handler, | |
@@ -248,4 +247,22 @@ public class PsychParser extends RubyObject { | |
return this; | |
} | |
+ | |
+ @JRubyMethod | |
+ public IRubyObject line(ThreadContext context) { | |
+ return context.runtime.newFixnum(currentEvent.getStartMark().getLine()); | |
+ } | |
+ | |
+ @JRubyMethod | |
+ public IRubyObject column(ThreadContext context) { | |
+ return context.runtime.newFixnum(currentEvent.getStartMark().getColumn()); | |
+ } | |
+ | |
+ @JRubyMethod | |
+ public IRubyObject offset(ThreadContext context) { | |
+ return context.runtime.newFixnum(0); | |
+ } | |
+ | |
+ private Parser parser; | |
+ private Event currentEvent; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment