I've gotten a very good serious of regular expressions to go through C code and add span tags around it to colour code the syntax.
The one thing I can't figure out is how to stop it from putting span tags around something it finds within a block that has previously been marked with span tags.
For example, this regex does the pass for multiline comments:
(?<=[\r\n\s\(])([\/][\*]([^\*]|\n|[\*]+[^\*\/])*[\*]+[\/])(?=[\r\n\s:;,\)])
Gets marked as:
Then I do the next pass for one line comments:
(?<=[\r\n\s\(])(\/\/[^\n\r]*)(?=[\r\n\s:;,\)])
Which obviously results in:
But I don't want the spans to appear in a section which has already been colour coded. I thought the simple solution was to use a pair of lookahead/lookbehind assertions to check to see if the match fell within an opened but not yet closed span block, but it turns out you can't have non-fixed length strings for the patterns in lookbehind assertions.
(?<!<span class.*(?!<\/span>).*) <insert pattern> (?!.*<\/span>(?<!<span class.*))
Any help would be appreciated.
Regards,
Rob.
The one thing I can't figure out is how to stop it from putting span tags around something it finds within a block that has previously been marked with span tags.
For example, this regex does the pass for multiline comments:
(?<=[\r\n\s\(])([\/][\*]([^\*]|\n|[\*]+[^\*\/])*[\*]+[\/])(?=[\r\n\s:;,\)])
Code:
/**************** This is a test. // Testing a // testing /* comment test est ************/
Code:
<span class="code_multi">/**************** This is a test. // Testing a // testing /* comment test est ************/</span>
(?<=[\r\n\s\(])(\/\/[^\n\r]*)(?=[\r\n\s:;,\)])
Which obviously results in:
Code:
<span class="code_multi">/**************** This is a test. <span class="code_oneline">// Testing a // testing /* comment</span> test est ************/</span>
(?<!<span class.*(?!<\/span>).*) <insert pattern> (?!.*<\/span>(?<!<span class.*))
Any help would be appreciated.
Regards,
Rob.