POV-Ray : Newsgroups : povray.off-topic : Mini-languages : Re: Mini-languages Server Time
4 Sep 2024 01:18:34 EDT (-0400)
  Re: Mini-languages  
From: Invisible
Date: 11 Nov 2010 04:22:39
Message: <4cdbb5df$1@news.povray.org>
>> OK, that's one big ol' complex regex, right there.
>
> I see you never looked at perl code.

It's something I generally try to avoid, yeah. :-)

> do you really believe spelling out "option (char '+' <|> char '-')" is
> any worth as opposed to "(\+|-)"?

Um, *yes*. Why, do you think it doesn't have worth?

>> Enforcing that the exponent is less than or equal to 3 digits would be
>> slightly more wordy. The obvious way is
>>
>> xs <- many1 digit
>> if length xs > 3 then fail else return ()
>
> no, sorry. Truly overkill against "\d{3}".

So define a combinator for it:

   manyN 0 _ = return []
   manyN n p = do x <- p; xs <- manyN (n-1) p; return (x:xs)

And now, forever more, you can merely write

   manyN 3 digit

Problem solved.

EDIT: Apparently this function is already predefined. I hadn't even 
noticed. I could have just written "count 3 digit". In all the time I've 
been writing parsers, I've never needed this.


Post a reply to this message

Copyright 2003-2023 Persistence of Vision Raytracer Pty. Ltd.