[REBOL] Re: Resusing 'parse rules
From: brett:codeconscious at: 22-Dec-2000 19:50
Here's one suggestion.
Create an object that holds your parse rules in one place. This object will
have a special field called "Writer" that is initially set to 'none or some
default object. Each of the actions in your parse rules will call a
particular function on Writer.
Create objects that know how to output a specfic formats for example a
Prior to calling PARSE, set the value of the Writer field in the parse-rules
object (or decendent) to one of your format writer objects like
So as parse calls the various rules in your parse-rules object, the actions
call the appropriate writer functions and you get your specific output.
A delegation style pattern (I think).
In this way you separate the scanner of the input (parse-rules object) from
the emitter of the output (Html-writer).
If you find that you want to vary your actions as well you could consider
creating a new field in the parse-rules object that is called "controller".
This object would then have the responsibility of calling the writer object
in response to events raised by the parse-rules object.
Food for thought. Hope it helps!