Last active
August 29, 2015 14:14
-
-
Save fge/acd81c7326c6551398bf 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
package com.github.fge.grappa.trace.parser; | |
import com.github.fge.grappa.parsers.EventBusParser; | |
import com.github.fge.grappa.rules.Rule; | |
import com.google.common.collect.Range; | |
import javax.annotation.Nonnull; | |
import java.util.Objects; | |
public class TraceEventParser | |
extends EventBusParser<Object> | |
{ | |
private final TraceEventBuilder builder = new TraceEventBuilder(); | |
private final Range<Integer> range; | |
public TraceEventParser() | |
{ | |
this(Range.atLeast(0)); | |
} | |
public TraceEventParser(final int maxEvents) | |
{ | |
if (maxEvents < 0) | |
throw new IllegalArgumentException("maxEvents must be positive"); | |
range = Range.atMost(maxEvents); | |
} | |
public TraceEventParser(@Nonnull final Range<Integer> range) | |
{ | |
this.range = Objects.requireNonNull(range); | |
} | |
Rule traceEvents() | |
{ | |
return join(traceEvent()).using('\n').range(range); | |
} | |
Rule traceEvent() | |
{ | |
builder.reset(); | |
return sequence( | |
eventType(), ';', | |
index(), ';', | |
level(), ';', | |
matcher(), ';', | |
matcherType(), ';', | |
matcherClass(), ';', | |
nanoSeconds(), | |
post(builder) | |
); | |
} | |
Rule eventType() | |
{ | |
return sequence(digit(), builder.setType(match())); | |
} | |
Rule index() | |
{ | |
return sequence(oneOrMore(digit()), builder.setIndex(match())); | |
} | |
Rule level() | |
{ | |
return sequence(oneOrMore(digit()), builder.setLevel(match())); | |
} | |
Rule matcher() | |
{ | |
return sequence( | |
join(oneOrMore(noneOf("\\;"))).using("\\;").min(1), | |
builder.setMatcher(match()) | |
); | |
} | |
Rule matcherType() | |
{ | |
return sequence(digit(), builder.setMatcherType(match())); | |
} | |
Rule matcherClass() | |
{ | |
return sequence(oneOrMore(noneOf(";")), | |
builder.setMatcherClass(match())); | |
} | |
Rule nanoSeconds() | |
{ | |
return sequence(oneOrMore(digit()), builder.setNanoseconds(match())); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment