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. |
21st February 2009, 07:44 | #1 | Link |
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} Code:
Function zz(clip a) # useless function {return a} Which was an unexpected error, at least for me. |
21st February 2009, 17:32 | #3 | Link |
Avisynth language lover
Join Date: Dec 2007
Location: Spain
Posts: 3,431
|
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} Last edited by Gavino; 21st February 2009 at 18:34. Reason: /*...*/ comment does work |
21st February 2009, 19:26 | #4 | Link |
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; Code:
// skip from # to end of line (comment) while (*pc != 0 && *pc != '\n' && *pc != '\r') pc++; if (*pc == 0) break; continue; 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. |
7th December 2009, 01:06 | #5 | Link |
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 ... */ { ... Code:
if (braced) Expect('{'); Code:
if (braced) { // allow newlines (and hence comments) before '{' while (tokenizer.IsNewline()) tokenizer.NextToken(); Expect('{'); } Code:
} else if (*pc == '{') { break; 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. |
Thread Tools | Search this Thread |
Display Modes | |
|
|