Jump to content

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

Syntax highlighting support for Eclipse,FAR man and others


  • Please log in to reply
27 replies to this topic
jonib
  • Members
  • 75 posts
  • Last active: Feb 18 2017 04:44 PM
  • Joined: 09 May 2006
I'm working on syntax highlighting support for AutoHotkey in Colorer Library take5 that can be used with Eclipse, FAR manager and others.

It's work in progress so some stuff don't work correctly or at all, if anybody tests comments are welcome.
This is a newer version than what I posted here

Keywords and other stuff should work.

Outlines should work on labels and functions but functions must have an open brace "{" on the same line as the function name.

You can change the colors by choosing a Color style/schema in colorers settings or make your own Color style/schema in colorer\hrd directory.

Updated info:
I have separated the Autohotkey syntax into 2 "modes" Basic and Advanced, Basic mode should be a stable/minimal/fast syntax highlighting and Advanced is unstable/experimental/anything that can be done with colorers syntax and my skill.

You choose which mode is default when installing, the mode can be changed by reinstalling, both modes are available within Colorers settings.

And now it uses the syntax files from AutoHotkeys extras folder.

Screenshots: Eclipse , FAR manager and FAR manager with outlines.

I will put same more info here later.

To install in Eclipse:
You need to install the Colorer Eclipse plugin more info here.
Update: In newer Eclipse versions you need to add "*.ahk" file-type in menu "Window -> Preferences... -> General -> Editors -> FileAssociations" and specify an "Colorer Editor" associated editor.
And when opening a .AHK file check that Eclipse is using a Colorer editor.

To install in FAR manager:
You need to download FarColorer and unpack to FAR manager plugin directory.

And finally my AutoHotkey support:
ColorerInstall012.exe: compiled install script, just run the exe it unpacks the needed files and when the script asks for "catalog.xml" go to Colorerplugin folder and choose the catalog file, now choose Basic or Advanced mode.
or
AHKColorer012.zip:Unpack the zipfile, run "ColorerInstall.ahk" install script and when the script asks for "catalog.xml" go to Colorerplugin and choose the catalog file, now choose Basic or Advanced mode.

In the Zipfile there are 7 files
ColorerInstall.ahk   Install script.
protoadv.hrc         Modification to Colorers proto.hrc file to add support for AHK, advanced mode.
protobasic.hrc       Modification to Colorers proto.hrc file to add support for AHK, Basic mode.
ahkAdvanced.hrc      This is the syntax highlighting file for AHK support, Advanced mode.
ahkBasic.hrc         This is the syntax highlighting file for AHK support, Basic mode
ahkPackage.xml       This is the syntax highlighting file for AHK support, used by both basic and advanced.
SyntaxTest.ahk       My AutoHotkey test script, it just shows some syntax examples.

Updated info about configuring Colorer in Eclipse.
Posted Image

Chris
  • Administrators
  • 10727 posts
  • Last active:
  • Joined: 02 Mar 2004
Thanks for posting your work. When you feel it's read to be distributed with AutoHotkey (assuming you want that), please let me know. Also, it would be ideal to eventually have some means of auto-generating the ahk.hrc file from the master syntax files (which are contained in Extras\Editors\Syntax). However, I realize that this might be a lot of work for you.

jonib
  • Members
  • 75 posts
  • Last active: Feb 18 2017 04:44 PM
  • Joined: 09 May 2006

Thanks for posting your work.

Thanks for posting your work. :D

When you feel it's read to be distributed with AutoHotkey (assuming you want that), please let me know.

I would want that when it's ready.

Also, it would be ideal to eventually have some means of auto-generating the ahk.hrc file from the master syntax files (which are contained in Extras\Editors\Syntax). However, I realize that this might be a lot of work for you.

Yes I will do that when it is finished.

Did you test it?
If you don't want to install Eclipse to test there is a colorer.exe in Library sources that shows syntax highlighting and can even be used to generate HTML with highlighting.

Chris
  • Administrators
  • 10727 posts
  • Last active:
  • Joined: 02 Mar 2004
I haven't tested it yet. I remember someone once suggested finding means of doing syntax coloring/highlighting in the forum -- or perhaps just to publish individual scripts in HTML. Although I think at least one editor can already do this (perhaps PSPad), it would be nice to have a lighter-weight solution.

PhiLho
  • Moderators
  • 6850 posts
  • Last active: Jan 02 2012 10:09 PM
  • Joined: 27 Dec 2005
Well, I saw in the phpBB list of modules a special BBCode tag to do syntax highlighting for PHP code. It is easy, as PHP has a built-in function to generate such HTML code.
But perhaps someday I might hack this module to generate AutoHotkey syntax colored HTML. If you are willing to install such module, of course.
And currently, that's just vaporware, I have to finish my Scintilla lexer first (which goes a major refactoring!).
Posted Image vPhiLho := RegExReplace("Philippe Lhoste", "^(\w{3})\w*\s+\b(\w{3})\w*$", "$1$2")

jonib
  • Members
  • 75 posts
  • Last active: Feb 18 2017 04:44 PM
  • Joined: 09 May 2006
Hi PhiLho

Do you have any more syntax testing scripts like you posted here?

PhiLho
  • Moderators
  • 6850 posts
  • Last active: Jan 02 2012 10:09 PM
  • Joined: 27 Dec 2005
Some, but of course, a good test is to save some complex scripts from the Scripts & Functions section, and look at them.
I also like to use my own _Permanent.ahk file.

LexAHK.ahk
/*
Sample file to show off syntax highlighting of AutoHotkey scripts within SciTE
*/
#SingleInstance Force		; Directive
SetTitleMatchMode 2		; Command

Start:	; Label

abc := 11 * (180 / 3.14159265358979) + 0xBEEFF00D	; Numbers and expressions
boo := "Version`n" . A_AhkVersion "!"	; Expression string, escape char, std variable
oob = Version`n%A_AhkVersion%!	; PLain string, esc, variable reference
cot := "Unterminated string
doom =
( LTrim Join
	Continuation`f
	Section for %A_AhkVersion%
)
Gui +LastFound	; Special parameter
guiID := WinExist()	; Standard function

If abc + boo = %cot	; Unterminated variable ref
{
	Foo(abc, boo%A_Now%)	; Function call, identifier (boo), std variable ref.
}
Else	; Flow of control kw
{
	; Command, (default), escape, std var ref, key name, number, regular var ref
	Send Year is `t%A_YYYY% {Tab 2} %cot% {Enter}{Incorrect}
	Goto Start
}

Escape::ExitApp	; Hotkey definition
:*:²k::[color=green][/color]	; Hotstring definition
a::z	; Remapping
SyntaxAmbiguity.ahk
/* Some strange constructs that must compile and work,
and must be correctly highlighted!
*/

Goto !Code/Ambiguity?

;### Var ambiguity

77 = 7.7	; Legal but hardly usable
0xBEEF = 48000	; Not better...
BEEF = 0xBEEF	; 48879
BEER := 0xBEEF

MsgBox 77=%77%`n0xBEEF=%0xBEEF%`nBEEF=%BEEF%`nBEER=%BEER%
result = Result:

; Variables starting with a number are not usable in expressions...
if (77 = 7.7)
	result = %result%`n77 = 11
if (0xBEEF = 0xBB80)
	result = %result%`n0xBEEF = 0xBB80
if (0xBEEF = 48000)
	result = %result%`n0xBEEF = 48000
if (0xBEEF = 48879)	;*
	result = %result%`n0xBEEF = 48879

if (BEEF = 0xBEEF)	;*
	result = %result%`nBEEF = 0xBEEF
if (BEEF = 48000)
	result = %result%`nBEEF = 48000
if (BEEF = 48879)	;*
	result = %result%`nBEEF = 48879

if (BEER = 0xBEEF)	;*
	result = %result%`nBEER = 0xBEEF
if (BEER = 48000)
	result = %result%`nBEER = 48000
if (BEER = 48879)	;*
	result = %result%`nBEER = 48879

MsgBox %result%

!Code/Ambiguity?:
;### Code ambiguity and other constructs hard to highlight

Send = If (foo = bar) ; Not a command, nor a test
NumPad0 = 0 ; Not the start of a hotkey
b := true
If (F(5, 4 + 1)	; Not the end of the If expression
		or b)
	Gosub MsgBox
ExitApp

NumPad0::
MsgBox: ; Not a command...
	MsgBox : %Send% ; Not a label
	MsgBox (foo)	; Not a function call
	Send :: NumPad0 ; Not a hotkey
	If !b
		Return ; Folding of label goes to next return, not this one!
	Send:=42 ; Not a label
	MsgBox => Result ; Not a MsgBox command!
	If b = (	; Not the start of an expression
		F(5, 6)
Return

F(a
, b)	; Not a function call!
; Legal

{
	%a% := "foo"
	x%b% = bar
	If ((a)&&(b))
		x:=a
	If (a =
(
x
)
and b)
		x -= a / 2
	Return a = b
}
SyntaxErrors.ahk
Bad Label:
invalid variable := 1
x := unknown -* operator
x := bad + / expression
x := illegal, syntax
a =
(
continuation
section
            ) ouch!
)

Posted Image vPhiLho := RegExReplace("Philippe Lhoste", "^(\w{3})\w*\s+\b(\w{3})\w*$", "$1$2")

jonib
  • Members
  • 75 posts
  • Last active: Feb 18 2017 04:44 PM
  • Joined: 09 May 2006
Thanks PhiLho.

Just what I wanted.

But I gave up after looking at SyntaxAmbiguity.ahk :shock: sorry no more updates.
Just kidding :D

PhiLho
  • Moderators
  • 6850 posts
  • Last active: Jan 02 2012 10:09 PM
  • Joined: 27 Dec 2005
Note that my lexer is still far from handling all ambiguities correctly, and probably never will anyway: to do so, you will have to rewrite completely the parser from AHK itself! :-)
Posted Image vPhiLho := RegExReplace("Philippe Lhoste", "^(\w{3})\w*\s+\b(\w{3})\w*$", "$1$2")

jonib
  • Members
  • 75 posts
  • Last active: Feb 18 2017 04:44 PM
  • Joined: 09 May 2006

Note that my lexer is still far from handling all ambiguities correctly, and probably never will anyway: to do so, you will have to rewrite completely the parser from AHK itself! :-)

Some tweaks and this is the result SyntaxAmbiguity.htm.
Nice brain teaser :twisted:

jonib
  • Members
  • 75 posts
  • Last active: Feb 18 2017 04:44 PM
  • Joined: 09 May 2006
I'm going to rebuild my syntax highlighting and I'm going to use AutohotKeys master syntax files in the installer.

Should I have different highlighting for the built in functions or the same as user defined functions?

Has anybody tested it?

PhiLho
  • Moderators
  • 6850 posts
  • Last active: Jan 02 2012 10:09 PM
  • Joined: 27 Dec 2005
Not tested...
I use a different highlight for AutoHotkey functions, this is also a help to get the syntax right. At least, I often do that with built-in variables: A_LoopLongFilePath, mmm, no special color, A_LoopFileLongPath, right color, gotcha! :-)
Posted Image vPhiLho := RegExReplace("Philippe Lhoste", "^(\w{3})\w*\s+\b(\w{3})\w*$", "$1$2")

jonib
  • Members
  • 75 posts
  • Last active: Feb 18 2017 04:44 PM
  • Joined: 09 May 2006
Yes seems most useful way to do it.

I was just thinking that other highlighters don't seem to think built in functions are special.

PhiLho
  • Moderators
  • 6850 posts
  • Last active: Jan 02 2012 10:09 PM
  • Joined: 27 Dec 2005
Oh, I don't know for your highligther, but that's the way it is done for most lexers of Scintilla.
Now, it depends on the language, the function list of Java or PHP isn't included by default, too big...
Come to think of it, C lexer has no style for built-in functions. But C hasn't really built-in functions, except those defined by the Ansi norm.
Lua as such lists, grouped by categories. So is POV-Ray. Well, bad examples, I worked on these... Mmm, indeed, most languages don't have a list of functions, perhaps because of their number.
Nsis lexer has a list of functions. It seems such list is useful for small languages.
Posted Image vPhiLho := RegExReplace("Philippe Lhoste", "^(\w{3})\w*\s+\b(\w{3})\w*$", "$1$2")

RobOtter
  • Members
  • 133 posts
  • Last active: Jul 24 2014 11:29 AM
  • Joined: 30 Jan 2005
Long time passed by...

jonib, PhiLho, anyone of you still (or again) working on this?
@jonib: Could you provide a working link to your AHKColorer.zip? The link given here is somewhat outdated... :-(

Best regards,
Rob