deviantgeek6966 Posted February 10, 2007 Share Posted February 10, 2007 im writing a template engine and im stuck on matching all the variables with a regular expression. here are what they can look like: $foo.bar $foo[0].bar $foo[$bar] $foo[$bar].foobar $foo[0].$bar.blah $foo[$bar + 1].bar $foo[$bar[0].$blah[$bleh].bluh + 1].bar $foo.$bar $foo[1 + 10].bleh.$bar $foo $foo.bar[$blah.foobar[0]].bleh[1 + 1] $foo.bar.$blah[$f + 1][0].bleh and so on, hopefully you get the idea. similar to accessing childen in php arrays except you can access children by using brackets ([ ]) or with the period (.). brackets are for mainly calculating an index or grabbing a certain char in a string. no need for referencing, i just need these variables whole so i can disassemble them myself. ive checked out smarty to see how they do it, but it seems they have a limit on how much you can nest things and im trying to avoid that. if anyone knows a better syntax for variables and a way of capturing them im open for suggestions. thanks Quote Link to comment Share on other sites More sharing options...
effigy Posted February 12, 2007 Share Posted February 12, 2007 I'm assuming you also want the ability to use ++, --, -, /, *, %, &, |, ^, ~, <<, and >> where you have used "+" in your example? What have you tried so far? This can be a big undertaking depending on how much nesting you're going to allow, and is most likely the reason you see limits in Smarty: heed the paths of those who have gone before you. The more nesting you allow, the slower your engine may be. Quote Link to comment Share on other sites More sharing options...
deviantgeek6966 Posted February 13, 2007 Author Share Posted February 13, 2007 yea i want the ability to use those as well. yea i know its a big undertaking. i might just make something simpler than this because i finally got an expression that works with limitless nesting in it but, i dunno if its my server thats going slow or if the expression is taking too long. i will have caching on my template engine so speed isnt a major problem but i dont want it to take too long to render something either. anyways here is what im using now, maybe someone can improve on it for me? if anyone wants to tackle decifering it, i will have to repost with a decifer of it because its really complicated lol. but! it works exactly how i wanted it to: \$[a-zA-Z][\w]*(?:\[[\s]*(?:[\d]+|\$[a-zA-Z][\w]*(?:\[.*?\])*(?:[\.][a-zA-Z][\w]*(?:\[.*?\])*)*)(?:[\s]*[\+\-\%\*][\s]*(?:[\d]+||\$[a-zA-Z][\w]*(?:\[.*?\])*(?:[\.][a-zA-Z][\w]*(?:\[.*?\])*)*))*[\s]*\])*(?:[\.][a-zA-Z][\w]*(?:\[[\s]*(?:[\d]+|\$[a-zA-Z][\w]*(?:\[.*?\])*(?:[\.][a-zA-Z][\w]*(?:\[.*?\])*)*)(?:[\s]*[\+\-\%\*][\s]*(?:[\d]+||\$[a-zA-Z][\w]*(?:\[.*?\])*(?:[\.][a-zA-Z][\w]*(?:\[.*?\])*)*))*[\s]*\])*)*[^\.\[\]] Quote Link to comment Share on other sites More sharing options...
effigy Posted February 13, 2007 Share Posted February 13, 2007 You should use the /x modifier so you can comment your expression. Also, there is mention in the docs of using (?R) for recursion. I've rarely used it myself; good luck. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.