Attached is an alternative lexer for AutoHotkey files, more fine-grained.
Install: just replace \cudatext\data\lexlib\AutoHotkey.lcf and .cuda-lexmap (after saving them in another dir) with the ones in the zip. Relaunch cuda. It is possible to keep both, then as renamed AutoHotkeyPhi.lcf, but you'll have to choose for each new file (lexer_detecter may help)...
No style mapping for the moment (edit AutoHotkey.lcf at the beginning).
It uses "//" comments and ";" is thus an invalid character but this is easy to change. There is no way to detect "#CommentFlag //" at the BoF and to switch to the relevant version (?). A "///" makes the comment more visible (bold, darker).
As in the last lexer.AutoHotkey version, the end marker "*/" is allowed at EoL but this is invalid for AHK1. It might need some more changes for AHK2.
NB: still a work in progress.
lexer.AutoHotkeyPhi
lexer.AutoHotkeyPhi
- Attachments
-
- lexer.AutoHotkeyPhi.zip
- (13.25 KiB) Downloaded 4 times
-
main Alexey
- Posts: 2907
- Joined: 25.08.2021 18:15
Re: lexer.AutoHotkeyPhi
Maybe it is useful for AHK users, I don't know AHK and cannot tell. Also, AHK users and you can give me wishes for my current AHK lexer.
Re: lexer.AutoHotkeyPhi
Well, I started with your lexer and added features for many years, quite slowly. There is no specification and no manual as that was done sporadically along the needs and wishes.
I had one idea (a minor wish) : implementing some kind of #if with variables, so that you don't have so many lexers for many variations of a language. The x first lines of the file could define variables like LC=0 (line comment ';') or 1 (line comment '//'), or AHKV=1 or 2 (AutoHotkey major version).
Then, some sections could include conditionals, like in:
item
DisplayName = 'eol Comment'
StyleName = 'Comment'
StatesRemove = 65535
TokenType = 14
#IF LC
Expression = '(\/\/[^\r\n]*)?(\r\n|\r|\n)^'
#ELSE
Expression = '(;[^\r\n]*)?(\r\n|\r|\n)^'
#ENDIF
ColumnFrom = 0
ColumnTo = 0
end
item
DisplayName = 'Comment multiline'
StyleName = 'Comment'
TokenType = 1
#IF AHKV=1
Expression =
'# =Comment2 ; block from /* (at line start) to */ (at line start)' +
#13#10'(?s)^\s*/\*.*?(^\s*\*/|\Z)'
#ELSE
Expression =
'# =Comment2 ; block from /* (at line start) to */ (at line start' +
' or line end)'#13#10'(?s)^\s*/\*.*?(\*/$|^\s*\*/|\Z)'
Expression = '(;[^\r\n]*)?(\r\n|\r|\n)^'
#ENDIF
ColumnFrom = 0
ColumnTo = 0
end
This could be specified in a preliminary section:
AnalyzerSpecifications
DeclarationLines=5
LC=0
LC=1 ::: ^#CommentFlag //
AHKV=1
AHKV=2 ::: ^#\s*AHK version=2
AHKV=2 ::: ^//\s*AHK version=2
A more concise syntax would need still more work... e.g. string variables or a "? :" operator...
I had one idea (a minor wish) : implementing some kind of #if with variables, so that you don't have so many lexers for many variations of a language. The x first lines of the file could define variables like LC=0 (line comment ';') or 1 (line comment '//'), or AHKV=1 or 2 (AutoHotkey major version).
Then, some sections could include conditionals, like in:
item
DisplayName = 'eol Comment'
StyleName = 'Comment'
StatesRemove = 65535
TokenType = 14
#IF LC
Expression = '(\/\/[^\r\n]*)?(\r\n|\r|\n)^'
#ELSE
Expression = '(;[^\r\n]*)?(\r\n|\r|\n)^'
#ENDIF
ColumnFrom = 0
ColumnTo = 0
end
item
DisplayName = 'Comment multiline'
StyleName = 'Comment'
TokenType = 1
#IF AHKV=1
Expression =
'# =Comment2 ; block from /* (at line start) to */ (at line start)' +
#13#10'(?s)^\s*/\*.*?(^\s*\*/|\Z)'
#ELSE
Expression =
'# =Comment2 ; block from /* (at line start) to */ (at line start' +
' or line end)'#13#10'(?s)^\s*/\*.*?(\*/$|^\s*\*/|\Z)'
Expression = '(;[^\r\n]*)?(\r\n|\r|\n)^'
#ENDIF
ColumnFrom = 0
ColumnTo = 0
end
This could be specified in a preliminary section:
AnalyzerSpecifications
DeclarationLines=5
LC=0
LC=1 ::: ^#CommentFlag //
AHKV=1
AHKV=2 ::: ^#\s*AHK version=2
AHKV=2 ::: ^//\s*AHK version=2
A more concise syntax would need still more work... e.g. string variables or a "? :" operator...
-
main Alexey
- Posts: 2907
- Joined: 25.08.2021 18:15
Re: lexer.AutoHotkeyPhi
Variables cannot be added: main editing of LCF file is done via SynWrite GUI; also LCF file loader code is based on Lazarus streaming code and it cannot handle 'variables'.
I think AHK 1 and AHK 2 - can be different lexers. Only 2 major versions of AHK exist, per Qwen AI: 1.0 + 1.1 and 2. Is my usual AHK lexer for AHK 1 ? Is your lexer for AHK 2?
I think AHK 1 and AHK 2 - can be different lexers. Only 2 major versions of AHK exist, per Qwen AI: 1.0 + 1.1 and 2. Is my usual AHK lexer for AHK 1 ? Is your lexer for AHK 2?
Re: lexer.AutoHotkeyPhi
Yes that would need some work with SynWrite; the simplest way, not so simple, might be to add a dialog for variables and to edit the syntax given this set of variables, the non relevant parts being ignored and left as is.
However, Cuda could manage the vars and generate and feed Lazarus streaming code with an adequate AutoHotkey_LC1_AHKV1.lcf (e.g.).
I use it with AHK1 but the last version in plug-ins, at least, introduced a mod for AHK2, which allows "*/" at eol, wich AHK1 doesn't. Thus my conditional item DisplayName = 'Comment multiline'.
However, Cuda could manage the vars and generate and feed Lazarus streaming code with an adequate AutoHotkey_LC1_AHKV1.lcf (e.g.).
I use it with AHK1 but the last version in plug-ins, at least, introduced a mod for AHK2, which allows "*/" at eol, wich AHK1 doesn't. Thus my conditional item DisplayName = 'Comment multiline'.
-
main Alexey
- Posts: 2907
- Joined: 25.08.2021 18:15
Re: lexer.AutoHotkeyPhi
to add 'variables' it will need lot of work and add generating of temp-LCF-files. I totally dislike the idea. sorry.
so we have usual AHK lexer for AHK2 and your lexer for AHK1 ? then you can rename yours one to 'AutoHotkey 1' for example.
so we have usual AHK lexer for AHK2 and your lexer for AHK1 ? then you can rename yours one to 'AutoHotkey 1' for example.
Re: lexer.AutoHotkeyPhi
I agree... That was a "minor wish"...
The way AutoHotkey.lcfx => AutoHotkey_LC1_AHKV1.lcf needs only a C preprocessor.
There is perhaps somewhere a C retropreprocessor that puts the modified lines (provided the changes are incremental) of AutoHotkey_LC1_AHKV1.lcf back into AutoHotkey.lcfx.
The way AutoHotkey.lcfx => AutoHotkey_LC1_AHKV1.lcf needs only a C preprocessor.
There is perhaps somewhere a C retropreprocessor that puts the modified lines (provided the changes are incremental) of AutoHotkey_LC1_AHKV1.lcf back into AutoHotkey.lcfx.