/
celluloid.java.stg
212 lines (183 loc) · 5.23 KB
/
celluloid.java.stg
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
group jcelluloid;
program(
events, constraints,
devices, predicates,
functions, code) ::=
<<
package org.celluloidlang.program;
import java.io.File;
import java.net.MalformedURLException;
import javax.media.Manager;
import org.celluloidlang.core.*;
import org.celluloidlang.devices.*;
import org.celluloidlang.reactive.*;
import org.celluloidlang.announcment.*;
import org.celluloidlang.constraints.buildtin.*;
import org.celluloidlang.constraints.defined.*;
<constraints:{ constraint | <constraint>}; separator="\r\n">
<devices:{ device | <device> }; separator="\r\n">
public class CelluloidProgram {
<events:{ event | <event> }; separator="\r\n">
<functions:{ function | <function> }; separator="\r\n">
<predicates:{ predicate | <predicates> }; separator="\r\n">
public static void main(String[] args) {
/*
* This is the one and only global timeline.
* REQUIRED: global timeline is required, see the bottom
* for the details
*/
Timeline globalTimeline = new Timeline();
// REQUIRED: Need this set to display video
Manager.setHint(Manager.LIGHTWEIGHT_RENDERER, true);
try {
<code:{ code | <code>}; separator="\r\n">
/*
* EXECUTION BEGINS HERE
*/
globalTimeline.play();
} catch (MalformedURLException e) { System.err.println(e); return; }
}
}
>>
announcementDefinition() ::= ""
eventDefinition(name) ::= "private String <name>_event = \"<name>\";"
constraintDefinition(
name, require,
requires, block) ::=
<<
interface <name> <requires> {
<block>
}
>>
deviceDefinition(name, accept, accepts, block) ::=
<<
class <name> extends JMF <accept> <accepts> {
<block>
}
>>
functionHeader(name, args) ::= "<name>(<args>);"
functionDefinition(name, args, block) ::=
<<
public void <name> (<args>) {
<block>
}
>>
predicateHeader(name, args) ::= "public bool <name> (<args>);"
predicateDefinition(name, args, block) ::=
<<
public boolean <name> (<args>) {
<block>
}
>>
predicateBlock(statements, returns) ::=
<<
<statements:{ statement | <statement>}; separator="\r\n">
return <returns>;
>>
ifStatement(exp, block) ::=
<<
if (<exp>)
<block>
>>
ifBlock(block, elifStmt, elseStmt) ::=
<<
{
<block>
}
<elifStmt>
<elseStmt>
>>
elseIfStatement(exp, block) ::=
<<
else if (<exp>)
{
<block>
}
>>
elseStatement(block) ::=
<<
else
{
<block>
}
>>
whenStatement(with, name, event, lblock) ::=
<<
<with>.addEventFunction(<name>, "<event>",
<lblock>
);
>>
everyStatement(with, name, event, time, lblock) ::=
<<
<with>.addEveryFunction(
new EveryFunction(new ReactiveNumber(<time>), <lblock>
)
>>
functionPredicateCall(name, args) ::= "<name>(<args>)"
constraintFunctionCall(
with, target,
type, function,
time, args) ::=
<<
<with>.addConstraintFunction(new ConstraintFunction(<target>, new ReactiveNumber(<time>)) {
public void execute() {
((<type>) input).<function>(<args.st>);
}
);
>>
eventFunctionCall(with, function, name, type) ::=
<<
new EventFunction(<name>) {
public void execute() {
((<type>) input).<function>();
}
}
>>
everyFunctionCall(function, name, type, target) ::=
<< <target>, <name>) {
public void execute() {
if(evals[0].isPlaying())
((<type>) input).<function>();
}
>>
outputConstraintFunctionCall(
with, target,
type, function,
time, args) ::=
<<
globalTimeline.addConstraintFunction(
new OutputConstraintFunction(
<target>,
<with>,
new ReactiveNumber(<time>)) {
public void execute() {
((<type>) input).attachOutput(output);
}
}
);
globalTimeline.addConstraintFunction(new ConstraintFunction(<target>, new ReactiveNumber(<time>)) {
public void execute() {
((<type>) input).<function>(<args>);
}
});
>>
passThrough(text) ::= "<text>"
idList(ids) ::= "<ids:{ id | <id.text> }; separator=\", \">"
variableList(vars) ::= "<vars:{ var | <var> }; separator=\", \">"
expressionList(exps) ::= "<exps:{ exp | <exp> }; separator=\", \">"
statementList(statements) ::=
<<
<statements:{ statement | <statement>}; separator="\r\n">
>>
variableArgument(type, name) ::= "<type> <name>"
timelineArgument(name) ::= "Timeline <name>"
outputDeclaration(type, name, args) ::= "<type> <name> = new <type>(\"Celluloid Output\", 1024, 768);"
jmfDeviceDeclaration(type, name, args) ::= "<type> <name> = new <type>(new File(<args>).toURI().toURL());"
deviceDeclaration(type, name, args) ::= "<type> <name> = new <type>(<args>);"
variableDeclaration(type, name, init) ::= "<type> <name> <init>;"
timelineDeclaration(name) ::= "Timeline <name> = new Timeline();"
initializer(exp) ::= " = <exp>"
expressionLine(lhand,op,rhand) ::= "<lhand> <op> <rhand>;"
expression(lhand,op,rhand) ::= "<lhand> <op> <rhand>"
simpleExpression(lhand) ::= "<lhand>"
primaryExpression ::= ""