1!% $SMALL ! This is ICL, not a comment.
2!% -w
3
4!% A comprehensive test of Inform6Lexer.
5
6Switches d2SDq;
7
8Constant Story "Informal Testing";
9Constant Headline "^Not a game.^";!% This is a comment, not ICL.
10
11Release 3;
12Serial "151213";
13Version 5;
14
15Ifndef TARGET_ZCODE;
16Ifndef TARGET_GLULX;
17Ifndef WORDSIZE;
18Default WORDSIZE 2;
19Constant TARGET_ZCODE;
20Endif;
21Endif;
22Endif;
23
24Ifv3; Message "Compiling to version 3"; Endif;
25Ifv5; Message "Not compiling to version 3"; endif;
26ifdef TARGET_ZCODE;
27#IFTRUE (#version_number == 5);
28Message "Compiling to version 5";
29#ENDIF;
30endif ;
31
32Replace CreatureTest;
33
34Include "Parser";
35Include "VerbLib";
36
37# ! A hash is optional at the top level.
38Object kitchen "Kitchen"
39    with description "You are in a kitchen.",
40        arr 1 2 3 4,
41    has light;
42
43#[ Initialise;
44    location = kitchen;
45    print "v"; inversion; "^";
46];
47
48Ifdef VN_1633;
49Replace IsSeeThrough IsSeeThroughOrig;
50[ IsSeeThrough * o;
51    return o hasnt opaque || IsSeeThroughOrig(o);
52];
53Endif;
54
55Abbreviate "test";
56
57Array table buffer 260;
58
59Attribute reversed;
60Attribute opaque alias locked;
61Constant to reversed;
62
63Property long additive additive long alias;
64Property long long long wingspan alias alias;
65
66Class Flier with wingspan 5;
67Class Bird(10) has animate class Flier with wingspan 2;
68
69Constant Constant1;
70Constant Constant2 Constant1;
71Constant Constant3 = Constant2;
72Ifdef VN_1633; Undef Constant; Endif;
73
74Ifdef VN_1633;
75Dictionary 'word' 1 2;
76Ifnot;
77Dictionary dict_word "word";
78Endif;
79
80Fake_action NotReal;
81
82Global global1;
83Global global2 = 69105;
84
85Lowstring low_string "low string";
86
87Iftrue false;
88Message error "Uh-oh!^~false~ shouldn't be ~true~.";
89Endif;
90Iffalse true;
91Message fatalerror "Uh-oh!^~true~ shouldn't be ~false~.";
92Endif;
93
94Nearby person "person"
95    with name 'person',
96         description "This person is barely implemented.",
97         life [ * x y z;
98             Ask: print_ret (The) self, " says nothing.";
99             Answer: print (The) self, " didn't say anything.^"; rfalse;
100         ]
101    has has animate transparent;
102
103Object -> -> test_tube "test tube"
104    with name 'test' "tube" 'testtube',
105    has ~openable ~opaque container;
106
107Bird -> pigeon
108    with name 'pigeon',
109        description [;
110            "The pigeon has a wingspan of ", self.&wingspan-->0, " wing units.";
111        ];
112
113Object -> "thimble" with name 'thimble';
114
115Object -> pebble "pebble" with name 'pebble';
116
117Ifdef TARGET_ZCODE; Trace objects; Endif;
118
119Statusline score;
120
121Stub StubR 3;
122
123Ifdef TARGET_ZCODE;
124Zcharacter "abcdefghijklmnopqrstuvwxyz"
125           "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
126           "123456789.,!?_#'0/@{005C}-:()";
127Zcharacter table '@!!' '@<<' '@'A';
128Zcharacter table + '@AE' '@{dc}' '@et' '@:y';
129Ifnot;
130Ifdef TARGET_GLULX;
131Message "Glulx doesn't use ~Zcharacter~.^Oh well."; ! '~' and '^' work here.
132Ifnot;
133Message warning "Uh-oh! ^~^"; ! They don't work in other Messages.
134Endif;
135Endif;
136
137Include "Grammar";
138
139Verb"acquire"'collect'='take';
140
141[ NounFilter; return noun ofclass Bird; ];
142
143[ ScopeFilter obj;
144    switch (scope_stage) {
145    1: rtrue;
146    2: objectloop (obj in compass) PlaceInScope(obj);
147    3: "Nothing is in scope.";
148    }
149];
150
151Verb meta "t" 'test'
152    * 'held' held -> TestHeld
153    * number -> TestNumber
154    * reversed -> TestAttribute
155    * 'creature' creature -> TestCreature
156    * 'multiheld' multiheld -> TestMultiheld
157    * 'm' multiexcept 'into'/"in" noun -> TestMultiexcept
158    * 'm' multiinside 'from' noun -> TestMultiinside
159    * multi -> TestMulti
160    * 'filter'/'f' noun=NounFilter -> TestNounFilter
161    * 'filter'/'f' scope=ScopeFilter -> TestScopeFilter
162    * 'special' special -> TestSpecial
163    * topic -> TestTopic;
164
165Verb 'reverse' 'swap' 'exchange'
166    * held 'for' noun -> reverse
167    * noun 'with' noun -> reverse reverse;
168
169Extend "t" last * noun -> TestNoun;
170
171Extend 't' first * -> Test;
172
173Extend 'wave' replace * -> NewWave;
174
175Extend only 'feel' 'touch' replace * noun -> Feel;
176
177[ TestSub "a\
178           " b o "@@98"; ! Not an escape sequence.
179    string 25 low_string;
180    print "Test what?> ";
181    table->0 = 260;
182    parse->0 = 61;
183    #Ifdef TARGET_ZCODE;
184    read buffer parse;
185    #Ifnot; ! TARGET_GLULX
186    KeyboardPrimitive(buffer, parse);
187    #Endif; ! TARGET_
188    switch (parse-->1) {
189    'save':
190        #Ifdef TARGET_ZCODE;
191        #Ifv3;
192        @save ?saved;
193        #Ifnot;
194        save saved;
195        #Endif;
196        #Endif;
197        print "Saving failed.^";
198    'restore':
199        #Ifdef TARGET_ZCODE;
200        restore saved;
201        #Endif;
202        print "Restoring failed.^";
203    'restart':
204        @restart;
205    'quit', 'q//':
206        quit;
207        return 2; rtrue; rfalse; return;
208    'print', 'p//':
209        print "Print:^",
210            " (string): ", (string) "xyzzy^",
211            " (number): ", (number) 123, "^",
212            " (char): ", (char) 'x', "^",
213            " (address): ", (address) 'plugh//p', "^",
214            " (The): ", (The) person, "^",
215            " (the): ", (the) person, "^",
216            " (A): ", (A) person, "^",
217            " (a): ", (a) person, "^",
218            " (an): ", (an) person, "^",
219            " (name): ", (name) person, "^",
220            " (object): ", (object) person, "^",
221            " (property): ", (property) alias, "^",
222            " (<routine>): ", (LanguageNumber) 123, "^",
223            " <expression>: ", a * 2 - 1, "^",
224            " (<expression>): ", (a + person), "^";
225        print "Escapes:^",
226            " by mnemonic: @!! @<< @'A @AE @et @:y^",
227            " by decimal value: @@64 @@126^",
228            " by Unicode value: @{DC}@{002b}^",
229            " by string variable: @25^";
230    'font', 'style':
231        font off; print "font off^";
232        font on; print "font on^";
233        style reverse; print "style reverse^"; style roman;
234        style bold; print "style bold^";
235        style underline; print "style underline^";
236        style fixed; print "style fixed^";
237        style roman; print "style roman^";
238    'statements':
239        spaces 8;
240        objectloop (o) {
241            print "objectloop (o): ", (the) o, "^";
242        }
243        objectloop (o in compass) { ! 'in' is a keyword
244            print "objectloop (o in compass): ", (the) o, "^";
245        }
246        objectloop (o in compass && true) { ! 'in' is an operator
247            print "objectloop (o in compass && true): ", (the) o, "^";
248        }
249        objectloop (o from se_obj) {
250            print "objectloop (o from se_obj): ", (the) o, "^";
251        }
252        objectloop (o near person) {
253            print "objectloop (o near person): ", (the) o, "^";
254        }
255        #Ifdef TARGET_ZCODE;
256        #Trace assembly on;
257@ ! This is assembly.
258        add -4 ($$1+$3)*2 -> b;
259        @get_sibling test_tube -> b ?saved;
260        @inc [b];
261        @je sp (1+3*0) ? equal;
262        @je 1 ((sp)) ?~ different;
263        .! This is a label:
264            equal;
265        print "sp == 1^";
266        jump label;
267        .different;
268        print "sp @@126= 1^";
269        .label;
270        #Trace off; #Endif; ! TARGET_ZCODE
271        a = random(10);
272        switch (a) {
273        1, 9:
274            box "Testing oneself is best when done alone."
275                "                         -- Jimmy Carter";
276        2, 6, to, 3 to 5, to to to:
277            <Take pigeon>;
278            #Ifdef VN_1633;
279            <Jump, person>;
280            #Endif;
281            a = ##Drop;
282            < ! The angle brackets may be separated by whitespace.
283                < (a) pigeon > >;
284        default:
285            do {
286                give person general ~general;
287            } until (person provides life && ~~false);
288            if (a == 7) a = 4;
289            else a = 5;
290        }
291    'expressions':
292        a = 1+1-1*1/1%1&1|1&&1||1==(1~=(1>(1<(1>=(1<=1)))));
293        a++; ++a; a--; --a;
294        a = person.life;
295        a = kitchen.&arr;
296        a = kitchen.#arr;
297        a = Bird::wingspan;
298        a = kitchen has general;
299        a = kitchen hasnt general;
300        a = kitchen provides arr;
301        a = person in kitchen;
302        a = person notin kitchen;
303        a = person ofclass Bird;
304        a = a == 0 or 1;
305        a = StubR();
306        a = StubR(a);
307        a = StubR(, a);
308        a = "string";
309        a = 'word';
310        a = '''; ! character
311        a = $09afAF;
312        a = $$01;
313        a = ##Eat; a = #a$Eat;
314        a = #g$self;
315        a = #n$!word;
316        a = #r$StubR;
317        a = #dict_par1;
318    default:
319        for (a = 2, b = a; (a < buffer->1 + 2) && (Bird::wingspan): ++a, b--) {
320            print (char) buffer->a;
321        }
322        new_line;
323        for (::) break;
324    }
325    .saved;;
326];
327
328[ TestNumberSub;
329    print_ret parsed_number, " is ", (number) parsed_number, ".";
330];
331
332[ TestAttributeSub; print_ret (The) noun, " has been reversed."; ];
333
334[ CreatureTest obj; return obj has animate; ];
335
336[ TestCreatureSub; print_ret (The) noun, " is a creature."; ];
337
338[ TestMultiheldSub; print_ret "You are holding ", (the) noun, "."; ];
339
340[ TestMultiexceptSub; "You test ", (the) noun, " with ", (the) second, "."; ];
341
342[ TestMultiinsideSub; "You test ", (the) noun, " from ", (the) second, "."; ];
343
344[ TestMultiSub; print_ret (The) noun, " is a thing."; ];
345
346[ TestNounFilterSub; print_ret (The) noun, " is a bird."; ];
347
348[ TestScopeFilterSub; print_ret (The) noun, " is a direction."; ];
349
350[ TestSpecialSub; "Your lucky number is ", parsed_number, "."; ];
351
352[ TestTopicSub; "You discuss a topic."; ];
353
354[ TestNounSub; "That is ", (a) noun, "."; ];
355
356[ TestHeldSub; "You are holding ", (a) noun, "."; ];
357
358[ NewWaveSub; "That would be foolish."; ];
359
360[ FeelSub; print_ret (The) noun, " feels normal."; ];
361
362[ ReverseSub from;
363    from = parent(noun);
364    move noun to parent(second);
365    if (from == to)
366        move second to to;
367    else
368        move second to from;
369    give noun to;
370    from = to;
371    give second from;
372    "You swap ", (the) noun, " and ", (the) second, ".";
373];
374
375End: The End directive ends the source code.
376