// // CHECKPAREN.VDM C.Z. 11.12.2000 // 12.12.2000 // // Checks a text/program for properly paired parenthesis ([{}]) // // Be careful: // The macro is not foolproof!!! (As the build in Match_Paren() too.) // (It seems to be absolutely impossible to code it foolproof since // the scanned texts are so different in their syntax, especially // with escaped characters and strings, which mustn't be evaluated.) // // See also VEDIT PLUS macro language manual, // chapter 3, topic "Using '{' and '}' in string arguments" for infos. // // So this macro could only be a little help or a programming example. ;-) // // Usage: // After calling the macro it checks the whole current buffer for // properly matching braces. // If there is a pairing error found it jumps into visual mode. // Now you can correct the error. // If it's not a real error but a problem as described some lines // earlier you should do nothing here. // // Then move the cursor after the real CLOSING BRACE of the problem // and press Ctrl-E ("[VISUAL EXIT]") to let the macro continue. // // If you want the macro to quit press ESCAPE C. ("Command Mode (Escape)") // //----------------------------------------------------------------------------- BoF Num_Push(97,98) #97=0 // counter for nesting #98=File_Size // Position(s) of closing parenthesis Reg_Set(102,' // clear the stack etc. after quitting while(#97>0){ Num_Pop(98,98) #97-- } Num_Pop(97,98) Visual_Macro(NOMSG) Break_Out(DELETE+EXTRA) ') Reg_Lock_Macro(102) repeat(ALL){ Search("|{(,[,{,|},],)}",NOERR) // search parenthesis if(Error_Match){ Statline_Message("Ready. No more braces") break } if(Cur_Pos >= #98){ // if on last found closing one again Char(1) // jump after that one if(#97>0){ // update stack Num_Pop(98,98) } #97-- continue // next loop } // if found opening one, search closing if(Match("|{(,[}")==0 || Cur_Char==0x7B){ Match_Paren(NOERR) // .return_value // if(Return_Value != 2){ // if no one found => error and out if(EM){ // if no one found => error and out Alert() Statline_Message("Err! => CUR after pair! Ctrl-E") Visual Continue }else{ // if closing paren. was found Num_Push(98,98) // handle nesting #97++ #98=Cur_Pos Match_Paren() // back to the open Char(1) // into it } }else{ // if found closing one: error Alert() Statline_Message("Err! => CUR after pair! Ctrl-E") Visual Continue } } Chain(102) // end it //-----------------------------------------------------------------------