Jump to content

AutoIt Syntax Highlighter


the DtTvB
 Share

Recommended Posts

And finally, I made a syntax highlighter for autoit.

It currently supports:

  • Strings
  • Comments
  • # statements (e.g. #include-once)
  • Variables
  • Macros
  • Functions
  • Numbers
But not:
  • Comment block
  • Operators
  • Sent keys
  • COM Objects
It can be used in web-based AutoIt applications.

How it works?

Step 1: Split the string into lines.

Step 2: Loop through each lines.

Step 2.1: Loop through each characters to find strings, comments, and preprocessors. Highlight and enity it (Will change A to A)

Step 2.2: Close the unclosed tags

Step 2.3: Indent the code, so we can match the text at the beginning of the string.

Step 2.4: Highlight the keywords.

Step 2.5: Highlight the numbers, functions, macros, and variables.

The global variables.

I defined the global variables so I don't have to declare it each time.

It defines how the syntax will look.

; Set the global variable so we don't have to declare it each time.
Global $stringStart   = '<span style="color: #999">';
Global $stringEnd     = '</span>';
Global $commentStart  = '<span style="color: #090; font-style: italic">';
Global $commentEnd    = '</span>';
Global $keywordStart  = '<span style="color: #00f; font-weight: bold">';
Global $keywordEnd    = '</span>';
Global $functionstart = '<span style="color: #009; font-weight: bold; font-style: italic">';
Global $functionend   = '</span>';
Global $numberStart   = '<span style="color: #909; font-weight: bold; font-style: italic">';
Global $numberEnd     = '</span>';
Global $macroStart    = '<span style="color: #f0f; font-weight: bold">';
Global $macroEnd      = '</span>';
Global $variableStart = '<span style="color: #900; font-weight: bold">';
Global $variableEnd   = '</span>';
Global $hashStart     = '<span style="color: #f0f; font-style: italic">';
Global $hashEnd       = '</span>';oÝ÷ Ù´áyû§rبڢ{Þ®Ûaz[`µ©Ýjjm8b±û§rبÊ'½êí²Ø^Ø-jwZhØ-jwZ®¶­sc²W66W2FRDÔÂ6&7FW ¦gVæ2&WGW&äW66VD6"b33c¶2 bb33c¶2ÓÒb33²fÇC²b33²FVà &WGW&âb33²fÇC²b33³° VÇ6Tbb33c¶2ÓÒb33²fwC²b33²FVà &WGW&âb33²fwC²b33³° VÇ6Tbb33c¶2ÓÒb33²fײb33²FVà &WGW&âb33²fײb33³° VÇ6P &WGW&âb33c¶3° VæD`¦VæDgVæ0oÝ÷ Ù²Ë
+v·©§"îËb¢ÛÓ~©ÊÞ}êÞÇ­¢Ø^)Þjwmí7êȬ¶¤{,(­ÔáÇîËb¢wâÛ-ì(­Û)yÈçbØ^Ó~¬¶­Ë.®º.×o&§¢v¥¦§ºg«Ç!j¶µêÚºÚ"µÍÈXÙÈHÙ^]ÛÜÂ[ÈXÙRÙ^]ÛÜÊTY    ÌÍÜ  ÌÍÜÊBIÌÍÜHÝ[ÔYÑ^XÙJ  ÌÍÜ  ÌÎNÊÚJJ×K^NW×JJ   ÌÎNÈ [È ÌÍÜÈ    [È ÌÎNÊJ×K^NW×JIÌÎNË   ÌÎNÉÌLÌIÌÎNÈ    [È ÌÍÚÙ^]ÛÜÝ    [È ÌÎNÉÌLÌÌÎNÈ [È ÌÍÚÙ^]ÛÜ[ [È ÌÎNÉÌLÌÉÌÎNÊNÂ[[oÝ÷ Ù´ázf¢û§rب}ÿm«­¢+Øì5¥¸Õ¹Ñ¥½¸)Õ¹}Må¹Ñá!¥¡±¥¡Ð ÀÌØí¤oÝ÷ ØX«²×(÷«¶Ú.,ewاÊ"µÆ§²b¶Ø^)ÞrëyËeÉ©Ývay§-¹©l¦X­jëh×6  ; Windows line ending   --> Unix line ending.
    $d = stringReplace($d, @CrLf, @Lf);
    ; Macintosh line ending --> Unix line ending.
    $d = stringReplace($d, @Cr, @Lf);

    ; Split into lines...
    $l = stringSplit($d, @Lf, 1);oÝ÷ Ø7ªÞ²½ªâi¹^±«­¢+Ø$ÀÌØí¼ôÌäìÌäììQ¡½ÕÑÁÕÐ(%½ÈÀÌØí¤ôÄѼÀÌØí±lÁt($$ÀÌØíÀôÌäìÌäìì
ÕÉɹÐÁÉͱ¥¹¸($$ÀÌØíÐôÌäìÌäììQáй½ÑÑ¥½¸¸oÝ÷ ØX§vØ^ªê-zƧuÚ"´:'ßÛp¢ºòûazËkx!j÷­ç¬qª^v«¨µë«¨µÉbrJ®¢Ú®¢Ø^­ê®¢Ú®¢Ú®¢Ò-Â)e²b¶)í¢f§ÊËkx,ªê-rX«¨¶«¨¶«z«¨µ©Ýªê-ªê-nëmêÞ²émË-Ymë殶­s`²bvRf÷VæBFRF÷V&ÆRV÷FP bb33c¶66"ÓÒb33²gV÷C²b33²FVà ²bæòFWB÷VæVBFVâ÷VâFRFWBà bb33c·BÓÒb33²b33²FVà b33c·BÒb33²gV÷C²b33³° b33c·f׳Òb33c·7G&æu7F'Bfײb33²gV÷C²b33³° ²bFRFWB2÷VæVBW6ærFRgV÷C²FVâ6Æ÷6RFRFWBà VÇ6Tbb33c·BÓÒb33²gV÷C²b33²FVà b33c·BÒb33²b33³° b33c·f׳Òb33²gV÷C²b33²fײb33c·7G&ætVæC° ²VÇ6RRærâ÷VæVBW6ærFRb33²Â÷"6öÖÖVçBÖöFRÂ&çB2æ÷&ÖÂà VÇ6P b33c·f׳Òb33²gV÷C²b33³° VæD` ²'WBbvRf÷VæBFR6ævÆRV÷FP VÇ6Tbb33c¶66"ÓÒgV÷C²b33²gV÷C²FVà ²bæòFWB2÷VæVBFVâ÷VâFRFWBà bb33c·BÓÒb33²b33²FVà b33c·BÒgV÷C²b33²gV÷C³° b33c·f׳Òb33c·7G&æu7F'BfײgV÷C²b33²gV÷C³° ²bFRFWBb÷VæVBW6ærFRb33²FVâ6Æ÷6RFRFWBà VÇ6Tbb33c·BÓÒgV÷C²b33²gV÷C²FVà b33c·BÒb33²b33³° b33c·f׳ÒgV÷C²b33²gV÷C²fײb33c·7G&ætVæC° ²VÇ6RÂ&çB2æ÷&ÖÂà VÇ6P b33c·f׳ÒgV÷C²b33²gV÷C³° VæDoÝ÷ ØX§vØ^r¦z{ljw^±Æ©z+Sç(g§µÆ§ßÛ[yÉh±çZØZ²²Ö­zg§¶Æ¥²(×hzÉ÷öÛZëh¢Z'Ú¡×¢µÊ{H¢éÝi©Ý^Æج¢§yØ­Æ¢i×¥±âãM7éÇ!joÝ÷ Ø)h±ëazéÜvÖ [(w^Ûaz×±¶Ê"µÆ§«Ø^!ö­¶¬µªí¡ûazX§y«­¢+Ø$$ì=-ä°Ý¥¹¥Í¡Ñ¡±½½À°Ý±½ÍÑ¡Õ¹±½ÍÍÑÉ¥¹¸($%¥ ÀÌØíÐôôÌäìÅÕ½ÐìÌäì=ÈÀÌØíÐôôÅÕ½ÐìÌäìÅÕ½Ðì¤Ñ¡¸($$$ÀÌØíÀµÀìôÀÌØíÍÑÉ¥¹¹ì($$츸¹Ý±½ÍÑ¡½µµ¹Ð¸($%±Í% ÀÌØíÐôôÌäììÌäì¤Ñ¡¸($$$ÀÌØíÀµÀìôÀÌØí½µµ¹Ñ¹ì($$츸¹Ý±½ÍÑ¡¡Í ¸($%±Í% ÀÌØíÐôôÌäìÌäì¤Ñ¡¸($$$ÀÌØíÀµÀìôÀÌØí¡Í¡¹ì($%¹%($$ì]¥¹¹ÐÑ¡Ñáаͼ¥ÐÌäíÌÍ¥ÈѼÁÉ͸($$ÀÌØíÀôÌäìÌäìµÀìÀÌØíÀµÀìÌäìÌäììoÝ÷ Øx X ÛazG²Âݱ«­¢+Ø$$ì!¥¡±¥¡ÐÑ¡­åݽɸÀÌØíÀ¥Ìåɸ($%ÉÁ±-åݽÉÌ ÀÌØíÀ°Ìäí¥Ìäì¤ì($%ÉÁ±-åݽÉÌ ÀÌØíÀ°ÌäíÑ¡¸Ìäì¤ì($%ÉÁ±-åݽÉÌ ÀÌØíÀ°Ìäí±Í¥Ìäì¤ì($%ÉÁ±-åݽÉÌ ÀÌØíÀ°Ìäí±ÍÌäì¤ì($%ÉÁ±-åݽÉÌ ÀÌØíÀ°Ìäí¹¥Ìäì¤ì($%ÉÁ±-åݽÉÌ ÀÌØíÀ°ÌäíͱÐÌäì¤ì($%ÉÁ±-åݽÉÌ ÀÌØíÀ°ÌäíÍÝ¥Ñ Ìäì¤ì($%ÉÁ±-åݽÉÌ ÀÌØíÀ°ÌäíÍÌäì¤ì($%ÉÁ±-åݽÉÌ ÀÌØíÀ°Ìäí¹ÍÝ¥Ñ Ìäì¤ì($%ÉÁ±-åݽÉÌ ÀÌØíÀ°Ìäí¹Í±ÐÌäì¤ì($%ÉÁ±-åݽÉÌ ÀÌØíÀ°Ìäí½ÈÌäì¤ì($%ÉÁ±-åݽÉÌ ÀÌØíÀ°Ìäí¥¸Ìäì¤ì($%ÉÁ±-åݽÉÌ ÀÌØíÀ°Ìäí¹áÐÌäì¤ì($%ÉÁ±-åݽÉÌ ÀÌØíÀ°ÌäíÍÑÀÌäì¤ì($%ÉÁ±-åݽÉÌ ÀÌØíÀ°ÌäíÝ¥Ñ Ìäì¤ì($%ÉÁ±-åݽÉÌ ÀÌØíÀ°Ìäí¹Ý¥Ñ Ìäì¤ì($%ÉÁ±-åݽÉÌ ÀÌØíÀ°ÌäíÝ¡¥±Ìäì¤ì($%ÉÁ±-åݽÉÌ ÀÌØíÀ°ÌäíݹÌäì¤ì($%ÉÁ±-åݽÉÌ ÀÌØíÀ°Ìäí¼Ìäì¤ì($%ÉÁ±-åݽÉÌ ÀÌØíÀ°Ìäíչѥ°Ìäì¤ì($%ÉÁ±-åݽÉÌ ÀÌØíÀ°ÌäíÕ¹Ìäì¤ì($%ÉÁ±-åݽÉÌ ÀÌØíÀ°Ìäí¹Õ¹Ìäì¤ì($%ÉÁ±-åݽÉÌ ÀÌØíÀ°Ìäí½¹ÍÐÌäì¤ì($%ÉÁ±-åݽÉÌ ÀÌØíÀ°Ìäí½¹Ñ¥¹ÕÍÌäì¤ì($%ÉÁ±-åݽÉÌ ÀÌØíÀ°Ìäí½¹Ñ¥¹Õ±½½ÀÌäì¤ì($%ÉÁ±-åݽÉÌ ÀÌØíÀ°ÌäíÕ±ÐÌäì¤ì($%ÉÁ±-åݽÉÌ ÀÌØíÀ°Ìäí¥´Ìäì¤ì($%ÉÁ±-åݽÉÌ ÀÌØíÀ°Ìäí¹Õ´Ìäì¤ì($%ÉÁ±-åݽÉÌ ÀÌØíÀ°Ìäíá¥ÐÌäì¤ì($%ÉÁ±-åݽÉÌ ÀÌØíÀ°Ìäíá¥Ñ±½½ÀÌäì¤ì($%ÉÁ±-åݽÉÌ ÀÌØíÀ°Ìäí±ÍÌäì¤ì($%ÉÁ±-åݽÉÌ ÀÌØíÀ°Ìäí±½°Ìäì¤ì($%ÉÁ±-åݽÉÌ ÀÌØíÀ°Ìäí±½°Ìäì¤ì($%ÉÁ±-åݽÉÌ ÀÌØíÀ°ÌäíÉ¥´Ìäì¤ì($%ÉÁ±-åݽÉÌ ÀÌØíÀ°ÌäíÉÑÕɸÌäì¤ì($%ÉÁ±-åݽÉÌ ÀÌØíÀ°ÌäíÑÉÕÌäì¤ìoÝ÷ Øx X Ú-êì¶çßjëh×6      ; Highlight the number.
        $p = stringRegExpReplace($p, '([^A-Za-z0-9_#])([0-9]+)([^A-Za-z0-9_])', '\1' & $numberStart & '\2' & $numberEnd & '\3');
        ; .. and the hexadecimal too.
        $p = stringRegExpReplace($p, '([^A-Za-z0-9_#])(0x)([0-9]+)([^A-Za-z0-9_])', '\1' & $numberStart & '\2\3' & $numberEnd & '\4');
        ; Now, highlight the function.
        $p = stringRegExpReplace($p, '([A-Za-z0-9_]+)(\s*?)\(', $functionstart & '\1' & $functionend & '\2(');
        ; Then, highlight the macro.
        $p = stringRegExpReplace($p, '@([A-Za-z0-9_]+)', $macroStart & '@\1' & $macroEnd);
        ; And some variable.
        $p = stringRegExpReplace($p, '\$([A-Za-z0-9_]+)', $variableStart & '$\1' & $variableEnd);
        ; Finally, outdent the text.
        $p = stringMid($p, 2);oÝ÷ Ø]¶ayø§jZ.¶­rí{¶¥¢^Ø¥¶Ú¶¬r¸©¶·­º¹ÞÖ®¶­s`b33c¶òf׳Òb33c·fײ7$Æc° æW@  &WGW&âb33c¶ó°¦VæDgVæoÝ÷ Ù:.±è­q©eK)íkâbtß«®*m¶bbH¶ÈhºW[{
Ú¦{az[i­è-µ¨ºÚ"µÍÈÝØÜÛÛÛÛUÜ]H
    ÌÎNÖTÝÙYPNHÌÎNÈ [ÈÜNÂÛÛÛÛUÜ]H
    ÌÎNÐÛÛ[UN^Ú[  ÌÎNÈ [ÈÜNÂÛÛÛÛUÜ]H
ÜNÂÌÍÙ]HH[TXY
    ÌÎNÜÛÛYØÜ]LÉÌÎNÊNÂÛÛÛÛUÜ]H
    ÌÎNÉÜIÝÉÌÎNÈ   [ÈÔÞ[^YÚYÚ
    ÌÍÙ]JH   [È ÌÎNÉËÜIÝÉÌÎNÊN

It is a bit slow, but it does work!

See the result here.

The full code: highlighter.au3

Edited by the DtTvB
Link to comment
Share on other sites

This is really good!

The result looks just like SciTE synatx colors.

I haven't taken a close look at the code yet.

If you think it's kinda slow, you could try using RichEdit instead of HTML.

Works the same way, and since you have the syntax lexer it should be

easy.

Well done. :lmao:

[quote name='Valik' post='301213' date='Jan 31 2007, 10:36 PM']You seem to have a habit of putting things in the wrong place. I feel sorry for any female you attempt to have sex with.[/quote][font="Lucida Sans Unicode"][/font]

Link to comment
Share on other sites

It works really well DtTvB. Good work!

My Programs:AInstall - Create a standalone installer for your programUnit Converter - Converts Length, Area, Volume, Weight, Temperature and Pressure to different unitsBinary Clock - Hours, minutes and seconds have 10 columns each to display timeAutoIt Editor - Code Editor with Syntax Highlighting.Laserix Editor & Player - Create, Edit and Play Laserix LevelsLyric Syncer - Create and use Synchronised Lyrics.Connect 4 - 2 Player Connect 4 Game (Local or Online!, Formatted Chat!!)MD5, SHA-1, SHA-256, Tiger and Whirlpool Hash Finder - Dictionary and Brute Force FindCool Text Client - Create Rendered ImageMy UDF's:GUI Enhance - Enhance your GUIs visually.IDEA File Encryption - Encrypt and decrypt files easily! File Rename - Rename files easilyRC4 Text Encryption - Encrypt text using the RC4 AlgorithmPrime Number - Check if a number is primeString Remove - remove lots of strings at onceProgress Bar - made easySound UDF - Play, Pause, Resume, Seek and Stop.
Link to comment
Share on other sites

Maybe he is used to doing it in other languages?

My Programs:AInstall - Create a standalone installer for your programUnit Converter - Converts Length, Area, Volume, Weight, Temperature and Pressure to different unitsBinary Clock - Hours, minutes and seconds have 10 columns each to display timeAutoIt Editor - Code Editor with Syntax Highlighting.Laserix Editor & Player - Create, Edit and Play Laserix LevelsLyric Syncer - Create and use Synchronised Lyrics.Connect 4 - 2 Player Connect 4 Game (Local or Online!, Formatted Chat!!)MD5, SHA-1, SHA-256, Tiger and Whirlpool Hash Finder - Dictionary and Brute Force FindCool Text Client - Create Rendered ImageMy UDF's:GUI Enhance - Enhance your GUIs visually.IDEA File Encryption - Encrypt and decrypt files easily! File Rename - Rename files easilyRC4 Text Encryption - Encrypt text using the RC4 AlgorithmPrime Number - Check if a number is primeString Remove - remove lots of strings at onceProgress Bar - made easySound UDF - Play, Pause, Resume, Seek and Stop.
Link to comment
Share on other sites

Very nice, i like this. I would also like the php version of this script that this forum uses when people post autoit code. Anyone know where i could fine such a php script?

Edited by The Kandie Man

"So man has sown the wind and reaped the world. Perhaps in the next few hours there will no remembrance of the past and no hope for the future that might have been." & _"All the works of man will be consumed in the great fire after which he was created." & _"And if there is a future for man, insensitive as he is, proud and defiant in his pursuit of power, let him resolve to live it lovingly, for he knows well how to do so." & _"Then he may say once more, 'Truly the light is sweet, and what a pleasant thing it is for the eyes to see the sun.'" - The Day the Earth Caught Fire

Link to comment
Share on other sites

Umm.. I think it's called GeSHi (General Syntax Highlighter), maybe, here!

And, and I previously code PHP and Javascript, but sometimes I code VB too. That's why my syntax is weird. Even through, my PHP coding style is weird.

Link to comment
Share on other sites

  • 2 months later...

can you make the code into one function that you plug in the code and it returns the highlighted html?

[center]AutoIT + Finger Print Reader/Scanner = COOL STUFF -> Check Out Topic![/center][center][font=Arial Black]Check out ConsultingJoe.com[/font][/center][center]My Scripts~~~~~~~~~~~~~~Web Protocol Managing - Simple WiFi Scanner - AutoTunes - Remote PC Control V2 - Audio SpectrascopePie Chart UDF - At&t's TTS - Custom Progress Bar - Windows Media Player Embed[/center]

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

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...