Jump to content

Sky Slate Blueberry Blackcurrant Watermelon Strawberry Orange Banana Apple Emerald Chocolate
Photo

LexAHKL - Scintilla Lexer for Autohotkey L (v0.10.3 - RC2)


  • Please log in to reply
5 replies to this topic
RaptorX
  • Members
  • 751 posts
  • Last active: Feb 19 2015 02:47 AM
  • Joined: 19 Feb 2010

This is a project that I have been working for quite a while now.
I first did an external lexer for Notepad++ a while ago which was a project based on PhilHos own Lexer found here.

But that got outdated quite quickly due to new changes to the scintilla component.
I had to completely learn C++ from zero to re-write the whole lexer from scratch and here is my work.

Note that this wont work as a Notepad++ plug-in yet but there is a work around presented below.
When the plug-in is ready i will publish it as a separate topic.


---------Download---------

LexAHKL - Single Lexer
Small in size great for personal projects where you want autohotkey lexing.
I would suggest you use my Scintilla Wrapper for best results. A great example is Autohotkey Toolkit.

LexAHKL - Standard Lexers included
A little bigger but has all the other Scintilla lexers included.
This version can be used to replace N++ SciLexer.dll temporarily until i finish with the external plug-in.
Make sure to rename LexAHKL.dll to SciLexer.dll for that. It can also be used in any other general purpose where you need all the standard lexers including the AHK one.

---------------------------------

Features

  • All bugs found in the previous versions of AHK Lexers have been fixed
  • Folding
  • More accurate reproduction of Autohotkey syntax
  • Lexing of Object Syntax
  • Extremely customizable coloring. You can change the following colors to the lexer:
    • Documentation Comments (See test file for information of what this is)
    • Line Comments
    • Block Comments
    • Strings
    • String Block
    • String Block Options
    • String Block Line Comments
    • Directives
    • Commands
    • Special Command Parameters
    • Control Flow Keywords (if, else, break, continue and so on)
    • Keyboard/Mouse Keys
    • Labels
    • Hotkeys
    • Hotstrings
    • Hotstring Options
    • Decimal Numbers
    • Hexadecimal Numbers
    • User Created Variables
    • Builtin Variables
    • Variable References (in expressions)
    • Objects
    • User Functions
    • Builtin Functions
    • Escape Sequences
    • Two user defined keyword lists <-- you can highlight custom words if you want wink.png

As you can see this Lexer is extremely customizable so i will make a few notes on that.

If you dont want to color a few things then just dont assign any color to them. Also a few things might look like 'duplicates' but they arent. I made it like that to give the programmer all the flexibility needed for making things his own way. While you might prefer the line comments and the string block comments to look the same way there are other people who might not want that.

Technical Information

If you are not going to use my scintilla wrapper you might want to have this info close to you.
This is a list of the available Styles which you will be manipulating with SCI_STYLESETFORE and SCI_STYLESETBACK.

SCE_AHKL_COMMENTDOC = 2
SCE_AHKL_COMMENTLINE = 3
SCE_AHKL_COMMENTBLOCK = 4
SCE_AHKL_COMMENTKEYWORD = 5
SCE_AHKL_STRING = 6
SCE_AHKL_STRINGOPTS = 7
SCE_AHKL_STRINGBLOCK = 8
SCE_AHKL_STRINGCOMMENT = 9
SCE_AHKL_LABEL = 10
SCE_AHKL_HOTKEY = 11
SCE_AHKL_HOTSTRING = 12
SCE_AHKL_HOTSTRINGOPT = 13
SCE_AHKL_HEXNUMBER = 14
SCE_AHKL_DECNUMBER = 15
SCE_AHKL_VAR = 16
SCE_AHKL_VARREF = 17
SCE_AHKL_OBJECT = 18
SCE_AHKL_USERFUNCTION = 19
SCE_AHKL_DIRECTIVE = 20
SCE_AHKL_COMMAND = 21
SCE_AHKL_PARAM = 22
SCE_AHKL_CONTROLFLOW = 23
SCE_AHKL_BUILTINFUNCTION = 24
SCE_AHKL_BUILTINVAR = 25
SCE_AHKL_KEY = 26
SCE_AHKL_USERDEFINED1 = 27
SCE_AHKL_USERDEFINED2 = 28
SCE_AHKL_ESCAPESEQ = 30

Usage and Examples

I will assume you are using my wrapper because it will make your life easier.
To change the coloring in your program you would do this for each of the styles which you want to modify. If you dont do this for a specific style, it will stay with the default color (black).

sci.StyleSetFore(SCE_AHKL_COMMENTLINE , 0x008800) ; set color to green
sci.StyleSetFore(SCE_AHKL_COMMENTBLOCK , 0x008800), sci.StyleSetBold(SCE_AHKL_COMMENTBLOCK, true) ; set color to green and make it bold

After having set the colors your application has to provide the lexer with the keyword lists for the built in commands.
You have 9 Lists available, 0 to 8, and the keywords can be a space or newline separated list.

sci.SetKeywords(0, "first second third") this would tell the lexer to highlight those three words as soon as they are typed.

To make it easy, you can have a few variables with all the autohotkey keywords (included in the example provided below) and then assigning them in the following order:

Loop 9
{
lstN:=a_index-1

sci.SetKeywords(lstN, ( lstN = 0 ? Directives
                      : lstN = 1 ? Commands
                      : lstN = 2 ? Parameters ; these are special command parameters like 'ahk_id', 'ahk_class', 'byref' and so on.
                      : lstN = 3 ? ControlFlow ; these are keywords like 'continue', 'break', 'if', 'else' and so on
                      : lstN = 4 ? Functions
                      : lstN = 5 ? Builtinvars
                      : lstN = 6 ? Keys
                      : lstN = 7 ? UserDefined1
                      : lstN = 8 ? UserDefined2
                      : null))

; for a comprehensive list of the available keywords please see the example provided below
}

That is all you have to do to have Lexing enabled in your application.

For folding you have to first tell scintilla to have a "folding margin" available and that it responds to clicks like this:

sci.SetMarginMaskN(1, SC_MASK_FOLDERS ) ; Show folding symbols
sci.SetMarginSensitiveN(1, true) ; Catch Margin click notifications

Then you have to tell scintilla which icons to use for each folding state. Scintilla comes with some predefined icons. You can read more in the scintilla documentation site at www.scintilla.org but in short this should work fine:

sci.MarkerDefine(SC_MARKNUM_FOLDER, SC_MARK_BOXPLUS)
sci.MarkerDefine(SC_MARKNUM_FOLDEROPEN, SC_MARK_BOXMINUS)
sci.MarkerDefine(SC_MARKNUM_FOLDERSUB, SC_MARK_VLINE)
sci.MarkerDefine(SC_MARKNUM_FOLDERTAIL, SC_MARK_LCORNER)
sci.MarkerDefine(SC_MARKNUM_FOLDEREND, SC_MARK_BOXPLUSCONNECTED)
sci.MarkerDefine(SC_MARKNUM_FOLDEROPENMID, SC_MARK_BOXMINUSCONNECTED)
sci.MarkerDefine(SC_MARKNUM_FOLDERMIDTAIL, SC_MARK_TCORNER)

You can change the color of each of those above like this:

sci.MarkerSetFore(SC_MARKNUM_FOLDER , 0xFFFFFF)
sci.MarkerSetBack(SC_MARKNUM_FOLDER , 0x5A5A5A) ; repeat this for all of the above if you dont like the default coloring

Finally we have to capture the user clicks and tell scintilla to fold/unfold.

sci.Notify := "SCI_NOTIFY" ; this tells the wrapper to call that function below whenever scintilla receives a message... we are interested in user clicking a margin.

SCI_NOTIFY(wParam, lParam, msg, hwnd, sciObj) {

line := sciObj.LineFromPosition(sciObj.position)

    if (sciObj.scnCode = SCN_MARGINCLICK)
        sciObj.ToggleFold(line)
}

That should be enough to have folding activated.

Here is a complete working example of all what i just explained. This is the source of the script that can be found compiled in the folder called "test" inside the download zip above.

#include ..\SCI.ahk
#singleinstance force
#Commentflag //

// Command list
Dir=
(
#allowsamelinecomments #clipboardtimeout #commentflag #errorstdout #escapechar #hotkeyinterval
#hotkeymodifiertimeout #hotstring #if #iftimeout #ifwinactive #ifwinexist #include #includeagain
#installkeybdhook #installmousehook #keyhistory #ltrim #maxhotkeysperinterval #maxmem #maxthreads
#maxthreadsbuffer #maxthreadsperhotkey #menumaskkey #noenv #notrayicon #persistent #singleinstance
#usehook #warn #winactivateforce
)

Com=
(
autotrim blockinput clipwait control controlclick controlfocus controlget controlgetfocus
controlgetpos controlgettext controlmove controlsend controlsendraw controlsettext coordmode
critical detecthiddentext detecthiddenwindows drive driveget drivespacefree edit endrepeat envadd
envdiv envget envmult envset envsub envupdate fileappend filecopy filecopydir filecreatedir
filecreateshortcut filedelete filegetattrib filegetshortcut filegetsize filegettime filegetversion
fileinstall filemove filemovedir fileread filereadline filerecycle filerecycleempty fileremovedir
fileselectfile fileselectfolder filesetattrib filesettime formattime getkeystate groupactivate
groupadd groupclose groupdeactivate gui guicontrol guicontrolget hideautoitwin hotkey if ifequal
ifexist ifgreater ifgreaterorequal ifinstring ifless iflessorequal ifmsgbox ifnotequal ifnotexist
ifnotinstring ifwinactive ifwinexist ifwinnotactive ifwinnotexist imagesearch inidelete iniread
iniwrite input inputbox keyhistory keywait listhotkeys listlines listvars menu mouseclick
mouseclickdrag mousegetpos mousemove msgbox outputdebug pixelgetcolor pixelsearch postmessage
process progress random regdelete regread regwrite reload run runas runwait send sendevent
sendinput sendmessage sendmode sendplay sendraw setbatchlines setcapslockstate setcontroldelay
setdefaultmousespeed setenv setformat setkeydelay setmousedelay setnumlockstate setscrolllockstate
setstorecapslockmode settitlematchmode setwindelay setworkingdir shutdown sort soundbeep soundget
soundgetwavevolume soundplay soundset soundsetwavevolume splashimage splashtextoff splashtexton
splitpath statusbargettext statusbarwait stringcasesense stringgetpos stringleft stringlen
stringlower stringmid stringreplace stringright stringsplit stringtrimleft stringtrimright
stringupper sysget thread tooltip transform traytip urldownloadtofile winactivate winactivatebottom
winclose winget wingetactivestats wingetactivetitle wingetclass wingetpos wingettext wingettitle
winhide winkill winmaximize winmenuselectitem winminimize winminimizeall winminimizeallundo winmove
winrestore winset winsettitle winshow winwait winwaitactive winwaitclose winwaitnotactive
fileencoding
)

Param=
(
ltrim rtrim join ahk_id ahk_pid ahk_class ahk_group processname minmax controllist statuscd
filesystem setlabel alwaysontop mainwindow nomainwindow useerrorlevel altsubmit hscroll vscroll
imagelist wantctrla wantf2 vis visfirst wantreturn backgroundtrans minimizebox maximizebox
sysmenu toolwindow exstyle check3 checkedgray readonly notab lastfound lastfoundexist alttab
shiftalttab alttabmenu alttabandmenu alttabmenudismiss controllisthwnd hwnd deref pow bitnot
bitand bitor bitxor bitshiftleft bitshiftright sendandmouse mousemove mousemoveoff
hkey_local_machine hkey_users hkey_current_user hkey_classes_root hkey_current_config hklm hku
hkcu hkcr hkcc reg_sz reg_expand_sz reg_multi_sz reg_dword reg_qword reg_binary reg_link
reg_resource_list reg_full_resource_descriptor caret reg_resource_requirements_list
reg_dword_big_endian regex pixel mouse screen relative rgb low belownormal normal abovenormal
high realtime between contains in is integer float number digit xdigit alpha upper lower alnum
time date not or and topmost top bottom transparent transcolor redraw region id idlast count
list capacity eject lock unlock label serial type status seconds minutes hours days read parse
logoff close error single shutdown menu exit reload tray add rename check uncheck togglecheck
enable disable toggleenable default nodefault standard nostandard color delete deleteall icon
noicon tip click show edit progress hotkey text picture pic groupbox button checkbox radio
dropdownlist ddl combobox statusbar treeview listbox listview datetime monthcal updown slider
tab tab2 iconsmall tile report sortdesc nosort nosorthdr grid hdr autosize range xm ym ys xs xp
yp font resize owner submit nohide minimize maximize restore noactivate na cancel destroy
center margin owndialogs guiescape guiclose guisize guicontextmenu guidropfiles tabstop section
wrap border top bottom buttons expand first lines number uppercase lowercase limit password
multi group background bold italic strike underline norm theme caption delimiter flash style
checked password hidden left right center section move focus hide choose choosestring text pos
enabled disabled visible notimers interrupt priority waitclose unicode tocodepage fromcodepage
yes no ok cancel abort retry ignore force on off all send wanttab monitorcount monitorprimary
monitorname monitorworkarea pid base useunsetlocal useunsetglobal localsameasglobal str astr wstr
int64 int short char uint64 uint ushort uchar float double int64p intp shortp charp uint64p uintp
ushortp ucharp floatp doublep ptr
)

Flow=
(
break continue else exit exitapp gosub goto loop onexit pause repeat return settimer sleep
suspend static global local byref while until for
)

Fun=
(
abs acos asc asin atan ceil chr cos dllcall exp fileexist floor getkeystate numget numput
registercallback il_add il_create il_destroy instr islabel isfunc ln log lv_add lv_delete
lv_deletecol lv_getcount lv_getnext lv_gettext lv_insert lv_insertcol lv_modify lv_modifycol
lv_setimagelist mod onmessage round regexmatch regexreplace sb_seticon sb_setparts sb_settext
sin sqrt strlen substr tan tv_add tv_delete tv_getchild tv_getcount tv_getnext tv_get tv_getparent
tv_getprev tv_getselection tv_gettext tv_modify varsetcapacity winactive winexist trim ltrim rtrim
fileopen strget strput object isobject objinsert objremove objminindex objmaxindex objsetcapacity
objgetcapacity objgetaddress objnewenum objaddref objrelease objclone _insert _remove _minindex
_maxindex _setcapacity _getcapacity _getaddress _newenum _addref _release _clone comobjcreate
comobjget comobjconnect comobjerror comobjactive comobjenwrap comobjunwrap comobjparameter
comobjmissing comobjtype comobjvalue comobjarray
)

BIVar=
(
a_ahkpath a_ahkversion a_appdata a_appdatacommon a_autotrim a_batchlines a_caretx a_carety
a_computername a_controldelay a_cursor a_dd a_ddd a_dddd a_defaultmousespeed a_desktop
a_desktopcommon a_detecthiddentext a_detecthiddenwindows a_endchar a_eventinfo a_exitreason
a_formatfloat a_formatinteger a_gui a_guievent a_guicontrol a_guicontrolevent a_guiheight
a_guiwidth a_guix a_guiy a_hour a_iconfile a_iconhidden a_iconnumber a_icontip a_index a_ipaddress1
a_ipaddress2 a_ipaddress3 a_ipaddress4 a_isadmin a_iscompiled a_issuspended a_keydelay a_language
a_lasterror a_linefile a_linenumber a_loopfield a_loopfileattrib a_loopfiledir a_loopfileext
a_loopfilefullpath a_loopfilelongpath a_loopfilename a_loopfileshortname a_loopfileshortpath
a_loopfilesize a_loopfilesizekb a_loopfilesizemb a_loopfiletimeaccessed a_loopfiletimecreated
a_loopfiletimemodified a_loopreadline a_loopregkey a_loopregname a_loopregsubkey
a_loopregtimemodified a_loopregtype a_mday a_min a_mm a_mmm a_mmmm a_mon a_mousedelay a_msec
a_mydocuments a_now a_nowutc a_numbatchlines a_ostype a_osversion a_priorhotkey a_programfiles
a_programs a_programscommon a_screenheight a_screenwidth a_scriptdir a_scriptfullpath a_scriptname
a_sec a_space a_startmenu a_startmenucommon a_startup a_startupcommon a_stringcasesense a_tab a_temp
a_thishotkey a_thismenu a_thismenuitem a_thismenuitempos a_tickcount a_timeidle a_timeidlephysical
a_timesincepriorhotkey a_timesincethishotkey a_titlematchmode a_titlematchmodespeed a_username
a_wday a_windelay a_windir a_workingdir a_yday a_year a_yweek a_yyyy clipboard clipboardall comspec
programfiles a_thisfunc a_thislabel a_ispaused a_iscritical a_isunicode a_ptrsize errorlevel
true false
)

Keys=
(
shift lshift rshift alt lalt ralt control lcontrol rcontrol ctrl lctrl rctrl lwin rwin appskey
altdown altup shiftdown shiftup ctrldown ctrlup lwindown lwinup rwindown rwinup lbutton rbutton
mbutton wheelup wheeldown xbutton1 xbutton2 joy1 joy2 joy3 joy4 joy5 joy6 joy7 joy8 joy9 joy10 joy11
joy12 joy13 joy14 joy15 joy16 joy17 joy18 joy19 joy20 joy21 joy22 joy23 joy24 joy25 joy26 joy27
joy28 joy29 joy30 joy31 joy32 joyx joyy joyz joyr joyu joyv joypov joyname joybuttons joyaxes
joyinfo space tab enter escape esc backspace bs delete del insert ins pgup pgdn home end up down
left right printscreen ctrlbreak pause scrolllock capslock numlock numpad0 numpad1 numpad2 numpad3
numpad4 numpad5 numpad6 numpad7 numpad8 numpad9 numpadmult numpadadd numpadsub numpaddiv numpaddot
numpaddel numpadins numpadclear numpadup numpaddown numpadleft numpadright numpadhome numpadend
numpadpgup numpadpgdn numpadenter f1 f2 f3 f4 f5 f6 f7 f8 f9 f10 f11 f12 f13 f14 f15 f16 f17 f18 f19
f20 f21 f22 f23 f24 browser_back browser_forward browser_refresh browser_stop browser_search
browser_favorites browser_home volume_mute volume_down volume_up media_next media_prev media_stop
media_play_pause launch_mail launch_media launch_app1 launch_app2 blind click raw wheelleft
wheelright
)

UD1 =
UD2 =

Gui +LastFound

sci := new scintilla(WinExist(), x,y,950,680,a_iscompiled ? "..\scintilla\bin\LexAHKL.dll"
: "C:\Users\RaptorX\Documents\C++\LexAHKL\scintilla\bin\LexAHKL.dll")

sci.Notify := "SCI_NOTIFY"

sci.SetMarginWidthN(0, 40) // Show line numbers
sci.SetMarginMaskN(1, SC_MASK_FOLDERS ) // Show folding symbols
sci.SetMarginSensitiveN(1, true) // Catch Margin click notifications

// Set up Margin Symbols
sci.MarkerDefine(SC_MARKNUM_FOLDER, SC_MARK_BOXPLUS)
sci.MarkerDefine(SC_MARKNUM_FOLDEROPEN, SC_MARK_BOXMINUS)
sci.MarkerDefine(SC_MARKNUM_FOLDERSUB, SC_MARK_VLINE)
sci.MarkerDefine(SC_MARKNUM_FOLDERTAIL, SC_MARK_LCORNER)
sci.MarkerDefine(SC_MARKNUM_FOLDEREND, SC_MARK_BOXPLUSCONNECTED)
sci.MarkerDefine(SC_MARKNUM_FOLDEROPENMID, SC_MARK_BOXMINUSCONNECTED)
sci.MarkerDefine(SC_MARKNUM_FOLDERMIDTAIL, SC_MARK_TCORNER)

// Change margin symbols colors
sci.MarkerSetFore(SC_MARKNUM_FOLDER , 0xFFFFFF)
sci.MarkerSetBack(SC_MARKNUM_FOLDER , 0x5A5A5A)
sci.MarkerSetFore(SC_MARKNUM_FOLDEROPEN , 0xFFFFFF)
sci.MarkerSetBack(SC_MARKNUM_FOLDEROPEN , 0x5A5A5A)
sci.MarkerSetFore(SC_MARKNUM_FOLDERSUB , 0xFFFFFF)
sci.MarkerSetBack(SC_MARKNUM_FOLDERSUB , 0x5A5A5A)
sci.MarkerSetFore(SC_MARKNUM_FOLDERTAIL , 0xFFFFFF)
sci.MarkerSetBack(SC_MARKNUM_FOLDERTAIL , 0x5A5A5A)
sci.MarkerSetFore(SC_MARKNUM_FOLDEREND , 0xFFFFFF)
sci.MarkerSetBack(SC_MARKNUM_FOLDEREND , 0x5A5A5A)
sci.MarkerSetFore(SC_MARKNUM_FOLDEROPENMID, 0xFFFFFF)
sci.MarkerSetBack(SC_MARKNUM_FOLDEROPENMID, 0x5A5A5A)
sci.MarkerSetFore(SC_MARKNUM_FOLDERMIDTAIL, 0xFFFFFF)
sci.MarkerSetBack(SC_MARKNUM_FOLDERMIDTAIL, 0x5A5A5A)
sci.SetFoldFlags(SC_FOLDFLAG_LEVELNUMBERS)

// Set Autohotkey Lexer and default options
sci.SetWrapMode(true), sci.SetLexer(SCLEX_AHKL)
sci.StyleSetFont(STYLE_DEFAULT, "Courier New"), sci.StyleSetSize(STYLE_DEFAULT, 10), sci.StyleClearAll()

// Set Style Colors
sci.StyleSetFore(SCE_AHKL_IDENTIFIER , 0x000000)

sci.StyleSetFore(SCE_AHKL_COMMENTDOC , 0x008888)
sci.StyleSetFore(SCE_AHKL_COMMENTLINE , 0x008800)
sci.StyleSetFore(SCE_AHKL_COMMENTBLOCK , 0x008800), sci.StyleSetBold(SCE_AHKL_COMMENTBLOCK, true)
sci.StyleSetFore(SCE_AHKL_COMMENTKEYWORD , 0xA50000), sci.StyleSetBold(SCE_AHKL_COMMENTKEYWORD, true)
sci.StyleSetFore(SCE_AHKL_STRING , 0xA2A2A2)
sci.StyleSetFore(SCE_AHKL_STRINGOPTS , 0x00EEEE)
sci.StyleSetFore(SCE_AHKL_STRINGBLOCK , 0xA2A2A2), sci.StyleSetBold(SCE_AHKL_STRINGBLOCK, true)
sci.StyleSetFore(SCE_AHKL_STRINGCOMMENT , 0xFF0000)
sci.StyleSetFore(SCE_AHKL_LABEL , 0x0000DD)
sci.StyleSetFore(SCE_AHKL_HOTKEY , 0x00AADD)
sci.StyleSetFore(SCE_AHKL_HOTSTRING , 0x00BBBB)
sci.StyleSetFore(SCE_AHKL_HOTSTRINGOPT , 0x990099)
sci.StyleSetFore(SCE_AHKL_HEXNUMBER , 0x880088)
sci.StyleSetFore(SCE_AHKL_DECNUMBER , 0xFF9000)
sci.StyleSetFore(SCE_AHKL_VAR , 0xFF9000)
sci.StyleSetFore(SCE_AHKL_VARREF , 0x990055)
sci.StyleSetFore(SCE_AHKL_OBJECT , 0x008888)
sci.StyleSetFore(SCE_AHKL_USERFUNCTION , 0x0000DD)

sci.StyleSetFore(SCE_AHKL_DIRECTIVE , 0x4A0000), sci.StyleSetBold(SCE_AHKL_DIRECTIVE, true)
sci.StyleSetFore(SCE_AHKL_COMMAND , 0x0000DD), sci.StyleSetBold(SCE_AHKL_COMMAND, true)
sci.StyleSetFore(SCE_AHKL_PARAM , 0x0085DD)
sci.StyleSetFore(SCE_AHKL_CONTROLFLOW , 0x0000DD)
sci.StyleSetFore(SCE_AHKL_BUILTINFUNCTION, 0xDD00DD)
sci.StyleSetFore(SCE_AHKL_BUILTINVAR , 0xEE3010), sci.StyleSetBold(SCE_AHKL_BUILTINVAR, true)
sci.StyleSetFore(SCE_AHKL_KEY , 0xA2A2A2), sci.StyleSetBold(SCE_AHKL_KEY, true), sci.StyleSetItalic(SCE_AHKL_KEY, true)
sci.StyleSetFore(SCE_AHKL_USERDEFINED1 , 0x000000)
sci.StyleSetFore(SCE_AHKL_USERDEFINED2 , 0x000000)

sci.StyleSetFore(SCE_AHKL_ESCAPESEQ , 0x660000), sci.StyleSetItalic(SCE_AHKL_ESCAPESEQ, true)
sci.StyleSetFore(SCE_AHKL_ERROR , 0xFF0000)

// Put some text in the control (optional)
FileRead, text, Highlight Test.txt
sci.SetText(unused, text), sci.GrabFocus()

// Set up keyword lists, the variables are set at the beginning of the code
Loop 9
{
lstN:=a_index-1

sci.SetKeywords(lstN, ( lstN = 0 ? Dir
                      : lstN = 1 ? Com
                      : lstN = 2 ? Param
                      : lstN = 3 ? Flow
                      : lstN = 4 ? Fun
                      : lstN = 5 ? BIVar
                      : lstN = 6 ? Keys
                      : lstN = 7 ? UD1
                      : lstN = 8 ? UD2
                      : null))
}
Gui, +resize +minsize
Gui, show, center w960 h690 // autosize doesnt recognize the scintilla control, width & height + 10px border
return

GuiSize:
WinMove, % "ahk_id " sci.hwnd,, 5, 5, % a_guiwidth - 10, % a_guiheight - 10
return

GuiClose:
ExitApp

Pause::
Reload
return

+Pause::
Run run.ahk
ExitApp

// This function handles the Click notifications and tells Scintilla to Fold/Unfold
SCI_NOTIFY(wParam, lParam, msg, hwnd, sciObj) {

line := sciObj.LineFromPosition(sciObj.position)

    if (sciObj.scnCode = SCN_MARGINCLICK)
        sciObj.ToggleFold(line)
}

Changelog

LexAHKL v0.10.3-22RC2
Date: Wed May 22 02:42:46 2013 +0200


Changes:

+ Add Scintilla.iface definitions for all other lexers

^ Update README file

Todo:

+ Add Line States and context sensitivity
+ Add Highlighting of forced expression operator


! Fix Expressions end Commands
! Fix dont start fold if text after fold opener
! Fix continue expression with Commas
! Fix Comma terminate single line expressions


LexAHKL v0.10.2-21RC1
Date: Thu May 2 14:47:28 2013 +0200


Changes:

! Fix String Block options not exiting at line end

Todo:

+ Add Line States and context sensitivity

! Fix Expressions end Commands
! Fix dont start fold if text after fold opener
! Fix continue expression with Commas
! Fix Comma terminate single line expressions


LexAHKL v0.10.1-20
Date: Thu May 2 13:35:26 2013 +0200


Changes:

! Fix Documentation Blocks quoted strings highlighting

Todo:

+ Add Line States and context sensitivity

! Fix String Block options not exiting at line end
! Fix Comma terminate expressions


License

Copyright © 2013 Isaias Baez 'RaptorX'

This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as
published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.

This program is distributed in the hope that it will be useful, WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the General Public License for more details.

You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/l...ses/gpl-3.0.txt>

Isaias Baez
Emden, Germany


AutoHotkey Toolkit [Main Project]
Scintilla Wrapper
LexAHKL

rmortensen
  • Members
  • 26 posts
  • Last active: Mar 14 2015 07:41 AM
  • Joined: 08 Sep 2008

Hi

 

I downloaded the bugger dll, renamed it, and replaced the SciLexer file in C:\Program Files (x86)\Notepad++

I installed latest npp, 6.3.3

I'm using Danish Win8

 

But ahk files look plain, i.e. no colors etc. Any hints?


--
Regards,
R. Mortensen

kraker148
  • Members
  • 42 posts
  • Last active: Sep 13 2014 06:05 PM
  • Joined: 12 Mar 2009

hi raptorx, thanks for this great project

my question is about custom Scintilla control

can we use your scintilla class with "custom Scintilla" control? I tried but cannot do.. I think, it is from CreateWindowEx dllcall issue. How can we work arround this? (I tried assign custom scintilla controls hwnd to hSci variable but not retrieve any thing, the script freezes).

Thanks...



maraskan_user
  • Members
  • 52 posts
  • Last active: Dec 08 2014 11:18 PM
  • Joined: 20 Jun 2008

Nice work, Raptorx.

There are two instances of

mainState == SCE_AHKL_NEUTRAL;

that should probably be

mainState = SCE_AHKL_NEUTRAL;

I guess, but it's working fine.

 

Are there any points that are still missing in your lexer? How would the road to a 1.0 release look like? What are your thoughts on going for an inclusion into scintilla?

 

Your "Highlight Test.txt" is very nice for testing AHK lexers. It might be of interest to add more edge cases to it that not all lexers handle well. So far I've come up with:

Send,{"}

Send,{#}

Success:=DllCall("CreateProcessW","UPtr", 0,"UPtr", &sCmd,"Uint", 0,"Uint", 0, "Int", 1,"Uint", 0x08000000,"Uint", 0,"UPtr", sDir ? &sDir : 0,"UPtr", &si,"UPtr", &pi)

Success:=DllCall("CreateProcessW","UPtr", 0
                ,"UPtr", &sCmd
                ,"Uint", 0
                ,"Uint", 0
                , "Int", 1
                ,"Uint", 0x08000000
                ,"Uint", 0
                ,"UPtr", sDir ? &sDir : 0
                ,"UPtr", &si
                ,"UPtr", &pi)

I integrated your 0.10.3RC2 ahkl lexer as well as PhiLho's ahk1 and ahk2 lexer from SciTE4AHK 3.0.4.0 into an up to date NotePad++ 6.4.5 plus SciLexer 2.2.7.0 private branch, so the lexers are available from N++ languages menu and can be switched easily for comparison. It uses the same styles as your "Highlight Test.exe" and  SciTE4AHK's Classic style. I was wondering if I should make those binaries and/or source available for people who might want them.



RaptorX
  • Members
  • 751 posts
  • Last active: Feb 19 2015 02:47 AM
  • Joined: 19 Feb 2010

Hi
 
I downloaded the bugger dll, renamed it, and replaced the SciLexer file in C:\Program Files (x86)\Notepad++
I installed latest npp, 6.3.3
I'm using Danish Win8
 
But ahk files look plain, i.e. no colors etc. Any hints?


I am not sure how it works on Win8... as soon as I have more info I will post an update.
and I think you are missing a configuration file for N++ that makes the Autohotkey Language to appear in the language list.
 

hi raptorx, thanks for this great project
my question is about custom Scintilla control
can we use your scintilla class with "custom Scintilla" control? I tried but cannot do.. I think, it is from CreateWindowEx dllcall issue. How can we work arround this? (I tried assign custom scintilla controls hwnd to hSci variable but not retrieve any thing, the script freezes).
Thanks...


As far as i understand yes. I havent tried it yet, because I recommend using the Scintilla wrapper that i created for it. You can find it in my signature.
Just download the wrapper, include it, and call the sci.add() function.
 

Nice work, Raptorx.
There are two instances of

mainState == SCE_AHKL_NEUTRAL;
that should probably be
mainState = SCE_AHKL_NEUTRAL;
I guess, but it's working fine.
 
Are there any points that are still missing in your lexer? How would the road to a 1.0 release look like? What are your thoughts on going for an inclusion into scintilla?
 
Your "Highlight Test.txt" is very nice for testing AHK lexers. It might be of interest to add more edge cases to it that not all lexers handle well. So far I've come up with:
Send,{"}

Send,{#}

Success:=DllCall("CreateProcessW","UPtr", 0,"UPtr", &sCmd,"Uint", 0,"Uint", 0, "Int", 1,"Uint", 0x08000000,"Uint", 0,"UPtr", sDir ? &sDir : 0,"UPtr", &si,"UPtr", &pi)

Success:=DllCall("CreateProcessW","UPtr", 0
                ,"UPtr", &sCmd
                ,"Uint", 0
                ,"Uint", 0
                , "Int", 1
                ,"Uint", 0x08000000
                ,"Uint", 0
                ,"UPtr", sDir ? &sDir : 0
                ,"UPtr", &si
                ,"UPtr", &pi)
I integrated your 0.10.3RC2 ahkl lexer as well as PhiLho's ahk1 and ahk2 lexer from SciTE4AHK 3.0.4.0 into an up to date NotePad++ 6.4.5 plus SciLexer 2.2.7.0 private branch, so the lexers are available from N++ languages menu and can be switched easily for comparison. It uses the same styles as your "Highlight Test.exe" and  SciTE4AHK's Classic style. I was wondering if I should make those binaries and/or source available for people who might want them.


The Send {"} and Send {#} are working as intended in my lexer, they wont highlight because they are not keyboard keywords... things like Send {a} wont highlight either, only keywords like {shift} or {enter} would become highlighted at the moment.

The thing with the continuation section with commas was a good catch though. If you precede the commas with a . it should highlight correctly.
I remember postponing the continuation section with commas because it creates a problem with another part of the lexer.

I am fairly sure that I will make the first release soon, but due to big changes in my life at the moment I am in a small coding-pause. hehe

And of course, all my code can be found on Github under the alias "RaptorX", here is the lexer:
https://github.com/RaptorX/LexAHKL
AutoHotkey Toolkit [Main Project]
Scintilla Wrapper
LexAHKL

maraskan_user
  • Members
  • 52 posts
  • Last active: Dec 08 2014 11:18 PM
  • Joined: 20 Jun 2008

The Send,{"} and Send,{#} I introduced since they cause problems with the UDL lexer of N++. Some of the User Defined Languages available on this forum have problems with them. As I said, I recompiled Notepad++ and its custom scintilla component with your's and PhiLho's lexers included into the source so I can easily switch between via N++'s menu and compare the output of them to each other and to UDL definitions.