|
|
|
package require punk
|
|
|
|
package require shellfilter
|
|
|
|
foreach d [debug names] {
|
|
|
|
#debug off $d
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
proc test1 {} {
|
|
|
|
alsoresult,data@@DATA.=\
|
|
|
|
result@1/1,returnvalue,status@0.=\
|
|
|
|
pipeswitch {
|
|
|
|
puts stderr "pre pipecase code always runs"
|
|
|
|
|
|
|
|
pipecase pipenomatchvar nomatch1 ,'p1v0'@0.= val {p1v0x b c} |> {
|
|
|
|
puts stdout "pipecase1 $data"
|
|
|
|
set data
|
|
|
|
}
|
|
|
|
|
|
|
|
# in between
|
|
|
|
puts stderr "code after unmatched but before matched will run"
|
|
|
|
|
|
|
|
pipecase pipenomatchvar nomatch2 input,'p2v1'@1.= val {x p2v1 z} |> {
|
|
|
|
puts stdout "pipecase2 $data"
|
|
|
|
return [list source pipecase2 data $data]
|
|
|
|
} |> {
|
|
|
|
string toupper $data
|
|
|
|
}
|
|
|
|
|
|
|
|
pipecase ,'p3v3'@2.= val {d e p3v3x} |> {
|
|
|
|
puts stdout "pipecase3 $data"
|
|
|
|
set data
|
|
|
|
}
|
|
|
|
|
|
|
|
puts stderr "no matches"
|
|
|
|
return nomatch
|
|
|
|
}
|
|
|
|
|
|
|
|
puts stdout "returnvalue of pipeswitch return is: $returnvalue"
|
|
|
|
puts stdout "[a+ yellow bold]nomatch var pipe1: $nomatch1[a+]"
|
|
|
|
puts stdout "nomatch destructured to 'matchinfo': [mi@@error/mismatch/matchinfo= $nomatch1]"
|
|
|
|
puts stdout "[a+ green bold]nomatch var pipe2 (empty if there was a match): $nomatch2[a+]"
|
|
|
|
puts stdout "value of pipeswitch result is: $result"
|
|
|
|
puts stdout "status of pipeswitch is: $status"
|
|
|
|
puts stdout "alsoresult:$alsoresult"
|
|
|
|
puts stdout "dict destructuring, DATA key = $data"
|
|
|
|
}
|
|
|
|
test1
|
|
|
|
|
|
|
|
puts stderr "proc test follows"
|
|
|
|
proc match_args {args} {
|
|
|
|
set arglist $args
|
|
|
|
procresult,'ok'@0.= pipeswitch {
|
|
|
|
puts stdout "----$arglist"
|
|
|
|
pipecase p1,'a'@0.= val $args |> string toupper |> {
|
|
|
|
puts stderr "p1 data:'$data'"
|
|
|
|
return [list source pipecase1 data $data]
|
|
|
|
}
|
|
|
|
|
|
|
|
pipecase p2,'x'@0,'y'@1.= val $args |> {
|
|
|
|
return [list source pipecase2 data $data]
|
|
|
|
}
|
|
|
|
|
|
|
|
pipecase p3,'x'@0.= val $args |> {
|
|
|
|
return [list source pipecase3 data [list transformed {*}$data]]
|
|
|
|
}
|
|
|
|
|
|
|
|
pipecase .= val $args |> {
|
|
|
|
puts "catchall pipe4 $data"
|
|
|
|
return $data
|
|
|
|
}
|
|
|
|
} {*}$args
|
|
|
|
#scope is ok - but pipeswitch overrides'args' so we need to either pass them in, or set another variable - Review.
|
|
|
|
}
|
|
|
|
puts "match_args a b c : [match_args a b c]"
|
|
|
|
puts "match_args x y z : [match_args x y z]"
|
|
|
|
puts "match_args x Y z : [match_args x Y z]"
|
|
|
|
puts "match_args other blah : [match_args other blah]"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|