Package monq.jfa
Class RecordingMatcher<T>
java.lang.Object
monq.jfa.RecordingMatcher<T>
- Type Parameters:
T- type of the value stored in theDfa
A matcher looping on
Dfa.transition(monq.jfa.CharSource), recording character positions when traversing a
state which tests true for a given predicate. See match(Dfa, CharSource) for
details.-
Constructor Summary
ConstructorsConstructorDescriptionRecordingMatcher(StringBuilder out, IntArray stops, Predicate<T> isIntermediateStop) Creates the instance.RecordingMatcher(Predicate<T> isStop) Calls the other constructor with default emptyStringBuilderandIntArray. -
Method Summary
Modifier and TypeMethodDescriptiongetPart(int i) match(Dfa<T> dfa, CharSource in) Matches aDfaagainst the input.out()The string builder provided to the constructor or created internally recording matching output.stops()The array provided to the constructor or created internally recording traversal of states testedtrueby the constructor provided predicate.
-
Constructor Details
-
RecordingMatcher
Creates the instance.- Parameters:
out- where to append matching charactersstops- where to record character positionsisIntermediateStop- must returntrueiff the value tested denotes an intermediate stop state. Will never be called withnull.
-
RecordingMatcher
Calls the other constructor with default emptyStringBuilderandIntArray.
-
-
Method Details
-
out
The string builder provided to the constructor or created internally recording matching output. -
stops
The array provided to the constructor or created internally recording traversal of states testedtrueby the constructor provided predicate. -
getPart
Returns parts ofout()depending on value recorded instops(). In particular it returnssubstring(stops()[i-1], stops()[i]with the two border values defaulting to 0 andout().length()respectively- Parameters:
i- the part to retrieve.- Returns:
- the extracted string
-
match
Matches aDfaagainst the input. Matching input is recorded inout(). While traversing states of theDfa, a state's value, if any, is tested with the predicate defined in the constructor. For a sequence of the same value ('==') testingtrue, the first character position which is different is recorded instops().Example: Consider an automaton state self looping on character
'a', like for a"a*"having a value such that the predicate is true. Further assume that a'b'leads to a different state, not having a value. Then, after matching"aaab",3is recorded instops(). This allows to retrieve the sub-match for"a*". The easiest way is to usedgetPart(int).Note: The regular expression parser does not currently have means to mark positions in regular expression to work with the
RecordingMatcher. The states' values must be added by using anNfaBuilder. A respective predicate must be defined and must fit to the predicate for stop provided byDfa.withIsStopValue(java.util.function.Predicate<T>).- Parameters:
dfa- to use for matchingin- input to match into- Returns:
- the value of the last stop state visited or
null. If non-nullis returned, the output text may still be empty if theDfamatches the empty string. - Throws:
IOException- See Also:
-
match
- Throws:
IOException
-