Talek's Paren Checker
Instructions
Copy and paste the below code into a compatible MUSH or MUX.
MUSHCode for Talek's Paren Checker
@create Paren Checker
@lock Paren Checker==me
@lset Paren Checker/Basic=no_inherit
@set Paren Checker = LINK_OK
@set Paren Checker = NO_COMMAND
&DESCRIBE Paren Checker=This is a tool to check balance of (), \{\}, and \[\] in MUSHcode. Parent an object to it, set that object !NO_COMMAND, and then use either of:%r%r pcheck obj/attr%r pshow obj/attr%r%rWildcards in the attribute are okay. The output of the two commands is similar: pcheck tells you in text were all the mismatches are, while pshow shows you graphically with ^s under the offending characters.
@set Paren Checker/DESCRIBE=no_command visual public nearby
&DO_PCHECK Paren Checker=$pcheck */*:@va me=[locate(me,%0,*)];@vb me=[switch(%va,#-*,,filter(u_attrmatch, lattr(%va/%1)))];@pemit %#=[switch(%va%vb,#-1*,No such object.,#-2*,I don't know which one you mean.,%va,No matching visible attributes.,Pairs Check for [name(%va)]\(%va[flags(%va)]\))];@dolist [iter(%vb,%va/%i0)]=@pemit %#=[u(u_pcheck,##)][switch(%q3,,,map(U_CREPORT,sort(%q3)))];
&DO_PCOLOR Paren Checker=$pcolor */*:@va me=[locate(me,%0,*)];@vb me=[switch(%va,#-*,,filter(u_attrmatch, lattr(%va/%1)))];@pemit %#=[switch(%va%vb,#-1*,No such object.,#-2*,I don't know which one you mean.,%va,No matching visible attributes.,Pairs Show for [name(%va)]\(%va[flags(%va)]\))];@dolist [iter(%vb,%va/%i0)]=@pemit %#=[u(U_PCOLORIZE,##)];
&DO_PSHOW Paren Checker=$pshow */*:@va me=[locate(me,%0,*)];@vb me=[switch(%va,#-*,,filter(u_attrmatch, lattr(%va/%1)))];@pemit %#=[switch(%va%vb,#-1*,No such object.,#-2*,I don't know which one you mean.,%va,No matching visible attributes.,Pairs Show for [name(%va)]\(%va[flags(%va)]\))];@dolist [iter(%vb,%va/%i0)]=@pemit %#=[u(u_pcheck,##)][switch(%q3,,,%r%b %q0%r [fold(U_SREPORT,sort(%q3),)])];
&U_ATTRMATCH Paren Checker=[visible(%#,%va/%0)]
&U_BAD Paren Checker=[switch(pos(%0,%q2),#-1,setq(3,strlen(%1) %q3),setq(3,iter(first(%q2,%0),rest(\##,:)) %q3)[setq(2,rest(rest(%q2,%0)))])]
&U_CREPORT Paren Checker=%r %bUnbalanced [mid(-%q0,%0,1)] at %0.
&U_PCHECK Paren Checker=[setq(0,get(%0))] [ljust(rest(%0,/):,19)][setq(1,edit(edit(edit(edit(edit(edit(edit(edit(edit(edit(edit(edit(edit(edit(edit(%q0,%%,\\),\\\\,--),|,-),\\\(,--),\\\),--),\\\[,--),\\\],--),\\\{,--),\\\},--),\(,|\(),\),|\)),\[,|\[),\],|\]),\{,|\{),\},|\}))]\{ \}: [ljust(sub(words(%q1,\{),1)/[sub(words(%q1,\}),1)],10)]\[ \]: [ljust(sub(words(%q1,\[),1)/[sub(words(%q1,\]),1)],10)]\( \): [ljust(sub(words(%q1,\(),1)/[sub(words(%q1,\)),1)],10)][setq(2,)][setq(3,)][setq(1,fold(U_PCHUNK,^%q1|$,,|))]
&U_PCHUNK Paren Checker=[switch(%1,\\\(*,setq(2,\):[strlen(%0)] %q2),\\\[*,setq(2,\]:[strlen(%0)] %q2),\\\{*,setq(2,\}:[strlen(%0)] %q2),\\\^*,setq(2,\$:0),mid(%q2,0,1)*,setq(2,rest(%q2)),u(U_BAD,mid(%1,0,1),%0))]%0%1
&U_PCOLCHUNK Paren Checker=%0[switch(%1,\\\(*,setq(2,\) %q2)[ansi(mid(%q3,words(%q2),1)h,\()][mid(%1,1,8000)],\\\[*,setq(2,\] %q2)[ansi(mid(%q3,words(%q2),1)h,\[)][mid(%1,1,8000)],\\\{*,setq(2,\} %q2)[ansi(mid(%q3,words(%q2),1)h,\{)][mid(%1,1,8000)],\\\^*,setq(2,\$)[mid(%1,1,8000)],mid(%q2,0,1)*,[ansi(mid(%q3,words(%q2),1)h,mid(%1,0,1))][mid(%1,1,8000)][setq(2,rest(%q2))],switch(pos(setq(4,mid(%1,0,1))%q4,%q2),#-1,,setq(2,rest(rest(%q2,%q4))))[ansi(rhf,%q4)][mid(%1,1,8000)])]
&U_PCOLORIZE Paren Checker=[setq(0,get(%0))] [ljust(rest(%0,/):,19)][setq(1,edit(edit(edit(edit(edit(edit(edit(edit(edit(edit(edit(edit(edit(edit(edit(%q0,%%,\\),\\\\,--),|,-),\\\(,--),\\\),--),\\\[,--),\\\],--),\\\{,--),\\\},--),\(,|\(),\),|\)),\[,|\[),\],|\]),\{,|\{),\},|\}))]\{ \}: [ljust(sub(words(%q1,\{),1)/[sub(words(%q1,\}),1)],10)]\[ \]: [ljust(sub(words(%q1,\[),1)/[sub(words(%q1,\]),1)],10)]\( \): [ljust(sub(words(%q1,\(),1)/[sub(words(%q1,\)),1)],10)][setq(2,)][setq(3,repeat(gybmc,2000))]%r[fold(U_PCOLCHUNK,^%q1|$,,|)]
&U_SREPORT Paren Checker=[ljust(%0,%1)]^
&VA Paren Checker=#-1
&VB Paren Checker=
look paren checker
@lock Paren Checker==me
@lset Paren Checker/Basic=no_inherit
@set Paren Checker = LINK_OK
@set Paren Checker = NO_COMMAND
&DESCRIBE Paren Checker=This is a tool to check balance of (), \{\}, and \[\] in MUSHcode. Parent an object to it, set that object !NO_COMMAND, and then use either of:%r%r pcheck obj/attr%r pshow obj/attr%r%rWildcards in the attribute are okay. The output of the two commands is similar: pcheck tells you in text were all the mismatches are, while pshow shows you graphically with ^s under the offending characters.
@set Paren Checker/DESCRIBE=no_command visual public nearby
&DO_PCHECK Paren Checker=$pcheck */*:@va me=[locate(me,%0,*)];@vb me=[switch(%va,#-*,,filter(u_attrmatch, lattr(%va/%1)))];@pemit %#=[switch(%va%vb,#-1*,No such object.,#-2*,I don't know which one you mean.,%va,No matching visible attributes.,Pairs Check for [name(%va)]\(%va[flags(%va)]\))];@dolist [iter(%vb,%va/%i0)]=@pemit %#=[u(u_pcheck,##)][switch(%q3,,,map(U_CREPORT,sort(%q3)))];
&DO_PCOLOR Paren Checker=$pcolor */*:@va me=[locate(me,%0,*)];@vb me=[switch(%va,#-*,,filter(u_attrmatch, lattr(%va/%1)))];@pemit %#=[switch(%va%vb,#-1*,No such object.,#-2*,I don't know which one you mean.,%va,No matching visible attributes.,Pairs Show for [name(%va)]\(%va[flags(%va)]\))];@dolist [iter(%vb,%va/%i0)]=@pemit %#=[u(U_PCOLORIZE,##)];
&DO_PSHOW Paren Checker=$pshow */*:@va me=[locate(me,%0,*)];@vb me=[switch(%va,#-*,,filter(u_attrmatch, lattr(%va/%1)))];@pemit %#=[switch(%va%vb,#-1*,No such object.,#-2*,I don't know which one you mean.,%va,No matching visible attributes.,Pairs Show for [name(%va)]\(%va[flags(%va)]\))];@dolist [iter(%vb,%va/%i0)]=@pemit %#=[u(u_pcheck,##)][switch(%q3,,,%r%b %q0%r [fold(U_SREPORT,sort(%q3),)])];
&U_ATTRMATCH Paren Checker=[visible(%#,%va/%0)]
&U_BAD Paren Checker=[switch(pos(%0,%q2),#-1,setq(3,strlen(%1) %q3),setq(3,iter(first(%q2,%0),rest(\##,:)) %q3)[setq(2,rest(rest(%q2,%0)))])]
&U_CREPORT Paren Checker=%r %bUnbalanced [mid(-%q0,%0,1)] at %0.
&U_PCHECK Paren Checker=[setq(0,get(%0))] [ljust(rest(%0,/):,19)][setq(1,edit(edit(edit(edit(edit(edit(edit(edit(edit(edit(edit(edit(edit(edit(edit(%q0,%%,\\),\\\\,--),|,-),\\\(,--),\\\),--),\\\[,--),\\\],--),\\\{,--),\\\},--),\(,|\(),\),|\)),\[,|\[),\],|\]),\{,|\{),\},|\}))]\{ \}: [ljust(sub(words(%q1,\{),1)/[sub(words(%q1,\}),1)],10)]\[ \]: [ljust(sub(words(%q1,\[),1)/[sub(words(%q1,\]),1)],10)]\( \): [ljust(sub(words(%q1,\(),1)/[sub(words(%q1,\)),1)],10)][setq(2,)][setq(3,)][setq(1,fold(U_PCHUNK,^%q1|$,,|))]
&U_PCHUNK Paren Checker=[switch(%1,\\\(*,setq(2,\):[strlen(%0)] %q2),\\\[*,setq(2,\]:[strlen(%0)] %q2),\\\{*,setq(2,\}:[strlen(%0)] %q2),\\\^*,setq(2,\$:0),mid(%q2,0,1)*,setq(2,rest(%q2)),u(U_BAD,mid(%1,0,1),%0))]%0%1
&U_PCOLCHUNK Paren Checker=%0[switch(%1,\\\(*,setq(2,\) %q2)[ansi(mid(%q3,words(%q2),1)h,\()][mid(%1,1,8000)],\\\[*,setq(2,\] %q2)[ansi(mid(%q3,words(%q2),1)h,\[)][mid(%1,1,8000)],\\\{*,setq(2,\} %q2)[ansi(mid(%q3,words(%q2),1)h,\{)][mid(%1,1,8000)],\\\^*,setq(2,\$)[mid(%1,1,8000)],mid(%q2,0,1)*,[ansi(mid(%q3,words(%q2),1)h,mid(%1,0,1))][mid(%1,1,8000)][setq(2,rest(%q2))],switch(pos(setq(4,mid(%1,0,1))%q4,%q2),#-1,,setq(2,rest(rest(%q2,%q4))))[ansi(rhf,%q4)][mid(%1,1,8000)])]
&U_PCOLORIZE Paren Checker=[setq(0,get(%0))] [ljust(rest(%0,/):,19)][setq(1,edit(edit(edit(edit(edit(edit(edit(edit(edit(edit(edit(edit(edit(edit(edit(%q0,%%,\\),\\\\,--),|,-),\\\(,--),\\\),--),\\\[,--),\\\],--),\\\{,--),\\\},--),\(,|\(),\),|\)),\[,|\[),\],|\]),\{,|\{),\},|\}))]\{ \}: [ljust(sub(words(%q1,\{),1)/[sub(words(%q1,\}),1)],10)]\[ \]: [ljust(sub(words(%q1,\[),1)/[sub(words(%q1,\]),1)],10)]\( \): [ljust(sub(words(%q1,\(),1)/[sub(words(%q1,\)),1)],10)][setq(2,)][setq(3,repeat(gybmc,2000))]%r[fold(U_PCOLCHUNK,^%q1|$,,|)]
&U_SREPORT Paren Checker=[ljust(%0,%1)]^
&VA Paren Checker=#-1
&VB Paren Checker=
look paren checker