1 EditAreaLoader.prototype.get_regexp= function(text_array){
\r
2 //res="( |=|\\n|\\r|\\[|\\(|ยต|)(";
\r
4 for(i=0; i<text_array.length; i++){
\r
7 //res+="("+ tab_text[i] +")";
\r
8 //res+=tab_text[i].replace(/(\.|\?|\*|\+|\\|\(|\)|\[|\]|\{|\})/g, "\\$1");
\r
9 res+=this.get_escaped_regexp(text_array[i]);
\r
11 //res+=")( |\\.|:|\\{|\\(|\\)|\\[|\\]|\'|\"|\\r|\\n|\\t|$)";
\r
13 reg= new RegExp(res);
\r
19 EditAreaLoader.prototype.get_escaped_regexp= function(str){
\r
20 return str.toString().replace(/(\.|\?|\*|\+|\\|\(|\)|\[|\]|\}|\{|\$|\^|\|)/g, "\\$1");
\r
23 EditAreaLoader.prototype.init_syntax_regexp= function(){
\r
24 var lang_style= {};
\r
25 for(var lang in this.load_syntax){
\r
26 if(!this.syntax[lang]) // init the regexp if not already initialized
\r
28 this.syntax[lang]= {};
\r
29 this.syntax[lang]["keywords_reg_exp"]= {};
\r
30 this.keywords_reg_exp_nb=0;
\r
32 if(this.load_syntax[lang]['KEYWORDS']){
\r
34 if(this.load_syntax[lang]['KEYWORD_CASE_SENSITIVE']===false)
\r
36 for(var i in this.load_syntax[lang]['KEYWORDS']){
\r
37 if(typeof(this.load_syntax[lang]['KEYWORDS'][i])=="function") continue;
\r
38 this.syntax[lang]["keywords_reg_exp"][i]= new RegExp(this.get_regexp( this.load_syntax[lang]['KEYWORDS'][i] ), param);
\r
39 this.keywords_reg_exp_nb++;
\r
43 if(this.load_syntax[lang]['OPERATORS']){
\r
46 for(var i in this.load_syntax[lang]['OPERATORS']){
\r
47 if(typeof(this.load_syntax[lang]['OPERATORS'][i])=="function") continue;
\r
50 str+=this.get_escaped_regexp(this.load_syntax[lang]['OPERATORS'][i]);
\r
54 this.syntax[lang]["operators_reg_exp"]= new RegExp("("+str+")","g");
\r
57 if(this.load_syntax[lang]['DELIMITERS']){
\r
60 for(var i in this.load_syntax[lang]['DELIMITERS']){
\r
61 if(typeof(this.load_syntax[lang]['DELIMITERS'][i])=="function") continue;
\r
64 str+=this.get_escaped_regexp(this.load_syntax[lang]['DELIMITERS'][i]);
\r
68 this.syntax[lang]["delimiters_reg_exp"]= new RegExp("("+str+")","g");
\r
72 // /(("(\\"|[^"])*"?)|('(\\'|[^'])*'?)|(//(.|\r|\t)*\n)|(/\*(.|\n|\r|\t)*\*/)|(<!--(.|\n|\r|\t)*-->))/gi
\r
73 var syntax_trace=[];
\r
75 // /("(?:[^"\\]*(\\\\)*(\\"?)?)*("|$))/g
\r
77 this.syntax[lang]["quotes"]={};
\r
79 if(this.load_syntax[lang]['QUOTEMARKS']){
\r
80 for(var i in this.load_syntax[lang]['QUOTEMARKS']){
\r
81 if(typeof(this.load_syntax[lang]['QUOTEMARKS'][i])=="function") continue;
\r
82 var x=this.get_escaped_regexp(this.load_syntax[lang]['QUOTEMARKS'][i]);
\r
83 this.syntax[lang]["quotes"][x]=x;
\r
84 //quote_tab[quote_tab.length]="("+x+"(?:\\\\"+x+"|[^"+x+"])*("+x+"|$))";
\r
85 //previous working : quote_tab[quote_tab.length]="("+x+"(?:[^"+x+"\\\\]*(\\\\\\\\)*(\\\\"+x+"?)?)*("+x+"|$))";
\r
86 quote_tab[quote_tab.length]="("+ x +"(\\\\.|[^"+ x +"])*(?:"+ x +"|$))";
\r
88 syntax_trace.push(x);
\r
92 this.syntax[lang]["comments"]={};
\r
93 if(this.load_syntax[lang]['COMMENT_SINGLE']){
\r
94 for(var i in this.load_syntax[lang]['COMMENT_SINGLE']){
\r
95 if(typeof(this.load_syntax[lang]['COMMENT_SINGLE'][i])=="function") continue;
\r
96 var x=this.get_escaped_regexp(this.load_syntax[lang]['COMMENT_SINGLE'][i]);
\r
97 quote_tab[quote_tab.length]="("+x+"(.|\\r|\\t)*(\\n|$))";
\r
98 syntax_trace.push(x);
\r
99 this.syntax[lang]["comments"][x]="\n";
\r
102 // (/\*(.|[\r\n])*?\*/)
\r
103 if(this.load_syntax[lang]['COMMENT_MULTI']){
\r
104 for(var i in this.load_syntax[lang]['COMMENT_MULTI']){
\r
105 if(typeof(this.load_syntax[lang]['COMMENT_MULTI'][i])=="function") continue;
\r
106 var start=this.get_escaped_regexp(i);
\r
107 var end=this.get_escaped_regexp(this.load_syntax[lang]['COMMENT_MULTI'][i]);
\r
108 quote_tab[quote_tab.length]="("+start+"(.|\\n|\\r)*?("+end+"|$))";
\r
109 syntax_trace.push(start);
\r
110 syntax_trace.push(end);
\r
111 this.syntax[lang]["comments"][i]=this.load_syntax[lang]['COMMENT_MULTI'][i];
\r
114 if(quote_tab.length>0)
\r
115 this.syntax[lang]["comment_or_quote_reg_exp"]= new RegExp("("+quote_tab.join("|")+")","gi");
\r
117 if(syntax_trace.length>0) // /((.|\n)*?)(\\*("|'|\/\*|\*\/|\/\/|$))/g
\r
118 this.syntax[lang]["syntax_trace_regexp"]= new RegExp("((.|\n)*?)(\\\\*("+ syntax_trace.join("|") +"|$))", "gmi");
\r
120 if(this.load_syntax[lang]['SCRIPT_DELIMITERS']){
\r
121 this.syntax[lang]["script_delimiters"]= {};
\r
122 for(var i in this.load_syntax[lang]['SCRIPT_DELIMITERS']){
\r
123 if(typeof(this.load_syntax[lang]['SCRIPT_DELIMITERS'][i])=="function") continue;
\r
124 this.syntax[lang]["script_delimiters"][i]= this.load_syntax[lang]['SCRIPT_DELIMITERS'];
\r
128 this.syntax[lang]["custom_regexp"]= {};
\r
129 if(this.load_syntax[lang]['REGEXPS']){
\r
130 for(var i in this.load_syntax[lang]['REGEXPS']){
\r
131 if(typeof(this.load_syntax[lang]['REGEXPS'][i])=="function") continue;
\r
132 var val= this.load_syntax[lang]['REGEXPS'][i];
\r
133 if(!this.syntax[lang]["custom_regexp"][val['execute']])
\r
134 this.syntax[lang]["custom_regexp"][val['execute']]= {};
\r
135 this.syntax[lang]["custom_regexp"][val['execute']][i]={'regexp' : new RegExp(val['search'], val['modifiers'])
\r
136 , 'class' : val['class']};
\r
140 if(this.load_syntax[lang]['STYLES']){
\r
141 lang_style[lang]= {};
\r
142 for(var i in this.load_syntax[lang]['STYLES']){
\r
143 if(typeof(this.load_syntax[lang]['STYLES'][i])=="function") continue;
\r
144 if(typeof(this.load_syntax[lang]['STYLES'][i]) != "string"){
\r
145 for(var j in this.load_syntax[lang]['STYLES'][i]){
\r
146 lang_style[lang][j]= this.load_syntax[lang]['STYLES'][i][j];
\r
149 lang_style[lang][i]= this.load_syntax[lang]['STYLES'][i];
\r
153 // build style string
\r
155 for(var i in lang_style[lang]){
\r
156 if(lang_style[lang][i].length>0){
\r
157 style+= "."+ lang +" ."+ i.toLowerCase() +" span{"+lang_style[lang][i]+"}\n";
\r
158 style+= "."+ lang +" ."+ i.toLowerCase() +"{"+lang_style[lang][i]+"}\n";
\r
161 this.syntax[lang]["styles"]=style;
\r
166 editAreaLoader.waiting_loading["reg_syntax.js"]= "loaded";
\r