ScintillaGadget using LEXER

Just starting out? Need help? Post your questions and find answers here.
User avatar
Kwai chang caine
Always Here
Always Here
Posts: 5611
Joined: Sun Nov 05, 2006 11:42 pm
Location: Lyon - France

ScintillaGadget using LEXER

Post by Kwai chang caine »

Hello at all,

I try to using the SciLexer embeded in PureBasic and that not works, perhaps it not exist ?

Code: Select all

#SCI_SETLEXER = 4001

OpenWindow(0, 0, 0, 800, 600, "Editeur Web - Scintilla", #PB_Window_SystemMenu)
IdEditor = ScintillaGadget(#PB_Any, 0, 0, 800, 600, 0)

; Set default font
ScintillaSendMessage(IdEditor, #SCI_STYLESETFONT, #STYLE_DEFAULT, @"Courier New")
ScintillaSendMessage(IdEditor, #SCI_STYLESETSIZE, #STYLE_DEFAULT, 16)
ScintillaSendMessage(IdEditor, #SCI_STYLESETBOLD, #STYLE_DEFAULT, #False)
ScintillaSendMessage(IdEditor, #SCI_STYLESETITALIC, #STYLE_DEFAULT, #False)

ScintillaSendMessage(IdEditor, #SCI_STYLECLEARALL, 0, 0)

; Set PHP style
ScintillaSendMessage(IdEditor, #SCI_STYLESETFORE, #SCLEX_PHP, RGB(255,0,0))
ScintillaSendMessage(IdEditor, #SCI_STYLESETBOLD, #SCLEX_PHP, #True)
ScintillaSendMessage(IdEditor, #SCI_STYLESETITALIC, #SCLEX_PHP, #True)

; Set JS style
ScintillaSendMessage(IdEditor, #SCI_STYLESETFORE, #SCLEX_HTML, RGB(0,255,0))
ScintillaSendMessage(IdEditor, #SCI_STYLESETBOLD, #SCLEX_HTML, #True)
ScintillaSendMessage(IdEditor, #SCI_STYLESETITALIC, #SCLEX_HTML, #True)

; Set CSS style 
ScintillaSendMessage(IdEditor, #SCI_STYLESETFORE, #SCLEX_CSS, RGB(0,0,255))
ScintillaSendMessage(IdEditor, #SCI_STYLESETBOLD, #SCLEX_CSS, #True)
ScintillaSendMessage(IdEditor, #SCI_STYLESETITALIC, #SCLEX_CSS, #True)
 
; Selecting the HTML lexer (the closest one for mixing HTML+PHP+JS)
ScintillaSendMessage(IdEditor, #SCI_SETLEXER, #SCLEX_CONTAINER, #SCLEX_HTML)

; Define PHP words
*PtrListePHP = UTF8("if else echo function return while for foreach")
ScintillaSendMessage(IdEditor, #SCI_SETKEYWORDS, #SCLEX_PHP, *PtrListePHP)
FreeMemory(*PtrListePHP)

; Define JS words
*PtrListeJS = UTF8("var let const if else function return for while")
ScintillaSendMessage(IdEditor, #SCI_SETKEYWORDS, #SCLEX_HTML, *PtrListeJS)
FreeMemory(*PtrListeJS)

; Define CSS words
*PtrListeCSS = UTF8("color background margin padding border")
ScintillaSendMessage(IdEditor, #SCI_SETKEYWORDS, #SCLEX_CSS, *PtrListeCSS)
FreeMemory(*PtrListeCSS)

; Exemple de code Web
code$ = "<html>" + #CRLF$
code$ + "<head><style>body {background-color: #fff;}</style></head>" + #CRLF$
code$ + "<body>" + #CRLF$
code$ + "<?php if($x > 0) { echo 'OK'; } ?>" + #CRLF$
code$ + "<script>if(true){console.log('Hello JS');}</script>" + #CRLF$
code$ + "</body></html>"

; Send source code
*PtrCodeSource = UTF8(code$)
ScintillaSendMessage(IdEditor, #SCI_SETTEXT, 0, *PtrCodeSource)
FreeMemory(*PtrCodeSource)

Repeat
 Event = WaitWindowEvent()
Until Event = #PB_Event_CloseWindow
Have a good day
ImageThe happiness is a road...
Not a destination

PureBasic French Forum
infratec
Always Here
Always Here
Posts: 7772
Joined: Sun Sep 07, 2008 12:45 pm
Location: Germany

Re: ScintillaGadget using LEXER

Post by infratec »

I think you need at least the SciLexer.dll

https://www.scintilla.org/SciTEDownload.html
AZJIO
Addict
Addict
Posts: 2254
Joined: Sun May 14, 2017 1:48 am

Re: ScintillaGadget using LEXER

Post by AZJIO »

User avatar
Kwai chang caine
Always Here
Always Here
Posts: 5611
Joined: Sun Nov 05, 2006 11:42 pm
Location: Lyon - France

Re: ScintillaGadget using LEXER

Post by Kwai chang caine »

infratec wrote: Sat Jan 17, 2026 10:21 pm I think you need at least the SciLexer.dll
Hello INFRATEC
You have right
After read the link of AZJIO :wink: i know now Fred use personal Lexer :|
So apparently scintillagadget not have lexer
Me too, i have create my own lever, because i not knowed what is lexer when i have begining my project :oops: it works at 90% for the moment and need to be optimized, i'm mainly afffraid for the futur part, the refresh when i add or paste words
Then i wanted compare mine to official LEXER
But apparently..it is not really creating for coloring several languages together, and for the web 4 exist in the same time
I have found nice codes of MRMAT using SciLexer. dll, but not the LEXER too
And i think i'm forced to make a choice, i can't use scintillagadget and adding the scilexer functions :|
Thanks for your advice

@AZJIO
Thanks for this precious link 8)
I have not found this thread because i have search with "scilexer.dll" word, and not know lexilla word :shock:
Again a word i must learn for what it is used :shock:
I have see you have the same need than me :wink:

A good day at you two 8)
ImageThe happiness is a road...
Not a destination

PureBasic French Forum
User avatar
Kwai chang caine
Always Here
Always Here
Posts: 5611
Joined: Sun Nov 05, 2006 11:42 pm
Location: Lyon - France

Re: ScintillaGadget using LEXER

Post by Kwai chang caine »

I don't understand why LEXILLA don't want to recognize my KEYWORDS in his own source :cry:

With the DLL
https://ps.reec.fr/Provisoires/Lexilla.zip

Code: Select all

; https://www.purebasic.fr/english/viewtopic.php?p=616117#p616117

Prototype.i CreateLexerProto(name.p-utf8)
Prototype.i GetLexerCountProto()
Prototype   GetLexerNameProto(index.i, *BufferName, *BufferNameLength)

#SCI_PB_STYLE_CRLF = 0
#SCI_PB_STYLE_COMMENT = 1
#SCI_PB_STYLE_NUMBER = 2
#SCI_PB_STYLE_STRING = 4
#SCI_PB_STYLE_NOTFOUND1 = 5
#SCI_PB_STYLE_SPACE = 6
#SCI_PB_STYLE_TEXT = 7
#SCI_PB_STYLE_NOTFOUND2 = 8
#SCI_PB_STYLE_NOTFOUND3 = 9
#SCI_PB_STYLE_NOTFOUND4 = 10
#SCI_PB_STYLE_NOTFOUND5 = 11
#SCI_PB_STYLE_CONSTANT = 13
#SCI_PB_STYLE_NOTFOUND6 = 14
#SCI_PB_STYLE_NOTFOUND7 = 15
#SCI_PB_STYLE_NOTFOUND8 = 16
#SCI_PB_STYLE_DOLLAR = 17
#SCI_PB_STYLE_NOTFOUND9 = 18
#SCI_PB_STYLE_NOTFOUND10 = 19
#SCI_PB_STYLE_NOTFOUND11 = 20
#SCI_PB_STYLE_NOTFOUND12 = 21
#SCI_PB_STYLE_NOTFOUND13 = 22
#SCI_PB_STYLE_NOTFOUND14 = 23
#SCI_PB_STYLE_NOTFOUND15 = 24
#SCI_PB_STYLE_NOTFOUND16 = 25
#SCI_PB_STYLE_NOTFOUND17 = 26
#SCI_PB_STYLE_NOTFOUND18 = 27
#SCI_PB_STYLE_NOTFOUND19 = 28
#SCI_PB_STYLE_NOTFOUND20 = 29
#SCI_PB_STYLE_NOTFOUND21 = 30
#SCI_PB_STYLE_NOTFOUND22 = 31
#SCI_PB_STYLE_EMPTY_CHARAC = 32

#SCI_PB_STYLE_KEYWORD = 5

Procedure ForTest(KccParam.s)

EndProcedure

If OpenLibrary(0, "Lexilla.dll")
 
 CreateLexer.CreateLexerProto = GetFunction(0, "CreateLexer")
 GetLexerCount.GetLexerCountProto = GetFunction(0, "GetLexerCount")
 GetLexerName.GetLexerNameProto = GetFunction(0, "GetLexerName")
 
 If CreateLexer = 0 Or GetLexerCount = 0 Or GetLexerName = 0
  Debug "Invalid Lexilla lib"
  End
 EndIf
 
EndIf

If OpenWindow(0, 0, 0, 1000, 700, "ScintillaGadget", #PB_Window_SystemMenu | #PB_Window_ScreenCentered)
 
 ScintillaGadget(0, 10, 10, 980, 690, 0)
 
 CreateLexer.CreateLexerProto = GetFunction(0, "CreateLexer")
 GetLexerCount.GetLexerCountProto = GetFunction(0, "GetLexerCount")
 GetLexerName.GetLexerNameProto = GetFunction(0, "GetLexerName")
 
 PureBasicLexer = CreateLexer("purebasic")
 ScintillaSendMessage(0, #SCI_SETILEXER, 0, PureBasicLexer)
 
 *PtrPolice = UTF8("Consolas")                                                     
 ScintillaSendMessage(SciID, #SCI_STYLESETFONT, #STYLE_DEFAULT, *PtrPolice)
 FreeMemory(*PtrPolice)
 ScintillaSendMessage(0, #SCI_STYLESETFORE, #STYLE_DEFAULT, 0)
 ScintillaSendMessage(0, #SCI_STYLESETSIZE, #STYLE_DEFAULT, 10)
 ScintillaSendMessage(0, #SCI_STYLESETBACK, #STYLE_DEFAULT, RGB(255, 255, 223))
 ScintillaSendMessage(0, #SCI_STYLECLEARALL) 
 
 ; Style for constants
 ScintillaSendMessage(0, #SCI_STYLESETFORE, #SCI_PB_STYLE_CONSTANT, RGB(146, 74, 113))
 ScintillaSendMessage(0, #SCI_STYLESETBACK, #SCI_PB_STYLE_CONSTANT, RGB(255, 255, 223))
 
 ; Style for comments
 ScintillaSendMessage(0, #SCI_STYLESETFORE, #SCI_PB_STYLE_COMMENT, RGB(0, 170, 170))
 ScintillaSendMessage(0, #SCI_STYLESETBACK, #SCI_PB_STYLE_COMMENT, RGB(255, 255, 223))
 
 ; Style for text
 ScintillaSendMessage(0, #SCI_STYLESETFORE, #SCI_PB_STYLE_TEXT, RGB(0, 0, 255))
 ScintillaSendMessage(0, #SCI_STYLESETBACK, #SCI_PB_STYLE_TEXT, RGB(255, 255, 223))
 
 ; Style for keywords
 ScintillaSendMessage(0, #SCI_STYLESETFORE, #SCI_PB_STYLE_KEYWORD, RGB(0, 0, 255))
 ScintillaSendMessage(0, #SCI_STYLESETBACK, #SCI_PB_STYLE_KEYWORD, RGB(255, 255, 223))
 ScintillaSendMessage(0, #SCI_STYLESETBOLD, #SCI_PB_STYLE_KEYWORD, #True)
 
 Keyword$ = "Structure Procedure EndProcedure Prototype"
 
 ; Send in ASCII
 ; ScintillaSendMessage(0, #SCI_SETKEYWORDS, #SCI_PB_STYLE_KEYWORD, @Keyword$)
 
 ; Send in UTF8 
 *PtrKWords = UTF8(Keyword$)
 ScintillaSendMessage(0, #SCI_SETKEYWORDS, #SCI_PB_STYLE_KEYWORD, *PtrKWords)
 
 *PtrKWords = UTF8("Structure Procedure EndProcedure Prototype")
 ScintillaSendMessage(0, #SCI_SETKEYWORDS, #SCI_PB_STYLE_KEYWORD, *PtrKWords)
  
 Delay(100)
 Canal = ReadFile(#PB_Any, #PB_Compiler_File, #PB_UTF8)
 
 If Canal
  
  TailleFichier = Lof(Canal)
  *Ptr = AllocateMemory(TailleFichier)
  ReadData(Canal, *Ptr, TailleFichier)
  CloseFile(Canal)
  ScintillaSendMessage(SciID, #SCI_SETTEXT, 0, *Ptr) 
  FreeMemory(*Ptr)
  
 Else
  
  MessageRequester("Erreur fichier", "Le fichier" + #CRLF$ + #PB_Compiler_File + #CRLF$ + "n'a pu être ouvert.")
  
 EndIf
  
 Repeat : Until WaitWindowEvent() = #PB_Event_CloseWindow
 
 FreeMemory(*PtrKWords)
 
EndIf
ImageThe happiness is a road...
Not a destination

PureBasic French Forum
Axolotl
Addict
Addict
Posts: 919
Joined: Wed Dec 31, 2008 3:36 pm

Re: ScintillaGadget using LEXER

Post by Axolotl »

Hmm, I just took a quick look at the help section and GitHub.
Something isn't quite clear to me.
There is no lexilla\lexers\LexPureBasic.cxx file.

Is that relevant? I have no idea... but I think so.
I haven't done anything with Lexilla yet... (it doesn't seem to be that easy.)

I get a few highlighted keywords (COMMENT) with your code... Maybe the constants aren't quite correct? Or there is some kind of default lexer at work?
BTW: Your DLL is probably x86.

Some details of my investigation
on Lexilla-History:
Lexilla-History wrote:Release 1.63
Released on 4 April 2005.
BlitzBasic and PureBasic support. ; <== It doesn't say “Lexer added for ... ” here, as it does with others.
Just because it worked doesn't mean it works.
PureBasic 6.04 (x86) and <latest stable version and current alpha/beta> (x64) on Windows 11 Home. Now started with Linux (VM: Ubuntu 22.04).
threedslider
Enthusiast
Enthusiast
Posts: 530
Joined: Sat Feb 12, 2022 7:15 pm

Re: ScintillaGadget using LEXER

Post by threedslider »

Say us a little bit of what do you are doing it ? Lexer used for what ? What is your purpose ?
Axolotl
Addict
Addict
Posts: 919
Joined: Wed Dec 31, 2008 3:36 pm

Re: ScintillaGadget using LEXER

Post by Axolotl »

@KCC,
well I would say this place is the source of wisdom: source codes on GITHUB.
My guess is that the problem here is probably that all Basic dialects use the same lexer...

I found the lexer corresponding to PB. => LexBasic.cxx

Please add this to your code (at the right places)

Code: Select all

; extracted from https://github.com/ScintillaOrg/lexilla/blob/master/include/LexicalStyles.iface 
; # Lexical states for SCLEX_VB, SCLEX_VBSCRIPT, SCLEX_POWERBASIC, SCLEX_BLITZBASIC, SCLEX_PUREBASIC, SCLEX_FREEBASIC
;
#SCE_B_DEFAULT      =  0
#SCE_B_COMMENT      =  1
#SCE_B_NUMBER       =  2
#SCE_B_KEYWORD      =  3
#SCE_B_STRING       =  4
#SCE_B_PREPROCESSOR =  5
#SCE_B_OPERATOR     =  6
#SCE_B_IDENTIFIER   =  7
#SCE_B_DATE         =  8
#SCE_B_STRINGEOL    =  9
#SCE_B_KEYWORD2     = 10
#SCE_B_KEYWORD3     = 11
#SCE_B_KEYWORD4     = 12
#SCE_B_CONSTANT     = 13
#SCE_B_ASM          = 14
#SCE_B_LABEL        = 15
#SCE_B_ERROR        = 16
#SCE_B_HEXNUMBER    = 17
#SCE_B_BINNUMBER    = 18
#SCE_B_COMMENTBLOCK = 19
#SCE_B_DOCLINE      = 20
#SCE_B_DOCBLOCK     = 21
#SCE_B_DOCKEYWORD   = 22 
;.... 
  ScintillaSendMessage(0, #SCI_STYLESETFORE, #SCE_B_DEFAULT      , #Black) ; 
  ScintillaSendMessage(0, #SCI_STYLESETFORE, #SCE_B_COMMENT      , #Green) ; 
  ScintillaSendMessage(0, #SCI_STYLESETFORE, #SCE_B_NUMBER       , #Blue) ; 
  ScintillaSendMessage(0, #SCI_STYLESETFORE, #SCE_B_KEYWORD      , #Yellow) ; 
  ScintillaSendMessage(0, #SCI_STYLESETFORE, #SCE_B_STRING       , $72ADC0) ;
  ScintillaSendMessage(0, #SCI_STYLESETFORE, #SCE_B_PREPROCESSOR , $F78865) ; 
  ScintillaSendMessage(0, #SCI_STYLESETFORE, #SCE_B_OPERATOR     , $72ADC0) ; 
  ScintillaSendMessage(0, #SCI_STYLESETFORE, #SCE_B_IDENTIFIER   , $FF8000) ; <= all text is using this color 
  ScintillaSendMessage(0, #SCI_STYLESETFORE, #SCE_B_DATE         , $71AE71) ; 
  ScintillaSendMessage(0, #SCI_STYLESETFORE, #SCE_B_STRINGEOL    , $DE98D9) ; 
  ScintillaSendMessage(0, #SCI_STYLESETFORE, #SCE_B_KEYWORD2     , $00FFFF) ; 
  ScintillaSendMessage(0, #SCI_STYLESETFORE, #SCE_B_KEYWORD3     , $8080FF) ; 
  ScintillaSendMessage(0, #SCI_STYLESETFORE, #SCE_B_KEYWORD4     , $D3D08C) ; 
  ScintillaSendMessage(0, #SCI_STYLESETFORE, #SCE_B_CONSTANT     , $D3D08C) ; 
  ScintillaSendMessage(0, #SCI_STYLESETFORE, #SCE_B_ASM          , #Red) ; 
  ScintillaSendMessage(0, #SCI_STYLESETFORE, #SCE_B_LABEL        , #Red) ; 
  ScintillaSendMessage(0, #SCI_STYLESETFORE, #SCE_B_ERROR        , #Red) ; 
  ScintillaSendMessage(0, #SCI_STYLESETFORE, #SCE_B_HEXNUMBER    , #Red) ; 
  ScintillaSendMessage(0, #SCI_STYLESETFORE, #SCE_B_BINNUMBER    , #Red) ; 
  ScintillaSendMessage(0, #SCI_STYLESETFORE, #SCE_B_COMMENTBLOCK , #Red) ; 
  ScintillaSendMessage(0, #SCI_STYLESETFORE, #SCE_B_DOCLINE      , #Red) ; 
  ScintillaSendMessage(0, #SCI_STYLESETFORE, #SCE_B_DOCBLOCK     , #Red) ; 
  ScintillaSendMessage(0, #SCI_STYLESETFORE, #SCE_B_DOCKEYWORD   , #Red) ; 

; ..... 
; lower characters are important 
Global Keyword$ = "structure endstructure procedure endprocedure " + 
                  "if endif for next " + 
                  "repeat until " + 
                  "global protected " + 
                  "" 
  ; 
  *PtrKWords = UTF8(Keyword$)
  ScintillaSendMessage(0, #SCI_SETKEYWORDS, 0,  *PtrKWords)  ; <= only 0 is working 
  FreeMemory(*PtrKWords)
; 
Just because it worked doesn't mean it works.
PureBasic 6.04 (x86) and <latest stable version and current alpha/beta> (x64) on Windows 11 Home. Now started with Linux (VM: Ubuntu 22.04).
User avatar
Kwai chang caine
Always Here
Always Here
Posts: 5611
Joined: Sun Nov 05, 2006 11:42 pm
Location: Lyon - France

Re: ScintillaGadget using LEXER

Post by Kwai chang caine »

threedslider wrote:Say us a little bit of what do you are doing it ? What is your purpose ?
Hello i try to create a web editor with manage the 4 languages HTML/PHP/CSS/JS
viewtopic.php?p=649971#p649971
threedslider wrote:Lexer used for what ?
Thanks to AZJIO :wink: i learn that apparently FRED not need a LEXER (Surely SciLexer) at the moment of he create his ScintillaGadget
viewtopic.php?p=629667#p629667
So we must coding for parsing and recognize the keywords :|
Like FRED i have create my own, finish at 90%, but now i want to compare the professionnal LEXER (Now LEXILLA whom replace SciLexer) with mine, for see what is the better to use for me
One of the advantage to use a LEXER is the refresh automaticaly when you add characters or paste code :wink:

@AXOLOTL

One thousand of thanks AXOLOTL !!!

for lost your precious time for little KCC :shock: 8)
Really... I felt a bit alone in this mess and I was starting to get depressed from trying everything without success. :cry:

Image

Like you see, when i have try all possibility i have found nearly all the same value of constants :D

Code: Select all

#SCI_PB_STYLE_CRLF = 0
#SCI_PB_STYLE_COMMENT = 1
#SCI_PB_STYLE_NUMBER = 2
#SCI_PB_STYLE_STRING = 4
#SCI_PB_STYLE_NOTFOUND1 = 5
#SCI_PB_STYLE_SPACE = 6
#SCI_PB_STYLE_TEXT = 7
#SCI_PB_STYLE_CONSTANT = 13
#SCI_PB_STYLE_DOLLAR = 17
#SCI_PB_STYLE_EMPTY_CHARAC = 32
But thanks to you, i can now bolding the keywords, and create EXACTELY the same coloring syntax like PB, and understand how that works 8)
It's really not simple to understand the rules of SCINTILLA and his LEXER :|

Code: Select all

; https://www.purebasic.fr/english/viewtopic.php?p=616117#p616117

Prototype.i CreateLexerProto(name.p-utf8)
Prototype.i GetLexerCountProto()
Prototype   GetLexerNameProto(index.i, *BufferName, *BufferNameLength)

; extracted from https://github.com/ScintillaOrg/lexilla/blob/master/include/LexicalStyles.iface 
; # Lexical states for SCLEX_VB, SCLEX_VBSCRIPT, SCLEX_POWERBASIC, SCLEX_BLITZBASIC, SCLEX_PUREBASIC, SCLEX_FREEBASIC
;
#SCE_B_DEFAULT      =  0
#SCE_B_COMMENT      =  1
#SCE_B_NUMBER       =  2
#SCE_B_KEYWORD      =  3
#SCE_B_STRING       =  4
#SCE_B_PREPROCESSOR =  5
#SCE_B_OPERATOR     =  6
#SCE_B_IDENTIFIER   =  7
#SCE_B_DATE         =  8
#SCE_B_STRINGEOL    =  9
#SCE_B_KEYWORD2     = 10
#SCE_B_KEYWORD3     = 11
#SCE_B_KEYWORD4     = 12
#SCE_B_CONSTANT     = 13
#SCE_B_ASM          = 14
#SCE_B_LABEL        = 15
#SCE_B_ERROR        = 16
#SCE_B_HEXNUMBER    = 17
#SCE_B_BINNUMBER    = 18
#SCE_B_COMMENTBLOCK = 19
#SCE_B_DOCLINE      = 20
#SCE_B_DOCBLOCK     = 21
#SCE_B_DOCKEYWORD   = 22 

Procedure ForTestTheLookOFPROCEDURE(KccParam.s)
 
EndProcedure

If OpenLibrary(0, "Lexilla.dll")
 
 CreateLexer.CreateLexerProto = GetFunction(0, "CreateLexer")
 GetLexerCount.GetLexerCountProto = GetFunction(0, "GetLexerCount")
 GetLexerName.GetLexerNameProto = GetFunction(0, "GetLexerName")
 
 If CreateLexer = 0 Or GetLexerCount = 0 Or GetLexerName = 0
  Debug "Invalid Lexilla lib"
  End
 EndIf
 
EndIf

If OpenWindow(0, 0, 0, 1000, 700, "ScintillaGadget", #PB_Window_SystemMenu | #PB_Window_ScreenCentered)
 
 ScintillaGadget(0, 10, 10, 980, 690, 0)
 
 CreateLexer.CreateLexerProto = GetFunction(0, "CreateLexer")
 GetLexerCount.GetLexerCountProto = GetFunction(0, "GetLexerCount")
 GetLexerName.GetLexerNameProto = GetFunction(0, "GetLexerName")
 
 PureBasicLexer = CreateLexer("purebasic")
 ScintillaSendMessage(0, #SCI_SETILEXER, 0, PureBasicLexer)
 
 *PtrPolice = UTF8("Consolas")                                                     
 ScintillaSendMessage(SciID, #SCI_STYLESETFONT, #STYLE_DEFAULT, *PtrPolice)
 FreeMemory(*PtrPolice)
 ScintillaSendMessage(0, #SCI_STYLESETFORE, #STYLE_DEFAULT, 0)
 ScintillaSendMessage(0, #SCI_STYLESETSIZE, #STYLE_DEFAULT, 11)
 ScintillaSendMessage(0, #SCI_STYLESETBACK, #STYLE_DEFAULT, RGB(255, 255, 223))
 ScintillaSendMessage(0, #SCI_STYLECLEARALL) 
 
 ScintillaSendMessage(0, #SCI_STYLESETFORE, #SCE_B_DEFAULT      , #Black) ; 
 ScintillaSendMessage(0, #SCI_STYLESETFORE, #SCE_B_COMMENT      , RGB(0, 170, 170)) ; 
 ScintillaSendMessage(0, #SCI_STYLESETFORE, #SCE_B_NUMBER       , #Black)           ; 
 ScintillaSendMessage(0, #SCI_STYLESETFORE, #SCE_B_KEYWORD      , RGB(0, 0, 255))   ; 
 ScintillaSendMessage(0, #SCI_STYLESETBOLD, #SCE_B_KEYWORD      , #True) 
 ScintillaSendMessage(0, #SCI_STYLESETFORE, #SCE_B_STRING       , #Black) ;
 ScintillaSendMessage(0, #SCI_STYLESETFORE, #SCE_B_PREPROCESSOR , $F78865); 
 ScintillaSendMessage(0, #SCI_STYLESETFORE, #SCE_B_OPERATOR     , #Black) ; 
 ScintillaSendMessage(0, #SCI_STYLESETFORE, #SCE_B_IDENTIFIER   , RGB(0, 0, 255)) ; <= all text is using this color 
 ScintillaSendMessage(0, #SCI_STYLESETFORE, #SCE_B_DATE         , $71AE71)        ; 
 ScintillaSendMessage(0, #SCI_STYLESETFORE, #SCE_B_STRINGEOL    , $DE98D9)        ; 
 ScintillaSendMessage(0, #SCI_STYLESETFORE, #SCE_B_KEYWORD2     , $00FFFF)        ; 
 ScintillaSendMessage(0, #SCI_STYLESETFORE, #SCE_B_KEYWORD3     , $8080FF)        ; 
 ScintillaSendMessage(0, #SCI_STYLESETFORE, #SCE_B_KEYWORD4     , $D3D08C)        ; 
 ScintillaSendMessage(0, #SCI_STYLESETFORE, #SCE_B_CONSTANT     , RGB(146, 74, 113)) ; 
 ScintillaSendMessage(0, #SCI_STYLESETFORE, #SCE_B_ASM          , RGB(146, 74, 113)) ; 
 ScintillaSendMessage(0, #SCI_STYLESETFORE, #SCE_B_LABEL        , #Black)            ; 
 ScintillaSendMessage(0, #SCI_STYLESETFORE, #SCE_B_ERROR        , #Black)            ; 
 ScintillaSendMessage(0, #SCI_STYLESETFORE, #SCE_B_HEXNUMBER    , #Red)              ; 
 ScintillaSendMessage(0, #SCI_STYLESETFORE, #SCE_B_BINNUMBER    , #Red)              ; 
 ScintillaSendMessage(0, #SCI_STYLESETFORE, #SCE_B_COMMENTBLOCK , #Red)              ; 
 ScintillaSendMessage(0, #SCI_STYLESETFORE, #SCE_B_DOCLINE      , #Red)              ; 
 ScintillaSendMessage(0, #SCI_STYLESETFORE, #SCE_B_DOCBLOCK     , #Red)              ; 
 ScintillaSendMessage(0, #SCI_STYLESETFORE, #SCE_B_DOCKEYWORD   , #Red)              ; 
 
 ; lower characters are important 
 Global Keyword$ = "structure endstructure procedure endprocedure " + 
                   "if endif for next " + 
                   "repeat until " + 
                   "global protected " + 
                   "" 
 *PtrKWords = UTF8(Keyword$)
 ScintillaSendMessage(0, #SCI_SETKEYWORDS, 0,  *PtrKWords)  ; <= only 0 is working 
 FreeMemory(*PtrKWords)
 
 Delay(100)
 Canal = ReadFile(#PB_Any, #PB_Compiler_File, #PB_UTF8)
 
 If Canal
  
  TailleFichier = Lof(Canal)
  *Ptr = AllocateMemory(TailleFichier)
  ReadData(Canal, *Ptr, TailleFichier)
  CloseFile(Canal)
  ScintillaSendMessage(SciID, #SCI_SETTEXT, 0, *Ptr) 
  FreeMemory(*Ptr)
  
 Else
  
  MessageRequester("Erreur fichier", "Le fichier" + #CRLF$ + #PB_Compiler_File + #CRLF$ + "n'a pu être ouvert.")
  
 EndIf
 
 Repeat : Until WaitWindowEvent() = #PB_Event_CloseWindow
 
EndIf
I see when even a litte problem :|
The $ character is RED because even if it is at the end, it is considerate like #SCE_B_HEXNUMBER :shock:
It's right in PB, at the begining it's a #SCE_B_HEXNUMBER but at the end it's a variable
Believe you there are a way for explain that to the LEXER ?
Axoloti wrote:BTW: Your DLL is probably x86.
Yes the DLL is X86
ImageThe happiness is a road...
Not a destination

PureBasic French Forum
threedslider
Enthusiast
Enthusiast
Posts: 530
Joined: Sat Feb 12, 2022 7:15 pm

Re: ScintillaGadget using LEXER

Post by threedslider »

Ok thanks for your info :)
Axolotl
Addict
Addict
Posts: 919
Joined: Wed Dec 31, 2008 3:36 pm

Re: ScintillaGadget using LEXER

Post by Axolotl »

@KCC all good and thanks.
Such large letters are not necessary. I am always happy when I can help a little. By the way, I like your posts....
I like to spend time on this, because I am always curious and have been trying to understand the Scintilla/Lexilla stuff for quite some time now.

Back to the topic:
The Lexer Implementation is a combination of different Basic dialects. (see comment line above)
Unfortunately, due to the special syntax in PB, some things are not displayed/processed correctly. (see C++ implementation)
(Well, this applies to all/many editors I know of that support PB syntax highlighting even if they dont use the lexilla.dll)
The constants #Constant and the string variables String$ are particularly 'critical'.
Many of the above constants (#SCE_B_Xxxx) are due to other Basic dialects and have no effect on PB code.
What needs to be done to improve this:
a) Improve the existing lexer “LexBasic.cxx”.
b) Separate the lexer and improve your own lexer.
However, I fear that this will not happen because no one will volunteer to do it.

BTW: For your original problem with HTML/... there is a separate lexer in the above-mentioned GitHub directory.... As I have shown, you can find the constants used in these source codes.
Just because it worked doesn't mean it works.
PureBasic 6.04 (x86) and <latest stable version and current alpha/beta> (x64) on Windows 11 Home. Now started with Linux (VM: Ubuntu 22.04).
Post Reply