ContextMatcher

trait ContextMatcher[Elem, +A]

An object responsible for inspecting a stack of StartElement events and determining if they correspond to some "context" value of type A.

ContextMatchers play a primary role in splitting an XML event stream into "substreams", i.e. each substream is defined as the series of consecutive events during which the XML tag stack matches a context.

ContextMatchers are intended to be transformed and combined with each other in order to build up more complex matching functionality. See also: SingleElementContextMatcher, which contains additional combination methods and some specialized transformation methods.

Type parameters:
A

The type of the matched context.

Companion:
object
class Object
trait Matchable
class Any
class Chained[Elem, H, T, F]
class Mapped[Elem, A, B]
class Or[Elem, A]
class And[Item, A, B, R]
class Default[Item, A]
class Mapped[Item, A, B]
class Or[Item, A]
class Predicate[Item]

Value members

Abstract methods

def applyChained[B](stack: IndexedSeq[Elem], offset: Int, avail: Int, next: ContextMatcher[Elem, B]): Option[(A, B)]

The underlying context match method.

The underlying context match method.

Inspects the elements in the XML "tag stack", which is essentially a List[StartElement], but for performance reasons is represented as an array with an "offset" index and a number of available elements from that offset. If the elements correspond to a context value of A, the implementation must then pass the remaining elements of the stack to the next matcher, i.e. by calling next(stack, offset + numConsumed, avail - numConsumed).

The next matcher is necessary in order to support non-greedy matchers, e.g. ContextMatcher.variableLength, a.k.a. **. Without a reference to the next matcher in the chain, matcher implementations would be forced to pick a fixed number of elements for matching, never knowing that the overall match could have succeeded if they had consumed some additional elements.

Type parameters:
B

The next matcher's context type

Value parameters:
avail

The number of elements available in the stack starting from the offset.

next

The next matcher in the chain.

offset

The index of the first element to be considered by the matching logic. From this method's point of view, the "first" element in the stack is actually at stack(offset)

stack

A reference to the complete XML "tag stack". Note that the responsibility of this method is limited to a slice of this value, as defined by offset and avail.

Returns:

If the match succeeded, and the next match succeded, an Option containing a tuple of both match results. If the match failed, or if the next match failed, None.

Concrete methods

def \[A1 >: A, B, R](next: ContextMatcher[Elem, B])(implicit reduce: Aux[A1, B, R]): ContextMatcher[Elem, R]

Create a new matcher by forming a chain with this matcher at the front, and the next matcher at the back. In other words, a matcher for a context within another context.

Create a new matcher by forming a chain with this matcher at the front, and the next matcher at the back. In other words, a matcher for a context within another context.

Type parameters:
A1

To satisfy covariance on A

B

The next matcher's context type

R

The "reduced" content type, derived from the tuple type (A, B) based on the reduce rule.

Value parameters:
next

A matcher which will be used to match the "inner" context

reduce

The TypeReduce rule to help omit Unit from the resulting context type

Returns:

A matcher which delegates to this matcher first, then the next matcher for the remaining stack.

def apply(stack: IndexedSeq[Elem], offset: Int, avail: Int): Option[A]

The main context match method.

The main context match method.

Inspects the elements in the XML "tag stack", which is essentially a List[StartElement], but for performance reasons is represented as an array with an "offset" index and a number of available elements from that offset. If the elements correspond to a context value of A, the implementation must then pass the remaining elements of the stack to the next matcher, i.e. by calling next(stack, offset + numConsumed, avail - numConsumed).

The difference between this method and applyChained is the lack of the next parameter; in this method, the current matcher is assumed to be the end of the chain.

Value parameters:
avail

The number of elements available in the stack starting from the offset.

offset

The index of the first element to be considered by the matching logic. From this method's point of view, the "first" element in the stack is actually at stack(offset)

stack

A reference to the complete XML "tag stack". Note that the responsibility of this method is limited to a slice of this value, as defined by offset and avail.

Returns:

An option containing the successfully-matched context, or None.

def filter(p: A => Boolean): ContextMatcher[Elem, A]

Create a new ContextMatcher which takes the match result of this matcher and passes it through the validation function f. If f returns false, the match is unsuccessful.

Create a new ContextMatcher which takes the match result of this matcher and passes it through the validation function f. If f returns false, the match is unsuccessful.

Value parameters:
p

The filter predicate, i.e. the validation function

Returns:

A new matcher with validated results

def flatMap[B](f: A => Option[B]): ContextMatcher[Elem, B]

Create a new ContextMatcher which takes the match result of this matcher and passes it through the combined transformation/validation function f. If f returns None, the match is unsuccessful; if f returns a Some, the value inside is the result of the match.

Create a new ContextMatcher which takes the match result of this matcher and passes it through the combined transformation/validation function f. If f returns None, the match is unsuccessful; if f returns a Some, the value inside is the result of the match.

Type parameters:
B

The transformed context type

Value parameters:
f

The transformation/validation function

Returns:

A new matcher with transformed and validated results

def map[B](f: A => B): ContextMatcher[Elem, B]

Create a new ContextMatcher which takes the match result of this matcher and passes it through the transformation function f.

Create a new ContextMatcher which takes the match result of this matcher and passes it through the transformation function f.

Type parameters:
B

The transformed context type

Value parameters:
f

The transformation function

Returns:

A new matcher with transformed results

def or[A2 >: A](that: ContextMatcher[Elem, A2]): ContextMatcher[Elem, A2]

Create a new ContextMatcher which will fall back to a second matcher in the event that this matcher fails to match a context.

Create a new ContextMatcher which will fall back to a second matcher in the event that this matcher fails to match a context.

Type parameters:
A2

The resulting context type (common supertype between this matcher and that)

Value parameters:
that

The matcher which will be used as the fallback

Returns:

A matcher that falls back to another matcher in case of failure

def |[A2 >: A](that: ContextMatcher[Elem, A2]): ContextMatcher[Elem, A2]

Operator version of or

Operator version of or