Jump to content

This site uses cookies. By continuing to browse the site you are agreeing to our use of cookies. Find out more here. X
X


Photo

AU3 Syntax Highlight for RichEdit - Machine Code Version - Updated 12/25/2013

syntax highlight

  • Please log in to reply
61 replies to this topic

#1 Beege

Beege

    Universalist

  • MVPs
  • 895 posts

Posted 23 May 2011 - 07:50 PM

Last Update - 12/25/2013
 
Here are a few functions that will take any Autoit code and convert it to RTF format with AutoIt syntax highlighted.
The code can be saved or applied right to the RichEdit control you are working with.

Special thanks go to MrCreator. A good amount of ideas for different parts of the code and regular expressions came from studying his Autoit Syntax Highlight for HTML\BBCode. Viewing how he handled certain situations was very helpful. Thanks to Robjong also for feedback on some of the SRE expressions.

 

Update - 12/25/2013

Fixed incorrect coloring for INI functions

Update - 10/29/2013
Heres my latest version. Its been completly rewritten in assembly and is working very fast. The previous version for this library worked by checking for each catagory (variable, keyword, string, etc) one catagory at a time using reg expressions. The libaray works by walking the data one time adds the coloring each time it hits a catagory. Each time we hit a catogory, we jump to that catagoys procedure and continue processing until that catagory is over, then return to the main loop, or another catagorey. This make processing parts like comments and strings very fast. 
 
For strings Im passing the data to an autoit function for the send keys. For the UDFs im also passing the data to an auto it function, but only to check if its a function, not modify any data. Using a dictionary, I setup a structure where the key is the function name and the item for that key is the length. Checking to see if a key exists in a dictionary is very fast, so is the lookup so if it is a key, I pass back the length of the funtion, along with the function type (Native, UDF, Keyword). Code for Native functions and Keywords are built into the assembly code, the reason they are also in the udfs is for case insensitve checks. The assembly code then adds the coloring and copys the bytes specifed by the length.
 
There full assembly code is in the build folder. That includes everything you need compile the full function if you wanted to change it somehow. Theres also a short little brief on assembly code in general and working with strings in assembly. 
 
Update - 10/20/2013

Spoiler

 
Please let me know if you have any problems. Thanks
 

Snap%203.PNG


Change Log:

Spoiler

Attached File  RESH.zip   17.51KB   299 downloads
Attached File  RESHv2.zip   21.1KB   171 downloads
Attached File  RESHv2.1.zip   22.39KB   202 downloads
Attached File  RESHv2.2.zip   24.44KB   505 downloads
Attached File  RESHv2.3.zip   25.23KB   91 downloads
 
asm version:
Attached File  RESHv3.zip   225.96KB   125 downloads
Attached File  RESHv3.1.zip   155.52KB   84 downloads


Edited by Beege, 25 December 2013 - 10:49 AM.








#2 Beege

Beege

    Universalist

  • MVPs
  • 895 posts

Posted 18 February 2012 - 10:50 AM

Updated this... because its so popular. :)

#3 guinness

guinness

    I've a handle on the fiction

  • Developers
  • 15,707 posts

Posted 18 February 2012 - 12:14 PM

Very nice indeed. Have you thought about adopting the latest style? (If you don't ask you don't get!)

Example List: _AdapterConnections()_AlwaysRun()_AppMon()_AppMonEx()_BinaryBin()_CheckMsgBox()_CmdLineRaw()_ContextMenu()_ConvertLHWebColor()/_ConvertSHWebColor()_DesktopDimensions()_DisplayPassword()_Fibonacci()_FileCompare()_FileCompareContents()_FileNameByHandle()_FilePrefix/SRE()_FindInFile()_GetBackgroundColor()/_SetBackgroundColor()_GetConrolID()_GetCtrlClass()_GetDirectoryFormat()_GetDriveMediaType()_GetFilename()/_GetFilenameExt()_GetHardwareID()_GetIP()_GetIP_Country()_GetOSLanguage()_GetSavedSource_GetStringSize()_GetSystemPaths()_GetURLImage()_GIFImage()_GoogleWeather()_GUICtrlCreateGroup()_GUICtrlListBox_CreateArray()_GUICtrlListView_CreateArray()_GUICtrlListView_SaveCSV()_GUICtrlListView_SaveHTML()_GUICtrlListView_SaveTxt()_GUICtrlListView_SaveXML()_GUICtrlMenu_Recent()_GUICtrlMenu_SetItemImage()_GUICtrlTreeView_CreateArray()_GUIDisable()_GUIImageList_SetIconFromHandle()_GUISetIcon()_Icon_Clear()/_Icon_Set()_InetGet()_InetGetGUI()_InetGetProgress()_IPDetails()_IsFileOlder()_IsGUID()_IsHex()_IsPalindrome()_IsRegKey()_IsStringRegExp()_IsUPX()_IsValidType()_IsWebColor()_Language()_Log()_MicrosoftInternetConnectivity()_MSDNDataType()_PathFull/GetRelative/Split()_PathSplitEx()_PrintFromArray()_ProgressSetMarquee()_ReDim()_RockPaperScissors()/_RockPaperScissorsLizardSpock()_ScrollingCredits_SelfDelete()_SelfRename()_SelfUpdate()_SendTo()_ShellAll()_ShellFile()_ShellFolder()_SingletonHWID()_SingletonPID()_Startup()_StringCompact()_StringIsValid()_StringRegExpMetaCharacters()_StringReplaceWholeWord()_StringStripChars()_Temperature()_TrialPeriod()_UKToUSDate()/_USToUKDate()_WinAPI_CreateGUID()_WMIDateStringToDate()/_DateToWMIDateString()Au3 script parsingAutoIt SearchAutoIt3 PortableAutoIt3WrapperToPragmaAutoItWinGetTitle()/AutoItWinSetTitle()CodingFileInstallrGeoIP databaseGUI - Only Close ButtonGUI ExamplesGUICtrlDeleteImage()GUICtrlGetBkColor()GUICtrlGetStyle()GUIGetBkColor()LockFile()PasswordValidPasteBinPosts Per DayPreExpandQueue()SciTE JumpSHELLHOOKShunting-YardSignature CreatorStack()StringAddLF()/StringStripLF()StringEOLToCRLF()WM_COPYDATAMore Examples...
Updated: 12/04/2014


#4 Beege

Beege

    Universalist

  • MVPs
  • 895 posts

Posted 18 February 2012 - 12:34 PM

Thanks Guinness.:) Yes I have thought about it. I've been wonder weather I should have preset styles that the user could switch, or create a function that allows them to set the colors to whatever they want. I think just passing an array of hex color values would be easy enough but wasnt sure which route I should go. What do you think?

#5 CaptainClucks

CaptainClucks

    Unum Cavillator Spuria

  • Active Members
  • PipPipPipPipPipPip
  • 1,222 posts

Posted 18 February 2012 - 12:42 PM

The regular expression use in this is nutz, awesome work!
Spoiler
Warning: Posts by this user are subject to change or may disappear without notice.

#6 guinness

guinness

    I've a handle on the fiction

  • Developers
  • 15,707 posts

Posted 18 February 2012 - 12:57 PM

What do you think?

An array should be fine. You've also got me hooked on using associative arrays.

Example List: _AdapterConnections()_AlwaysRun()_AppMon()_AppMonEx()_BinaryBin()_CheckMsgBox()_CmdLineRaw()_ContextMenu()_ConvertLHWebColor()/_ConvertSHWebColor()_DesktopDimensions()_DisplayPassword()_Fibonacci()_FileCompare()_FileCompareContents()_FileNameByHandle()_FilePrefix/SRE()_FindInFile()_GetBackgroundColor()/_SetBackgroundColor()_GetConrolID()_GetCtrlClass()_GetDirectoryFormat()_GetDriveMediaType()_GetFilename()/_GetFilenameExt()_GetHardwareID()_GetIP()_GetIP_Country()_GetOSLanguage()_GetSavedSource_GetStringSize()_GetSystemPaths()_GetURLImage()_GIFImage()_GoogleWeather()_GUICtrlCreateGroup()_GUICtrlListBox_CreateArray()_GUICtrlListView_CreateArray()_GUICtrlListView_SaveCSV()_GUICtrlListView_SaveHTML()_GUICtrlListView_SaveTxt()_GUICtrlListView_SaveXML()_GUICtrlMenu_Recent()_GUICtrlMenu_SetItemImage()_GUICtrlTreeView_CreateArray()_GUIDisable()_GUIImageList_SetIconFromHandle()_GUISetIcon()_Icon_Clear()/_Icon_Set()_InetGet()_InetGetGUI()_InetGetProgress()_IPDetails()_IsFileOlder()_IsGUID()_IsHex()_IsPalindrome()_IsRegKey()_IsStringRegExp()_IsUPX()_IsValidType()_IsWebColor()_Language()_Log()_MicrosoftInternetConnectivity()_MSDNDataType()_PathFull/GetRelative/Split()_PathSplitEx()_PrintFromArray()_ProgressSetMarquee()_ReDim()_RockPaperScissors()/_RockPaperScissorsLizardSpock()_ScrollingCredits_SelfDelete()_SelfRename()_SelfUpdate()_SendTo()_ShellAll()_ShellFile()_ShellFolder()_SingletonHWID()_SingletonPID()_Startup()_StringCompact()_StringIsValid()_StringRegExpMetaCharacters()_StringReplaceWholeWord()_StringStripChars()_Temperature()_TrialPeriod()_UKToUSDate()/_USToUKDate()_WinAPI_CreateGUID()_WMIDateStringToDate()/_DateToWMIDateString()Au3 script parsingAutoIt SearchAutoIt3 PortableAutoIt3WrapperToPragmaAutoItWinGetTitle()/AutoItWinSetTitle()CodingFileInstallrGeoIP databaseGUI - Only Close ButtonGUI ExamplesGUICtrlDeleteImage()GUICtrlGetBkColor()GUICtrlGetStyle()GUIGetBkColor()LockFile()PasswordValidPasteBinPosts Per DayPreExpandQueue()SciTE JumpSHELLHOOKShunting-YardSignature CreatorStack()StringAddLF()/StringStripLF()StringEOLToCRLF()WM_COPYDATAMore Examples...
Updated: 12/04/2014


#7 Beege

Beege

    Universalist

  • MVPs
  • 895 posts

Posted 18 February 2012 - 01:00 PM

The regular expression use in this is nutz, awesome work!

Thanks

An array should be fine.

Array it is then.

You've also got me hooked on using associative arrays.

Their addicting! It seemed the more I started using them the more situations started poping up that fit them perfectly! Plus their pretty fast! :)

Edited by Beege, 18 February 2012 - 01:07 PM.


#8 Beege

Beege

    Universalist

  • MVPs
  • 895 posts

Posted 19 February 2012 - 05:37 PM

Updated with new function to change color table to whatever you want.

#9 guinness

guinness

    I've a handle on the fiction

  • Developers
  • 15,707 posts

Posted 19 February 2012 - 05:52 PM

Updated with new function to change color table to whatever you want.

Sweet! :)

Example List: _AdapterConnections()_AlwaysRun()_AppMon()_AppMonEx()_BinaryBin()_CheckMsgBox()_CmdLineRaw()_ContextMenu()_ConvertLHWebColor()/_ConvertSHWebColor()_DesktopDimensions()_DisplayPassword()_Fibonacci()_FileCompare()_FileCompareContents()_FileNameByHandle()_FilePrefix/SRE()_FindInFile()_GetBackgroundColor()/_SetBackgroundColor()_GetConrolID()_GetCtrlClass()_GetDirectoryFormat()_GetDriveMediaType()_GetFilename()/_GetFilenameExt()_GetHardwareID()_GetIP()_GetIP_Country()_GetOSLanguage()_GetSavedSource_GetStringSize()_GetSystemPaths()_GetURLImage()_GIFImage()_GoogleWeather()_GUICtrlCreateGroup()_GUICtrlListBox_CreateArray()_GUICtrlListView_CreateArray()_GUICtrlListView_SaveCSV()_GUICtrlListView_SaveHTML()_GUICtrlListView_SaveTxt()_GUICtrlListView_SaveXML()_GUICtrlMenu_Recent()_GUICtrlMenu_SetItemImage()_GUICtrlTreeView_CreateArray()_GUIDisable()_GUIImageList_SetIconFromHandle()_GUISetIcon()_Icon_Clear()/_Icon_Set()_InetGet()_InetGetGUI()_InetGetProgress()_IPDetails()_IsFileOlder()_IsGUID()_IsHex()_IsPalindrome()_IsRegKey()_IsStringRegExp()_IsUPX()_IsValidType()_IsWebColor()_Language()_Log()_MicrosoftInternetConnectivity()_MSDNDataType()_PathFull/GetRelative/Split()_PathSplitEx()_PrintFromArray()_ProgressSetMarquee()_ReDim()_RockPaperScissors()/_RockPaperScissorsLizardSpock()_ScrollingCredits_SelfDelete()_SelfRename()_SelfUpdate()_SendTo()_ShellAll()_ShellFile()_ShellFolder()_SingletonHWID()_SingletonPID()_Startup()_StringCompact()_StringIsValid()_StringRegExpMetaCharacters()_StringReplaceWholeWord()_StringStripChars()_Temperature()_TrialPeriod()_UKToUSDate()/_USToUKDate()_WinAPI_CreateGUID()_WMIDateStringToDate()/_DateToWMIDateString()Au3 script parsingAutoIt SearchAutoIt3 PortableAutoIt3WrapperToPragmaAutoItWinGetTitle()/AutoItWinSetTitle()CodingFileInstallrGeoIP databaseGUI - Only Close ButtonGUI ExamplesGUICtrlDeleteImage()GUICtrlGetBkColor()GUICtrlGetStyle()GUIGetBkColor()LockFile()PasswordValidPasteBinPosts Per DayPreExpandQueue()SciTE JumpSHELLHOOKShunting-YardSignature CreatorStack()StringAddLF()/StringStripLF()StringEOLToCRLF()WM_COPYDATAMore Examples...
Updated: 12/04/2014


#10 Beege

Beege

    Universalist

  • MVPs
  • 895 posts

Posted 19 February 2012 - 06:41 PM

Thanks!

Before I start writing something, do you have or know of any snippet that will extract the color values from the Scite User Options file?

#11 AZJIO

AZJIO

    Universalist

  • Active Members
  • PipPipPipPipPipPip
  • 1,546 posts

Posted 19 February 2012 - 07:09 PM

Beege

Before I start writing something, do you have or know of any snippet that will extract the color values from the Scite User Options file?

"Case $Import" in CreationTheme

([()[]<>.*+-=&^,/]) = ([][()<>.*+=&^,/-])

#12 Beege

Beege

    Universalist

  • MVPs
  • 895 posts

Posted 19 February 2012 - 07:59 PM

Thanks AZJIO, I came up with the following:

#include <array.au3> Global $aCurrentColors = _GetCurrentSciteColors() _ArrayDisplay($aCurrentColors) Func _GetCurrentSciteColors($sSciteUserPropPath = '')      If Not $sSciteUserPropPath Then $sSciteUserPropPath = @UserProfileDir & 'SciteUser.properties'      If Not FileExists($sSciteUserPropPath) Then Return SetError(1, 0, 0)      Local $sSciteUserProps = FileRead($sSciteUserPropPath)      If @error Then Return SetError(2,0,0)      Local $aUserColors = StringRegExp($sSciteUserProps, '(?mi)^style.au3.(?:d|10|11|12|13|14|15)=fore:(#[0-9a-f]{6}).*$', 3)      If @error Then Return SetError(3, @error, 0)      Return $aUserColors EndFunc   ;==>_GetCurrentSciteColors


([()[]<>.*+-=&^,/]) = ([][()<>.*+=&^,/-])

Thats partly true but I think some of those characters would need need to be escaped. I would surely think '^' would because thats an operorator for sets.

Edit: Changed expression to more secure version. Thanks AZJIO

Edited by Beege, 19 February 2012 - 08:48 PM.


#13 AZJIO

AZJIO

    Universalist

  • Active Members
  • PipPipPipPipPipPip
  • 1,546 posts

Posted 19 February 2012 - 08:16 PM

screenshot

(?mi)^style.au3.(?:)|10|11|12|13|14|15)=fore:#([0-9a-f]{6}).*$

# au3 style.au3.0=fore:#72ADC0   # White space style.au3.1=fore:#71AE71,italics   # Comment line style.au3.2=fore:#71AE71,italics   # Comment block style.au3.3=fore:#C738B9   # Number style.au3.4=fore:#AAA6DB   # Function style.au3.5=fore:#0080FF   # Keyword style.au3.6=fore:#FF46FF   # Macro style.au3.7=fore:#999999   # String style.au3.8=fore:#FF8080   # Operator style.au3.9=fore:#D29A6C   # Variable style.au3.10=fore:#EA9515,bold   # Sent keys style.au3.11=fore:#F000FF   # Pre-Processor style.au3.12=fore:#0080C0   # Special style.au3.13=fore:#7D8AE6,bold   # Abbrev-Expand style.au3.14=fore:#0080FF,bold   # Com Objects style.au3.15=fore:#72ADC0   # Standard UDF's

Edited by AZJIO, 19 February 2012 - 08:25 PM.


#14 guinness

guinness

    I've a handle on the fiction

  • Developers
  • 15,707 posts

Posted 19 February 2012 - 08:21 PM

Beege,

I tried your version of _GetCurrentSciteColors which returned only 2 results. Then I substituted your SRE for AZJIO's and it returned 15, which looking at au3.properties is correct. Nice function by the way, I'll be saving that to my functions folder.

Example List: _AdapterConnections()_AlwaysRun()_AppMon()_AppMonEx()_BinaryBin()_CheckMsgBox()_CmdLineRaw()_ContextMenu()_ConvertLHWebColor()/_ConvertSHWebColor()_DesktopDimensions()_DisplayPassword()_Fibonacci()_FileCompare()_FileCompareContents()_FileNameByHandle()_FilePrefix/SRE()_FindInFile()_GetBackgroundColor()/_SetBackgroundColor()_GetConrolID()_GetCtrlClass()_GetDirectoryFormat()_GetDriveMediaType()_GetFilename()/_GetFilenameExt()_GetHardwareID()_GetIP()_GetIP_Country()_GetOSLanguage()_GetSavedSource_GetStringSize()_GetSystemPaths()_GetURLImage()_GIFImage()_GoogleWeather()_GUICtrlCreateGroup()_GUICtrlListBox_CreateArray()_GUICtrlListView_CreateArray()_GUICtrlListView_SaveCSV()_GUICtrlListView_SaveHTML()_GUICtrlListView_SaveTxt()_GUICtrlListView_SaveXML()_GUICtrlMenu_Recent()_GUICtrlMenu_SetItemImage()_GUICtrlTreeView_CreateArray()_GUIDisable()_GUIImageList_SetIconFromHandle()_GUISetIcon()_Icon_Clear()/_Icon_Set()_InetGet()_InetGetGUI()_InetGetProgress()_IPDetails()_IsFileOlder()_IsGUID()_IsHex()_IsPalindrome()_IsRegKey()_IsStringRegExp()_IsUPX()_IsValidType()_IsWebColor()_Language()_Log()_MicrosoftInternetConnectivity()_MSDNDataType()_PathFull/GetRelative/Split()_PathSplitEx()_PrintFromArray()_ProgressSetMarquee()_ReDim()_RockPaperScissors()/_RockPaperScissorsLizardSpock()_ScrollingCredits_SelfDelete()_SelfRename()_SelfUpdate()_SendTo()_ShellAll()_ShellFile()_ShellFolder()_SingletonHWID()_SingletonPID()_Startup()_StringCompact()_StringIsValid()_StringRegExpMetaCharacters()_StringReplaceWholeWord()_StringStripChars()_Temperature()_TrialPeriod()_UKToUSDate()/_USToUKDate()_WinAPI_CreateGUID()_WMIDateStringToDate()/_DateToWMIDateString()Au3 script parsingAutoIt SearchAutoIt3 PortableAutoIt3WrapperToPragmaAutoItWinGetTitle()/AutoItWinSetTitle()CodingFileInstallrGeoIP databaseGUI - Only Close ButtonGUI ExamplesGUICtrlDeleteImage()GUICtrlGetBkColor()GUICtrlGetStyle()GUIGetBkColor()LockFile()PasswordValidPasteBinPosts Per DayPreExpandQueue()SciTE JumpSHELLHOOKShunting-YardSignature CreatorStack()StringAddLF()/StringStripLF()StringEOLToCRLF()WM_COPYDATAMore Examples...
Updated: 12/04/2014


#15 Beege

Beege

    Universalist

  • MVPs
  • 895 posts

Posted 19 February 2012 - 08:35 PM

Yup that works too. Only I would need the # included for the new function.

(?mi)^style.au3.(?:)|10|11|12|13|14|15)=fore:(#[0-9a-f]{6}).*$

#16 Beege

Beege

    Universalist

  • MVPs
  • 895 posts

Posted 19 February 2012 - 08:39 PM

Beege,

I tried your version of _GetCurrentSciteColors which returned only 2 results. Then I substituted your SRE for AZJIO's and it returned 15, which looking at au3.properties is correct. Nice function by the way, I'll be saving that to my functions folder.

Ya my version is a little two specific. AZJIO's version will be more secure for property files that might have been modified or slightly different in some way. Ill update my previous post.

#17 Beege

Beege

    Universalist

  • MVPs
  • 895 posts

Posted 19 February 2012 - 08:56 PM

screenshot

Is that PCRE engine? I'm confused why the doc states:

 Note that special characters do not retain their special meanings inside a set, with the exception of , ^, -,[ and ] match the escaped character inside a set.


#18 CaptainClucks

CaptainClucks

    Unum Cavillator Spuria

  • Active Members
  • PipPipPipPipPipPip
  • 1,222 posts

Posted 19 February 2012 - 09:54 PM

I was using the new version and suddenly BAM, right when it was about to load the large UDF into the edit control it gave me this.

Spoiler


I'm on a x86 acer aspire one d250 with win xp if its of any importance.

Edited by THAT1ANONYMOUSEDUDE, 19 February 2012 - 09:56 PM.

Spoiler
Warning: Posts by this user are subject to change or may disappear without notice.

#19 Beege

Beege

    Universalist

  • MVPs
  • 895 posts

Posted 19 February 2012 - 10:06 PM

The pic you posted is not visible. The code you were trying to highlight is the only thing that might help me figure out what happened..

#20 CaptainClucks

CaptainClucks

    Unum Cavillator Spuria

  • Active Members
  • PipPipPipPipPipPip
  • 1,222 posts

Posted 19 February 2012 - 10:12 PM

Hmm, really? the image isn't visible? damn, I need to find a better site then.

Anyway, the image doesn't matter, what matters is that AutoIt is crashing on my PC when loading anything above about 2k or 3k lines of script, and aside from that, on your 3rd version, It would be nice if we could just copy and past the result as in your second version.

Also, AutoIt is crashing no matter what version I use, but I haven't tried the first file you posted, just v2 and v2.1.

Must be something that has to do with running on a crappy laptop.

Edited by THAT1ANONYMOUSEDUDE, 19 February 2012 - 10:13 PM.

Spoiler
Warning: Posts by this user are subject to change or may disappear without notice.





Also tagged with one or more of these keywords: syntax, highlight

0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users