File: syntax.bs

package info (click to toggle)
storm-lang 0.7.4-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 52,004 kB
  • sloc: ansic: 261,462; cpp: 140,405; sh: 14,891; perl: 9,846; python: 2,525; lisp: 2,504; asm: 860; makefile: 678; pascal: 70; java: 52; xml: 37; awk: 12
file content (208 lines) | stat: -rw-r--r-- 4,406 bytes parent folder | download | duplicates (2)
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
use core:lang;
use lang:bs;
use lang:bs:macro;
use layout;

/**
 * Functions used by the syntax.
 */


/**
 * A presentation declaration.
 */
package class PresDecl extends NamedDecl {
	SStr name;
	Str title;
	Scope scope;
	SPresCont content;

	init(SStr name, Str title, Scope scope, SPresCont content) {
		init() {
			name = name;
			title = title;
			scope = scope;
			content = content;
		}
	}

	// Create a named entity.
	Named doCreate() {
		PresFn(name, title, scope, content);
	}

	// Update!
	Named? update(Scope scope) {
		var found = scope.find(Name(name.v));
		if (found as PresFn) {
			found.update(title, scope, content);
		} else if (found.empty) {
			var c = create();
			resolve();
			return c;
		}

		return null;
	}
}


/**
 * A function that declares a presentation.
 */
package class PresFn extends BSRawFn {
	Str title;
	Scope scope;
	SPresCont content;

	init(SStr name, Str title, Scope scope, SPresCont content) {
		init(Value(named{Presentation}), name, ValParam[], named{ui:Render}) {
			title = title;
			scope = scope;
			content = content;
		}
	}

	// Update ourselves.
	void update(Str title, Scope scope, SPresCont content) {
		this.title = title;
		this.scope = scope;
		this.content = content;
		reset();
	}

	// Create the function's body.
	FnBody createBody() {
		FnBody body(this, scope);

		// Create a presentation in a variable named 'this'.
		Var thisVar(body, Value(named{Presentation}), SStr("this"), Actuals(strConstant(SStr(title))));
		body.add(thisVar);

		content.transform(body);

		// Return the presentation.
		body.add(LocalVarAccess(SrcPos(), thisVar.var));

		// print(body.toS);
		body;
	}
}


// Apply the slide layout. Also: jam it inside a SlideBorder layout.
Expr slideLayout(Block inside, LayoutRoot layout, SStr? name, Expr? intro) on Compiler {
	var create = if (intro) {
		pattern (inside) {
			presentation:SlideBorder layout(this);
			layout.add(layout:Component:toAdd(${layout.block}));

			presentation:Slide slide(layout);
			slide.intro = ${intro};
			this.add(slide);
			slide;
		};
	} else {
		pattern (inside) {
			presentation:SlideBorder layout(this);
			layout.add(layout:Component:toAdd(${layout.block}));

			presentation:Slide slide(layout);
			this.add(slide);
			slide;
		};
	};

	if (name) {
		// If we have a name, we want to create a variable!
		Var(inside, name, create);
	} else {
		// Otherwise, we just execute the statements.
		create;
	}
}

// Apply the slide layout, but don't add a border.
Expr slidePlainLayout(Block inside, LayoutRoot layout, SStr? name, Expr? intro) on Compiler {
	var create = if (intro) {
		pattern (inside) {
			presentation:Slide slide(${layout.block});
			slide.intro = ${intro};
			this.add(slide);
			slide;
		};
	} else {
		pattern (inside) {
			presentation:Slide slide(${layout.block});
			this.add(slide);
			slide;
		};
	};

	if (name) {
		Var(inside, name, create);
	} else {
		create;
	}
}

// Set the background. Does not use a SlideBorder layout.
Expr slideBackground(Block inside, LayoutRoot layout) on Compiler {
	pattern(inside) {
		this.background(presentation:Slide(${layout.block}));
	};
}

// Get a slide intro expression.
Expr slideIntro(Block block, SrcName name, Actuals params) on Compiler {
	name.last.name = name.last.name + "Intro";
	namedExpr(block, name, params);
}

// Animation declaration.
class AniDecl on Compiler {
	// Block where we store everything.
	ExprBlock block;

	// Variable accessing the created type.
	LocalVarAccess created;

	init(Block parent, Str step, SrcName type, Actuals params) {
		ExprBlock b(type.pos, parent);
		type.last.name = type.last.name + "Animation";
		params.addFirst(intConstant(type.pos, step));
		Var ani(b, SStr("@ animation", type.pos), namedExpr(b, type, params));
		b.add(ani);

		init() {
			block = b;
			created(type.pos, ani.var);
		}
	}

	// Finalize this block.
	void finalize() {
		block.add(created);
	}

	// Set a property.
	void setProperty(Str property, Expr to) {
		var lhs = namedExpr(block, SStr(property, to.pos), created, Actuals());

		AssignOpInfo assign(SStr("=", to.pos), 10, true);
		block.add(assign.meaning(block, lhs, to));
	}

	void setDuration(Expr to) {
		setProperty("duration", to);
	}

	void setOffset(Expr to) {
		setProperty("offset", to);
	}
}

void add(LayoutBlock block, AniDecl ani) on Compiler {
	ani.finalize();
	block.add(SStr("animation", ani.block.pos), Actuals(ani.block));
}