O7 ProcedureTextLine
Kelly Burgess
kellyb at montana.com
Wed Dec 11 22:53:53 EST 2013
Stephen wrote:
>It is certainly possible. I even have some code somewhere that indents the
>lines for the loop statements etc. Sorry I cant put my hands on it straight away.
I found some old Leon Venter code for doing that - it's returning a 3-column list, with straight line text in the first column for doing comparisons, the formatted line text in the second column for display purposes, and a flag in the third column for use in later comparisons. Adjust as needed (e.g. sys(6)='M' is outdated), and thank Good Ol' Leon Venter.
Kelly
##### Method 'FormatProcText' #####
No. Parameter Type Subtype
1 pLines Field reference
2 pText Character 100000000
No. Local Variable Type Subtype Init.Val/Calc
1 lineText Character 10000
2 compareText Character 10000
3 displayText Character 10000
4 caseStack Character 100 ''
5 kDelim Character 2 pick(sys(6)='M',chr(13,10),chr(13))
6 indent Long integer 0
7 lineMatch Boolean kFalse
8 case Boolean kFalse
No. Method text
1
2
3 Begin reversible block
4 Set current list pLines
5 End reversible block
6 Define list {compareText,displayText,lineMatch}
7 Calculate pText as con(pText,pick(len(pText)>0,'',kDelim)) ;; Add a line delimiter if proctext is non-empty
8 While len(pText) ;; While there's text to process
9 Calculate indent as indent-(pos(mid(pText,1,4),'Else,Case,Defa,Unti')|pos(mid(pText,1,6),'End If,End Fo,End Sw,End Wh,End re'))+(pos(mid(pText,1,4),'Case,Defa')¬(case)&len(caseStack))-(mid(pText,1,6)='End Sw'&case) ;; Reduce indent for ends of constructs
10 Calculate indent as indent*(indent>0) ;; Don't allow indent to become negative
11 Calculate lineText as mid(pText,1,pos(kDelim,pText)-1) ;; Get the line text
12 Add line to list {(lineText,con(mid(kSpaces,1,4*indent),lineText),kFalse)} ;; Indent it and add it to the list
13 Calculate indent as indent+(mid(pText,1,2)='If'|pos(mid(pText,1,4),'Else,Whil,For ,Swit,Case,Defa,Repe')|mid(pText,1,7)='Begin r') ;; Increase indent for begins of constructs
14 If mid(pText,1,6)='Switch' ;; This code handles Switch constructs, which are gnarly (especially if they're nested)
15 Calculate caseStack as con(caseStack,case+0) ;; Entering a new Switch construct, so push the case flag for the current Switch (if any) on the stack
16 Calculate case as kFalse ;; Clear the case flag for the new Switch
17 Else If mid(pText,1,6)='End Sw'
18 Calculate case as mid(caseStack,len(caseStack),1) ;; We're leaving a Switch, so pop the case flag for the lower-level Switch (if any) from the stack
19 Calculate caseStack as mid(caseStack,1,len(caseStack)-1)
20 Else If pos(mid(pText,1,4),'Case,Defa')
21 Calculate case as kTrue ;; Set the case flag if there's at least one Case or Default command in the Switch
22 End If
23 Calculate pText as mid(pText,pos(kDelim,pText)+len(kDelim),len(pText)) ;; Strip this line's text
24 End While
No method errors found
More information about the omnisdev-en
mailing list