regex match for ahk syntax

Get help with using AutoHotkey and its commands and hotkeys
User avatar
Bugz000
Posts: 41
Joined: 30 Sep 2013, 10:01

regex match for ahk syntax

01 Jul 2018, 12:49

hey guys, i'm trying to use regex to find variable names/functions/labels etc in ahk code as i wish to manipulate this code using AHK
it appears one of the hardest things to do in AHK is get it to understand itself :p

currently i'm looking at finding := and whatever is before it is a variable but ofcourse, variables in AHK can be defined in various ways, which leads to the problem
likewise with function names and labels, so on
is there any regex gurus out there that could verify if this is even possible?

here's a small snippet of the code that handles finding variable names, and it does a fairly decent job but it's not thorough by any means, the input of it is A_Loopreadline

Code: Select all

Checkforvars(in)
{
	if instr(in, ":=")
		{
			o := Strsplit(in, ":=")
			Variable(o[1])
			return 1
		}
	return 0
}

variable(var)
{
	global
	Index +=1
	;index|type|LN|name
	var := regexreplace(regexreplace(var, "[^,\w]+", ""), "^\s*(\S.*\S|\S)\s*$", "$1")
	LV_Add("", index, "var", LineNumber, var, "?????")
}
Image
User avatar
Frosti
Posts: 249
Joined: 27 Oct 2017, 14:30
GitHub: Ixiko

Re: regex match for ahk syntax

01 Jul 2018, 13:28

There are much scripts that use RegEx to find function/labels and so on.
I find no RegEx that work's 100% in any case. The most common failure occurs when searching for functions. When function calls are found instead of functions.
But I think the best one you can find in here.
or Build UserAHkAPi
or Boilers try for Notepad++
or PhiLho's 2006 version of List functions (+ labels + hotstuff) in an AutoHotkey script
or use something from GoToTilla.ahk
and least but not least GoTo.ahk from Avi Aryan.


Hope I can help a little bit.
User avatar
Bugz000
Posts: 41
Joined: 30 Sep 2013, 10:01

Re: regex match for ahk syntax

01 Jul 2018, 14:00

Frosti wrote:There are much scripts that use RegEx to find function/labels and so on.
I find no RegEx that work's 100% in any case. The most common failure occurs when searching for functions. When function calls are found instead of functions.
But I think the best one you can find in here.
or Build UserAHkAPi
or Boilers try for Notepad++
or PhiLho's 2006 version of List functions (+ labels + hotstuff) in an AutoHotkey script
or use something from GoToTilla.ahk
and least but not least GoTo.ahk from Avi Aryan.


Hope I can help a little bit.


wow, spot on :D it doesn't matter if it finds function declaration or function call, so long as it finds one of them, it's variables that are the tricky one :)
Image

this works brilliantly, exactly what i need, even finds more than i want, though the question still remains about variables, i guess some vars are found in the sense of func(var,var) {} (one of the ways of creating variables without declaring it) so it clears that base up at least :)

i'll check the others out now but i'm trying to think of all the ways a var can be created

var :=
var =
var+=
func(var := )
return var?

so on

my script finds := (as first post says) Image
and it returns a decent ammount (around 170 for my particular script) but i suspect it will be missing a lot :p

so aside from := ( = is a bit trickier, += is simple enough to implement)
and local vars for each function, i'd imagine that would cover MOST bases for variables?

it doesn't have to be absolutely perfect, just as best as it can be
Image

Return to “Ask For Help”

Who is online

Users browsing this forum: DaInferno, FlizzyDuck, flyingDman, MIRKOSOFT, Urza, Wigi and 147 guests