AutoHotkey Homepage AutoHotkey Community
Let's help each other out
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

More AHK commands in the single liine
Goto page 1, 2  Next
 
Post new topic   Reply to topic    AutoHotkey Community Forum Index -> Scripts & Functions
View previous topic :: View next topic  

Do you want an option for more AHK commands in the single line
I do
50%
 50%  [ 8 ]
I don't
50%
 50%  [ 8 ]
Total Votes : 16

Author Message
majkinetor



Joined: 24 May 2006
Posts: 3624
Location: Belgrade

PostPosted: Mon Nov 06, 2006 12:57 pm    Post subject: More AHK commands in the single liine Reply with quote

This is mini preprocesor that will allow you to use more commands in single line. This is an example script that I created just to present an idea, not as an final solution as it uses ; as delimiter (folowing bunch of languages) witch is currently used as a comment.

The rules
- put ; at the end of the command
- if space or tab are before ; it will be considered as a comment
- if ; is at the beginning of the line, it is also a comment

How to use
Execute Run.bat and select the ahk file you want to execute.

This is just a quick project some things are not handled at all, like ; in strings. If people are interested I can extend this.

Code:
;test script for mini preprocesor

x := 1; y := 2; z=0      ;initialise variables
if (x=1) { MsgBox X=%x%; x := 2 }

z := z + y + x;
MsgBox Z=%z%;

loop, %z% { MsgBox % A_INDEX }



Download zip here
Sorry for the rapidshare link, can not upload to my server from the job.

NOTE: ZIP contains uniix utility SED witch is used to parse AHK script with preprocessor given in preproc.txt. GuiBox is used for graphics in batch.
_________________


Last edited by majkinetor on Tue Dec 12, 2006 4:28 pm; edited 6 times in total
Back to top
View user's profile Send private message MSN Messenger
jonny



Joined: 13 Nov 2004
Posts: 3004
Location: Minnesota

PostPosted: Mon Nov 06, 2006 2:09 pm    Post subject: Reply with quote

I think it could work, but let's not get carried away. The semicolon has always been the comment character, and just because it's familiar to C (and C-esque language) programmers is no good reason to confuse long-time AHK users.

I propose using a two-character sequence that is both unique (that is, unlikely to appear in normal usage or strings) and syntactically clear. This would require no change in the parser, it could be handled by the preprocessor or by a subset of the preprocessor.
Back to top
View user's profile Send private message
majkinetor



Joined: 24 May 2006
Posts: 3624
Location: Belgrade

PostPosted: Mon Nov 06, 2006 2:56 pm    Post subject: Reply with quote

If you can find any other charachter that is easy to write, not currently used and not obfuscating !

If I take your advice and take for instance ## above script would look like


Code:
x := 1## y := 2##; z=0      ;initialise variables
if (x=1) { MsgBox X=%x%## x := 2 }

z := z + y + x##
MsgBox Z=%z%##

loop, %z% { MsgBox % A_INDEX }


This is somewhat better:


Code:
x := 1,, y := 2,, z=0      ;initialise variables
if (x=1) { MsgBox X=%x%,, x := 2 }

z := z + y + x,,
MsgBox Z=%z%,,

loop, %z% { MsgBox % A_INDEX }

except it is already used for blank parameters ....
_________________
Back to top
View user's profile Send private message MSN Messenger
PhiLho



Joined: 27 Dec 2005
Posts: 6721
Location: France (near Paris)

PostPosted: Mon Nov 06, 2006 4:33 pm    Post subject: Reply with quote

MsgBox % A_Index;
is probably OK.
MsgBox X=%x%; x := 2 }
or
MsgBox Z=%z%;
is bad... At least ambiguous. I expect everything up to the end of the line to be part of the message... Hey, semi-colon without space before is normal English typography, you will find it in many sentences that can be in a MsgBox...
So I stick to my idea of keeping sentence delimiters to expressions.
_________________
vPhiLho := RegExReplace("Philippe Lhoste", "^(\w{3})\w*\s+\b(\w{3})\w*$", "$1$2")
Back to top
View user's profile Send private message Visit poster's website
majkinetor



Joined: 24 May 2006
Posts: 3624
Location: Belgrade

PostPosted: Mon Nov 06, 2006 4:48 pm    Post subject: Reply with quote

I wasn't thinking about this much. I just did it with ;
This is just a idea for more serious preprocesor.
I used SED now, witch is pretty criptic in its REs, but GAWK can be used for serious preprocessor - it is simple, and made for such things. I didn't use it now as it appeard that it doesn't have groups in reg exp, but I discovered that GAWK have it in gensub function.


The problems you mention with strings can be solved with escape charachter.
_________________
Back to top
View user's profile Send private message MSN Messenger
jonny



Joined: 13 Nov 2004
Posts: 3004
Location: Minnesota

PostPosted: Mon Nov 06, 2006 4:59 pm    Post subject: Reply with quote

Quote:
I propose using a two-character sequence that is both unique (that is, unlikely to appear in normal usage or strings) and syntactically clear. This would require no change in the parser, it could be handled by the preprocessor or by a subset of the preprocessor.


I was actually talking about a new commenting style here, not suggesting a different delimiter, and I meant the AHK preprocessor, not this one.
Back to top
View user's profile Send private message
Demokos



Joined: 28 Dec 2005
Posts: 84

PostPosted: Mon Nov 06, 2006 8:06 pm    Post subject: Reply with quote

May be a single character to separate the commands would be sufficent, with a directive to say what is the character, like "#CommandSeparatorChar" and a character as specific as it is possible, like #, §, $ or £...
Back to top
View user's profile Send private message
PhiLho



Joined: 27 Dec 2005
Posts: 6721
Location: France (near Paris)

PostPosted: Mon Nov 06, 2006 8:45 pm    Post subject: Reply with quote

#CommentFlag...
Should probably made obsolete in v.2.
AutoHotkey cannot use high Ascii officially, as a Russian or a Turk will see other characters.
_________________
vPhiLho := RegExReplace("Philippe Lhoste", "^(\w{3})\w*\s+\b(\w{3})\w*$", "$1$2")
Back to top
View user's profile Send private message Visit poster's website
Demokos



Joined: 28 Dec 2005
Posts: 84

PostPosted: Tue Nov 07, 2006 7:13 pm    Post subject: Reply with quote

PhiLho wrote:
Should probably made obsolete in v.2.

And when do you plan to launch this v.2 ? Very Happy Very Happy Very Happy
Back to top
View user's profile Send private message
PhiLho



Joined: 27 Dec 2005
Posts: 6721
Location: France (near Paris)

PostPosted: Tue Nov 07, 2006 8:28 pm    Post subject: Reply with quote

I only reflect Chris' thoughts on the subject, something like "I shouldn't have made these commands".
Up to know, I didn't saw it much used...
The idea is to remove unused/useless/obsolete/deprecated commands, to reduce confusion and documentation size (thus number of stuff to learn).
_________________
vPhiLho := RegExReplace("Philippe Lhoste", "^(\w{3})\w*\s+\b(\w{3})\w*$", "$1$2")
Back to top
View user's profile Send private message Visit poster's website
Demokos



Joined: 28 Dec 2005
Posts: 84

PostPosted: Tue Nov 07, 2006 8:52 pm    Post subject: Reply with quote

C'était juste une plaisanterie, Philippe !!! Apologies...
It was just a joke.
Back to top
View user's profile Send private message
PhiLho



Joined: 27 Dec 2005
Posts: 6721
Location: France (near Paris)

PostPosted: Wed Nov 08, 2006 10:49 am    Post subject: Reply with quote

I wasn't offended, but I wanted to clarify. Indeed, I want to help Chris improve AHK, at least by providing ideas, at best by giving a hand for code.
_________________
vPhiLho := RegExReplace("Philippe Lhoste", "^(\w{3})\w*\s+\b(\w{3})\w*$", "$1$2")
Back to top
View user's profile Send private message Visit poster's website
aydc



Joined: 12 Dec 2006
Posts: 14

PostPosted: Wed Dec 13, 2006 1:29 pm    Post subject: Reply with quote

I'm all for putting multiple codes to the same line.
It's ridiculous the way we're programming now:

a:=10
b:=30
c:=40
d:=a+b-c
e:=2*d

etc.etc....

Even simple scripts take thousands of lines. It should have been:

a:=10 // b:=30 // c:=40 // d:=a+b-c // e:=2*d

See how easy that is? Top languages like c++ and java can do this. Why not Autohotkey too, at least as an option.
Back to top
View user's profile Send private message
toralf



Joined: 31 Jan 2005
Posts: 3842
Location: Bremen, Germany

PostPosted: Wed Dec 13, 2006 1:52 pm    Post subject: Reply with quote

Read the manual! It is available now:
Manual on variables and expressions wrote:
Multi-statement [v1.0.46+]. Commas may be used to write multiple sub-expressions on a single line. This is most commonly used to perform multiple assignments or function calls on the same line. For example: x:=1, y+=2, ++index, func(). A line that begins with a comma (or any other operator) is automatically merged with the line above it. See also: comma performance.

_________________
Ciao
toralf
Back to top
View user's profile Send private message Send e-mail Visit poster's website
PhiLho



Joined: 27 Dec 2005
Posts: 6721
Location: France (near Paris)

PostPosted: Wed Dec 13, 2006 1:58 pm    Post subject: Reply with quote

aydc wrote:
Even simple scripts take thousands of lines.
Wow, your notion of simple is strange... Wink
I don't have so much successive expressions in my scripts, I doubt typical scripts will gain a lot (unless you are doing 3D computing in AHK...).
Note that multi-statement works only for expressions, not for commands.
_________________
vPhiLho := RegExReplace("Philippe Lhoste", "^(\w{3})\w*\s+\b(\w{3})\w*$", "$1$2")
Back to top
View user's profile Send private message Visit poster's website
Display posts from previous:   
Post new topic   Reply to topic    AutoHotkey Community Forum Index -> Scripts & Functions All times are GMT
Goto page 1, 2  Next
Page 1 of 2

 
Jump to:  
You can post new topics in this forum
You can reply to topics in this forum


Powered by phpBB © 2001, 2005 phpBB Group