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.

64 lines
1.5 KiB

proc p_digit str {
if {[string is digit -strict [string index $str 0]]} {
return [list [string index $str 0] [string range $str 1 end]]
} else {
return [list]
}
}
proc p_char {str ch} {
if {[string index $str 0] eq $ch} {
return [list [string index $str 0] [string range $str 1 end]]
} else {
return [list]
}
}
proc parser_of_char {ch} {
pipeset outparser @@ok/result.= {
pipeswitch {
pipecase .= list $input $ch |data/0,char/1> \
,'${ch}'@0.= {p_char $data $char}
return [list ok [list result [list]]]
}
} <ch/0,input/1| $ch
}
proc some {parser} {
}
#generate a functor on a pipeline targeting a specific section of the 'value' in: ok {result value}
proc fmap {cmdlist pipeline} {
pipeset functor .= {
pipeswitch {
pipecase .= list $cmd $p $input |cmd@,pipe@,input@> \
,'result'@@ok/@0.= {
.= list $pipe $input |p@,i@> {{*}$p $i}
} |result@@ok/result> =result>1/1
return nothing-functor
}
} <cmd@,p@,input@| $cmdlist $pipeline
}
proc charP {ch} {
pipeset parser .= {
pipeswitch {
#puts "-->$input"
pipecase = $input |> \
,'${ch}'@0.= {list [string index $data 0] [string range $data 1 end] } |> {
set data
}
return nothing
}
} <ch/0,input/1| $ch
}