Mailing List Archive: 49091 messages
  • Home
  • Script library
  • AltME Archive
  • Mailing list
  • Articles Index
  • Site search
 

Resusing 'parse rules

 [1/5] from: al::bri::xtra::co::nz at: 22-Dec-2000 21:08


I'm involved in several largish projects now where I find that I'm reusing (or should I say wanting to reuse) 'parse rules and/or the actions associated with them. In simplified form, a 'parse rule looks like: [pattern (action)] In some cases I'd like to reuse the pattern, and change the action (for example generating HTML or XML, or say, postscript all from the one eText), in other cases keeping the same pattern and action (different projects). If I was using C++ (my only OO language I'm skilled in), I'd write the rules as objects and inherit from them, that's assuming that Rebol was smoothly integrated into C++. Does anyone have any suggestions on how to do this? Thank you for your help. BTW, have a Merry Christmas and a Happy New Year. Andrew Martin Spreading Rebolius good cheer... ICQ: 26227169 http://members.nbci.com/AndrewMartin/

 [2/5] 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 Html-Writer object. 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 Html-Writer . 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! Brett.

 [3/5] from: al:bri:xtra at: 22-Dec-2000 22:13


Brett wrote:
> Food for thought. Hope it helps!
It does help. Thank you Brett! Have a merry Christmas. Andrew Martin ICQ: 26227169 http://members.nbci.com/AndrewMartin/

 [4/5] from: brett:codeconscious at: 22-Dec-2000 22:02


My pleasure. I'm still wondering what a truly Rebolous solution would look like. So an incremental change to my last suggestion might be to use parse-rules to create a structured language that would be interpreted by the later writer objects, instead of writer objects having their functions called directly. The structured language could be a new dialect or just a block that is bound then passed to do in the writer object. It would have the interesting possibility of functions built for editing the structured language enabling one editor function to handle all sorts of different input and outputs. So there's more food for thought. Hmm. better stop there before I give myself mental indigestion. Merry xmas to you too. Brett.

 [5/5] from: g:santilli:tiscalinet:it at: 22-Dec-2000 13:40


Andrew Martin wrote: [...]
> [pattern (action)] > In some cases I'd like to reuse the pattern, and change the action (for > example generating HTML or XML, or say, postscript all from the one eText), > in other cases keeping the same pattern and action (different projects). If
What about creating a function that generates the rule? You can then parametrize it if needed and add a refinement to change the action from the default one...
> BTW, have a Merry Christmas and a Happy New Year.
Merry Christmas and a Happy New Year everyone! Regards, Gabriele. -- Gabriele Santilli <[giesse--writeme--com]> - Amigan - REBOL programmer Amiga Group Italia sez. L'Aquila -- http://www.amyresource.it/AGI/