Log in

View Full Version : Script parsing bug?


wonkey_monkey
25th July 2015, 23:08
I've found some inconsistencies happening with Avisynth 2.6.0 when I accidentally miss out a . between keywords.

I was expecting none of the below to work, since I have omitted a . between the crop and the info, but they all work with inconsistent results:


version.crop(0,0,0,0)info # works as if I had typed .info



return version.crop(0,0,0,0)info # returns version WITHOUT info



q=version.crop(0,0,0,0)info # error: 'I don't know what "info" means'



blankclip
q=version.crop(0,0,0,0)info # applies info to the implicit last blankclip, but not to q


EDIT: All of the above are explained if the parser is imagining an implicit newline between the crop(...) and the info. Maybe that's what was intended, though I'd have thought an error in all cases would be more helpful.

raffriff42
25th July 2015, 23:52
http://avisynth.nl/index.php/GrammarAll basic AviSynth scripting statements have one of these forms:

variable_name = expression
expression
return expression

(Two higher-level constructs also exist - the function declaration and the try..catch statement.)
...
As a shorthand, a bare expression as the final statement in a script (or script block) is treated as if the keyword return was present.
so version.crop(0,0,0,0)info
is equivalent to
Last=version.crop(0,0,0,0) # (1. variable_name = expression)
Last.Info # (2. expression)
return Last # (implied)
(adding implicit Last and return)

and return version.crop(0,0,0,0)info
is equivalent to
return version.crop(0,0,0,0) # (3. return expression )
(Info is simply ignored here)

As you guessed, newlines are not required to terminate a statement, which I find makes the code harder to read, but oh well.

continuing, q=version.crop(0,0,0,0)info # error: 'I don't know what "info" means'
is equivalent to
q=version.crop(0,0,0,0) # (1. variable_name = expression)
???.Info # (????)
(missing Last argument to Info) (shouldn't the error message be "invalid argument to function Info" then?)

and blankclip
q=version.crop(0,0,0,0)info
is equivalent to
Last=blankclip # (1. variable_name = expression)
q=version.crop(0,0,0,0) # (1. variable_name = expression)
Last=Last.info # (2. expression)
return Last # (implied)

((Gavino? What have I missed?))

Gavino
26th July 2015, 09:53
(missing Last argument to Info) (shouldn't the error message be "invalid argument to function Info" then?)
Because there are no parentheses after "info", and there is no valid implicit function argument, it is treated as a variable here, hence the error message.
q=version.crop(0,0,0,0)info() would produce "invalid argument ..."

On the subject of statement separators, see this thread.