[DGD] Search and replace with parse_string?
Krister Svanlund
krister.svanlund at gmail.com
Fri Jul 23 23:07:00 CEST 2010
Continuing on the same theme! I've written this grammar that works for
a color string (such as "RED!") but not for a movement string such as
"<5" or "^". Movement strings only gives a nil return value and the
"showthis" function is never called.
mod = /[!_]/
move = /[v<>\^]/
word = /[A-Z]+/
nr = /[0-9]+/
color : word
color : color mod
movem : move ?showthis
movem : movem nr
On Fri, Jul 23, 2010 at 10:07 PM, Krister Svanlund
<krister.svanlund at gmail.com> wrote:
> I checked this file out earlier but it feels too advanced for what I
> want to do. Also I don't understand why this grammer gives nil of the
> string "hello!!":
> exc = /[!]/
> word = /[a-z]+/
> excs : exc
> excs : exc excs
> worde : word
> worde : word excs
> sentance : worde
> sentance : worde sentance
>
> I did however figure out how to write it while writing this e-mail:
> exc = /[!]/
> word = /[a-z]+/
> worde = word
> worde = word exc
> sentance : worde
> sentance : worde sentance
>
> On Fri, Jul 23, 2010 at 6:22 PM, <bart at wotf.org> wrote:
>> 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/
>>
>> ___________________________________________
>> https://mail.dworkin.nl/mailman/listinfo/dgd
>>
>
More information about the DGD
mailing list