Historique des modifications - Message

Message #6756

Sujet: Coloration syntaxique.


Type Date Auteur Contenu
Dernière modification 28-08-2009 21:16:25 nico
Bein c'est cool, ça nous aura pris a peu près une semaine. et maintenant on peut se reposer smile
N'hésitez pas à critiquer si quelque chose vous déplait, ou si il manque une fonctionnalité.

Voici les éléments colorés:
Les mots réservés du c++. les commentaires. Les directives de préprocesseur. Les opérateurs. Les chiffres. Les textes entre guillemets simples. Les textes entre guillemets doubles.
  • Le texte.


Récapitulatif du code:
/include/parser.php

ligne 2
  require PUN_ROOT.'include/coloration_syntaxique.php';

ligne 120
 // Look for regular code and quote tags
$c_start = strpos($text, '[Code=cpp.]');    //mod
$c_end = strpos($text, '[/Code.]');           //mod
$c_start = strpos($text, '[code.]');
$c_end = strpos($text, '[/code.]');

ligne 300
       function do_bbcode($text)
{
 $text=preg_replace_callback("#\\[Code=cpp\\](.+)\\[/Code\\]#isU","cpp",$text);        //mod


/include/coloration_syntaxique.php
    
<?php    
if (!defined('PUN'))exit;
function pregoperateurs(){      return array( '#(\\!)#is',     '#(\\|)#is',     '#(\\%)#is',     '#(\\&amp;)#is', '#(\\')#is',     '#(\\()#is',     '#(\\))#is',     '#(\\+)#is',     '#(\\,)#is',     '#(\\-)#is',     '#(\\.)#is',     '#(\\/)#is',     '#(\\;)#is',     '#(\\=)#is',     '#(\\@)#is',       '#(\\[)#is',     '#(\\])#is',     '#(\\{)#is',     '#(\\})#is',     '#(\\^)#is',     '#(\\:)#is',     '#(\\~)#is',     '#(\\")#is',     '#(\\<)#is',     '#(\\>)#is' ,    '#(\\&lt;)#is',  '#(\\&gt;)#is',  '#(\\*)#is',     '#(\\?)#is',     '#(0)#is',      '#(1)#is',      '#(2)#is',   '#(3)#is',    '#(4)#is',    '#(5)#is',    '#(6)#is',    '#(7)#is',    '#(8)#is',    '#(9)#is',    '#(\\&quot;)#is', '#( )#is');}                                                                          
function pregcryptogrammes(){   return array( '#(§¤¤¤¤¤§)#is','#(§¤¤¤¤£§)#is','#(§¤¤¤££§)#is','#(§¤¤£¤¤§)#is','#(§¤¤£¤£§)#is','#(§¤¤££¤§)#is','#(§¤¤£££§)#is','#(§¤£¤¤¤§)#is','#(§¤£¤¤£§)#is','#(§¤£¤£¤§)#is','#(§¤£¤££§)#is','#(§¤££¤¤§)#is','#(§¤££¤£§)#is','#(§¤£££¤§)#is','#(§¤££££§)#is','#(§£¤¤¤¤§)#is','#(§£¤¤¤£§)#is','#(§£¤¤£¤§)#is','#(§£¤¤££§)#is','#(§£¤£¤¤§)#is','#(§£¤£¤£§)#is','#(§£¤££¤§)#is','#(§£¤£££§)#is','#(§££¤¤£§)#is','#(§££¤£¤§)#is','#(§££¤££§)#is','#(§£££¤¤§)#is','#(§£££¤£§)#is','#(§££££¤§)#is','#(§£££££§)#is','#(§£££§)#is','#(§¤¤§)#is','#(§££¤§)#is','#(§£¤£§)#is','#(§£¤¤§)#is','#(§¤££§)#is','#(§¤£¤§)#is','#(§¤¤£§)#is','#(§¤¤¤§)#is','#(§¤£¤§)#is',   '#(§)#is');}   
function operateurs(){          return array( '!',            '|',            '%',            '&amp;',        '\\'',           '(',            ')',            '+',            ',',            '-',            '.',            '/',            ';',            '=',            '@',               '[',            ']',            '{',            '}',            '^',            ':',            '~',            '"',            '<',            '>' ,           '&lt;',         '&gt;',         '*',            '?',            '0',              '1',            '2',         '3',           '4',             '5',           '6',             '7',           '8',          '9',           '&quot;',        ' '      );}                                                                        
function cryptogrammes(){       return array( '§¤¤¤¤¤§',      '§¤¤¤¤£§',      '§¤¤¤££§',      '§¤¤£¤¤§',      '§¤¤£¤£§',      '§¤¤££¤§',      '§¤¤£££§',      '§¤£¤¤¤§',      '§¤£¤¤£§',      '§¤£¤£¤§',      '§¤£¤££§',      '§¤££¤¤§',      '§¤££¤£§',      '§¤£££¤§',      '§¤££££§',      '§£¤¤¤¤§',      '§£¤¤¤£§',      '§£¤¤£¤§',      '§£¤¤££§',      '§£¤£¤¤§',      '§£¤£¤£§',      '§£¤££¤§',      '§£¤£££§',      '§££¤¤£§',      '§££¤£¤§' ,     '§££¤££§',      '§£££¤¤§',      '§£££¤£§',      '§££££¤§',      '§£££££§',      '§£££§',        '§¤¤§',     '§££¤§',       '§£¤£§',         '§£¤¤§',       '§¤££§',         '§¤£¤§',       '§¤¤£§',      '§¤¤¤§',       '§¤£¤§',         '§'      );}              
function hide($matches){        return preg_replace(pregoperateurs(),cryptogrammes(),$matches[0]);}
function hide2($matches){       return $matches[1].preg_replace(pregoperateurs(),cryptogrammes(),$matches[2]).$matches[3];}
function hide3($matches){       return '§£¤§'.preg_replace(pregoperateurs(),cryptogrammes(),$matches[2]).'§£¤§';}
function dev($matches){         return preg_replace(pregcryptogrammes(),operateurs(),$matches[0]);}
function cpp($matches){    
    $matches[1]=preg_replace_callback('#(//|// )(.+)(\
)#isU',"hide",$matches[1]);                                                                                           //cacher    commentaires //
    $matches[1]=preg_replace_callback('#(/\\*|/\\* )(.*)(\\*/)#isU',"hide",$matches[1]);                                                                                        //cacher    commentaires /*
    $matches[1]=preg_replace_callback('#(\
*)(.+)(\\\\\\ *\
)#',"hide",$matches[1]);                                                                                            //cacher directives         \\                        
    $matches[1]=preg_replace_callback('#(\\\\\\ *\
)(.+)(; *\
|} *\
|\\) *\
)#',"hide",$matches[1]);                                                                                    //cacher directives
    $matches[1]=preg_replace_callback('#(\\#include|\\#ifndef|\\#define|\\#if|\\#else|\\#elif)(.*)(\
)#isU','hide',$matches[1]);                                                          //cacher directives inline
    $matches[1]=preg_replace_callback('#(?<!div class=)(\\&quot;)(.*)(\\&quot;)#isU',"hide3", $matches[1]);                                                                    //cacher guillemets doubles
   	$matches[1]=preg_replace_callback('#(?<!div class=)(\\')(.*)(\\')#isU',"hide2", $matches[1]);                                                                              //cacher guillemets simples    
    $matches[1]=preg_replace('#(?<!&quot)(?<!&lt)(?<!&gt)(?<!&amp)(;|\\,|\\(|\\)|\\{|\\}|\\[|\\]|\\+|\\-|\\=|^|\\:|\\&lt;|\\&gt;|\\&amp;|\\*|/|!|%|@|\\.|\\^|\\~|\\?)#isU','<span class="operateurs">$1</span>', $matches[1]);        //colorer operateurs    
    $matches[1]=preg_replace('#([^a-zA-Z0-9§£¤_\\#])(for|while|if|else|switch|case|break|default|return|printf|struct|class|public|private|new|delete|asm|auto|catch|const|continue|do|enum|extern|explicit|exit|friend|goto|inline|protected|register|signed|sizeof|static|this|try|typedef|using|virtual|volatile|printf)([^a-zA-Z0-9§£¤=_])#isU','$1<span class="mots_cles">$2</span>$3', $matches[1]);
    $matches[1]=preg_replace('#([^a-zA-Z0-9§£¤_])(namespace|true|false|void|int|char|double|float|unsigned|signed|bool|long)([^a-zA-Z0-9_])#isU','$1<span class="mots_cles">$2</span>$3', $matches[1]);                                     //colorer mots cles    
    $matches[1]=preg_replace('#( |\\(|\\=|\\*|\\.|,|\\+\\-\\/|<|>|\\[)([0-9]++)(?![a-eg-zA-EG-Z])#isU','$1<span class="chiffres">$2</span>', $matches[1]);                           //colorer chiffres    
    $matches[1]=preg_replace('#(?<!div class=)(\\')(.*)(\\')#isU','<span class="guillemetsimple">$1$2$3</span>', $matches[1]);                                                 //colorer guillemets simples    
    $matches[1]=preg_replace('#(§£¤§)(.*)(§£¤§)#isU','&quot;$2&quot;', $matches[1]);   
    $matches[1]=preg_replace('#(?<!div class=)(\\&quot;)(.*)(\\&quot;)#isU','<span class="guillemetdouble">$1$2$3</span>', $matches[1]);                                       //colorer guillemets doubles
    $matches[1]=preg_replace(pregcryptogrammes(),operateurs(), $matches[1]);                                                                                                 //dévoiler tout le monde    
    $matches[1]=preg_replace('#(\\#include|\\#ifndef|\\#define|\\#if|\\#else|\\#elif)(.*)(\
)#isU','<span class="directives">$1$2$3</span>',$matches[1]);                                 //colorer directives inline    
    $matches[1]=preg_replace('#(\\#endif)#isU','<span class="directives">$1</span>',$matches[1]);                                                                             //colorer directives inline    
    $matches[1]=preg_replace('#(\\\\\\)( *\
)(.+)(;|}|\\))( *\
)#isU','$1$2<span class="directives">$3$4</span>$5', $matches[1]);                                                   //colorer directives
    $matches[1]=preg_replace('#(/\\*|/\\* )(.*)(\\*/)#isU','<span class="commentaires">$1$2$3</span>', $matches[1]);                                                            //colorer commentaires  /*    
    $matches[1]=preg_replace('#(?<!http:)(//)(?!http://)(.*)(\
)#isU','<span class="commentaires">$1$2</span>$3', $matches[1]);                                              //colorer commentaires  //        
 return '<div class="codebox" ><div class="incqbox"><h4>Code c++ :</h4><div class="texte" style="font-family:monospace; FONT-SIZE: 1.1em">'.$matches[1].'</div></div></div>';}                                               //encadrer le code
?>


/style/imports/Mercury_cs.css
[quote].mots_cles{color:3288cb;}
.commentaires{color 898989;}
.directives{color:44a444;}
.operateurs{color:e16644;}
.guillemetsimple{color:898989;}
.guillemetdouble{color:898989;}
.chiffres{color:ccaa77;}
.texte{color:}

[/quote]
Test de coloration:

Code c++ :


#define TEST()   printf("Coloration Syntaxique"); 

//exemple
int main(int argc, char *argv[])
{
    TEST()

    return 0;
}

Création du message 15-08-2009 18:48:39 nico
Bein c'est cool, ça nous aura pris a peu près une semaine. et maintenant on peut se reposer smile
N'hésitez pas à critiquer si quelque chose vous déplait, ou si il manque une fonctionnalité.

Voici les éléments colorés:
Les mots réservés du c++. les commentaires. Les directives de préprocesseur. Les opérateurs. Les chiffres. Les textes entre guillemets simples. Les textes entre guillemets doubles.
  • Le texte.


Récapitulatif du code:
/include/parser.php

ligne 2
  require PUN_ROOT.'include/coloration_syntaxique.php';

ligne 120
 // Look for regular code and quote tags
$c_start = strpos($text, '[Code=cpp.]');    //mod
$c_end = strpos($text, '[/Code.]');           //mod
$c_start = strpos($text, '[code.]');
$c_end = strpos($text, '[/code.]');

ligne 300
       function do_bbcode($text)
{
 $text=preg_replace_callback("#\\[Code=cpp\\](.+)\\[/Code\\]#isU","cpp",$text);        //mod


/include/coloration_syntaxique.php
    
<?php    
if (!defined('PUN'))exit;
function pregoperateurs(){      return array( '#(\\!)#is',     '#(\\|)#is',     '#(\\%)#is',     '#(\\&amp;)#is', '#(\\')#is',     '#(\\()#is',     '#(\\))#is',     '#(\\+)#is',     '#(\\,)#is',     '#(\\-)#is',     '#(\\.)#is',     '#(\\/)#is',     '#(\\;)#is',     '#(\\=)#is',     '#(\\@)#is',       '#(\\[)#is',     '#(\\])#is',     '#(\\{)#is',     '#(\\})#is',     '#(\\^)#is',     '#(\\:)#is',     '#(\\~)#is',     '#(\\")#is',     '#(\\<)#is',     '#(\\>)#is' ,    '#(\\&lt;)#is',  '#(\\&gt;)#is',  '#(\\*)#is',     '#(\\?)#is',     '#(0)#is',      '#(1)#is',      '#(2)#is',   '#(3)#is',    '#(4)#is',    '#(5)#is',    '#(6)#is',    '#(7)#is',    '#(8)#is',    '#(9)#is',    '#(\\&quot;)#is', '#( )#is');}                                                                          
function pregcryptogrammes(){   return array( '#(§¤¤¤¤¤§)#is','#(§¤¤¤¤£§)#is','#(§¤¤¤££§)#is','#(§¤¤£¤¤§)#is','#(§¤¤£¤£§)#is','#(§¤¤££¤§)#is','#(§¤¤£££§)#is','#(§¤£¤¤¤§)#is','#(§¤£¤¤£§)#is','#(§¤£¤£¤§)#is','#(§¤£¤££§)#is','#(§¤££¤¤§)#is','#(§¤££¤£§)#is','#(§¤£££¤§)#is','#(§¤££££§)#is','#(§£¤¤¤¤§)#is','#(§£¤¤¤£§)#is','#(§£¤¤£¤§)#is','#(§£¤¤££§)#is','#(§£¤£¤¤§)#is','#(§£¤£¤£§)#is','#(§£¤££¤§)#is','#(§£¤£££§)#is','#(§££¤¤£§)#is','#(§££¤£¤§)#is','#(§££¤££§)#is','#(§£££¤¤§)#is','#(§£££¤£§)#is','#(§££££¤§)#is','#(§£££££§)#is','#(§£££§)#is','#(§¤¤§)#is','#(§££¤§)#is','#(§£¤£§)#is','#(§£¤¤§)#is','#(§¤££§)#is','#(§¤£¤§)#is','#(§¤¤£§)#is','#(§¤¤¤§)#is','#(§¤£¤§)#is',   '#(§)#is');}   
function operateurs(){          return array( '!',            '|',            '%',            '&amp;',        '\\'',           '(',            ')',            '+',            ',',            '-',            '.',            '/',            ';',            '=',            '@',               '[',            ']',            '{',            '}',            '^',            ':',            '~',            '"',            '<',            '>' ,           '&lt;',         '&gt;',         '*',            '?',            '0',              '1',            '2',         '3',           '4',             '5',           '6',             '7',           '8',          '9',           '&quot;',        ' '      );}                                                                        
function cryptogrammes(){       return array( '§¤¤¤¤¤§',      '§¤¤¤¤£§',      '§¤¤¤££§',      '§¤¤£¤¤§',      '§¤¤£¤£§',      '§¤¤££¤§',      '§¤¤£££§',      '§¤£¤¤¤§',      '§¤£¤¤£§',      '§¤£¤£¤§',      '§¤£¤££§',      '§¤££¤¤§',      '§¤££¤£§',      '§¤£££¤§',      '§¤££££§',      '§£¤¤¤¤§',      '§£¤¤¤£§',      '§£¤¤£¤§',      '§£¤¤££§',      '§£¤£¤¤§',      '§£¤£¤£§',      '§£¤££¤§',      '§£¤£££§',      '§££¤¤£§',      '§££¤£¤§' ,     '§££¤££§',      '§£££¤¤§',      '§£££¤£§',      '§££££¤§',      '§£££££§',      '§£££§',        '§¤¤§',     '§££¤§',       '§£¤£§',         '§£¤¤§',       '§¤££§',         '§¤£¤§',       '§¤¤£§',      '§¤¤¤§',       '§¤£¤§',         '§'      );}              
function hide($matches){        return preg_replace(pregoperateurs(),cryptogrammes(),$matches[0]);}
function hide2($matches){       return $matches[1].preg_replace(pregoperateurs(),cryptogrammes(),$matches[2]).$matches[3];}
function hide3($matches){       return '§£¤§'.preg_replace(pregoperateurs(),cryptogrammes(),$matches[2]).'§£¤§';}
function dev($matches){         return preg_replace(pregcryptogrammes(),operateurs(),$matches[0]);}
function cpp($matches){    
    $matches[1]=preg_replace_callback('#(//|// )(.+)(\
)#isU',"hide",$matches[1]);                                                                                           //cacher    commentaires //
    $matches[1]=preg_replace_callback('#(/\\*|/\\* )(.*)(\\*/)#isU',"hide",$matches[1]);                                                                                        //cacher    commentaires /*
    $matches[1]=preg_replace_callback('#(\
*)(.+)(\\\\\\ *\
)#',"hide",$matches[1]);                                                                                            //cacher directives         \\                        
    $matches[1]=preg_replace_callback('#(\\\\\\ *\
)(.+)(; *\
|} *\
|\\) *\
)#',"hide",$matches[1]);                                                                                    //cacher directives
    $matches[1]=preg_replace_callback('#(\\#include|\\#ifndef|\\#define|\\#if|\\#else|\\#elif)(.*)(\
)#isU','hide',$matches[1]);                                                          //cacher directives inline
    $matches[1]=preg_replace_callback('#(?<!div class=)(\\&quot;)(.*)(\\&quot;)#isU',"hide3", $matches[1]);                                                                    //cacher guillemets doubles
   	$matches[1]=preg_replace_callback('#(?<!div class=)(\\')(.*)(\\')#isU',"hide2", $matches[1]);                                                                              //cacher guillemets simples    
    $matches[1]=preg_replace('#(?<!&quot)(?<!&lt)(?<!&gt)(?<!&amp)(;|\\,|\\(|\\)|\\{|\\}|\\[|\\]|\\+|\\-|\\=|^|\\:|\\&lt;|\\&gt;|\\&amp;|\\*|/|!|%|@|\\.|\\^|\\~|\\?)#isU','<span class="operateurs">$1</span>', $matches[1]);        //colorer operateurs    
    $matches[1]=preg_replace('#([^a-zA-Z0-9§£¤_\\#])(for|while|if|else|switch|case|break|default|return|printf|struct|class|public|private|new|delete|asm|auto|catch|const|continue|do|enum|extern|explicit|exit|friend|goto|inline|protected|register|signed|sizeof|static|this|try|typedef|using|virtual|volatile|printf)([^a-zA-Z0-9§£¤=_])#isU','$1<span class="mots_cles">$2</span>$3', $matches[1]);
    $matches[1]=preg_replace('#([^a-zA-Z0-9§£¤_])(namespace|true|false|void|int|char|double|float|unsigned|signed|bool|long)([^a-zA-Z0-9_])#isU','$1<span class="mots_cles">$2</span>$3', $matches[1]);                                     //colorer mots cles    
    $matches[1]=preg_replace('#( |\\(|\\=|\\*|\\.|,|\\+\\-\\/|<|>|\\[)([0-9]++)(?![a-eg-zA-EG-Z])#isU','$1<span class="chiffres">$2</span>', $matches[1]);                           //colorer chiffres    
    $matches[1]=preg_replace('#(?<!div class=)(\\')(.*)(\\')#isU','<span class="guillemetsimple">$1$2$3</span>', $matches[1]);                                                 //colorer guillemets simples    
    $matches[1]=preg_replace('#(§£¤§)(.*)(§£¤§)#isU','&quot;$2&quot;', $matches[1]);   
    $matches[1]=preg_replace('#(?<!div class=)(\\&quot;)(.*)(\\&quot;)#isU','<span class="guillemetdouble">$1$2$3</span>', $matches[1]);                                       //colorer guillemets doubles
    $matches[1]=preg_replace(pregcryptogrammes(),operateurs(), $matches[1]);                                                                                                 //dévoiler tout le monde    
    $matches[1]=preg_replace('#(\\#include|\\#ifndef|\\#define|\\#if|\\#else|\\#elif)(.*)(\
)#isU','<span class="directives">$1$2$3</span>',$matches[1]);                                 //colorer directives inline    
    $matches[1]=preg_replace('#(\\#endif)#isU','<span class="directives">$1</span>',$matches[1]);                                                                             //colorer directives inline    
    $matches[1]=preg_replace('#(\\\\\\)( *\
)(.+)(;|}|\\))( *\
)#isU','$1$2<span class="directives">$3$4</span>$5', $matches[1]);                                                   //colorer directives
    $matches[1]=preg_replace('#(/\\*|/\\* )(.*)(\\*/)#isU','<span class="commentaires">$1$2$3</span>', $matches[1]);                                                            //colorer commentaires  /*    
    $matches[1]=preg_replace('#(?<!http:)(//)(?!http://)(.*)(\
)#isU','<span class="commentaires">$1$2</span>$3', $matches[1]);                                              //colorer commentaires  //        
 return '<div class="codebox" ><div class="incqbox"><h4>Code c++ :</h4><div class="texte" style="font-family:monospace; FONT-SIZE: 1.1em">'.$matches[1].'</div></div></div>';}                                               //encadrer le code
?>


/style/imports/Mercury_cs.css
[quote].mots_cles{color:3288cb;}
.commentaires{color 898989;}
.directives{color:44a444;}
.operateurs{color:e16644;}
.guillemetsimple{color:898989;}
.guillemetdouble{color:898989;}
.chiffres{color:ccaa77;}
.texte{color:}

[/quote]
Test de coloration:

Code c++ :


#define TEST()   printf("Coloration Syntaxique"); 

//exemple
int main(int argc, char *argv[])
{
    TEST()

    return 0;
}


Retour

Options Liens officiels Caractéristiques Statistiques Communauté
Préférences cookies
Corrections
irrlicht
irrklang
irredit
irrxml
Propulsé par Django
xhtml 1.0
css 2.1
884 membres
1440 sujets
11337 messages
Dernier membre inscrit: Saidov17
266 invités en ligne
membre en ligne: -
RSS Feed