|
Wildcard script | —> JavaScript |
on <handler> <parameterList> | function <handler>(<parameterList>) { |
[ <command> | <statement> ]* | |
end <handler> | } |
<command> | |
if <expression> then | if (<expression>) { |
else | } else { |
end if | } |
return <expression> | return <expression>; |
<statement> | |
get <expression> | _.it = <expression>; |
put <expression> into <variable> | set <variable> to <expression> | _.<variable> = <expression>; |
answer <expression> | alert(<expression>); |
ask <expression> with <expression> | prompt(<expression>,<expression>); |
ask <expression> | confirm(<expression>); |
set [the] <property> of <part> to <expression> | <part>.<property> = <expression>; |
send <message> <expressionList> to <part> | Script.Send(<part>,<message>,<expressionList>); |
<message> <expressionList> | (this.<message>)(<expressionList>); |
<expression> | |
<expression> or <expression> | boolean(<expression>) || boolean(<expression>) |
<expression> and <expression> | boolean(<expression>) && boolean(<expression>) |
<expression> [ is | equals | = ]! <expression> | <expression> == <expression> |
| <expression> [ is not | ≠ | <> ]! <expression> | <expression> != <expression> |
<expression> [ < | is less than ]! <expression> | number(<expression>) < number(<expression>) |
| <expression> [ > | is more than ]! <expression> | number(<expression>) > number(<expression>) |
| <expression> [ <= | is less [than] or equal to ]! <expression> | number(<expression>) <= number(<expression>) |
| <expression> [ >= | is more [than] or equal to ]! <expression> | number(<expression>) >= number(<expression>) |
<expression> & <expression> | Array(<expression>,<expression>).join('') |
| <expression> && <expression> | Array(<expression>,<expression>).join(' ') |
<expression> [ plus | + ]! <expression> | number(<expression>)+number(<expression>) |
| <expression> [ minus | - ]! <expression> | number(<expression>)-number(<expression>) |
<expression> [ times | * ]! <expression> | number(<expression>)*number(<expression>) |
| <expression> [ divided by | / ]! <expression> | number(<expression>)/number(<expression>) |
| <expression> div <expression> | Math.floor(number(<expression>)/number(<expression>)) |
| <expression> mod <expression> | number(<expression>) % number(<expression>) |
<factor>^<expression> | Math.pow(<factor>, <expression>) |
<factor> | |
<factor> | |
<number> | <string> | true | false | |
<message>(<expressionList>) | this.<message>(<expressionList>) |
[the] <identifier> of <part> | <part>.<identifier> |
[the] <message> of <factor> | this.<message>(<factor>) |
the <identifier> | wildcard.<identifier> | |
my <identifier> | this.me.<identifier> |
me | this.me |
comma | ',' |
return | '\n' |
space | ' ' |
empty | '' |
-<factor> | |
not <factor> | !boolean(<factor>) |
<variable> | _.<variable> |
(<expression>) | (<expression>) |
<part> | |
wildcard | |
me | this.me |
this stack | (this.me.closest('stack-part') || currentStack()) |
this card | (this.me.closest('card-part') || currentStack().querySelector('card-part.current')) |
Where |
<expressionList> = [ <expression> [, <expression> ]* ] |
<parameterList> = [ <parameter> [, <parameter> ]* ] |
<handler> | <message> | <variable> | <property> = <identifier> |
<identifier> | /[A-Z][A-Z\d]*/i |
<number> | /[\d]+([.][\d]+)?/ |
<string> | /"[^"]*"/ |
Wildcard script
|
-- these handlers are available to all Wildcard scripts.
-- When WildCard gets the message called beep, this handler acts
-- To send the 'beep' message, you type 'beep' in the message box
on beep
perform_system_beep();
end beep
-- Handlers can accept parameters and return a value
on double n
return n plus n
end double
-- You can use JavaScript
on sqrt n
return Math.sqrt(n);
end sqrt
on random n
return 1+Math.floor(Math.random()*n);
end random
-- Send messages from Javascript with wildcard.do('beep') or just wildcard.Beep();
on do lineOfScript
put "on run" & return & lineOfScript & return & "end run" into handler
return new Script(null, _.handler).run();
end do
|