Welcome to Doom9's Forum, THE in-place to be for everyone interested in DVD conversion.

Before you start posting please read the forum rules. By posting to this forum you agree to abide by the rules.

 

Go Back   Doom9's Forum > Capturing and Editing Video > Avisynth Development
Register FAQ Calendar Today's Posts Search

Reply
 
Thread Tools Search this Thread Display Modes
Old 21st February 2009, 07:44   #1  |  Link
AlanHK
Registered User
 
Join Date: May 2006
Posts: 237
Function + comment = error

I found that if in any function definition I have a comment after the function name and before the body, it throws an error:

Code:
AVISource("Garden.avi",false)
zz()

Function zz(clip a) # useless function
{return a}
same for
Code:
Function zz(clip a) 
# useless function
{return a}
The error is "expected "{"

Which was an unexpected error, at least for me.
AlanHK is offline   Reply With Quote
Old 21st February 2009, 10:27   #2  |  Link
tebasuna51
Moderator
 
tebasuna51's Avatar
 
Join Date: Feb 2005
Location: Spain
Posts: 6,915
You are right.
Maybe a 2.58 issue?
With 2.57 was OK.

BTW this work:

Code:
Function zz(clip a) { # useless function
return a}
__________________
BeHappy, AviSynth audio transcoder.
tebasuna51 is online now   Reply With Quote
Old 21st February 2009, 17:32   #3  |  Link
Gavino
Avisynth language lover
 
Join Date: Dec 2007
Location: Spain
Posts: 3,431
Quote:
Originally Posted by tebasuna51 View Post
Maybe a 2.58 issue?
With 2.57 was OK.
Are you sure? I tried with 2.57 and got exactly the same behaviour as 2.58.

Looks like this is a 'feature' of the tokeniser. Newlines are skipped if the next token is '{', but not when there is a comment present.

Using the new /* ... */ form of comment available in 2.58 does work, ie
Code:
Function zz(clip a) /* useless function */
{return a}
is accepted.

Last edited by Gavino; 21st February 2009 at 18:34. Reason: /*...*/ comment does work
Gavino is offline   Reply With Quote
Old 21st February 2009, 19:26   #4  |  Link
Gavino
Avisynth language lover
 
Join Date: Dec 2007
Location: Spain
Posts: 3,431
It's not clear to me if this is intended behaviour or an oversight.
However, since newlines are allowed before a '{', it seems inconsistent not to allow a comment here too.

I believe a simple fix is to change the code that handles #-comments (in Tokenizer::NextToken(), tokenizer.cpp) from
Code:
      // skip from # to end of line (comment)
      while (*pc != 0 && *pc != '\n' && *pc != '\r')
        pc++;
      break;
to
Code:
      // skip from # to end of line (comment)
      while (*pc != 0 && *pc != '\n' && *pc != '\r')
        pc++;
      if (*pc == 0) break;
      continue;
This would force the newline terminating the comment to be treated like any other newline.

As an added bonus, it would also allow a '\' continuation on the line following a comment, something not possible at the moment.
Two extensions for the price of one.
Gavino is offline   Reply With Quote
Old 7th December 2009, 01:06   #5  |  Link
Gavino
Avisynth language lover
 
Join Date: Dec 2007
Location: Spain
Posts: 3,431
Looking further at this, my suggested fix above would only be a partial solution, since it doesn't help when the comment (even a new-style one) is on a different line to the function header, eg
Code:
function zz(clip a)
/* some inane comment ... */
{ ...
A better approach is to do it in the parser rather than hacking the lexer with even more special cases, by changing the code in ScriptParser::ParseBlock() from
Code:
  if (braced)
    Expect('{');
to
Code:
  if (braced) {
    // allow newlines (and hence comments) before '{'
    while (tokenizer.IsNewline())
      tokenizer.NextToken();
    Expect('{');
  }
The code in Tokenizer::NextToken()
Code:
      } else if (*pc == '{') {
        break;
could then safely be removed. (probably! )

The revised fix no longer extends to allow a '\' continuation on the line following a comment, but I'm not sure that is desirable anyway.

Last edited by Gavino; 7th December 2009 at 01:10.
Gavino is offline   Reply With Quote
Reply


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 09:42.


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2024, vBulletin Solutions Inc.