Official syntax definition anywhere?

Discuss the future of the AutoHotkey language
User avatar
Curdflappers
Posts: 11
Joined: 13 Nov 2020, 03:18
Contact:

Official syntax definition anywhere?

11 Jun 2022, 00:06

I'm new to AutoHotkey, but not programming in general. I'm also writing a program that aims to format AHK files, but I need to know how to parse the language syntax in order to do this. A quick search through the codebase didn't help much, but I'm very new to C++.

Does anyone know where I can find the syntax definition for all the features of AHK? Either in the source code or in some documentation file? I'm looking for something like the Java declaration: https://docs.oracle.com/javase/specs/jls/se11/html/jls-19.html, but it doesn't have to be that fancy.
BoBo
Posts: 6564
Joined: 13 May 2014, 17:15

Re: Official syntax definition anywhere?

11 Jun 2022, 00:10

@lexikos ?
User avatar
Curdflappers
Posts: 11
Joined: 13 Nov 2020, 03:18
Contact:

Re: Official syntax definition anywhere?

11 Jun 2022, 00:18

I've opened https://github.com/mark-wiemer/vscode-autohotkey-plus-plus/issues/123 to track my research, in case anyone is curious. It turns out I'm currently using one provided by someone else, but I have no way of contacting them to know where they got it or how accurate it is.
lexikos
Posts: 9583
Joined: 30 Sep 2013, 04:07
Contact:

Re: Official syntax definition anywhere?

11 Jun 2022, 04:43

You've posted in the v2 Development forum, but are you targeting v1, v2 or both?

The v1 syntax has many inconsistencies and hidden complexity. How accurate you need to be might depend on exactly what level of formatting you are looking to do.

The v2 syntax is much more straightforward.

There is no formal definition of the complete syntax for either version, only explanations scattered throughout the documentation and forum. I attempted to document the majority of it in Language (v1) and Language (v2), but it probably doesn't cover everything.

You might refer to ahk1.lua and ahk2.lua, which are LPEG-based lexers. They are probably the most accurate lexers external to AutoHotkey itself (I wrote them because there were no other accurate syntax highlighters at the time).

Gleaning the syntax from the C++ source code is probably futile, as it doesn't use any kind of sane parsing strategy. The language and parsing code started out with just commands, and various things (like expressions) have been added to the language over time. It wasn't designed from the ground up to handle the syntax we have now. Rewriting the parser is a more realistic possibility for v2+ than v1 due to the removal of many inconsistencies, but I'm not rushing into it.

What kind of formatting are you doing?
User avatar
Curdflappers
Posts: 11
Joined: 13 Nov 2020, 03:18
Contact:

Re: Official syntax definition anywhere?

11 Jun 2022, 09:51

Currently I'm supporting a VS Code extension that targets v1, but v2 seems easier to format in the short term. If I can get something working for v2, I'll likely write another parser for v1, since that'll likely be in use for a long time to come.

Thank you very much for the quick reply and the links to the lua files, they seem to be exactly what I've been looking for! You can tell I hadn't done much research yet :) I'll spend some time reading the existing docs, lua parsers, and the custom TextMate grammar I found to learn more.

Reading the C++ code was not super helpful, but I also have minimal C++ experience. I'll stick with the above resources for now :D

Ideally I'd be able to build a complete and accurate abstract syntax tree. That would be passed to a Prettier plugin that would then reformat the entire file from just the AST itself. You can see the link to my GitHub project for more details.

Thanks again :)

Return to “AutoHotkey Development”

Who is online

Users browsing this forum: Nextron and 107 guests