jnthn/grammar-debugger — pull request #7 by meisl (2014-09-11 01:51:50+00:00)
Title: fix (superset of) #5, add REAL tests, consolidate Tracer&Debugger, prep *proper* handling of state

Ok, quite a bunch of things...

First of all: this thing really deserves being pushed beyond a mere demonstration piece, IMHO. So that's what I'm trying here (and, on the way, learning; which is my humble benefit in it).

So, the one essential thing to have in order to start moving things around - was tests. I mean **REAL tests**, not just the pseudo (!) ones that are currently there.
Well, testing an interactive thing like `Debugger` ain't so easy. So I put together **RemoteControl** in `Grammar::Test::Helper`, which is kind of a robot that exercises Tracer/Debugger and logs what they write to STDOUT and STDERR. Then there's another test helper **&parseTasks** to help with easily run a bunch of tests on all ways of triggering a parse: (`parse`, `subparse`, `parsefile`) X (invoked on class, invoked on instance)[1].
So **these test-helpers plus the actual tests** that use them are the first chief contribution in this pr.
They can - and should be - further improved, though.

Anyways, thus being able to "move things around" safely, I hope to have managed to considerably consolidate things:
- **eliminated** all plain **code duplication** so far[2], namely `DebuggedGrammarHOW` isa `TracedGrammarHOW`isa `InterceptedGrammarHOW`
- **reduced** the crucial **part that kills perf** (`find_method`) to a minimum (eliminating it is tbd next)
- **isolated the *state*** that's kept (and must be so) by both, `Tracer` and `Debugger`, st it is *reset* whenever a new parse is initiated (done) and, left to be done, can be *associated to the right thing* (see https://github.com/jnthn/grammar-debugger/pull/5#issuecomment-54876455)
- thereby **fixed #5**, at least with *substantially* less cheating than as originally proposed (though that's still not entirly right, see above)
- **prepared** a general Publish-Subscribe/**Observer pattern** (`onRegexEnter` / `onRegexExit`) in order to be able to open up for new functionality like eg profiling
- oh, and I put some hints re colour output on Windows into README

___
[1] as I now have learned "on class" vs "on instance" doesn't really matter at all, but well, to be sure - plus there was a (real!) issue re that (#4)...
[2] anyone to actually compare the pure LOC...?