Hi, Simon. I've been using regex's recently, so here are some thoughts;
Code: Select all
on mouseUp
# first add quotes to the values
local tString, tStart, tEnd, tMatch
put "(NOT favoriteColor = Blue) AND ((bestSound = Laughter) OR (bestSound= Dishes clattering in a distant restaurant) OR (happyToday = NO NOT AT ALL))" into tString
repeat while matchChunk(tString, "=\W*[^" & quote & "]\b([[:alnum:]\s]+)\b[^" & quote & "]\W", tStart, tEnd)
put char tStart to tEnd of tString into tMatch
put quote & tMatch & quote into char tStart to tEnd of tString
end repeat
# cheeky replacement to allow LC to evaluate the NOTs correctly
replace "(NOT" with "NOT(" in tString
# show the modified string
answer "The string is now;" & LF & tString
# try and evaluate the string
# change these values for testing the result - the real values would come from the data
local favoriteColor, bestSound, happyToday
put "Orange" into favoriteColor
put "Laughter" into bestSound
put "Yes" into happyToday
answer "Expression evaluates to " & value(tString)
end mouseUp
Firstly, I've added quotes around the values - so far so good!
Then I've adjusted the 'NOT' so that it will evaluate properly
Finally, I've defined the values that I assume would be read from a database or file, etc...
(My test values evaluate to true, you can mess about with them more to test)
This could be totally off in the wrong direction, but hopefully it helps!
(would be a lot easier if replaceText supported backreferences)