Modify logging methods of MatchJournal to return logged Chunks
This commit is contained in:
parent
7074112b7c
commit
18fc4592f0
|
|
@ -28,13 +28,15 @@ interface MatchJournal : MutableIterable<MatchJournal.Chunk> {
|
|||
/**
|
||||
* Add new [Chunk] for matches of principal rules.
|
||||
* Log occurrences discarded by match in current [Chunk].
|
||||
* Returns added [Chunk], null for non-principal rules.
|
||||
*/
|
||||
fun logMatch(match: RuleMatch)
|
||||
fun logMatch(match: RuleMatch): MatchChunk?
|
||||
|
||||
/**
|
||||
* Log occurrence activation in current [Chunk].
|
||||
* Returns added [Chunk], null for non-principal occurrences.
|
||||
*/
|
||||
fun logActivation(occ: Occurrence)
|
||||
fun logActivation(occ: Occurrence): OccChunk?
|
||||
|
||||
/**
|
||||
* Returns nearest MatchChunk which justifies current chunk.
|
||||
|
|
|
|||
|
|
@ -66,23 +66,33 @@ internal open class MatchJournalImpl(
|
|||
override fun iterator(): MutableIterator<Chunk> = hist.iterator()
|
||||
|
||||
|
||||
override fun logMatch(match: RuleMatch) {
|
||||
override fun logMatch(match: RuleMatch): MatchChunk? {
|
||||
var added: MatchChunk? = null
|
||||
|
||||
if (ispec.isPrincipal(match.rule())) {
|
||||
current = MatchChunk(nextChunkId++, match)
|
||||
added = MatchChunk(nextChunkId++, match)
|
||||
current = added
|
||||
posPtr.add(current)
|
||||
}
|
||||
// Log discarded occurrences
|
||||
(match as RuleMatchImpl).forEachReplaced { occ ->
|
||||
current.entries.add(Chunk.Entry(occ, true))
|
||||
}
|
||||
|
||||
return added
|
||||
}
|
||||
|
||||
override fun logActivation(occ: Occurrence) {
|
||||
override fun logActivation(occ: Occurrence): OccChunk? {
|
||||
var added: OccChunk? = null
|
||||
|
||||
if (ispec.isPrincipal(occ.constraint)) {
|
||||
current = OccChunk(nextChunkId++, occ)
|
||||
added = OccChunk(nextChunkId++, occ)
|
||||
current = added
|
||||
posPtr.add(current)
|
||||
}
|
||||
current.entries.add(Chunk.Entry(occ))
|
||||
|
||||
return added
|
||||
}
|
||||
|
||||
override fun ancestorMatch(): MatchChunk {
|
||||
|
|
@ -118,11 +128,13 @@ internal open class MatchJournalImpl(
|
|||
while (posPtr.hasPrevious()) {
|
||||
current = posPtr.previous()
|
||||
if (current === pastPos.chunk) {
|
||||
// todo: need reversed?
|
||||
resetOccurrences(current.entries.drop(pastPos.entriesCount))
|
||||
current.entries = current.entries.subList(0, pastPos.entriesCount)
|
||||
posPtr.next() // make 'posPtr' to always point right after 'current'
|
||||
return
|
||||
}
|
||||
// todo: need reversed?
|
||||
resetOccurrences(current.entries)
|
||||
posPtr.remove()
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue