Scintilla Documentation Processing

Everything else that doesn't fall into one of the other PB categories.
AZJIO
Addict
Addict
Posts: 1298
Joined: Sun May 14, 2017 1:48 am

Scintilla Documentation Processing

Post by AZJIO »

Earlier I wrote a script to highlight the Scintilla documentation code to make it easier to read.
Save this page in the program folder. Run the program and get the highlighted code.

Corrected version, now works:

Code: Select all

EnableExplicit
Define Format, Text$, type$
Define Text.string


Procedure.s RegexReplace2(*Result.string, Find$, Replace0$)
	Protected i, CountGr, Pos, Offset = 1
	Protected Result$, Replace$
	Protected NewList item.s()
	Protected LenT, *Point ;, Count
	Protected RgEx
	
	RgEx = CreateRegularExpression(#PB_Any, Find$, #PB_RegularExpression_NoCase)
	If RgEx
		
		CountGr = CountRegularExpressionGroups(RgEx)
; ограничение групп, только обратные ссылки \1 .. \9
; 		If CountGr > 9
; 			CountGr = 9
; 		EndIf
		
		If ExamineRegularExpression(RgEx, *Result\s)
			While NextRegularExpressionMatch(RgEx)
				Pos = RegularExpressionMatchPosition(RgEx)
; 				Убрал поиск группы \0 так как отсутствует в данных регулярных выражениях
; 				Replace$ = ReplaceString(Replace0$,"\0", RegularExpressionMatchString(RgEx)) ; обратная ссылка \0
				Replace$ = Replace0$
				For i = 1 To CountGr
					Replace$ = ReplaceString(Replace$, "\"+Str(i), RegularExpressionGroup(RgEx, i))
				Next
				; item() = часть строки между началом и первым совпадением или между двумя совпадениями + результат подстановки групп
				
				If AddElement(item())
					item() = Mid(*Result\s, Offset, Pos - Offset) + Replace$
				EndIf
				Offset = Pos + RegularExpressionMatchLength(RgEx)
			Wend
		EndIf
		FreeRegularExpression(RgEx)
		
		If AddElement(item())
			item() = Mid(*Result\s, Offset)
		EndIf
		
		; Формирования текстового списка
		; Debug "Count = " + Str(ListSize(item()))
		; Count = ListSize(item())
		LenT = 0
		ForEach item()
			LenT + Len(item()) ; вычисляем длину данных для  вмещения частей текста
		Next
		
		*Result\s = Space(LenT) ; создаём строку забивая её пробелами
		*Point = @*Result\s		; Получаем адрес строки
		ForEach item()
			CopyMemoryString(item(), @*Point) ; копируем очередной путь в указатель
		Next
		; Конец => Формирования текстового списка
		
		FreeList(item()) ; удаляем список, хотя в функции наверно это не требуется
	Else
		Debug RegularExpressionError()
	EndIf
EndProcedure

#File = 0
If ReadFile(#File, GetCurrentDirectory() + "\Scintilla Documentation.html")
	Format = ReadStringFormat(#File)
	Text\s = ReadString(#File, Format | #PB_File_IgnoreEOL)
	; 	Text$ = ReadString(#File, #PB_UTF8 | #PB_File_IgnoreEOL)
	CloseFile(#File)
EndIf

Structure RegExpStr
	find.s
	repl.s
EndStructure

type$ = "bool|int|const char|char|document|colouralpha|colour|Sci_TextRange|Sci_TextToFind|cell|position|alpha|line|pointer"

NewList RegExpStr.RegExpStr()
; Text\s=ReplaceString(Text\s, "<unused>", "&lt;unused&gt;")
; функция множество параметров
If AddElement(RegExpStr())
	RegExpStr()\find = "(?i)(SCI_(?:\w+))\(((?:(?:" + type$ + ")\s+[\s\w*-]+,\s+)?(?:" + type$ + ")\s+[\s\w*-]+)\)"
	RegExpStr()\repl = "<span class='func'>\1</span><span class='oper'>(</span><span class='cont'>\2</span><span class='oper'>)</span>"
EndIf
; функция 1 параметр
If AddElement(RegExpStr())
	RegExpStr()\find = "(?i)(<span class='cont'>(?:" + type$ + "))\s+([\h\w*-]+</span>)"
	RegExpStr()\repl = "\1</span> <span class='nparam'>\2"
EndIf
; функция 2 параметра
If AddElement(RegExpStr())
	RegExpStr()\find = "(?i)(<span class='cont'>(?:" + type$ + "))\s+([\s\w*-]+),\h+(" + type$ + ")\s+([\s\w*-]+</span>)"
	RegExpStr()\repl = "\1</span> <span class='nparam'>\2</span><span class='oper'>, </span><span class='cont'>\3</span><span class='nparam'> \4"
EndIf
; функция стрелка тип
If AddElement(RegExpStr())
	RegExpStr()\find = "(?i)(SCI_\w+)\s+(&#8594;)\s+(" + type$ + ")"
	RegExpStr()\repl = "<span class='func'>\1</span> <span class='oper'>\2</span> <span class='cont'>\3</span>"
EndIf
; стрелка тип
If AddElement(RegExpStr())
	RegExpStr()\find = "(?i)(?<!>)(&#8594;)\s+(" + type$ + ")"
	RegExpStr()\repl = "<span class='oper'>\1</span> <span class='cont'>\2</span>"
EndIf
; unused
If AddElement(RegExpStr())
	RegExpStr()\find = "(?i)(SCI_\w+)\(((?:(?:&lt;unused&gt;),\s+)(?:" + type$ + ")\s+[\s\w*-]+)\)"
	RegExpStr()\repl = "<span class='func'>\1</span><span class='oper'>(</span><span class='cont'>\2</span><span class='oper'>)</span>"
EndIf
; unused
If AddElement(RegExpStr())
	RegExpStr()\find = "(?i)(<span class='cont'>(?:&lt;unused&gt;)),\s+(" + type$ + ")\s+([\h\w*-]+</span>)"
	RegExpStr()\repl = "\1</span> <span class='oper'>, </span><span class='cont'>\2</span><span class='nparam'> \3"
EndIf
; стрелка
If AddElement(RegExpStr())
	RegExpStr()\find = "(?<!>)&#8594;(?!<)"
	RegExpStr()\repl = "<span class='oper'>&#8594;</span>"
EndIf
; подсветить все функции
If AddElement(RegExpStr())
	RegExpStr()\find = "(?<=>)\h*(SCI_\w+)\s*(?=</[abc])"
	RegExpStr()\repl = "<span class='func'>\1</span>"
EndIf
; константа
If AddElement(RegExpStr())
	RegExpStr()\find = "(?<=>)\h*(SC_\w+)\s*(?=</[bc])"
	RegExpStr()\repl = "<span class='const'>\1</span>"
EndIf
; убирание жирного шрифта в синтаксисе
If AddElement(RegExpStr())
	RegExpStr()\find = ~"<b( id=\"[^\v]+?)</b>"
	RegExpStr()\repl = "<span class='syntax'\1</span>"
EndIf

ForEach RegExpStr()
	RegexReplace2(@Text, RegExpStr()\find, RegExpStr()\repl)
Next



Text\s=ReplaceString(Text\s, "<title>Scintilla Documentation</title>", "<title>Scintilla Documentation</title>" + #CRLF$ + "<link type='text/css' rel='stylesheet' href='styles.css'>")

#File = 0
If CreateFile(#File, GetCurrentDirectory() + "\Scintilla Documentation Done.html")
	WriteStringFormat(#File, #PB_UTF8)
	WriteString(#File, Text\s, #PB_UTF8)
	CloseFile(#File)
EndIf
MessageRequester("Done", "Done")
styles.css

Code: Select all

body
{
	color:#000;
	background-color:#FFFFFF;
	font-weight:normal;
	font-size: 1.0em;
}

CODE { font-family: Arial, Consolas, Courier New,monospace; }
A:visited { color: blue; }
A:hover { text-decoration: underline ! important; }
A.message { text-decoration: none; font-family: Arial, Consolas, Courier New,monospace; }
A.seealso { text-decoration: none; font-family: Arial, Consolas, Courier New,monospace; }
A.toc { text-decoration: none; }
A.jump { text-decoration: none; }
A.go { text-decoration: none; background-color:#FF9;}
A.go:hover { text-decoration: none; background-color:#FF0; color:#FF0;}
LI.message { text-decoration: none; font-family: Arial, Consolas, Courier New,monospace; }
H2 { background: #E0EAFF; }

.const {
	color: #FF00FF;
}
.oper {
	color: #FF0000;
}
.func {
	color: #0080FF;
}
.cont {
	color: #00A8BF;
}
.nparam {
	color: #FF8000;
}


p{
line-height: normal;
margin-top: 0.5em;
margin-bottom: 0.5em;
}

table {
	border: 0px;
	border-collapse: collapse;
}

table.categories {
	border: 0px;
	border-collapse: collapse;
}
table.categories td {
	padding: 0px 4px;
}

table.standard {
	border-collapse: collapse;
}
table.standard th {
	background: #404040;
	color: #FFFFFF;
	padding: 1px 5px 1px 5px;
}
table.standard tr:nth-child(odd) {background: #D7D7D7}
table.standard tr:nth-child(even) {background: #F0F0F0}
table.standard td {
	padding: 1px 5px 1px 5px;
}

.S0 {
	color: #808080;
}
.S2 {
	font-family: Georgia, 'DejaVu Serif';
	color: #007F00;
	font-size: 9pt;
}
.S3 {
	font-family: Georgia, 'DejaVu Serif';
	color: #3F703F;
	font-size: 9pt;
}
.S4 {
	color: #007F7F;
}
.S5 {
	font-weight: bold;
	color: #00007F;
}
.S9 {
	color: #7F7F00;
}
.S10 {
	font-weight: bold;
	color: #000000;
}
DIV.highlighted {
	background: #F7FCF7;
	border: 1px solid #C0D7C0;
	margin: 0.3em 3em;
	padding: 0.3em 0.6em;
	font-family: 'Verdana';
	color: #000000;
	font-size: 10pt;
}
.provisional {
	background: #FFD999;
	}
.deprecated {
	text-decoration: line-through red;
	}
.parameter {
	font-style:italic;
	color: #FF8000;
	}
.go {
	border: 0px;
	margin: 0px 9px 0px 9px;
}
I made a comparison of the results, as a result, the script on AutoIt3 gives the correct result, and in PureBasic it is necessary to change regular expressions, because it works differently.
AutoIt3:

Code: Select all

$sText = FileRead(@ScriptDir & '\Scintilla Documentation.html')

$type = 'bool|int|const char|char|document|colour|Sci_TextRange|cell|position|alpha'
; функция множество параметров
$sText=StringRegExpReplace($sText, '(?i)(SCI_(?:\w+))(\()((?:(?:' & $type & ') [\h\w*-]+, )?(?:' & $type & ') [\h\w*-]+)(\))', '<span class="func">\1</span><span class="oper">\2</span><span class="cont">\3</span><span class="oper">\4</span>')

; функция 1 параметр
$sText=StringRegExpReplace($sText, '(?i)(<span class="cont">(?:' & $type & ')) ([\h\w*-]+</span>)', '\1</span> <span class="nparam">\2')

; функция 2 параметра
$sText=StringRegExpReplace($sText, '(?i)(<span class="cont">(?:' & $type & ')) ([\h\w*-]+)(, )(' & $type & ') ([\h\w*-]+</span>)', '\1</span> <span class="nparam">\2</span><span class="oper">\3</span><span class="cont">\4</span><span class="nparam"> \5')

; функция стрелка тип
$sText=StringRegExpReplace($sText, '(?i)(SCI_\w+)\h+(&#8594;)\h+(' & $type & ')', '<span class="func">\1</span> <span class="oper">\2</span> <span class="cont">\3</span>')

; стрелка тип
$sText=StringRegExpReplace($sText, '(?i)(?<!>)(&#8594;)\h+(' & $type & ')', '<span class="oper">\1</span> <span class="cont">\2</span>')

; unused
$sText=StringRegExpReplace($sText, '(?i)(SCI_(?:\w+))(\()((?:(?:&lt;unused&gt;), )(?:' & $type & ') [\h\w*-]+)(\))', '<span class="func">\1</span><span class="oper">\2</span><span class="cont">\3</span><span class="oper">\4</span>')

; unused
$sText=StringRegExpReplace($sText, '(?i)(<span class="cont">(?:&lt;unused&gt;))(, )(' & $type & ') ([\h\w*-]+</span>)', '\1</span> <span class="oper">\2</span><span class="cont">\3</span><span class="nparam"> \4')

; стрелка
$sText=StringRegExpReplace($sText, '(?<!>)&#8594;(?!<)', '<span class="oper">&#8594;</span>')

; подсветить все функции
$sText=StringRegExpReplace($sText, '(?<=>)\h*(SCI_\w+)\h*(?=</[abc])', '<span class="func">\1</span>')

; константа
$sText=StringRegExpReplace($sText, '(?<=>)\h*(SC_\w+)\h*(?=</[bc])', '<span class="const">\1</span>')

; убирание жирного шрифта в синтаксисе
$sText=StringRegExpReplace($sText, '<b( id="[^\v]+?)</b>', '<span class="syntax"\1</span>')

$sText=StringReplace($sText, '<title>Scintilla Documentation</title>', '<title>Scintilla Documentation</title>' & @CRLF & '<link type="text/css" rel="stylesheet" href="styles.css">')

$hFile = FileOpen(@ScriptDir & '\Scintilla Documentation (Style).htm', 2)
FileWrite($hFile, $sText)
FileClose($hFile)

MsgBox(0, '', 'Done')