@@ -7,18 +7,46 @@ create or replace package body ut_annotations as
77
88 gc_annotation_qualifier constant varchar2(1) := '%';
99 c_multiline_comment_pattern constant varchar2(50) := '/\*.*?\*/';
10- c_singleline_comment_pattern constant varchar2(30) := '( |'||chr(09)||')*--( .*?)$'; -- chr(09) is a tab character
11- c_nonannotat_comment_pattern constant varchar2(30) := '( |'||chr(09)||')*-{2,}\s *[^'||gc_annotation_qualifier||']*?$';
10+ c_annot_comment_pattern constant varchar2(30) := '^ ( |'||chr(09)||')*-- *('||gc_annotation_qualifier||' .*?)$'; -- chr(09) is a tab character
11+ -- c_nonannotat_comment_pattern constant varchar2(30) := '^ ( |'||chr(09)||')*--+ *[^'||gc_annotation_qualifier||']*?$';
1212 c_comment_replacer_patter constant varchar2(50) := '{COMMENT#%N%}';
1313 c_comment_replacer_regex_ptrn constant varchar2(25) := '{COMMENT#(\d+)}';
1414 c_rgexp_identifier constant varchar2(50) := '[a-z][a-z0-9#_$]*';
15- c_annotation_block_pattern constant varchar2(200) := '(({COMMENT#\d +}'||chr(10)||')+)( |'||chr(09)||')*(procedure|function)\s+(' ||
15+ c_annotation_block_pattern constant varchar2(200) := '(({COMMENT#. +}'||chr(10)||')+)( |'||chr(09)||')*(procedure|function)\s+(' ||
1616 c_rgexp_identifier || ')';
1717 c_annotation_pattern constant varchar2(50) := gc_annotation_qualifier || c_rgexp_identifier || '(\(.*?\))?';
1818
1919
2020 function delete_multiline_comments(a_source in clob) return clob is
21+ l_tmp_clob clob;
2122 begin
23+
24+ /* l_tmp_clob := regexp_replace(srcstr => a_source
25+ ,pattern => c_multiline_comment_pattern
26+ ,modifier => 'n');
27+ l_tmp_clob := regexp_replace(srcstr => l_tmp_clob
28+ ,pattern => c_nonannotat_comment_pattern
29+ ,modifier => 'm');
30+
31+ -- performance is too low when deleting spaces as it leads to lots of writes
32+ -- l_tmp_clob := regexp_replace(srcstr => l_tmp_cl0ob
33+ -- ,pattern => '(( |'||chr(09)||')*'|| chr(10)||'){3,}'
34+ -- ,replacestr => chr(10)||chr(10));
35+ return l_tmp_clob;
36+ */
37+ return regexp_replace(srcstr => a_source
38+ ,pattern => c_multiline_comment_pattern
39+ ,modifier => 'n');
40+
41+ --this is not fast enough as the regexp parten is more complicated
42+ /*
43+ return regexp_replace(srcstr => a_source
44+ ,pattern => '('||c_multiline_comment_pattern
45+ ||'|'||c_nonannotat_comment_pattern||')'
46+ ,modifier => 'mn');
47+ */
48+
49+ /*
2250 return regexp_replace(
2351 srcstr => regexp_replace(srcstr => regexp_replace(srcstr => a_source
2452 ,pattern => c_multiline_comment_pattern
@@ -28,6 +56,7 @@ create or replace package body ut_annotations as
2856 ,replacestr => '\1'
2957 ,modifier => 'mn'
3058 );
59+ */
3160 end;
3261
3362 function get_annotations(a_source varchar2, a_comments tt_comment_list) return tt_annotations is
@@ -86,7 +115,7 @@ create or replace package body ut_annotations as
86115 ,pattern => '(' || c_rgexp_identifier || ')\s*='
87116 ,modifier => 'i'
88117 ,subexpression => 1);
89- l_param_item.value := regexp_substr(l_param_str, '(.+?=)?(.*$)', subexpression => 2);
118+ l_param_item.value := trim( regexp_substr(l_param_str, '(.+?=)?(.*$)', subexpression => 2) );
90119
91120 l_annotation_params(l_annotation_params.count + 1) := l_param_item;
92121 end;
@@ -156,7 +185,11 @@ create or replace package body ut_annotations as
156185 -- parse the comment block for the syntactically correct annotations and store them as an array
157186 l_procedure_annotations(l_proc_name) := get_annotations(l_proc_comments, a_comments);
158187
159- l_annot_proc_ind := l_annot_proc_ind + length(l_annot_proc_block);
188+ --l_annot_proc_ind := l_annot_proc_ind + length(l_annot_proc_block);
189+ l_annot_proc_ind := regexp_instr(srcstr => a_source
190+ ,pattern => ';'
191+ ,occurrence => 1
192+ ,position => l_annot_proc_ind + length(l_annot_proc_block));
160193 end loop;
161194 return l_procedure_annotations;
162195 end;
@@ -168,15 +201,20 @@ create or replace package body ut_annotations as
168201 begin
169202 l_comment_pos := 1;
170203 loop
204+
171205 l_comment_pos := regexp_instr(srcstr => a_source
172- ,pattern => c_singleline_comment_pattern
206+ ,pattern => c_annot_comment_pattern
173207 ,occurrence => 1
174208 ,modifier => 'm'
175- ,position => l_comment_pos
176- );
209+ ,position => l_comment_pos);
210+
177211 exit when l_comment_pos = 0;
212+
213+ -- position index is shifted by 1 because c_annot_comment_pattern contains ^ as first sign
214+ -- but after instr index already points to the char on that line
215+ l_comment_pos := l_comment_pos-1;
178216 l_comments(l_comments.count + 1) := trim(regexp_substr(srcstr => a_source
179- ,pattern => c_singleline_comment_pattern
217+ ,pattern => c_annot_comment_pattern
180218 ,occurrence => 1
181219 ,position => l_comment_pos
182220 ,modifier => 'm'
@@ -185,7 +223,7 @@ create or replace package body ut_annotations as
185223 l_comment_replacer := replace(c_comment_replacer_patter, '%N%', l_comments.count);
186224
187225 a_source := regexp_replace(srcstr => a_source
188- ,pattern => c_singleline_comment_pattern
226+ ,pattern => c_annot_comment_pattern
189227 ,replacestr => l_comment_replacer
190228 ,position => l_comment_pos
191229 ,occurrence => 1
0 commit comments