TextHighlighter: Fix 'highlight' definition file highlighting.
[GB.HIGHLIGHT] * BUG: TextHighlighter: Understand "from here" and "between here" commands. * BUG: TextHighlighter: Fix 'highlight' definition file highlighting. * NEW: TextHighlighter: "@word" special command allows to define the regular expression that defines what a word is.
This commit is contained in:
parent
c795d95912
commit
816fbdc210
7 changed files with 71 additions and 16 deletions
|
@ -21,6 +21,7 @@ Public Sub SetArgs(aArgs As String[])
|
|||
Endif
|
||||
Else If aArgs.Count = 1 Then
|
||||
$sFrom = aArgs[0]
|
||||
If $sFrom = "here" Then $sFrom = ""
|
||||
$sTo = "\n"
|
||||
Else
|
||||
Error.Raise("Syntax error")
|
||||
|
|
|
@ -21,6 +21,7 @@ Public Sub SetArgs(aArgs As String[])
|
|||
Endif
|
||||
Else If aArgs.Count = 1 Then
|
||||
$sFrom = aArgs[0]
|
||||
If $sFrom = "here" Then $sFrom = ""
|
||||
$sTo = "\n"
|
||||
Else
|
||||
Error.Raise("Syntax error")
|
||||
|
@ -99,6 +100,15 @@ Public Sub Compile(hState As CState)
|
|||
|
||||
hState.Continue()
|
||||
CState.Print("Endif")
|
||||
|
||||
' If $sMatch Then
|
||||
' If CState.IsRegExp($sMatch) Then
|
||||
' CState.Print("sWord = Match(" & Quote(CState.Pattern) & ")")
|
||||
' CState.Print("If Not sWord Then Goto " & hState.GetContinueLabel())
|
||||
' Else
|
||||
' CState.IfStartWith(CState.Pattern, hState.GetContinueLabel())
|
||||
' Endif
|
||||
' Endif
|
||||
|
||||
hState.CompileChildren(hState.GetLabel() & "_LOOP", True)
|
||||
|
||||
|
|
|
@ -22,13 +22,13 @@ Public Sub Main()
|
|||
'File.Save("~/test.html", TextHighlighter["sh"].ToHTML(File.Load("~/gambas/git/master/acinclude.m4")))
|
||||
|
||||
'Print TextHighlighter["javascript"].ToANSI(File.Load("~/asap/omogen/master/src/kernel/guygle.cgi/javascript/selectr.js"))
|
||||
With TextHighlighter["javascript"]
|
||||
With TextHighlighter["highlight"]
|
||||
Print .Colors.Join()
|
||||
'Print .ToANSI(File.Load("~/asap/omogen/master/src/kernel/guygle.cgi/style/style-modern.css"))
|
||||
'Print .ToANSI(File.Load("~/gambas/git/master/comp/src/gb.desktop/.src/Desktop.class"))
|
||||
'Print .ToANSI(File.Load("~/asap/omogen/master/src/kernel/guygle.cgi/.src/Site/Dialog.webpage"))
|
||||
'Print .ToANSI(File.Load("highlight/c.highlight"))
|
||||
Print .ToANSI("'ceci est une chaîne avec \\\'function(toto){}'")
|
||||
File.Save("~/test.html", .ToHTML(File.Load("highlight/webpage.highlight")))
|
||||
'Print .ToANSI("'ceci est une chaîne avec \\\'function(toto){}'")
|
||||
'File.Save("~/test.html", .ToHTML(File.Load("~/asap/omogen/master/src/kernel/guygle.cgi/.src/Site/CloseMe.webpage")))
|
||||
End With
|
||||
|
||||
|
|
|
@ -288,6 +288,7 @@ Static Private Sub CreateCustomHighlighter(sHighlight As String, sPath As String
|
|||
Dim aLines As String[]
|
||||
Dim aInclude As String[]
|
||||
Dim I As Integer
|
||||
Dim sWordRegExp As String = "[A-Za-z_][A-Za-z0-9_]*"
|
||||
|
||||
sDir = File.Dir(Temp$()) &/ "gb.highlight." & sHighlight
|
||||
|
||||
|
@ -335,6 +336,16 @@ Static Private Sub CreateCustomHighlighter(sHighlight As String, sPath As String
|
|||
Continue
|
||||
Endif
|
||||
|
||||
If sLine Begins "@word " Then
|
||||
sWordRegExp = Trim(Mid$(sLine, 7))
|
||||
If sWordRegExp Begins "/" And If sWordRegExp Ends "/" Then
|
||||
sWordRegExp = Mid$(sWordRegExp, 2, -1)
|
||||
Else
|
||||
sWordRegExp = ""
|
||||
Endif
|
||||
If Not sWordRegExp Then Error.Raise("Syntax error. Bad regular expression")
|
||||
Endif
|
||||
|
||||
If sLine Begins "$(" Then
|
||||
sLine = Mid$(sLine, 3)
|
||||
iPos = InStr(sLine, ")=")
|
||||
|
@ -408,6 +419,7 @@ Static Private Sub CreateCustomHighlighter(sHighlight As String, sPath As String
|
|||
CState.Print("aKeywords.ReadOnly = True")
|
||||
CState.Print("Return aKeywords")
|
||||
CState.Print("End")
|
||||
CState.Print("Static $sWordRegExp As String = " & Quote(sWordRegExp))
|
||||
|
||||
' CState.Print("Public Sub GetStateFromName(sName As String) As Integer")
|
||||
' CState.Print()
|
||||
|
|
|
@ -7,7 +7,6 @@ Inherits TextHighlighter
|
|||
Property Read Keywords As String[]
|
||||
|
||||
Static Private $hWordRegExp As RegExp
|
||||
Static Private $sWordRegExp As String
|
||||
Static Private $cRegExp As New Collection
|
||||
|
||||
Private $sText As String
|
||||
|
@ -34,7 +33,6 @@ Private Sub Init(sText As String)
|
|||
$bTextAfter = False
|
||||
|
||||
If Not $hWordRegExp Then
|
||||
$sWordRegExp = "[A-Za-z_][A-Za-z0-9_]*"
|
||||
$hWordRegExp = New RegExp
|
||||
$hWordRegExp.Compile("^" & $sWordRegExp & "(.*)")
|
||||
Endif
|
||||
|
|
|
@ -10,8 +10,8 @@ file{File=Keyword}:
|
|||
position{Position=Datatype}:
|
||||
from /^@@/ to @@
|
||||
added{Added}:
|
||||
from /^\+/ to "\n"
|
||||
from /^\+/
|
||||
removed{Removed}:
|
||||
from /^-/ to "\n"
|
||||
from /^-/
|
||||
normal:
|
||||
from /./ to "\n"
|
||||
from /./
|
||||
|
|
|
@ -1,13 +1,47 @@
|
|||
@word /\S+/
|
||||
$(IDENT)=[A-Za-z][A-Za-z0-9.]*
|
||||
comment:
|
||||
from #
|
||||
class{Function}:
|
||||
match /$(IDENT)({$(IDENT)(=$(IDENT))?})?:/
|
||||
subst{Preprocessor}:
|
||||
from /^\$\($(IDENT)\)=/
|
||||
command.from{Keyword}:
|
||||
from "from" to "\n"
|
||||
command.to{Keyword}:
|
||||
match "to"
|
||||
@include highlight.arg
|
||||
command.match{Keyword}:
|
||||
from "match" to "\n"
|
||||
@include highlight.arg
|
||||
include{Preprocessor}:
|
||||
from "@include"
|
||||
command{Keyword}:
|
||||
match /(from|between|match)/
|
||||
args:
|
||||
from here
|
||||
keyword:
|
||||
match /(to|and|here)/
|
||||
with{Preprocessor}:
|
||||
from "with"
|
||||
arg{Normal}:
|
||||
word " "" / // /* /**
|
||||
space{Normal}:
|
||||
match /(/s|[^"/])/
|
||||
string:
|
||||
match "\""
|
||||
string.contents{String}:
|
||||
between here and /\s/
|
||||
string.subst{Preprocessor}:
|
||||
match /\$\($(IDENT)\)/
|
||||
escape:
|
||||
match /\\[fnrtv0'"\\]/
|
||||
match /\\x[0-9a-fA-F]{2}/
|
||||
regexp{Datatype}:
|
||||
match "/"
|
||||
regexp.contents{Datatype}:
|
||||
between here and /\s/
|
||||
regexp.subst{Preprocessor}:
|
||||
match /\$\($(IDENT)\)/
|
||||
regexp.escape{Escape}:
|
||||
match /\\./
|
||||
word{Keyword}:
|
||||
match /(word|keyword|symbol)/
|
||||
args{Normal}:
|
||||
from here
|
||||
include{Preprocessor}:
|
||||
from @
|
||||
limit{Keyword}:
|
||||
match "limit"
|
||||
|
|
Loading…
Reference in a new issue