[DGD] Search and replace with parse_string?

bart at wotf.org bart at wotf.org
Fri Jul 23 18:22:02 CEST 2010


Hi Krister,

Maybe http://mud.wotf.org/downloads/lpc/colorize.c is useful as an example for
this.

Regards,
Bart

On Fri, 23 Jul 2010 17:49:52 +0200, Krister Svanlund wrote
> I've just started playing with DGD again after quite some time away
> from text-based games and thought I would do som actual coding this
> time.
> 
> Just to get a feel for LPC i decided to write a small module to add
> color and escape-sequences to strings, since I like a colorful
> terminal window :)
> 
> My basic idea is that if a string such as "Hello 
> %RED!%World%RESET%!!" is sent to a user the %RED!% part will be 
> replaced with \x1b[1;31m and the %RESET% part with \x1b[0m. I have 
> gotten it to (kind of) work a few times but it's always with severe 
> limitations, such as % being unusable in the string. I solved this 
> by doing what I would have done in C and looped over the text and 
> calling a function on each color-string (such as RED!). This being 
> my current version I'm attempting to parse those strings with parse_string.
> 
> My idea is to have a grammer something like this:
> 
> mod = /[!_]/ /* ! becomes bold, !! becomes highcolor bold etc. */
> move = /[\^v<>]/ /* different kinds of cursor movements, also used as
> function arguments for clear and such */
> word = /[a-zA-Z]+/
> count = /[0-9]+/
> mods : mod mods /* each mod can be followed by several other mods */
> mods : mod
> color : word ? colorify /* a color can either be a simple color name
> or a color name followed by a modifier */
> color : word mods ? colorify
> movement : move ? movify /* a movement can be specified with a number
> otherwise it defaults to one */
> movement : count move ? movify
> func : word ? funcify
> func : word move ? funcify
> func : word count move ? funcify /* this should be used for clear...
> and maybe something else */
> 
> This does not seems to work. At best I get a nil back no matter what
> 
> (correct) text i feed it. If anyone can help me, either with a 
> grammar that handles it all or just a grammer for the color-
> specification it would be really cool.
> 
> I'm running DGD 1.4.3 and Kernel mudlib 1.3.3 and all this on linux.
> ___________________________________________
> https://mail.dworkin.nl/mailman/listinfo/dgd


--
Created with Open WebMail at http://www.bartsplace.net/
Read my weblog at http://soapbox.bartsplace.net/




More information about the DGD mailing list