Je cherche à colorer les commentaires d'un code Javascript.
1 - un commentaire sur une seule ligne est précédé d'un double-slash //.
2 - Un commentaire qui s'étend sur plusieurs lignes est précédé de /* et suivis par */.// texte de commentaire
Pour le moment je me concentre sur la cas numéro 1./* Ceci est un commentaire sur plusieurs lignes.
Il peut être de n'importe quelle longeur. */
■ Voici le code de test
Code : Tout sélectionner
EnableExplicit
Enumeration Highlight
#Style_Comment
#Style_Bracket
#Style_NonKeyword
EndEnumeration
Enumeration Form
#mf
EndEnumeration
Enumeration Gadget
#Editor
EndEnumeration
Declare Start()
Declare MainFormShow()
Declare MainFormResize()
Declare MainFormClose()
Declare ScintillaProperties(Gadget)
Declare ScintillaCallBack(Gadget, *scinotify.SCNotification)
Declare ScintillaHighlight(Gadget.l, EndPos.l)
Declare ScintillaGetLineEndPosition(Gadget, Line)
Declare ScintillaLineFromPosition(gadget, Pos)
Start()
Procedure Start()
OpenWindow(#mf, 0, 0, 1024, 768, "Test", #PB_Window_SystemMenu | #PB_Window_ScreenCentered)
If InitScintilla()
ScintillaGadget(#Editor, 0, 0, WindowWidth(#mf), WindowHeight(#mf), @ScintillaCallBack())
ScintillaProperties(#Editor)
SetActiveGadget(#Editor)
EndIf
BindEvent(#PB_Event_CloseWindow, @MainFormClose())
Repeat : WaitWindowEvent(10) : ForEver
EndProcedure
Procedure MainFormClose()
End
EndProcedure
Procedure ScintillaProperties(Gadget)
ScintillaSendMessage(#Editor, #SCI_SETCODEPAGE, #SC_CP_UTF8)
ScintillaSendMessage(Gadget, #SCI_STYLESETBACK, #STYLE_DEFAULT, RGB(175, 175, 175))
ScintillaSendMessage(Gadget, #SCI_STYLESETFORE, #Style_Comment, RGB(255, 255, 255))
ScintillaSendMessage(Gadget, #SCI_STYLESETFONT,#STYLE_DEFAULT, @"Lucida Console") ;Police à utiliser
ScintillaSendMessage(Gadget, #SCI_STYLESETSIZE, #STYLE_DEFAULT, 11) ;Taille de la police
ScintillaSendMessage(Gadget, #SCI_STYLECLEARALL)
;Line numbering column
ScintillaSendMessage(Gadget, #SCI_SETMARGINTYPEN, 0, #SC_MARGIN_NUMBER)
ScintillaSendMessage(Gadget, #SCI_SETMARGINWIDTHN, 0, 50)
ScintillaSendMessage(Gadget, #SCI_STYLESETBACK, #STYLE_LINENUMBER, RGB(154, 205, 50))
ScintillaSendMessage(Gadget, #SCI_STYLESETFORE, #STYLE_LINENUMBER, RGB(82, 86, 111))
;Comment
ScintillaSendMessage(Gadget, #SCI_STYLESETFORE, #Style_Comment, RGB(0, 128, 0))
;Tag
ScintillaSendMessage(Gadget, #SCI_STYLESETFORE, #Style_Bracket, RGB(255, 0, 0))
;Default
ScintillaSendMessage(Gadget, #SCI_STYLESETFORE, #Style_NonKeyword, RGB(255, 255, 255))
EndProcedure
Procedure ScintillaCallBack(Gadget, *scinotify.SCNotification)
Select *scinotify\nmhdr\code
Case #SCN_CHARADDED
Case #SCN_STYLENEEDED
ScintillaHighlight(Gadget, *scinotify\position)
EndSelect
EndProcedure
Procedure ScintillaHighlight(Gadget.l, EndPos.l)
Protected Char, CurrentPos.i = 0, EndLinePos.i, StartKeyword.i
ScintillaSendMessage(Gadget, #SCI_STARTSTYLING, CurrentPos, $1F | #INDICS_MASK)
While CurrentPos <= EndPos
Char = ScintillaSendMessage(Gadget, #SCI_GETCHARAT, CurrentPos)
Select Char
Case '{', '}'
Debug "Styling { or }"
ScintillaSendMessage(Gadget, #SCI_SETSTYLING, 1, #Style_Bracket)
Case '/' ;Comment
;Is the preceding character a /?
If ScintillaSendMessage(Gadget, #SCI_GETCHARAT, currentpos - 1) = '/'
Debug "Styling comment"
currentpos - 1
EndLinePos = ScintillaGetLineEndPosition(Gadget, ScintillaLineFromPosition(Gadget, currentpos+1))
StartKeyword = 1
While currentpos < EndLinePos
currentpos + 1
StartKeyword + 1
Wend
ScintillaSendMessage(Gadget, #SCI_SETSTYLING, StartKeyword, #Style_Comment)
Else
ScintillaSendMessage(Gadget, #SCI_SETSTYLING, 0, #Style_NonKeyword)
EndIf
Default
ScintillaSendMessage(Gadget, #SCI_SETSTYLING, 1, #Style_NonKeyword)
EndSelect
currentpos+1
Wend
EndProcedure
Procedure ScintillaGetLineEndPosition(Gadget, Line)
ProcedureReturn ScintillaSendMessage(Gadget, #SCI_GETLINEENDPOSITION, Line)
EndProcedure
Procedure ScintillaLineFromPosition(gadget, Pos)
ProcedureReturn ScintillaSendMessage(Gadget, #SCI_LINEFROMPOSITION, Pos)
EndProcedure
Code : Tout sélectionner
// Get the canvas element (#renderCanvas)
var canvas = document.getElementById("renderCanvas");
// Generate the BABYLON 3D engine
var engine = new BABYLON.Engine(canvas, true);
// Add the create scene function
var createScene = function () {
// Create the scene space
var scene = new BABYLON.Scene(engine);
// Add a camera to the scene and attach it to the canvas
var camera = new BABYLON.ArcRotateCamera("Camera", Math.PI / 2, Math.PI / 2, 10, BABYLON.Vector3.Zero(), scene);
camera.attachControl(canvas, true);
// Add lights to the scene
var light1 = new BABYLON.HemisphericLight("light1", new BABYLON.Vector3(1, 1, 0), scene);
var light2 = new BABYLON.PointLight("light2", new BABYLON.Vector3(0, 1, -1), scene);
// Add and manipulate meshes in the scene
var sphere = BABYLON.MeshBuilder.CreateSphere("sphere", { diameter:1 }, scene);
return scene;
};
// End of the create scene function : Call the createScene function
var scene = createScene();
// Register a render loop to repeatedly render the scene
engine.runRenderLoop(function () {
scene.render();
});
// Watch for browser/canvas resize events
window.addEventListener("resize", function () {
engine.resize();
});
-Les brackets {} ne sont pas colorés correctement.
Si on supprime la ligne 14, la coloration syntaxique est correcte.
J'espére que vous allez pouvoir m'aider. Merci.
■ La solution est donnée par Zorro : Lors du processus de coloration syntaxique, quand le process repère le caractère "/" il faut vérifier que le caractère suivant est lui aussi un "/".
Code : Tout sélectionner
Case '/' ; By Dobro
If ScintillaSendMessage(Gadget, #SCI_GETCHARAT, CurrentPos+1) ='/'
Code : Tout sélectionner
Case '/' ;Comment
;Is the preceding character a /?
If ScintillaSendMessage(Gadget, #SCI_GETCHARAT, currentpos - 1) = '/'