Create custom highlighter component with two 'Shell' instructions. Add the 'limit' instruction.

[GB.HIGHLIGHT]
* BUG: Create custom highlighter component with two 'Shell' instructions, one for the compiler, and one for the archiver.
* NEW: Add the 'limit' command so that a state can define the 'TextHighlighter.Limit' flag.
* NEW: TextHighlighter: Handle the 'Limit' flag in the ToHTML() method.
* NEW: Use the 'limit' command in 'javascript' and 'diff' highlighting.
This commit is contained in:
Benoît Minisini 2023-10-29 16:48:08 +01:00
parent 587bc846a0
commit 4325f62269
7 changed files with 42 additions and 11 deletions

View File

@ -0,0 +1,15 @@
' Gambas class file
Inherits CCommand
Public Sub SetArgs(aArgs As String[])
If aArgs.Count Then Error.Raise("Syntax error")
End
Public Sub Compile((hState) As CState)
hState.Limit = True
End

View File

@ -22,6 +22,7 @@ Public Indent As Integer
Public Parent As CState
Public Commands As New CCommand[]
Public Children As New CState[]
Public Limit As Boolean
Private $iCurrentCommand As Integer
Private $iCurrentChild As Integer
@ -102,18 +103,20 @@ Public Sub AddCommand(sText As String)
Dim I As Integer
iPos = InStr(sText, " ")
If iPos = 0 Then Return
sCommand = Left(sText, iPos - 1)
If iPos = 0 Then
sCommand = sText
aArg = New String[]
Else
sCommand = Left(sText, iPos - 1)
aArg = Split(Mid$(sText, iPos + 1), " ", "", True)
For I = 0 To aArg.Max
aArg[I] = CState.Subst(aArg[I])
Next
Endif
Try hCommand = Object.New("CCommand" & UCase(Left(sCommand)) & Mid$(sCommand, 2))
If Error Then Error.Raise("Unknown command: " & sCommand)
aArg = Split(Mid$(sText, iPos + 1), " ", "", True)
For I = 0 To aArg.Max
aArg[I] = CState.Subst(aArg[I])
Next
hCommand.SetArgs(aArg)
hCommand.Init()
Commands.Add(hCommand)
@ -206,6 +209,9 @@ Public Sub Forward(Optional sLen As String, iColorIndex As Integer = ColorIndex)
Else
Print("Forward(" & CStr(iColorIndex) & ")")
Endif
If Limit Then
Print("Me.Limit = True")
Endif
End

View File

@ -17,8 +17,8 @@ Public Sub Main()
'File.Save("~/test.html", TextHighlighter["diff"].ToHTML(File.Load(Application.Path &/ ".hidden/test/diff.txt")))
'TextHighlighter.Register("~/gambas/git/master/app/src/gambas3/highlight/conflict.highlight")
'File.Save("~/test.html", TextHighlighter["conflict"].ToHTML(File.Load("test/conflict.txt")))
'File.Save("~/test.html", TextHighlighter["javascript"].ToHTML(File.Load("~/asap/omogen/master/src/kernel/guygle.cgi/javascript/selectr.js")))
File.Save("~/test.html", TextHighlighter["javascript"].ToHTML(File.Load("~/asap/omogen/master/src/kernel/guygle.cgi/javascript/selectr.js")))
'File.Save("~/test.html", TextHighlighter["webpage"].ToHTML(File.Load(Application.Path &/ ".hidden/test/Webpage1.webpage")))
File.Save("~/test.html", TextHighlighter["sh"].ToHTML(File.Load("~/gambas/git/master/comp/src/gb.desktop/xdg-utils/xdg-open")))
'File.Save("~/test.html", TextHighlighter["sh"].ToHTML(File.Load("~/gambas/git/master/acinclude.m4")))
End

View File

@ -271,7 +271,11 @@ Static Private Sub CreateCustomHighlighter(sHighlight As String, sPath As String
sProject = Replace(sProject, "$(startup)", "_TextHighlighter_" & sHighlight)
File.Save(sDir &/ ".project", sProject)
Shell "cd " & Shell$(sDir) & " && gbc3 -agt 2>&1 && gba3 2>&1" To sOutput
Shell "cd " & Shell$(sDir) & " && gbc3 -agt 2>&1" To sOutput
sOutput = Trim(sOutput)
If Process.LastValue And If sOutput Then Error.Raise(sOutput)
Shell "cd " & Shell$(sDir) & " && gba3 2>&1" To sOutput
sOutput = Trim(sOutput)
If Process.LastValue And If sOutput Then Error.Raise(sOutput)
@ -439,6 +443,8 @@ Public Sub ToHTML(Text As String, Optional Theme As TextHighlighterTheme) As Str
HighlightLine(aText[Y])
sLineHtml = ""
If Y And If Me.Limit Then sLineHtml &= "<div style=\"height:1px; background-color:#C0C0C0; margin:0.5em 0;\"></div>"
While Not HighlightToken()

View File

@ -24,6 +24,8 @@ Private $aHighlight As Byte[]
Private Sub Init(sText As String)
Me.Limit = False
$sText = sText
$iLen = String.Len($sText)
$iPos = 1

View File

@ -1,4 +1,5 @@
diff{Datatype}:
limit
from /^diff/
index{Keyword}:
from /^index/

View File

@ -32,6 +32,7 @@ number:
keyword:
keyword @javascript.keyword
function:
limit
keyword function
constant:
keyword false null this true undefined NaN Infinity