Jump to content

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


Beege
 Share

Recommended Posts

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 HTMLBBCode. 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


Alot of the performance changes I made can really only be seen if you are using one of the new beta versions of autoit. This is mainly due to the regexp engine updates. If your still on 3.3.8.1 you wont see much speed changes, but with 3.3.9.18 and up, you should see a lot.
Check out these time comparisons for parsing WinApi.au3:
 

-3.3.9.21 (Beta)
ReplaceRichEditTags     = 22.4785932416519
Mark Strings        = 726.858602765271
Vars            = 7.65824463155854
Operators       = 132.610412680671
Numbers         = 96.6795644227232
Macros          = 11.6307915154246
ComObjects      = 27.3305066622565
Special         = 3.60985095820728
Functions       = 2621.53934766058
Keywords        = 407.872668637923
UDFs            = 100.098942992298
PreProcessor        = 37.0309118437898
Strings         = 1002.14652117009
Comments        = 625.995489111994
CleanUp         = 46.58760731893
RestoreCommentBlocks    = 0.598790443304525
Total Time      = 6017.28508413006

-3.3.8.1
ReplaceRichEditTags     = 59.0612676678823
Mark Strings        = 1487.37892314667
Vars            = 21.9932878442689
Operators       = 292.73325026304
Numbers         = 191.066046585896
Macros          = 27.8009848677101
ComObjects      = 54.8651723518493
Special         = 6.52339417234329
Functions       = 4179.81049708161
Keywords        = 644.222099929571
UDFs            = 192.171242661253
PreProcessor        = 64.9037515646964
Strings         = 2307.7007302392
Comments        = 6276.41364443823
CleanUp         = 91.1678409612583
RestoreCommentBlocks    = 0.897045111731445
Total Time      = 16117.5066365941


 
Please let me know if you have any problems. Thanks

Snap 3.PNG

Change Log:

 

Spoiler


 
Update: 10/20/13

  • Updated to support new betas. RegEx has changed a bit and needed some modifications
  • Quite a few changes to how the quotes strings get parsed. 
  • added ternary operators
  • New Beta RegEx engine is alot faster! Really should get on if you haven't yet. 

Update: 3/18/12

  • Got more help from Robjong with some of the regular expressions. Thanks again!
  • Fixed crash when loading large file.

Update: 2/19/12

  • Added new function _RESH_SetColorTable() that allows the user to change the color table to there own preference.

Update: 2/18/12

  • Rewrote for speed. Also broke out colors and fonts from RTF header making them much easier to modify.


RESH.zip
RESHv2.zip
RESHv2.1.zip
RESHv2.2.zip
RESHv2.3.zip
 
asm version:
RESHv3.zip
RESHv3.1.zip

Edited by Beege
Link to comment
Share on other sites

  • 8 months later...
Link to comment
Share on other sites

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

UDF List:

 
_AdapterConnections()_AlwaysRun()_AppMon()_AppMonEx()_ArrayFilter/_ArrayReduce_BinaryBin()_CheckMsgBox()_CmdLineRaw()_ContextMenu()_ConvertLHWebColor()/_ConvertSHWebColor()_DesktopDimensions()_DisplayPassword()_DotNet_Load()/_DotNet_Unload()_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()_GUIRegisterMsg()_GUISetIcon()_Icon_Clear()/_Icon_Set()_IdleTime()_InetGet()_InetGetGUI()_InetGetProgress()_IPDetails()_IsFileOlder()_IsGUID()_IsHex()_IsPalindrome()_IsRegKey()_IsStringRegExp()_IsSystemDrive()_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_Create_CTL_CODE()_WinAPI_CreateGUID()_WMIDateStringToDate()/_DateToWMIDateString()Au3 script parsingAutoIt SearchAutoIt3 PortableAutoIt3WrapperToPragmaAutoItWinGetTitle()/AutoItWinSetTitle()CodingDirToHTML5FileInstallrFileReadLastChars()GeoIP databaseGUI - Only Close ButtonGUI ExamplesGUICtrlDeleteImage()GUICtrlGetBkColor()GUICtrlGetStyle()GUIEventsGUIGetBkColor()Int_Parse() & Int_TryParse()IsISBN()LockFile()Mapping CtrlIDsOOP in AutoItParseHeadersToSciTE()PasswordValidPasteBinPosts Per DayPreExpandProtect GlobalsQueue()Resource UpdateResourcesExSciTE JumpSettings INISHELLHOOKShunting-YardSignature CreatorStack()Stopwatch()StringAddLF()/StringStripLF()StringEOLToCRLF()VSCROLLWM_COPYDATAMore Examples...

Updated: 22/04/2018

Link to comment
Share on other sites

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?

Link to comment
Share on other sites

What do you think?

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

UDF List:

 
_AdapterConnections()_AlwaysRun()_AppMon()_AppMonEx()_ArrayFilter/_ArrayReduce_BinaryBin()_CheckMsgBox()_CmdLineRaw()_ContextMenu()_ConvertLHWebColor()/_ConvertSHWebColor()_DesktopDimensions()_DisplayPassword()_DotNet_Load()/_DotNet_Unload()_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()_GUIRegisterMsg()_GUISetIcon()_Icon_Clear()/_Icon_Set()_IdleTime()_InetGet()_InetGetGUI()_InetGetProgress()_IPDetails()_IsFileOlder()_IsGUID()_IsHex()_IsPalindrome()_IsRegKey()_IsStringRegExp()_IsSystemDrive()_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_Create_CTL_CODE()_WinAPI_CreateGUID()_WMIDateStringToDate()/_DateToWMIDateString()Au3 script parsingAutoIt SearchAutoIt3 PortableAutoIt3WrapperToPragmaAutoItWinGetTitle()/AutoItWinSetTitle()CodingDirToHTML5FileInstallrFileReadLastChars()GeoIP databaseGUI - Only Close ButtonGUI ExamplesGUICtrlDeleteImage()GUICtrlGetBkColor()GUICtrlGetStyle()GUIEventsGUIGetBkColor()Int_Parse() & Int_TryParse()IsISBN()LockFile()Mapping CtrlIDsOOP in AutoItParseHeadersToSciTE()PasswordValidPasteBinPosts Per DayPreExpandProtect GlobalsQueue()Resource UpdateResourcesExSciTE JumpSettings INISHELLHOOKShunting-YardSignature CreatorStack()Stopwatch()StringAddLF()/StringStripLF()StringEOLToCRLF()VSCROLLWM_COPYDATAMore Examples...

Updated: 22/04/2018

Link to comment
Share on other sites

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
Link to comment
Share on other sites

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

Link to comment
Share on other sites

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

Sweet! :)

UDF List:

 
_AdapterConnections()_AlwaysRun()_AppMon()_AppMonEx()_ArrayFilter/_ArrayReduce_BinaryBin()_CheckMsgBox()_CmdLineRaw()_ContextMenu()_ConvertLHWebColor()/_ConvertSHWebColor()_DesktopDimensions()_DisplayPassword()_DotNet_Load()/_DotNet_Unload()_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()_GUIRegisterMsg()_GUISetIcon()_Icon_Clear()/_Icon_Set()_IdleTime()_InetGet()_InetGetGUI()_InetGetProgress()_IPDetails()_IsFileOlder()_IsGUID()_IsHex()_IsPalindrome()_IsRegKey()_IsStringRegExp()_IsSystemDrive()_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_Create_CTL_CODE()_WinAPI_CreateGUID()_WMIDateStringToDate()/_DateToWMIDateString()Au3 script parsingAutoIt SearchAutoIt3 PortableAutoIt3WrapperToPragmaAutoItWinGetTitle()/AutoItWinSetTitle()CodingDirToHTML5FileInstallrFileReadLastChars()GeoIP databaseGUI - Only Close ButtonGUI ExamplesGUICtrlDeleteImage()GUICtrlGetBkColor()GUICtrlGetStyle()GUIEventsGUIGetBkColor()Int_Parse() & Int_TryParse()IsISBN()LockFile()Mapping CtrlIDsOOP in AutoItParseHeadersToSciTE()PasswordValidPasteBinPosts Per DayPreExpandProtect GlobalsQueue()Resource UpdateResourcesExSciTE JumpSettings INISHELLHOOKShunting-YardSignature CreatorStack()Stopwatch()StringAddLF()/StringStripLF()StringEOLToCRLF()VSCROLLWM_COPYDATAMore Examples...

Updated: 22/04/2018

Link to comment
Share on other sites

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?

Link to comment
Share on other sites

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
Link to comment
Share on other sites

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
Link to comment
Share on other sites

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.

UDF List:

 
_AdapterConnections()_AlwaysRun()_AppMon()_AppMonEx()_ArrayFilter/_ArrayReduce_BinaryBin()_CheckMsgBox()_CmdLineRaw()_ContextMenu()_ConvertLHWebColor()/_ConvertSHWebColor()_DesktopDimensions()_DisplayPassword()_DotNet_Load()/_DotNet_Unload()_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()_GUIRegisterMsg()_GUISetIcon()_Icon_Clear()/_Icon_Set()_IdleTime()_InetGet()_InetGetGUI()_InetGetProgress()_IPDetails()_IsFileOlder()_IsGUID()_IsHex()_IsPalindrome()_IsRegKey()_IsStringRegExp()_IsSystemDrive()_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_Create_CTL_CODE()_WinAPI_CreateGUID()_WMIDateStringToDate()/_DateToWMIDateString()Au3 script parsingAutoIt SearchAutoIt3 PortableAutoIt3WrapperToPragmaAutoItWinGetTitle()/AutoItWinSetTitle()CodingDirToHTML5FileInstallrFileReadLastChars()GeoIP databaseGUI - Only Close ButtonGUI ExamplesGUICtrlDeleteImage()GUICtrlGetBkColor()GUICtrlGetStyle()GUIEventsGUIGetBkColor()Int_Parse() & Int_TryParse()IsISBN()LockFile()Mapping CtrlIDsOOP in AutoItParseHeadersToSciTE()PasswordValidPasteBinPosts Per DayPreExpandProtect GlobalsQueue()Resource UpdateResourcesExSciTE JumpSettings INISHELLHOOKShunting-YardSignature CreatorStack()Stopwatch()StringAddLF()/StringStripLF()StringEOLToCRLF()VSCROLLWM_COPYDATAMore Examples...

Updated: 22/04/2018

Link to comment
Share on other sites

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}).*$

Link to comment
Share on other sites

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.
Link to comment
Share on other sites

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.
Link to comment
Share on other sites

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.

Posted Image

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

Edited by THAT1ANONYMOUSEDUDE
Link to comment
Share on other sites

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..

Link to comment
Share on other sites

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
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...