I'm using a PHP template engine I've written some time ago. It relies on regexes to create a cached PHP file. Some examples of the syntax:
{$foo} - regular variable
{$foo.bar} - variable foo that uses the array key 'bar'
{$foo|uppercase} - modifier 'uppercase' that takes 'foo' and applies some method to it
{iteration:users}
Hi there {$users.name}
{/iteration: users}
The list goes on... There's quite an amount of nasty regexes involved to parse all this. Note that an iteration can be inside another iteration and so on.
Recently I've been seeing template engines like twig, smarty3, that use a template lexer. I have a few questions about this: - In general isn't the lexer way slower than using a few regexes to create a cached php template? - Are there good resources on how to write your own lexer to interpret some sort of (template) language (I couldn't find anything I understand on google) - Should I keep using regexes or is a lexer something worth exploring?