diff --git a/comp/src/gb.highlight/.src/CCommandBetween.class b/comp/src/gb.highlight/.src/CCommandBetween.class index 3e59c51fd..1a6cbcaaa 100644 --- a/comp/src/gb.highlight/.src/CCommandBetween.class +++ b/comp/src/gb.highlight/.src/CCommandBetween.class @@ -34,27 +34,26 @@ Public Sub Compile(hState As CState) If Not $sFrom Then - - Else If CState.IsRegExp(ByRef $sFrom) Then + Else If CState.IsRegExp($sFrom) Then - CState.Print("sWord = MatchBefore(" & Quote($sFrom) & ")") + CState.Print("sWord = MatchBefore(" & Quote(CState.Pattern) & ")") CState.Print("If Not sWord Then Goto " & hState.GetNextLabel()) Else - CState.IfEndWith($sFrom, hState.GetNextLabel()) + CState.IfEndWith(CState.Pattern, hState.GetNextLabel()) Endif hState.PrintLabel(hState.GetLabel() & "_LOOP") - If CState.IsRegExp(ByRef $sTo) Then + If CState.IsRegExp($sTo) Then - CState.Print("If Include(" & CStr($iInclude) & ", " & Quote($sInclude) & ", True, " & Quote($sTo) & ", aState) Then Return") + CState.Print("If Include(" & CStr($iInclude) & ", " & Quote($sInclude) & ", True, " & Quote(CState.Pattern) & ", aState) Then Return") Else - CState.Print("If Include(" & CStr($iInclude) & ", " & Quote($sInclude) & ", False, " & Quote($sTo) & ", aState) Then Return") + CState.Print("If Include(" & CStr($iInclude) & ", " & Quote($sInclude) & ", False, " & Quote(CState.Pattern) & ", aState) Then Return") Endif @@ -64,24 +63,24 @@ Public Sub Compile(hState As CState) If Not $sFrom Then - Else If CState.IsRegExp(ByRef $sFrom) Then + Else If CState.IsRegExp($sFrom) Then - CState.Print("sWord = MatchBefore(" & Quote($sFrom) & ")") + CState.Print("sWord = MatchBefore(" & Quote(CState.Pattern) & ")") CState.Print("If Not sWord Then Goto " & hState.GetNextLabel()) Else - CState.IfEndWith($sFrom, hState.GetNextLabel()) + CState.IfEndWith(CState.Pattern, hState.GetNextLabel()) Endif hState.PrintLabel(hState.GetLabel() & "_LOOP") - If CState.IsRegExp(ByRef $sTo) Then - CState.Print("sWord = Match(" & Quote($sTo) & ")") + If CState.IsRegExp($sTo) Then + CState.Print("sWord = Match(" & Quote(CState.Pattern) & ")") CState.Print("If sWord Then") Else - CState.IfStartWith($sTo) + CState.IfStartWith(CState.Pattern) Endif hState.Continue() diff --git a/comp/src/gb.highlight/.src/CCommandFrom.class b/comp/src/gb.highlight/.src/CCommandFrom.class index 88e0a1cc4..a27e10759 100644 --- a/comp/src/gb.highlight/.src/CCommandFrom.class +++ b/comp/src/gb.highlight/.src/CCommandFrom.class @@ -34,35 +34,35 @@ Public Sub Compile(hState As CState) If Not $sFrom Then - Else If CState.IsRegExp(ByRef $sFrom) Then + Else If CState.IsRegExp($sFrom) Then - CState.Print("sWord = Match(" & Quote($sFrom) & ")") + CState.Print("sWord = Match(" & Quote(CState.Pattern) & ")") CState.Print("If Not sWord Then Goto " & hState.GetNextLabel()) CState.Print("SetIncludeHighlight(" & CStr($iInclude) & ")") hState.Forward("String.Len(sWord)") Else - CState.IfStartWith($sFrom, hState.GetNextLabel()) + CState.IfStartWith(CState.Pattern, hState.GetNextLabel()) CState.Print("SetIncludeHighlight(" & CStr($iInclude) & ")") - hState.Forward(String.Len($sFrom)) + hState.Forward(String.Len(CState.Pattern)) Endif hState.PrintLabel(hState.GetLabel() & "_LOOP") - If CState.IsRegExp(ByRef $sTo) Then + If CState.IsRegExp($sTo) Then - CState.Print("If Include(" & CStr($iInclude) & ", " & Quote($sInclude) & ", True, " & Quote($sTo) & ", aState) Then Return") + CState.Print("If Include(" & CStr($iInclude) & ", " & Quote($sInclude) & ", True, " & Quote(CState.Pattern) & ", aState) Then Return") CState.Print("SetIncludeHighlight(" & CStr($iInclude) & ")") - hState.Forward("String.Len(Match(" & Quote($sTo) & "))") + hState.Forward("String.Len(Match(" & Quote(CState.Pattern) & "))") CState.Print("SetIncludeHighlight(Me._IncludeHighlight)") Else - CState.Print("If Include(" & CStr($iInclude) & ", " & Quote($sInclude) & ", False, " & Quote($sTo) & ", aState) Then Return") + CState.Print("If Include(" & CStr($iInclude) & ", " & Quote($sInclude) & ", False, " & Quote(CState.Pattern) & ", aState) Then Return") CState.Print("SetIncludeHighlight(" & CStr($iInclude) & ")") - hState.Forward(String.Len($sTo)) + hState.Forward(String.Len(CState.Pattern)) CState.Print("SetIncludeHighlight(Me._IncludeHighlight)") Endif @@ -73,28 +73,28 @@ Public Sub Compile(hState As CState) If Not $sFrom Then - Else If CState.IsRegExp(ByRef $sFrom) Then + Else If CState.IsRegExp($sFrom) Then - CState.Print("sWord = Match(" & Quote($sFrom) & ")") + CState.Print("sWord = Match(" & Quote(CState.Pattern) & ")") CState.Print("If Not sWord Then Goto " & hState.GetNextLabel()) hState.Forward("String.Len(sWord)") Else - CState.IfStartWith($sFrom, hState.GetNextLabel()) - hState.Forward(String.Len($sFrom)) + CState.IfStartWith(CState.Pattern, hState.GetNextLabel()) + hState.Forward(String.Len(CState.Pattern)) Endif hState.PrintLabel(hState.GetLabel() & "_LOOP") - If CState.IsRegExp(ByRef $sTo) Then - CState.Print("sWord = Match(" & Quote($sTo) & ")") + If CState.IsRegExp($sTo) Then + CState.Print("sWord = Match(" & Quote(CState.Pattern) & ")") CState.Print("If sWord Then") hState.Forward("String.Len(sWord)") Else - CState.IfStartWith($sTo) - hState.Forward(String.Len($sTo)) + CState.IfStartWith(CState.Pattern) + hState.Forward(String.Len(CState.Pattern)) Endif hState.Continue() diff --git a/comp/src/gb.highlight/.src/CCommandMatch.class b/comp/src/gb.highlight/.src/CCommandMatch.class index 4c61e5a5d..8f496ad59 100644 --- a/comp/src/gb.highlight/.src/CCommandMatch.class +++ b/comp/src/gb.highlight/.src/CCommandMatch.class @@ -16,16 +16,16 @@ End Public Sub Compile(hState As CState) - If CState.IsRegExp(ByRef $sFrom) Then + If CState.IsRegExp($sFrom) Then - CState.Print("sWord = Match(" & Quote($sFrom) & ")") + CState.Print("sWord = Match(" & Quote(CState.Pattern) & ")") CState.Print("If Not sWord Then Goto " & hState.GetNextLabel()) hState.Forward("String.Len(sWord)") Else - CState.IfStartWith($sFrom, hState.GetNextLabel()) - hState.Forward(String.Len($sFrom)) + CState.IfStartWith(CState.Pattern, hState.GetNextLabel()) + hState.Forward(String.Len(CState.Pattern)) Endif diff --git a/comp/src/gb.highlight/.src/CState.class b/comp/src/gb.highlight/.src/CState.class index d51c5d73b..052ebea6f 100644 --- a/comp/src/gb.highlight/.src/CState.class +++ b/comp/src/gb.highlight/.src/CState.class @@ -18,6 +18,8 @@ Static Private $cInclude As New Collection Static Private $cSubst As New Collection +Static Public Pattern As String + Public Name As String Public ColorIndex As Integer Public Indent As Integer @@ -449,14 +451,16 @@ Static Public Sub AddInclude(sInclude As String) As Integer End -Static Public Sub IsRegExp(ByRef sPattern As String) As Boolean +Static Public Sub IsRegExp(sPattern As String) As Boolean If sPattern Begins "/" And If sPattern Ends "/" And If Len(sPattern) > 2 Then - sPattern = Mid$(sPattern, 2, -1) + Pattern = Mid$(sPattern, 2, -1) Return True Else If sPattern Begins "\"" And If sPattern Ends "\"" Then - sPattern = UnQuote(sPattern) + Pattern = UnQuote(sPattern) Return False + Else + Pattern = sPattern Endif End diff --git a/comp/src/gb.highlight/.src/Main.module b/comp/src/gb.highlight/.src/Main.module index 061ad9db5..be2bfc488 100644 --- a/comp/src/gb.highlight/.src/Main.module +++ b/comp/src/gb.highlight/.src/Main.module @@ -22,13 +22,14 @@ 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["webpage"] + With TextHighlighter["javascript"] Print .Colors.Join() - .CanRewrite = True '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")) - File.Save("~/test.html", .ToHTML(File.Load("~/asap/omogen/master/src/kernel/guygle.cgi/.src/Site/CloseMe.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("~/asap/omogen/master/src/kernel/guygle.cgi/.src/Site/CloseMe.webpage"))) End With End diff --git a/comp/src/gb.highlight/highlight/highlight.arg b/comp/src/gb.highlight/highlight/highlight.arg new file mode 100644 index 000000000..7f6803b28 --- /dev/null +++ b/comp/src/gb.highlight/highlight/highlight.arg @@ -0,0 +1,17 @@ +arg.subst{Preprocessor}: + match /\$\($(IDENT)\) +ident{Normal}: + match .*? +string: + from " to " + string.subst{Preprocessor}: + match /\$\($(IDENT)\) + escape: + match /\\[fnrtv0'"\\]/ + match /\\x[0-9a-fA-F]{2}/ +regexp{RegExp=Datatype}: + match //\S// + regexp.subst{Preprocessor}: + match /\$\($(IDENT)\) + regexp.escape{Escape}: + match /\\./ diff --git a/comp/src/gb.highlight/highlight/highlight.highlight b/comp/src/gb.highlight/highlight/highlight.highlight new file mode 100644 index 000000000..dc2cba526 --- /dev/null +++ b/comp/src/gb.highlight/highlight/highlight.highlight @@ -0,0 +1,13 @@ +$(IDENT)=[A-Za-z][A-Za-z0-9.]* +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 diff --git a/comp/src/gb.highlight/highlight/javascript.highlight b/comp/src/gb.highlight/highlight/javascript.highlight index fb4b671ce..1acaa331c 100644 --- a/comp/src/gb.highlight/highlight/javascript.highlight +++ b/comp/src/gb.highlight/highlight/javascript.highlight @@ -23,7 +23,7 @@ string.subst{String}: subst{Escape}: from ${ to } with javascript regexp{RegExp=Datatype}: - match //.*?/[a-z]*/ + match //.*?(/[a-z]*)?/ regexp.escape{Escape}: match /\\./ number: