Where do I start when writing a new scripting “language”?

qypisesusojod

New Member
I have a need to write a basic scripting/templating engine that will run under PHP. Ideally, I would be able to mix my own markup language with an (X)HTML template and run the document through a server-side parser to dynamically replace my own markup with (X)HTML served out of a database.Unfortunately, for all my knowledge of PHP and scripting, I'm not quite sure where to start. My first instinct was to run the entire document through some kind of regex parser and map my custom markup to specific PHP functions ... but that seems a bit slow and heavy-handed to me.What resources/tutorials/examples exist that can point me in the right direction? For comparison, I really like the new Razor templating engine for .NET MVC ... I don't want to completely knock it off for a PHP project, but building something similar would be great.UpdateOK, let me refine my explanation a bit more ... I develop websites for WordPress. A lot of my clients want to customize their websites but run away whenever I start talking about PHP. It's a scripting language that looks too complex for the lay user to even want to get interested.What I want to do is create my own form of markup specifically for WordPress. So rather than having PHP function calls (\[code\]get_header()\[/code\] and \[code\]get_footer()\[/code\] and \[code\]if(has_posts())\[/code\]...) in the theme file, you'd have namespaced XML (\[code\]<wpml:header />\[/code\] and \[code\]<wpml:footer />\[/code\] and \[code\]<wpml:loop> ... </wpml:loop>\[/code\]) that translates to the same thing. It would do a better job of separating your template files from the server-side script (there are several themes that place whole PHP functions directly in the theme's PHP template files!!!) and would make it easier for non-developers to begin working with an customizing a WordPress theme.With that in mind, the already suggested solutions of TWIG and Mackrell definitely support the idea of embedding script "nuggets" in the file, but they don't really help me parse the custom XML/XHTML markup into something recognizable by the server-side code.So ... where do I start when building a new server-side markup processor?
 
Back
Top