Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Peak does not return next event #381

Open
BernieWhite opened this issue Feb 5, 2019 · 1 comment
Open

Peak does not return next event #381

BernieWhite opened this issue Feb 5, 2019 · 1 comment
Labels
feedback-needed More feedback is required

Comments

@BernieWhite
Copy link

BernieWhite commented Feb 5, 2019

Peak nomenclature and comment indicates that it should return the next event without consuming it.

Actual behaviour is to return the current event without consuming it.

/// <summary>
/// Gets the next event without consuming it.
/// </summary>
/// <typeparam name="T">Type of the <see cref="ParsingEvent"/>.</typeparam>
/// <returns>Returns the current event if it is of type T; otherwise returns null.</returns>
public static T Peek<T>(this IParser parser) where T : ParsingEvent
{
if (!parser.Accept<T>())
{
return null;
}
return (T)parser.Current;
}

Accept indicates it checks the current event.

/// <summary>
/// Checks whether the current event is of the specified type.
/// </summary>
/// <typeparam name="T">Type of the event.</typeparam>
/// <returns>Returns true if the current event is of type <typeparamref name="T"/>. Otherwise returns false.</returns>
public static bool Accept<T>(this IParser parser) where T : ParsingEvent
{
if(parser.Current == null)
{
if (!parser.MoveNext())
{
throw new EndOfStreamException();
}
}
return parser.Current is T;
}

This is from master currently.

Really what I want to achieve is to check the next event so that I can determine a sequence, so that I can avoid consuming DocumentEnd unless it is followed by a DocumentStart event.

if (reader.Accept<DocumentEnd>())
{
    if (reader.Peek<DocumentStart>() != null)
    {
        reader.Allow<DocumentEnd>();
        reader.Allow<DocumentStart>();
    }
}
@aaubry
Copy link
Owner

aaubry commented Jun 10, 2019

I agree that the documentation is not very strict, but the behavior seems correct. It is not very clear what you are trying to achieve. It seems that you would want to peek on the next two events. I am correct ?

@aaubry aaubry added the feedback-needed More feedback is required label Jun 10, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feedback-needed More feedback is required
Projects
None yet
Development

No branches or pull requests

2 participants