AutoHotkey Community

It is currently May 27th, 2012, 11:49 am

All times are UTC [ DST ]




Post new topic Reply to topic  [ 10 posts ] 
Author Message
PostPosted: August 6th, 2010, 3:22 pm 
Offline
User avatar

Joined: August 11th, 2004, 1:47 am
Posts: 5347
Location: UK
Found this interesting bug while working on IronAHK (ab82004c):

Code:
/* ; comment out this line
MsgBox, first
*/ MsgBox, second

_________________
GitHubScriptsIronAHK Contact by email not private message.


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: August 6th, 2010, 5:14 pm 
Offline

Joined: October 17th, 2006, 4:15 pm
Posts: 7503
Location: Australia
Quote:
Method #1: A line that starts with "and", "or", ||, &&, a comma, or a period is automatically merged with the line directly above it (in v1.0.46+, the same is true for all other expression operators except ++ and --).
Source: AutoHotkey Scripts and Macros
Rather than "expression operators", it's really any character or character sequence which forms an operator, whether or not it's actually part of an expression. Continuation sections/lines are handled at a much earlier stage than expressions, and the logic used only excludes hotkeys and hotstrings (such as ,::MsgBox). I'd say it's by design, rather than an outright bug.
Code:
MsgBox, first
*** MsgBox, second
MsgBox, first
/// MsgBox, second


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: August 7th, 2010, 1:59 pm 
Offline
User avatar

Joined: August 11th, 2004, 1:47 am
Posts: 5347
Location: UK
A single line comment character (;) does not form part of a continuation section so it would be more intuitive by design to also ignore */ to give comments precedence above all else.

_________________
GitHubScriptsIronAHK Contact by email not private message.


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: August 7th, 2010, 2:51 pm 
Offline
User avatar

Joined: May 5th, 2007, 7:24 pm
Posts: 1240
Location: Seville, Spain
Reminds me of this:
Code:
; gives syntax error
MsgBox % "Hello ; World!"

_________________
fincs
Highly recommended: AutoHotkey_L (see why) (all my code snippets require it)
Formal request to polyethene - I support the unity of the AutoHotkey community
Get SciTE4AutoHotkey v3.0.00 (Release Candidate)
[My project list]


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: August 7th, 2010, 5:22 pm 
Offline

Joined: February 19th, 2010, 8:07 pm
Posts: 615
fincs wrote:
Reminds me of this:
Code:
; gives syntax error
MsgBox % "Hello ; World!"


well, you are commenting out the closing quote so you are trying to pass
Code:
 MsgBox % "Hello


which will always give a syntax error.


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: August 7th, 2010, 11:10 pm 
Offline

Joined: March 26th, 2010, 5:55 pm
Posts: 129
I would have expected */ to generate a syntax error if there is no matching /*. It should not be ignored, it should generate a syntax error.

Treating it as a continuation "by design" is really a stretch. The sequence */ should be treated as a single token, not as two operators. If the parser only feels like looking ahead one character then that's simply a reason for the bug, not a justification for a design.

And ; within a string should not begin a comment. It should be treated as a literal semicolon. I'd call that a bug too. Comment characters and sequences should lose their special function within string literals, just like they do in every other language.

I believe that to defend existing behavior as "correct" through mental contortions does a disservice to AHK, because it inhibits opportunities for improvement.


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: August 8th, 2010, 12:04 am 
Offline
User avatar

Joined: August 11th, 2004, 1:47 am
Posts: 5347
Location: UK
Jamie wrote:
I would have expected */ to generate a syntax error if there is no matching /*. It should not be ignored, it should generate a syntax error.

I disagree. By definition anything in code that is a comment should be ignored. It also serves a practical purpose - you could comment out the /* line itself if you need to quickly enable a section of code without having to look for the closing */.

Jamie wrote:
The sequence */ should be treated as a single token, not as two operators. If the parser only feels like looking ahead one character then that's simply a reason for the bug, not a justification for a design.

Currently IronAHK also scans the first non-whitespace character for a continuation section with the exception of */. Perhaps for added clarity the documentation could be reworded to "the same is true for all other expression operator symbols".

Jamie wrote:
And ; within a string should not begin a comment. It should be treated as a literal semicolon. I'd call that a bug too.

Yes, while it contradicts with my earlier statement that comments should take precedence IronAHK defers comment scanning to allow ; in string literals for expressions. Every other language is the same, AutoHotkey should be no different.

_________________
GitHubScriptsIronAHK Contact by email not private message.


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: August 8th, 2010, 5:22 am 
Offline

Joined: October 17th, 2006, 4:15 pm
Posts: 7503
Location: Australia
Sorry, I hadn't properly explained my motivation:

Continuation lines are processed at an early stage, along with continuation sections and comments. This stage builds a line of code from one or more physical lines, preparing it for the later stages which handle hotkeys, function declarations, commands, expressions, etc. It seems to me that the implementation can either be complicated, duplicating much of the work done by the later stages in order to give the most consistent and sensible results; or (as it is now) simple and fast, giving adequate results in the majority of cases.

At the point continuation lines are processed, no "tokens" exist, only strings of characters. The current parser wasn’t designed from the start with expressions in mind, as they were introduced later. Redesigning it to tokenize everything at an early stage (or the only stage) would give the best results and would give benefits in other areas, but hardly seems justified.

"Fixing" only */ is simple:
Code:
if ((*next_buf == ':' || *next_buf == '+' || *next_buf == '-') && next_buf[1] == *next_buf
   || (*next_buf == '.' || *next_buf == '?') && !IS_SPACE_OR_TAB_OR_NBSP(next_buf[1])
      && next_buf[1] != '='
   || (*next_buf == '*' && next_buf[1] == '/')
   || !strchr(CONTINUATION_LINE_SYMBOLS, *next_buf)) // Line doesn't start with a continuation char.
   break; // Leave is_continuation_line set to its default of false.

Quote:
And ; within a string should not begin a comment. It should be treated as a literal semicolon.
The documentation only states that the comment flag must have a space or tab to its left - there's nothing excluding it as a comment flag in a literal string. If you were to say "treating the comment flag as part of the string would be more useful and intuitive", I'd agree; but I disagree with your statement in principle (-> "should").
Code:
MsgBox % "Hello ; This line begins the string
        , World!" ; and this line ends it.
MsgBox Hello ; This line begins the string
     , World! ; and this line ends it.

Jamie wrote:
... just like they do in every other language.
polyethene wrote:
Every other language is the same, AutoHotkey should be no different.
I tend to ignore such suggestions when they aren't backed up with any actual reasoning, like why it is that way in other languages. If the reason is obvious (as for "foo ; bar"), there is no need to mention other languages and no added value in doing so. Similarity to any or all other languages is not a goal of AutoHotkey.

I understand that sometimes similarity to other languages can be a benefit, but the similarity itself isn't a reason - the users' familiarity with it is.
Jamie wrote:
I believe that to defend existing behavior as "correct" through mental contortions does a disservice to AHK, because it inhibits opportunities for improvement.
Wasting time developing solutions for inconsequential "problems" inhibits opportunities for improvement where it actually matters.
polyethene wrote:
[Ignoring unpaired */] also serves a practical purpose
I agree.
Quote:
Perhaps for added clarity the documentation could be reworded to "the same is true for all other expression operator symbols".
"Symbol" isn't perfectly accurate, unfortunately.
Code:
MsgBox This is part of the message...
       and so is this.


Edit: Just because I like wasting time ;), making the following change to script.cpp is sufficient for causing */ at the beginning of a line to be entirely ignored if there wasn't a /*.
Code:
if (in_comment_section)
{

    if (!_tcsncmp(next_buf, _T("*/"), 2))
    {
        ...
    }
    else if (in_comment_section)
        continue;
}
else
if (!in_continuation_section && !_tcsncmp(next_buf, _T("/*"), 2))
{
    in_comment_section = true;
    continue;
}
Does IronAhk ignore unpaired */?


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: August 9th, 2010, 5:47 am 
Offline

Joined: March 26th, 2010, 5:55 pm
Posts: 129
Just because something is a bug does not mean that it has to be fixed. I'm fine with there being bugs that are decided to be not worth fixing.

But to me there is quite a difference between 'not worth fixing' and 'by design', even if they lead to the same outcome.

Maybe one day I will finally write that lint tool I keep talking about. Then people like me can stop complaining about things that should be illegal, but aren't. And by "should" I mean a personal judgment call, not a universal principle.


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: August 9th, 2010, 10:46 am 
Offline
User avatar

Joined: August 11th, 2004, 1:47 am
Posts: 5347
Location: UK
Lexikos wrote:
At the point continuation lines are processed, no "tokens" exist, only strings of characters. The current parser wasn’t designed from the start with expressions in mind, as they were introduced later. Redesigning it to tokenize everything at an early stage (or the only stage) would give the best results and would give benefits in other areas, but hardly seems justified.

You've highlighted the fundamental problem. Many of the current design flaws and inconsistencies exist because of initial poor planning (since AutoIt 2) and failure to recognise how other programming languages were constructed to have a solid foundation for the syntax parser. Tobias (IronAHK co-developer) joked that it would be an impossibility to write ANTLR or EBNF grammar for AutoHotkey syntax, I didn't tell him he wasn't wrong. There are dozens of legacy syntax features gated by kill switches in IronAHK and I would have liked to discuss every one in a topic like this. Sadly though it seems that nobody is willing to take the responsibility for fixing AutoHotkey at its core and I have yet to see developers working in unison to move things forward. In the end we will end up with more confused users and wildly different forks/versions that have little common ground.

Lexikos wrote:
"Symbol" isn't perfectly accurate, unfortunately.

It was part of the longer sentence: Method #1: A line that starts with "and", "or", ||, &&, a comma, or a period is automatically merged with the line directly above it (in v1.0.46+, the same is true for all other expression operator symbols except ++ and --).

Lexikos wrote:
Does IronAhk ignore unpaired */?

Yes, note the commit referenced in my first post. Like ++ and -- it is not recognised as a continuation section and will be silently ignored if unpaired.

_________________
GitHubScriptsIronAHK Contact by email not private message.


Report this post
Top
 Profile  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 10 posts ] 

All times are UTC [ DST ]


Who is online

Users browsing this forum: No registered users and 17 guests


You can post new topics in this forum
You can reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Powered by phpBB® Forum Software © phpBB Group