Debian Codegraph @

terps/tads/tads3/test/data/words.t

raw
1 /*
2 * dictionary test
3 */
4
5 #include "tads.h"
6 #include "t3.h"
7 #include "dict.h"
8
9 class RuntimeError: object
10 construct(errno, ...) { errno_ = errno; }
11 display = "Runtime error: <<exceptionMessage>>"
12 errno_ = 0
13 exceptionMessage = ''
14 ;
15
16 _say_embed(str) { tadsSay(str); }
17
18 _main(args)
19 {
20 try
21 {
22 t3SetSay(&_say_embed);
23 main(args);
24 }
25 catch (RuntimeError rte)
26 {
27 "\n<<rte.display>>\n";
28 }
29 }
30
31 obj1: object
32 adjective = 'none'
33 noun = 'none'
34 ;
35
36 bluebook: object sdesc = "blue_book";
37 redbook: object sdesc = "red_book";
38 greenbook: object sdesc = "green_book";
39 blueball: object sdesc = "blue_ball";
40 redball: object sdesc = "red_ball";
41 greenball: object sdesc = "green_ball";
42
43 main(args)
44 {
45 local dict;
46 local lst;
47
48 /* create a dictionary */
49 dict = new Dictionary(6);
50
51 /* add some words */
52 dict.addWord(bluebook, 'blue', &adjective);
53 dict.addWord(redbook, 'red', &adjective);
54 dict.addWord(greenbook, 'green', &adjective);
55
56 dict.addWord(blueball, 'blue', &adjective);
57 dict.addWord(redball, 'red', &adjective);
58 dict.addWord(greenball, 'green', &adjective);
59
60 dict.addWord(bluebook, 'book', &noun);
61 dict.addWord(redbook, 'book', &noun);
62 dict.addWord(greenbook, 'book', &noun);
63
64 dict.addWord(blueball, 'ball', &noun);
65 dict.addWord(redball, 'ball', &noun);
66 dict.addWord(greenball, 'ball', &noun);
67
68 dict.addWord(redball, ['rouge', 'reddish', 'ruddy', 'rosy'], &adjective);
69
70 /* look up some words */
71 "noun 'book': <<sayList(dict.findWord('book', &noun))>>\n";
72 "noun: 'ball': <<sayList(dict.findWord('ball', &noun))>>\n";
73 "adjective: 'red': <<sayList(dict.findWord('red', &adjective))>>\n";
74 "adjective: 'blue': <<sayList(dict.findWord('blue', &adjective))>>\n";
75 "adjective: 'green': <<sayList(dict.findWord('green', &adjective))>>\n";
76 "adjective: 'rouge':
77 <<sayList(dict.findWord('rouge', &adjective))>>\n";
78 "adjective: 'reddish':
79 <<sayList(dict.findWord('reddish', &adjective))>>\n";
80 "adjective: 'ruddy':
81 <<sayList(dict.findWord('ruddy', &adjective))>>\n";
82 "adjective: 'rosy':
83 <<sayList(dict.findWord('rosy', &adjective))>>\n";
84
85 /* shorten the truncation length */
86 dict.setTruncLen(3);
87
88 "\bAfter setting truncation length to 3:\n";
89 "noun 'book': <<sayList(dict.findWord('book', &noun))>>\n";
90 "noun: 'ball': <<sayList(dict.findWord('ball', &noun))>>\n";
91 "adjective: 'red': <<sayList(dict.findWord('red', &adjective))>>\n";
92 "adjective: 'blue': <<sayList(dict.findWord('blue', &adjective))>>\n";
93 "adjective: 'green': <<sayList(dict.findWord('green', &adjective))>>\n";
94
95 "noun: 'boo': <<sayList(dict.findWord('boo', &noun))>>\n";
96 "noun: 'boop': <<sayList(dict.findWord('boop', &noun))>>\n";
97 "adjective: 'green': <<sayList(dict.findWord('green', &adjective))>>\n";
98 "adjective: 'gree': <<sayList(dict.findWord('gree', &adjective))>>\n";
99 "adjective: 'gre': <<sayList(dict.findWord('gre', &adjective))>>\n";
100 "adjective: 'gr': <<sayList(dict.findWord('gr', &adjective))>>\n";
101 "adjective: 'greek': <<sayList(dict.findWord('greek', &adjective))>>\n";
102 "adjective: 'greeny': <<sayList(dict.findWord('greeny', &adjective))>>\n";
103
104 "\bFinding with truncation:\n";
105 "noun: 'boo': <<sayList(dict.findWordTrunc('boo', &noun))>>\n";
106 "noun: 'boop': <<sayList(dict.findWordTrunc('boop', &noun))>>\n";
107 "adjective: 'green':
108 <<sayList(dict.findWordTrunc('green', &adjective))>>\n";
109 "adjective: 'gree':
110 <<sayList(dict.findWordTrunc('gree', &adjective))>>\n";
111 "adjective: 'gre': <<sayList(dict.findWordTrunc('gre', &adjective))>>\n";
112 "adjective: 'gr': <<sayList(dict.findWordTrunc('gr', &adjective))>>\n";
113 "adjective: 'greek':
114 <<sayList(dict.findWordTrunc('greek', &adjective))>>\n";
115 "adjective: 'greeny':
116 <<sayList(dict.findWordTrunc('greeny', &adjective))>>\n";
117 }
118
119 sayList(lst)
120 {
121 "[";
122 for (local i = 1, local len = lst.length() ; i <= len ; ++i)
123 {
124 if (i > 1)
125 ", ";
126 lst[i].sdesc;
127 }
128 "]";
129 }