Heres an old project of mine using blue...
It loads all DarkBasic's Keyword files so it knows the commands, (may help), it was never completed as it was a little slow at updating
It operated through 2 Functions
Gadget = AddSyntaxEdit(x,y,w,h,LanguagesFile$) LanguagesFile$ = This has a list of languages and links to the relivent keywords folder
UpdateSyntaxEdit()
Update the Syntax HighLighting in the RichEdit
You may be able to strip this down if you wanted, but it was all done in DarkBasic
` Multi-Language Syntax Hightlighting to a BlueGui EditBox
`
` By Michael Mihalyfi
` Mihalyfi@Hotmail.co.uk
set window on
` Required Setup
GoSub SetupSyntax
Global fontb
Global Statusbar
Global Toolbar
Main = CreateWindow(100,100,500,300,"QuickCode v0.1",WINDOW_NORMAL,0,1,0)
` SetGadgetShape Main,"C:Blank.bmp"
Statusbar = CreateStatusbar(Main)
AddStatusPanel Statusbar,200
Toolbar = CreateToolBar(Main)
AddStandardToolbarButtons Toolbar
AddToolbarButton Toolbar,TOOLBAR_NEW,0,"New"
AddToolbarButton Toolbar,TOOLBAR_OPEN,0,"Open"
AddToolbarButton Toolbar,TOOLBAR_SAVE,0,"Save"
AddToolbarSplitter Toolbar
AddToolbarButton Toolbar,TOOLBAR_DELETE,0,"Close"
AddToolbarSplitter Toolbar
AddToolbarButton Toolbar,TOOLBAR_CUT,0,"Cut"
AddToolbarButton Toolbar,TOOLBAR_COPY,0,"Copy"
AddToolbarButton Toolbar,TOOLBAR_PASTE,0,"Paste"
AddToolbarSplitter Toolbar
AddToolbarButton Toolbar,TOOLBAR_UNDO,0,"Undo"
AddToolbarButton Toolbar,TOOLBAR_REDO,0,"Redo"
AddToolbarSplitter Toolbar
AddToolbarButton Toolbar,TOOLBAR_FIND,0,"Find"
AddToolbarButton Toolbar,TOOLBAR_REPLACE,0,"Replace"
AddToolbarSplitter Toolbar
AddToolbarButton Toolbar,TOOLBAR_PROPERTIES,0,"Properties"
AddToolbarSplitter Toolbar
AddToolbarButton Toolbar,TOOLBAR_PRINT,0,"Print"
AddToolbarButton Toolbar,TOOLBAR_PRINTPREVIEW,0,"Print Preview"
AddToolbarSplitter Toolbar
AddToolbarButton Toolbar,TOOLBAR_HELP,0,"Help"
y = GadgetHeight(Toolbar)
h = 300-15-GadgetHeight(Statusbar)-GadgetHeight(Toolbar)
AddSyntaxEdit(15,y,500,h,"C:Languages.ini")
`Dim FunctionStore(999) As String
Marlett = CreateFont("Marlett",10,0,0,0)
Margin = CreateRichEdit(0,y,50,h,Main)
SetGadgetText Margin,"4"
SetSelStart Edit,0
SetSelLen Edit,Len(GetGadgetText(Margin))
SetSelFont Margin,Marlett,RGB(0,0,0)
SetSelLen Edit,0
Do : UpdateSyntaxEdit() : Loop
` ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
Function AddSyntaxEdit(x,y,w,h,LangFile$) : ` Step 1 - Create a SyntaxEdit Box
ActiveLang = 0
` Setup Display
` Set Window On
` Set Window Position x,y
` Set Window Size w+50,h+50
` Set Window Layout 0,0,0
Edit = CreateRichEdit(x,y,w,h,Main)
` Load All Language Settings
LoadLanguages(LangFile$)
` SetGadgetText Edit,Lang(0).Text$+Lang(0).Numb$+Lang(0).Math$+"!£$%^&*()"
SetGadgetText Edit,"For n = 1 to 100 : Sprite 1,100,100,100,100,1 : Next n"
` SetGadgetText Edit,Str$(Keyword(555).Lang)+Keyword(555).Word$+Keyword(555).Help$+"Sprite"
` SetGadgetText Edit,Extract$("How,To,Sprite,It",8,6)
RedrawSyntax(0)
EndFunction
Function UpdateSyntaxEdit() : ` Step 2 - Update the Syntax Checker
` Press F1 For Command Help
` If ScanCode(59) = 1
` k = KeywordUnderCarot()
` If k = "" Then Execute File Lang(ActiveLang).Help$,"",""
` If k <> "" Then Execute File Keyword(k).Help$,"",""
` EndIf
` Updating the Syntax Coloring
s$ = GetGadgetText(Edit)
If s$ = OldSyntaxContents Then ExitFunction
If Len(s$) > Len(OldSyntaxContents)+5 then Mode = 1
OldSyntaxContents = s$
RedrawSyntax(Mode)
` c = GetSelPos
` For n = c-10 to c+10
` SetSelStart Edit,4
` SetSelLen Edit,4
` SetSelFont Edit,font,RGB(255,0,0)
` SetSelLen Edit,0
` Next n
EndFunction
Function KeywordUnderCarot()
` LineStart = 0 : LineEnd = Len(s$)
` For Pos = LineStart To LineEnd
` If Mid$(s$,Pos) = Chr$(10) Then Inc ReturnCount,1
` For k = 1 to Array Count(Keyword())-1
` If Keyword(k).Lang = ActiveLang And Keyword(k).Word$ = Upper$(Extract$(s$,Pos,Len(Keyword(k).Word$))) Then ExitFunction k
` Next k : EndIf
` Next Pos
EndFunction k
` ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
Function LoadLanguages(LangFile$)
fn = FreeFileNum()
Open To Read fn,LangFile$
cText = Val(ReadString(fn))
cMath = Val(ReadString(fn))
cNumb = Val(ReadString(fn))
cRem = Val(ReadString(fn))
cCmd = Val(ReadString(fn))
Font1 = CreateFont(ReadString(fn),Val(ReadString(fn)),Val(ReadString(fn)),Val(ReadString(fn)),Val(ReadString(fn)))
Font = CreateFont("Courier New",10,0,0,0)
Fontb = CreateFont("Courier New",10,1,0,0)
While File End(fn) = 0
n = Array Count(Lang())
Add To Stack Lang()
Lang(n).Name$ = ReadString(fn)
Lang(n).Ext$ = ReadString(fn)
Lang(n).Text$ = ReadString(fn)
Lang(n).Numb$ = ReadString(fn)
Lang(n).Math$ = ReadString(fn)
Lang(n).Help$ = ReadString(fn)
LoadKeywords(n,ReadString(fn))
EndWhile
Close File fn
EndFunction
Function LoadKeywords(Lang,Path$)
fn = FreeFileNum()
Set Dir Path$
Perform Checklist For Files
For f = 3 to Checklist Quantity()
Catch : Open To Read fn,CheckList String$(f) : EndCatch
If Get Error() = 0
While File End(fn) = 0
n = Array Count(Keyword())
Add To Stack Keyword()
Keyword(n).Lang = Lang
SplitPara(ReadString(fn),"=")
Keyword(n).Word$ = Upper$(Para(1))
Keyword(n).Para$ = Para(2)
Keyword(n).Help$ = Para(3)
EndWhile
Close File fn
Else ErrorMessage "Unable to load "+Lang(Lang).Name$+" Keyword File "+CheckList String$(f) : EndIf
Next f
Empty CheckList
EndFunction
Function RedrawSyntax(LineOnly)
SetAutoUpdate Edit,0
` Required Values
s$ = GetGadgetText(Edit)
c = GetSelStart(Edit)
LineStart = 0 : LineEnd = Len(s$)
If LineOnly = 1
`LineStart = c : Repeat : Dec LineStart,1 : Until Mid$(s$,LineStart) = Chr$(10) or LineStart = 0
`LineEnd = c : Repeat : Inc LineEnd ,1 : Until Mid$(s$,LineEnd ) = Chr$(10) or LineEnd = Len(s$)
EndIf
For Pos = LineStart To LineEnd
If Mid$(s$,Pos) = Chr$(10) Then Inc ReturnCount,1
` This Recognises Text, Numbers, Math Symbles, Ect
Mode = ChrType(s$,Pos) : ModeLenth = 1
` This Recognises Commands
` If ChrType(s$,Pos) <> 1
For k = 1 to Array Count(Keyword())-1
If Keyword(k).Lang = ActiveLang And Keyword(k).Word$ = Upper$(Extract$(s$,Pos,Len(Keyword(k).Word$)))
If Pos = c And GetStatusText(Statusbar,1) <> Keyword(k).Para$ : SetStatusText Statusbar,1,Keyword(K).Para$ : EndIf
` If ChrType(s$,Pos+Len(Keyword(k).Word$)) <> 1
Mode = 4 : ModeLenth = Len(Keyword(k).Word$)
If Keyword(k).Word$ = "REMSTART" Then ForceRem = 1
If Keyword(k).Word$ = "REMEND" Then ForceRem = 0
EndIf : `EndIf
Next k : `EndIf
If ForceRem = 1 Then Mode = 5
If Mode = 4 : SetSelStart Edit,Pos-ReturnCount-1
Else SetSelStart Edit,Pos-ReturnCount : EndIf
SetSelLen Edit,ModeLenth
If Mode = 0 Then SetSelFont Edit,Font ,RGB(200,0,0)
If Mode = 1 Then SetSelFont Edit,Font ,RGB(0,0,0)
If Mode = 2 Then SetSelFont Edit,Font ,RGB(0,200,0)
If Mode = 3 Then SetSelFont Edit,Font ,RGB(200,0,200)
If Mode = 4 Then SetSelFont Edit,Fontb,RGB(0,0,200)
If Mode = 5 Then SetSelFont Edit,Font ,RGB(100,100,100)
SetSelLen Edit,0
If ModeLenth > 1 Then Pos = Pos+(ModeLenth-1) : ModeLenth = 1
Next Pos
SetSelStart Edit,c
SetAutoUpdate Edit,1
PaintGadget Edit
EndFunction
Function Extract$(s$,Pos,Lenth)
Pos = Pos-1
s$ = Right$(s$,Len(s$)-Pos)
s$ = Left$(s$,Lenth)
EndFunction s$
` ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
Function ChrType(s$,Pos)
` 0 = Not Recognised
` 1 = Text
` 2 = Number
` 3 = Math
s$ = Upper$(Mid$(s$,Pos+1))
For n = 1 to Len(Lang(ActiveLang).Text$) : If s$ = Mid$(Lang(ActiveLang).Text$,n) : ExitFunction 1 : EndIf : Next n
For n = 1 to Len(Lang(ActiveLang).Numb$) : If s$ = Mid$(Lang(ActiveLang).Numb$,n) : ExitFunction 2 : EndIf : Next n
For n = 1 to Len(Lang(ActiveLang).Math$) : If s$ = Mid$(Lang(ActiveLang).Math$,n) : ExitFunction 3 : EndIf : Next n
EndFunction 0
Function SplitPara(s$,Spliter$)
n = 0
ParaReloopPoint:
If Len(s$) = 0 Then para(0) = Str$(n) : ExitFunction n
Inc n,1
For p = 1 to Len(s$)
If Mid$(s$,p) = Spliter$ or p = Len(s$) Then Para(n) = Left$(s$,p-1) : s$ = Right$(s$,Len(s$)-p) : Goto ParaReloopPoint
Next p
` Shound NEVER Exit with -1
EndFunction -1
` ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
Function FreeFileNum()
Repeat : Inc n,1 : Until File Open(n) = 0
EndFunction n
Function ReadString(fn)
Read String fn,n$
EndFunction n$
SetupSyntax: StartBlue "Get Your Own","Get Your Own"
` Random Values ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
Global Main As Integer
Global Edit As Integer
Global ActiveLang As Integer
Global ForceRem As Integer
Global OldSyntaxContents As String
` Syntax Colors and Font ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
Global cRem As Integer
Global cText As Integer
Global cNumb As Integer
Global cMath As Integer
Global cFont As String
Global Font As Integer
` Enabled Languages ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
Type LangType
Name$ As String
Help$ As String
Text$ As String
Numb$ As String
Math$ As String
Ext$ As String
EndType
Dim Lang(0) As LangType
Lang(0).Name$ = "NONE"
` Recognised Keywords ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
Type KeywordType
Lang As Integer
Word$ As String
Help$ As String
Para$ As String
EndType
Dim Keyword(0) As KeywordType
` Use with SplitPara() ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
Dim Para(10) As String
` ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
Return
Everyone Be Cool, You, Be Cool.