Welcome! Log In Create A New Profile

Advanced

PING Ken W-Language Syntax highlightning

Posted by BLS 
BLS
PING Ken W-Language Syntax highlightning
February 16, 2009 06:02PM
Hi Ken, Thanks smiling smiley

-- It is not my intention to make too much noise, but W-language coloring is a bit different from SQL language coloring---

I have done some work on W language Syntax highlitghning ->(will I ever learn how to write this word ?)
As you can see, I have already made some efforts to support code folding. Unfortunately this is not as trivial as writing the scintilla wrapper... but first a shot, some comments and information below the pic.



The code to enable W language code folding, as well as W language code coloring is a bit different than the standard way say : for SQL, C Pascal whatheheck language, ' cause W-Language is not official supported by scintilla.
However you can establish this features by declaring the language as a generic one . I haven' t touched the code to support W-Language for quit a while and today it would like to say ... we need a cleanup..(to say the least) ***

However, If you are interested to use this code, just send a mail. nanali (at) wanadoo (dot) fr.

Bjoern

*** A snippet, to show you what I mean :
PROCEDURE WindevStyle(_hwnd, _start, _end)

	lengthDoc is int = SendMessage(_hwnd, SCI_GETLENGTH, 0, 0)
	IF _end = -1 THEN _end = lengthDoc

	// backup to start of previous line
	line is int = SendMessage(_hwnd, SCI_LINEFROMPOSITION, _start, 0)
	IF _start > 0 AND line > 0
		line--
		_start = SendMessage(_hwnd, SCI_POSITIONFROMLINE, line, 0)
	END
	
	// backup to start of line
	line = SendMessage(_hwnd, SCI_LINEFROMPOSITION, _start, 0)
	_start = SendMessage(_hwnd, SCI_POSITIONFROMLINE, line, 0)

	// backup to outside string or comment
	style is int
	WHILE _start > 0

		style = SendMessage(_hwnd, SCI_GETSTYLEAT, _start, 0)
		
		IF style <> STYLE_COMMENT AND style <> STYLE_STRING THEN 
			BREAK
		END
		line--
		_start = SendMessage(_hwnd, SCI_POSITIONFROMLINE, line, 0)
	END

	size is int = _end - _start;

	level is int = BinaryAND(SendMessage(_hwnd, SCI_GETFOLDLEVEL, line, 0), SC_FOLDLEVELNUMBERMASK)
	prev_level is int = level
    
	buffer is string = Complète(buffer, (lengthDoc - _start + 1), Charact(0)) // +1 because allow for null
	tr is TextRange
	tr:lpstrText = &buffer
	tr:chrg:cpMin = _start
	tr:chrg:cpMax = lengthDoc
	SendMessage(_hwnd, SCI_GETTEXTRANGE, 0, &tr)
	
	// Heureka we have a buffer vartype !
	styles is Buffer = Complète(styles, size, 0) 
	
	SendMessage(_hwnd, SCI_STARTSTYLING, _start, 0x1F)
	currText is string = StringRetrieve(tr:lpstrText, srASCIIZAddress)
	scanIndex is int = 0
	currBuffer is string = ""
    currChar is string fixed on 1 = ""

	WHILE True
		
		scanIndex++
		
		IF scanIndex > size +1 THEN 
			BREAK
		END
		
		currChar = currText[[scanIndex]]
		
		IF currChar  = Charact(13)_OR_ currChar = EOT THEN
			currBuffer = "" 
			CONTINUE  		
		END
		IF currChar = " " THEN
			 currBuffer = ""
			 CONTINUE
		END
		
	NEWLINE:	
		IF currChar = Charact(10) THEN
			i is int = line
			line = SendMessage(_hwnd, SCI_LINEFROMPOSITION, _start + scanIndex, 0)
			flags is int = level > prev_level ? SC_FOLDLEVELHEADERFLAG ELSE 0
			
			WHILE i < line
				SendMessage(_hwnd, SCI_SETFOLDLEVEL, i, BinaryOR(prev_level, flags))
				flags = 0 // header only on first
				prev_level = level
				i++
			
			END	
			currBuffer = ""
			CONTINUE
		END
			
		// Comment   : current and next char are /  
		IF currChar = "/" AND currText[[scanIndex +1]] = "/" THEN
			currBuffer = "/"

			LOOP
				
				scanIndex++
			
				currChar = currText[[scanIndex]]
				
				IF currChar = EOT OR scanIndex > size +1 THEN BREAK
				
				IF currChar <> Charact(13) _AND_ currChar <> Charact(10) THEN
					currBuffer += currChar  
				END
				
				IF currChar = Charact(10) THEN
					scanIndex--
					FOR i = (scanIndex - Length(currBuffer) ) TO scanIndex  
						styles[[i]] = 1
					END
					//trace(currbuffer)
					currBuffer = ""					
					scanIndex++
					
					GOTO NEWLINE
				END
				
			END  // Loop
		END // Comment
		
		// String		TO DO
		IF currChar = Charact(34) THEN		 
			currBuffer = Charact(34)	
		
			LOOP
			
				scanIndex++
			
				currChar = currText[[scanIndex]]
			
				IF currChar = EOT OR scanIndex > size +1 THEN BREAK
			
				IF currChar <> Charact(13) _AND_ currChar <> Charact(10) THEN
					currBuffer += currChar  
				END
			
				// End of String
				IF currChar = Charact(34) THEN
					FOR i = (scanIndex - Length(currBuffer)+1 ) TO scanIndex  
						styles[[i]] = 3
					END	
					BREAK					
				END
			
			END // Loop
			//currBuffer = ""		
		END // String
	
		currBuffer += currChar
	
		IF currBuffer  IN ("IF", "WHILE", "FOR", "SWITCH") THEN 
			level++	
			FOR i = (scanIndex - Length(currBuffer) ) TO scanIndex  
				styles[[i]] = 4
			END
			currBuffer = ""					
		END
		
		IF currBuffer = "END" THEN 
			level--
			FOR i = (scanIndex - Length(currBuffer) ) TO scanIndex 
				styles[[i]] = 4
			END
			currBuffer = ""					
		END
		
		IF  currBuffer IN ("THEN", "ELSE", "OTHER", "CASE", "BREAK", "CONTINUE", "EACH", "TO")  THEN 
			FOR i = (scanIndex - Length(currBuffer) ) TO scanIndex 
				styles[[i]] = 4
			END
			currBuffer = ""					
		END	
		
		IF currBuffer IN ("True", "False", "Null") THEN //, "MySelf", "MyParent", "MyPopupControl") then )
			FOR i = (scanIndex - Length(currBuffer) ) TO scanIndex 
				styles[[i]] = 5
			END
			currBuffer = ""							
		END
	END

	//Trace(styles)
	i  = line
	line = SendMessage(_hwnd, SCI_LINEFROMPOSITION, _start + scanIndex, 0)
	WHILE i <= line
		SendMessage(_hwnd, SCI_SETFOLDLEVEL, i, prev_level)
		prev_level = level
		i++
	END
  
	SendMessage(_hwnd, SCI_SETSTYLINGEX, size, &styles)







Author:

Your Email:


Subject:


Spam prevention:
Please, enter the code that you see below in the input field. This is for blocking bots that try to post this form automatically. If the code is hard to read, then just try to guess it right. If you enter the wrong code, a new image is created and you get another chance to enter it right.
Message: