You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
77 lines
2.0 KiB
77 lines
2.0 KiB
1 year ago
|
package require punk
|
||
|
|
||
|
proc test1 {} {
|
||
|
alsoresult,data@@DATA.=\
|
||
|
result@1/1,returnvalue,status@0.= pipeswitch {
|
||
|
puts stderr "pre pipecase code always runs"
|
||
|
|
||
|
pipecase ,'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 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 "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
|
||
|
test1
|
||
|
|
||
|
puts stderr "proc test follows"
|
||
|
proc match_args {args} {
|
||
|
procresult,'ok@0.= pipeswitch {
|
||
|
pipecase p1,'a@0.= val $args |> string toupper |> {
|
||
|
|
||
|
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"
|
||
|
return $data
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
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]"
|
||
|
|
||
|
|
||
|
|
||
|
|
||
|
|
||
|
|
||
|
|
||
|
|
||
|
|
||
|
|
||
|
|