Тест автоматической подсветки кода, для разных тем.

Код:
;.  ________           _____    _________     _________     
;.  ___  __/_____________  /_   __  ____/___________  /____ 
;.  __  /  _  _ \_  ___/  __/   _  /    _  __ \  __  /_  _ \
;.  _  /   /  __/(__  )/ /_     / /___  / /_/ / /_/ / /  __/
;.  /_/    \___//____/ \__/     \____/  \____/\__,_/  \___/ 

; © Webarion
; Version 0.1a

EnableExplicit

DeclareModule Settings
  
  EnableExplicit
  
  XIncludeFile "Internal"+#PS$+"Config.pb" ; подключение конфигурации
  
  Macro Change_MapElement_Settings(MyMap, MapElement)
    FindMapElement( MyMap, PeekS( PeekI( MapElement - SizeOf(Integer) ) ) )
  EndMacro
  
  ;- ОБЪЯВЛЕНИЕ РЕГУЛЯРНЫХ ВЫРАЖЕНИЙ
  Enumeration REGEXP
    #REGEX_Get_Comment_Or_Space
    #REGEX_Split_Link_Line
    #REGEX_Get_Link
    #REGEX_Name_Section_Line
    #REGEX_Item_Line
    #REGEX_Parameter
  EndEnumeration
  
  ;- ОБЪЯВЛЕНИЕ ПОЛЬЗОВАТЕЛЬСКИХ ПРОЦЕДУР                                                                                                
  
  ; Container
  Declare   Set_Container( Container$ )                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                             
  Declare.a Examine_Containers()                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                      
  Declare   Next_Container()                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                          
  Declare.s Get_Current_Container_Name()  
  
  ; Section
  Declare   Set_Section( Container$, Section$, Comment$ = "", CommentPos.a = 1 )     
  Declare.a Examine_Sections( Container$ )                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                           
  Declare   Next_Section()                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                               
  Declare.s Get_Current_Section_Name()                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                               
  
  ; Item
  Declare   Examine_Items( Container$, Section$ )                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                    
  Declare   Next_Item()                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                 
  Declare.s Get_Current_Item_Name()                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                  
  Declare.s Get_Current_Item_Value()                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                 
  Declare.a Set_Item_String( Container$, Section$, Item$, Value$, Comment$ = "", CommentPos.a = 1 )                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                            
  Declare.s Get_Item_String( Container$, Section$, Item$, Default_Value$ = "" )                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                      
  Declare.s Get_Item_Template_String( Container$, Section$, Item$, Default_Value$ = "" )                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                             
  Declare   Set_Item_Integer( Container$, Section$, Item$, Value, Comment$ = "", CommentPos.a = 1 )                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                   
  Declare   Get_Item_Integer( Container$, Section$, Item$, Default_Value = 0 )
  
  ; Param
  Declare   Examine_Params( Container$, Section$, Item$ )                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                            
  Declare   Next_Param()                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                             
  Declare.s Get_Current_Param_Name()                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                 
  Declare.s Get_Current_Param_Value()                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                
  Declare   Set_Param_String( Container$, Section$, Item$, Param$, Value$ )                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                          
  Declare.s Get_Param_String( Container$, Section$, Item$, Param$, Default_Value$ = "" )                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                             
  Declare   Set_Param_Integer( Container$, Section$, Item$, Param$, Value )                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                          
  Declare   Get_Param_Integer( Container$, Section$, Item$, Param$, Default_Value = 0 )                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                              
  Declare   Set_Parameters_String( Container$, Section$, Item$, Param1.s, Value1.s, Param2.s = "", Value2.s = "", Param3.s = "", Value3.s = "", Param4.s = "", Value4.s = "", Param5.s = "", Value5.s = "", Param6.s = "", Value6.s = "", Param7.s = "", Value7.s = "", Param8.s = "", Value8.s = "", Param9.s = "", Value9.s = "", Param10.s = "", Value10.s = "", Param11.s = "", Value11.s = "", Param12.s = "", Value12.s = "", Param13.s = "", Value13.s = "", Param14.s = "", Value14.s = "", Param15.s = "", Value15.s = "", Param16.s = "", Value16.s = "", Param17.s = "", Value17.s = "", Param18.s = "", Value18.s = "", Param19.s = "", Value19.s = "", Param20.s = "", Value20.s = "", Param21.s = "", Value21.s = "", Param22.s = "", Value22.s = "", Param23.s = "", Value23.s = "", Param24.s = "", Value24.s = "", Param25.s = "", Value25.s = "", Param26.s = "", Value26.s = "", Param27.s = "", Value27.s = "", Param28.s = "", Value28.s = "", Param29.s = "", Value29.s = "", Param30.s = "", Value30.s = "" ) 
  
  ; Other
  Declare   Load_File( FilePath$, Container$ = "", Flags_File = #PB_UTF8 )                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                           
  Declare   Save_File( FilePath$, Container$ = "", Flags_File = #PB_UTF8 )                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                
  Declare   Free_RegEx() 
  
  ; ОБЪЯВЛЕНИЕ АРХИТЕКТУРЫ
  ; на данный момент, используется единственная архитектура по умолчанию
  ; #SETTINGS_ARCHITECTURE = #Architecture_Default
  
  XIncludeFile "Internal"+#PS$+"Architectures"+#PS$+"Default_Architecture"+#PS$+"Default_Architecture_Declares.pb"
  
  ;- ОБЪЯВЛЕНИЕ РАСШИРЕНИЙ
  
  ;- - COMMENTS
  ; расширение, позволяющее создавать комментарии
  CompilerIf #EXTENSION_COMMENTS
    XIncludeFile "Internal"+#PS$+"Extensions"+#PS$+"Comments"+#PS$+"Comments_Declares.pb"
  CompilerEndIf
  
  ;- - TREE
  ; расширение, позволяющее читать и сохранять древовидную конфигурацию
  ; Пример .:Item1 = Value1
  ;         :  Item2 = Value2
  ;         :    Item3 = Value3
  CompilerIf #EXTENSION_TREE
    XIncludeFile "Internal"+#PS$+"Extensions"+#PS$+"Tree"+#PS$+"Tree_Declares.pb"
  CompilerEndIf
  
EndDeclareModule

Module Settings
  
  ;- СИСТЕМНЫЕ ПРОЦЕДУРЫ                                                                                                            
  
  XIncludeFile "Internal"+#PS$+"RegexReplace.pb"
  
  ; очищает строку от пробелов
  Procedure.s _Clear_All_Space_String(Text$)
    While FindString(Text$, " ") : Text$ = ReplaceString(Text$, " ", "") : Wend 
    ProcedureReturn Text$
  EndProcedure
  
  ; #СИСТЕМНАЯ ПРОЦЕДУРА# ============================================================================================================
  ; Описание ...: Ищет в тексте неэкранированную строку
  ; Параметры ..: Text$        - Текст, в котором происходит поиск
  ;             : Search_Text$ - Строка поиска
  ;             : Escape_Text$ - Экранирующий текст
  ; Возвращает .: Позицию строки от начала (первый символ = 1), если строка найдена и не экранирована
  ;             : #False - Если строка не найдена, либо данная строка экранирована
  ; ==================================================================================================================================
  Procedure _Find_Text_Not_Escape( Text$, Search_Text$, Escape_Text$ )
    Protected Find_Text = FindString( Text$, Search_Text$, 1 )
    Protected Find_Escape = FindString( Text$, Escape_Text$, Find_Text - Len(Escape_Text$) )
    If Not Find_Escape And Find_Text
      ProcedureReturn Find_Text
    EndIf
    ProcedureReturn #False
  EndProcedure
  
  ; создаёт регулярные выражения, если их нет
  Procedure _Create_RegEx()
    
    ; определяет, является ли строка комментарием либо пустой строкой
    If Not IsRegularExpression( #REGEX_Get_Comment_Or_Space )
      CreateRegularExpression( #REGEX_Get_Comment_Or_Space, "^\s*;|^\s*$" )
    EndIf   

    ; определение ссылок шаблонизатора в строке
    If Not IsRegularExpression( #REGEX_Get_Link )
      CreateRegularExpression( #REGEX_Get_Link, "(?<!\\)\{\s*(.+?)\s*\}" ) ; с двоеточием: "(?<!\\)\{\s*(.+?)\s*(?::(.+?))?\s*\}"
    EndIf     
    
    ; получение вложенностей базы относительно ссылки шаблонизатора
    If Not IsRegularExpression( #REGEX_Split_Link_Line)
      CreateRegularExpression( #REGEX_Split_Link_Line, "\s*((?:[^\\/]|\\\/)+)" )
    EndIf 
    
    ; определение имени секции
    If Not IsRegularExpression( #REGEX_Name_Section_Line )
      CreateRegularExpression( #REGEX_Name_Section_Line, "^\s*\[(.*)\]" )
    EndIf 
    
    ; определение элемента
    If Not IsRegularExpression( #REGEX_Item_Line )
      CreateRegularExpression( #REGEX_Item_Line, "^(\s*)(.+?)\s*(:|=)\s*(.+?)\s*$" ) ;"^(\s*)(?:([^:]+?)\s*(?<!\\)=\s*(.*?)\s*|([^=]+?)\s*(?<!\\):\s*(.*)\s*)$" )
    EndIf 

    If Not IsRegularExpression( #REGEX_Parameter )
      CreateRegularExpression( #REGEX_Parameter, "\s*(.*?)\s*(?:(?<!\\)=\s*(.*?))?\s*(?:[^\\]\||\z)" )
    EndIf 
  EndProcedure
  _Create_RegEx()

  ;- ПОДКЛЮЧЕНИЕ ПРОЦЕДУР АРХИТЕКТУРЫ
  ; на данный момент включает единственную архитектуру по умолчанию
  XIncludeFile "Internal"+#PS$+"Architectures"+#PS$+"Default_Architecture"+#PS$+"Default_Architecture_Procedures.pb" 
  
  
  ;- --- LINKS
  
  ; разделяет ссылку шаблонизатора на уровни иерархии
  Procedure _Split_Link( Line$, List lList$() )
    If IsRegularExpression( #REGEX_Split_Link_Line )
      ClearList( lList$() ) 
      If ExamineRegularExpression( #REGEX_Split_Link_Line, Line$ )
        While NextRegularExpressionMatch( #REGEX_Split_Link_Line )
          AddElement( lList$() )
          lList$() = Trim( RegularExpressionGroup( #REGEX_Split_Link_Line, 1) )
        Wend
      EndIf
    EndIf
  EndProcedure
  
  ; #СИСТЕМНАЯ ПРОЦЕДУРА# ============================================================================================================
  ; Описание ...: Процедура линкера. Заменяет ссылку на данные, расположенные по этой ссылке
  ; ==================================================================================================================================
  Global NewMap g_History_Link$()
  
  ; декларация внутренней процедуры линкера.
  Declare.s _Get_Link_String( Link$, Default_Value$ = "", Container$ = "" ) 
  
  Procedure.s _Replace_Link( Line$, Container$ = "" )
    
    ; ищем ссылки линкера
    If IsRegularExpression( #REGEX_Get_Link ) And ExamineRegularExpression( #REGEX_Get_Link, Line$ )
      While NextRegularExpressionMatch( #REGEX_Get_Link )
        Define Find_Text$ = Trim( RegularExpressionMatchString( #REGEX_Get_Link ) )
        Define Link$      = RegularExpressionGroup( #REGEX_Get_Link, 1 )
        
        Define NoSpace_Find$ = LCase( _Clear_All_Space_String(Find_Text$) ) ; удаляем все пробелы из строки
        
        If Link$
          Define Find_History = FindMapElement( g_History_Link$(), NoSpace_Find$ ) ; узнаём записана ли ссылка в истории
          AddMapElement( g_History_Link$(), NoSpace_Find$ )
          
          If Find_History ; если ссылка найдена в истории, значит она циклическая, сбрасываем историю и выходим без преобразования ссылки
            ClearMap( g_History_Link$() )
            ProcedureReturn Line$
          EndIf
          
          Define Replace$ = _Get_Link_String( Link$, "", Container$ ) ; TODO DEFAULT 
          Line$ = ReplaceString(Line$, Find_Text$, Replace$, #PB_String_NoCase)

        EndIf
      Wend
    EndIf
    ProcedureReturn Line$
  EndProcedure

  Procedure.s _Get_Replace_Link_Item_String( Container$, Section$, Item$, Default_Value$ = "" )
    Default_Value$ = _Get_Item_String( Container$, Section$, Item$, Default_Value$ )
    ProcedureReturn _Replace_Link( Default_Value$, Container$ )
  EndProcedure
  
  Procedure.s _Get_Replace_Link_Param_String( Container$, Section$, Item$, Param$, Default_Value$ = "" )
    Default_Value$ = _Get_Param_String( Container$, Section$, Item$, Param$, Default_Value$ )
    ProcedureReturn _Replace_Link( Default_Value$, Container$ )
  EndProcedure
  
  Procedure.s _Get_Link_String( Link$, Default_Value$ = "", Container$ = "" )
    Protected NewList Hierarchy$(), Section$, Item$, Param$
    _Split_Link( Link$, Hierarchy$() )
    FirstElement( Hierarchy$() )
    Select ListSize( Hierarchy$() ) 
      Case 1 ; поиск в ""/Item - когда Section пустой
        ProcedureReturn _Get_Replace_Link_Item_String( Container$, "", Hierarchy$(), Default_Value$ )
      Case 2 ; поиск в Section/Item
        Section$ = Hierarchy$()
        NextElement( Hierarchy$() )
        Item$ = Hierarchy$()
        ProcedureReturn _Get_Replace_Link_Item_String( Container$, Section$, Item$, Default_Value$ )
      Case 3  ; поиск в Section/Item/Param
        Section$ = Hierarchy$()
        NextElement( Hierarchy$() )
        Item$    = Hierarchy$()
        NextElement( Hierarchy$() )
        Param$   = Hierarchy$()
        ProcedureReturn _Get_Replace_Link_Param_String( Container$, Section$, Item$, Param$, Default_Value$ )
    EndSelect  
    ProcedureReturn Default_Value$
  EndProcedure
  
  ;- ПОДКЛЮЧЕНИЕ ПРОЦЕДУР РАСШИРЕНИЙ                                                                                                          
  CompilerIf #EXTENSION_COMMENTS
    XIncludeFile "Internal"+#PS$+"Extensions"+#PS$+"Comments"+#PS$+"Comments_Procedures.pb"
  CompilerEndIf
  
  CompilerIf #EXTENSION_TREE
    XIncludeFile "Internal"+#PS$+"Extensions"+#PS$+"Tree"+#PS$+"Tree_Procedures.pb"
  CompilerEndIf
  
  ;- ПОДКЛЮЧЕНИЕ ПОЛЬЗОВАТЕЛЬСКИХ ПРОЦЕДУР                                                                                                   
  
  XIncludeFile "User_Procedures"+#PS$+"3_Containers.pb"
  XIncludeFile "User_Procedures"+#PS$+"4_Sections.pb"
  XIncludeFile "User_Procedures"+#PS$+"5_Items.pb"
  XIncludeFile "User_Procedures"+#PS$+"6_Params.pb"
  XIncludeFile "User_Procedures"+#PS$+"7_Load_Save.pb"
  XIncludeFile "User_Procedures"+#PS$+"8_RegEx.pb"
  
  ; #ПОЛЬЗОВАТЕЛЬСКАЯ ПРОЦЕДУРА# ============================================================================================================
  ; Описание ...: Получает данные, по иерархической ссылке
  ; Параметры ..: Link$ - Иерархическая ссылка к данным. Например: Elements/Начало/Default
  ;             : Container$ [ По умолчанию = "" ] - контейнер, внутри которого будут извлечены данные
  ; Возвращает .: данные из базы данных, соответствующие иерархической ссылке
  ; Пример .....: Get_Link_String( "SectionName/ItemName/ParamName", "ContainerName" )
  ; =========================================================================================================================================
  Procedure.s Get_Link_String( Link$, Default_Value$ = "", Container$ = "" )
    ClearMap( g_History_Link$() ) ; сбрасываем предохранитель от циклических ссылок
    ProcedureReturn _Get_Link_String( Link$, Default_Value$, Container$ )
  EndProcedure
  
EndModule

; Математика прямоугольников

Procedure.l _Min( a.l, b.l )
  If( a < b ) : ProcedureReturn a : EndIf
  ProcedureReturn b
EndProcedure

Procedure.l _Max( a.l, b.l )
  If( a < b ) : ProcedureReturn b : EndIf
  ProcedureReturn a
EndProcedure  

; проверяет, пересекаются ли структуры прямоугольников
Procedure.a _Is_Intersection_StrRectangles( *R1.DefRect, *R2.DefRect )
  If ( *R1\x + *R1\w > *R2\x ) And ( *R2\x + *R2\w > *R1\x ) And 
     ( *R1\y + *R1\h > *R2\y ) And ( *R2\y + *R2\h > *R1\y )
    ProcedureReturn #True
  EndIf
  ProcedureReturn #False
EndProcedure

; получает пересечение двух указанных структур прямоугольников и записывает его по адресу указанной структуры
; возвращает #True в случае успеха, в противном случае #False
Procedure.a _Get_Intersection_StrRectangles( *R1.DefRect, *R2.DefRect, *RetRect.DefRect )
  If _Is_Intersection_StrRectangles( *R1, *R2 ) ; если пересекаются
    Protected Rect.DefRect
    With Rect
      \x = _Max( *R1\x, *R2\x )
      \w = _Min( *R1\x + *R1\w, *R2\x + *R2\w ) - \x
      \y = _Max( *R1\y, *R2\y )
      \h = _Min( *R1\y + *R1\h, *R2\y + *R2\h ) - \y
    EndWith
    CopyStructure( @Rect, *RetRect, DefRect)
    ProcedureReturn #True
  EndIf
  ProcedureReturn #False
EndProcedure

; отвечает, находится ли прямоугольник 1 внутри прямоугольника 2
Procedure.a _Rect1_Inside_Rect2( *R1.DefRect, *R2.DefRect )
  If *R1\X >= *R2\X And *R1\X+*R1\W <= *R2\X+*R2\W And *R1\Y >= *R2\Y And *R1\Y+*R1\H <= *R2\Y+*R2\H 
    ProcedureReturn #True
  EndIf
  ProcedureReturn #False
EndProcedure

; получает четыре отсечения по четырём сторонам, между старым и новым прямоугольниками
; записывает результат в *RetRects
; возвращает соответствующие найденным сторонам флаги
; если прямоугольники не пересекаются, возвращается флаг 16
Procedure.a _Get_Four_Rects_Intersection( *Old.DefRect, *New.DefRect, *RetRects.FourRects )
  Protected RetTypes.a = 0
  If Not _Is_Intersection_StrRectangles( *Old, *New )
    ProcedureReturn 16
  EndIf
  Protected MaxONX.l = _Max( *Old\x, *New\x )
  Protected MinONX.l = _Min( *Old\x+*Old\w, *New\x+*New\w )
  
  With *RetRects
    ; верхний
    If *New\y < *Old\y
      \t\x = MaxONX
      \t\y = *New\y
      \t\w = MinONX - \t\x
      \t\h = _Max( *Old\y, *New\y ) - \t\y
      RetTypes | 1
    EndIf
    ; левый
    If *New\x < *Old\x
      \l\x = *New\x
      \l\y = *New\y
      \l\w = *Old\x - \l\x
      \l\h = *New\h
      RetTypes | 2
    EndIf
    ; правый
    Protected NewXE.l = *New\x + *New\w
    Protected OldXE.l = *Old\x + *Old\w
    If NewXE > OldXE
      \r\x = OldXE
      \r\y = *New\y
      \r\w = NewXE - \r\x
      \r\h = *New\h
      RetTypes | 4
    EndIf
    ; нижний
    Protected NewYE.l = *New\y + *New\h
    Protected OldYE.l = *Old\y + *Old\h
    If NewYE > OldYE
      \b\x = MaxONX
      \b\y = OldYE
      \b\w = MinONX - \b\x
      \b\h = NewYE  - \b\y
      RetTypes | 8
    EndIf
  EndWith
  ProcedureReturn RetTypes
EndProcedure

; ЕЩЁ ПРИМЕРЫ ОФОРМЛЕНИЯ

;.  ______                __        ____                __            
;. /\__  _\              /\ \__    /\  _`\             /\ \           
;. \/_/\ \/    __    ____\ \ ,_\   \ \ \/\_\    ___    \_\ \     __   
;.    \ \ \  /'__`\ /',__\\ \ \/    \ \ \/_/_  / __`\  /'_` \  /'__`\ 
;.     \ \ \/\  __//\__, `\\ \ \_    \ \ \L\ \/\ \L\ \/\ \L\ \/\  __/ 
;.      \ \_\ \____\/\____/ \ \__\    \ \____/\ \____/\ \___,_\ \____\
;.       \/_/\/____/\/___/   \/__/     \/___/  \/___/  \/__,_ /\/____/
;.                                                                    

;. _/_/_/_/_/                      _/            _/_/_/                  _/           
;.    _/      _/_/      _/_/_/  _/_/_/_/      _/          _/_/      _/_/_/    _/_/    
;.   _/    _/_/_/_/  _/_/        _/          _/        _/    _/  _/    _/  _/_/_/_/   
;.  _/    _/            _/_/    _/          _/        _/    _/  _/    _/  _/          
;. _/      _/_/_/  _/_/_/        _/_/        _/_/_/    _/_/      _/_/_/    _/_/_/     

;. __ __|            |         ___|             |       
;.    |   _ \   __|  __|      |       _ \    _` |   _ \ 
;.    |   __/ \__ \  |        |      (   |  (   |   __/ 
;.   _| \___| ____/ \__|     \____| \___/  \__,_| \___|