'From Cuis 5.0 [latest update: #3923] on 16 October 2019 at 4:02:34 pm'!

!OMeta2Debug methodsFor: 'ometa grammar' stamp: 'jmv 10/16/2019 15:46:47'!
seq
	| xs |
	xs := self apply: #anything.
	[
	xs do: [ :x |
		" may want to inline #apply:withArgs: below as an
		  optimization, since this rule gets used a lot "
		self
			apply: #exactly
			withArgs: {x} ].
	^ xs ] on: Exception
		do: [ :e |
			(xs isKindOf: Collection)
				ifTrue: [ e pass
					"no idea what the problem is" ]
				ifFalse: [ OMeta2DebugError new signal: 'Not a sequence: ' , xs asString
					"we were probably passed in a character, number, etc..." ]].! !


!OMeta2Debug class methodsFor: 'private' stamp: 'jmv 10/16/2019 15:47:21'!
matchStream: aReadStream with: aRule withArgs: args withPlaybackDebugging: debugging
	| input matcher ans |
	input := OM2LazyStream
		for: aReadStream
		withPos: 1.
	matcher := self new initInput: input.
	matcher om2DebugRoot: aRule.
	LastMatcher := matcher.
	[
	matcher
		apply: #empty
		withArgs: args.
	ans := matcher apply: aRule.
	matcher apply: #end.
	^ ans ]
		on: OM2Fail
		do: [ :e | | curr prev prevPrev |
			debugging ifFalse: [ e pass ].
			curr := input.
			prev := nil.
			prevPrev := nil.
			[ curr notNil ] whileTrue: [
				prevPrev := prev.
				prev := curr.
				curr := curr basicTail ].
			curr := prevPrev
				ifNil: [ prev ]
				ifNotNil: [ prevPrev ].
			"fixme - does this add any value?
		self inform: 'will halt each time matcher reaches ', curr printString.
		"
			matcher
				initInput: input;
				forgetEverything.
			curr ifNil: [ self error: 'you''ve found a bug -- please tell Alex' ].
			curr become: (OM2StreamDebugger for: curr copy).
			matcher haltingPoint: curr.
			matcher
				apply: #empty
				withArgs: args.
			ans := matcher apply: aRule.
			matcher apply: #end.
			Transcript
				show: matcher om2DebugPc asString;
				finishEntry.
			^ ans ].! !

