Shlomi Fish wrote:

>> I'm going to start learning C++ Templates Zen, for PPI's Tokenizer.
>> Wish me luck.
> But why do you need it? Isn't PPI written in Perl? Or do you mean something 
> else beside http://search.cpan.org/dist/PPI/ ?

It is, but for performance, I'm writing a C++ port for its tokenizer.

Now, enabled with template mojo, I can write things like:
PredicateOr<
        PredicateAnd<
                PredicateNot< PredicateFunc< is_digit > >,
                PredicateFunc< is_word > >,
        PredicateAnd<
                PredicateZeroOrMore< PredicateFunc< is_whitespace > >,
                PredicateFunc< is_quote > >,
        PredicateAnd<
                PredicateIsChar<'\\'>,
                PredicateFunc< is_word > > > regex;

Which implement the regex: /^(?: (?!\d)\w | \s*['"`] | \\\w ) /x.
And I get:
1. somewhat readable.
  (probably C programmer will prefer this for regular expressions... :-)
2. no virtual functions
  (because every class knows exactly the type of its inners)
3. most of the code will be inlined
  (or so I hope)
4. I can make the whole thing static

I just hope that I won't have to convert it to C one day.
The compiler does so much work for me here, that I'd hate to do it myself.

If someone is interested in the C++ code that enable it, drop me an email.

Shmuel.




_______________________________________________
Perl mailing list
[email protected]
http://perl.org.il/mailman/listinfo/perl

Reply via email to