if { [regexp {rise_constraints|fall_constraint} $line] }
Doesn't work because there is no rise_constraints
in the lines. There is rise_constraint
with no s
.
Also, try to better indent your code next time.
Вопрос
I did a little reading up and realized the pipe symbol | can be used like "or" logic when matching. I've tried to incorporate this in my following code but it doesn't work in doing some text processing that follows regexp (see snippet code below file format) . First here's my file type (.lib used in chip design)
pin (d) {
direction : input;
nextstate_type : data;
related_ground_pin : vss;
related_power_pin : vcc;
max_transition : 0.4;
capacitance : 0.000719782;
rise_capacitance : 0.000719782;
rise_capacitance_range (0.000462301, 0.000719782);
fall_capacitance : 0.000569233;
fall_capacitance_range (0.000459043, 0.000569233);
timing () {
related_pin : "clk";
timing_type : setup_rising;
rise_constraint (constraint_template_5X5) {
index_1 ("0.01, 0.05, 0.12, 0.2, 0.4");
index_2 ("0.005, 0.025, 0.06, 0.1, 0.3");
index_3 ("0.084, 0.84, 3.36, 8.4, 13.44") ;
values ( \
"5.1,1.2,1.3,1.4,1.5", \
"9.1,2.2,2.3,2.4,2.5", \
"3.1,3.2,3.3,3.4,3.5", \
"4.1,4.2,4.3,4.4,4.5", \
"5.1,5.2,5.3,5.4,5.5", \
"6.1,6.2,6.3,6.4,6.5", \
"7.1,7.2,7.3,7.4,7.5", \
"8.1,8.2,8.3,8.4,8.5", \
"9.1,9.2,9.3,9.4,9.5", \
"10.1,10.2,10.3,10.4,10.5", \
"11.1,11.2,11.3,11.4,11.5", \
"12.1,12.2,12.3,12.4,12.5", \
"13.1,13.2,13.3,13.4,13.5", \
"14.1,14.2,14.3,14.4,14.5", \
"15.1,15.2,15.3,15.4,15.5", \
"16.1,16.2,16.3,16.4,16.5", \
"17.1,17.2,17.3,17.4,17.5", \
"18.1,18.2,18.3,18.4,18.5", \
"19.1,19.2,19.3,19.4,19.5", \
"20.1,20.2,20.3,20.4,20.5", \
"21.1,21.2,21.3,21.4,21.5", \
"22.1,22.2,22.3,22.4,22.5", \
"23.1,23.2,23.3,23.4,23.5", \
"24.1,24.2,24.3,24.4,24.5", \
"25.1,25.2,25.3,25.4,25.5", \
);
}
fall_constraint (constraint_template_5X5) {
index_1 ("0.01, 0.05, 0.12, 0.2, 0.4");
index_2 ("0.005, 0.025, 0.06, 0.1, 0.3");
index_3 ("0.084, 0.84, 3.36, 8.4, 13.44") ;
values ( \
"1.1,1.2,1.3,1.4,1.5", \
"2.1,2.2,2.3,2.4,2.5", \
"3.1,3.2,3.3,3.4,3.5", \
"4.1,4.2,4.3,4.4,4.5", \
"5.1,5.2,5.3,5.4,5.5", \
"6.1,6.2,6.3,6.4,6.5", \
"7.1,7.2,7.3,7.4,7.5", \
"8.1,8.2,8.3,8.4,8.5", \
"9.1,9.2,9.3,9.4,9.5", \
"10.1,10.2,10.3,10.4,10.5", \
"11.1,11.2,11.3,11.4,11.5", \
"12.1,12.2,12.3,12.4,12.5", \
"13.1,13.2,13.3,13.4,13.5", \
"14.1,14.2,14.3,14.4,14.5", \
"15.1,15.2,15.3,15.4,15.5", \
"16.1,16.2,16.3,16.4,16.5", \
"17.1,17.2,17.3,17.4,17.5", \
"18.1,18.2,18.3,18.4,18.5", \
"19.1,19.2,19.3,19.4,19.5", \
"20.1,20.2,20.3,20.4,20.5", \
"21.1,21.2,21.3,21.4,21.5", \
"22.1,22.2,22.3,22.4,22.5", \
"23.1,23.2,23.3,23.4,23.5", \
"24.1,24.2,24.3,24.4,24.5", \
"25.1,25.2,25.3,25.4,25.5", \
);
}
}
}
Ok, so I have to do some text processing (aided by Brad Lanam - user of SO) which is done as follows. The aim of this piece of code is to zero in on the right types of constraints (in my .lib) to do text processing.
set inFile [open "C:/Tcl/official/ref.lib" r]
set inval false
set foundValues 0
set found_setup 0
set found_fall 0
set extract1 0
set extract2 0
set DETECT_END_SYNTAX {\);}
while { [gets $inFile line] >= 0 } {
if { [regexp {setup_rising;} $line] } { set found_setup 1 }
if { [regexp {hold_rising;} $line] } { set found_setup 0 }
if { $found_setup } {
if { [regexp {rise_constraint|fall_constraint} $line] } { set found_fall 1 }
if { $found_fall } {
if {[regexp {values} $line]} {
set foundValues 1
}
if {$foundValues} {
if { [regexp $DETECT_END_SYNTAX $line] } {
if { $inval } {
set inval false
set foundValues 0
set found_fall 0
}
}
}
}
}
}
# { Do text processing after this }
But
if { [regexp {rise_constraint|fall_constraint} $line] }
# Does NOT work
in matching either rise_constraint
or fall_constraint
to do some regsub
commands. My code only ends up processing values for rise_constraint
in the modified file written out. I need the values of both constraint types to be changed. Am I doing something wrong in the regexp? Thanks!
Should I just do this:
if { [regexp {rise_constraint} $line] } { set found_fall 1 }
if { [regexp {fall_constraint} $line] } { set found_fall 1 }
Instead of:
if { [regexp {rise_constraint|fall_constraint} $line] } { set found_fall 1 }
Note: found_fall
actually will find even the rise_constraint
values, it's just a variable.
Reference: tcl text processing - rearrange values in rows and columns based on user defined value
Решение
if { [regexp {rise_constraints|fall_constraint} $line] }
Doesn't work because there is no rise_constraints
in the lines. There is rise_constraint
with no s
.
Also, try to better indent your code next time.