Mini parsing script

Any questions involving matching text strings to patterns - the pattern is called a "regular expression."

Moderator: General Moderators

Post Reply
astropirate
Forum Newbie
Posts: 12
Joined: Tue Oct 28, 2008 3:59 pm

Mini parsing script

Post by astropirate »

Greetings all
i am trying to write a templating engine and i require a simple conditional statement to be part of it.
the syntax for the statement would go something like this:

Code: Select all

{-IF UserOnline DO 'this will be printed out! and this {-UserName-}' ''-}
what i would like to do is find a statement such as that and get the argument in this case "UserOnline" and if it returns true then it will replace the while thing with what is inside the single quotes ''.
i just need help with the ragex part. i dont know how i would test if there is another "{-" inside it should look for two "-}" before ending the search.
so far i have this but it definatly isnt working

Code: Select all

 
 
$prepat = '([A-Za-z0-9(\<(/?[^\>]+)\>)(\{\-([A-Za-z0-9-]+)\-\})-]+)';
$pattern = '`' .$this->LEFT_DELIMITER ."\s*" ."IF" ."\s*" ."UserOnline"."\s*" ."DO" ."\s*'\s*" .$prepat ."\s*'\s*" .$this->RIGHT_DELIMITER .'`i';
        
 
any help would be greatly apreciated.
User avatar
prometheuzz
Forum Regular
Posts: 779
Joined: Fri Apr 04, 2008 5:51 am

Re: Mini parsing script

Post by prometheuzz »

Let me get this straight, your grammar allows for statements like these:

Code: Select all

{- ... {- {- ... -} ... -} ... -}
In other words, these {- and -} can be nested?
astropirate
Forum Newbie
Posts: 12
Joined: Tue Oct 28, 2008 3:59 pm

Re: Mini parsing script

Post by astropirate »

it can be nested just once. it will look at the outer one and decide the outcome. then it will print out what is inside the single quotes. then i will come around and parse what ever is inside the single quotes. it would be great if i could do both in one statement but i guess that is too advance.
Post Reply