Had a mess with the Line Format function.
Got the Keyword highlight working so that if you had more than one occurrence of a keyword on a line, it highlights them all.
Got numbers working.
Changed the precedence of Strings and Comments. It was highlighting wrong if you had ";" in your code.
Tried speeding stuff up reading the keywords into an array but that seemed to slow it down (thought an array might have been faster than a type).
Function FormatLine(textarea,linenum)
char=TextAreaChar(textarea,linenum)
length=TextAreaLineLen(textarea,linenum)
s$=TextAreaText(textarea)
codeline$=Mid(s,char+1,length)
FormatTextAreaText textarea,PLAINR,PLAING,PLAINB,0,char,Len(codeline)
If Not Len(codeline) Return
;Strings
p=1
While p
p=Instr(codeline,Chr(34),p)
If p
p2=Instr(codeline,Chr(34),p+1)
If p2=0 p2=Len(codeline)
FormatTextAreaText textarea,STRINGR,STRINGG,STRINGB,0,char+p-1,p2-p+1
kf=Len(codeline)
codeline=Left(codeline,p-1)+String(Chr$(160),p2-p+1)+Right(codeline,Len(codeline)-p2)
EndIf
Wend
;Comments
p=Instr(codeline,";")
If p
FormatTextAreaText textarea,COMMENTR,COMMENTG,COMMENTB,0,char+p-1,Len(codeline)-p
codeline=Left(codeline,p-1)
EndIf
If Not Len(codeline) Return
;Keywords
Repeat
found=0
lcodeline$=Lower(codeline)
For k.keyword=Each keyword
p=Instr(lcodeline,k\lword,0)
If p
spacer=Asc(Lower(Mid(codeline,(p-1),1)))
If spacer<97 Or spacer>122
spacer=Asc(Lower(Mid(codeline,(p+Len(k\lword)),1)))
If spacer<97 Or spacer>122
SetTextAreaText textarea,k\word,(char+p-1),Len(k\word)
FormatTextAreaText textarea,COMMANDR,COMMANDG,COMMANDB,0,(char+p-1),Len(k\lword)
p2=p+Len(k\word)
codeline=Left(codeline,p-1)+String(Chr$(160),p2-p+1)+Right(codeline,(Len(codeline)-p2))
found=1
Exit
EndIf
EndIf
EndIf
Next
Until found=0
;Numbers
start=0
Repeat
ch=Asc(Mid$(codeline,start,1))
If ch>47 And ch<58
spacer=Asc(Mid(codeline,(start-1),1))
If spacer<97 Or spacer>122
For i=start To Len(codeline)
cn=Asc(Mid(codeline,i,1))
If cn<48 Or cn>57
sp$=Mid(codeline,(start-1),1)
If sp="$" Or sp="%"
start=start-1
End If
FormatTextAreaText textarea,NUMBERR,NUMBERG,NUMBERB,0,(char+start-1),i-start
start=i
Exit
End If
Next
End If
End If
start=start+1
Until start>Len(codeline)
End Function
|