Scintilla If-Else-Endif

Just starting out? Need help? Post your questions and find answers here.
Lite
User
User
Posts: 17
Joined: Fri Dec 21, 2012 7:50 am

Scintilla If-Else-Endif

Post by Lite »

Hello

How works "Else" correct ?

Here is my code:

Code: Select all


InitScintilla("Scintilla.dll")
 

Enumeration 0 
   #LexerState_Space 
   #LexerState_Comment 
   #LexerState_Keyword 
   #LexerState_FoldKeyword 
 EndEnumeration 
 
 Procedure MakeUTF8Text(text$)
  Static buffer.s
  buffer = Space(StringByteLength(text$, #PB_UTF8)+1)
  PokeS(@buffer, text$, -1, #PB_UTF8)
  ProcedureReturn @buffer
EndProcedure
 
Procedure MyLexerInit()
   
   ScintillaSendMessage(0, #SCI_STYLESETFONT,#STYLE_DEFAULT, @"Lucida Console") 
   
   ScintillaSendMessage(0, #SCI_STYLESETSIZE,#STYLE_DEFAULT, 10) 
   ScintillaSendMessage(0, #SCI_STYLECLEARALL) 
   
   
   ScintillaSendMessage(0, #SCI_SETCARETLINEBACK,RGB(254, 252, 202)) 
   
   ScintillaSendMessage(0, #SCI_SETCARETLINEVISIBLE,#True) 
   
  
   ScintillaSendMessage(0, #SCI_STYLESETFORE,#LexerState_Comment, $ff00)  
   ScintillaSendMessage(0, #SCI_STYLESETITALIC,#LexerState_Comment, 1) 
   ScintillaSendMessage(0, #SCI_STYLESETFORE,#LexerState_Keyword, 0)  
   ScintillaSendMessage(0, #SCI_STYLESETFORE,#LexerState_FoldKeyword, $FF) 
   
   ; Margins 
  ; ScintillaSendMessage(0, #SCI_SETMARGINTYPEN, 0, #SC_MARGIN_NUMBER)
   ScintillaSendMessage(0, #SCI_SETMARGINMASKN, 2, #SC_MASK_FOLDERS) 
   ScintillaSendMessage(0, #SCI_SETMARGINWIDTHN, 0, 20) 
   ScintillaSendMessage(0, #SCI_SETMARGINWIDTHN, 2, 20) 
   ScintillaSendMessage(0, #SCI_SETMARGINSENSITIVEN, 2, #True) 
   
   ; Иконки свёртки текста 
   ScintillaSendMessage(0, #SCI_MARKERDEFINE, #SC_MARKNUM_FOLDER, #SC_MARK_CIRCLEPLUS) 
   ScintillaSendMessage(0, #SCI_MARKERDEFINE, #SC_MARKNUM_FOLDEROPEN, #SC_MARK_CIRCLEMINUS) 
   ScintillaSendMessage(0, #SCI_MARKERDEFINE, #SC_MARKNUM_FOLDERSUB, #SC_MARK_VLINE) 
   ScintillaSendMessage(0, #SCI_MARKERDEFINE, #SC_MARKNUM_FOLDERTAIL, #SC_MARK_LCORNERCURVE) 
   ScintillaSendMessage(0, #SCI_MARKERDEFINE, #SC_MARKNUM_FOLDEREND, #SC_MARK_CIRCLEPLUSCONNECTED) 
   ScintillaSendMessage(0, #SCI_MARKERDEFINE, #SC_MARKNUM_FOLDEROPENMID, #SC_MARK_CIRCLEMINUSCONNECTED) 
   ScintillaSendMessage(0, #SCI_MARKERDEFINE, #SC_MARKNUM_FOLDERMIDTAIL, #SC_MARK_TCORNERCURVE) 
   
   ; Choose folding icon colours 
   ScintillaSendMessage(0, #SCI_MARKERSETFORE, #SC_MARKNUM_FOLDER, $FFFFFF) 
   ScintillaSendMessage(0, #SCI_MARKERSETBACK, #SC_MARKNUM_FOLDER, $FF) 
   
   ScintillaSendMessage(0, #SCI_MARKERSETFORE, #SC_MARKNUM_FOLDEROPEN, $FFFFFF) 
   ScintillaSendMessage(0, #SCI_MARKERSETBACK, #SC_MARKNUM_FOLDEROPEN, $FF) 
   
   ScintillaSendMessage(0, #SCI_MARKERSETFORE, #SC_MARKNUM_FOLDEROPENMID, $FFFFFF) 
   ScintillaSendMessage(0, #SCI_MARKERSETBACK, #SC_MARKNUM_FOLDEROPENMID, $FF00) 
   
   ScintillaSendMessage(0, #SCI_MARKERSETFORE, #SC_MARKNUM_FOLDEREND, $FFFFFF) 
   ScintillaSendMessage(0, #SCI_MARKERSETBACK, #SC_MARKNUM_FOLDEREND, $FF00) 
   
   ScintillaSendMessage(0, #SCI_MARKERSETFORE, #SC_MARKNUM_FOLDERMIDTAIL, $FFFFFF) 
   ScintillaSendMessage(0, #SCI_MARKERSETBACK, #SC_MARKNUM_FOLDERMIDTAIL, 0)
   
   ScintillaSendMessage(0, #SCI_MARKERSETFORE, #SC_MARKNUM_FOLDERSUB, $FFFFFF) 
   ScintillaSendMessage(0, #SCI_MARKERSETBACK, #SC_MARKNUM_FOLDERSUB, 0) 
   
   ScintillaSendMessage(0, #SCI_MARKERSETFORE, #SC_MARKNUM_FOLDERTAIL, $FFFFFF) 
   ScintillaSendMessage(0, #SCI_MARKERSETBACK, #SC_MARKNUM_FOLDERTAIL, 0) 
EndProcedure
 
Procedure SCI_CB(Gadget, *scinotify.SCNotification) 
 code=             *scinotify.SCNotification\nmhdr\code
 pos=              *scinotify.SCNotification\Position
 ch=               *scinotify.SCNotification\ch
 modificationType= *scinotify.SCNotification\modifiers
 text=             *scinotify.SCNotification\text
 Length=           *scinotify.SCNotification\length
 linesAdded=       *scinotify.SCNotification\linesAdded
 message=          *scinotify.SCNotification\message
 wParam=           *scinotify.SCNotification\wParam
 lParam=           *scinotify.SCNotification\lParam
 line=             *scinotify.SCNotification\line
 foldLevelNow=     *scinotify.SCNotification\foldLevelNow
 foldLevelPrev=    *scinotify.SCNotification\foldLevelPrev
 margin=           *scinotify.SCNotification\margin
 listType=         *scinotify.SCNotification\listType
 x=                *scinotify.SCNotification\x
 y=                *scinotify.SCNotification\y
 
 
 Select code
      Case #SCN_MARGINCLICK 
         ; Update folding 
         linenumber = ScintillaSendMessage(0,#SCI_LINEFROMPOSITION,pos ) 
        ; Debug "linenumber"
         Select margin 
            Case 2 
               ScintillaSendMessage(0,#SCI_TOGGLEFOLD,linenumber) 
         EndSelect 
      Case #SCN_STYLENEEDED
        
  
        ; Syntax highlighter   
         EndPos=pos
         EndStyledPos = ScintillaSendMessage(0,#SCI_GETENDSTYLED) 
         linenumber = ScintillaSendMessage(0,#SCI_LINEFROMPOSITION,EndStyledPos) 
         
         If linenumber = 0 
            level = #SC_FOLDLEVELBASE 
         Else 
            linenumber - 1 
            level = ScintillaSendMessage(0,#SCI_GETFOLDLEVEL,linenumber) & ~ #SC_FOLDLEVELHEADERFLAG 
         EndIf 
         
         thislevel = level 
         nextlevel = level 
         
         CurrentPos.l = ScintillaSendMessage(0,#SCI_POSITIONFROMLINE,linenumber) 
         ScintillaSendMessage(0,#SCI_STARTSTYLING,CurrentPos, $1F | #INDICS_MASK) 
         State = #LexerState_Space 
         KeywordStartPos = CurrentPos 
         keyword.s = "" 
         
         While CurrentPos <= EndPos 
            OldState = State 
            
            Char.l = ScintillaSendMessage(0,#SCI_GETCHARAT, CurrentPos) 
            ;Debug Chr(Char)
            If Char = ';' 
               State = #LexerState_Comment 
            ElseIf Char = 10 Or Char = 13 
               State = #LexerState_Space 
            ElseIf State <> #LexerState_Comment 
               If Char = 9 Or Char = ' ' Or Char = '.' 
                  State = #LexerState_Space 
               Else 
                  State = #LexerState_Keyword 
                  keyword + Chr(Char) 
               EndIf 
            EndIf 
          ;  Debug keyword
            If OldState <> State Or CurrentPos = EndPos 
               If OldState = #LexerState_Keyword 
                  lkeyword.s = LCase(keyword) 
                  If lkeyword = "procedure" Or lkeyword = "if" 
                     thislevel | #SC_FOLDLEVELHEADERFLAG 
                     nextlevel + 1 
                     OldState = #LexerState_FoldKeyword 
                  ElseIf lkeyword = "endprocedure" Or lkeyword = "endif" 
                     nextlevel - 1 
                     If nextlevel < #SC_FOLDLEVELBASE 
                        nextlevel = #SC_FOLDLEVELBASE 
                     EndIf 
                     OldState = #LexerState_FoldKeyword 
                  ElseIf lkeyword = "else"     
                     OldState = #LexerState_FoldKeyword 
                     thislevel |  #SC_FOLDLEVELNUMBERMASK
                  EndIf 
                  keyword = "" 
               EndIf 
               ScintillaSendMessage(0,#SCI_SETSTYLING, CurrentPos - KeywordStartPos, OldState) 
               KeywordStartPos = CurrentPos 
            EndIf 
            
            If Char = 10 Or CurrentPos = EndPos 
               ScintillaSendMessage(0,#SCI_SETFOLDLEVEL, linenumber, thislevel) 
               thislevel = nextlevel 
               linenumber + 1 
            EndIf 
            
            CurrentPos + 1 
         Wend
         
   EndSelect
EndProcedure
 
If OpenWindow(2, 450, 200, 402, 402, "Static Scintilla Example", #PB_Window_MinimizeGadget|#PB_Window_MaximizeGadget|#PB_Window_ScreenCentered|#PB_Window_SizeGadget)
 
  ScintillaGadget(0, 2, 2, 398, 398, @SCI_CB()) 
   
  MyLexerInit() 
   ; Set some sample text 
   text.s = " How work 'else' correct ?" 
   text + #CRLF$ + "" + #CRLF$
   text + #CRLF$ + "If debug =1"
   text + #CRLF$ + "  Debug(" + Chr(34) + " 1 " + Chr(34) + ")"
   text + #CRLF$ + "else"
   text + #CRLF$ + "  end "
   text + #CRLF$ + "EndIf" + #CRLF$
   ;Debug text
 ;  SetGadgetText(0,MakeUTF8Text(text))
 ScintillaSendMessage(0, #SCI_SETTEXT, 0, MakeUTF8Text(text))
  Repeat 
  Event = WaitWindowEvent() 
  Gadget=EventGadget()
  
  If Event=#PB_Event_SizeWindow
   ResizeGadget(0,#PB_Ignore,#PB_Ignore,WindowWidth(0)-4,WindowHeight(0)-2)
  EndIf
      
  Until Event=#PB_Event_CloseWindow 

EndIf 
Lite