1
EditAreaLoader.prototype.get_regexp= function(text_array){
2
//res="( |=|\\n|\\r|\\[|\\(|µ|)(";
4
for(i=0; i<text_array.length; i++){
7
//res+="("+ tab_text[i] +")";
8
//res+=tab_text[i].replace(/(\.|\?|\*|\+|\\|\(|\)|\[|\]|\{|\})/g, "\\$1");
9
res+=this.get_escaped_regexp(text_array[i]);
11
//res+=")( |\\.|:|\\{|\\(|\\)|\\[|\\]|\'|\"|\\r|\\n|\\t|$)";
19
EditAreaLoader.prototype.get_escaped_regexp= function(str){
20
return str.replace(/(\.|\?|\*|\+|\\|\(|\)|\[|\]|\}|\{|\$|\^|\|)/g, "\\$1");
23
EditAreaLoader.prototype.init_syntax_regexp= function(){
24
var lang_style= new Object();
25
for(var lang in this.load_syntax){
26
if(!this.syntax[lang]) // init the regexp if not already initialized
28
this.syntax[lang]= new Object();
29
this.syntax[lang]["keywords_reg_exp"]= new Object();
30
this.keywords_reg_exp_nb=0;
32
if(this.load_syntax[lang]['KEYWORDS']){
34
if(this.load_syntax[lang]['KEYWORD_CASE_SENSITIVE']===false)
36
for(var i in this.load_syntax[lang]['KEYWORDS']){
37
if(typeof(this.load_syntax[lang]['KEYWORDS'][i])=="function") continue;
38
this.syntax[lang]["keywords_reg_exp"][i]= new RegExp(this.get_regexp( this.load_syntax[lang]['KEYWORDS'][i] ), param);
39
this.keywords_reg_exp_nb++;
43
if(this.load_syntax[lang]['OPERATORS']){
46
for(var i in this.load_syntax[lang]['OPERATORS']){
47
if(typeof(this.load_syntax[lang]['OPERATORS'][i])=="function") continue;
50
str+=this.get_escaped_regexp(this.load_syntax[lang]['OPERATORS'][i]);
54
this.syntax[lang]["operators_reg_exp"]= new RegExp("("+str+")","g");
57
if(this.load_syntax[lang]['DELIMITERS']){
60
for(var i in this.load_syntax[lang]['DELIMITERS']){
61
if(typeof(this.load_syntax[lang]['DELIMITERS'][i])=="function") continue;
64
str+=this.get_escaped_regexp(this.load_syntax[lang]['DELIMITERS'][i]);
68
this.syntax[lang]["delimiters_reg_exp"]= new RegExp("("+str+")","g");
72
// /(("(\\"|[^"])*"?)|('(\\'|[^'])*'?)|(//(.|\r|\t)*\n)|(/\*(.|\n|\r|\t)*\*/)|(<!--(.|\n|\r|\t)*-->))/gi
73
var syntax_trace=new Array();
75
// /("(?:[^"\\]*(\\\\)*(\\"?)?)*("|$))/g
77
this.syntax[lang]["quotes"]=new Object();
78
var quote_tab= new Array();
79
if(this.load_syntax[lang]['QUOTEMARKS']){
80
for(var i in this.load_syntax[lang]['QUOTEMARKS']){
81
if(typeof(this.load_syntax[lang]['QUOTEMARKS'][i])=="function") continue;
82
var x=this.get_escaped_regexp(this.load_syntax[lang]['QUOTEMARKS'][i]);
83
this.syntax[lang]["quotes"][x]=x;
84
//quote_tab[quote_tab.length]="("+x+"(?:\\\\"+x+"|[^"+x+"])*("+x+"|$))";
85
quote_tab[quote_tab.length]="("+x+"(?:[^"+x+"\\\\]*(\\\\\\\\)*(\\\\"+x+"?)?)*("+x+"|$))";
90
this.syntax[lang]["comments"]=new Object();
91
if(this.load_syntax[lang]['COMMENT_SINGLE']){
92
for(var i in this.load_syntax[lang]['COMMENT_SINGLE']){
93
if(typeof(this.load_syntax[lang]['COMMENT_SINGLE'][i])=="function") continue;
94
var x=this.get_escaped_regexp(this.load_syntax[lang]['COMMENT_SINGLE'][i]);
95
quote_tab[quote_tab.length]="("+x+"(.|\\r|\\t)*(\\n|$))";
97
this.syntax[lang]["comments"][x]="\n";
100
// (/\*(.|[\r\n])*?\*/)
101
if(this.load_syntax[lang]['COMMENT_MULTI']){
102
for(var i in this.load_syntax[lang]['COMMENT_MULTI']){
103
if(typeof(this.load_syntax[lang]['COMMENT_MULTI'][i])=="function") continue;
104
var start=this.get_escaped_regexp(i);
105
var end=this.get_escaped_regexp(this.load_syntax[lang]['COMMENT_MULTI'][i]);
106
quote_tab[quote_tab.length]="("+start+"(.|\\n|\\r)*?("+end+"|$))";
107
syntax_trace.push(start);
108
syntax_trace.push(end);
109
this.syntax[lang]["comments"][i]=this.load_syntax[lang]['COMMENT_MULTI'][i];
112
if(quote_tab.length>0)
113
this.syntax[lang]["comment_or_quote_reg_exp"]= new RegExp("("+quote_tab.join("|")+")","gi");
115
if(syntax_trace.length>0) // /((.|\n)*?)(\\*("|'|\/\*|\*\/|\/\/|$))/g
116
this.syntax[lang]["syntax_trace_regexp"]= new RegExp("((.|\n)*?)(\\\\*("+ syntax_trace.join("|") +"|$))", "gmi");
118
if(this.load_syntax[lang]['SCRIPT_DELIMITERS']){
119
this.syntax[lang]["script_delimiters"]= new Object();
120
for(var i in this.load_syntax[lang]['SCRIPT_DELIMITERS']){
121
if(typeof(this.load_syntax[lang]['SCRIPT_DELIMITERS'][i])=="function") continue;
122
this.syntax[lang]["script_delimiters"][i]= this.load_syntax[lang]['SCRIPT_DELIMITERS'];
126
this.syntax[lang]["custom_regexp"]= new Object();
127
if(this.load_syntax[lang]['REGEXPS']){
128
for(var i in this.load_syntax[lang]['REGEXPS']){
129
if(typeof(this.load_syntax[lang]['REGEXPS'][i])=="function") continue;
130
var val= this.load_syntax[lang]['REGEXPS'][i];
131
if(!this.syntax[lang]["custom_regexp"][val['execute']])
132
this.syntax[lang]["custom_regexp"][val['execute']]= new Object();
133
this.syntax[lang]["custom_regexp"][val['execute']][i]={'regexp' : new RegExp(val['search'], val['modifiers'])
134
, 'class' : val['class']};
138
if(this.load_syntax[lang]['STYLES']){
139
lang_style[lang]= new Object();
140
for(var i in this.load_syntax[lang]['STYLES']){
141
if(typeof(this.load_syntax[lang]['STYLES'][i])=="function") continue;
142
if(typeof(this.load_syntax[lang]['STYLES'][i]) != "string"){
143
for(var j in this.load_syntax[lang]['STYLES'][i]){
144
lang_style[lang][j]= this.load_syntax[lang]['STYLES'][i][j];
147
lang_style[lang][i]= this.load_syntax[lang]['STYLES'][i];
151
// build style string
153
for(var i in lang_style[lang]){
154
if(lang_style[lang][i].length>0){
155
style+= "."+ lang +" ."+ i.toLowerCase() +" span{"+lang_style[lang][i]+"}\n";
156
style+= "."+ lang +" ."+ i.toLowerCase() +"{"+lang_style[lang][i]+"}\n";
159
this.syntax[lang]["styles"]=style;
164
editAreaLoader.waiting_loading["reg_syntax.js"]= "loaded";