> -----Original Message-----
> From: Joel
> Subject: Re: [Spirit-general] RE: [Spirit-devel] More Quickbook updates
> 
> David Barrett wrote:
> > Yes, it's a nasty problem.  Here is the regular expression I use for
> bold:
> >
> '/(?<=^|^\W|\s\W|\s|<b>|<i>|<code>)\*(([^*\s]+\s+)*[^*\s]+)\*(?=<\/b>|<\/i
> >|<\/code>|\s|\W\s|\W$|$)/i'
> >
> 
> Now, before giving me a headache (I always get one when reading
> regexes-- certainly one of the reasons why I wrote Spirit), how
> do you translate that in simple english?

So, you want *me* to get the headache while translating... :)

Even better than English, I'll try to convert to pseudo-Spirit

String bold;
Rule<> sol = start of line;
Rule<> nonwordchar = ~(chset_p[a-zA-Z0-9_]);
Rule<> prefix = ( sol | (sol >> nonword) | (+space_p >> nonword) | space_p |
                  "<b>" | "<i>" | "<code>" )
Rule<> wordchar = ~( '*' | space_p );
Rule<> boldtext = (( +wordchar >> +space_p ) >> +wordchar)[ assign_a(bold)]
Rule<> postfix = ( "</b>" | "</i>" | "</code>" | space_p | 
                   nonword >> space_p | nonword >> eol_p | eol_p );

Rule<> match = prefix >> '*' >> boldtext >> '*' >> postfix;

Or something like that.  Basically, so long as it's surrounded by:
1) Bold, italics, or code HTML tags
2) Whitespace
3) Start/end of line
4) Exactly one non-word character, surrounded by space
5) Exactly one non-word character, surrounded by start/end of line

The reason for rules 4, and 5 is to allow shorthand notations to combine.
So, for example, you can do /*bold italics*/ or /#italics code#/ and so
forth.  The reason for rule 1 is to accommodate previous passes of the
pattern (it can be applied multiple times).

I hope that made sense.  I'm not sure how well it translates into a one-pass
parser.

-david



-------------------------------------------------------
This SF.Net email is sponsored by: YOU BE THE JUDGE. Be one of 170
Project Admins to receive an Apple iPod Mini FREE for your judgement on
who ports your project to Linux PPC the best. Sponsored by IBM.
Deadline: Sept. 24. Go here: http://sf.net/ppc_contest.php
_______________________________________________
Boost-docs mailing list
[EMAIL PROTECTED]
Unsubscribe and other administrative requests: 
https://lists.sourceforge.net/lists/listinfo/boost-docs

Reply via email to